Skip to content

Commit

Permalink
WiP Introduce a global pause state
Browse files Browse the repository at this point in the history
Addresses #1971
  • Loading branch information
Daniel Molkentin committed Jan 18, 2015
1 parent 91fce3e commit c2957b0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ FolderMan* FolderMan::_instance = 0;
static int msBetweenRequestAndSync = 2000;

FolderMan::FolderMan(QObject *parent) :
QObject(parent),
_syncEnabled( true )
QObject(parent)
, _syncEnabled( true )
, _allPaused( false )
{
_folderChangeSignalMapper = new QSignalMapper(this);
connect(_folderChangeSignalMapper, SIGNAL(mapped(const QString &)),
Expand Down Expand Up @@ -665,6 +666,21 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& )
QTimer::singleShot(200, this, SLOT(slotStartScheduledFolderSync()));
}

void FolderMan::slotSetAllPaused(bool paused)
{
foreach (Folder *f, _folderMap.values()) {
f->slotTerminateSync();
}
setSyncEnabled(false);
_allPaused = paused;
}

bool FolderMan::isAllPaused() const
{
return _allPaused;
}


bool FolderMan::addFolderDefinition(const QString& alias, const QString& sourceFolder,
const QString& targetPath, const QStringList& selectiveSyncBlackList)
{
Expand Down
4 changes: 4 additions & 0 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class FolderMan : public QObject

SocketApi *socketApi();

bool isAllPaused() const;

signals:
/**
* signal to indicate a folder named by alias has changed its sync state.
Expand All @@ -113,6 +115,7 @@ public slots:

void slotFolderSyncStarted();
void slotFolderSyncFinished( const SyncResult& );
void slotSetAllPaused(bool paused);

/**
* Terminates the current folder sync.
Expand Down Expand Up @@ -170,6 +173,7 @@ private slots:

QMap<QString, FolderWatcher*> _folderWatchers;
QPointer<SocketApi> _socketApi;
bool _allPaused;

/** The aliases of folders that shall be synced. */
QQueue<QString> _scheduleQueue;
Expand Down
23 changes: 20 additions & 3 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace OCC {

ownCloudGui::ownCloudGui(Application *parent) :
QObject(parent),
_tray(0),

This comment has been minimized.

Copy link
@dragotin

dragotin May 7, 2015

Contributor

Why was this removed?

This comment has been minimized.

Copy link
@danimo

danimo May 7, 2015

Contributor

_tray is of QPointer<Systray> and is null by default. But I agree it's an independent change.

#if defined(Q_OS_MAC)
_settingsDialog(new SettingsDialogMac(this)),
#else
Expand All @@ -57,7 +56,7 @@ ownCloudGui::ownCloudGui(Application *parent) :
_recentItemsMapper(new QSignalMapper(this)),
_app(parent)
{
_tray = new Systray();
_tray = new Systray;
_tray->setParent(this);

// for the beginning, set the offline icon until the account was verified
Expand Down Expand Up @@ -237,6 +236,12 @@ void ownCloudGui::slotComputeOverallSyncStatus()
if( !_settingsDialog.isNull() )
_settingsDialog->setGeneralErrors( _startupFails );

if (folderMan->isAllPaused()) {
_tray->setIcon(Theme::instance()->syncStateIcon( SyncResult::Paused ));
_tray->setToolTip(tr("Syncing has been paused"));
return;
}

if( !_startupFails.isEmpty() ) {
trayMessage = _startupFails.join(QLatin1String("\n"));
QIcon statusIcon;
Expand Down Expand Up @@ -341,6 +346,8 @@ void ownCloudGui::setupContextMenu()
_contextMenu->addAction(_actionStatus);
_contextMenu->addMenu(_recentActionsMenu);
_contextMenu->addSeparator();
_contextMenu->addAction(_actionPause);
_contextMenu->addSeparator();
}
_contextMenu->addAction(_actionSettings);
if (!Theme::instance()->helpUrl().isEmpty()) {
Expand Down Expand Up @@ -412,8 +419,13 @@ void ownCloudGui::setupActions()
_actionSettings = new QAction(tr("Settings..."), this);
_actionRecent = new QAction(tr("Details..."), this);
_actionRecent->setEnabled( true );
_actionPause = new QAction("Pause syncing", this);
_actionPause->setEnabled( true );
_actionPause->setCheckable(true);
_actionPause->setChecked(FolderMan::instance()->isAllPaused());

QObject::connect(_actionRecent, SIGNAL(triggered(bool)), SLOT(slotShowSyncProtocol()));
QObject::connect(_actionPause, SIGNAL(triggered(bool)), SLOT(slotSetAllPaused(bool)));
QObject::connect(_actionSettings, SIGNAL(triggered(bool)), SLOT(slotShowSettings()));
_actionHelp = new QAction(tr("Help"), this);
QObject::connect(_actionHelp, SIGNAL(triggered(bool)), SLOT(slotHelp()));
Expand Down Expand Up @@ -563,7 +575,6 @@ void ownCloudGui::slotShowSyncProtocol()
_settingsDialog->showActivityPage();
}


void ownCloudGui::slotShutdown()
{
// those do delete on close
Expand Down Expand Up @@ -645,5 +656,11 @@ void ownCloudGui::slotShowShareDialog(const QString &path)
w->show();
}

void ownCloudGui::slotSetAllPaused(bool paused)
{
FolderMan::instance()->slotSetAllPaused(paused);
slotComputeOverallSyncStatus();
}


} // end namespace
2 changes: 2 additions & 0 deletions src/gui/owncloudgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public slots:
void slotOpenPath(const QString& path);
void slotAccountStateChanged();
void slotShowShareDialog(const QString &path);
void slotSetAllPaused(bool paused);

private slots:
void slotDisplayIdle();
Expand Down Expand Up @@ -98,6 +99,7 @@ private slots:
QAction *_actionStatus;
QAction *_actionEstimate;
QAction *_actionRecent;
QAction *_actionPause;
QAction *_actionHelp;
QAction *_actionQuit;
QAction *_actionCrash;
Expand Down

0 comments on commit c2957b0

Please sign in to comment.