From da482e742b38a1387d12b9edbeb18680693ff155 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 21 Feb 2012 11:50:19 +0100 Subject: [PATCH] removed all GUI related stuff finally away from the folder class, last thing were the openActions, which went to the GUI class. --- src/mirall/application.cpp | 79 +++++++++++++++++++++++++------------- src/mirall/application.h | 3 ++ src/mirall/folder.cpp | 21 ---------- src/mirall/folder.h | 5 --- src/mirall/folderman.cpp | 15 +++++++- src/mirall/folderman.h | 5 +++ 6 files changed, 73 insertions(+), 55 deletions(-) diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 8c8336006b..6bead36a38 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "mirall/constants.h" #include "mirall/application.h" @@ -57,10 +58,14 @@ Application::Application(int argc, char **argv) : INotify::initialize(); _folderMan = new FolderMan(); - connect( _folderMan, SIGNAL(folderSyncStateChange(QString)), this,SLOT(slotSyncStateChange(QString))); + /* use a signal mapper to map the open requests to the alias names */ + _folderOpenActionMapper = new QSignalMapper(this); + connect(_folderOpenActionMapper, SIGNAL(mapped(const QString &)), + this, SLOT(slotFolderOpenAction(const QString &))); + setQuitOnLastWindowClosed(false); _folderWizard = new FolderWizard(); @@ -80,21 +85,20 @@ Application::Application(int argc, char **argv) : connect( _statusDialog, SIGNAL(infoFolderAlias(const QString&)), SLOT(slotInfoFolder( const QString&))); - setupActions(); - setupSystemTray(); - qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline"); foreach (QNetworkConfiguration netCfg, _networkMgr->allConfigurations(QNetworkConfiguration::Active)) { //qDebug() << "Network:" << netCfg.identifier(); } - setupContextMenu(); - /* setup the folder list */ int cnt = _folderMan->setupFolders(); - if( cnt ) _tray->setIcon(QIcon::fromTheme(MIRALL_ICON, QIcon( QString( ":/mirall/resources/%1").arg(MIRALL_ICON)))); + setupActions(); + setupSystemTray(); + if( cnt ) { + _tray->setIcon(QIcon::fromTheme(MIRALL_ICON, QIcon( QString( ":/mirall/resources/%1").arg(MIRALL_ICON)))); + } qDebug() << "Network Location: " << NetworkLocation::currentLocation().encoded(); } @@ -115,6 +119,8 @@ void Application::setupActions() QObject::connect(_actionAddFolder, SIGNAL(triggered(bool)), SLOT(slotAddFolder())); _actionConfigure = new QAction(tr("Configure..."), this); QObject::connect(_actionConfigure, SIGNAL(triggered(bool)), SLOT(slotConfigure())); + + _actionQuit = new QAction(tr("Quit"), this); QObject::connect(_actionQuit, SIGNAL(triggered(bool)), SLOT(quit())); } @@ -127,9 +133,48 @@ void Application::setupSystemTray() connect(_tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason))); + setupContextMenu(); + _tray->show(); } +void Application::setupContextMenu() +{ + delete _contextMenu; + _contextMenu = new QMenu(); + _contextMenu->setTitle(_theme->appName() ); + _contextMenu->addAction(_actionConfigure); + _contextMenu->addAction(_actionAddFolder); + _contextMenu->addSeparator(); + + // here all folders should be added + foreach (Folder *folder, _folderMan->map() ) { + QAction *action = new QAction( tr("open %1").arg( folder->alias()), this ); + action->setIcon( _theme->folderIcon( folder->backend(), 22) ); + + connect( action, SIGNAL(triggered()),_folderOpenActionMapper,SLOT(map())); + _folderOpenActionMapper->setMapping( action, folder->alias() ); + + _contextMenu->addAction(action); + } + + _contextMenu->addSeparator(); + + _contextMenu->addAction(_actionQuit); + _tray->setContextMenu(_contextMenu); +} + +/* + * open the folder with the given Alais + */ +void Application::slotFolderOpenAction( const QString& alias ) +{ + Folder *f = _folderMan->folder(alias); + if( f ) { + QDesktopServices::openUrl(QUrl( f->path() )); + } +} + void Application::slotTrayClicked( QSystemTrayIcon::ActivationReason reason ) { if( reason == QSystemTrayIcon::Trigger ) { @@ -154,26 +199,6 @@ void Application::slotTrayClicked( QSystemTrayIcon::ActivationReason reason ) } } -void Application::setupContextMenu() -{ - delete _contextMenu; - _contextMenu = new QMenu(); - _contextMenu->setTitle(tr( "Mirall" )); - _contextMenu->addAction(_actionConfigure); - _contextMenu->addAction(_actionAddFolder); - _contextMenu->addSeparator(); - - // here all folders should be added - foreach (Folder *folder, _folderMan->map() ) { - _contextMenu->addAction(folder->openAction()); - } - - _contextMenu->addSeparator(); - - _contextMenu->addAction(_actionQuit); - _tray->setContextMenu(_contextMenu); -} - void Application::slotAddFolder() { _folderMan->disableFoldersWithRestore(); diff --git a/src/mirall/application.h b/src/mirall/application.h index b41a73963e..aaadbba8cd 100644 --- a/src/mirall/application.h +++ b/src/mirall/application.h @@ -27,6 +27,7 @@ class QAction; class QMenu; class QSystemTrayIcon; class QNetworkConfigurationManager; +class QSignalMapper; namespace Mirall { class Theme; @@ -67,6 +68,7 @@ protected: protected slots: void slotTrayClicked( QSystemTrayIcon::ActivationReason ); + void slotFolderOpenAction(const QString & ); private: // configuration file -> folder @@ -86,6 +88,7 @@ private: FolderMan *_folderMan; Theme *_theme; + QSignalMapper *_folderOpenActionMapper; }; } // namespace Mirall diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index bb050a1c4e..e6f2560e1a 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -12,11 +12,7 @@ * for more details. */ -#include #include -#include -#include -#include #include #include @@ -40,12 +36,6 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent) _online(false), _enabled(true) { - _openAction = new QAction(QIcon::fromTheme(FOLDER_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_ICON))), path, this); - _openAction->setIconVisibleInMenu(true); - _openAction->setIcon(QIcon::fromTheme(FOLDER_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_ICON)))); - - QObject::connect(_openAction, SIGNAL(triggered(bool)), SLOT(slotOpenFolder())); - _pollTimer->setSingleShot(true); _pollTimer->setInterval(pollInterval() * 1000); QObject::connect(_pollTimer, SIGNAL(timeout()), this, SLOT(slotPollTimerTimeout())); @@ -67,11 +57,6 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent) } -QAction * Folder::openAction() const -{ - return _openAction; -} - Folder::~Folder() { } @@ -190,11 +175,6 @@ void Folder::slotChanged(const QStringList &pathList) evaluateSync(pathList); } -void Folder::slotOpenFolder() -{ - QDesktopServices::openUrl(QUrl(_path)); -} - void Folder::slotSyncStarted() { // disable events until syncing is done @@ -202,7 +182,6 @@ void Folder::slotSyncStarted() _syncResult = SyncResult( SyncResult::SyncRunning ); emit syncStateChange(); - _openAction->setIcon(QIcon::fromTheme(FOLDER_SYNC_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_SYNC_ICON)))); } void Folder::slotSyncFinished(const SyncResult &result) diff --git a/src/mirall/folder.h b/src/mirall/folder.h index cb4c888947..8a07b16c1b 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -51,8 +51,6 @@ public: */ QString path() const; - QAction *openAction() const; - /** * switch sync on or off * If the sync is switched off, the startSync method is not going to @@ -162,7 +160,6 @@ private: void evaluateSync(const QStringList &pathList); QString _path; - QAction *_openAction; // poll timer for remote syncs QTimer *_pollTimer; int _pollInterval; @@ -184,8 +181,6 @@ protected slots: /* called when the watcher detect a list of changed paths */ - void slotOpenFolder(); - void slotSyncStarted(); }; diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index 884a9e9bba..bec63fdcd6 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -207,11 +207,22 @@ void FolderMan::slotEnableFolder( const QString& alias, bool enable ) f->setSyncEnabled(enable); } +Folder *FolderMan::folder( const QString& alias ) +{ + if( !alias.isEmpty() ) { + if( _folderMap.contains( alias )) { + return _folderMap[alias]; + } + } + return 0; +} + SyncResult FolderMan::syncResult( const QString& alias ) { SyncResult res; - if( _folderMap.contains( alias ) ) { - Folder *f = _folderMap[alias]; + Folder *f = folder( alias ); + + if( f ) { res = f->syncResult(); } return res; diff --git a/src/mirall/folderman.h b/src/mirall/folderman.h index 78f9f0c586..1ec0bad354 100644 --- a/src/mirall/folderman.h +++ b/src/mirall/folderman.h @@ -52,6 +52,11 @@ public: */ Folder *addFolderDefinition( const QString&, const QString&, const QString&, const QString&, bool ); + /** + * return the folder by alias or NULL if no folder with the alias exists. + */ + Folder *folder( const QString& ); + /** * return the last sync result by alias */