2011-04-06 13:48:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
2013-07-05 15:14:48 +04:00
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
2011-04-06 13:48:02 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-06-15 15:36:38 +04:00
|
|
|
#include <iostream>
|
2012-06-05 17:11:29 +04:00
|
|
|
|
2013-08-22 11:40:15 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-01-15 14:08:42 +04:00
|
|
|
|
|
|
|
#include "mirall/account.h"
|
2011-02-17 02:21:45 +03:00
|
|
|
#include "mirall/application.h"
|
2014-01-15 14:08:42 +04:00
|
|
|
#include "mirall/connectionvalidator.h"
|
2011-02-17 02:21:45 +03:00
|
|
|
#include "mirall/folder.h"
|
2013-07-22 15:59:52 +04:00
|
|
|
#include "mirall/folderman.h"
|
2014-01-15 14:08:42 +04:00
|
|
|
#include "mirall/logger.h"
|
|
|
|
#include "mirall/mirallconfigfile.h"
|
|
|
|
#include "mirall/socketapi.h"
|
2012-08-15 20:01:32 +04:00
|
|
|
#include "mirall/sslerrordialog.h"
|
2012-02-16 13:42:44 +04:00
|
|
|
#include "mirall/theme.h"
|
2014-01-15 14:08:42 +04:00
|
|
|
#include "mirall/updater.h"
|
2013-07-04 21:59:40 +04:00
|
|
|
#include "mirall/utility.h"
|
2011-02-17 02:21:45 +03:00
|
|
|
|
2013-07-30 13:19:22 +04:00
|
|
|
#include "creds/abstractcredentials.h"
|
2013-07-29 16:28:19 +04:00
|
|
|
|
2013-06-05 18:14:20 +04:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
#include <QTranslator>
|
2012-07-31 12:17:52 +04:00
|
|
|
#include <QNetworkProxy>
|
|
|
|
#include <QNetworkProxyFactory>
|
2013-08-28 22:58:22 +04:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
2012-05-21 18:48:49 +04:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
namespace Mirall {
|
|
|
|
|
2013-02-14 21:27:44 +04:00
|
|
|
namespace {
|
2013-06-06 18:00:51 +04:00
|
|
|
|
|
|
|
static const char optionsC[] =
|
|
|
|
"Options:\n"
|
|
|
|
" -h --help : show this help screen.\n"
|
|
|
|
" --logwindow : open a window to show log output.\n"
|
|
|
|
" --logfile <filename> : write log output to file <filename>.\n"
|
|
|
|
" --logdir <name> : write each sync log output in a new file\n"
|
|
|
|
" in directory <name>.\n"
|
2013-06-07 20:57:45 +04:00
|
|
|
" --logexpire <hours> : removes logs older than <hours> hours.\n"
|
|
|
|
" (to be used with --logdir)\n"
|
2013-06-06 18:00:51 +04:00
|
|
|
" --logflush : flush the log file after every write.\n"
|
|
|
|
" --confdir <dirname> : Use the given configuration directory.\n"
|
|
|
|
;
|
|
|
|
|
2013-02-14 21:27:44 +04:00
|
|
|
QString applicationTrPath()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_LINUX
|
2013-09-05 13:06:40 +04:00
|
|
|
return QString::fromLatin1(DATADIR"/"APPLICATION_EXECUTABLE"/i18n/");
|
2013-02-14 21:27:44 +04:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
return QApplication::applicationDirPath()+QLatin1String("/../Resources/Translations"); // path defaults to app dir.
|
|
|
|
#endif
|
2013-12-03 19:23:49 +04:00
|
|
|
#ifdef Q_OS_WIN
|
2013-02-14 21:27:44 +04:00
|
|
|
return QApplication::applicationDirPath();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:11:29 +04:00
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
|
2012-04-20 15:17:48 +04:00
|
|
|
Application::Application(int &argc, char **argv) :
|
2012-07-30 18:10:48 +04:00
|
|
|
SharedTools::QtSingleApplication(argc, argv),
|
2013-10-01 15:52:07 +04:00
|
|
|
_gui(0),
|
2012-09-24 19:55:10 +04:00
|
|
|
_theme(Theme::instance()),
|
2013-10-02 17:28:33 +04:00
|
|
|
_helpOnly(false),
|
2013-10-11 13:43:23 +04:00
|
|
|
_startupNetworkError(false),
|
2012-10-16 21:05:28 +04:00
|
|
|
_showLogWindow(false),
|
2013-10-02 17:28:33 +04:00
|
|
|
_logExpire(0),
|
2013-11-27 17:15:56 +04:00
|
|
|
_logFlush(false),
|
|
|
|
_userTriggeredConnect(false)
|
2011-02-17 02:21:45 +03:00
|
|
|
{
|
2013-02-21 15:21:42 +04:00
|
|
|
setApplicationName( _theme->appNameGUI() );
|
2012-03-31 13:31:28 +04:00
|
|
|
setWindowIcon( _theme->applicationIcon() );
|
2012-02-23 14:44:44 +04:00
|
|
|
|
2012-10-16 21:05:28 +04:00
|
|
|
parseOptions(arguments());
|
|
|
|
//no need to waste time;
|
|
|
|
if ( _helpOnly ) return;
|
2012-04-18 14:10:14 +04:00
|
|
|
|
2013-12-10 15:46:00 +04:00
|
|
|
initialize();
|
|
|
|
if (isRunning())
|
|
|
|
return;
|
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
setupLogging();
|
2013-08-15 15:02:27 +04:00
|
|
|
setupTranslations();
|
|
|
|
|
2012-10-16 21:05:28 +04:00
|
|
|
connect( this, SIGNAL(messageReceived(QString)), SLOT(slotParseOptions(QString)));
|
2013-07-31 00:22:43 +04:00
|
|
|
|
2013-11-04 19:36:23 +04:00
|
|
|
Account *account = Account::restore();
|
2013-10-28 23:01:59 +04:00
|
|
|
if (account) {
|
|
|
|
account->setSslErrorHandler(new SslDialogErrorHandler);
|
|
|
|
AccountManager::instance()->setAccount(account);
|
|
|
|
}
|
2013-10-24 02:29:08 +04:00
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
FolderMan::instance()->setSyncEnabled(false);
|
2012-02-19 00:21:58 +04:00
|
|
|
|
2011-04-05 20:31:14 +04:00
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
2013-07-05 20:46:43 +04:00
|
|
|
qRegisterMetaType<Progress::Kind>("Progress::Kind");
|
2013-07-26 15:44:38 +04:00
|
|
|
qRegisterMetaType<Progress::Info>("Progress::Info");
|
2013-11-25 19:12:47 +04:00
|
|
|
qRegisterMetaType<Progress::SyncProblem>("Progress::SyncProblem");
|
2013-10-11 13:43:23 +04:00
|
|
|
|
2013-11-04 19:36:23 +04:00
|
|
|
MirallConfigFile cfg;
|
2013-07-04 21:59:40 +04:00
|
|
|
_theme->setSystrayUseMonoIcons(cfg.monoIcons());
|
|
|
|
connect (_theme, SIGNAL(systrayUseMonoIconsChanged(bool)), SLOT(slotUseMonoIconsChanged(bool)));
|
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
FolderMan::instance()->setupFolders();
|
2013-10-14 18:11:15 +04:00
|
|
|
slotSetupProxy(); // folders have to be defined first.
|
2012-07-30 18:10:48 +04:00
|
|
|
|
2013-11-18 12:34:57 +04:00
|
|
|
_gui = new ownCloudGui(this);
|
|
|
|
if( _showLogWindow ) {
|
|
|
|
_gui->slotToggleLogBrowser(); // _showLogWindow is set in parseOptions.
|
|
|
|
}
|
|
|
|
connect( _gui, SIGNAL(setupProxy()), SLOT(slotSetupProxy()));
|
2013-11-23 03:14:02 +04:00
|
|
|
if (account) {
|
2013-11-25 18:33:35 +04:00
|
|
|
connect(account, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
|
2013-11-23 03:14:02 +04:00
|
|
|
}
|
|
|
|
connect(AccountManager::instance(), SIGNAL(accountChanged(Account*,Account*)),
|
|
|
|
this, SLOT(slotAccountChanged(Account*,Account*)));
|
2013-11-18 12:34:57 +04:00
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
// startup procedure.
|
|
|
|
QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));
|
2012-02-23 14:44:44 +04:00
|
|
|
|
2014-01-15 14:08:42 +04:00
|
|
|
if( !cfg.skipUpdateCheck() ) {
|
2012-04-02 22:10:29 +04:00
|
|
|
QTimer::singleShot( 3000, this, SLOT( slotStartUpdateDetector() ));
|
|
|
|
}
|
|
|
|
|
2013-09-18 16:11:19 +04:00
|
|
|
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
|
|
|
|
|
2013-10-03 19:04:55 +04:00
|
|
|
_socketApi = new SocketApi(this, cfg.configPathWithAppName().append(QLatin1String("socket")));
|
2013-11-23 03:14:02 +04:00
|
|
|
|
2011-02-17 02:21:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
2013-10-02 17:28:33 +04:00
|
|
|
// qDebug() << "* Mirall shutdown";
|
2012-03-29 11:41:30 +04:00
|
|
|
}
|
|
|
|
|
2013-11-23 03:14:02 +04:00
|
|
|
void Application::slotLogin()
|
|
|
|
{
|
|
|
|
Account *a = AccountManager::instance()->account();
|
|
|
|
if (a) {
|
|
|
|
FolderMan::instance()->setupFolders();
|
2013-11-27 17:15:56 +04:00
|
|
|
_userTriggeredConnect = true;
|
2013-11-23 03:14:02 +04:00
|
|
|
slotCheckConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::slotLogout()
|
|
|
|
{
|
|
|
|
Account *a = AccountManager::instance()->account();
|
|
|
|
if (a) {
|
|
|
|
// invalidate & forget token/password
|
|
|
|
a->credentials()->invalidateToken(a);
|
|
|
|
// terminate all syncs and unload folders
|
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
|
|
|
folderMan->setSyncEnabled(false);
|
|
|
|
folderMan->terminateSyncProcess();
|
|
|
|
folderMan->unloadAllFolders();
|
2013-11-25 18:33:35 +04:00
|
|
|
a->setState(Account::SignedOut);
|
2013-11-23 03:14:02 +04:00
|
|
|
// show result
|
|
|
|
_gui->slotComputeOverallSyncStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::slotAccountChanged(Account *newAccount, Account *oldAccount)
|
|
|
|
{
|
2013-12-09 22:18:50 +04:00
|
|
|
disconnect(oldAccount, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
|
|
|
|
connect(newAccount, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
|
2013-11-23 03:14:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-01 15:52:07 +04:00
|
|
|
void Application::slotCleanup()
|
|
|
|
{
|
|
|
|
// explicitly close windows. This is somewhat of a hack to ensure
|
|
|
|
// that saving the geometries happens ASAP during a OS shutdown
|
2013-10-24 02:29:08 +04:00
|
|
|
Account *account = AccountManager::instance()->account();
|
|
|
|
if (account) {
|
2013-11-04 19:36:23 +04:00
|
|
|
account->save();
|
2013-10-24 02:29:08 +04:00
|
|
|
}
|
2013-10-02 17:28:33 +04:00
|
|
|
_gui->slotShutdown();
|
2013-10-01 15:52:07 +04:00
|
|
|
_gui->deleteLater();
|
|
|
|
}
|
|
|
|
|
2012-04-02 22:10:29 +04:00
|
|
|
void Application::slotStartUpdateDetector()
|
|
|
|
{
|
2014-01-15 14:08:42 +04:00
|
|
|
Updater *updater = Updater::instance();
|
|
|
|
updater->backgroundCheckForUpdate();
|
2012-03-29 11:41:30 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
void Application::slotCheckConnection()
|
2013-07-29 16:28:19 +04:00
|
|
|
{
|
2013-11-29 19:12:58 +04:00
|
|
|
Account *account = AccountManager::instance()->account();
|
|
|
|
|
|
|
|
if( account ) {
|
2013-11-04 19:36:23 +04:00
|
|
|
AbstractCredentials* credentials(account->credentials());
|
2013-08-05 14:19:53 +04:00
|
|
|
|
|
|
|
if (! credentials->ready()) {
|
|
|
|
connect( credentials, SIGNAL(fetched()),
|
|
|
|
this, SLOT(slotCredentialsFetched()));
|
2013-11-04 19:36:23 +04:00
|
|
|
credentials->fetch(account);
|
2013-08-05 14:19:53 +04:00
|
|
|
} else {
|
|
|
|
runValidator();
|
|
|
|
}
|
2013-07-29 16:28:19 +04:00
|
|
|
} else {
|
2013-11-29 19:12:58 +04:00
|
|
|
// let gui open the setup wizard
|
|
|
|
_gui->slotOpenSettingsDialog( true );
|
2013-07-29 16:28:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::slotCredentialsFetched()
|
|
|
|
{
|
2013-11-04 19:36:23 +04:00
|
|
|
Account *account = AccountManager::instance()->account();
|
|
|
|
disconnect(account->credentials(), SIGNAL(fetched()),
|
2013-07-29 16:28:19 +04:00
|
|
|
this, SLOT(slotCredentialsFetched()));
|
|
|
|
runValidator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::runValidator()
|
2012-03-29 11:41:30 +04:00
|
|
|
{
|
2013-10-23 16:48:44 +04:00
|
|
|
_conValidator = new ConnectionValidator(AccountManager::instance()->account());
|
2013-07-05 15:14:48 +04:00
|
|
|
connect( _conValidator, SIGNAL(connectionResult(ConnectionValidator::Status)),
|
|
|
|
this, SLOT(slotConnectionValidatorResult(ConnectionValidator::Status)) );
|
|
|
|
_conValidator->checkConnection();
|
2012-03-29 11:41:30 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
void Application::slotConnectionValidatorResult(ConnectionValidator::Status status)
|
2012-11-13 14:15:25 +04:00
|
|
|
{
|
2013-07-05 15:14:48 +04:00
|
|
|
qDebug() << "Connection Validator Result: " << _conValidator->statusString(status);
|
2013-10-01 20:25:30 +04:00
|
|
|
QStringList startupFails;
|
2013-10-01 15:52:07 +04:00
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
if( status == ConnectionValidator::Connected ) {
|
2013-07-22 15:59:52 +04:00
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
2013-07-05 15:14:48 +04:00
|
|
|
qDebug() << "######## Connection and Credentials are ok!";
|
2013-07-22 15:59:52 +04:00
|
|
|
folderMan->setSyncEnabled(true);
|
2013-02-19 20:24:10 +04:00
|
|
|
// queue up the sync for all folders.
|
2013-07-22 15:59:52 +04:00
|
|
|
folderMan->slotScheduleAllFolders();
|
2013-11-27 17:15:56 +04:00
|
|
|
if(!_connectionMsgBox.isNull()) {
|
|
|
|
_connectionMsgBox->close();
|
|
|
|
}
|
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
} else {
|
2013-09-11 12:24:31 +04:00
|
|
|
// if we have problems here, it's unlikely that syncing will work.
|
|
|
|
FolderMan::instance()->setSyncEnabled(false);
|
|
|
|
|
2013-10-01 20:25:30 +04:00
|
|
|
startupFails = _conValidator->errors();
|
2013-10-11 13:43:23 +04:00
|
|
|
_startupNetworkError = _conValidator->networkError();
|
2013-11-27 17:15:56 +04:00
|
|
|
if (_userTriggeredConnect) {
|
|
|
|
if(_connectionMsgBox.isNull()) {
|
|
|
|
_connectionMsgBox = new QMessageBox(QMessageBox::Warning, tr("Connection failed"),
|
|
|
|
_conValidator->errors().join(". ").append('.'), QMessageBox::Ok, 0);
|
|
|
|
_connectionMsgBox->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
_connectionMsgBox->open();
|
|
|
|
_userTriggeredConnect = false;
|
|
|
|
}
|
|
|
|
}
|
2013-10-11 13:43:23 +04:00
|
|
|
QTimer::singleShot(30*1000, this, SLOT(slotCheckConnection()));
|
2012-03-30 22:42:40 +04:00
|
|
|
}
|
2013-10-01 20:25:30 +04:00
|
|
|
_gui->startupConnected( (status == ConnectionValidator::Connected), startupFails);
|
2013-09-11 12:24:31 +04:00
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
_conValidator->deleteLater();
|
2012-03-30 22:42:40 +04:00
|
|
|
}
|
2011-04-04 13:36:44 +04:00
|
|
|
|
2012-11-28 22:25:12 +04:00
|
|
|
void Application::slotownCloudWizardDone( int res )
|
|
|
|
{
|
2013-07-22 15:59:52 +04:00
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
2012-11-28 22:25:12 +04:00
|
|
|
if( res == QDialog::Accepted ) {
|
2013-07-22 15:59:52 +04:00
|
|
|
int cnt = folderMan->setupFolders();
|
2013-02-19 15:04:36 +04:00
|
|
|
qDebug() << "Set up " << cnt << " folders.";
|
2013-07-05 03:05:23 +04:00
|
|
|
// We have some sort of configuration. Enable autostart
|
2013-07-07 00:38:33 +04:00
|
|
|
Utility::setLaunchOnStartup(_theme->appName(), _theme->appNameGUI(), true);
|
2013-07-04 21:59:40 +04:00
|
|
|
// FIXME!
|
2013-07-22 15:59:52 +04:00
|
|
|
// _statusDialog->setFolderList( folderMan->map() );
|
2012-11-28 22:25:12 +04:00
|
|
|
}
|
2013-07-22 15:59:52 +04:00
|
|
|
folderMan->setSyncEnabled( true );
|
2013-07-05 15:14:48 +04:00
|
|
|
if( res == QDialog::Accepted ) {
|
|
|
|
slotCheckConnection();
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:25:12 +04:00
|
|
|
}
|
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
void Application::setupLogging()
|
2012-06-05 17:49:53 +04:00
|
|
|
{
|
2012-10-16 21:05:28 +04:00
|
|
|
// might be called from second instance
|
2013-10-02 17:28:33 +04:00
|
|
|
Logger::instance()->setLogFile(_logFile);
|
|
|
|
Logger::instance()->setLogDir(_logDir);
|
|
|
|
Logger::instance()->setLogExpire(_logExpire);
|
|
|
|
Logger::instance()->setLogFlush(_logFlush);
|
2012-06-05 17:49:53 +04:00
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
Logger::instance()->enterNextLogFile();
|
2012-06-15 15:04:23 +04:00
|
|
|
|
2013-02-14 21:27:44 +04:00
|
|
|
qDebug() << QString::fromLatin1( "################## %1 %2 (%3) %4").arg(_theme->appName())
|
2012-06-05 17:49:53 +04:00
|
|
|
.arg( QLocale::system().name() )
|
2013-02-14 21:27:44 +04:00
|
|
|
.arg(property("ui_lang").toString())
|
2012-06-05 17:49:53 +04:00
|
|
|
.arg(_theme->version());
|
2012-10-16 21:05:28 +04:00
|
|
|
|
2012-06-05 17:49:53 +04:00
|
|
|
}
|
2012-07-31 12:17:52 +04:00
|
|
|
|
2013-05-29 14:56:23 +04:00
|
|
|
QNetworkProxy proxyFromConfig(const MirallConfigFile& cfg)
|
|
|
|
{
|
|
|
|
QNetworkProxy proxy;
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
if (cfg.proxyHostName().isEmpty())
|
|
|
|
return QNetworkProxy();
|
|
|
|
|
2013-05-29 14:56:23 +04:00
|
|
|
proxy.setHostName(cfg.proxyHostName());
|
|
|
|
proxy.setPort(cfg.proxyPort());
|
|
|
|
if (cfg.proxyNeedsAuth()) {
|
|
|
|
proxy.setUser(cfg.proxyUser());
|
|
|
|
proxy.setPassword(cfg.proxyPassword());
|
|
|
|
}
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
2013-06-27 18:54:33 +04:00
|
|
|
void Application::slotSetupProxy()
|
2012-07-31 12:17:52 +04:00
|
|
|
{
|
|
|
|
Mirall::MirallConfigFile cfg;
|
2013-05-29 14:56:23 +04:00
|
|
|
int proxyType = cfg.proxyType();
|
|
|
|
QNetworkProxy proxy = proxyFromConfig(cfg);
|
2012-08-08 17:47:25 +04:00
|
|
|
|
2013-05-29 14:56:23 +04:00
|
|
|
switch(proxyType) {
|
|
|
|
case QNetworkProxy::NoProxy:
|
2013-10-11 16:24:18 +04:00
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(false);
|
2012-10-09 12:10:41 +04:00
|
|
|
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
|
2013-05-31 18:16:41 +04:00
|
|
|
break;
|
2013-05-29 14:56:23 +04:00
|
|
|
case QNetworkProxy::DefaultProxy:
|
2012-07-31 12:17:52 +04:00
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
2013-05-31 18:16:41 +04:00
|
|
|
break;
|
2013-05-29 14:56:23 +04:00
|
|
|
case QNetworkProxy::Socks5Proxy:
|
2013-05-29 04:14:40 +04:00
|
|
|
proxy.setType(QNetworkProxy::Socks5Proxy);
|
2013-10-11 16:24:18 +04:00
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(false);
|
2013-05-29 04:14:40 +04:00
|
|
|
QNetworkProxy::setApplicationProxy(proxy);
|
2013-05-31 18:16:41 +04:00
|
|
|
break;
|
2013-05-29 14:56:23 +04:00
|
|
|
case QNetworkProxy::HttpProxy:
|
2012-10-08 13:03:15 +04:00
|
|
|
proxy.setType(QNetworkProxy::HttpProxy);
|
2013-10-11 16:24:18 +04:00
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(false);
|
2012-07-31 12:17:52 +04:00
|
|
|
QNetworkProxy::setApplicationProxy(proxy);
|
2013-05-31 18:16:41 +04:00
|
|
|
break;
|
2013-05-29 14:56:23 +04:00
|
|
|
default:
|
2013-05-31 18:16:41 +04:00
|
|
|
break;
|
2012-07-31 12:17:52 +04:00
|
|
|
}
|
2013-08-27 12:02:59 +04:00
|
|
|
|
|
|
|
FolderMan::instance()->setDirtyProxy(true);
|
|
|
|
FolderMan::instance()->slotScheduleAllFolders();
|
2012-07-31 12:17:52 +04:00
|
|
|
}
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
void Application::slotUseMonoIconsChanged(bool)
|
|
|
|
{
|
2013-10-02 17:28:33 +04:00
|
|
|
_gui->slotComputeOverallSyncStatus();
|
2012-06-05 17:11:29 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 21:05:28 +04:00
|
|
|
void Application::slotParseOptions(const QString &opts)
|
|
|
|
{
|
|
|
|
QStringList options = opts.split(QLatin1Char('|'));
|
|
|
|
parseOptions(options);
|
2013-10-02 17:28:33 +04:00
|
|
|
setupLogging();
|
2012-01-24 01:10:01 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 21:05:28 +04:00
|
|
|
void Application::parseOptions(const QStringList &options)
|
|
|
|
{
|
|
|
|
QStringListIterator it(options);
|
|
|
|
// skip file name;
|
|
|
|
if (it.hasNext()) it.next();
|
|
|
|
|
2013-01-29 08:19:14 +04:00
|
|
|
//parse options; if help or bad option exit
|
2012-10-16 21:05:28 +04:00
|
|
|
while (it.hasNext()) {
|
|
|
|
QString option = it.next();
|
2013-07-29 16:28:19 +04:00
|
|
|
if (option == QLatin1String("--help") || option == QLatin1String("-h")) {
|
2013-01-29 08:19:14 +04:00
|
|
|
setHelp();
|
|
|
|
break;
|
2012-10-16 21:05:28 +04:00
|
|
|
} else if (option == QLatin1String("--logwindow") ||
|
2013-10-02 17:28:33 +04:00
|
|
|
option == QLatin1String("-l")) {
|
2012-10-16 21:05:28 +04:00
|
|
|
_showLogWindow = true;
|
|
|
|
} else if (option == QLatin1String("--logfile")) {
|
|
|
|
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
|
2013-10-02 17:28:33 +04:00
|
|
|
_logFile = it.next();
|
2012-10-16 21:05:28 +04:00
|
|
|
} else {
|
2013-01-29 08:19:14 +04:00
|
|
|
setHelp();
|
2012-10-16 21:05:28 +04:00
|
|
|
}
|
2013-06-03 18:23:29 +04:00
|
|
|
} else if (option == QLatin1String("--logdir")) {
|
|
|
|
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
|
2013-10-02 17:28:33 +04:00
|
|
|
_logDir = it.next();
|
2013-06-03 18:23:29 +04:00
|
|
|
} else {
|
|
|
|
setHelp();
|
|
|
|
}
|
2013-06-07 20:57:45 +04:00
|
|
|
} else if (option == QLatin1String("--logexpire")) {
|
|
|
|
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
|
|
|
|
_logExpire = it.next().toInt();
|
|
|
|
} else {
|
|
|
|
setHelp();
|
|
|
|
}
|
2012-10-16 21:05:28 +04:00
|
|
|
} else if (option == QLatin1String("--logflush")) {
|
|
|
|
_logFlush = true;
|
2013-01-02 21:43:40 +04:00
|
|
|
} else if (option == QLatin1String("--confdir")) {
|
|
|
|
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
|
2013-04-03 16:42:13 +04:00
|
|
|
QString confDir = it.next();
|
|
|
|
MirallConfigFile::setConfDir( confDir );
|
2013-01-02 21:43:40 +04:00
|
|
|
} else {
|
|
|
|
showHelp();
|
|
|
|
}
|
2013-04-03 16:42:13 +04:00
|
|
|
} else {
|
|
|
|
setHelp();
|
|
|
|
break;
|
2012-10-16 21:05:28 +04:00
|
|
|
}
|
2013-10-02 17:28:33 +04:00
|
|
|
}
|
2012-10-16 21:05:28 +04:00
|
|
|
}
|
|
|
|
|
2013-06-06 18:00:51 +04:00
|
|
|
// Helpers for displaying messages. Note that there is no console on Windows.
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// Format as <pre> HTML
|
|
|
|
static inline void toHtml(QString &t)
|
|
|
|
{
|
|
|
|
t.replace(QLatin1Char('&'), QLatin1String("&"));
|
|
|
|
t.replace(QLatin1Char('<'), QLatin1String("<"));
|
|
|
|
t.replace(QLatin1Char('>'), QLatin1String(">"));
|
|
|
|
t.insert(0, QLatin1String("<html><pre>"));
|
|
|
|
t.append(QLatin1String("</pre></html>"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void displayHelpText(QString t) // No console on Windows.
|
|
|
|
{
|
|
|
|
toHtml(t);
|
|
|
|
QMessageBox::information(0, Theme::instance()->appNameGUI(), t);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static void displayHelpText(const QString &t)
|
|
|
|
{
|
|
|
|
std::cout << qPrintable(t);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-15 15:36:38 +04:00
|
|
|
void Application::showHelp()
|
|
|
|
{
|
2013-06-06 18:00:51 +04:00
|
|
|
setHelp();
|
|
|
|
QString helpText;
|
|
|
|
QTextStream stream(&helpText);
|
|
|
|
stream << _theme->appName().toLatin1().constData()
|
|
|
|
<< QLatin1String(" version ")
|
|
|
|
<< _theme->version().toLatin1().constData() << endl;
|
|
|
|
|
|
|
|
stream << QLatin1String("File synchronisation desktop utility.") << endl << endl
|
|
|
|
<< QLatin1String(optionsC);
|
|
|
|
|
2012-09-24 19:55:10 +04:00
|
|
|
if (_theme->appName() == QLatin1String("ownCloud"))
|
2013-10-02 17:28:33 +04:00
|
|
|
stream << endl << "For more information, see http://www.owncloud.org" << endl << endl;
|
2013-06-06 18:00:51 +04:00
|
|
|
|
|
|
|
displayHelpText(helpText);
|
2013-01-29 08:19:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Application::setHelp()
|
|
|
|
{
|
2012-06-15 15:36:38 +04:00
|
|
|
_helpOnly = true;
|
|
|
|
}
|
|
|
|
|
2013-06-05 18:14:20 +04:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
bool Application::winEventFilter(MSG *pMsg, long *result)
|
|
|
|
{
|
|
|
|
if (pMsg->message == WM_POWERBROADCAST) {
|
|
|
|
switch(pMsg->wParam) {
|
|
|
|
case PBT_APMPOWERSTATUSCHANGE:
|
|
|
|
qDebug() << "WM_POWERBROADCAST: Power state changed";
|
|
|
|
break;
|
|
|
|
case PBT_APMSUSPEND:
|
|
|
|
qDebug() << "WM_POWERBROADCAST: Entering low power state";
|
|
|
|
break;
|
|
|
|
case PBT_APMRESUMEAUTOMATIC:
|
|
|
|
qDebug() << "WM_POWERBROADCAST: Resuming from low power state";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-10 17:37:29 +04:00
|
|
|
return SharedTools::QtSingleApplication::winEventFilter(pMsg, result);
|
2013-06-05 18:14:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-24 18:22:21 +04:00
|
|
|
QString substLang(const QString &lang)
|
|
|
|
{
|
|
|
|
// Map the more apropriate script codes
|
|
|
|
// to country codes as used by Qt and
|
|
|
|
// transifex translation conventions.
|
|
|
|
|
|
|
|
// Simplified Chinese
|
|
|
|
if (lang == QLatin1String("zh_Hans"))
|
|
|
|
return QLatin1String("zh_CN");
|
|
|
|
// Traditional Chinese
|
|
|
|
if (lang == QLatin1String("zh_Hant"))
|
|
|
|
return QLatin1String("zh_TW");
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
2013-02-14 21:27:44 +04:00
|
|
|
void Application::setupTranslations()
|
|
|
|
{
|
|
|
|
QStringList uiLanguages;
|
|
|
|
// uiLanguages crashes on Windows with 4.8.0 release builds
|
|
|
|
#if (QT_VERSION >= 0x040801) || (QT_VERSION >= 0x040800 && !defined(Q_OS_WIN))
|
|
|
|
uiLanguages = QLocale::system().uiLanguages();
|
|
|
|
#else
|
|
|
|
// older versions need to fall back to the systems locale
|
|
|
|
uiLanguages << QLocale::system().name();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QString enforcedLocale = Theme::instance()->enforcedLocale();
|
|
|
|
if (!enforcedLocale.isEmpty())
|
|
|
|
uiLanguages.prepend(enforcedLocale);
|
|
|
|
|
|
|
|
QTranslator *translator = new QTranslator(this);
|
|
|
|
QTranslator *qtTranslator = new QTranslator(this);
|
|
|
|
QTranslator *qtkeychainTranslator = new QTranslator(this);
|
|
|
|
|
|
|
|
foreach(QString lang, uiLanguages) {
|
|
|
|
lang.replace(QLatin1Char('-'), QLatin1Char('_')); // work around QTBUG-25973
|
2013-02-24 18:22:21 +04:00
|
|
|
lang = substLang(lang);
|
2013-02-14 21:27:44 +04:00
|
|
|
const QString trPath = applicationTrPath();
|
|
|
|
const QString trFile = QLatin1String("mirall_") + lang;
|
2013-02-24 18:20:59 +04:00
|
|
|
if (translator->load(trFile, trPath) ||
|
|
|
|
lang.startsWith(QLatin1String("en"))) {
|
|
|
|
// Permissive approach: Qt and keychain translations
|
|
|
|
// may be missing, but Qt translations must be there in order
|
|
|
|
// for us to accept the language. Otherwise, we try with the next.
|
|
|
|
// "en" is an exeption as it is the default language and may not
|
|
|
|
// have a translation file provided.
|
|
|
|
qDebug() << Q_FUNC_INFO << "Using" << lang << "translation";
|
|
|
|
setProperty("ui_lang", lang);
|
2013-02-14 21:27:44 +04:00
|
|
|
const QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
|
|
const QString qtTrFile = QLatin1String("qt_") + lang;
|
2013-02-24 18:20:59 +04:00
|
|
|
if (qtTranslator->load(qtTrFile, qtTrPath)) {
|
|
|
|
qtTranslator->load(qtTrFile, trPath);
|
|
|
|
}
|
2013-02-14 21:27:44 +04:00
|
|
|
const QString qtkeychainFile = QLatin1String("qt_") + lang;
|
2013-02-24 18:20:59 +04:00
|
|
|
if (!qtkeychainTranslator->load(qtkeychainFile, qtTrPath)) {
|
|
|
|
qtkeychainTranslator->load(qtkeychainFile, trPath);
|
|
|
|
}
|
|
|
|
if (!translator->isEmpty())
|
2013-02-14 21:27:44 +04:00
|
|
|
installTranslator(translator);
|
2013-02-24 18:20:59 +04:00
|
|
|
if (!qtTranslator->isEmpty())
|
2013-02-14 21:27:44 +04:00
|
|
|
installTranslator(qtTranslator);
|
2013-02-24 18:20:59 +04:00
|
|
|
if (!qtkeychainTranslator->isEmpty())
|
|
|
|
installTranslator(qtkeychainTranslator);
|
2013-02-21 18:16:02 +04:00
|
|
|
break;
|
2013-02-14 21:27:44 +04:00
|
|
|
}
|
|
|
|
if (property("ui_lang").isNull())
|
|
|
|
setProperty("ui_lang", "C");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:36:38 +04:00
|
|
|
bool Application::giveHelp()
|
|
|
|
{
|
|
|
|
return _helpOnly;
|
|
|
|
}
|
2011-02-17 02:21:45 +03:00
|
|
|
} // namespace Mirall
|
|
|
|
|