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

error handling: sitecopy not installed

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

+ 19 - 4
src/mirall/application.cpp

@@ -77,7 +77,14 @@ Application::Application(int argc, char **argv) :
     setupKnownFolders();
     setupContextMenu();
 
-    qDebug() << NetworkLocation::currentLocation().encoded();
+    // Check if sitecopy is installed
+    QFileInfo fi( SITECOPY_BIN );
+    if( !fi.exists() ) {
+      QMessageBox::critical( 0, tr("Sitecopy not Installed."),
+                            tr("The program <i>sitecopy</i> is not installed but it is needed by mirall.<br/>Please install sitecopy!"));
+    }
+
+    qDebug() << "Network Location: " << NetworkLocation::currentLocation().encoded();
 }
 
 Application::~Application()
@@ -331,9 +338,16 @@ void Application::setupFolderFromConfigFile(const QString &file) {
           QString targetPath = settings.value("backend:sitecopy/targetPath").toString();
 
           SiteCopyFolder *scf = new SiteCopyFolder( file, /* file is the same as the alias */
-                                                      path.toString(),
-                                                      targetPath,
-                                                      this);
+                                                    path.toString(),
+                                                    targetPath,
+                                                    this);
+          QFileInfo fi( SITECOPY_BIN );
+          if( ! fi.exists() ) {
+            SyncResult sr( SyncResult::SetupError );
+            sr.setErrorString( tr("Sitecopy is not installed!"));
+            scf->slotSyncFinished( sr );
+          }
+
           folder = scf;
 
         } else if (backend == "unison") {
@@ -361,6 +375,7 @@ void Application::setupFolderFromConfigFile(const QString &file) {
     folder->setOnlyThisLANEnabled(settings.value("folder/onlyThisLAN", false).toBool());
 
     _folderMap[file] = folder;
+    qDebug() << "Adding folder to Folder Map " << folder;
     QObject::connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
     QObject::connect(folder, SIGNAL(syncFinished(const SyncResult &)), SLOT(slotFolderSyncFinished(const SyncResult &)));
 }

+ 14 - 3
src/mirall/folder.cpp

@@ -91,7 +91,10 @@ bool Folder::syncEnabled() const
 
 void Folder::setSyncEnabled( bool doit )
 {
+  if( _lastSyncResult.result() != SyncResult::Success ) doit = false;
+
   _enabled = doit;
+  _watcher->setEventsEnabled( doit );
 }
 
 bool Folder::onlyOnlineEnabled() const
@@ -201,12 +204,20 @@ void Folder::slotSyncStarted()
 void Folder::slotSyncFinished(const SyncResult &result)
 {
   _lastSyncResult = result;
+  qDebug() << "XX got a sync result: " << _lastSyncResult.result()<< " for folder " << this ;
+
+  bool enabled = ( result.result() == SyncResult::Success );
+  setSyncEnabled( enabled );
 
-  _watcher->setEventsEnabled(true);
   _openAction->setIcon(icon(22));
   // reenable the poll timer
-  qDebug() << "* " << alias() << "Poll timer enabled";
-  _pollTimer->start();
+  if( enabled ) {
+    qDebug() << "* " << alias() << "Poll timer enabled";
+    _pollTimer->start();
+  } else {
+    qDebug() << "* Not enabling poll timer for " << alias();
+    _pollTimer->stop();
+  }
 }
 
 void Folder::setBackend( const QString& b )

+ 15 - 11
src/mirall/folder.h

@@ -126,6 +126,10 @@ public:
      QString backend() const;
 
      QIcon icon( int size ) const;
+
+public slots:
+     void slotSyncFinished(const SyncResult &);
+
 protected:
     /**
      * The minimum amounts of seconds to wait before
@@ -156,19 +160,19 @@ private:
      */
     void evaluateSync(const QStringList &pathList);
 
-    QString _path;
-    QAction *_openAction;
+    QString   _path;
+    QAction  *_openAction;
     // poll timer for remote syncs
-    QTimer *_pollTimer;
-    int _pollInterval;
-    QString _alias;
-    bool _onlyOnlineEnabled;
-    bool _onlyThisLANEnabled;
+    QTimer   *_pollTimer;
+    int       _pollInterval;
+    QString   _alias;
+    bool      _onlyOnlineEnabled;
+    bool      _onlyThisLANEnabled;
     QNetworkConfigurationManager _networkMgr;
-    bool _online;
-    bool _enabled;
+    bool      _online;
+    bool      _enabled;
     SyncResult _lastSyncResult;
-    QString _backend;
+    QString   _backend;
 
 protected slots:
 
@@ -183,7 +187,7 @@ protected slots:
     void slotOpenFolder();
 
     void slotSyncStarted();
-    void slotSyncFinished(const SyncResult &);
+
 };
 
 }

+ 9 - 1
src/mirall/sitecopyfolder.cpp

@@ -70,6 +70,14 @@ void SiteCopyFolder::startSync(const QStringList &pathList)
 {
   QMutexLocker locker(&_syncMutex);
 
+  QFileInfo fi( SITECOPY_BIN );
+  if( ! fi.exists() ) {
+    SyncResult sr( SyncResult::SetupError );
+    sr.setErrorString( tr("Sitecopy is not installed!"));
+    this->slotSyncFinished( sr );
+    return;
+  }
+
   emit syncStarted();
   qDebug() << "PATHLIST: " << pathList;
 
@@ -99,7 +107,7 @@ void SiteCopyFolder::startSiteCopy( const QString& command, SiteCopyState nextSt
       return;
   }
 
-  QString programm = "/usr/bin/sitecopy";
+  const QString programm( SITECOPY_BIN );
   QStringList args;
   args << command << alias();
   qDebug() << "** starting command " << args;

+ 2 - 0
src/mirall/sitecopyfolder.h

@@ -21,6 +21,8 @@
 
 #include "mirall/folder.h"
 
+#define SITECOPY_BIN "/usr/bin/sitecopy"
+
 class QProcess;
 
 namespace Mirall {

+ 4 - 0
src/mirall/statusdialog.cpp

@@ -152,6 +152,7 @@ void StatusDialog::setFolderList( Folder::Map folders )
     SyncResult res = f->lastSyncResult();
     QString resultStr = tr("Undefined");
     QString statusIcon = "view-refresh";
+    qDebug() << "Status: " << res.result();
     if( res.result() == SyncResult::Error ) {
       resultStr = tr("Error");
       statusIcon = "dialog-close";
@@ -161,6 +162,9 @@ void StatusDialog::setFolderList( Folder::Map folders )
     } else if( res.result() == SyncResult::Disabled ) {
       resultStr = tr("Disabled");
       statusIcon = "dialog-cancel";
+    } else if( res.result() == SyncResult::SetupError ) {
+      resultStr = tr( "Setup Error" );
+      statusIcon = "dialog-cancel";
     }
     item->setData( QIcon::fromTheme( statusIcon ), FolderViewDelegate::FolderStatusIcon );
     item->setData( resultStr, FolderViewDelegate::FolderStatus );

+ 1 - 1
src/mirall/statusdialog.h

@@ -47,7 +47,7 @@ class StatusDialog : public QDialog, public Ui::statusDialog
     Q_OBJECT
 public:
     explicit StatusDialog(QWidget *parent = 0);
-    void setFolderList( QHash<QString, Folder*> );
+    void setFolderList( Folder::Map );
     void setOCUrl( const QUrl& );
 
 signals:

+ 2 - 1
src/mirall/syncresult.h

@@ -28,7 +28,8 @@ public:
       Undefined,
       Success,
       Error,
-      Disabled
+      Disabled,
+      SetupError
     };
 
     SyncResult();