Pārlūkot izejas kodu

Error publishing in the status dialog

Klaas Freitag 14 gadi atpakaļ
vecāks
revīzija
4911a528c4

+ 5 - 1
src/mirall/application.cpp

@@ -336,11 +336,15 @@ void Application::slotFolderSyncFinished(const SyncResult &result)
         else {
             _tray->setIcon(QIcon::fromTheme(FOLDER_SYNC_ERROR));
             _tray->showMessage(tr("Folder %1").arg(folder->alias()),
-                               tr("Synchronization did not finish successfully"),
+                               result.errorString(),
+                               /* tr("Synchronization did not finish successfully"), */
                                QSystemTrayIcon::Warning);
         }
 
     }
+    if( _statusDialog->isVisible() ) {
+      _statusDialog->setFolderList( _folderMap );
+    }
 }
 
 

+ 28 - 6
src/mirall/folder.cpp

@@ -37,7 +37,8 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
       _alias(alias),
       _onlyOnlineEnabled(false),
       _onlyThisLANEnabled(false),
-      _online(false)
+      _online(false),
+      _enabled(true)
 {
     _openAction = new QAction(QIcon::fromTheme(FOLDER_ICON), path, this);
     _openAction->setIconVisibleInMenu(true);
@@ -83,6 +84,16 @@ QString Folder::path() const
     return _path;
 }
 
+bool Folder::syncEnabled() const
+{
+  return _enabled;
+}
+
+void Folder::setSyncEnabled( bool doit )
+{
+  _enabled = doit;
+}
+
 bool Folder::onlyOnlineEnabled() const
 {
     return _onlyOnlineEnabled;
@@ -137,8 +148,17 @@ void Folder::incrementErrorCount()
   }
 }
 
+SyncResult Folder::lastSyncResult() const
+{
+  return _lastSyncResult;
+}
+
 void Folder::evaluateSync(const QStringList &pathList)
 {
+  if( !_enabled ) {
+    qDebug() << "*" << alias() << "sync skipped, disabled!";
+    return;
+  }
   if (!_online && onlyOnlineEnabled()) {
     qDebug() << "*" << alias() << "sync skipped, not online";
     return;
@@ -180,11 +200,13 @@ void Folder::slotSyncStarted()
 
 void Folder::slotSyncFinished(const SyncResult &result)
 {
-    _watcher->setEventsEnabled(true);
-    _openAction->setIcon(QIcon::fromTheme(FOLDER_ICON));
-    // reenable the poll timer
-    qDebug() << "* " << alias() << "Poll timer enabled";
-    _pollTimer->start();
+  _lastSyncResult = result;
+
+  _watcher->setEventsEnabled(true);
+  _openAction->setIcon(QIcon::fromTheme(FOLDER_ICON));
+  // reenable the poll timer
+  qDebug() << "* " << alias() << "Poll timer enabled";
+  _pollTimer->start();
 }
 
 } // namespace Mirall

+ 17 - 0
src/mirall/folder.h

@@ -52,6 +52,15 @@ public:
 
     QAction *openAction() const;
 
+    /**
+     * switch sync on or off
+     * If the sync is switched off, the startSync method is not going to
+     * be called.
+     */
+     void setSyncEnabled( bool );
+
+     bool syncEnabled() const;
+
     /**
      * Starts a sync operation
      *
@@ -101,6 +110,11 @@ public:
 
     void incrementErrorCount();
 
+    /**
+     * return the last sync result with error message and status
+     */
+     SyncResult lastSyncResult() const;
+
 protected:
     /**
      * The minimum amounts of seconds to wait before
@@ -141,6 +155,9 @@ private:
     bool _onlyThisLANEnabled;
     QNetworkConfigurationManager _networkMgr;
     bool _online;
+    bool _enabled;
+    SyncResult _lastSyncResult;
+
 protected slots:
 
     void slotOnlineChanged(bool online);

+ 17 - 5
src/mirall/sitecopyfolder.cpp

@@ -67,12 +67,14 @@ QString SiteCopyFolder::siteCopyAlias() const
 
 void SiteCopyFolder::startSync(const QStringList &pathList)
 {
-    QMutexLocker locker(&_syncMutex);
+  QMutexLocker locker(&_syncMutex);
 
-    emit syncStarted();
-    qDebug() << "PATHLIST: " << pathList;
+  emit syncStarted();
+  qDebug() << "PATHLIST: " << pathList;
 
-    startSiteCopy( "--fetch", FlatList );
+  _pathListEmpty = (pathList.count() == 0);
+
+  startSiteCopy( "--fetch", FlatList );
 }
 
 void SiteCopyFolder::fetchFromOC()
@@ -153,7 +155,17 @@ void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
         if( exitCode == 1 ) {
             qDebug() << "Exit-Code: Sync Needed!";
             analyzeStatus();
-            startSiteCopy( "--update", Status );
+            if( _ChangesHash.contains("deleted") && _pathListEmpty ) {
+              // problem: Files were added on the cloud. If we say update,
+              // the new files are going to be deleted. Lets warn the user.
+              qDebug() << "!!!! Better not call update, changes happened on the cloud!";
+              SyncResult res( SyncResult::Disabled );
+              res.setErrorString( tr("The ownCloud changed. Disabling syncing for security reasons."));
+              setSyncEnabled( false );
+              emit syncFinished( res );
+            } else {
+              startSiteCopy( "--update", Status );
+            }
         } else if( exitCode == 0 ) {
             qDebug() << "No update needed, remote is in sync.";
             // No update needed

+ 4 - 3
src/mirall/sitecopyfolder.h

@@ -61,9 +61,10 @@ protected slots:
     void analyzeStatus();
 
 private:
-    QMutex _syncMutex;
-    QProcess *_SiteCopy;
-    int _syncCount;
+    QMutex      _syncMutex;
+    QProcess   *_SiteCopy;
+    int         _syncCount;
+    bool        _pathListEmpty;
 
     QByteArray    _lastOutput;
     QString       _StatusString;

+ 33 - 6
src/mirall/statusdialog.cpp

@@ -53,15 +53,17 @@ void FolderViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
   painter->save();
 
   QFont font = QApplication::font();
-  QFont SubFont = QApplication::font();
+  QFont subFont = QApplication::font();
   //font.setPixelSize(font.weight()+);
   font.setBold(true);
-  SubFont.setWeight(SubFont.weight()-2);
+  subFont.setWeight(subFont.weight()-2);
   QFontMetrics fm(font);
 
   QIcon icon = qvariant_cast<QIcon>(index.data(FolderIconRole));
+  QIcon statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIcon));
   QString aliasText = qvariant_cast<QString>(index.data(FolderNameRole));
   QString pathText = qvariant_cast<QString>(index.data(FolderPathRole));
+  QString statusText = qvariant_cast<QString>(index.data(FolderStatus));
 
   QSize iconsize = icon.actualSize(option.decorationSize);
 
@@ -76,18 +78,25 @@ void FolderViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
   headerRect.setTop(headerRect.top()+5);
   headerRect.setBottom(headerRect.top()+fm.height());
 
-  subheaderRect.setTop(headerRect.bottom()+2);
+  subheaderRect.setTop(headerRect.bottom());
+  QFontMetrics fmSub( subFont );
+  subheaderRect.setBottom(subheaderRect.top()+fmSub.height());
+  QRect statusRect = subheaderRect;
+  statusRect.setTop( subheaderRect.bottom() + 2 );
+  statusRect.setBottom( statusRect.top() + fmSub.height());
 
   //painter->drawPixmap(QPoint(iconRect.right()/2,iconRect.top()/2),icon.pixmap(iconsize.width(),iconsize.height()));
   painter->drawPixmap(QPoint(iconRect.left()+iconsize.width()/2+2,iconRect.top()+iconsize.height()/2+3),icon.pixmap(iconsize.width(),iconsize.height()));
 
+  painter->drawPixmap(QPoint(option.rect.right() - 4 - 48, option.rect.top() + 8 ), statusIcon.pixmap( 48,48));
+
+
   painter->setFont(font);
   painter->drawText(headerRect, aliasText);
 
-
-  painter->setFont(SubFont);
+  painter->setFont(subFont);
   painter->drawText(subheaderRect.left(),subheaderRect.top()+17, pathText);
-
+  painter->drawText(statusRect, tr("Status: %1").arg( statusText ));
   painter->restore();
 
 }
@@ -119,6 +128,24 @@ void StatusDialog::setFolderList( Folder::Map folders )
     item->setData( QIcon::fromTheme( "folder-sync" ), FolderViewDelegate::FolderIconRole );
     item->setData( f->path(),  FolderViewDelegate::FolderPathRole );
     item->setData( f->alias(),  FolderViewDelegate::FolderNameRole );
+
+    SyncResult res = f->lastSyncResult();
+    QString resultStr = tr("Undefined");
+    QString statusIcon = "view-refresh";
+    if( res.result() == SyncResult::Error ) {
+      resultStr = tr("Error");
+      statusIcon = "dialog-close";
+    } else if( res.result() == SyncResult::Success ) {
+      resultStr = tr("Success");
+      statusIcon = "dialog-ok";
+    } else if( res.result() == SyncResult::Disabled ) {
+      resultStr = tr("Disabled");
+      statusIcon = "dialog-cancel";
+    }
+    item->setData( QIcon::fromTheme( statusIcon ), FolderViewDelegate::FolderStatusIcon );
+    item->setData( resultStr, FolderViewDelegate::FolderStatus );
+    item->setData( res.errorString(), FolderViewDelegate::FolderErrorMsg );
+
     _model->appendRow( item );
   }
 }

+ 7 - 3
src/mirall/statusdialog.h

@@ -30,9 +30,13 @@ class FolderViewDelegate : public QStyledItemDelegate
     FolderViewDelegate();
     virtual ~FolderViewDelegate();
 
-    enum datarole { FolderNameRole = Qt::UserRole + 100,
-                    FolderPathRole = Qt::UserRole + 101,
-                    FolderIconRole = Qt::UserRole + 102 };
+    enum datarole { FolderNameRole   = Qt::UserRole + 100,
+                    FolderPathRole   = Qt::UserRole + 101,
+                    FolderIconRole   = Qt::UserRole + 102,
+                    FolderRemotePath = Qt::UserRole + 103,
+                    FolderStatus     = Qt::UserRole + 104,
+                    FolderErrorMsg   = Qt::UserRole + 105,
+                    FolderStatusIcon = Qt::UserRole + 106 };
     void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const;
     QSize sizeHint( const QStyleOptionViewItem&, const QModelIndex& ) const;
 };

+ 6 - 0
src/mirall/syncresult.cpp

@@ -17,6 +17,12 @@
 namespace Mirall
 {
 
+SyncResult::SyncResult()
+: _result( Undefined )
+{
+
+}
+
 SyncResult::SyncResult(SyncResult::Result result)
     : _result(result)
 {

+ 5 - 2
src/mirall/syncresult.h

@@ -25,10 +25,13 @@ class SyncResult
 public:
     enum Result
     {
-        Success,
-        Error
+      Undefined,
+      Success,
+      Error,
+      Disabled
     };
 
+    SyncResult();
     SyncResult(Result result);
     ~SyncResult();
     void setErrorString( const QString& );