[Pkg-owncloud-commits] [owncloud-client] 301/498: AccountSettings: disable the add folder button when syncing the entire owncloud #3438

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:49:00 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit b485e8f97fb37c2f0cb7012b8146948d45602ec7
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Tue Jul 14 11:03:25 2015 +0200

    AccountSettings: disable the add folder button when syncing the entire owncloud #3438
---
 src/gui/accountsettings.cpp      |  3 ++-
 src/gui/folderstatusdelegate.cpp |  7 +++----
 src/gui/folderstatusdelegate.h   |  2 +-
 src/gui/folderstatusmodel.cpp    | 33 ++++++++++++++++++++++++---------
 4 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index 89db940..c071f66 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -161,7 +161,8 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
 
 void AccountSettings::slotFolderActivated( const QModelIndex& indx )
 {
-    if (indx.data(FolderStatusDelegate::AddButton).toBool()) {
+    if (indx.data(FolderStatusDelegate::AddButton).toBool()
+            && indx.flags() & Qt::ItemIsEnabled) {
         slotAddFolder();
         return;
     }
diff --git a/src/gui/folderstatusdelegate.cpp b/src/gui/folderstatusdelegate.cpp
index f19331b..6c2ab44 100644
--- a/src/gui/folderstatusdelegate.cpp
+++ b/src/gui/folderstatusdelegate.cpp
@@ -93,12 +93,12 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
 {
     QStyledItemDelegate::paint(painter,option,index);
 
-    if (qvariant_cast<bool>(index.data(AddButton))) {
+    if (index.data(AddButton).toBool()) {
         QSize hint = sizeHint(option, index);
         QStyleOptionButton opt;
         static_cast<QStyleOption&>(opt) = option;
-        // only keep the flags interesting for the button:
-        opt.state = QStyle::State_Enabled;
+        opt.state &= ~QStyle::State_Selected;
+        opt.state |= QStyle::State_Raised;
         opt.text = addFolderText();
         opt.rect.setWidth(qMin(opt.rect.width(), hint.width()));
         QApplication::style()->drawControl(QStyle::CE_PushButton, &opt, painter
@@ -330,7 +330,6 @@ bool FolderStatusDelegate::editorEvent ( QEvent * event, QAbstractItemModel * mo
                                          const QStyleOptionViewItem & option, const QModelIndex & index )
 {
     return QStyledItemDelegate::editorEvent(event, model, option, index);
-    return false;
 }
 
 } // namespace OCC
diff --git a/src/gui/folderstatusdelegate.h b/src/gui/folderstatusdelegate.h
index 1e63b61..a6585f3 100644
--- a/src/gui/folderstatusdelegate.h
+++ b/src/gui/folderstatusdelegate.h
@@ -44,7 +44,7 @@ public:
                     WarningCount,
                     SyncRunning,
 
-                    AddButton
+                    AddButton // 1 = enabled; 2 = disabled
                   };
     void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const Q_DECL_OVERRIDE;
     QSize sizeHint( const QStyleOptionViewItem&, const QModelIndex& ) const Q_DECL_OVERRIDE;
diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp
index d8f1ece..55631db 100644
--- a/src/gui/folderstatusmodel.cpp
+++ b/src/gui/folderstatusmodel.cpp
@@ -69,8 +69,15 @@ void FolderStatusModel::setAccountState(const AccountState* accountState)
 Qt::ItemFlags FolderStatusModel::flags ( const QModelIndex &index  ) const
 {
     switch (classify(index)) {
-        case AddButton:
-            return Qt::ItemIsEnabled;
+        case AddButton: {
+            if (_folders.count() == 1 && _folders.at(0)._folder->remotePath() == QLatin1String("/")) {
+                // special case when syncing the entire owncloud: disable the add folder button (#3438)
+                return Qt::ItemNeverHasChildren;
+            } else if (!_accountState->isConnected()) {
+                return Qt::ItemNeverHasChildren;
+            }
+            return Qt::ItemIsEnabled | Qt::ItemNeverHasChildren;
+        }
         case RootFolder:
             return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
         case SubFolder:
@@ -88,10 +95,23 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
         return QVariant();
 
     switch(classify(index)) {
-    case AddButton:
-        if (role == FolderStatusDelegate::AddButton)
+    case AddButton: {
+        if (role == FolderStatusDelegate::AddButton) {
             return QVariant(true);
+        } else if (role == Qt::ToolTipRole) {
+            if (!_accountState->isConnected()) {
+                return tr("You need to be connected to add a folder");
+            } else if (_folders.count() == 1
+                        && _folders.at(0)._folder->remotePath() == QLatin1String("/")) {
+                // Syncing the entire owncloud: disable the add folder button (#3438)
+                return tr("Adding folder is disabled because your are already syncing all your files. "
+                          "If you want to sync multiple folders, please remove the currently "
+                          "configured root folder.");
+            }
+            return tr("Click this button to add a folder to synchronize.");
+        }
         return QVariant();
+    }
     case SubFolder:
     {
         const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs[index.row()];
@@ -244,11 +264,6 @@ int FolderStatusModel::columnCount(const QModelIndex&) const
 int FolderStatusModel::rowCount(const QModelIndex& parent) const
 {
     if (!parent.isValid()) {
-        if (_folders.count() == 1 && _folders.at(0)._folder->remotePath() == QLatin1String("/")) {
-            // special case when syncing the entire owncloud: hide the add folder button (#3438)
-            return 1;
-        }
-
         return _folders.count() + 1;
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list