1/*
2 * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#ifndef OWNCLOUDGUI_H
16#define OWNCLOUDGUI_H
17
18#include "systray.h"
19#include "connectionvalidator.h"
20#include "progressdispatcher.h"
21
22#include <QObject>
23#include <QPointer>
24#include <QAction>
25#include <QMenu>
26#include <QSize>
27#include <QTimer>
28
29namespace OCC {
30
31class Folder;
32
33class SettingsDialog;
34class SettingsDialogMac;
35class ShareDialog;
36class Application;
37class LogBrowser;
38class AccountState;
39
40enum class ShareDialogStartPage {
41 UsersAndGroups,
42 PublicLinks,
43};
44
45/**
46 * @brief The ownCloudGui class
47 * @ingroup gui
48 */
49class ownCloudGui : public QObject
50{
51 Q_OBJECT
52public:
53 explicit ownCloudGui(Application *parent = 0);
54
55 bool checkAccountExists(bool openSettings);
56
57 static void raiseDialog(QWidget *raiseWidget);
58 static QSize settingsDialogSize() { return QSize(800, 500); }
59 void setupOverlayIcons();
60
61 /// Whether the tray menu is visible
62 bool contextMenuVisible() const;
63
64signals:
65 void setupProxy();
66
67public slots:
68 void setupContextMenu();
69 void updateContextMenu();
70 void updateContextMenuNeeded();
71 void slotContextMenuAboutToShow();
72 void slotContextMenuAboutToHide();
73 void slotComputeOverallSyncStatus();
74 void slotShowTrayMessage(const QString &title, const QString &msg);
75 void slotShowOptionalTrayMessage(const QString &title, const QString &msg);
76 void slotFolderOpenAction(const QString &alias);
77 void slotRebuildRecentMenus();
78 void slotUpdateProgress(const QString &folder, const ProgressInfo &progress);
79 void slotShowGuiMessage(const QString &title, const QString &message);
80 void slotFoldersChanged();
81 void slotShowSettings();
82 void slotShowSyncProtocol();
83 void slotShutdown();
84 void slotSyncStateChange(Folder *);
85 void slotTrayClicked(QSystemTrayIcon::ActivationReason reason);
86 void slotToggleLogBrowser();
87 void slotOpenOwnCloud();
88 void slotOpenSettingsDialog();
89 void slotHelp();
90 void slotOpenPath(const QString &path);
91 void slotAccountStateChanged();
92 void slotTrayMessageIfServerUnsupported(Account *account);
93
94 /**
95 * Open a share dialog for a file or folder.
96 *
97 * sharePath is the full remote path to the item,
98 * localPath is the absolute local path to it (so not relative
99 * to the folder).
100 */
101 void slotShowShareDialog(const QString &sharePath, const QString &localPath, ShareDialogStartPage startPage);
102
103 void slotRemoveDestroyedShareDialogs();
104
105private slots:
106 void slotLogin();
107 void slotLogout();
108 void slotUnpauseAllFolders();
109 void slotPauseAllFolders();
110 void slotNewAccountWizard();
111 void slotAbout();
112
113private:
114 void setPauseOnAllFoldersHelper(bool pause);
115 void setupActions();
116 void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu);
117
118 QPointer<Systray> _tray;
119#if defined(Q_OS_MAC)
120 QPointer<SettingsDialogMac> _settingsDialog;
121#else
122 QPointer<SettingsDialog> _settingsDialog;
123#endif
124 QPointer<LogBrowser> _logBrowser;
125 // tray's menu
126 QScopedPointer<QMenu> _contextMenu;
127
128 // Manually tracking whether the context menu is visible via aboutToShow
129 // and aboutToHide. Unfortunately aboutToHide isn't reliable everywhere
130 // so this only gets used with _workaroundManualVisibility (when the tray's
131 // isVisible() is unreliable)
132 bool _contextMenuVisibleManual = false;
133
134 QMenu *_recentActionsMenu;
135 QVector<QMenu *> _accountMenus;
136 bool _workaroundShowAndHideTray = false;
137 bool _workaroundNoAboutToShowUpdate = false;
138 bool _workaroundFakeDoubleClick = false;
139 bool _workaroundManualVisibility = false;
140 QTimer _delayedTrayUpdateTimer;
141 QMap<QString, QPointer<ShareDialog>> _shareDialogs;
142
143 QAction *_actionLogin;
144 QAction *_actionLogout;
145
146 QAction *_actionNewAccountWizard;
147 QAction *_actionSettings;
148 QAction *_actionStatus;
149 QAction *_actionEstimate;
150 QAction *_actionRecent;
151 QAction *_actionHelp;
152 QAction *_actionAbout;
153 QAction *_actionQuit;
154 QAction *_actionCrash;
155
156 QList<QAction *> _recentItemsActions;
157 Application *_app;
158};
159
160} // namespace OCC
161
162#endif // OWNCLOUDGUI_H
163