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
* the Free Software Foundation ; version 2 of the License .
*
* 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"
2014-07-11 02:31:24 +04:00
# include "utility.h"
# 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"
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 <QDebug>
# include <QDesktopServices>
# 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>
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
2015-12-02 19:59:02 +03:00
# ifdef Q_OS_MAC
# include "settingsdialogmac.h"
# endif
2014-11-10 00:34:07 +03:00
namespace OCC {
2013-07-04 21:59:40 +04: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; "
" } " ;
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 )
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
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
2015-11-13 16:50:07 +03:00
createAccountToolbox ( ) ;
connect ( AccountManager : : instance ( ) , SIGNAL ( accountAdded ( AccountState * ) ) ,
SLOT ( slotAccountAdded ( AccountState * ) ) ) ;
2015-03-27 13:46:03 +03:00
connect ( ui - > _folderList , SIGNAL ( customContextMenuRequested ( QPoint ) ) ,
this , SLOT ( slotCustomContextMenuRequested ( QPoint ) ) ) ;
2013-07-04 21:59:40 +04:00
2015-03-27 13:46:03 +03:00
connect ( ui - > _folderList , SIGNAL ( expanded ( QModelIndex ) ) , this , SLOT ( refreshSelectiveSyncStatus ( ) ) ) ;
connect ( ui - > _folderList , SIGNAL ( collapsed ( QModelIndex ) ) , this , SLOT ( refreshSelectiveSyncStatus ( ) ) ) ;
2015-09-01 16:37:01 +03:00
connect ( ui - > selectiveSyncNotification , SIGNAL ( linkActivated ( QString ) ) ,
this , SLOT ( slotLinkActivated ( QString ) ) ) ;
2015-08-05 13:51:49 +03:00
connect ( _model , SIGNAL ( suggestExpand ( QModelIndex ) ) , ui - > _folderList , SLOT ( expand ( QModelIndex ) ) ) ;
2015-03-27 13:46:03 +03:00
connect ( _model , SIGNAL ( dirtyChanged ( ) ) , this , SLOT ( refreshSelectiveSyncStatus ( ) ) ) ;
2015-06-12 12:28:56 +03:00
refreshSelectiveSyncStatus ( ) ;
2015-10-15 19:50:54 +03:00
connect ( _model , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) ,
this , SLOT ( refreshSelectiveSyncStatus ( ) ) ) ;
2013-07-04 21:59:40 +04:00
2013-08-15 19:00:01 +04:00
QAction * resetFolderAction = new QAction ( this ) ;
resetFolderAction - > setShortcut ( QKeySequence ( Qt : : Key_F5 ) ) ;
connect ( resetFolderAction , SIGNAL ( triggered ( ) ) , SLOT ( slotResetCurrentFolder ( ) ) ) ;
addAction ( resetFolderAction ) ;
2013-10-30 19:58:08 +04:00
QAction * syncNowAction = new QAction ( this ) ;
syncNowAction - > setShortcut ( QKeySequence ( Qt : : Key_F6 ) ) ;
connect ( syncNowAction , SIGNAL ( triggered ( ) ) , SLOT ( slotSyncCurrentFolderNow ( ) ) ) ;
addAction ( syncNowAction ) ;
2015-10-19 19:23:56 +03:00
connect ( ui - > _folderList , SIGNAL ( clicked ( const QModelIndex & ) ) ,
this , SLOT ( slotFolderListClicked ( const QModelIndex & ) ) ) ;
2013-07-04 21:59:40 +04:00
2015-03-27 13:46:03 +03:00
connect ( ui - > selectiveSyncApply , SIGNAL ( clicked ( ) ) , _model , SLOT ( slotApplySelectiveSync ( ) ) ) ;
connect ( ui - > selectiveSyncCancel , SIGNAL ( clicked ( ) ) , _model , SLOT ( resetFolders ( ) ) ) ;
connect ( FolderMan : : instance ( ) , SIGNAL ( folderListLoaded ( Folder : : Map ) ) , _model , SLOT ( resetFolders ( ) ) ) ;
connect ( this , SIGNAL ( folderChanged ( ) ) , _model , SLOT ( resetFolders ( ) ) ) ;
2013-08-18 19:00:37 +04:00
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
2015-04-17 18:56:17 +03:00
connect ( _accountState , SIGNAL ( stateChanged ( int ) ) , SLOT ( slotAccountStateChanged ( int ) ) ) ;
slotAccountStateChanged ( _accountState - > state ( ) ) ;
2015-06-26 16:40:34 +03:00
connect ( & _quotaInfo , SIGNAL ( quotaUpdated ( qint64 , qint64 ) ) ,
2015-04-17 18:56:17 +03:00
this , SLOT ( slotUpdateQuota ( qint64 , qint64 ) ) ) ;
2015-11-13 16:50:07 +03:00
}
void AccountSettings : : createAccountToolbox ( )
{
QMenu * menu = new QMenu ( ) ;
2015-11-16 17:50:32 +03:00
_addAccountAction = new QAction ( tr ( " Add new " ) , this ) ;
menu - > addAction ( _addAccountAction ) ;
connect ( _addAccountAction , SIGNAL ( triggered ( bool ) ) , SLOT ( slotOpenAccountWizard ( ) ) ) ;
_toggleSignInOutAction = new QAction ( tr ( " Sign out " ) , this ) ;
2015-11-13 16:50:07 +03:00
connect ( _toggleSignInOutAction , SIGNAL ( triggered ( bool ) ) , SLOT ( slotToggleSignInState ( ) ) ) ;
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 ) ;
connect ( action , SIGNAL ( triggered ( bool ) ) , SLOT ( slotDeleteAccount ( ) ) ) ;
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
}
void AccountSettings : : slotOpenAccountWizard ( )
{
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
topLevelWidget ( ) - > close ( ) ;
}
2015-12-02 19:59:02 +03:00
# ifdef Q_OS_MAC
qDebug ( ) < < parent ( ) < < topLevelWidget ( ) ;
SettingsDialogMac * sd = qobject_cast < SettingsDialogMac * > ( topLevelWidget ( ) ) ;
if ( sd ) {
sd - > showActivityPage ( ) ;
} else {
qFatal ( " nope " ) ;
}
# endif
2015-11-13 16:50:07 +03:00
OwncloudSetupWizard : : runWizard ( qApp , SLOT ( slotownCloudWizardDone ( int ) ) , 0 ) ;
}
2015-12-02 18:31:58 +03:00
// FIXME: Use same code path as ownCloudGui::slotLogout()
2015-11-13 16:50:07 +03:00
void AccountSettings : : slotToggleSignInState ( )
{
2015-12-02 18:31:58 +03:00
bool signedOutState = _accountState - > isSignedOut ( ) ;
if ( ! signedOutState ) {
_accountState - > account ( ) - > credentials ( ) - > invalidateToken ( ) ;
}
_accountState - > setSignedOut ( ! signedOutState ) ;
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
}
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 ;
}
QString alias = _model - > data ( index , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
if ( alias . isEmpty ( ) ) {
return ;
}
tv - > setCurrentIndex ( index ) ;
bool folderPaused = _model - > data ( index , FolderStatusDelegate : : FolderSyncPaused ) . toBool ( ) ;
2015-09-29 18:00:06 +03:00
bool folderConnected = _model - > data ( index , FolderStatusDelegate : : FolderAccountConnected ) . toBool ( ) ;
2015-03-27 13:46:03 +03:00
QMenu * menu = new QMenu ( tv ) ;
menu - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2015-09-29 18:00:06 +03:00
QAction * ac = menu - > addAction ( tr ( " Open folder " ) ) ;
connect ( ac , SIGNAL ( triggered ( bool ) ) , this , SLOT ( slotOpenCurrentFolder ( ) ) ) ;
2015-10-27 14:12:21 +03:00
ac = menu - > addAction ( tr ( " Choose what to sync " ) ) ;
2015-09-29 18:00:06 +03:00
ac - > setEnabled ( folderConnected ) ;
connect ( ac , SIGNAL ( triggered ( bool ) ) , this , SLOT ( doExpand ( ) ) ) ;
ac = menu - > addAction ( folderPaused ? tr ( " Resume sync " ) : tr ( " Pause sync " ) ) ;
connect ( ac , SIGNAL ( triggered ( bool ) ) , this , SLOT ( slotEnableCurrentFolder ( ) ) ) ;
2015-10-27 14:12:21 +03:00
ac = menu - > addAction ( tr ( " Remove folder sync connection " ) ) ;
2015-09-29 18:00:06 +03:00
connect ( ac , SIGNAL ( triggered ( bool ) ) , this , SLOT ( slotRemoveCurrentFolder ( ) ) ) ;
2015-03-27 13:46:03 +03:00
menu - > exec ( 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 ( ) ) {
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 ( ) ) ;
if ( FolderStatusDelegate : : optionsButtonRect ( tv - > visualRect ( indx ) ) . contains ( pos ) ) {
slotCustomContextMenuRequested ( pos ) ;
2015-10-19 19:23:56 +03:00
return ;
}
// 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
connect ( folderWizard , SIGNAL ( accepted ( ) ) , SLOT ( slotFolderWizardAccepted ( ) ) ) ;
connect ( folderWizard , SIGNAL ( rejected ( ) ) , SLOT ( slotFolderWizardRejected ( ) ) ) ;
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
qDebug ( ) < < " * Folder wizard completed " ;
2015-04-24 11:18:33 +03:00
FolderDefinition definition ;
definition . alias = folderWizard - > field ( QLatin1String ( " alias " ) ) . toString ( ) ;
2015-09-17 13:14:35 +03:00
definition . localPath = FolderDefinition : : prepareLocalPath (
folderWizard - > field ( QLatin1String ( " sourceFolder " ) ) . toString ( ) ) ;
2015-04-24 11:18:33 +03:00
definition . targetPath = 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 ( ) ) {
qDebug ( ) < < " Creating folder " < < definition . localPath ;
if ( ! dir . mkpath ( " . " ) ) {
QMessageBox : : warning ( this , tr ( " Folder creation failed " ) ,
tr ( " <p>Could not create local folder <i>%1</i>. " )
. arg ( QDir : : toNativeSeparators ( definition . localPath ) ) ) ;
return ;
}
}
}
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 .
2015-07-15 15:51:37 +03:00
* The default is to not sync hidden files
*/
2015-08-10 12:03:57 +03:00
definition . ignoreHiddenFiles = folderMan - > ignoreHiddenFiles ( ) ;
2015-07-15 15:51:37 +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 ( " / " ) ) ;
2013-07-22 15:59:52 +04:00
folderMan - > slotScheduleAllFolders ( ) ;
2013-07-04 21:59:40 +04:00
emit folderChanged ( ) ;
}
}
void AccountSettings : : slotFolderWizardRejected ( )
{
qDebug ( ) < < " * 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 ( )
{
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
if ( selected . isValid ( ) ) {
2013-09-19 23:27:43 +04:00
int row = selected . row ( ) ;
2013-07-04 21:59:40 +04:00
QString alias = _model - > data ( selected , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
qDebug ( ) < < " Remove Folder alias " < < alias ;
if ( ! alias . isEmpty ( ) ) {
2015-08-21 12:01:01 +03:00
QMessageBox messageBox ( QMessageBox : : Question ,
2015-10-27 14:12:21 +03:00
tr ( " Confirm Folder Sync Connection Removal " ) ,
2015-08-21 12:01:01 +03:00
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 ( alias ) ,
QMessageBox : : NoButton ,
this ) ;
QPushButton * yesButton =
2015-10-27 14:12:21 +03:00
messageBox . addButton ( tr ( " Remove Folder Sync Connection " ) , QMessageBox : : YesRole ) ;
2015-08-21 12:01:01 +03:00
messageBox . addButton ( tr ( " Cancel " ) , QMessageBox : : NoRole ) ;
messageBox . exec ( ) ;
if ( messageBox . clickedButton ( ) ! = yesButton ) {
2013-07-04 21:59:40 +04:00
return ;
}
2013-09-19 23:27:43 +04:00
2013-07-22 15:59:52 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
2015-04-28 16:13:39 +03:00
folderMan - > slotRemoveFolder ( folderMan - > folder ( alias ) ) ;
2013-09-19 23:27:43 +04:00
_model - > removeRow ( row ) ;
2013-12-09 19:23:00 +04:00
// single folder fix to show add-button and hide remove-button
2013-07-04 21:59:40 +04:00
emit folderChanged ( ) ;
}
}
}
2013-12-12 19:38:45 +04:00
2013-07-04 21:59:40 +04:00
void AccountSettings : : slotResetCurrentFolder ( )
{
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
if ( selected . isValid ( ) ) {
QString alias = _model - > data ( selected , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
2015-03-27 13:46:03 +03:00
if ( alias . isEmpty ( ) )
return ;
2013-07-04 21:59:40 +04:00
int ret = QMessageBox : : question ( 0 , tr ( " Confirm Folder Reset " ) ,
tr ( " <p>Do you really want to reset folder <i>%1</i> and rebuild your client database?</p> "
2013-08-15 19:00:01 +04:00
" <p><b>Note:</b> This function is designed for maintenance purposes only. "
" No files will be removed, but this can cause significant data traffic and "
" take several minutes or hours to complete, depending on the size of the folder. "
" Only use this option if advised by your administrator.</p> " ) . arg ( alias ) ,
2013-07-04 21:59:40 +04:00
QMessageBox : : Yes | QMessageBox : : No ) ;
if ( ret = = QMessageBox : : Yes ) {
2013-07-22 15:59:52 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
2015-09-01 12:39:55 +03:00
if ( Folder * f = folderMan - > folder ( alias ) ) {
f - > slotTerminateSync ( ) ;
f - > wipe ( ) ;
}
2013-07-22 15:59:52 +04:00
folderMan - > slotScheduleAllFolders ( ) ;
2013-07-04 21:59:40 +04:00
}
}
}
2015-08-13 12:53:00 +03:00
void AccountSettings : : slotOpenCurrentFolder ( )
2013-07-04 21:59:40 +04:00
{
2015-08-13 12:53:00 +03:00
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
2013-07-04 21:59:40 +04:00
2015-08-13 12:53:00 +03:00
if ( selected . isValid ( ) ) {
QString alias = _model - > data ( selected , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
emit openFolderAlias ( alias ) ;
}
2013-07-04 21:59:40 +04:00
}
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 ( ) ) {
2013-09-11 12:24:31 +04:00
ui - > connectLabel - > setText ( message ) ;
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 ) ;
const QString msg = errors . join ( QLatin1String ( " \n " ) ) ;
qDebug ( ) < < msg ;
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 ( )
{
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
if ( selected . isValid ( ) ) {
QString alias = _model - > data ( selected , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
2014-08-19 15:58:20 +04:00
if ( alias . isEmpty ( ) ) {
qDebug ( ) < < " Empty alias to enable. " ;
return ;
}
2013-07-04 21:59:40 +04:00
2014-08-19 15:58:20 +04:00
FolderMan * folderMan = FolderMan : : instance ( ) ;
2013-07-04 21:59:40 +04:00
2014-08-19 15:58:20 +04:00
qDebug ( ) < < " Application: enable folder with alias " < < alias ;
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
2014-08-19 15:58:20 +04:00
QWidget * parent = 0 ;
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
}
f - > setSyncPaused ( ! currentlyPaused ) ; // toggle the pause setting
2015-04-28 16:13:39 +03:00
folderMan - > slotSetFolderPaused ( f , ! 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
}
}
2013-10-30 19:58:08 +04:00
void AccountSettings : : slotSyncCurrentFolderNow ( )
2013-10-30 19:25:03 +04:00
{
QModelIndex selected = ui - > _folderList - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! selected . isValid ( ) )
return ;
QString alias = _model - > data ( selected , FolderStatusDelegate : : FolderAliasRole ) . toString ( ) ;
FolderMan * folderMan = FolderMan : : instance ( ) ;
2015-04-28 16:13:39 +03:00
folderMan - > slotScheduleSync ( folderMan - > folder ( alias ) ) ;
2013-10-30 19:25:03 +04: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
}
2013-11-25 18:33:35 +04:00
void AccountSettings : : slotAccountStateChanged ( int state )
2013-11-04 19:36:23 +04:00
{
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
QString server = QString : : fromLatin1 ( " <a href= \" %1 \" >%2</a> " ) . arg ( account - > url ( ) . toString ( ) , safeUrl . toString ( ) ) ;
QString serverWithUser = server ;
if ( AbstractCredentials * cred = account - > credentials ( ) ) {
serverWithUser = tr ( " %1 as <i>%2</i> " ) . arg ( server , cred - > user ( ) ) ;
}
2015-07-15 15:02:45 +03:00
if ( state = = AccountState : : Connected ) {
2015-07-15 12:37:38 +03:00
showConnectionLabel ( tr ( " Connected to %1. " ) . arg ( serverWithUser ) ) ;
} else if ( state = = AccountState : : ServiceUnavailable ) {
showConnectionLabel ( tr ( " Server %1 is temporarily unavailable. " ) . arg ( server ) ) ;
} else if ( state = = AccountState : : SignedOut ) {
showConnectionLabel ( tr ( " Signed out from %1. " ) . arg ( serverWithUser ) ) ;
2013-11-04 19:36:23 +04:00
} else {
2015-07-15 12:37:38 +03:00
showConnectionLabel ( tr ( " No connection to %1 at %2. " )
2013-11-07 15:22:17 +04:00
. arg ( Theme : : instance ( ) - > appNameGUI ( ) ,
2015-07-15 12:37:38 +03:00
server ) , _accountState - > connectionErrors ( ) ) ;
2013-11-04 19:36:23 +04:00
}
} else {
// ownCloud is not yet configured.
showConnectionLabel ( tr ( " No %1 connection configured. " ) . arg ( Theme : : instance ( ) - > appNameGUI ( ) ) ) ;
}
2015-09-25 13:22:51 +03:00
/* Allow to expand the item if the account is connected. */
ui - > _folderList - > setItemsExpandable ( state = = AccountState : : Connected ) ;
/* check if there are expanded root items, if so, close them, if the state is different from being Connected. */
if ( state ! = AccountState : : Connected ) {
int i ;
for ( i = 0 ; i < _model - > rowCount ( ) ; + + i ) {
if ( ui - > _folderList - > isExpanded ( _model - > index ( i ) ) )
ui - > _folderList - > setExpanded ( _model - > index ( i ) , false ) ;
}
}
2015-11-13 16:50:07 +03:00
/* set the correct label for the Account toolbox button */
if ( _accountState ) {
bool isConnected = _accountState - > isConnected ( ) ;
if ( isConnected ) {
_toggleSignInOutAction - > setText ( tr ( " Sign out " ) ) ;
} else {
_toggleSignInOutAction - > setText ( tr ( " Sign in " ) ) ;
}
}
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 {
qDebug ( ) < < " 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 ( )
{
bool shouldBeVisible = _model - > isDirty ( ) ;
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 ;
}
2015-06-12 12:28:56 +03:00
auto undecidedList = folder - > journalDb ( ) - > getSelectiveSyncList ( SyncJournalDb : : SelectiveSyncUndecidedList ) ;
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 ( ) ) {
msg + = QString : : fromLatin1 ( " <a href= \" %1?folder=%2 \" >%1</a> " ) . arg ( myFolder ) . arg ( folder - > alias ( ) ) ;
} 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 ( ) ) {
2015-08-28 16:51:11 +03:00
ui - > selectiveSyncNotification - > setVisible ( false ) ;
2015-06-12 12:28:56 +03:00
ui - > selectiveSyncNotification - > setText ( QString ( ) ) ;
} else {
2015-08-28 16:51:11 +03:00
ui - > selectiveSyncNotification - > setVisible ( true ) ;
2015-10-05 13:06:26 +03:00
QString wholeMsg = tr ( " There are new folders that were not synchronized because they are too big: " ) + msg ;
ui - > selectiveSyncNotification - > setText ( wholeMsg ) ;
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 ) ;
if ( ! shouldBeVisible ) {
connect ( anim , SIGNAL ( finished ( ) ) , ui - > selectiveSyncStatus , SLOT ( hide ( ) ) ) ;
}
}
}
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
}
2015-12-01 21:21:52 +03:00
_model - > setAccountState ( 0 ) ; // Else it might access during destruction. This should be better handled by it having a QSharedPointer
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 ) {
ui - > _folderList - > setExpanded ( _model - > index ( 0 , 0 ) , true ) ;
}
2015-06-26 16:40:34 +03:00
return QWidget : : event ( e ) ;
}
2015-05-12 16:16:32 +03:00
2014-11-10 00:34:07 +03:00
} // namespace OCC