connect(_tray.data(), &Systray::openAccountWizard,
this, &ownCloudGui::slotNewAccountWizard);
- connect(_tray.data(), &Systray::openMainDialog,
- this, &ownCloudGui::slotOpenMainDialog);
-
connect(_tray.data(), &Systray::openSettings,
this, &ownCloudGui::slotShowSettings);
void ownCloudGui::slotOpenMainDialog()
{
- if (!_tray->isOpen()) {
- _tray->showWindow();
- }
+ _tray->showWindow();
}
void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason)
#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
// is placed
connect(AccountManager::instance(), &AccountManager::accountAdded,
- this, [this]{ emit showWindow(WindowPosition::Center); });
+ this, [this]{ showWindow(WindowPosition::Center); });
#endif
}
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);
}
}
+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();
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);
enum class TaskBarPosition { Bottom, Left, Top, Right };
Q_ENUM(TaskBarPosition);
-
+
enum class NotificationPosition { Default, TopLeft, TopRight, BottomLeft, BottomRight };
Q_ENUM(NotificationPosition);
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);
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();
bool _syncIsPaused = true;
QPointer<QQmlApplicationEngine> _trayEngine;
QPointer<QMenu> _contextMenu;
+ QSharedPointer<QQuickWindow> _trayWindow;
AccessManagerFactory _accessManagerFactory;
Connections {\r
target: Systray\r
\r
- function onShowWindow(position) {\r
- if(trayWindow.visible) {\r
- return;\r
+ function onIsOpenChanged() {\r
+ if(Systray.isOpen) {\r
+ accountMenu.close();\r
+ appsMenu.close();\r
}\r
-\r
- accountMenu.close();\r
- appsMenu.close();\r
-\r
- if(position === Systray.WindowPosition.Center) {\r
- Systray.positionWindowAtScreenCenter(trayWindow);\r
- } else {\r
- Systray.positionWindowAtTray(trayWindow);\r
- }\r
-\r
- trayWindow.show();\r
- trayWindow.raise();\r
- trayWindow.requestActivate();\r
-\r
- Systray.isOpen = true;\r
- UserModel.fetchCurrentActivityModel();\r
- }\r
-\r
- function onHideWindow() {\r
- trayWindow.hide();\r
- Systray.isOpen = false;\r
}\r
\r
function onShowFileActivityDialog(objectName, objectId) {\r