Skip to content

Commit

Permalink
Treat FileProviderSettingsController::settingsViewWidget as a factory…
Browse files Browse the repository at this point in the history
… method

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Sep 4, 2023
1 parent 9f4f1ac commit 16b22b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)

#if defined(BUILD_FILE_PROVIDER_MODULE)
if (Mac::FileProvider::fileProviderAvailable()) {
const auto fpSettingsWidget = Mac::FileProviderSettingsController::instance()->settingsViewWidget();
const auto fpSettingsLayout = new QVBoxLayout(_ui->fileProviderTab);
const auto fileProviderTab = _ui->fileProviderTab;
const auto fpSettingsLayout = new QVBoxLayout(fileProviderTab);
const auto fpSettingsWidget = Mac::FileProviderSettingsController::instance()->settingsViewWidget(fileProviderTab);
fpSettingsLayout->setMargin(0);
fpSettingsLayout->addWidget(fpSettingsWidget);
_ui->fileProviderTab->setLayout(fpSettingsLayout);
fileProviderTab->setLayout(fpSettingsLayout);
} else {
disguiseTabWidget();
}
Expand Down
7 changes: 2 additions & 5 deletions src/gui/macOS/ui/fileprovidersettingscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ class FileProviderSettingsController : public QObject
public:
static FileProviderSettingsController *instance();

[[nodiscard]] QQuickWidget *settingsViewWidget();
[[nodiscard]] QQuickWidget *settingsViewWidget(QWidget *const parent = nullptr,
const QQuickWidget::ResizeMode resizeMode = QQuickWidget::SizeRootObjectToView);

private:
explicit FileProviderSettingsController(QObject *parent = nullptr);
~FileProviderSettingsController() override;

void instantiateSettingsWidget();

class MacImplementation;
std::unique_ptr<MacImplementation> d;

std::unique_ptr<QQuickWidget> _settingsViewWidget;
};

} // Mac
Expand Down
20 changes: 6 additions & 14 deletions src/gui/macOS/ui/fileprovidersettingscontroller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,13 @@
d = std::make_unique<FileProviderSettingsController::MacImplementation>(this);
}

void FileProviderSettingsController::instantiateSettingsWidget()
QQuickWidget *FileProviderSettingsController::settingsViewWidget(QWidget *const parent, const QQuickWidget::ResizeMode resizeMode)
{
_settingsViewWidget = std::make_unique<QQuickWidget>(Systray::instance()->trayEngine(), nullptr);
_settingsViewWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
_settingsViewWidget->setSource(QUrl(fpSettingsQmlPath));
_settingsViewWidget->rootContext()->setContextProperty(fpSettingsControllerProp, this);
}

QQuickWidget *FileProviderSettingsController::settingsViewWidget()
{
if (!_settingsViewWidget) {
instantiateSettingsWidget();
}

return _settingsViewWidget.get();
const auto settingsViewWidget = new QQuickWidget(Systray::instance()->trayEngine(), parent);
settingsViewWidget->setResizeMode(resizeMode);
settingsViewWidget->setSource(QUrl(fpSettingsQmlPath));
settingsViewWidget->rootContext()->setContextProperty(fpSettingsControllerProp, this);
return settingsViewWidget;
}

} // namespace Mac
Expand Down

0 comments on commit 16b22b5

Please sign in to comment.