diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 89db94023..c071f669a 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 f19331bb3..6c2ab443f 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(index.data(AddButton))) { + if (index.data(AddButton).toBool()) { QSize hint = sizeHint(option, index); QStyleOptionButton opt; static_cast(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 1e63b61bc..a6585f3cf 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 d8f1ece4e..55631db90 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(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; }