Просмотр исходного кода

removed all GUI related stuff finally away from the folder class,
last thing were the openActions, which went to the GUI class.

Klaas Freitag 14 лет назад
Родитель
Сommit
da482e742b

+ 52 - 27
src/mirall/application.cpp

@@ -17,6 +17,7 @@
 #include <QHash>
 #include <QHashIterator>
 #include <QUrl>
+#include <QDesktopServices>
 
 #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();

+ 3 - 0
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

+ 0 - 21
src/mirall/folder.cpp

@@ -12,11 +12,7 @@
  * for more details.
  */
 
-#include <QAction>
 #include <QDebug>
-#include <QDesktopServices>
-#include <QIcon>
-#include <QMutexLocker>
 #include <QTimer>
 #include <QUrl>
 
@@ -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)

+ 0 - 5
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();
 
 };

+ 13 - 2
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;

+ 5 - 0
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
       */