mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Merge pull request #4688 from nextcloud/bugfix/refactor-tray-window-open
Refactor tray window opening code for clarity and efficiency
This commit is contained in:
commit
fc16d82dfd
@ -82,9 +82,6 @@ ownCloudGui::ownCloudGui(Application *parent)
|
||||
connect(_tray.data(), &Systray::openAccountWizard,
|
||||
this, &ownCloudGui::slotNewAccountWizard);
|
||||
|
||||
connect(_tray.data(), &Systray::openMainDialog,
|
||||
this, &ownCloudGui::slotOpenMainDialog);
|
||||
|
||||
connect(_tray.data(), &Systray::openSettings,
|
||||
this, &ownCloudGui::slotShowSettings);
|
||||
|
||||
@ -157,9 +154,7 @@ void ownCloudGui::slotOpenSettingsDialog()
|
||||
|
||||
void ownCloudGui::slotOpenMainDialog()
|
||||
{
|
||||
if (!_tray->isOpen()) {
|
||||
_tray->showWindow();
|
||||
}
|
||||
_tray->showWindow();
|
||||
}
|
||||
|
||||
void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason)
|
||||
|
||||
@ -120,7 +120,7 @@ Systray::Systray()
|
||||
|
||||
#if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
|
||||
connect(AccountManager::instance(), &AccountManager::accountAdded,
|
||||
this, [this]{ emit showWindow(); });
|
||||
this, [this]{ showWindow(); });
|
||||
#else
|
||||
// Since the positioning of the QSystemTrayIcon is borked on non-Windows and non-macOS desktop environments,
|
||||
// we hardcode the position of the tray to be in the center when we add a new account from somewhere like
|
||||
@ -128,7 +128,7 @@ Systray::Systray()
|
||||
// is placed
|
||||
|
||||
connect(AccountManager::instance(), &AccountManager::accountAdded,
|
||||
this, [this]{ emit showWindow(WindowPosition::Center); });
|
||||
this, [this]{ showWindow(WindowPosition::Center); });
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -138,7 +138,9 @@ void Systray::create()
|
||||
if (!AccountManager::instance()->accounts().isEmpty()) {
|
||||
_trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel());
|
||||
}
|
||||
_trayEngine->load(QStringLiteral("qrc:/qml/src/gui/tray/Window.qml"));
|
||||
|
||||
QQmlComponent trayWindowComponent(_trayEngine, QStringLiteral("qrc:/qml/src/gui/tray/Window.qml"));
|
||||
_trayWindow.reset(qobject_cast<QQuickWindow*>(trayWindowComponent.create()));
|
||||
}
|
||||
hideWindow();
|
||||
emit activated(QSystemTrayIcon::ActivationReason::Unknown);
|
||||
@ -152,6 +154,36 @@ void Systray::create()
|
||||
}
|
||||
}
|
||||
|
||||
void Systray::showWindow(WindowPosition position)
|
||||
{
|
||||
if(isOpen() || !_trayWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(position == WindowPosition::Center) {
|
||||
positionWindowAtScreenCenter(_trayWindow.data());
|
||||
} else {
|
||||
positionWindowAtTray(_trayWindow.data());
|
||||
}
|
||||
_trayWindow->show();
|
||||
_trayWindow->raise();
|
||||
_trayWindow->requestActivate();
|
||||
|
||||
setIsOpen(true);
|
||||
|
||||
UserModel::instance()->fetchCurrentActivityModel();
|
||||
}
|
||||
|
||||
void Systray::hideWindow()
|
||||
{
|
||||
if(!isOpen() || !_trayWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
_trayWindow->hide();
|
||||
setIsOpen(false);
|
||||
}
|
||||
|
||||
void Systray::setupContextMenu()
|
||||
{
|
||||
const auto oldContextMenu = _contextMenu.data();
|
||||
@ -169,7 +201,7 @@ void Systray::setupContextMenu()
|
||||
if (AccountManager::instance()->accounts().isEmpty()) {
|
||||
_contextMenu->addAction(tr("Add account"), this, &Systray::openAccountWizard);
|
||||
} else {
|
||||
_contextMenu->addAction(tr("Open main dialog"), this, &Systray::openMainDialog);
|
||||
_contextMenu->addAction(tr("Open main dialog"), this, [this]{ showWindow(); });
|
||||
}
|
||||
|
||||
auto pauseAction = _contextMenu->addAction(tr("Pause sync"), this, &Systray::slotPauseAllFolders);
|
||||
|
||||
@ -75,7 +75,7 @@ public:
|
||||
|
||||
enum class TaskBarPosition { Bottom, Left, Top, Right };
|
||||
Q_ENUM(TaskBarPosition);
|
||||
|
||||
|
||||
enum class NotificationPosition { Default, TopLeft, TopRight, BottomLeft, BottomRight };
|
||||
Q_ENUM(NotificationPosition);
|
||||
|
||||
@ -98,15 +98,10 @@ public:
|
||||
signals:
|
||||
void currentUserChanged();
|
||||
void openAccountWizard();
|
||||
void openMainDialog();
|
||||
void openSettings();
|
||||
void openHelp();
|
||||
void shutdown();
|
||||
|
||||
// These window signals are listened to in Window.qml
|
||||
void hideWindow();
|
||||
void showWindow(WindowPosition position = WindowPosition::Default);
|
||||
|
||||
void openShareDialog(const QString &sharePath, const QString &localPath);
|
||||
void showFileActivityDialog(const QString &objectName, const int objectId);
|
||||
void sendChatMessage(const QString &token, const QString &message, const QString &replyTo);
|
||||
@ -117,15 +112,18 @@ signals:
|
||||
|
||||
public slots:
|
||||
void slotNewUserSelected();
|
||||
|
||||
void forceWindowInit(QQuickWindow *window) const;
|
||||
void positionWindowAtTray(QQuickWindow *window) const;
|
||||
void positionWindowAtScreenCenter(QQuickWindow *window) const;
|
||||
void positionNotificationWindow(QQuickWindow *window) const;
|
||||
|
||||
void showWindow(WindowPosition position = WindowPosition::Default);
|
||||
void hideWindow();
|
||||
|
||||
void setSyncIsPaused(const bool syncIsPaused);
|
||||
void setIsOpen(const bool isOpen);
|
||||
|
||||
void forceWindowInit(QQuickWindow *window) const;
|
||||
void positionNotificationWindow(QQuickWindow *window) const;
|
||||
|
||||
private slots:
|
||||
void slotUnpauseAllFolders();
|
||||
void slotPauseAllFolders();
|
||||
@ -153,6 +151,7 @@ private:
|
||||
bool _syncIsPaused = true;
|
||||
QPointer<QQmlApplicationEngine> _trayEngine;
|
||||
QPointer<QMenu> _contextMenu;
|
||||
QSharedPointer<QQuickWindow> _trayWindow;
|
||||
|
||||
AccessManagerFactory _accessManagerFactory;
|
||||
|
||||
|
||||
@ -77,31 +77,11 @@ Window {
|
||||
Connections {
|
||||
target: Systray
|
||||
|
||||
function onShowWindow(position) {
|
||||
if(trayWindow.visible) {
|
||||
return;
|
||||
function onIsOpenChanged() {
|
||||
if(Systray.isOpen) {
|
||||
accountMenu.close();
|
||||
appsMenu.close();
|
||||
}
|
||||
|
||||
accountMenu.close();
|
||||
appsMenu.close();
|
||||
|
||||
if(position === Systray.WindowPosition.Center) {
|
||||
Systray.positionWindowAtScreenCenter(trayWindow);
|
||||
} else {
|
||||
Systray.positionWindowAtTray(trayWindow);
|
||||
}
|
||||
|
||||
trayWindow.show();
|
||||
trayWindow.raise();
|
||||
trayWindow.requestActivate();
|
||||
|
||||
Systray.isOpen = true;
|
||||
UserModel.fetchCurrentActivityModel();
|
||||
}
|
||||
|
||||
function onHideWindow() {
|
||||
trayWindow.hide();
|
||||
Systray.isOpen = false;
|
||||
}
|
||||
|
||||
function onShowFileActivityDialog(objectName, objectId) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user