2013-07-04 21:59:40 +04:00
/*
* Copyright ( C ) by Daniel Molkentin < danimo @ owncloud . com >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2016-10-25 12:00:07 +03:00
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
2013-07-04 21:59:40 +04:00
*
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License
* for more details .
*/
# include "accountsettings.h"
# include "ui_accountsettings.h"
2014-07-11 02:31:24 +04:00
# include "theme.h"
# include "folderman.h"
# include "folderwizard.h"
# include "folderstatusmodel.h"
2015-06-15 15:16:21 +03:00
# include "folderstatusdelegate.h"
2017-08-16 09:36:52 +03:00
# include "common/utility.h"
2014-07-11 02:31:24 +04:00
# include "application.h"
2014-11-10 01:25:57 +03:00
# include "configfile.h"
2014-07-11 02:31:24 +04:00
# include "account.h"
2014-12-17 16:09:57 +03:00
# include "accountstate.h"
2014-07-11 02:31:24 +04:00
# include "quotainfo.h"
2015-05-12 16:16:32 +03:00
# include "accountmanager.h"
2015-08-07 14:14:33 +03:00
# include "owncloudsetupwizard.h"
2013-11-11 19:56:52 +04:00
# include "creds/abstractcredentials.h"
2017-07-13 12:27:02 +03:00
# include "creds/httpcredentialsgui.h"
2016-01-21 13:32:27 +03:00
# include "tooltipupdater.h"
2016-11-23 13:05:41 +03:00
# include "filesystem.h"
2017-12-12 21:36:47 +03:00
# include "clientsideencryptionjobs.h"
2018-05-12 00:22:33 +03:00
# include "syncresult.h"
2019-08-15 00:27:17 +03:00
# include "ignorelisttablewidget.h"
2013-07-04 21:59:40 +04:00
2013-07-10 11:20:25 +04:00
# include <math.h>
2013-07-04 21:59:40 +04:00
# include <QDesktopServices>
2019-08-15 00:27:17 +03:00
# include <QDialogButtonBox>
2016-03-17 14:26:44 +03:00
# include <QDir>
2013-07-04 21:59:40 +04:00
# include <QListWidgetItem>
# include <QMessageBox>
2013-08-15 19:00:01 +04:00
# include <QAction>
2015-03-27 13:46:03 +03:00
# include <QVBoxLayout>
# include <QTreeView>
2013-08-15 19:00:01 +04:00
# include <QKeySequence>
2013-10-11 19:51:55 +04:00
# include <QIcon>
# include <QVariant>
2017-08-25 16:00:30 +03:00
# include <QJsonDocument>
2015-10-14 12:34:30 +03:00
# include <QToolTip>
2015-03-27 13:46:03 +03:00
# include <qstringlistmodel.h>
# include <qpropertyanimation.h>
2013-07-04 21:59:40 +04:00
2014-07-11 02:31:24 +04:00
# include "account.h"
2013-11-04 19:36:23 +04:00
2014-11-10 00:34:07 +03:00
namespace OCC {
2013-07-04 21:59:40 +04:00
2017-12-28 22:33:10 +03:00
Q_LOGGING_CATEGORY ( lcAccountSettings , " nextcloud.gui.account.settings " , QtInfoMsg )
2017-05-09 15:24:11 +03:00
2013-08-18 19:00:37 +04:00
static const char progressBarStyleC [ ] =
" QProgressBar { "
2013-08-21 13:34:20 +04:00
" border: 1px solid grey; "
2013-08-18 19:00:37 +04:00
" border-radius: 5px; "
" text-align: center; "
" } "
" QProgressBar::chunk { "
" background-color: %1; width: 1px; "
" } " ;
2017-05-17 11:55:42 +03:00
2017-07-04 15:08:41 +03:00
/**
* Adjusts the mouse cursor based on the region it is on over the folder tree view .
*
* Used to show that one can click the red error list box by changing the cursor
* to the pointing hand .
*/
class MouseCursorChanger : public QObject
{
Q_OBJECT
public :
MouseCursorChanger ( QObject * parent )
: QObject ( parent )
{
}
QTreeView * folderList ;
FolderStatusModel * model ;
protected :
bool eventFilter ( QObject * watched , QEvent * event ) override
{
if ( event - > type ( ) = = QEvent : : HoverMove ) {
Qt : : CursorShape shape = Qt : : ArrowCursor ;
auto pos = folderList - > mapFromGlobal ( QCursor : : pos ( ) ) ;
auto index = folderList - > indexAt ( pos ) ;
if ( model - > classify ( index ) = = FolderStatusModel : : RootFolder
& & ( FolderStatusDelegate : : errorsListRect ( folderList - > visualRect ( index ) ) . contains ( pos )
| | FolderStatusDelegate : : optionsButtonRect ( folderList - > visualRect ( index ) , folderList - > layoutDirection ( ) ) . contains ( pos ) ) ) {
shape = Qt : : PointingHandCursor ;
}
folderList - > setCursor ( shape ) ;
}
return QObject : : eventFilter ( watched , event ) ;
}
} ;
2015-04-17 18:56:17 +03:00
AccountSettings : : AccountSettings ( AccountState * accountState , QWidget * parent )
2013-07-04 21:59:40 +04:00
: QWidget ( parent )
2013-10-11 19:51:55 +04:00
, ui ( new Ui : : AccountSettings )
2013-11-04 19:36:23 +04:00
, _wasDisabledBefore ( false )
2015-06-26 16:40:34 +03:00
, _accountState ( accountState )
, _quotaInfo ( accountState )
2018-06-21 18:20:09 +03:00
, _menuShown ( false )
2013-07-04 21:59:40 +04:00
{
ui - > setupUi ( this ) ;
_model = new FolderStatusModel ;
2015-07-03 16:03:18 +03:00
_model - > setAccountState ( _accountState ) ;
2013-08-05 18:48:54 +04:00
_model - > setParent ( this ) ;
2013-07-04 21:59:40 +04:00
FolderStatusDelegate * delegate = new FolderStatusDelegate ;
2013-08-16 22:18:35 +04:00
delegate - > setParent ( this ) ;
2013-07-04 21:59:40 +04:00
2019-12-19 21:50:21 +03:00
// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
connect ( this , & AccountSettings : : styleChanged , delegate , & FolderStatusDelegate : : slotStyleChanged ) ;
2015-03-27 13:46:03 +03:00
ui - > _folderList - > header ( ) - > hide ( ) ;
2013-07-04 21:59:40 +04:00
ui - > _folderList - > setItemDelegate ( delegate ) ;
ui - > _folderList - > setModel ( _model ) ;
2014-02-14 06:02:59 +04:00
# if defined(Q_OS_MAC)
ui - > _folderList - > setMinimumWidth ( 400 ) ;
# else
2013-07-04 21:59:40 +04:00
ui - > _folderList - > setMinimumWidth ( 300 ) ;
2014-02-14 06:02:59 +04:00
# endif
2016-01-21 13:32:27 +03:00
new ToolTipUpdater ( ui - > _folderList ) ;
2017-07-04 15:08:41 +03:00
auto mouseCursorChanger = new MouseCursorChanger ( this ) ;
mouseCursorChanger - > folderList = ui - > _folderList ;
mouseCursorChanger - > model = _model ;
ui - > _folderList - > setMouseTracking ( true ) ;
ui - > _folderList - > setAttribute ( Qt : : WA_Hover , true ) ;
ui - > _folderList - > installEventFilter ( mouseCursorChanger ) ;
2015-11-13 16:50:07 +03:00
createAccountToolbox ( ) ;
2017-09-20 11:14:48 +03:00
connect ( AccountManager : : instance ( ) , & AccountManager : : accountAdded ,
this , & AccountSettings : : slotAccountAdded ) ;
2019-07-24 14:56:21 +03:00
connect ( this , & AccountSettings : : removeAccountFolders ,
AccountManager : : instance ( ) , & AccountManager : : removeAccountFolders ) ;
2017-09-20 11:14:48 +03:00
connect ( ui - > _folderList , & QWidget : : customContextMenuRequested ,
this , & AccountSettings : : slotCustomContextMenuRequested ) ;
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 ,
this , & AccountSettings : : slotLinkActivated ) ;
connect ( _model , & FolderStatusModel : : suggestExpand , ui - > _folderList , & QTreeView : : expand ) ;
connect ( _model , & FolderStatusModel : : dirtyChanged , this , & AccountSettings : : refreshSelectiveSyncStatus ) ;
2015-06-12 12:28:56 +03:00
refreshSelectiveSyncStatus ( ) ;
2017-09-20 11:14:48 +03:00
connect ( _model , & QAbstractItemModel : : rowsInserted ,
this , & AccountSettings : : refreshSelectiveSyncStatus ) ;
2013-07-04 21:59:40 +04:00
2013-10-30 19:58:08 +04:00
QAction * syncNowAction = new QAction ( this ) ;
syncNowAction - > setShortcut ( QKeySequence ( Qt : : Key_F6 ) ) ;
2017-09-20 11:14:48 +03:00
connect ( syncNowAction , & QAction : : triggered , this , & AccountSettings : : slotScheduleCurrentFolder ) ;
2013-10-30 19:58:08 +04:00
addAction ( syncNowAction ) ;
2017-04-12 16:25:26 +03:00
QAction * syncNowWithRemoteDiscovery = new QAction ( this ) ;
syncNowWithRemoteDiscovery - > setShortcut ( QKeySequence ( Qt : : CTRL + Qt : : Key_F6 ) ) ;
2017-09-20 11:14:48 +03:00
connect ( syncNowWithRemoteDiscovery , & QAction : : triggered , this , & AccountSettings : : slotScheduleCurrentFolderForceRemoteDiscovery ) ;
2017-04-12 16:25:26 +03:00
addAction ( syncNowWithRemoteDiscovery ) ;
2017-04-26 21:03:55 +03:00
2017-09-20 11:14:48 +03:00
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 ) ;
2016-09-23 14:47:57 +03:00
2017-09-20 11:14:48 +03:00
connect ( FolderMan : : instance ( ) , & FolderMan : : folderListChanged , _model , & FolderStatusModel : : resetFolders ) ;
connect ( this , & AccountSettings : : folderChanged , _model , & FolderStatusModel : : resetFolders ) ;
2015-03-27 13:46:03 +03:00
2019-12-19 21:50:21 +03:00
// quotaProgressBar style now set in customizeStyle()
/*QColor color = palette().highlight().color();
ui - > quotaProgressBar - > setStyleSheet ( QString : : fromLatin1 ( progressBarStyleC ) . arg ( color . name ( ) ) ) ; */
2015-08-14 11:07:28 +03:00
2013-11-11 17:02:54 +04:00
ui - > connectLabel - > setText ( tr ( " No account configured. " ) ) ;
2014-03-26 20:41:04 +04:00
2017-07-13 12:27:02 +03:00
connect ( _accountState , & AccountState : : stateChanged , this , & AccountSettings : : slotAccountStateChanged ) ;
slotAccountStateChanged ( ) ;
2015-04-17 18:56:17 +03:00
2017-09-20 11:14:48 +03:00
connect ( & _quotaInfo , & QuotaInfo : : quotaUpdated ,
this , & AccountSettings : : slotUpdateQuota ) ;
2018-06-21 18:20:09 +03:00
// Connect E2E stuff
connect ( this , & AccountSettings : : requesetMnemonic , _accountState - > account ( ) - > e2e ( ) , & ClientSideEncryption : : slotRequestMnemonic ) ;
connect ( _accountState - > account ( ) - > e2e ( ) , & ClientSideEncryption : : showMnemonic , this , & AccountSettings : : slotShowMnemonic ) ;
2019-05-08 20:56:00 +03:00
connect ( _accountState - > account ( ) - > e2e ( ) , & ClientSideEncryption : : mnemonicGenerated , this , & AccountSettings : : slotNewMnemonicGenerated ) ;
if ( _accountState - > account ( ) - > e2e ( ) - > newMnemonicGenerated ( ) )
{
slotNewMnemonicGenerated ( ) ;
} else {
ui - > encryptionMessage - > hide ( ) ;
}
2019-12-09 22:47:42 +03:00
customizeStyle ( ) ;
2015-11-13 16:50:07 +03:00
}
void AccountSettings : : createAccountToolbox ( )
{
QMenu * menu = new QMenu ( ) ;
2018-06-21 18:20:09 +03:00
connect ( menu , & QMenu : : aboutToShow , this , & AccountSettings : : slotMenuBeforeShow ) ;
2015-11-16 17:50:32 +03:00
_addAccountAction = new QAction ( tr ( " Add new " ) , this ) ;
menu - > addAction ( _addAccountAction ) ;
2017-09-20 11:14:48 +03:00
connect ( _addAccountAction , & QAction : : triggered , this , & AccountSettings : : slotOpenAccountWizard ) ;
2015-11-16 17:50:32 +03:00
2015-12-08 14:05:14 +03:00
_toggleSignInOutAction = new QAction ( tr ( " Log out " ) , this ) ;
2017-09-20 11:14:48 +03:00
connect ( _toggleSignInOutAction , & QAction : : triggered , this , & AccountSettings : : slotToggleSignInState ) ;
2015-11-13 16:50:07 +03:00
menu - > addAction ( _toggleSignInOutAction ) ;
2015-11-16 17:50:32 +03:00
QAction * action = new QAction ( tr ( " Remove " ) , this ) ;
2015-11-13 16:50:07 +03:00
menu - > addAction ( action ) ;
2017-09-20 11:14:48 +03:00
connect ( action , & QAction : : triggered , this , & AccountSettings : : slotDeleteAccount ) ;
2015-11-13 16:50:07 +03:00
2015-11-16 17:50:32 +03:00
ui - > _accountToolbox - > setText ( tr ( " Account " ) + QLatin1Char ( ' ' ) ) ;
2015-11-13 16:50:07 +03:00
ui - > _accountToolbox - > setMenu ( menu ) ;
ui - > _accountToolbox - > setPopupMode ( QToolButton : : InstantPopup ) ;
2015-12-02 18:33:24 +03:00
slotAccountAdded ( _accountState ) ;
2015-11-13 16:50:07 +03:00
}
2019-05-08 20:56:00 +03:00
void AccountSettings : : slotNewMnemonicGenerated ( )
{
2019-05-11 20:19:17 +03:00
ui - > encryptionMessage - > setText ( tr ( " This account supports end-to-end encryption " ) ) ;
2019-05-08 20:56:00 +03:00
2019-05-18 23:58:41 +03:00
QAction * mnemonic = new QAction ( tr ( " Enable encryption " ) , this ) ;
2019-05-08 20:56:00 +03:00
connect ( mnemonic , & QAction : : triggered , this , & AccountSettings : : requesetMnemonic ) ;
connect ( mnemonic , & QAction : : triggered , ui - > encryptionMessage , & KMessageWidget : : hide ) ;
ui - > encryptionMessage - > addAction ( mnemonic ) ;
ui - > encryptionMessage - > show ( ) ;
}
2018-06-21 18:20:09 +03:00
void AccountSettings : : slotMenuBeforeShow ( ) {
if ( _menuShown ) {
return ;
}
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 ( ) ) {
QAction * mnemonic = new QAction ( tr ( " Show E2E mnemonic " ) , this ) ;
connect ( mnemonic , & QAction : : triggered , this , & AccountSettings : : requesetMnemonic ) ;
menu - > addAction ( mnemonic ) ;
}
_menuShown = true ;
}
2017-04-12 16:24:54 +03:00
QString AccountSettings : : selectedFolderAlias ( ) const
{
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! selected . isValid ( ) )
return " " ;
return _model - > data ( selected , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
}
2015-11-13 16:50:07 +03:00
void AccountSettings : : slotOpenAccountWizard ( )
{
2017-09-13 07:26:56 +03:00
// We can't call isSystemTrayAvailable with appmenu-qt5 because it breaks the systemtray
// (issue #4693, #4944)
if ( qgetenv ( " QT_QPA_PLATFORMTHEME " ) = = " appmenu-qt5 " | | QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
2015-11-13 16:50:07 +03:00
topLevelWidget ( ) - > close ( ) ;
}
2015-12-02 19:59:02 +03:00
2018-11-11 12:56:22 +03:00
OwncloudSetupWizard : : runWizard ( qApp , SLOT ( slotownCloudWizardDone ( int ) ) , nullptr ) ;
2015-11-13 16:50:07 +03:00
}
void AccountSettings : : slotToggleSignInState ( )
{
2015-12-09 13:06:28 +03:00
if ( _accountState - > isSignedOut ( ) ) {
2017-06-13 14:49:26 +03:00
_accountState - > account ( ) - > resetRejectedCertificates ( ) ;
2015-12-09 13:06:28 +03:00
_accountState - > signIn ( ) ;
} else {
_accountState - > signOutByUi ( ) ;
2015-12-02 18:31:58 +03:00
}
2015-03-27 13:46:03 +03:00
}
2014-03-26 20:41:04 +04:00
2015-09-16 04:07:04 +03:00
void AccountSettings : : doExpand ( )
{
2015-09-16 18:06:32 +03:00
ui - > _folderList - > expandToDepth ( 0 ) ;
2015-09-16 04:07:04 +03:00
}
2018-06-21 18:20:09 +03:00
void AccountSettings : : slotShowMnemonic ( const QString & mnemonic ) {
2018-06-21 20:57:51 +03:00
AccountManager : : instance ( ) - > displayMnemonic ( mnemonic ) ;
2018-06-21 18:20:09 +03:00
}
2017-11-03 14:00:25 +03:00
void AccountSettings : : slotEncryptionFlagSuccess ( const QByteArray & fileId )
2017-10-31 13:09:34 +03:00
{
2017-12-15 16:00:42 +03:00
if ( auto info = _model - > infoForFileId ( fileId ) ) {
accountsState ( ) - > account ( ) - > e2e ( ) - > setFolderEncryptedStatus ( info - > _path , true ) ;
} else {
qCInfo ( lcAccountSettings ( ) ) < < " Could not get information from the current folder. " ;
}
2017-11-03 14:00:25 +03:00
auto lockJob = new LockEncryptFolderApiJob ( accountsState ( ) - > account ( ) , fileId ) ;
2017-11-03 14:34:30 +03:00
connect ( lockJob , & LockEncryptFolderApiJob : : success ,
2017-12-16 01:32:41 +03:00
this , & AccountSettings : : slotLockForEncryptionSuccess ) ;
2017-11-03 14:34:30 +03:00
connect ( lockJob , & LockEncryptFolderApiJob : : error ,
2017-12-16 01:32:41 +03:00
this , & AccountSettings : : slotLockForEncryptionError ) ;
2017-11-03 14:00:25 +03:00
lockJob - > start ( ) ;
}
void AccountSettings : : slotEncryptionFlagError ( const QByteArray & fileId , int httpErrorCode )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
Q_UNUSED ( httpErrorCode ) ;
2017-11-03 14:00:25 +03:00
qDebug ( ) < < " Error on the encryption flag " ;
}
2017-12-16 01:32:41 +03:00
void AccountSettings : : slotLockForEncryptionSuccess ( const QByteArray & fileId , const QByteArray & token )
2017-11-03 14:00:25 +03:00
{
2019-07-24 14:56:21 +03:00
accountsState ( ) - > account ( ) - > e2e ( ) - > setTokenForFolder ( fileId , token ) ;
2017-11-13 18:46:30 +03:00
2019-07-24 14:56:21 +03:00
FolderMetadata emptyMetadata ( accountsState ( ) - > account ( ) ) ;
2018-03-25 23:31:49 +03:00
auto encryptedMetadata = emptyMetadata . encryptedMetadata ( ) ;
if ( encryptedMetadata . isEmpty ( ) ) {
//TODO: Mark the folder as unencrypted as the metadata generation failed.
QMessageBox : : warning ( nullptr , " Warning " ,
" Could not generate the metadata for encryption, Unlocking the folder. \n "
" This can be an issue with your OpenSSL libraries, please note that OpenSSL 1.1 is \n "
" not compatible with Nextcloud yet. "
) ;
return ;
}
auto storeMetadataJob = new StoreMetaDataApiJob ( accountsState ( ) - > account ( ) , fileId , emptyMetadata . encryptedMetadata ( ) ) ;
2019-07-24 14:56:21 +03:00
connect ( storeMetadataJob , & StoreMetaDataApiJob : : success ,
this , & AccountSettings : : slotUploadMetadataSuccess ) ;
connect ( storeMetadataJob , & StoreMetaDataApiJob : : error ,
this , & AccountSettings : : slotUpdateMetadataError ) ;
2017-11-13 19:54:19 +03:00
2019-07-24 14:56:21 +03:00
storeMetadataJob - > start ( ) ;
2017-11-03 14:00:25 +03:00
}
2017-11-13 18:46:30 +03:00
void AccountSettings : : slotUploadMetadataSuccess ( const QByteArray & folderId )
{
2019-07-24 14:56:21 +03:00
const auto token = accountsState ( ) - > account ( ) - > e2e ( ) - > tokenForFolder ( folderId ) ;
auto unlockJob = new UnlockEncryptFolderApiJob ( accountsState ( ) - > account ( ) , folderId , token ) ;
connect ( unlockJob , & UnlockEncryptFolderApiJob : : success ,
this , & AccountSettings : : slotUnlockFolderSuccess ) ;
connect ( unlockJob , & UnlockEncryptFolderApiJob : : error ,
this , & AccountSettings : : slotUnlockFolderError ) ;
unlockJob - > start ( ) ;
2017-11-13 18:46:30 +03:00
}
void AccountSettings : : slotUpdateMetadataError ( const QByteArray & folderId , int httpReturnCode )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( httpReturnCode ) ;
2019-07-24 14:56:21 +03:00
const auto token = accountsState ( ) - > account ( ) - > e2e ( ) - > tokenForFolder ( folderId ) ;
auto unlockJob = new UnlockEncryptFolderApiJob ( accountsState ( ) - > account ( ) , folderId , token ) ;
connect ( unlockJob , & UnlockEncryptFolderApiJob : : success ,
this , & AccountSettings : : slotUnlockFolderSuccess ) ;
connect ( unlockJob , & UnlockEncryptFolderApiJob : : error ,
this , & AccountSettings : : slotUnlockFolderError ) ;
unlockJob - > start ( ) ;
2017-11-13 18:46:30 +03:00
}
2017-12-16 01:32:41 +03:00
void AccountSettings : : slotLockForEncryptionError ( const QByteArray & fileId , int httpErrorCode )
2017-11-03 14:00:25 +03:00
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
Q_UNUSED ( httpErrorCode ) ;
2017-11-03 14:34:30 +03:00
qCInfo ( lcAccountSettings ( ) ) < < " Locking error " < < httpErrorCode ;
2017-11-03 14:00:25 +03:00
}
2017-11-03 14:34:30 +03:00
void AccountSettings : : slotUnlockFolderError ( const QByteArray & fileId , int httpErrorCode )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
Q_UNUSED ( httpErrorCode ) ;
2017-11-03 14:34:30 +03:00
qCInfo ( lcAccountSettings ( ) ) < < " Unlocking error! " ;
}
void AccountSettings : : slotUnlockFolderSuccess ( const QByteArray & fileId )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
2017-11-03 14:34:30 +03:00
qCInfo ( lcAccountSettings ( ) ) < < " Unlocking success! " ;
}
2018-05-12 00:22:33 +03:00
bool AccountSettings : : canEncryptOrDecrypt ( const FolderStatusModel : : SubFolderInfo * info ) {
if ( info - > _folder - > syncResult ( ) . status ( ) ! = SyncResult : : Status : : Success ) {
QMessageBox msgBox ;
msgBox . setText ( " Please wait for the folder to sync before trying to encrypt it. " ) ;
msgBox . exec ( ) ;
return false ;
}
// for some reason the actual folder in disk is info->_folder->path + info->_path.
QDir folderPath ( info - > _folder - > path ( ) + info - > _path ) ;
folderPath . setFilter ( QDir : : AllEntries | QDir : : NoDotAndDotDot ) ;
if ( folderPath . count ( ) ! = 0 ) {
QMessageBox msgBox ;
msgBox . setText ( " You cannot encyrpt a folder with contents, please remove the files \n "
" Wait for the new sync, then encrypt it. " ) ;
msgBox . exec ( ) ;
return false ;
}
return true ;
}
2019-08-15 01:08:21 +03:00
void AccountSettings : : slotMarkSubfolderEncrypted ( const FolderStatusModel : : SubFolderInfo * folderInfo )
2017-11-03 14:00:25 +03:00
{
2018-05-12 00:22:33 +03:00
if ( ! canEncryptOrDecrypt ( folderInfo ) ) {
return ;
}
auto job = new OCC : : SetEncryptionFlagApiJob ( accountsState ( ) - > account ( ) , folderInfo - > _fileId ) ;
2017-11-03 14:00:25 +03:00
connect ( job , & OCC : : SetEncryptionFlagApiJob : : success , this , & AccountSettings : : slotEncryptionFlagSuccess ) ;
connect ( job , & OCC : : SetEncryptionFlagApiJob : : error , this , & AccountSettings : : slotEncryptionFlagError ) ;
2017-10-31 13:09:34 +03:00
job - > start ( ) ;
}
2017-12-16 01:32:41 +03:00
// Order:
// 1 - Lock folder,
// 2 - Delete Metadata,
// 3 - Unlock Folder,
// 4 - Mark as Decrypted.
2018-05-12 00:22:33 +03:00
void AccountSettings : : slotMarkSubfolderDecrypted ( const FolderStatusModel : : SubFolderInfo * folderInfo )
2017-10-31 13:09:34 +03:00
{
2018-05-12 00:22:33 +03:00
if ( ! canEncryptOrDecrypt ( folderInfo ) ) {
return ;
}
2017-12-16 01:32:41 +03:00
qDebug ( ) < < " Starting to mark as decrypted " ;
qDebug ( ) < < " Locking the folder " ;
2018-05-12 00:22:33 +03:00
auto lockJob = new LockEncryptFolderApiJob ( accountsState ( ) - > account ( ) , folderInfo - > _fileId ) ;
2017-12-16 01:32:41 +03:00
connect ( lockJob , & LockEncryptFolderApiJob : : success ,
this , & AccountSettings : : slotLockForDecryptionSuccess ) ;
connect ( lockJob , & LockEncryptFolderApiJob : : error ,
this , & AccountSettings : : slotLockForDecryptionError ) ;
lockJob - > start ( ) ;
}
void AccountSettings : : slotLockForDecryptionSuccess ( const QByteArray & fileId , const QByteArray & token )
{
qDebug ( ) < < " Locking success, trying to delete the metadata " ;
accountsState ( ) - > account ( ) - > e2e ( ) - > setTokenForFolder ( fileId , token ) ;
auto job = new DeleteMetadataApiJob ( accountsState ( ) - > account ( ) , fileId ) ;
connect ( job , & DeleteMetadataApiJob : : success ,
this , & AccountSettings : : slotDeleteMetadataSuccess ) ;
connect ( job , & DeleteMetadataApiJob : : error ,
this , & AccountSettings : : slotDeleteMetadataError ) ;
job - > start ( ) ;
}
void AccountSettings : : slotDeleteMetadataSuccess ( const QByteArray & fileId )
{
qDebug ( ) < < " Metadata successfully deleted, unlocking the folder " ;
auto token = accountsState ( ) - > account ( ) - > e2e ( ) - > tokenForFolder ( fileId ) ;
auto job = new UnlockEncryptFolderApiJob ( accountsState ( ) - > account ( ) , fileId , token ) ;
connect ( job , & UnlockEncryptFolderApiJob : : success ,
this , & AccountSettings : : slotUnlockForDecryptionSuccess ) ;
connect ( job , & UnlockEncryptFolderApiJob : : error ,
this , & AccountSettings : : slotUnlockForDecryptionError ) ;
job - > start ( ) ;
}
void AccountSettings : : slotUnlockForDecryptionSuccess ( const QByteArray & fileId )
{
qDebug ( ) < < " Unlocked the folder successfully, removing the encrypted bit. " ;
auto job = new OCC : : DeleteApiJob ( accountsState ( ) - > account ( ) ,
" ocs/v2.php/apps/end_to_end_encryption/api/v1/encrypted/ " + QString ( fileId ) ) ;
// This Delete ApiJob is different than all other jobs used here, sigh.
connect ( job , & OCC : : DeleteApiJob : : result , [ this , & fileId ] ( int httpResponse ) {
if ( httpResponse = = 200 ) {
slotDecryptionFlagSuccess ( fileId ) ;
} else {
slotDecryptionFlagError ( fileId , httpResponse ) ;
}
} ) ;
job - > start ( ) ;
}
void AccountSettings : : slotDecryptionFlagSuccess ( const QByteArray & fileId )
{
if ( auto info = _model - > infoForFileId ( fileId ) ) {
accountsState ( ) - > account ( ) - > e2e ( ) - > setFolderEncryptedStatus ( info - > _path , false ) ;
} else {
qCInfo ( lcAccountSettings ( ) ) < < " Could not get information for the current path. " ;
}
}
2018-07-02 14:02:15 +03:00
void AccountSettings : : slotDecryptionFlagError ( const QByteArray & fileId , int httpReturnCode )
2017-12-16 01:32:41 +03:00
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
Q_UNUSED ( httpReturnCode ) ;
2017-12-16 01:32:41 +03:00
qDebug ( ) < < " Error Setting the Decryption Flag " ;
}
void AccountSettings : : slotUnlockForDecryptionError ( const QByteArray & fileId , int httpReturnCode )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
Q_UNUSED ( httpReturnCode ) ;
2017-12-17 21:14:34 +03:00
qDebug ( ) < < " Error unlocking folder after decryption " ;
2017-12-16 01:32:41 +03:00
}
void AccountSettings : : slotDeleteMetadataError ( const QByteArray & fileId , int httpReturnCode )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
Q_UNUSED ( httpReturnCode ) ;
qDebug ( ) < < " Error deleting the metadata " ;
2017-12-16 01:32:41 +03:00
}
void AccountSettings : : slotLockForDecryptionError ( const QByteArray & fileId , int httpReturnCode )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( fileId ) ;
Q_UNUSED ( httpReturnCode ) ;
qDebug ( ) < < " Error Locking for decryption " ;
2017-10-31 13:09:34 +03:00
}
2019-08-15 01:04:16 +03:00
void AccountSettings : : slotEditCurrentIgnoredFiles ( )
2019-08-15 00:27:17 +03:00
{
2019-08-15 01:04:16 +03:00
Folder * f = FolderMan : : instance ( ) - > folder ( selectedFolderAlias ( ) ) ;
if ( f = = nullptr )
return ;
openIgnoredFilesDialog ( f - > path ( ) ) ;
}
void AccountSettings : : slotEditCurrentLocalIgnoredFiles ( )
{
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! selected . isValid ( ) | | _model - > classify ( selected ) ! = FolderStatusModel : : SubFolder )
return ;
QString fileName = _model - > data ( selected , FolderStatusDelegate : : FolderPathRole ) . toString ( ) ;
openIgnoredFilesDialog ( fileName ) ;
}
2019-08-15 00:27:17 +03:00
2019-08-15 01:04:16 +03:00
void AccountSettings : : openIgnoredFilesDialog ( const QString & absFolderPath )
{
Q_ASSERT ( absFolderPath . startsWith ( ' / ' ) ) ;
Q_ASSERT ( absFolderPath . endsWith ( ' / ' ) ) ;
const QString ignoreFile = absFolderPath + " .sync-exclude.lst " ;
2019-08-15 00:27:17 +03:00
auto layout = new QVBoxLayout ( ) ;
auto ignoreListWidget = new IgnoreListTableWidget ( this ) ;
ignoreListWidget - > readIgnoreFile ( ignoreFile ) ;
layout - > addWidget ( ignoreListWidget ) ;
auto buttonBox = new QDialogButtonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
layout - > addWidget ( buttonBox ) ;
auto dialog = new QDialog ( ) ;
dialog - > setLayout ( layout ) ;
connect ( buttonBox , & QDialogButtonBox : : clicked , [ = ] ( QAbstractButton * button ) {
if ( buttonBox - > buttonRole ( button ) = = QDialogButtonBox : : AcceptRole )
ignoreListWidget - > slotWriteIgnoreFile ( ignoreFile ) ;
dialog - > close ( ) ;
} ) ;
connect ( buttonBox , & QDialogButtonBox : : rejected ,
dialog , & QDialog : : close ) ;
dialog - > open ( ) ;
}
2017-10-31 13:03:24 +03:00
void AccountSettings : : slotSubfolderContextMenuRequested ( const QModelIndex & index , const QPoint & pos )
{
2018-07-02 14:02:15 +03:00
Q_UNUSED ( pos ) ;
2017-10-31 13:03:24 +03:00
QMenu menu ;
auto ac = menu . addAction ( tr ( " Open folder " ) ) ;
connect ( ac , & QAction : : triggered , this , & AccountSettings : : slotOpenCurrentLocalSubFolder ) ;
auto fileName = _model - > data ( index , FolderStatusDelegate : : FolderPathRole ) . toString ( ) ;
if ( ! QFile : : exists ( fileName ) ) {
ac - > setEnabled ( false ) ;
}
2017-11-27 23:06:38 +03:00
auto info = _model - > infoForIndex ( index ) ;
auto acc = _accountState - > account ( ) ;
2017-10-31 13:03:24 +03:00
2017-11-27 23:19:54 +03:00
if ( acc - > capabilities ( ) . clientSideEncryptionAvaliable ( ) ) {
2018-05-12 00:22:33 +03:00
// Verify if the folder is empty before attempting to encrypt.
2017-11-27 23:19:54 +03:00
bool isEncrypted = acc - > e2e ( ) - > isFolderEncrypted ( info - > _path ) ;
2017-10-31 13:03:24 +03:00
2018-06-08 17:33:17 +03:00
if ( ! isEncrypted ) {
2018-06-22 13:13:04 +03:00
ac = menu . addAction ( tr ( " Encrypt " ) ) ;
2019-08-15 01:08:21 +03:00
connect ( ac , & QAction : : triggered , [ this , & info ] { slotMarkSubfolderEncrypted ( info ) ; } ) ;
2017-11-27 23:19:54 +03:00
} else {
2018-06-22 13:13:04 +03:00
// Ingore decrypting for now since it only works with an empty folder
// connect(ac, &QAction::triggered, [this, &info] { slotMarkSubfolderDecrypted(info); });
2017-11-27 23:19:54 +03:00
}
2017-10-31 13:03:24 +03:00
}
2019-08-15 00:27:17 +03:00
ac = menu . addAction ( tr ( " Edit Ignored Files " ) ) ;
2019-08-15 01:04:16 +03:00
connect ( ac , & QAction : : triggered , this , & AccountSettings : : slotEditCurrentLocalIgnoredFiles ) ;
2019-08-15 00:27:17 +03:00
2017-10-31 13:03:24 +03:00
menu . exec ( QCursor : : pos ( ) ) ;
}
2015-03-27 13:46:03 +03:00
void AccountSettings : : slotCustomContextMenuRequested ( const QPoint & pos )
{
QTreeView * tv = ui - > _folderList ;
QModelIndex index = tv - > indexAt ( pos ) ;
if ( ! index . isValid ( ) ) {
return ;
}
2017-04-26 21:03:55 +03:00
if ( _model - > classify ( index ) = = FolderStatusModel : : SubFolder ) {
2017-10-31 13:03:24 +03:00
slotSubfolderContextMenuRequested ( index , pos ) ;
2017-04-26 21:03:55 +03:00
return ;
}
2016-04-27 12:21:58 +03:00
if ( _model - > classify ( index ) ! = FolderStatusModel : : RootFolder ) {
2015-03-27 13:46:03 +03:00
return ;
}
tv - > setCurrentIndex ( index ) ;
2016-12-13 17:28:52 +03:00
QString alias = _model - > data ( index , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
2015-03-27 13:46:03 +03:00
bool folderPaused = _model - > data ( index , FolderStatusDelegate : : FolderSyncPaused ) . toBool ( ) ;
2015-09-29 18:00:06 +03:00
bool folderConnected = _model - > data ( index , FolderStatusDelegate : : FolderAccountConnected ) . toBool ( ) ;
2016-12-13 17:28:52 +03:00
auto folderMan = FolderMan : : instance ( ) ;
2015-03-27 13:46:03 +03:00
QMenu * menu = new QMenu ( tv ) ;
2017-11-20 15:23:03 +03:00
2015-03-27 13:46:03 +03:00
menu - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2015-09-29 18:00:06 +03:00
QAction * ac = menu - > addAction ( tr ( " Open folder " ) ) ;
2017-09-20 11:14:48 +03:00
connect ( ac , & QAction : : triggered , this , & AccountSettings : : slotOpenCurrentFolder ) ;
2015-09-29 18:00:06 +03:00
2019-08-15 01:04:16 +03:00
ac = menu - > addAction ( tr ( " Edit Ignored Files " ) ) ;
connect ( ac , & QAction : : triggered , this , & AccountSettings : : slotEditCurrentIgnoredFiles ) ;
2016-02-22 14:47:26 +03:00
if ( ! ui - > _folderList - > isExpanded ( index ) ) {
ac = menu - > addAction ( tr ( " Choose what to sync " ) ) ;
ac - > setEnabled ( folderConnected ) ;
2017-09-20 11:14:48 +03:00
connect ( ac , & QAction : : triggered , this , & AccountSettings : : doExpand ) ;
2016-02-22 14:47:26 +03:00
}
2015-09-29 18:00:06 +03:00
2016-11-25 16:23:56 +03:00
if ( ! folderPaused ) {
ac = menu - > addAction ( tr ( " Force sync now " ) ) ;
2016-12-13 17:28:52 +03:00
if ( folderMan - > currentSyncFolder ( ) = = folderMan - > folder ( alias ) ) {
ac - > setText ( tr ( " Restart sync " ) ) ;
}
ac - > setEnabled ( folderConnected ) ;
2017-09-20 11:14:48 +03:00
connect ( ac , & QAction : : triggered , this , & AccountSettings : : slotForceSyncCurrentFolder ) ;
2016-11-25 16:23:56 +03:00
}
2015-09-29 18:00:06 +03:00
ac = menu - > addAction ( folderPaused ? tr ( " Resume sync " ) : tr ( " Pause sync " ) ) ;
2017-09-20 11:14:48 +03:00
connect ( ac , & QAction : : triggered , this , & AccountSettings : : slotEnableCurrentFolder ) ;
2015-09-29 18:00:06 +03:00
2015-10-27 14:12:21 +03:00
ac = menu - > addAction ( tr ( " Remove folder sync connection " ) ) ;
2017-09-20 11:14:48 +03:00
connect ( ac , & QAction : : triggered , this , & AccountSettings : : slotRemoveCurrentFolder ) ;
2017-11-20 15:23:03 +03:00
menu - > popup ( tv - > mapToGlobal ( pos ) ) ;
2014-03-26 20:41:04 +04:00
}
2015-10-19 19:23:56 +03:00
void AccountSettings : : slotFolderListClicked ( const QModelIndex & indx )
2013-07-04 21:59:40 +04:00
{
2015-10-14 12:34:30 +03:00
if ( indx . data ( FolderStatusDelegate : : AddButton ) . toBool ( ) ) {
2017-04-26 21:03:55 +03:00
// "Add Folder Sync Connection"
2015-10-14 12:34:30 +03:00
if ( indx . flags ( ) & Qt : : ItemIsEnabled ) {
slotAddFolder ( ) ;
} else {
QToolTip : : showText (
QCursor : : pos ( ) ,
_model - > data ( indx , Qt : : ToolTipRole ) . toString ( ) ,
this ) ;
}
2015-03-27 13:46:03 +03:00
return ;
2013-07-04 21:59:40 +04:00
}
2015-08-13 13:33:20 +03:00
if ( _model - > classify ( indx ) = = FolderStatusModel : : RootFolder ) {
// tries to find if we clicked on the '...' button.
QTreeView * tv = ui - > _folderList ;
auto pos = tv - > mapFromGlobal ( QCursor : : pos ( ) ) ;
2016-01-07 15:37:46 +03:00
if ( FolderStatusDelegate : : optionsButtonRect ( tv - > visualRect ( indx ) , layoutDirection ( ) ) . contains ( pos ) ) {
2015-08-13 13:33:20 +03:00
slotCustomContextMenuRequested ( pos ) ;
2015-10-19 19:23:56 +03:00
return ;
}
2017-07-04 15:08:41 +03:00
if ( FolderStatusDelegate : : errorsListRect ( tv - > visualRect ( indx ) ) . contains ( pos ) ) {
2018-11-09 14:12:25 +03:00
emit showIssuesList ( _accountState ) ;
2017-07-04 15:08:41 +03:00
return ;
}
2015-10-19 19:23:56 +03:00
// Expand root items on single click
if ( _accountState & & _accountState - > state ( ) = = AccountState : : Connected ) {
bool expanded = ! ( ui - > _folderList - > isExpanded ( indx ) ) ;
ui - > _folderList - > setExpanded ( indx , expanded ) ;
2015-08-13 13:33:20 +03:00
}
}
2013-07-04 21:59:40 +04:00
}
void AccountSettings : : slotAddFolder ( )
{
2013-07-22 15:59:52 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
folderMan - > setSyncEnabled ( false ) ; // do not start more syncs.
2013-07-04 21:59:40 +04:00
2015-04-17 18:56:17 +03:00
FolderWizard * folderWizard = new FolderWizard ( _accountState - > account ( ) , this ) ;
2013-07-04 21:59:40 +04:00
2017-09-20 11:14:48 +03:00
connect ( folderWizard , & QDialog : : accepted , this , & AccountSettings : : slotFolderWizardAccepted ) ;
connect ( folderWizard , & QDialog : : rejected , this , & AccountSettings : : slotFolderWizardRejected ) ;
2013-07-04 21:59:40 +04:00
folderWizard - > open ( ) ;
}
void AccountSettings : : slotFolderWizardAccepted ( )
{
FolderWizard * folderWizard = qobject_cast < FolderWizard * > ( sender ( ) ) ;
2013-07-22 15:59:52 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
2013-07-04 21:59:40 +04:00
2017-03-30 14:46:20 +03:00
qCInfo ( lcAccountSettings ) < < " Folder wizard completed " ;
2013-07-04 21:59:40 +04:00
2015-04-24 11:18:33 +03:00
FolderDefinition definition ;
2015-09-17 13:14:35 +03:00
definition . localPath = FolderDefinition : : prepareLocalPath (
folderWizard - > field ( QLatin1String ( " sourceFolder " ) ) . toString ( ) ) ;
2016-11-23 12:40:17 +03:00
definition . targetPath = FolderDefinition : : prepareTargetPath (
folderWizard - > property ( " targetPath " ) . toString ( ) ) ;
2015-07-15 15:51:37 +03:00
2015-07-28 13:14:52 +03:00
{
QDir dir ( definition . localPath ) ;
if ( ! dir . exists ( ) ) {
2017-03-30 14:46:20 +03:00
qCInfo ( lcAccountSettings ) < < " Creating folder " < < definition . localPath ;
2015-07-28 13:14:52 +03:00
if ( ! dir . mkpath ( " . " ) ) {
QMessageBox : : warning ( this , tr ( " Folder creation failed " ) ,
2019-11-15 01:15:49 +03:00
tr ( " <p>Could not create local folder <i>%1</i>.</p> " )
2015-07-28 13:14:52 +03:00
. arg ( QDir : : toNativeSeparators ( definition . localPath ) ) ) ;
return ;
}
}
2017-04-10 17:15:28 +03:00
FileSystem : : setFolderMinimumPermissions ( definition . localPath ) ;
2017-08-03 20:54:20 +03:00
Utility : : setupFavLink ( definition . localPath ) ;
2015-07-28 13:14:52 +03:00
}
2015-07-15 15:51:37 +03:00
/* take the value from the definition of already existing folders. All folders have
2015-08-10 12:03:57 +03:00
* the same setting so far .
2018-08-28 12:24:36 +03:00
* The default is to sync hidden files
2015-07-15 15:51:37 +03:00
*/
2015-08-10 12:03:57 +03:00
definition . ignoreHiddenFiles = folderMan - > ignoreHiddenFiles ( ) ;
2015-07-15 15:51:37 +03:00
2017-10-19 17:37:51 +03:00
if ( folderMan - > navigationPaneHelper ( ) . showInExplorerNavigationPane ( ) )
definition . navigationPaneClsid = QUuid : : createUuid ( ) ;
2017-10-04 14:49:42 +03:00
2015-06-10 17:22:14 +03:00
auto selectiveSyncBlackList = folderWizard - > property ( " selectiveSyncBlackList " ) . toStringList ( ) ;
2013-07-04 21:59:40 +04:00
2015-07-01 12:39:57 +03:00
folderMan - > setSyncEnabled ( true ) ;
2015-04-24 11:18:33 +03:00
Folder * f = folderMan - > addFolder ( _accountState , definition ) ;
2013-07-04 21:59:40 +04:00
if ( f ) {
2015-06-10 17:22:14 +03:00
f - > journalDb ( ) - > setSelectiveSyncList ( SyncJournalDb : : SelectiveSyncBlackList , selectiveSyncBlackList ) ;
2015-08-05 17:11:59 +03:00
// The user already accepted the selective sync dialog. everything is in the white list
f - > journalDb ( ) - > setSelectiveSyncList ( SyncJournalDb : : SelectiveSyncWhiteList ,
QStringList ( ) < < QLatin1String ( " / " ) ) ;
2016-10-19 12:03:13 +03:00
folderMan - > scheduleAllFolders ( ) ;
2013-07-04 21:59:40 +04:00
emit folderChanged ( ) ;
}
}
void AccountSettings : : slotFolderWizardRejected ( )
{
2017-03-30 14:46:20 +03:00
qCInfo ( lcAccountSettings ) < < " Folder wizard cancelled " ;
2013-07-22 15:59:52 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
folderMan - > setSyncEnabled ( true ) ;
2013-07-04 21:59:40 +04:00
}
void AccountSettings : : slotRemoveCurrentFolder ( )
{
2017-04-12 16:24:54 +03:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
auto folder = folderMan - > folder ( selectedFolderAlias ( ) ) ;
2013-07-04 21:59:40 +04:00
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
2017-04-12 16:24:54 +03:00
if ( selected . isValid ( ) & & folder ) {
2013-09-19 23:27:43 +04:00
int row = selected . row ( ) ;
2017-03-30 14:46:20 +03:00
qCInfo ( lcAccountSettings ) < < " Remove Folder alias " < < folder - > alias ( ) ;
2017-04-12 16:24:54 +03:00
QString shortGuiLocalPath = folder - > shortGuiLocalPath ( ) ;
QMessageBox messageBox ( QMessageBox : : Question ,
tr ( " Confirm Folder Sync Connection Removal " ) ,
tr ( " <p>Do you really want to stop syncing the folder <i>%1</i>?</p> "
" <p><b>Note:</b> This will <b>not</b> delete any files.</p> " )
. arg ( shortGuiLocalPath ) ,
QMessageBox : : NoButton ,
this ) ;
QPushButton * yesButton =
messageBox . addButton ( tr ( " Remove Folder Sync Connection " ) , QMessageBox : : YesRole ) ;
messageBox . addButton ( tr ( " Cancel " ) , QMessageBox : : NoRole ) ;
messageBox . exec ( ) ;
if ( messageBox . clickedButton ( ) ! = yesButton ) {
return ;
}
2013-09-19 23:27:43 +04:00
2017-04-12 16:24:54 +03:00
folderMan - > removeFolder ( folder ) ;
_model - > removeRow ( row ) ;
2013-09-19 23:27:43 +04:00
2017-04-12 16:24:54 +03:00
// single folder fix to show add-button and hide remove-button
2013-12-09 19:23:00 +04:00
2017-04-12 16:24:54 +03:00
emit folderChanged ( ) ;
2013-07-04 21:59:40 +04:00
}
}
2013-12-12 19:38:45 +04:00
2015-08-13 12:53:00 +03:00
void AccountSettings : : slotOpenCurrentFolder ( )
2013-07-04 21:59:40 +04:00
{
2017-04-12 16:24:54 +03:00
auto alias = selectedFolderAlias ( ) ;
if ( ! alias . isEmpty ( ) ) {
2015-08-13 12:53:00 +03:00
emit openFolderAlias ( alias ) ;
}
2013-07-04 21:59:40 +04:00
}
2017-04-26 21:03:55 +03:00
void AccountSettings : : slotOpenCurrentLocalSubFolder ( )
{
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! selected . isValid ( ) | | _model - > classify ( selected ) ! = FolderStatusModel : : SubFolder )
return ;
QString fileName = _model - > data ( selected , FolderStatusDelegate : : FolderPathRole ) . toString ( ) ;
QUrl url = QUrl : : fromLocalFile ( fileName ) ;
QDesktopServices : : openUrl ( url ) ;
}
2015-07-15 12:37:38 +03:00
void AccountSettings : : showConnectionLabel ( const QString & message , QStringList errors )
2013-09-11 12:24:31 +04:00
{
const QString errStyle = QLatin1String ( " color:#ffffff; background-color:#bb4d4d;padding:5px; "
" border-width: 1px; border-style: solid; border-color: #aaaaaa; "
" border-radius:5px; " ) ;
2015-07-15 12:37:38 +03:00
if ( errors . isEmpty ( ) ) {
2019-12-09 22:47:42 +03:00
QString msg = message ;
Theme : : replaceLinkColorStringBackgroundAware ( msg ) ;
ui - > connectLabel - > setText ( msg ) ;
2015-07-15 12:37:38 +03:00
ui - > connectLabel - > setToolTip ( QString ( ) ) ;
2014-04-22 16:07:27 +04:00
ui - > connectLabel - > setStyleSheet ( QString ( ) ) ;
2013-09-11 12:24:31 +04:00
} else {
2015-07-15 12:37:38 +03:00
errors . prepend ( message ) ;
2019-12-09 22:47:42 +03:00
QString msg = errors . join ( QLatin1String ( " \n " ) ) ;
2017-05-09 15:24:11 +03:00
qCDebug ( lcAccountSettings ) < < msg ;
2019-12-19 21:31:42 +03:00
Theme : : replaceLinkColorString ( msg , QColor ( " #c1c8e6 " ) ) ;
2013-09-11 12:24:31 +04:00
ui - > connectLabel - > setText ( msg ) ;
ui - > connectLabel - > setToolTip ( QString ( ) ) ;
ui - > connectLabel - > setStyleSheet ( errStyle ) ;
}
2015-03-27 13:46:03 +03:00
ui - > accountStatus - > setVisible ( ! message . isEmpty ( ) ) ;
2013-07-04 21:59:40 +04:00
}
void AccountSettings : : slotEnableCurrentFolder ( )
{
2017-04-12 16:24:54 +03:00
auto alias = selectedFolderAlias ( ) ;
2013-07-04 21:59:40 +04:00
2017-04-12 16:24:54 +03:00
if ( ! alias . isEmpty ( ) ) {
2014-08-19 15:58:20 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
2013-07-04 21:59:40 +04:00
2017-03-30 14:46:20 +03:00
qCInfo ( lcAccountSettings ) < < " Application: enable folder with alias " < < alias ;
2014-08-19 15:58:20 +04:00
bool terminate = false ;
bool currentlyPaused = false ;
2014-06-20 13:39:48 +04:00
2014-08-19 15:58:20 +04:00
// this sets the folder status to disabled but does not interrupt it.
Folder * f = folderMan - > folder ( alias ) ;
if ( ! f ) {
return ;
}
currentlyPaused = f - > syncPaused ( ) ;
if ( ! currentlyPaused ) {
// check if a sync is still running and if so, ask if we should terminate.
if ( f - > isBusy ( ) ) { // its still running
2014-02-14 06:02:59 +04:00
# if defined(Q_OS_MAC)
2014-08-19 15:58:20 +04:00
QWidget * parent = this ;
Qt : : WindowFlags flags = Qt : : Sheet ;
2014-02-14 06:02:59 +04:00
# else
2018-11-11 12:56:22 +03:00
QWidget * parent = nullptr ;
2014-08-19 15:58:20 +04:00
Qt : : WindowFlags flags = Qt : : Dialog | Qt : : MSWindowsFixedSizeDialogHint ; // default flags
2014-02-14 06:02:59 +04:00
# endif
2014-08-19 15:58:20 +04:00
QMessageBox msgbox ( QMessageBox : : Question , tr ( " Sync Running " ) ,
tr ( " The syncing operation is running.<br/>Do you want to terminate it? " ) ,
QMessageBox : : Yes | QMessageBox : : No , parent , flags ) ;
msgbox . setDefaultButton ( QMessageBox : : Yes ) ;
int reply = msgbox . exec ( ) ;
if ( reply = = QMessageBox : : Yes )
terminate = true ;
else
return ; // do nothing
2013-10-03 15:41:15 +04:00
}
2014-08-19 15:58:20 +04:00
}
2013-07-04 21:59:40 +04:00
2014-08-19 15:58:20 +04:00
// message box can return at any time while the thread keeps running,
// so better check again after the user has responded.
if ( f - > isBusy ( ) & & terminate ) {
2014-09-26 14:43:54 +04:00
f - > slotTerminateSync ( ) ;
2014-08-19 15:58:20 +04:00
}
2016-03-02 13:06:03 +03:00
f - > setSyncPaused ( ! currentlyPaused ) ;
2013-10-11 19:51:55 +04:00
2014-08-19 15:58:20 +04:00
// keep state for the icon setting.
if ( currentlyPaused )
_wasDisabledBefore = true ;
2013-10-11 19:51:55 +04:00
2015-06-02 20:45:23 +03:00
_model - > slotUpdateFolderState ( f ) ;
2013-07-04 21:59:40 +04:00
}
}
2016-11-25 16:23:56 +03:00
void AccountSettings : : slotScheduleCurrentFolder ( )
2013-10-30 19:25:03 +04:00
{
FolderMan * folderMan = FolderMan : : instance ( ) ;
2017-04-12 16:24:54 +03:00
if ( auto folder = folderMan - > folder ( selectedFolderAlias ( ) ) ) {
folderMan - > scheduleFolder ( folder ) ;
}
2013-10-30 19:25:03 +04:00
}
2017-04-12 16:25:26 +03:00
void AccountSettings : : slotScheduleCurrentFolderForceRemoteDiscovery ( )
{
FolderMan * folderMan = FolderMan : : instance ( ) ;
if ( auto folder = folderMan - > folder ( selectedFolderAlias ( ) ) ) {
folder - > journalDb ( ) - > forceRemoteDiscoveryNextSync ( ) ;
folderMan - > scheduleFolder ( folder ) ;
}
}
2016-11-25 16:23:56 +03:00
void AccountSettings : : slotForceSyncCurrentFolder ( )
{
FolderMan * folderMan = FolderMan : : instance ( ) ;
2017-04-12 16:24:54 +03:00
if ( auto selectedFolder = folderMan - > folder ( selectedFolderAlias ( ) ) ) {
// Terminate and reschedule any running sync
if ( Folder * current = folderMan - > currentSyncFolder ( ) ) {
folderMan - > terminateSyncProcess ( ) ;
folderMan - > scheduleFolder ( current ) ;
}
2016-11-25 16:23:56 +03:00
2017-04-12 16:24:54 +03:00
// Insert the selected folder at the front of the queue
folderMan - > scheduleFolderNext ( selectedFolder ) ;
2016-11-25 16:23:56 +03:00
}
}
2013-07-04 21:59:40 +04:00
void AccountSettings : : slotOpenOC ( )
{
if ( _OCUrl . isValid ( ) )
QDesktopServices : : openUrl ( _OCUrl ) ;
}
void AccountSettings : : slotUpdateQuota ( qint64 total , qint64 used )
{
2013-09-03 15:13:11 +04:00
if ( total > 0 ) {
ui - > quotaProgressBar - > setVisible ( true ) ;
ui - > quotaProgressBar - > setEnabled ( true ) ;
// workaround the label only accepting ints (which may be only 32 bit wide)
2015-08-19 16:16:09 +03:00
const double percent = used / ( double ) total * 100 ;
const int percentInt = qMin ( qRound ( percent ) , 100 ) ;
ui - > quotaProgressBar - > setValue ( percentInt ) ;
2013-09-03 15:13:11 +04:00
QString usedStr = Utility : : octetsToString ( used ) ;
QString totalStr = Utility : : octetsToString ( total ) ;
2013-11-07 15:50:39 +04:00
QString percentStr = Utility : : compactFormatDouble ( percent , 1 ) ;
2015-08-30 16:57:33 +03:00
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 ) ;
2013-09-03 15:13:11 +04:00
} else {
2015-08-30 16:57:33 +03:00
ui - > quotaProgressBar - > setVisible ( false ) ;
2015-10-29 16:33:29 +03:00
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. " ) ) ;
} else {
QString usedStr = Utility : : octetsToString ( used ) ;
ui - > quotaInfoLabel - > setText ( tr ( " %1 in use " ) . arg ( usedStr ) ) ;
}
2013-07-20 03:26:11 +04:00
}
2013-07-20 00:14:07 +04:00
}
2017-07-13 12:27:02 +03:00
void AccountSettings : : slotAccountStateChanged ( )
2013-11-04 19:36:23 +04:00
{
2017-07-13 12:27:02 +03:00
int state = _accountState ? _accountState - > state ( ) : AccountState : : Disconnected ;
2014-12-17 16:09:57 +03:00
if ( _accountState ) {
ui - > sslButton - > updateAccountState ( _accountState ) ;
2014-12-18 14:09:48 +03:00
AccountPtr account = _accountState - > account ( ) ;
2014-12-17 16:09:57 +03:00
QUrl safeUrl ( account - > url ( ) ) ;
2013-11-07 15:22:17 +04:00
safeUrl . setPassword ( QString ( ) ) ; // Remove the password from the URL to avoid showing it in the UI
2014-08-15 17:01:01 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
foreach ( Folder * folder , folderMan - > map ( ) . values ( ) ) {
2015-06-02 20:45:23 +03:00
_model - > slotUpdateFolderState ( folder ) ;
2014-08-15 17:01:01 +04:00
}
2015-07-15 12:37:38 +03:00
2017-02-23 16:54:17 +03:00
QString server = QString : : fromLatin1 ( " <a href= \" %1 \" >%2</a> " )
. arg ( Utility : : escape ( account - > url ( ) . toString ( ) ) ,
Utility : : escape ( safeUrl . toString ( ) ) ) ;
2015-07-15 12:37:38 +03:00
QString serverWithUser = server ;
if ( AbstractCredentials * cred = account - > credentials ( ) ) {
2017-10-05 22:08:38 +03:00
QString user = account - > davDisplayName ( ) ;
if ( user . isEmpty ( ) ) {
user = cred - > user ( ) ;
}
serverWithUser = tr ( " %1 as <i>%2</i> " ) . arg ( server , Utility : : escape ( user ) ) ;
2015-07-15 12:37:38 +03:00
}
2015-07-15 15:02:45 +03:00
if ( state = = AccountState : : Connected ) {
2016-03-02 13:59:36 +03:00
QStringList errors ;
if ( account - > serverVersionUnsupported ( ) ) {
errors < < tr ( " The server version %1 is old and unsupported! Proceed at your own risk. " ) . arg ( account - > serverVersion ( ) ) ;
}
showConnectionLabel ( tr ( " Connected to %1. " ) . arg ( serverWithUser ) , errors ) ;
2015-07-15 12:37:38 +03:00
} else if ( state = = AccountState : : ServiceUnavailable ) {
showConnectionLabel ( tr ( " Server %1 is temporarily unavailable. " ) . arg ( server ) ) ;
2017-05-08 13:39:08 +03:00
} else if ( state = = AccountState : : MaintenanceMode ) {
showConnectionLabel ( tr ( " Server %1 is currently in maintenance mode. " ) . arg ( server ) ) ;
2015-07-15 12:37:38 +03:00
} else if ( state = = AccountState : : SignedOut ) {
showConnectionLabel ( tr ( " Signed out from %1. " ) . arg ( serverWithUser ) ) ;
2017-07-13 12:27:02 +03:00
} else if ( state = = AccountState : : AskingCredentials ) {
QUrl url ;
if ( auto cred = qobject_cast < HttpCredentialsGui * > ( account - > credentials ( ) ) ) {
connect ( cred , & HttpCredentialsGui : : authorisationLinkChanged ,
this , & AccountSettings : : slotAccountStateChanged , Qt : : UniqueConnection ) ;
url = cred - > authorisationLink ( ) ;
}
if ( url . isValid ( ) ) {
showConnectionLabel ( tr ( " Obtaining authorization from the browser. "
" <a href='%1'>Click here</a> to re-open the browser. " )
. arg ( url . toString ( QUrl : : FullyEncoded ) ) ) ;
} else {
2019-11-15 01:23:43 +03:00
showConnectionLabel ( tr ( " Connecting to %1 … " ) . arg ( serverWithUser ) ) ;
2017-07-13 12:27:02 +03:00
}
2013-11-04 19:36:23 +04:00
} else {
2017-02-23 16:54:17 +03:00
showConnectionLabel ( tr ( " No connection to %1 at %2. " )
. arg ( Utility : : escape ( Theme : : instance ( ) - > appNameGUI ( ) ) , server ) ,
_accountState - > connectionErrors ( ) ) ;
2013-11-04 19:36:23 +04:00
}
} else {
// ownCloud is not yet configured.
2017-02-23 16:54:17 +03:00
showConnectionLabel ( tr ( " No %1 connection configured. " )
. arg ( Utility : : escape ( Theme : : instance ( ) - > appNameGUI ( ) ) ) ) ;
2013-11-04 19:36:23 +04:00
}
2015-09-25 13:22:51 +03:00
/* Allow to expand the item if the account is connected. */
ui - > _folderList - > setItemsExpandable ( state = = AccountState : : Connected ) ;
if ( state ! = AccountState : : Connected ) {
2017-06-08 14:33:37 +03:00
/* check if there are expanded root items, if so, close them */
2015-09-25 13:22:51 +03:00
int i ;
for ( i = 0 ; i < _model - > rowCount ( ) ; + + i ) {
if ( ui - > _folderList - > isExpanded ( _model - > index ( i ) ) )
ui - > _folderList - > setExpanded ( _model - > index ( i ) , false ) ;
}
2017-06-08 14:33:37 +03:00
} else if ( _model - > isDirty ( ) ) {
// If we connect and have pending changes, show the list.
doExpand ( ) ;
2015-09-25 13:22:51 +03:00
}
2017-06-08 14:33:37 +03:00
// Disabling expansion of folders might require hiding the selective
// sync user interface buttons.
refreshSelectiveSyncStatus ( ) ;
2015-11-13 16:50:07 +03:00
/* set the correct label for the Account toolbox button */
if ( _accountState ) {
2016-03-29 13:14:53 +03:00
if ( _accountState - > isSignedOut ( ) ) {
2015-12-08 14:05:14 +03:00
_toggleSignInOutAction - > setText ( tr ( " Log in " ) ) ;
2016-03-29 13:14:53 +03:00
} else {
_toggleSignInOutAction - > setText ( tr ( " Log out " ) ) ;
2015-11-13 16:50:07 +03:00
}
}
2017-08-24 16:53:26 +03:00
if ( state = = AccountState : : State : : Connected ) {
/* TODO: We should probably do something better here.
* Verify if the user has a private key already uploaded to the server ,
* if it has , do not offer to create one .
*/
qCInfo ( lcAccountSettings ) < < " Accout " < < accountsState ( ) - > account ( ) - > displayName ( )
2017-09-03 14:33:50 +03:00
< < " Client Side Encryption " < < accountsState ( ) - > account ( ) - > capabilities ( ) . clientSideEncryptionAvaliable ( ) ;
2017-08-24 16:53:26 +03:00
}
2013-11-04 19:36:23 +04:00
}
2015-09-01 16:37:01 +03:00
void AccountSettings : : slotLinkActivated ( const QString & link )
{
2015-10-07 19:00:21 +03:00
// Parse folder alias and filename from the link, calculate the index
// and select it if it exists.
const QStringList li = link . split ( QLatin1String ( " ?folder= " ) ) ;
2015-10-05 13:06:26 +03:00
if ( li . count ( ) > 1 ) {
2015-10-07 19:00:21 +03:00
QString myFolder = li [ 0 ] ;
const QString alias = li [ 1 ] ;
if ( myFolder . endsWith ( QLatin1Char ( ' / ' ) ) )
myFolder . chop ( 1 ) ;
2015-10-19 19:46:39 +03:00
// Make sure the folder itself is expanded
2015-10-07 19:00:21 +03:00
Folder * f = FolderMan : : instance ( ) - > folder ( alias ) ;
QModelIndex folderIndx = _model - > indexForPath ( f , QString ( ) ) ;
if ( ! ui - > _folderList - > isExpanded ( folderIndx ) ) {
ui - > _folderList - > setExpanded ( folderIndx , true ) ;
}
QModelIndex indx = _model - > indexForPath ( f , myFolder ) ;
2015-10-05 13:06:26 +03:00
if ( indx . isValid ( ) ) {
2015-10-19 19:46:39 +03:00
// 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 ) ;
}
}
2015-10-05 13:06:26 +03:00
ui - > _folderList - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
2015-10-07 19:00:21 +03:00
ui - > _folderList - > setCurrentIndex ( indx ) ;
ui - > _folderList - > scrollTo ( indx ) ;
} else {
2017-03-30 14:46:20 +03:00
qCWarning ( lcAccountSettings ) < < " Unable to find a valid index for " < < myFolder ;
2015-10-05 13:06:26 +03:00
}
}
2015-09-01 16:37:01 +03:00
}
2013-07-04 21:59:40 +04:00
AccountSettings : : ~ AccountSettings ( )
{
delete ui ;
}
2015-03-27 13:46:03 +03:00
void AccountSettings : : refreshSelectiveSyncStatus ( )
{
2017-06-08 14:33:37 +03:00
bool shouldBeVisible = _model - > isDirty ( ) & & _accountState - > isConnected ( ) ;
2015-06-12 12:28:56 +03:00
2015-10-05 13:06:26 +03:00
QString msg ;
int cnt = 0 ;
2015-06-12 12:28:56 +03:00
foreach ( Folder * folder , FolderMan : : instance ( ) - > map ( ) . values ( ) ) {
2015-09-09 18:51:38 +03:00
if ( folder - > accountState ( ) ! = _accountState ) {
continue ;
}
2016-04-06 16:01:28 +03:00
bool ok ;
auto undecidedList = folder - > journalDb ( ) - > getSelectiveSyncList ( SyncJournalDb : : SelectiveSyncUndecidedList , & ok ) ;
2015-10-05 13:06:26 +03:00
QString p ;
2015-06-12 12:28:56 +03:00
foreach ( const auto & it , undecidedList ) {
2015-10-05 13:06:26 +03:00
// FIXME: add the folder alias in a hoover hint.
// folder->alias() + QLatin1String("/")
if ( cnt + + ) {
msg + = QLatin1String ( " , " ) ;
}
QString myFolder = ( it ) ;
2015-10-07 19:00:21 +03:00
if ( myFolder . endsWith ( ' / ' ) ) {
myFolder . chop ( 1 ) ;
}
QModelIndex theIndx = _model - > indexForPath ( folder , myFolder ) ;
if ( theIndx . isValid ( ) ) {
2017-02-23 16:54:17 +03:00
msg + = QString : : fromLatin1 ( " <a href= \" %1?folder=%2 \" >%1</a> " )
. arg ( Utility : : escape ( myFolder ) , Utility : : escape ( folder - > alias ( ) ) ) ;
2015-10-07 19:00:21 +03:00
} else {
msg + = myFolder ; // no link because we do not know the index yet.
}
2015-06-12 12:28:56 +03:00
}
}
2015-09-09 18:51:38 +03:00
2015-10-05 13:06:26 +03:00
if ( msg . isEmpty ( ) ) {
2016-09-23 14:47:57 +03:00
ui - > selectiveSyncButtons - > setVisible ( true ) ;
ui - > bigFolderUi - > setVisible ( false ) ;
2015-06-12 12:28:56 +03:00
} else {
2017-01-24 12:16:10 +03:00
ConfigFile cfg ;
2017-05-17 11:54:57 +03:00
QString info = ! cfg . confirmExternalStorage ( )
? tr ( " There are folders that were not synchronized because they are too big: " )
: ! cfg . newBigFolderSizeLimit ( ) . first
? 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: " ) ;
2017-01-24 12:16:10 +03:00
ui - > selectiveSyncNotification - > setText ( info + msg ) ;
2016-09-23 14:47:57 +03:00
ui - > selectiveSyncButtons - > setVisible ( false ) ;
ui - > bigFolderUi - > setVisible ( true ) ;
2015-06-12 12:28:56 +03:00
shouldBeVisible = true ;
}
2015-10-05 13:06:26 +03:00
ui - > selectiveSyncApply - > setEnabled ( _model - > isDirty ( ) | | ! msg . isEmpty ( ) ) ;
2015-06-17 15:43:38 +03:00
bool wasVisible = ! ui - > selectiveSyncStatus - > isHidden ( ) ;
2015-03-27 13:46:03 +03:00
if ( wasVisible ! = shouldBeVisible ) {
QSize hint = ui - > selectiveSyncStatus - > sizeHint ( ) ;
if ( shouldBeVisible ) {
ui - > selectiveSyncStatus - > setMaximumHeight ( 0 ) ;
ui - > selectiveSyncStatus - > setVisible ( true ) ;
}
auto anim = new QPropertyAnimation ( ui - > selectiveSyncStatus , " maximumHeight " , ui - > selectiveSyncStatus ) ;
anim - > setEndValue ( shouldBeVisible ? hint . height ( ) : 0 ) ;
anim - > start ( QAbstractAnimation : : DeleteWhenStopped ) ;
2017-07-27 11:46:46 +03:00
connect ( anim , & QPropertyAnimation : : finished , [ this , shouldBeVisible ] ( ) {
ui - > selectiveSyncStatus - > setMaximumHeight ( QWIDGETSIZE_MAX ) ;
if ( ! shouldBeVisible ) {
ui - > selectiveSyncStatus - > hide ( ) ;
}
} ) ;
2015-03-27 13:46:03 +03:00
}
}
2015-11-13 16:50:07 +03:00
void AccountSettings : : slotAccountAdded ( AccountState * )
2015-08-29 14:32:36 +03:00
{
2015-11-13 16:50:07 +03:00
// if the theme is limited to single account, the button must hide if
// there is already one account.
2015-12-02 18:33:24 +03:00
int s = AccountManager : : instance ( ) - > accounts ( ) . size ( ) ;
if ( s > 0 & & ! Theme : : instance ( ) - > multiAccount ( ) ) {
2015-11-13 16:50:07 +03:00
_addAccountAction - > setVisible ( false ) ;
2015-12-02 18:33:24 +03:00
} else {
_addAccountAction - > setVisible ( true ) ;
2015-11-13 16:50:07 +03:00
}
2015-08-29 14:32:36 +03:00
}
2015-05-12 16:16:32 +03:00
void AccountSettings : : slotDeleteAccount ( )
{
2015-08-21 12:01:01 +03:00
// Deleting the account potentially deletes 'this', so
// the QMessageBox should be destroyed before that happens.
{
QMessageBox messageBox ( QMessageBox : : Question ,
2015-09-11 06:01:53 +03:00
tr ( " Confirm Account Removal " ) ,
2015-08-21 12:01:01 +03:00
tr ( " <p>Do you really want to remove the connection to the account <i>%1</i>?</p> "
" <p><b>Note:</b> This will <b>not</b> delete any files.</p> " )
. arg ( _accountState - > account ( ) - > displayName ( ) ) ,
QMessageBox : : NoButton ,
this ) ;
QPushButton * yesButton =
messageBox . addButton ( tr ( " Remove connection " ) , QMessageBox : : YesRole ) ;
messageBox . addButton ( tr ( " Cancel " ) , QMessageBox : : NoRole ) ;
messageBox . exec ( ) ;
if ( messageBox . clickedButton ( ) ! = yesButton ) {
return ;
}
2015-05-12 16:16:32 +03:00
}
2017-04-28 11:03:49 +03:00
// Else it might access during destruction. This should be better handled by it having a QSharedPointer
2018-11-11 12:56:22 +03:00
_model - > setAccountState ( nullptr ) ;
2017-04-28 11:03:49 +03:00
2015-05-12 16:37:16 +03:00
auto manager = AccountManager : : instance ( ) ;
manager - > deleteAccount ( _accountState ) ;
manager - > save ( ) ;
2015-08-07 14:14:33 +03:00
2015-12-01 18:30:57 +03:00
// IMPORTANT: "this" is deleted from this point on. We should probably remove this synchronous
// .exec() QMessageBox magic above as it recurses into the event loop.
2015-05-12 16:16:32 +03:00
}
2015-06-26 16:40:34 +03:00
bool AccountSettings : : event ( QEvent * e )
{
if ( e - > type ( ) = = QEvent : : Hide | | e - > type ( ) = = QEvent : : Show ) {
_quotaInfo . setActive ( isVisible ( ) ) ;
}
2015-10-15 18:27:38 +03:00
if ( e - > type ( ) = = QEvent : : Show ) {
2016-01-20 14:41:52 +03:00
// 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 ) ;
}
2015-10-15 18:27:38 +03:00
}
2015-06-26 16:40:34 +03:00
return QWidget : : event ( e ) ;
}
2015-05-12 16:16:32 +03:00
2019-12-09 22:47:42 +03:00
void AccountSettings : : slotStyleChanged ( )
{
customizeStyle ( ) ;
2019-12-19 21:50:21 +03:00
// Notify the other widgets (Dark-/Light-Mode switching)
emit styleChanged ( ) ;
2019-12-09 22:47:42 +03:00
}
void AccountSettings : : customizeStyle ( )
{
QString msg = ui - > connectLabel - > text ( ) ;
Theme : : replaceLinkColorStringBackgroundAware ( msg ) ;
ui - > connectLabel - > setText ( msg ) ;
2019-12-19 21:50:21 +03:00
QColor color = palette ( ) . highlight ( ) . color ( ) ;
ui - > quotaProgressBar - > setStyleSheet ( QString : : fromLatin1 ( progressBarStyleC ) . arg ( color . name ( ) ) ) ;
2019-12-09 22:47:42 +03:00
}
2014-11-10 00:34:07 +03:00
} // namespace OCC
2017-07-04 15:08:41 +03:00
# include "accountsettings.moc"