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.
|
|
|
|
*/
|
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
#include "application.h"
|
|
|
|
|
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-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 "connectionvalidator.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "folderman.h"
|
|
|
|
#include "logger.h"
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "socketapi.h"
|
|
|
|
#include "sslerrordialog.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "utility.h"
|
|
|
|
#include "clientproxy.h"
|
2014-09-03 18:12:21 +04:00
|
|
|
#include "sharedialog.h"
|
2015-04-09 17:19:17 +03:00
|
|
|
#include "accountmanager.h"
|
2013-07-30 13:19:22 +04:00
|
|
|
#include "creds/abstractcredentials.h"
|
2015-07-23 12:34:12 +03:00
|
|
|
#include "updater/ocupdater.h"
|
2015-10-02 10:40:44 +03:00
|
|
|
#include "excludedfiles.h"
|
2015-12-01 18:30:57 +03:00
|
|
|
#include "owncloudsetupwizard.h"
|
2013-07-29 16:28:19 +04:00
|
|
|
|
2014-02-12 15:17:32 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-01-28 18:49:19 +04:00
|
|
|
#if defined(Q_OS_WIN)
|
2013-06-05 18:14:20 +04:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2015-03-12 18:49:47 +03:00
|
|
|
#if defined(WITH_CRASHREPORTER)
|
|
|
|
#include <libcrashreporter-handler/Handler.h>
|
|
|
|
#endif
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
#include <QTranslator>
|
2013-08-28 22:58:22 +04:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
2012-05-21 18:48:49 +04:00
|
|
|
|
2014-05-21 14:31:44 +04:00
|
|
|
class QSocket;
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2011-02-17 02:21:45 +03:00
|
|
|
|
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"
|
2015-09-07 09:51:22 +03:00
|
|
|
" in folder <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"
|
2015-09-07 09:51:22 +03:00
|
|
|
" --confdir <dirname> : Use the given configuration folder.\n"
|
2013-06-06 18:00:51 +04:00
|
|
|
;
|
|
|
|
|
2013-02-14 21:27:44 +04:00
|
|
|
QString applicationTrPath()
|
|
|
|
{
|
2015-09-10 02:25:16 +03:00
|
|
|
QString devTrPath = qApp->applicationDirPath() + QString::fromLatin1("/../src/gui/");
|
|
|
|
if (QDir(devTrPath).exists()) {
|
|
|
|
// might miss Qt, QtKeyChain, etc.
|
|
|
|
qDebug() << "Running from build location! Translations may be incomplete!";
|
|
|
|
return devTrPath;
|
|
|
|
}
|
2014-04-29 13:02:44 +04:00
|
|
|
#if defined(Q_OS_WIN)
|
2013-02-14 21:27:44 +04:00
|
|
|
return QApplication::applicationDirPath();
|
2014-04-29 13:02:44 +04:00
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
return QApplication::applicationDirPath()+QLatin1String("/../Resources/Translations"); // path defaults to app dir.
|
|
|
|
#elif defined(Q_OS_UNIX)
|
2015-07-30 17:37:22 +03:00
|
|
|
return QString::fromLatin1(SHAREDIR "/" APPLICATION_EXECUTABLE "/i18n/");
|
2013-02-14 21:27:44 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:11:29 +04:00
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
|
2012-04-20 15:17:48 +04:00
|
|
|
Application::Application(int &argc, char **argv) :
|
2014-05-20 19:12:56 +04:00
|
|
|
SharedTools::QtSingleApplication(Theme::instance()->appName() ,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),
|
2015-07-16 19:12:45 +03:00
|
|
|
_versionOnly(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),
|
2014-08-26 17:46:24 +04:00
|
|
|
_userTriggeredConnect(false),
|
|
|
|
_debugMode(false)
|
2011-02-17 02:21:45 +03:00
|
|
|
{
|
2015-09-28 23:51:16 +03:00
|
|
|
_startedAt.start();
|
|
|
|
|
2015-10-05 07:21:19 +03:00
|
|
|
// TODO: Can't set this without breaking current config paths
|
2014-02-12 15:17:32 +04:00
|
|
|
// setOrganizationName(QLatin1String(APPLICATION_VENDOR));
|
|
|
|
setOrganizationDomain(QLatin1String(APPLICATION_REV_DOMAIN));
|
2013-02-21 15:21:42 +04:00
|
|
|
setApplicationName( _theme->appNameGUI() );
|
2012-03-31 13:31:28 +04:00
|
|
|
setWindowIcon( _theme->applicationIcon() );
|
2015-02-13 00:13:58 +03:00
|
|
|
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
2015-02-12 21:44:30 +03:00
|
|
|
setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
2016-01-04 13:49:03 +03:00
|
|
|
#endif
|
2016-01-11 17:27:13 +03:00
|
|
|
|
2012-10-16 21:05:28 +04:00
|
|
|
parseOptions(arguments());
|
|
|
|
//no need to waste time;
|
2015-07-16 19:12:45 +03:00
|
|
|
if ( _helpOnly || _versionOnly ) return;
|
2012-04-18 14:10:14 +04:00
|
|
|
|
2013-12-10 15:46:00 +04:00
|
|
|
if (isRunning())
|
|
|
|
return;
|
|
|
|
|
2015-05-12 18:25:45 +03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) && QT_VERSION < QT_VERSION_CHECK(5, 4, 2)
|
2015-05-08 15:02:44 +03:00
|
|
|
// Workaround for QTBUG-44576: Make sure a stale QSettings lock file
|
2015-05-12 18:25:45 +03:00
|
|
|
// is deleted. (Introduced in Qt 5.4.0 and fixed in Qt 5.4.2)
|
2015-05-08 15:02:44 +03:00
|
|
|
{
|
|
|
|
QString lockFilePath = ConfigFile().configFile() + QLatin1String(".lock");
|
|
|
|
QLockFile(lockFilePath).removeStaleLockFile();
|
|
|
|
}
|
2015-05-11 14:35:04 +03:00
|
|
|
#endif
|
2015-05-08 15:02:44 +03:00
|
|
|
|
2015-03-12 18:49:47 +03:00
|
|
|
#if defined(WITH_CRASHREPORTER)
|
|
|
|
if (ConfigFile().crashReporter())
|
|
|
|
_crashHandler.reset(new CrashReporter::Handler( QDir::tempPath(), true, CRASHREPORTER_EXECUTABLE ));
|
|
|
|
#endif
|
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
setupLogging();
|
2013-08-15 15:02:27 +04:00
|
|
|
setupTranslations();
|
|
|
|
|
2015-10-02 10:40:44 +03:00
|
|
|
// Setup global excludes
|
|
|
|
ConfigFile cfg;
|
|
|
|
ExcludedFiles& excludes = ExcludedFiles::instance();
|
|
|
|
excludes.addExcludeFilePath( cfg.excludeFile(ConfigFile::SystemScope) );
|
|
|
|
excludes.addExcludeFilePath( cfg.excludeFile(ConfigFile::UserScope) );
|
|
|
|
excludes.reloadExcludes();
|
|
|
|
|
2015-01-08 18:52:23 +03:00
|
|
|
_folderManager.reset(new FolderMan);
|
|
|
|
|
2015-02-19 18:54:34 +03:00
|
|
|
connect(this, SIGNAL(messageReceived(QString, QObject*)), SLOT(slotParseMessage(QString, QObject*)));
|
2013-07-31 00:22:43 +04:00
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
AccountManager::instance()->restore();
|
2013-10-24 02:29:08 +04:00
|
|
|
|
2015-07-01 12:39:57 +03:00
|
|
|
FolderMan::instance()->setSyncEnabled(true);
|
2012-02-19 00:21:58 +04:00
|
|
|
|
2011-04-05 20:31:14 +04:00
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
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();
|
2014-01-16 15:07:58 +04:00
|
|
|
_proxy.setupQtProxyFromConfig(); // folders have to be defined first, than we set up the Qt proxy.
|
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.
|
|
|
|
}
|
2014-01-16 15:07:58 +04:00
|
|
|
|
2015-12-21 17:35:45 +03:00
|
|
|
// Enable word wrapping of QInputDialog (#4197)
|
|
|
|
setStyleSheet("QInputDialog QLabel { qproperty-wordWrap:1; }");
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
connect(AccountManager::instance(), SIGNAL(accountAdded(AccountState*)),
|
2014-12-17 16:09:57 +03:00
|
|
|
SLOT(slotAccountStateAdded(AccountState*)));
|
2015-04-17 18:56:17 +03:00
|
|
|
connect(AccountManager::instance(), SIGNAL(accountRemoved(AccountState*)),
|
2014-12-17 16:09:57 +03:00
|
|
|
SLOT(slotAccountStateRemoved(AccountState*)));
|
2015-04-17 18:56:17 +03:00
|
|
|
foreach (auto ai , AccountManager::instance()->accounts()) {
|
|
|
|
slotAccountStateAdded(ai.data());
|
2013-11-23 03:14:02 +04:00
|
|
|
}
|
2013-11-18 12:34:57 +04:00
|
|
|
|
2015-03-11 16:09:31 +03:00
|
|
|
connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString, bool)),
|
|
|
|
_gui, SLOT(slotShowShareDialog(QString, QString, bool)));
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
// startup procedure.
|
2014-04-19 11:45:54 +04:00
|
|
|
connect(&_checkConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCheckConnection()));
|
2016-02-10 14:35:26 +03:00
|
|
|
_checkConnectionTimer.setInterval(ConnectionValidator::DefaultCallingIntervalMsec); // check for connection every 32 seconds.
|
2014-04-19 11:45:54 +04:00
|
|
|
_checkConnectionTimer.start();
|
2015-10-05 07:21:19 +03:00
|
|
|
// Also check immediately
|
2013-07-05 15:14:48 +04:00
|
|
|
QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));
|
2012-02-23 14:44:44 +04:00
|
|
|
|
2015-11-23 23:47:30 +03:00
|
|
|
// Can't use onlineStateChanged because it is always true on modern systems because of many interfaces
|
|
|
|
connect(&_networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)),
|
|
|
|
this, SLOT(slotSystemOnlineConfigurationChanged(QNetworkConfiguration)));
|
|
|
|
|
2015-06-03 10:04:12 +03:00
|
|
|
// Update checks
|
2015-07-22 14:44:19 +03:00
|
|
|
UpdaterScheduler *updaterScheduler = new UpdaterScheduler(this);
|
|
|
|
connect(updaterScheduler, SIGNAL(updaterAnnouncement(QString, QString)),
|
|
|
|
_gui, SLOT(slotShowTrayMessage(QString, QString)));
|
2015-08-06 20:34:23 +03:00
|
|
|
connect(updaterScheduler, SIGNAL(requestRestart()),
|
|
|
|
_folderManager.data(), SLOT(slotScheduleAppRestart()));
|
2012-04-02 22:10:29 +04:00
|
|
|
|
2015-07-20 13:10:54 +03:00
|
|
|
// Cleanup at Quit.
|
2013-09-18 16:11:19 +04:00
|
|
|
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
|
2011-02-17 02:21:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
2015-09-18 12:58:10 +03:00
|
|
|
// Make sure all folders are gone, otherwise removing the
|
|
|
|
// accounts will remove the associated folders from the settings.
|
2015-09-30 12:40:33 +03:00
|
|
|
if (_folderManager) {
|
|
|
|
_folderManager->unloadAndDeleteAllFolders();
|
|
|
|
}
|
2015-09-18 12:58:10 +03:00
|
|
|
|
2015-03-27 12:30:35 +03:00
|
|
|
// Remove the account from the account manager so it can be deleted.
|
2015-04-17 18:56:17 +03:00
|
|
|
AccountManager::instance()->shutdown();
|
2012-03-29 11:41:30 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
void Application::slotAccountStateRemoved(AccountState *accountState)
|
2013-11-23 03:14:02 +04:00
|
|
|
{
|
2015-04-23 15:24:54 +03:00
|
|
|
if (_gui) {
|
2015-07-01 12:39:57 +03:00
|
|
|
disconnect(accountState, SIGNAL(stateChanged(int)),
|
|
|
|
_gui, SLOT(slotAccountStateChanged()));
|
2016-03-02 13:59:36 +03:00
|
|
|
disconnect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
|
|
|
|
_gui, SLOT(slotTrayMessageIfServerUnsupported(Account*)));
|
2015-07-01 12:39:57 +03:00
|
|
|
}
|
|
|
|
if (_folderManager) {
|
|
|
|
disconnect(accountState, SIGNAL(stateChanged(int)),
|
|
|
|
_folderManager.data(), SLOT(slotAccountStateChanged()));
|
2016-03-02 13:59:36 +03:00
|
|
|
disconnect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
|
|
|
|
_folderManager.data(), SLOT(slotServerVersionChanged(Account*)));
|
2015-04-23 15:24:54 +03:00
|
|
|
}
|
2015-12-01 18:30:57 +03:00
|
|
|
|
|
|
|
// if there is no more account, show the wizard.
|
|
|
|
if( AccountManager::instance()->accounts().isEmpty() ) {
|
|
|
|
// allow to add a new account if there is non any more. Always think
|
|
|
|
// about single account theming!
|
|
|
|
OwncloudSetupWizard::runWizard(this, SLOT(slotownCloudWizardDone(int)));
|
|
|
|
}
|
2013-11-23 03:14:02 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
void Application::slotAccountStateAdded(AccountState *accountState)
|
|
|
|
{
|
2015-07-01 12:39:57 +03:00
|
|
|
connect(accountState, SIGNAL(stateChanged(int)),
|
|
|
|
_gui, SLOT(slotAccountStateChanged()));
|
2016-03-02 13:59:36 +03:00
|
|
|
connect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
|
|
|
|
_gui, SLOT(slotTrayMessageIfServerUnsupported(Account*)));
|
2015-07-01 12:39:57 +03:00
|
|
|
connect(accountState, SIGNAL(stateChanged(int)),
|
|
|
|
_folderManager.data(), SLOT(slotAccountStateChanged()));
|
2016-03-02 13:59:36 +03:00
|
|
|
connect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
|
|
|
|
_folderManager.data(), SLOT(slotServerVersionChanged(Account*)));
|
|
|
|
|
|
|
|
_gui->slotTrayMessageIfServerUnsupported(accountState->account().data());
|
2014-12-17 16:09:57 +03:00
|
|
|
}
|
2013-11-23 03:14:02 +04:00
|
|
|
|
2013-10-01 15:52:07 +04:00
|
|
|
void Application::slotCleanup()
|
|
|
|
{
|
2015-04-09 17:19:17 +03:00
|
|
|
AccountManager::instance()->save();
|
2015-02-27 12:42:59 +03:00
|
|
|
FolderMan::instance()->unloadAndDeleteAllFolders();
|
2014-08-20 18:27:44 +04:00
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
_gui->slotShutdown();
|
2013-10-01 15:52:07 +04:00
|
|
|
_gui->deleteLater();
|
|
|
|
}
|
|
|
|
|
2015-11-23 23:47:30 +03:00
|
|
|
// FIXME: This is not ideal yet since a ConnectionValidator might already be running and is in
|
|
|
|
// progress of timing out in some seconds.
|
|
|
|
// Maybe we need 2 validators, one triggered by timer, one by network configuration changes?
|
|
|
|
void Application::slotSystemOnlineConfigurationChanged(QNetworkConfiguration cnf)
|
|
|
|
{
|
|
|
|
if (cnf.state() & QNetworkConfiguration::Active) {
|
|
|
|
//qDebug() << "Trying fast reconnect";
|
|
|
|
QMetaObject::invokeMethod(this, "slotCheckConnection", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 15:14:48 +04:00
|
|
|
void Application::slotCheckConnection()
|
2013-07-29 16:28:19 +04:00
|
|
|
{
|
2015-04-17 18:56:17 +03:00
|
|
|
auto list = AccountManager::instance()->accounts();
|
|
|
|
foreach (const auto &accountState , list) {
|
2015-07-01 13:30:18 +03:00
|
|
|
AccountState::State state = accountState->state();
|
|
|
|
|
|
|
|
// Don't check if we're manually signed out or
|
|
|
|
// when the error is permanent.
|
|
|
|
if (state != AccountState::SignedOut
|
|
|
|
&& state != AccountState::ConfigurationError) {
|
2016-01-21 15:33:03 +03:00
|
|
|
accountState->checkConnectivity();
|
2015-07-01 13:30:18 +03:00
|
|
|
}
|
2015-04-17 18:56:17 +03:00
|
|
|
}
|
2014-02-27 16:06:29 +04:00
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
if (list.isEmpty()) {
|
2013-11-29 19:12:58 +04:00
|
|
|
// let gui open the setup wizard
|
2015-09-02 12:10:01 +03:00
|
|
|
_gui->slotOpenSettingsDialog();
|
2014-05-27 13:04:16 +04:00
|
|
|
|
|
|
|
_checkConnectionTimer.stop(); // don't popup the wizard on interval;
|
2013-07-29 16:28:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 17:46:24 +04:00
|
|
|
void Application::slotCrash()
|
|
|
|
{
|
|
|
|
Utility::crash();
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:25:12 +04:00
|
|
|
void Application::slotownCloudWizardDone( int res )
|
|
|
|
{
|
2015-12-08 16:37:37 +03:00
|
|
|
AccountManager *accountMan = AccountManager::instance();
|
2013-07-22 15:59:52 +04:00
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
2015-12-08 16:37:37 +03:00
|
|
|
|
|
|
|
// During the wizard, scheduling of new syncs is disabled
|
|
|
|
folderMan->setSyncEnabled(true);
|
|
|
|
|
2012-11-28 22:25:12 +04:00
|
|
|
if( res == QDialog::Accepted ) {
|
2015-12-08 16:37:37 +03:00
|
|
|
// Open the settings page for the new account if no folders
|
|
|
|
// were configured. Using the last account for this check is
|
|
|
|
// not exactly correct, but good enough.
|
|
|
|
if (!accountMan->accounts().isEmpty()) {
|
|
|
|
AccountStatePtr newAccount = accountMan->accounts().last();
|
|
|
|
bool hasFolder = false;
|
|
|
|
foreach (Folder* folder, folderMan->map()) {
|
|
|
|
if (folder->accountState() == newAccount.data()) {
|
|
|
|
hasFolder = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasFolder) {
|
|
|
|
_gui->slotShowSettings();
|
|
|
|
}
|
2014-08-12 19:33:17 +04:00
|
|
|
}
|
2015-12-08 16:37:37 +03:00
|
|
|
|
|
|
|
// Check connectivity of the newly created account
|
2014-05-27 13:04:16 +04:00
|
|
|
_checkConnectionTimer.start();
|
2013-07-05 15:14:48 +04:00
|
|
|
slotCheckConnection();
|
|
|
|
|
2015-12-08 16:37:37 +03:00
|
|
|
// The very first time an account is configured: enabled autostart
|
|
|
|
// TODO: Doing this every time the account wizard finishes will annoy users.
|
|
|
|
Utility::setLaunchOnStartup(_theme->appName(), _theme->appNameGUI(), true);
|
|
|
|
}
|
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-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
|
|
|
}
|
|
|
|
|
2015-02-19 18:54:34 +03:00
|
|
|
void Application::slotParseMessage(const QString &msg, QObject*)
|
2012-10-16 21:05:28 +04:00
|
|
|
{
|
2015-02-19 18:54:34 +03:00
|
|
|
if (msg.startsWith(QLatin1String("MSG_PARSEOPTIONS:"))) {
|
|
|
|
const int lengthOfMsgPrefix = 17;
|
|
|
|
QStringList options = msg.mid(lengthOfMsgPrefix).split(QLatin1Char('|'));
|
|
|
|
parseOptions(options);
|
|
|
|
setupLogging();
|
|
|
|
} else if (msg.startsWith(QLatin1String("MSG_SHOWSETTINGS"))) {
|
2015-09-28 23:51:16 +03:00
|
|
|
qDebug() << "Running for" << _startedAt.elapsed()/1000.0 << "sec";
|
2015-10-15 15:19:46 +03:00
|
|
|
if (_startedAt.elapsed() < 10*1000) {
|
2015-09-28 23:51:16 +03:00
|
|
|
// This call is mirrored with the one in int main()
|
|
|
|
qWarning() << "Ignoring MSG_SHOWSETTINGS, possibly double-invocation of client via session restore and auto start";
|
|
|
|
return;
|
|
|
|
}
|
2015-02-19 18:54:34 +03:00
|
|
|
showSettingsDialog();
|
|
|
|
}
|
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 {
|
2015-07-03 17:01:24 +03:00
|
|
|
showHint("Log file not specified");
|
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 {
|
2015-07-03 17:01:24 +03:00
|
|
|
showHint("Log dir not specified");
|
2013-06-03 18:23:29 +04:00
|
|
|
}
|
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 {
|
2015-07-03 17:01:24 +03:00
|
|
|
showHint("Log expiration not specified");
|
2013-06-07 20:57:45 +04:00
|
|
|
}
|
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();
|
2015-03-23 16:59:29 +03:00
|
|
|
if (!ConfigFile::setConfDir( confDir )) {
|
2015-07-03 17:01:24 +03:00
|
|
|
showHint("Invalid path passed to --confdir");
|
2015-03-23 16:59:29 +03:00
|
|
|
}
|
2013-01-02 21:43:40 +04:00
|
|
|
} else {
|
2015-07-03 17:01:24 +03:00
|
|
|
showHint("Path for confdir not specified");
|
2013-01-02 21:43:40 +04:00
|
|
|
}
|
2014-08-26 17:46:24 +04:00
|
|
|
} else if (option == QLatin1String("--debug")) {
|
|
|
|
_debugMode = true;
|
2015-07-16 19:12:45 +03:00
|
|
|
} else if (option == QLatin1String("--version")) {
|
|
|
|
_versionOnly = true;
|
2013-04-03 16:42:13 +04:00
|
|
|
} else {
|
2015-07-03 17:01:24 +03:00
|
|
|
showHint("Unrecognized option '" + option.toStdString() + "'");
|
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
|
|
|
}
|
|
|
|
|
2015-07-16 19:12:45 +03:00
|
|
|
void Application::showVersion()
|
|
|
|
{
|
|
|
|
QString helpText;
|
|
|
|
QTextStream stream(&helpText);
|
|
|
|
stream << _theme->appName().toLatin1().constData()
|
|
|
|
<< QLatin1String(" version ")
|
|
|
|
<< _theme->version().toLatin1().constData() << endl;
|
2015-10-29 11:48:36 +03:00
|
|
|
stream << "Using Qt " << qVersion() << endl;
|
2015-07-16 19:12:45 +03:00
|
|
|
|
|
|
|
displayHelpText(helpText);
|
|
|
|
}
|
|
|
|
|
2015-07-03 17:01:24 +03:00
|
|
|
void Application::showHint(std::string errorHint)
|
|
|
|
{
|
|
|
|
static QString binName = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
|
|
|
|
std::cerr << errorHint << std::endl;
|
|
|
|
std::cerr << "Try '" << binName.toStdString() << " --help' for more information" << std::endl;
|
|
|
|
std::exit(1);
|
|
|
|
}
|
|
|
|
|
2014-08-26 17:46:24 +04:00
|
|
|
bool Application::debugMode()
|
|
|
|
{
|
|
|
|
return _debugMode;
|
|
|
|
}
|
|
|
|
|
2013-01-29 08:19:14 +04:00
|
|
|
void Application::setHelp()
|
|
|
|
{
|
2012-06-15 15:36:38 +04:00
|
|
|
_helpOnly = true;
|
|
|
|
}
|
|
|
|
|
2013-02-24 18:22:21 +04:00
|
|
|
QString substLang(const QString &lang)
|
|
|
|
{
|
2015-10-05 07:21:19 +03:00
|
|
|
// Map the more appropriate script codes
|
2013-02-24 18:22:21 +04:00
|
|
|
// 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();
|
2015-02-06 17:15:33 +03:00
|
|
|
const QString trFile = QLatin1String("client_") + 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.
|
2015-10-05 07:21:19 +03:00
|
|
|
// "en" is an exception as it is the default language and may not
|
2013-02-24 18:20:59 +04:00
|
|
|
// 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;
|
2014-10-15 19:10:41 +04:00
|
|
|
const QString qtBaseTrFile = QLatin1String("qtbase_") + lang;
|
2014-10-15 11:32:44 +04:00
|
|
|
if (!qtTranslator->load(qtTrFile, qtTrPath)) {
|
2014-10-15 19:10:41 +04:00
|
|
|
if (!qtTranslator->load(qtTrFile, trPath)) {
|
2016-01-04 13:47:11 +03:00
|
|
|
if (!qtTranslator->load(qtBaseTrFile, qtTrPath)) {
|
|
|
|
qtTranslator->load(qtBaseTrFile, trPath);
|
|
|
|
}
|
2014-10-15 19:10:41 +04:00
|
|
|
}
|
2013-02-24 18:20:59 +04:00
|
|
|
}
|
2014-10-15 19:10:41 +04:00
|
|
|
const QString qtkeychainTrFile = QLatin1String("qtkeychain_") + lang;
|
|
|
|
if (!qtkeychainTranslator->load(qtkeychainTrFile, qtTrPath)) {
|
|
|
|
qtkeychainTranslator->load(qtkeychainTrFile, trPath);
|
2013-02-24 18:20:59 +04:00
|
|
|
}
|
|
|
|
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");
|
|
|
|
}
|
2016-01-06 14:51:25 +03:00
|
|
|
// Work around Qt 5 < 5.5.0 regression, see https://bugreports.qt.io/browse/QTBUG-43447
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
|
|
|
setLayoutDirection(QApplication::tr("QT_LAYOUT_DIRECTION") == QLatin1String("RTL") ? Qt::RightToLeft : Qt::LeftToRight);
|
|
|
|
#endif
|
2013-02-14 21:27:44 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 15:36:38 +04:00
|
|
|
bool Application::giveHelp()
|
|
|
|
{
|
|
|
|
return _helpOnly;
|
|
|
|
}
|
2015-01-26 15:00:45 +03:00
|
|
|
|
2015-07-16 19:12:45 +03:00
|
|
|
bool Application::versionOnly()
|
|
|
|
{
|
|
|
|
return _versionOnly;
|
|
|
|
}
|
|
|
|
|
2015-01-26 15:00:45 +03:00
|
|
|
void Application::showSettingsDialog()
|
|
|
|
{
|
|
|
|
_gui->slotShowSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|
2011-02-17 02:21:45 +03:00
|
|
|
|