mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
simplified the folder change notification to the GUI app: Reduced
to one signal stateChanged(), provided an easy api to get the new state and last sync result by alias in folderman.
This commit is contained in:
parent
b52f9f534d
commit
e63fcdc9f0
6 changed files with 66 additions and 29 deletions
|
@ -58,6 +58,9 @@ Application::Application(int argc, char **argv) :
|
|||
|
||||
_folderMan = new FolderMan();
|
||||
|
||||
connect( _folderMan, SIGNAL(folderSyncStateChange(QString)),
|
||||
this,SLOT(slotSyncStateChange(QString)));
|
||||
|
||||
setQuitOnLastWindowClosed(false);
|
||||
|
||||
_folderWizard = new FolderWizard();
|
||||
|
@ -66,10 +69,12 @@ Application::Application(int argc, char **argv) :
|
|||
|
||||
connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)),
|
||||
SLOT(slotRemoveFolder(const QString&)));
|
||||
#if 0
|
||||
connect( _statusDialog, SIGNAL(fetchFolderAlias(const QString&)),
|
||||
SLOT(slotFetchFolder( const QString&)));
|
||||
connect( _statusDialog, SIGNAL(pushFolderAlias(const QString&)),
|
||||
SLOT(slotPushFolder( const QString&)));
|
||||
#endif
|
||||
connect( _statusDialog, SIGNAL(enableFolderAlias(QString,bool)),
|
||||
SLOT(slotEnableFolder(QString,bool)));
|
||||
connect( _statusDialog, SIGNAL(infoFolderAlias(const QString&)),
|
||||
|
@ -134,7 +139,6 @@ void Application::slotTrayClicked( QSystemTrayIcon::ActivationReason reason )
|
|||
_owncloudSetupWizard->wizard()->show();
|
||||
}
|
||||
|
||||
|
||||
// if no config file is there, start the configuration wizard.
|
||||
MirallConfigFile cfgFile;
|
||||
|
||||
|
@ -143,15 +147,10 @@ void Application::slotTrayClicked( QSystemTrayIcon::ActivationReason reason )
|
|||
_owncloudSetupWizard->startWizard();
|
||||
} else {
|
||||
_statusDialog->setOCUrl( QUrl( cfgFile.ownCloudUrl()) );
|
||||
|
||||
_statusDialog->setFolderList( _folderMan->map() );
|
||||
_statusDialog->show();
|
||||
}
|
||||
_folderMan->restoreEnabledFolders();
|
||||
|
||||
// FIXME:
|
||||
// if ( !_folderMap.isEmpty() && _statusDialog->isVisible() ) {
|
||||
// _statusDialog->setFolderList( _folderMap );
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,9 +216,7 @@ void Application::slotAddFolder()
|
|||
if( goodData ) {
|
||||
_folderMan->addFolderDefinition( backend, alias, sourceFolder, targetPath, onlyThisLAN );
|
||||
}
|
||||
#ifdef PUT_TO_FOLDERMAN
|
||||
|
||||
#endif
|
||||
} else {
|
||||
qDebug() << "* Folder wizard cancelled";
|
||||
}
|
||||
|
@ -353,17 +350,14 @@ void Application::slotConfigure()
|
|||
_folderMan->restoreEnabledFolders();
|
||||
}
|
||||
|
||||
// FIXME: Better start- and end handling
|
||||
void Application::slotFolderSyncStarted()
|
||||
void Application::slotSyncStateChange( const QString& alias )
|
||||
{
|
||||
_tray->setIcon(QIcon::fromTheme(FOLDER_SYNC_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_SYNC_ICON))));
|
||||
}
|
||||
Folder::SyncState state = _folderMan->syncState( alias );
|
||||
|
||||
void Application::slotFolderSyncFinished(const SyncResult &result)
|
||||
{
|
||||
// if( _folderSyncCount == 0 ) {
|
||||
computeOverallSyncStatus();
|
||||
// }
|
||||
_statusDialog->setFolderList( _folderMan->map() );
|
||||
if( state == Folder::Waiting ) computeOverallSyncStatus();
|
||||
|
||||
qDebug() << "Sync state changed for folder " << alias << ": " << state;
|
||||
}
|
||||
|
||||
void Application::computeOverallSyncStatus()
|
||||
|
|
|
@ -55,9 +55,7 @@ protected slots:
|
|||
void slotInfoFolder( const QString& );
|
||||
void slotConfigure();
|
||||
|
||||
void slotFolderSyncStarted();
|
||||
void slotFolderSyncFinished(const SyncResult &);
|
||||
|
||||
void slotSyncStateChange( const QString& );
|
||||
protected:
|
||||
|
||||
void setupActions();
|
||||
|
|
|
@ -38,7 +38,8 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
|
|||
_onlyOnlineEnabled(false),
|
||||
_onlyThisLANEnabled(false),
|
||||
_online(false),
|
||||
_enabled(true)
|
||||
_enabled(true),
|
||||
_syncState( Unknown )
|
||||
{
|
||||
_openAction = new QAction(QIcon::fromTheme(FOLDER_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_ICON))), path, this);
|
||||
_openAction->setIconVisibleInMenu(true);
|
||||
|
@ -197,6 +198,8 @@ void Folder::slotSyncStarted()
|
|||
{
|
||||
// disable events until syncing is done
|
||||
_watcher->setEventsEnabled(false);
|
||||
_syncState = Running;
|
||||
emit syncStateChange();
|
||||
_openAction->setIcon(QIcon::fromTheme(FOLDER_SYNC_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_SYNC_ICON))));
|
||||
}
|
||||
|
||||
|
@ -204,6 +207,8 @@ void Folder::slotSyncFinished(const SyncResult &result)
|
|||
{
|
||||
_lastSyncResult = result;
|
||||
_openAction->setIcon(icon(22));
|
||||
_syncState = Waiting;
|
||||
emit syncStateChange();
|
||||
|
||||
// reenable the poll timer if folder is sync enabled
|
||||
if( syncEnabled() ) {
|
||||
|
|
|
@ -39,6 +39,8 @@ public:
|
|||
Folder(const QString &alias, const QString &path, QObject *parent = 0L);
|
||||
virtual ~Folder();
|
||||
|
||||
enum SyncState{ Unknown, Running, Waiting };
|
||||
|
||||
typedef QHash<QString, Folder*> Map;
|
||||
|
||||
/**
|
||||
|
@ -116,6 +118,8 @@ public:
|
|||
*/
|
||||
SyncResult lastSyncResult() const;
|
||||
|
||||
SyncState syncState() { return _syncState; }
|
||||
|
||||
/**
|
||||
* set the backend description string.
|
||||
*/
|
||||
|
@ -144,7 +148,7 @@ protected:
|
|||
void setPollInterval(int seconds);
|
||||
|
||||
signals:
|
||||
|
||||
void syncStateChange();
|
||||
void syncStarted();
|
||||
void syncFinished(const SyncResult &result);
|
||||
|
||||
|
@ -169,10 +173,11 @@ private:
|
|||
bool _onlyOnlineEnabled;
|
||||
bool _onlyThisLANEnabled;
|
||||
QNetworkConfigurationManager _networkMgr;
|
||||
bool _online;
|
||||
bool _enabled;
|
||||
bool _online;
|
||||
bool _enabled;
|
||||
SyncResult _lastSyncResult;
|
||||
QString _backend;
|
||||
SyncState _syncState;
|
||||
QString _backend;
|
||||
|
||||
protected slots:
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
#include <QUrl>
|
||||
#include <QSignalMapper>
|
||||
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/unisonfolder.h"
|
||||
|
@ -37,6 +38,10 @@ FolderMan::FolderMan(QObject *parent) :
|
|||
QDir storageDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||
storageDir.mkpath("folders");
|
||||
_folderConfigPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/folders";
|
||||
|
||||
_folderChangeSignalMapper = new QSignalMapper(this);
|
||||
connect(_folderChangeSignalMapper, SIGNAL(mapped(const QString &)),
|
||||
this, SIGNAL(folderSyncStateChange(const QString &)));
|
||||
}
|
||||
|
||||
FolderMan::~FolderMan()
|
||||
|
@ -159,9 +164,11 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
|
|||
folder->setOnlyThisLANEnabled(settings.value("folder/onlyThisLAN", false).toBool());
|
||||
|
||||
_folderMap[file] = folder;
|
||||
|
||||
qDebug() << "Adding folder to Folder Map " << folder;
|
||||
QObject::connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
|
||||
QObject::connect(folder, SIGNAL(syncFinished(const SyncResult &)), SLOT(slotFolderSyncFinished(const SyncResult &)));
|
||||
/* Use a signal mapper to connect the signals to the alias */
|
||||
connect(folder, SIGNAL(syncStateChange()), _folderChangeSignalMapper, SLOT(map()));
|
||||
_folderChangeSignalMapper->setMapping( folder, folder->alias() );
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
@ -200,14 +207,25 @@ SyncResult FolderMan::syncResult( const QString& alias )
|
|||
{
|
||||
SyncResult res;
|
||||
if( _folderMap.contains( alias ) ) {
|
||||
Folder *f = _folderMap[alias];
|
||||
res = f->lastSyncResult();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Folder::SyncState FolderMan::syncState( const QString& alias )
|
||||
{
|
||||
Folder::SyncState res( Folder::Unknown );
|
||||
|
||||
if( _folderMap.contains( alias ) ) {
|
||||
Folder *f = _folderMap[alias];
|
||||
res = f->syncState();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void FolderMan::slotFolderSyncStarted( )
|
||||
{
|
||||
_folderSyncCount++;
|
||||
}
|
||||
|
||||
void FolderMan::slotFolderSyncFinished( const SyncResult& )
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "mirall/folder.h"
|
||||
#include "mirall/folderwatcher.h"
|
||||
|
||||
class QSignalMapper;
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
class SyncResult;
|
||||
|
@ -52,8 +54,22 @@ public:
|
|||
*/
|
||||
Folder *addFolderDefinition( const QString&, const QString&, const QString&, const QString&, bool );
|
||||
|
||||
/**
|
||||
* return the last sync result by alias
|
||||
*/
|
||||
SyncResult syncResult( const QString& );
|
||||
|
||||
/**
|
||||
* returns the current sync state of the folder named by alias
|
||||
*/
|
||||
Folder::SyncState syncState( const QString& );
|
||||
|
||||
signals:
|
||||
/**
|
||||
* signal to indicate a folder named by alias has changed its sync state.
|
||||
* Get the state via the Folder Map or the syncResult and syncState methods.
|
||||
*/
|
||||
void folderSyncStateChange( const QString & );
|
||||
|
||||
public slots:
|
||||
void slotRemoveFolder( const QString& );
|
||||
|
@ -76,6 +92,7 @@ private:
|
|||
QHash<QString, bool> _folderEnabledMap;
|
||||
QString _folderConfigPath;
|
||||
OwncloudSetup *_ownCloudSetup;
|
||||
QSignalMapper *_folderChangeSignalMapper;
|
||||
|
||||
// counter tracking number of folders doing a sync
|
||||
int _folderSyncCount;
|
||||
|
|
Loading…
Reference in a new issue