mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 05:25:50 +03:00
AccountSettings: disable the add folder button when syncing the entire owncloud #3438
This commit is contained in:
parent
ab23368764
commit
b485e8f97f
4 changed files with 30 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue