From bf0bf2c1b609712b210827f4fee9c813c6c048bc Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Thu, 19 Dec 2019 19:53:48 +0100 Subject: [PATCH] Refactor ActivitySettings: Rename member variable ui to _ui Signed-off-by: Michael Schuster --- src/gui/accountsettings.cpp | 178 ++++++++++++++++++------------------ src/gui/accountsettings.h | 2 +- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 0be7dc534..dfef2d61b 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -109,13 +109,13 @@ protected: AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) : QWidget(parent) - , ui(new Ui::AccountSettings) + , _ui(new Ui::AccountSettings) , _wasDisabledBefore(false) , _accountState(accountState) , _quotaInfo(accountState) , _menuShown(false) { - ui->setupUi(this); + _ui->setupUi(this); _model = new FolderStatusModel; _model->setAccountState(_accountState); @@ -126,37 +126,37 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) // Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching) connect(this, &AccountSettings::styleChanged, delegate, &FolderStatusDelegate::slotStyleChanged); - ui->_folderList->header()->hide(); - ui->_folderList->setItemDelegate(delegate); - ui->_folderList->setModel(_model); + _ui->_folderList->header()->hide(); + _ui->_folderList->setItemDelegate(delegate); + _ui->_folderList->setModel(_model); #if defined(Q_OS_MAC) - ui->_folderList->setMinimumWidth(400); + _ui->_folderList->setMinimumWidth(400); #else ui->_folderList->setMinimumWidth(300); #endif - new ToolTipUpdater(ui->_folderList); + new ToolTipUpdater(_ui->_folderList); auto mouseCursorChanger = new MouseCursorChanger(this); - mouseCursorChanger->folderList = ui->_folderList; + mouseCursorChanger->folderList = _ui->_folderList; mouseCursorChanger->model = _model; - ui->_folderList->setMouseTracking(true); - ui->_folderList->setAttribute(Qt::WA_Hover, true); - ui->_folderList->installEventFilter(mouseCursorChanger); + _ui->_folderList->setMouseTracking(true); + _ui->_folderList->setAttribute(Qt::WA_Hover, true); + _ui->_folderList->installEventFilter(mouseCursorChanger); createAccountToolbox(); connect(AccountManager::instance(), &AccountManager::accountAdded, this, &AccountSettings::slotAccountAdded); connect(this, &AccountSettings::removeAccountFolders, AccountManager::instance(), &AccountManager::removeAccountFolders); - connect(ui->_folderList, &QWidget::customContextMenuRequested, + connect(_ui->_folderList, &QWidget::customContextMenuRequested, this, &AccountSettings::slotCustomContextMenuRequested); - connect(ui->_folderList, &QAbstractItemView::clicked, + connect(_ui->_folderList, &QAbstractItemView::clicked, this, &AccountSettings::slotFolderListClicked); - connect(ui->_folderList, &QTreeView::expanded, this, &AccountSettings::refreshSelectiveSyncStatus); - connect(ui->_folderList, &QTreeView::collapsed, this, &AccountSettings::refreshSelectiveSyncStatus); - connect(ui->selectiveSyncNotification, &QLabel::linkActivated, + connect(_ui->_folderList, &QTreeView::expanded, this, &AccountSettings::refreshSelectiveSyncStatus); + connect(_ui->_folderList, &QTreeView::collapsed, this, &AccountSettings::refreshSelectiveSyncStatus); + connect(_ui->selectiveSyncNotification, &QLabel::linkActivated, this, &AccountSettings::slotLinkActivated); - connect(_model, &FolderStatusModel::suggestExpand, ui->_folderList, &QTreeView::expand); + connect(_model, &FolderStatusModel::suggestExpand, _ui->_folderList, &QTreeView::expand); connect(_model, &FolderStatusModel::dirtyChanged, this, &AccountSettings::refreshSelectiveSyncStatus); refreshSelectiveSyncStatus(); connect(_model, &QAbstractItemModel::rowsInserted, @@ -173,11 +173,11 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) addAction(syncNowWithRemoteDiscovery); - connect(ui->selectiveSyncApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync); - connect(ui->selectiveSyncCancel, &QAbstractButton::clicked, _model, &FolderStatusModel::resetFolders); - connect(ui->bigFolderApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync); - connect(ui->bigFolderSyncAll, &QAbstractButton::clicked, _model, &FolderStatusModel::slotSyncAllPendingBigFolders); - connect(ui->bigFolderSyncNone, &QAbstractButton::clicked, _model, &FolderStatusModel::slotSyncNoPendingBigFolders); + connect(_ui->selectiveSyncApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync); + connect(_ui->selectiveSyncCancel, &QAbstractButton::clicked, _model, &FolderStatusModel::resetFolders); + connect(_ui->bigFolderApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync); + connect(_ui->bigFolderSyncAll, &QAbstractButton::clicked, _model, &FolderStatusModel::slotSyncAllPendingBigFolders); + connect(_ui->bigFolderSyncNone, &QAbstractButton::clicked, _model, &FolderStatusModel::slotSyncNoPendingBigFolders); connect(FolderMan::instance(), &FolderMan::folderListChanged, _model, &FolderStatusModel::resetFolders); connect(this, &AccountSettings::folderChanged, _model, &FolderStatusModel::resetFolders); @@ -185,9 +185,9 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) // quotaProgressBar style now set in customizeStyle() /*QColor color = palette().highlight().color(); - ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name()));*/ + _ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name()));*/ - ui->connectLabel->setText(tr("No account configured.")); + _ui->connectLabel->setText(tr("No account configured.")); connect(_accountState, &AccountState::stateChanged, this, &AccountSettings::slotAccountStateChanged); slotAccountStateChanged(); @@ -204,7 +204,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) { slotNewMnemonicGenerated(); } else { - ui->encryptionMessage->hide(); + _ui->encryptionMessage->hide(); } customizeStyle(); @@ -229,9 +229,9 @@ void AccountSettings::createAccountToolbox() menu->addAction(action); connect(action, &QAction::triggered, this, &AccountSettings::slotDeleteAccount); - ui->_accountToolbox->setText(tr("Account") + QLatin1Char(' ')); - ui->_accountToolbox->setMenu(menu); - ui->_accountToolbox->setPopupMode(QToolButton::InstantPopup); + _ui->_accountToolbox->setText(tr("Account") + QLatin1Char(' ')); + _ui->_accountToolbox->setMenu(menu); + _ui->_accountToolbox->setPopupMode(QToolButton::InstantPopup); slotAccountAdded(_accountState); } @@ -239,14 +239,14 @@ void AccountSettings::createAccountToolbox() void AccountSettings::slotNewMnemonicGenerated() { - ui->encryptionMessage->setText(tr("This account supports end-to-end encryption")); + _ui->encryptionMessage->setText(tr("This account supports end-to-end encryption")); QAction *mnemonic = new QAction(tr("Enable encryption"), this); connect(mnemonic, &QAction::triggered, this, &AccountSettings::requesetMnemonic); - connect(mnemonic, &QAction::triggered, ui->encryptionMessage, &KMessageWidget::hide); + connect(mnemonic, &QAction::triggered, _ui->encryptionMessage, &KMessageWidget::hide); - ui->encryptionMessage->addAction(mnemonic); - ui->encryptionMessage->show(); + _ui->encryptionMessage->addAction(mnemonic); + _ui->encryptionMessage->show(); } void AccountSettings::slotMenuBeforeShow() { @@ -254,7 +254,7 @@ void AccountSettings::slotMenuBeforeShow() { return; } - auto menu = ui->_accountToolbox->menu(); + auto menu = _ui->_accountToolbox->menu(); // We can't check this during the initial creation as there is no account yet then if (_accountState->account()->capabilities().clientSideEncryptionAvaliable()) { @@ -269,7 +269,7 @@ void AccountSettings::slotMenuBeforeShow() { QString AccountSettings::selectedFolderAlias() const { - QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); + QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); if (!selected.isValid()) return ""; return _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString(); @@ -298,7 +298,7 @@ void AccountSettings::slotToggleSignInState() void AccountSettings::doExpand() { - ui->_folderList->expandToDepth(0); + _ui->_folderList->expandToDepth(0); } void AccountSettings::slotShowMnemonic(const QString &mnemonic) { @@ -546,7 +546,7 @@ void AccountSettings::slotEditCurrentIgnoredFiles() void AccountSettings::slotEditCurrentLocalIgnoredFiles() { - QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); + QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); if (!selected.isValid() || _model->classify(selected) != FolderStatusModel::SubFolder) return; QString fileName = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString(); @@ -618,7 +618,7 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) { - QTreeView *tv = ui->_folderList; + QTreeView *tv = _ui->_folderList; QModelIndex index = tv->indexAt(pos); if (!index.isValid()) { return; @@ -649,7 +649,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) ac = menu->addAction(tr("Edit Ignored Files")); connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentIgnoredFiles); - if (!ui->_folderList->isExpanded(index)) { + if (!_ui->_folderList->isExpanded(index)) { ac = menu->addAction(tr("Choose what to sync")); ac->setEnabled(folderConnected); connect(ac, &QAction::triggered, this, &AccountSettings::doExpand); @@ -688,7 +688,7 @@ void AccountSettings::slotFolderListClicked(const QModelIndex &indx) } if (_model->classify(indx) == FolderStatusModel::RootFolder) { // tries to find if we clicked on the '...' button. - QTreeView *tv = ui->_folderList; + QTreeView *tv = _ui->_folderList; auto pos = tv->mapFromGlobal(QCursor::pos()); if (FolderStatusDelegate::optionsButtonRect(tv->visualRect(indx), layoutDirection()).contains(pos)) { slotCustomContextMenuRequested(pos); @@ -701,8 +701,8 @@ void AccountSettings::slotFolderListClicked(const QModelIndex &indx) // Expand root items on single click if (_accountState && _accountState->state() == AccountState::Connected) { - bool expanded = !(ui->_folderList->isExpanded(indx)); - ui->_folderList->setExpanded(indx, expanded); + bool expanded = !(_ui->_folderList->isExpanded(indx)); + _ui->_folderList->setExpanded(indx, expanded); } } } @@ -784,7 +784,7 @@ void AccountSettings::slotRemoveCurrentFolder() { FolderMan *folderMan = FolderMan::instance(); auto folder = folderMan->folder(selectedFolderAlias()); - QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); + QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); if (selected.isValid() && folder) { int row = selected.row(); @@ -826,7 +826,7 @@ void AccountSettings::slotOpenCurrentFolder() void AccountSettings::slotOpenCurrentLocalSubFolder() { - QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); + QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); if (!selected.isValid() || _model->classify(selected) != FolderStatusModel::SubFolder) return; QString fileName = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString(); @@ -842,19 +842,19 @@ void AccountSettings::showConnectionLabel(const QString &message, QStringList er if (errors.isEmpty()) { QString msg = message; Theme::replaceLinkColorStringBackgroundAware(msg); - ui->connectLabel->setText(msg); - ui->connectLabel->setToolTip(QString()); - ui->connectLabel->setStyleSheet(QString()); + _ui->connectLabel->setText(msg); + _ui->connectLabel->setToolTip(QString()); + _ui->connectLabel->setStyleSheet(QString()); } else { errors.prepend(message); QString msg = errors.join(QLatin1String("\n")); qCDebug(lcAccountSettings) << msg; Theme::replaceLinkColorString(msg, QColor("#c1c8e6")); - ui->connectLabel->setText(msg); - ui->connectLabel->setToolTip(QString()); - ui->connectLabel->setStyleSheet(errStyle); + _ui->connectLabel->setText(msg); + _ui->connectLabel->setToolTip(QString()); + _ui->connectLabel->setStyleSheet(errStyle); } - ui->accountStatus->setVisible(!message.isEmpty()); + _ui->accountStatus->setVisible(!message.isEmpty()); } void AccountSettings::slotEnableCurrentFolder() @@ -952,29 +952,29 @@ void AccountSettings::slotOpenOC() void AccountSettings::slotUpdateQuota(qint64 total, qint64 used) { if (total > 0) { - ui->quotaProgressBar->setVisible(true); - ui->quotaProgressBar->setEnabled(true); + _ui->quotaProgressBar->setVisible(true); + _ui->quotaProgressBar->setEnabled(true); // workaround the label only accepting ints (which may be only 32 bit wide) const double percent = used / (double)total * 100; const int percentInt = qMin(qRound(percent), 100); - ui->quotaProgressBar->setValue(percentInt); + _ui->quotaProgressBar->setValue(percentInt); QString usedStr = Utility::octetsToString(used); QString totalStr = Utility::octetsToString(total); QString percentStr = Utility::compactFormatDouble(percent, 1); QString toolTip = tr("%1 (%3%) of %2 in use. Some folders, including network mounted or shared folders, might have different limits.").arg(usedStr, totalStr, percentStr); - ui->quotaInfoLabel->setText(tr("%1 of %2 in use").arg(usedStr, totalStr)); - ui->quotaInfoLabel->setToolTip(toolTip); - ui->quotaProgressBar->setToolTip(toolTip); + _ui->quotaInfoLabel->setText(tr("%1 of %2 in use").arg(usedStr, totalStr)); + _ui->quotaInfoLabel->setToolTip(toolTip); + _ui->quotaProgressBar->setToolTip(toolTip); } else { - ui->quotaProgressBar->setVisible(false); - ui->quotaInfoLabel->setToolTip(QString()); + _ui->quotaProgressBar->setVisible(false); + _ui->quotaInfoLabel->setToolTip(QString()); /* -1 means not computed; -2 means unknown; -3 means unlimited (#3940)*/ if (total == 0 || total == -1) { - ui->quotaInfoLabel->setText(tr("Currently there is no storage usage information available.")); + _ui->quotaInfoLabel->setText(tr("Currently there is no storage usage information available.")); } else { QString usedStr = Utility::octetsToString(used); - ui->quotaInfoLabel->setText(tr("%1 in use").arg(usedStr)); + _ui->quotaInfoLabel->setText(tr("%1 in use").arg(usedStr)); } } } @@ -983,7 +983,7 @@ void AccountSettings::slotAccountStateChanged() { int state = _accountState ? _accountState->state() : AccountState::Disconnected; if (_accountState) { - ui->sslButton->updateAccountState(_accountState); + _ui->sslButton->updateAccountState(_accountState); AccountPtr account = _accountState->account(); QUrl safeUrl(account->url()); safeUrl.setPassword(QString()); // Remove the password from the URL to avoid showing it in the UI @@ -1042,14 +1042,14 @@ void AccountSettings::slotAccountStateChanged() } /* Allow to expand the item if the account is connected. */ - ui->_folderList->setItemsExpandable(state == AccountState::Connected); + _ui->_folderList->setItemsExpandable(state == AccountState::Connected); if (state != AccountState::Connected) { /* check if there are expanded root items, if so, close them */ int i; for (i = 0; i < _model->rowCount(); ++i) { - if (ui->_folderList->isExpanded(_model->index(i))) - ui->_folderList->setExpanded(_model->index(i), false); + if (_ui->_folderList->isExpanded(_model->index(i))) + _ui->_folderList->setExpanded(_model->index(i), false); } } else if (_model->isDirty()) { // If we connect and have pending changes, show the list. @@ -1093,21 +1093,21 @@ void AccountSettings::slotLinkActivated(const QString &link) // Make sure the folder itself is expanded Folder *f = FolderMan::instance()->folder(alias); QModelIndex folderIndx = _model->indexForPath(f, QString()); - if (!ui->_folderList->isExpanded(folderIndx)) { - ui->_folderList->setExpanded(folderIndx, true); + if (!_ui->_folderList->isExpanded(folderIndx)) { + _ui->_folderList->setExpanded(folderIndx, true); } QModelIndex indx = _model->indexForPath(f, myFolder); if (indx.isValid()) { // make sure all the parents are expanded for (auto i = indx.parent(); i.isValid(); i = i.parent()) { - if (!ui->_folderList->isExpanded(i)) { - ui->_folderList->setExpanded(i, true); + if (!_ui->_folderList->isExpanded(i)) { + _ui->_folderList->setExpanded(i, true); } } - ui->_folderList->setSelectionMode(QAbstractItemView::SingleSelection); - ui->_folderList->setCurrentIndex(indx); - ui->_folderList->scrollTo(indx); + _ui->_folderList->setSelectionMode(QAbstractItemView::SingleSelection); + _ui->_folderList->setCurrentIndex(indx); + _ui->_folderList->scrollTo(indx); } else { qCWarning(lcAccountSettings) << "Unable to find a valid index for " << myFolder; } @@ -1116,7 +1116,7 @@ void AccountSettings::slotLinkActivated(const QString &link) AccountSettings::~AccountSettings() { - delete ui; + delete _ui; } void AccountSettings::refreshSelectiveSyncStatus() @@ -1154,8 +1154,8 @@ void AccountSettings::refreshSelectiveSyncStatus() } if (msg.isEmpty()) { - ui->selectiveSyncButtons->setVisible(true); - ui->bigFolderUi->setVisible(false); + _ui->selectiveSyncButtons->setVisible(true); + _ui->bigFolderUi->setVisible(false); } else { ConfigFile cfg; QString info = !cfg.confirmExternalStorage() @@ -1164,27 +1164,27 @@ void AccountSettings::refreshSelectiveSyncStatus() ? tr("There are folders that were not synchronized because they are external storages: ") : tr("There are folders that were not synchronized because they are too big or external storages: "); - ui->selectiveSyncNotification->setText(info + msg); - ui->selectiveSyncButtons->setVisible(false); - ui->bigFolderUi->setVisible(true); + _ui->selectiveSyncNotification->setText(info + msg); + _ui->selectiveSyncButtons->setVisible(false); + _ui->bigFolderUi->setVisible(true); shouldBeVisible = true; } - ui->selectiveSyncApply->setEnabled(_model->isDirty() || !msg.isEmpty()); - bool wasVisible = !ui->selectiveSyncStatus->isHidden(); + _ui->selectiveSyncApply->setEnabled(_model->isDirty() || !msg.isEmpty()); + bool wasVisible = !_ui->selectiveSyncStatus->isHidden(); if (wasVisible != shouldBeVisible) { - QSize hint = ui->selectiveSyncStatus->sizeHint(); + QSize hint = _ui->selectiveSyncStatus->sizeHint(); if (shouldBeVisible) { - ui->selectiveSyncStatus->setMaximumHeight(0); - ui->selectiveSyncStatus->setVisible(true); + _ui->selectiveSyncStatus->setMaximumHeight(0); + _ui->selectiveSyncStatus->setVisible(true); } - auto anim = new QPropertyAnimation(ui->selectiveSyncStatus, "maximumHeight", ui->selectiveSyncStatus); + auto anim = new QPropertyAnimation(_ui->selectiveSyncStatus, "maximumHeight", _ui->selectiveSyncStatus); anim->setEndValue(shouldBeVisible ? hint.height() : 0); anim->start(QAbstractAnimation::DeleteWhenStopped); connect(anim, &QPropertyAnimation::finished, [this, shouldBeVisible]() { - ui->selectiveSyncStatus->setMaximumHeight(QWIDGETSIZE_MAX); + _ui->selectiveSyncStatus->setMaximumHeight(QWIDGETSIZE_MAX); if (!shouldBeVisible) { - ui->selectiveSyncStatus->hide(); + _ui->selectiveSyncStatus->hide(); } }); } @@ -1244,7 +1244,7 @@ bool AccountSettings::event(QEvent *e) // Expand the folder automatically only if there's only one, see #4283 // The 2 is 1 folder + 1 'add folder' button if (_model->rowCount() <= 2) { - ui->_folderList->setExpanded(_model->index(0, 0), true); + _ui->_folderList->setExpanded(_model->index(0, 0), true); } } return QWidget::event(e); @@ -1260,12 +1260,12 @@ void AccountSettings::slotStyleChanged() void AccountSettings::customizeStyle() { - QString msg = ui->connectLabel->text(); + QString msg = _ui->connectLabel->text(); Theme::replaceLinkColorStringBackgroundAware(msg); - ui->connectLabel->setText(msg); + _ui->connectLabel->setText(msg); QColor color = palette().highlight().color(); - ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name())); + _ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name())); } } // namespace OCC diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index 545b3cac8..886ebed23 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -136,7 +136,7 @@ private: /// Returns the alias of the selected folder, empty string if none QString selectedFolderAlias() const; - Ui::AccountSettings *ui; + Ui::AccountSettings *_ui; FolderStatusModel *_model; QUrl _OCUrl;