2011-04-06 13:48:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
|
|
|
*
|
|
|
|
* 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; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-10-13 15:55:52 +04:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QtGui>
|
2012-01-24 01:10:01 +04:00
|
|
|
#include <QHash>
|
|
|
|
#include <QHashIterator>
|
2012-02-15 17:44:09 +04:00
|
|
|
#include <QUrl>
|
2012-02-21 14:50:19 +04:00
|
|
|
#include <QDesktopServices>
|
2012-02-23 14:44:44 +04:00
|
|
|
#include <QSplashScreen>
|
2011-02-17 02:21:45 +03:00
|
|
|
|
|
|
|
#include "mirall/application.h"
|
|
|
|
#include "mirall/folder.h"
|
2011-09-30 13:49:19 +04:00
|
|
|
#include "mirall/folderwatcher.h"
|
2011-04-05 20:31:14 +04:00
|
|
|
#include "mirall/folderwizard.h"
|
2011-04-06 17:22:40 +04:00
|
|
|
#include "mirall/networklocation.h"
|
2011-03-23 01:03:43 +03:00
|
|
|
#include "mirall/unisonfolder.h"
|
2012-02-15 17:44:09 +04:00
|
|
|
#include "mirall/owncloudfolder.h"
|
2011-09-26 17:00:12 +04:00
|
|
|
#include "mirall/statusdialog.h"
|
2012-02-17 14:11:18 +04:00
|
|
|
#include "mirall/owncloudsetupwizard.h"
|
2012-03-29 11:41:30 +04:00
|
|
|
#include "mirall/owncloudinfo.h"
|
2012-02-16 13:42:44 +04:00
|
|
|
#include "mirall/theme.h"
|
2012-02-17 14:11:18 +04:00
|
|
|
#include "mirall/mirallconfigfile.h"
|
2012-04-02 22:10:29 +04:00
|
|
|
#include "mirall/updatedetector.h"
|
2012-02-16 13:42:44 +04:00
|
|
|
|
|
|
|
#include "mirall/miralltheme.h"
|
|
|
|
#include "mirall/owncloudtheme.h"
|
2011-09-26 15:12:00 +04:00
|
|
|
|
2011-04-07 21:04:07 +04:00
|
|
|
#ifdef WITH_CSYNC
|
|
|
|
#include "mirall/csyncfolder.h"
|
|
|
|
#endif
|
2011-03-16 16:50:34 +03:00
|
|
|
#include "mirall/inotify.h"
|
2011-02-17 02:21:45 +03:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
Application::Application(int argc, char **argv) :
|
2011-04-04 13:36:44 +04:00
|
|
|
QApplication(argc, argv),
|
2012-03-31 13:31:28 +04:00
|
|
|
_tray(0),
|
2011-04-04 14:23:30 +04:00
|
|
|
_networkMgr(new QNetworkConfigurationManager(this)),
|
2012-03-29 11:41:30 +04:00
|
|
|
_contextMenu(0),
|
2012-04-02 22:10:29 +04:00
|
|
|
_ocInfo(0),
|
|
|
|
_updateDetector(0)
|
2011-02-17 02:21:45 +03:00
|
|
|
{
|
2012-03-31 13:31:28 +04:00
|
|
|
|
2012-02-16 13:42:44 +04:00
|
|
|
#ifdef OWNCLOUD_CLIENT
|
|
|
|
_theme = new ownCloudTheme();
|
|
|
|
#else
|
|
|
|
_theme = new mirallTheme();
|
|
|
|
#endif
|
2012-02-17 15:16:48 +04:00
|
|
|
setApplicationName( _theme->appName() );
|
2012-03-31 13:31:28 +04:00
|
|
|
setWindowIcon( _theme->applicationIcon() );
|
2012-02-23 14:44:44 +04:00
|
|
|
|
|
|
|
_splash = new QSplashScreen( _theme->splashScreen() );
|
|
|
|
_splash->show();
|
|
|
|
|
|
|
|
processEvents();
|
|
|
|
|
2012-03-26 13:02:01 +04:00
|
|
|
// Internationalization support.
|
2012-04-18 14:10:14 +04:00
|
|
|
qDebug() << "################## ownCloud client " << QLocale::system().name();
|
|
|
|
|
2012-03-26 13:02:01 +04:00
|
|
|
QTranslator qtTranslator;
|
|
|
|
qtTranslator.load("qt_" + QLocale::system().name(),
|
|
|
|
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
installTranslator(&qtTranslator);
|
|
|
|
|
|
|
|
QTranslator myappTranslator;
|
|
|
|
myappTranslator.load("mirall_" + QLocale::system().name());
|
|
|
|
installTranslator(&myappTranslator);
|
|
|
|
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
_folderMan = new FolderMan();
|
2012-02-19 00:21:58 +04:00
|
|
|
connect( _folderMan, SIGNAL(folderSyncStateChange(QString)),
|
|
|
|
this,SLOT(slotSyncStateChange(QString)));
|
|
|
|
|
2012-02-21 14:50:19 +04:00
|
|
|
/* use a signal mapper to map the open requests to the alias names */
|
|
|
|
_folderOpenActionMapper = new QSignalMapper(this);
|
|
|
|
connect(_folderOpenActionMapper, SIGNAL(mapped(const QString &)),
|
|
|
|
this, SLOT(slotFolderOpenAction(const QString &)));
|
|
|
|
|
2011-04-05 20:31:14 +04:00
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
2012-03-26 17:19:40 +04:00
|
|
|
_folderWizard = new FolderWizard( 0, _theme );
|
2012-03-30 15:57:02 +04:00
|
|
|
|
|
|
|
_ocInfo = new ownCloudInfo( QString(), this );
|
|
|
|
connect( _ocInfo,SIGNAL(ownCloudInfoFound(QString,QString)),
|
|
|
|
SLOT(slotOwnCloudFound(QString,QString)));
|
|
|
|
|
2012-04-10 16:51:45 +04:00
|
|
|
connect( _ocInfo,SIGNAL(noOwncloudFound(QNetworkReply*)),
|
|
|
|
SLOT(slotNoOwnCloudFound(QNetworkReply*)));
|
2012-03-30 15:57:02 +04:00
|
|
|
|
2012-03-30 22:42:40 +04:00
|
|
|
connect( _ocInfo,SIGNAL(ownCloudDirExists(QString,QNetworkReply*)),
|
|
|
|
this,SLOT(slotAuthCheck(QString,QNetworkReply*)));
|
|
|
|
|
2012-03-26 17:19:40 +04:00
|
|
|
_owncloudSetupWizard = new OwncloudSetupWizard( _folderMan, _theme );
|
2012-03-30 15:57:02 +04:00
|
|
|
connect( _owncloudSetupWizard, SIGNAL(ownCloudWizardDone(int)), SLOT(slotStartFolderSetup()));
|
2012-02-21 16:26:39 +04:00
|
|
|
|
2012-02-20 19:45:27 +04:00
|
|
|
_statusDialog = new StatusDialog( _theme );
|
2012-02-21 16:26:39 +04:00
|
|
|
connect( _statusDialog, SIGNAL(addASync()), this, SLOT(slotAddFolder()) );
|
2011-04-04 13:36:44 +04:00
|
|
|
|
2011-10-13 15:55:52 +04:00
|
|
|
connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)),
|
|
|
|
SLOT(slotRemoveFolder(const QString&)));
|
2012-02-19 00:21:58 +04:00
|
|
|
#if 0
|
2011-10-18 12:22:24 +04:00
|
|
|
connect( _statusDialog, SIGNAL(fetchFolderAlias(const QString&)),
|
|
|
|
SLOT(slotFetchFolder( const QString&)));
|
2011-12-05 15:01:39 +04:00
|
|
|
connect( _statusDialog, SIGNAL(pushFolderAlias(const QString&)),
|
|
|
|
SLOT(slotPushFolder( const QString&)));
|
2012-02-19 00:21:58 +04:00
|
|
|
#endif
|
2011-12-12 20:47:30 +04:00
|
|
|
connect( _statusDialog, SIGNAL(enableFolderAlias(QString,bool)),
|
|
|
|
SLOT(slotEnableFolder(QString,bool)));
|
2012-01-24 01:10:01 +04:00
|
|
|
connect( _statusDialog, SIGNAL(infoFolderAlias(const QString&)),
|
|
|
|
SLOT(slotInfoFolder( const QString&)));
|
2012-03-08 15:08:53 +04:00
|
|
|
connect( _statusDialog, SIGNAL(openFolderAlias(const QString&)),
|
|
|
|
SLOT(slotFolderOpenAction(QString)));
|
2011-12-12 20:47:30 +04:00
|
|
|
|
2011-04-04 13:36:44 +04:00
|
|
|
qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline");
|
|
|
|
foreach (QNetworkConfiguration netCfg, _networkMgr->allConfigurations(QNetworkConfiguration::Active)) {
|
|
|
|
//qDebug() << "Network:" << netCfg.identifier();
|
|
|
|
}
|
|
|
|
|
2012-02-21 14:50:19 +04:00
|
|
|
setupActions();
|
2012-03-31 13:31:28 +04:00
|
|
|
setupSystemTray();
|
|
|
|
processEvents();
|
2011-04-04 13:36:44 +04:00
|
|
|
|
2012-02-23 14:44:44 +04:00
|
|
|
QTimer::singleShot( 5000, this, SLOT(slotHideSplash()) );
|
2012-03-29 11:41:30 +04:00
|
|
|
QTimer::singleShot( 0, this, SLOT( slotStartFolderSetup() ));
|
2012-02-23 14:44:44 +04:00
|
|
|
|
2012-04-02 22:10:29 +04:00
|
|
|
MirallConfigFile cfg;
|
|
|
|
if( !cfg.ownCloudSkipUpdateCheck() ) {
|
|
|
|
QTimer::singleShot( 3000, this, SLOT( slotStartUpdateDetector() ));
|
|
|
|
}
|
|
|
|
|
2011-11-04 14:41:49 +04:00
|
|
|
qDebug() << "Network Location: " << NetworkLocation::currentLocation().encoded();
|
2011-02-17 02:21:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
2011-04-05 20:31:19 +04:00
|
|
|
qDebug() << "* Mirall shutdown";
|
|
|
|
|
|
|
|
delete _networkMgr;
|
2012-02-17 12:48:31 +04:00
|
|
|
delete _folderMan;
|
2012-03-29 11:41:30 +04:00
|
|
|
delete _ocInfo;
|
|
|
|
}
|
|
|
|
|
2012-04-02 22:10:29 +04:00
|
|
|
void Application::slotStartUpdateDetector()
|
|
|
|
{
|
|
|
|
_updateDetector = new UpdateDetector(this);
|
|
|
|
_updateDetector->versionCheck(_theme);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-29 11:41:30 +04:00
|
|
|
void Application::slotStartFolderSetup()
|
|
|
|
{
|
|
|
|
if( _ocInfo->isConfigured() ) {
|
|
|
|
_ocInfo->checkInstallation();
|
|
|
|
} else {
|
2012-04-10 16:51:45 +04:00
|
|
|
QMessageBox::warning(0, tr("No ownCloud Configuration"),
|
2012-04-10 22:55:50 +04:00
|
|
|
tr("<p>No ownCloud connection was configured yet.</p><p>Please configure one by clicking on the tray icon!</p>"));
|
|
|
|
// It was evaluated to open the config dialog from here directly but decided
|
|
|
|
// against because the user does not know why. The popup gives a better user
|
|
|
|
// guidance, even if its a click more.
|
2012-03-29 11:41:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::slotOwnCloudFound( const QString& url , const QString& version )
|
|
|
|
{
|
|
|
|
qDebug() << "** Application: ownCloud found: " << url << " with version " << version;
|
2012-03-30 22:42:40 +04:00
|
|
|
// now check the authentication!
|
|
|
|
QTimer::singleShot( 0, this, SLOT( slotCheckAuthentication() ));
|
2012-03-29 11:41:30 +04:00
|
|
|
}
|
|
|
|
|
2012-04-10 16:51:45 +04:00
|
|
|
void Application::slotNoOwnCloudFound( QNetworkReply* reply )
|
2012-03-29 11:41:30 +04:00
|
|
|
{
|
|
|
|
qDebug() << "** Application: NO ownCloud found!";
|
2012-04-10 16:51:45 +04:00
|
|
|
QString msg;
|
|
|
|
if( reply ) {
|
2012-04-10 22:55:50 +04:00
|
|
|
QString url( reply->url().toString() );
|
|
|
|
url.remove( "/status.php" );
|
|
|
|
msg = tr("<p>The ownCloud at %1 could not be reached.</p>").arg( url );
|
2012-04-10 16:51:45 +04:00
|
|
|
msg += tr("<p>The detailed error message is<br/><tt>%1</tt></p>").arg( reply->errorString() );
|
|
|
|
}
|
|
|
|
msg += tr("<p>Please check your configuration by clicking on the tray icon.</p>");
|
|
|
|
|
|
|
|
QMessageBox::warning(0, tr("ownCloud Connection Failed"), msg );
|
2012-03-30 15:57:02 +04:00
|
|
|
_actionAddFolder->setEnabled( false );
|
|
|
|
setupContextMenu();
|
2011-04-04 13:36:44 +04:00
|
|
|
}
|
2012-04-02 15:21:13 +04:00
|
|
|
|
2012-03-30 22:42:40 +04:00
|
|
|
void Application::slotCheckAuthentication()
|
|
|
|
{
|
2012-04-06 10:53:57 +04:00
|
|
|
qDebug() << "# checking for authentication settings.";
|
2012-03-30 22:42:40 +04:00
|
|
|
_ocInfo->getRequest("/", true ); // this call needs to be authenticated.
|
|
|
|
// simply GET the webdav root, will fail if credentials are wrong.
|
|
|
|
// continue in slotAuthCheck here :-)
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::slotAuthCheck( const QString& ,QNetworkReply *reply )
|
|
|
|
{
|
2012-04-17 15:06:25 +04:00
|
|
|
if( reply->error() == QNetworkReply::AuthenticationRequiredError ) { // returned if the user is wrong.
|
|
|
|
qDebug() << "******** Password is wrong!";
|
2012-03-30 22:42:40 +04:00
|
|
|
QMessageBox::warning(0, tr("No ownCloud Connection"),
|
2012-04-10 22:55:50 +04:00
|
|
|
tr("<p>Your ownCloud credentials are not correct.</p>"
|
|
|
|
"<p>Please correct them by starting the configuration dialog from the tray!</p>"));
|
2012-03-30 22:42:40 +04:00
|
|
|
_actionAddFolder->setEnabled( false );
|
2012-04-17 15:06:25 +04:00
|
|
|
} else if( reply->error() == QNetworkReply::OperationCanceledError ) {
|
|
|
|
// the username was wrong and ownCloudInfo was closing the request after a couple of auth tries.
|
2012-04-18 13:59:56 +04:00
|
|
|
qDebug() << "******** Username or password is wrong!";
|
2012-04-17 15:06:25 +04:00
|
|
|
QMessageBox::warning(0, tr("No ownCloud Connection"),
|
2012-04-18 13:59:56 +04:00
|
|
|
tr("<p>Your ownCloud user name or password is not correct.</p>"
|
2012-04-17 15:06:25 +04:00
|
|
|
"<p>Please correct it by starting the configuration dialog from the tray!</p>"));
|
|
|
|
_actionAddFolder->setEnabled( false );
|
2012-03-30 22:42:40 +04:00
|
|
|
} else {
|
|
|
|
qDebug() << "######## Credentials are ok!";
|
|
|
|
int cnt = _folderMan->setupFolders();
|
|
|
|
if( cnt ) {
|
|
|
|
_tray->setIcon(_theme->folderIcon("owncloud", 24));
|
|
|
|
_tray->show();
|
2012-03-31 13:31:28 +04:00
|
|
|
processEvents();
|
|
|
|
|
2012-03-30 22:42:40 +04:00
|
|
|
if( _tray )
|
|
|
|
_tray->showMessage(tr("ownCloud Sync Started"), tr("Sync started for %1 configured sync folder(s).").arg(cnt));
|
|
|
|
}
|
|
|
|
_actionAddFolder->setEnabled( true );
|
|
|
|
}
|
|
|
|
setupContextMenu();
|
|
|
|
}
|
2011-04-04 13:36:44 +04:00
|
|
|
|
2012-02-23 14:44:44 +04:00
|
|
|
void Application::slotHideSplash()
|
|
|
|
{
|
|
|
|
delete _splash;
|
|
|
|
}
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
void Application::setupActions()
|
|
|
|
{
|
2011-10-14 18:39:53 +04:00
|
|
|
_actionAddFolder = new QAction(tr("Add folder..."), this);
|
2011-02-17 02:21:45 +03:00
|
|
|
QObject::connect(_actionAddFolder, SIGNAL(triggered(bool)), SLOT(slotAddFolder()));
|
2011-10-14 18:39:53 +04:00
|
|
|
_actionConfigure = new QAction(tr("Configure..."), this);
|
|
|
|
QObject::connect(_actionConfigure, SIGNAL(triggered(bool)), SLOT(slotConfigure()));
|
2012-02-21 14:50:19 +04:00
|
|
|
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
_actionQuit = new QAction(tr("Quit"), this);
|
|
|
|
QObject::connect(_actionQuit, SIGNAL(triggered(bool)), SLOT(quit()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::setupSystemTray()
|
|
|
|
{
|
2012-03-31 13:31:28 +04:00
|
|
|
_tray = new QSystemTrayIcon();
|
2012-03-30 22:42:40 +04:00
|
|
|
_tray->setIcon( _theme->folderIcon("none", 48) ); // load the grey icon
|
2011-09-26 17:00:12 +04:00
|
|
|
|
|
|
|
connect(_tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
|
|
SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason)));
|
|
|
|
|
2012-04-10 16:51:45 +04:00
|
|
|
setupContextMenu();
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
_tray->show();
|
|
|
|
}
|
|
|
|
|
2012-02-21 14:50:19 +04:00
|
|
|
void Application::setupContextMenu()
|
|
|
|
{
|
2012-03-31 13:31:28 +04:00
|
|
|
if( _contextMenu ) {
|
|
|
|
_contextMenu->clear();
|
|
|
|
} else {
|
|
|
|
_contextMenu = new QMenu();
|
|
|
|
}
|
2012-02-21 14:50:19 +04:00
|
|
|
_contextMenu->setTitle(_theme->appName() );
|
|
|
|
_contextMenu->addAction(_actionConfigure);
|
|
|
|
_contextMenu->addAction(_actionAddFolder);
|
|
|
|
_contextMenu->addSeparator();
|
|
|
|
|
|
|
|
// here all folders should be added
|
|
|
|
foreach (Folder *folder, _folderMan->map() ) {
|
|
|
|
QAction *action = new QAction( tr("open %1").arg( folder->alias()), this );
|
|
|
|
action->setIcon( _theme->folderIcon( folder->backend(), 22) );
|
|
|
|
|
|
|
|
connect( action, SIGNAL(triggered()),_folderOpenActionMapper,SLOT(map()));
|
|
|
|
_folderOpenActionMapper->setMapping( action, folder->alias() );
|
|
|
|
|
|
|
|
_contextMenu->addAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
_contextMenu->addSeparator();
|
|
|
|
|
|
|
|
_contextMenu->addAction(_actionQuit);
|
|
|
|
_tray->setContextMenu(_contextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open the folder with the given Alais
|
|
|
|
*/
|
|
|
|
void Application::slotFolderOpenAction( const QString& alias )
|
|
|
|
{
|
|
|
|
Folder *f = _folderMan->folder(alias);
|
2012-04-02 14:13:55 +04:00
|
|
|
qDebug() << "opening local url " << f->path();
|
2012-02-21 14:50:19 +04:00
|
|
|
if( f ) {
|
2012-04-02 14:13:55 +04:00
|
|
|
QUrl url(f->path(), QUrl::TolerantMode);
|
|
|
|
url.setScheme( "file" );
|
|
|
|
QDesktopServices::openUrl(url);
|
2012-02-21 14:50:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 17:00:12 +04:00
|
|
|
void Application::slotTrayClicked( QSystemTrayIcon::ActivationReason reason )
|
|
|
|
{
|
|
|
|
if( reason == QSystemTrayIcon::Trigger ) {
|
2011-10-05 17:48:30 +04:00
|
|
|
// check if there is a mirall.cfg already.
|
2012-02-17 14:11:18 +04:00
|
|
|
if( _owncloudSetupWizard->wizard()->isVisible() ) {
|
|
|
|
_owncloudSetupWizard->wizard()->show();
|
2011-10-14 18:39:53 +04:00
|
|
|
}
|
2012-02-17 14:11:18 +04:00
|
|
|
|
|
|
|
// if no config file is there, start the configuration wizard.
|
|
|
|
MirallConfigFile cfgFile;
|
|
|
|
|
|
|
|
if( !cfgFile.exists() ) {
|
2011-09-27 21:10:01 +04:00
|
|
|
qDebug() << "No configured folders yet, start the Owncloud integration dialog.";
|
2012-02-17 14:11:18 +04:00
|
|
|
_owncloudSetupWizard->startWizard();
|
2011-09-27 21:10:01 +04:00
|
|
|
} else {
|
2012-03-31 14:44:22 +04:00
|
|
|
qDebug() << "#============# Status dialog starting #=============#";
|
|
|
|
|
2012-02-19 00:21:58 +04:00
|
|
|
_statusDialog->setFolderList( _folderMan->map() );
|
2011-10-20 12:26:40 +04:00
|
|
|
_statusDialog->show();
|
2011-09-27 21:10:01 +04:00
|
|
|
}
|
2011-09-26 17:00:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
void Application::slotAddFolder()
|
|
|
|
{
|
2012-02-17 12:48:31 +04:00
|
|
|
_folderMan->disableFoldersWithRestore();
|
2011-11-03 19:06:40 +04:00
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
Folder::Map folderMap = _folderMan->map();
|
|
|
|
|
|
|
|
_folderWizard->setFolderMap( &folderMap );
|
2011-10-11 16:23:32 +04:00
|
|
|
|
2011-10-14 20:13:34 +04:00
|
|
|
_folderWizard->restart();
|
|
|
|
|
2011-10-11 16:23:32 +04:00
|
|
|
if (_folderWizard->exec() == QDialog::Accepted) {
|
|
|
|
qDebug() << "* Folder wizard completed";
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
bool goodData = true;
|
2011-10-11 16:23:32 +04:00
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
QString alias = _folderWizard->field("alias").toString();
|
|
|
|
QString sourceFolder = _folderWizard->field("sourceFolder").toString();
|
|
|
|
QString backend = QString::fromLocal8Bit("csync");
|
|
|
|
QString targetPath;
|
|
|
|
bool onlyThisLAN = false;
|
|
|
|
bool onlyOnline = false;
|
2011-10-11 16:23:32 +04:00
|
|
|
|
|
|
|
if (_folderWizard->field("local?").toBool()) {
|
2012-02-17 12:48:31 +04:00
|
|
|
// setup a local csync folder
|
|
|
|
targetPath = _folderWizard->field("targetLocalFolder").toString();
|
2011-10-11 16:23:32 +04:00
|
|
|
} else if (_folderWizard->field("remote?").toBool()) {
|
2012-02-17 12:48:31 +04:00
|
|
|
// setup a remote csync folder
|
|
|
|
targetPath = _folderWizard->field("targetURLFolder").toString();
|
|
|
|
onlyOnline = _folderWizard->field("onlyOnline?").toBool();
|
|
|
|
onlyThisLAN = _folderWizard->field("onlyThisLAN?").toBool();
|
2011-10-11 16:23:32 +04:00
|
|
|
} else if( _folderWizard->field("OC?").toBool()) {
|
2012-02-17 12:48:31 +04:00
|
|
|
// setup a ownCloud folder
|
|
|
|
backend = QString::fromLocal8Bit("owncloud");
|
|
|
|
targetPath = _folderWizard->field("targetOCFolder").toString();
|
2011-10-11 16:23:32 +04:00
|
|
|
} else {
|
|
|
|
qWarning() << "* Folder not local and note remote?";
|
2012-02-17 12:48:31 +04:00
|
|
|
goodData = false;
|
2011-04-05 20:31:14 +04:00
|
|
|
}
|
2011-10-11 16:23:32 +04:00
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
if( goodData ) {
|
|
|
|
_folderMan->addFolderDefinition( backend, alias, sourceFolder, targetPath, onlyThisLAN );
|
2012-04-02 15:21:13 +04:00
|
|
|
_folderMan->setupFolderFromConfigFile( alias );
|
2012-03-13 18:39:04 +04:00
|
|
|
_statusDialog->slotAddFolder( _folderMan->folder( alias ) );
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2011-12-12 20:47:30 +04:00
|
|
|
} else {
|
2011-10-11 16:23:32 +04:00
|
|
|
qDebug() << "* Folder wizard cancelled";
|
2011-12-12 20:47:30 +04:00
|
|
|
}
|
2012-02-17 12:48:31 +04:00
|
|
|
_folderMan->restoreEnabledFolders();
|
2011-02-17 02:21:45 +03:00
|
|
|
}
|
|
|
|
|
2012-03-16 13:39:20 +04:00
|
|
|
/*
|
|
|
|
* the folder is to be removed. The slot is called from a signal emitted by
|
|
|
|
* the status dialog, which removes the folder from its list by itself.
|
|
|
|
*/
|
2011-10-13 15:55:52 +04:00
|
|
|
void Application::slotRemoveFolder( const QString& alias )
|
|
|
|
{
|
2012-03-16 13:39:20 +04:00
|
|
|
int ret = QMessageBox::question( 0, tr("Confirm Folder Remove"), tr("Do you really want to remove upload folder <i>%1</i>?").arg(alias),
|
|
|
|
QMessageBox::Yes|QMessageBox::No );
|
2011-10-13 15:55:52 +04:00
|
|
|
|
2012-03-16 13:39:20 +04:00
|
|
|
if( ret == QMessageBox::No ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-13 15:55:52 +04:00
|
|
|
|
2012-03-16 13:39:20 +04:00
|
|
|
_folderMan->slotRemoveFolder( alias );
|
2012-03-29 11:41:30 +04:00
|
|
|
_statusDialog->slotRemoveSelectedFolder( );
|
2011-10-13 15:55:52 +04:00
|
|
|
}
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
#ifdef HAVE_FETCH_AND_PUSH
|
2011-10-18 12:22:24 +04:00
|
|
|
void Application::slotFetchFolder( const QString& alias )
|
|
|
|
{
|
|
|
|
qDebug() << "start to fetch folder with alias " << alias;
|
|
|
|
|
|
|
|
if( ! _folderMap.contains( alias ) ) {
|
|
|
|
qDebug() << "!! Can not fetch alias " << alias << ", can not be found in folderMap.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Folder *f = _folderMap[alias];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-05 15:01:39 +04:00
|
|
|
void Application::slotPushFolder( const QString& alias )
|
|
|
|
{
|
|
|
|
qDebug() << "start to push folder with alias " << alias;
|
|
|
|
|
|
|
|
if( ! _folderMap.contains( alias ) ) {
|
|
|
|
qDebug() << "!! Can not push alias " << alias << ", can not be found in folderMap.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Folder *f = _folderMap[alias];
|
|
|
|
|
|
|
|
}
|
2012-02-17 12:48:31 +04:00
|
|
|
#endif
|
2011-12-05 15:01:39 +04:00
|
|
|
|
2012-01-24 01:10:01 +04:00
|
|
|
void Application::slotInfoFolder( const QString& alias )
|
|
|
|
{
|
|
|
|
qDebug() << "details of folder with alias " << alias;
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
SyncResult folderResult = _folderMan->syncResult( alias );
|
2012-01-24 01:10:01 +04:00
|
|
|
|
2012-04-18 13:59:56 +04:00
|
|
|
QString folderMessage = tr( "Last sync was succesful." );
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2012-02-20 19:45:27 +04:00
|
|
|
SyncResult::Status syncStatus = folderResult.status();
|
|
|
|
if ( syncStatus == SyncResult::Error ) {
|
2012-03-22 19:22:08 +04:00
|
|
|
folderMessage = tr( "<b>Syncing Error</b><br/>" );
|
2012-02-20 19:45:27 +04:00
|
|
|
} else if ( syncStatus == SyncResult::SetupError ) {
|
2012-03-22 19:22:08 +04:00
|
|
|
folderMessage = tr( "<b>Setup Error</b><br/>" );
|
2012-02-20 19:45:27 +04:00
|
|
|
} else if ( syncStatus == SyncResult::Disabled ) {
|
2012-03-22 19:22:08 +04:00
|
|
|
folderMessage = tr( "<b>Disabled Folder</b><br/>" ).arg( folderResult.errorString() );
|
2012-02-20 19:45:27 +04:00
|
|
|
} else if ( syncStatus == SyncResult::Undefined ) {
|
2012-03-22 19:22:08 +04:00
|
|
|
folderMessage = tr( "<b>Undefined state</b><br/>" );
|
2012-01-24 01:10:01 +04:00
|
|
|
}
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
QMessageBox infoBox( QMessageBox::Information, tr( "Folder information" ), alias, QMessageBox::Ok );
|
2012-03-22 19:22:08 +04:00
|
|
|
QStringList li = folderResult.errorStrings();
|
|
|
|
foreach( const QString l, li ) {
|
|
|
|
folderMessage += "<p>" + l +"</p>";
|
|
|
|
}
|
|
|
|
|
|
|
|
infoBox.setText( folderMessage );
|
2012-01-24 01:10:01 +04:00
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
// qDebug() << "informative text: " << infoBox.informativeText();
|
2012-01-24 01:10:01 +04:00
|
|
|
|
|
|
|
if ( !folderResult.syncChanges().isEmpty() ) {
|
|
|
|
QString details;
|
|
|
|
QHash < QString, QStringList > changes = folderResult.syncChanges();
|
|
|
|
QHash< QString, QStringList >::const_iterator change_it = changes.constBegin();
|
|
|
|
for(; change_it != changes.constEnd(); ++change_it ) {
|
|
|
|
QString changeType = tr( "Unknown" );
|
|
|
|
if ( change_it.key() == "changed" ) {
|
|
|
|
changeType = tr( "Changed files:\n" );
|
|
|
|
} else if ( change_it.key() == "added" ) {
|
|
|
|
changeType = tr( "Added files:\n" );
|
|
|
|
} else if ( change_it.key() == "deleted" ) {
|
|
|
|
changeType = tr( "New files in the server, or files deleted locally:\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList files = change_it.value();
|
|
|
|
QString fileList;
|
|
|
|
foreach( QString file, files) {
|
|
|
|
fileList += file + "\n";
|
|
|
|
}
|
|
|
|
details += changeType + fileList;
|
|
|
|
}
|
|
|
|
infoBox.setDetailedText(details);
|
|
|
|
qDebug() << "detailed text: " << infoBox.detailedText();
|
|
|
|
}
|
|
|
|
infoBox.exec();
|
|
|
|
}
|
|
|
|
|
2011-12-12 20:47:30 +04:00
|
|
|
void Application::slotEnableFolder(const QString& alias, const bool enable)
|
|
|
|
{
|
2012-03-03 13:51:06 +04:00
|
|
|
qDebug() << "Application: enable folder with alias " << alias;
|
2011-12-12 20:47:30 +04:00
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
_folderMan->slotEnableFolder( alias, enable );
|
2012-04-18 13:59:56 +04:00
|
|
|
_statusDialog->slotUpdateFolderState( _folderMan->folder(alias));
|
2011-12-12 20:47:30 +04:00
|
|
|
}
|
|
|
|
|
2011-10-14 18:39:53 +04:00
|
|
|
void Application::slotConfigure()
|
|
|
|
{
|
2012-02-17 12:48:31 +04:00
|
|
|
_folderMan->disableFoldersWithRestore();
|
2012-02-17 14:11:18 +04:00
|
|
|
_owncloudSetupWizard->startWizard();
|
2012-02-17 12:48:31 +04:00
|
|
|
_folderMan->restoreEnabledFolders();
|
2011-04-04 14:23:30 +04:00
|
|
|
}
|
|
|
|
|
2012-02-19 00:21:58 +04:00
|
|
|
void Application::slotSyncStateChange( const QString& alias )
|
2011-04-04 14:23:30 +04:00
|
|
|
{
|
2012-02-20 19:45:27 +04:00
|
|
|
SyncResult result = _folderMan->syncResult( alias );
|
2011-04-04 14:23:30 +04:00
|
|
|
|
2012-04-17 15:16:48 +04:00
|
|
|
// do not promote LocalSyncState to the status dialog.
|
|
|
|
if( !result.localRunOnly() ) {
|
|
|
|
_statusDialog->slotUpdateFolderState( _folderMan->folder(alias) );
|
|
|
|
}
|
2012-04-17 17:02:18 +04:00
|
|
|
computeOverallSyncStatus();
|
2012-02-19 00:21:58 +04:00
|
|
|
|
2012-04-17 15:16:48 +04:00
|
|
|
qDebug() << "Sync state changed for folder " << alias << ": " << result.localRunOnly();
|
2012-01-24 01:10:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Application::computeOverallSyncStatus()
|
|
|
|
{
|
|
|
|
|
2012-04-17 17:02:18 +04:00
|
|
|
// display the info of the least succesful sync (eg. not just display the result of the latest sync
|
|
|
|
SyncResult overallResult = SyncResult::Success;
|
|
|
|
QString trayMessage;
|
|
|
|
Folder::Map map = _folderMan->map();
|
|
|
|
|
|
|
|
foreach ( Folder *syncedFolder, map ) {
|
|
|
|
QString folderMessage = _overallStatusStrings[syncedFolder];
|
|
|
|
|
|
|
|
SyncResult folderResult = syncedFolder->syncResult();
|
|
|
|
SyncResult::Status syncStatus = folderResult.status();
|
|
|
|
|
|
|
|
if( ! folderResult.localRunOnly() ) { // skip local runs, use the last message.
|
|
|
|
if ( syncStatus == SyncResult::Success ) {
|
|
|
|
folderMessage = tr( "Folder %1: Ok." ).arg( syncedFolder->alias() );
|
|
|
|
} else if ( syncStatus == SyncResult::Error ) {
|
|
|
|
overallResult = SyncResult::Error;
|
|
|
|
folderMessage = tr( "Folder %1: %2" ).arg( syncedFolder->alias(), folderResult.errorString() );
|
|
|
|
} else if ( syncStatus == SyncResult::SetupError ) {
|
|
|
|
if ( overallResult.status() != SyncResult::Error ) {
|
|
|
|
overallResult = SyncResult::SetupError;
|
|
|
|
}
|
|
|
|
folderMessage = tr( "Folder %1: setup error" ).arg( syncedFolder->alias() );
|
|
|
|
} else if ( syncStatus == SyncResult::Disabled ) {
|
|
|
|
if ( overallResult.status() != SyncResult::SetupError
|
|
|
|
&& overallResult.status() != SyncResult::Error ) {
|
|
|
|
overallResult = SyncResult::Disabled;
|
|
|
|
}
|
|
|
|
folderMessage = tr( "Folder %1: %2" ).arg( syncedFolder->alias(), folderResult.errorString() );
|
|
|
|
} else if ( syncStatus == SyncResult::Undefined ) {
|
|
|
|
if ( overallResult.status() == SyncResult::Success ) {
|
|
|
|
overallResult = SyncResult::Undefined;
|
|
|
|
}
|
|
|
|
folderMessage = tr( "Folder %1: undefined state" ).arg( syncedFolder->alias() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_overallStatusStrings[syncedFolder] = folderMessage;
|
2011-10-13 18:41:24 +04:00
|
|
|
}
|
2012-03-23 18:31:46 +04:00
|
|
|
|
2012-04-17 17:02:18 +04:00
|
|
|
// create the tray blob message
|
|
|
|
QStringList allStatusStrings = _overallStatusStrings.values();
|
|
|
|
trayMessage = allStatusStrings.join("\n");
|
|
|
|
|
|
|
|
#if 0
|
2012-03-23 18:31:46 +04:00
|
|
|
if( _statusDialog->isVisible() ) {
|
2012-04-17 17:02:18 +04:00
|
|
|
_statusDialog->slotUpdateFolderState( syncedFolder );
|
2012-03-23 18:31:46 +04:00
|
|
|
}
|
2012-04-17 17:02:18 +04:00
|
|
|
#endif
|
2012-01-24 01:10:01 +04:00
|
|
|
|
2012-04-17 17:02:18 +04:00
|
|
|
QIcon statusIcon = _theme->syncStateIcon( overallResult.status(), 22 );
|
2012-03-03 13:51:06 +04:00
|
|
|
|
2012-04-17 17:02:18 +04:00
|
|
|
if( overallResult.status() == SyncResult::Success ) {
|
|
|
|
// Rather display the mirall icon instead of the ok icon.
|
|
|
|
statusIcon = _theme->applicationIcon();
|
|
|
|
}
|
2012-01-24 01:10:01 +04:00
|
|
|
|
2012-04-17 17:02:18 +04:00
|
|
|
_tray->setIcon( statusIcon );
|
|
|
|
_tray->setToolTip(trayMessage);
|
2011-12-12 20:47:30 +04:00
|
|
|
}
|
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
} // namespace Mirall
|
|
|
|
|