2012-02-17 14:11:18 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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-05-21 18:48:49 +04:00
|
|
|
|
2012-09-18 14:55:58 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
#include "mirall/mirallconfigfile.h"
|
2013-02-06 12:08:36 +04:00
|
|
|
#include "mirall/owncloudinfo.h"
|
2012-05-21 18:48:49 +04:00
|
|
|
#include "mirall/owncloudtheme.h"
|
2013-05-17 22:12:31 +04:00
|
|
|
#include "mirall/theme.h"
|
2013-07-30 13:19:22 +04:00
|
|
|
#include "creds/abstractcredentials.h"
|
|
|
|
#include "creds/credentialsfactory.h"
|
2012-02-17 14:11:18 +04:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QtGui>
|
|
|
|
|
2012-05-26 16:37:21 +04:00
|
|
|
#define DEFAULT_REMOTE_POLL_INTERVAL 30000 // default remote poll time in milliseconds
|
2013-07-19 18:27:54 +04:00
|
|
|
#define DEFAULT_MAX_LOG_LINES 20000
|
2012-08-06 15:57:26 +04:00
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
namespace Mirall {
|
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
static const char urlC[] = "url";
|
2013-07-29 16:28:19 +04:00
|
|
|
static const char authTypeC[] = "authType";
|
2013-07-19 18:27:54 +04:00
|
|
|
|
|
|
|
static const char caCertsKeyC[] = "CaCertificates";
|
|
|
|
static const char remotePollIntervalC[] = "remotePollInterval";
|
2013-08-08 16:30:45 +04:00
|
|
|
static const char forceSyncIntervalC[] = "forceSyncInterval";
|
2013-07-19 18:27:54 +04:00
|
|
|
static const char monoIconsC[] = "monoIcons";
|
|
|
|
static const char optionalDesktopNoficationsC[] = "optionalDesktopNotifications";
|
|
|
|
static const char skipUpdateCheckC[] = "skipUpdateCheck";
|
2013-07-22 14:28:43 +04:00
|
|
|
static const char geometryC[] = "geometry";
|
2013-07-19 18:27:54 +04:00
|
|
|
|
|
|
|
static const char proxyHostC[] = "Proxy/host";
|
|
|
|
static const char proxyTypeC[] = "Proxy/type";
|
|
|
|
static const char proxyPortC[] = "Proxy/port";
|
|
|
|
static const char proxyUserC[] = "Proxy/user";
|
|
|
|
static const char proxyPassC[] = "Proxy/pass";
|
|
|
|
static const char proxyNeedsAuthC[] = "Proxy/needsAuth";
|
|
|
|
|
2013-07-24 21:53:05 +04:00
|
|
|
static const char useUploadLimitC[] = "BWLimit/useUploadLimit";
|
|
|
|
static const char useDownloadLimitC[] = "BWLimit/useDownloadLimit";
|
|
|
|
static const char uploadLimitC[] = "BWLimit/uploadLimit";
|
|
|
|
static const char downloadLimitC[] = "BWLimit/downloadLimit";
|
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
static const char seenVersionC[] = "Updater/seenVersion";
|
|
|
|
static const char maxLogLinesC[] = "Logging/maxLogLines";
|
|
|
|
|
2012-06-12 14:27:02 +04:00
|
|
|
QString MirallConfigFile::_oCVersion;
|
2013-04-04 17:19:23 +04:00
|
|
|
QString MirallConfigFile::_confDir = QString::null;
|
2012-04-12 16:06:59 +04:00
|
|
|
bool MirallConfigFile::_askedUser = false;
|
2013-07-29 16:28:19 +04:00
|
|
|
QMap< QString, MirallConfigFile::SharedCreds > MirallConfigFile::credentialsPerConfig;
|
2012-04-12 16:06:59 +04:00
|
|
|
|
2013-08-08 15:03:49 +04:00
|
|
|
MirallConfigFile::MirallConfigFile( const QString& appendix, bool useOldConfig )
|
2012-02-17 14:11:18 +04:00
|
|
|
{
|
2013-08-08 15:03:49 +04:00
|
|
|
|
|
|
|
if (useOldConfig && !appendix.isEmpty()) {
|
|
|
|
QString oldConfigFile = configFile();
|
|
|
|
_customHandle = appendix;
|
|
|
|
QString newConfigFile = configFile();
|
|
|
|
QFile::copy(oldConfigFile, newConfigFile);
|
|
|
|
} else {
|
|
|
|
_customHandle = appendix;
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
2013-07-29 16:28:19 +04:00
|
|
|
if (! credentialsPerConfig.contains(_customHandle)) {
|
|
|
|
QString con( _customHandle );
|
|
|
|
if( _customHandle.isEmpty() ) con = defaultConnection();
|
|
|
|
|
|
|
|
const QString config = configFile();
|
|
|
|
qDebug() << "Loading config: " << config;
|
|
|
|
|
2013-08-08 15:03:49 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(config, QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
|
|
|
settings.beginGroup( con );
|
|
|
|
|
|
|
|
QString type = settings.value( QLatin1String(authTypeC) ).toString();
|
|
|
|
|
|
|
|
qDebug() << "Getting credentials of type " << type << " for " << _customHandle;
|
|
|
|
|
|
|
|
credentialsPerConfig.insert(_customHandle, SharedCreds(CredentialsFactory::create (type)));
|
|
|
|
}
|
2012-02-17 14:11:18 +04:00
|
|
|
}
|
|
|
|
|
2013-01-14 03:48:26 +04:00
|
|
|
void MirallConfigFile::setConfDir(const QString &value)
|
|
|
|
{
|
2013-08-15 15:01:05 +04:00
|
|
|
QString dirPath = value;
|
|
|
|
if( dirPath.isEmpty() ) return;
|
|
|
|
|
|
|
|
QFileInfo fi(dirPath);
|
|
|
|
if ( !fi.exists() && !fi.isAbsolute() ) {
|
|
|
|
QDir::current().mkdir(dirPath);
|
|
|
|
QDir dir = QDir::current();
|
|
|
|
dir.cd(dirPath);
|
|
|
|
fi.setFile(dir.path());
|
|
|
|
}
|
2013-04-03 16:42:13 +04:00
|
|
|
if( fi.exists() && fi.isDir() ) {
|
2013-08-15 15:09:20 +04:00
|
|
|
dirPath = fi.absoluteFilePath();
|
|
|
|
qDebug() << "** Using custom config dir " << dirPath;
|
|
|
|
_confDir=dirPath;
|
2013-04-03 16:42:13 +04:00
|
|
|
}
|
2013-01-14 03:48:26 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 03:01:23 +04:00
|
|
|
bool MirallConfigFile::optionalDesktopNotifications() const
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
return settings.value(QLatin1String(optionalDesktopNoficationsC), true).toBool();
|
2013-07-05 03:01:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setOptionalDesktopNotifications(bool show)
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue(QLatin1String(optionalDesktopNoficationsC), show);
|
2013-07-05 03:01:23 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
2013-04-30 19:41:31 +04:00
|
|
|
QString MirallConfigFile::seenVersion() const
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
return settings.value(QLatin1String(seenVersionC)).toString();
|
2013-04-30 19:41:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setSeenVersion(const QString &version)
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue(QLatin1String(seenVersionC), version);
|
2013-04-30 19:41:31 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
2013-07-22 14:28:43 +04:00
|
|
|
void MirallConfigFile::saveGeometry(QWidget *w)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!w->objectName().isNull());
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-22 14:28:43 +04:00
|
|
|
settings.beginGroup(w->objectName());
|
|
|
|
settings.setValue(QLatin1String(geometryC), w->saveGeometry());
|
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::restoreGeometry(QWidget *w)
|
|
|
|
{
|
|
|
|
w->restoreGeometry(getValue(geometryC, w->objectName()).toByteArray());
|
|
|
|
}
|
|
|
|
|
2012-03-28 13:26:51 +04:00
|
|
|
QString MirallConfigFile::configPath() const
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
if( _confDir.isEmpty() ) {
|
2013-04-04 17:19:23 +04:00
|
|
|
_confDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
2013-07-29 16:28:19 +04:00
|
|
|
}
|
|
|
|
QString dir = _confDir;
|
2013-04-04 17:19:23 +04:00
|
|
|
|
2012-08-17 19:13:17 +04:00
|
|
|
if( !dir.endsWith(QLatin1Char('/')) ) dir.append(QLatin1Char('/'));
|
2012-03-28 13:26:51 +04:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2013-07-05 18:54:11 +04:00
|
|
|
QString MirallConfigFile::excludeFile(Scope scope) const
|
2012-03-28 14:23:34 +04:00
|
|
|
{
|
2012-09-27 15:16:14 +04:00
|
|
|
// prefer sync-exclude.lst, but if it does not exist, check for
|
2013-07-05 18:54:11 +04:00
|
|
|
// exclude.lst for compatibility reasons in the user writeable
|
2012-09-27 15:16:14 +04:00
|
|
|
// directories.
|
|
|
|
const QString exclFile("sync-exclude.lst");
|
|
|
|
QFileInfo fi;
|
|
|
|
|
2013-07-05 18:54:11 +04:00
|
|
|
if (scope != SystemScope) {
|
|
|
|
fi.setFile( configPath(), exclFile );
|
|
|
|
|
|
|
|
if( ! fi.isReadable() ) {
|
|
|
|
fi.setFile( configPath(), QLatin1String("exclude.lst") );
|
|
|
|
}
|
|
|
|
if( ! fi.isReadable() ) {
|
|
|
|
fi.setFile( configPath(), exclFile );
|
|
|
|
}
|
2012-03-28 14:23:34 +04:00
|
|
|
}
|
2012-08-17 19:00:03 +04:00
|
|
|
|
2013-07-05 18:54:11 +04:00
|
|
|
if (scope != UserScope) {
|
|
|
|
// Check alternative places...
|
|
|
|
if( ! fi.isReadable() ) {
|
2013-07-19 18:27:54 +04:00
|
|
|
#ifdef Q_OS_WIN
|
2013-07-05 18:54:11 +04:00
|
|
|
fi.setFile( QApplication::applicationDirPath(), exclFile );
|
2012-05-16 16:55:19 +04:00
|
|
|
#endif
|
2013-07-19 18:27:54 +04:00
|
|
|
#ifdef Q_OS_UNIX
|
2013-08-22 11:40:15 +04:00
|
|
|
fi.setFile( QString( SYSCONFDIR "/%1").arg(Theme::instance()->appName()), exclFile );
|
2012-05-16 16:55:19 +04:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_MAC
|
2013-07-05 18:54:11 +04:00
|
|
|
// exec path is inside the bundle
|
|
|
|
fi.setFile( QApplication::applicationDirPath(),
|
|
|
|
QLatin1String("../Resources/") + exclFile );
|
2012-04-01 17:09:04 +04:00
|
|
|
#endif
|
2013-07-05 18:54:11 +04:00
|
|
|
}
|
2012-09-27 15:16:14 +04:00
|
|
|
}
|
2013-07-05 18:54:11 +04:00
|
|
|
qDebug() << " ==> returning exclude file path: " << fi.absoluteFilePath();
|
|
|
|
return fi.absoluteFilePath();
|
2012-04-01 17:09:04 +04:00
|
|
|
qDebug() << "EMPTY exclude file path!";
|
2012-08-17 19:13:17 +04:00
|
|
|
return QString::null;
|
2012-03-28 14:23:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MirallConfigFile::configFile() const
|
2012-02-17 14:11:18 +04:00
|
|
|
{
|
2012-02-17 15:16:48 +04:00
|
|
|
if( qApp->applicationName().isEmpty() ) {
|
2013-02-21 15:21:42 +04:00
|
|
|
qApp->setApplicationName( Theme::instance()->appNameGUI() );
|
2012-02-17 15:16:48 +04:00
|
|
|
}
|
2013-07-29 16:28:19 +04:00
|
|
|
QString file = configPath() + Theme::instance()->configFileName();
|
2012-06-12 14:27:02 +04:00
|
|
|
if( !_customHandle.isEmpty() ) {
|
2013-07-29 16:28:19 +04:00
|
|
|
file.append( QLatin1Char('_'));
|
|
|
|
file.append( _customHandle );
|
|
|
|
qDebug() << __PRETTY_FUNCTION__ << " OO Custom config file in use: " << file;
|
2012-06-12 14:27:02 +04:00
|
|
|
}
|
2013-07-29 16:28:19 +04:00
|
|
|
return file;
|
2012-02-17 14:11:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MirallConfigFile::exists()
|
|
|
|
{
|
2012-03-28 14:23:34 +04:00
|
|
|
QFile file( configFile() );
|
2012-02-17 14:11:18 +04:00
|
|
|
return file.exists();
|
|
|
|
}
|
|
|
|
|
2012-02-18 20:02:10 +04:00
|
|
|
QString MirallConfigFile::defaultConnection() const
|
|
|
|
{
|
2012-09-26 18:53:56 +04:00
|
|
|
return Theme::instance()->appName();
|
2012-02-18 20:02:10 +04:00
|
|
|
}
|
|
|
|
|
2012-02-17 18:54:39 +04:00
|
|
|
bool MirallConfigFile::connectionExists( const QString& conn )
|
|
|
|
{
|
|
|
|
QString con = conn;
|
2012-02-18 20:02:10 +04:00
|
|
|
if( conn.isEmpty() ) con = defaultConnection();
|
2012-02-17 18:54:39 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-02-17 18:54:39 +04:00
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.beginGroup(conn);
|
|
|
|
return settings.contains( QLatin1String(urlC) );
|
2012-02-17 18:54:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
void MirallConfigFile::writeOwncloudConfig( const QString& connection,
|
2012-04-12 16:06:59 +04:00
|
|
|
const QString& url,
|
2013-07-29 16:28:19 +04:00
|
|
|
AbstractCredentials* credentials)
|
2012-02-17 14:11:18 +04:00
|
|
|
{
|
2012-03-28 14:23:34 +04:00
|
|
|
const QString file = configFile();
|
2013-07-19 17:50:33 +04:00
|
|
|
qDebug() << "*** writing mirall config to " << file;
|
2012-03-13 20:52:23 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-02-17 14:11:18 +04:00
|
|
|
|
|
|
|
settings.beginGroup( connection );
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue( QLatin1String(urlC), url );
|
2013-07-29 16:28:19 +04:00
|
|
|
settings.setValue(QLatin1String(authTypeC), credentials->authType());
|
|
|
|
credentialsPerConfig.insert(_customHandle, SharedCreds(credentials));
|
2012-02-17 14:11:18 +04:00
|
|
|
settings.sync();
|
2012-03-13 20:52:23 +04:00
|
|
|
// check the perms, only read-write for the owner.
|
|
|
|
QFile::setPermissions( file, QFile::ReadOwner|QFile::WriteOwner );
|
|
|
|
|
2012-12-09 01:56:48 +04:00
|
|
|
// Store credentials temporar until the config is finalized.
|
2013-07-29 16:28:19 +04:00
|
|
|
//ownCloudInfo::instance()->setCredentials( user, passwd, _customHandle );
|
2012-11-15 14:42:49 +04:00
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
void MirallConfigFile::storeData(const QString& group, const QString& key, const QVariant& value)
|
2012-12-04 20:27:59 +04:00
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
const QString con(group.isEmpty() ? defaultConnection() : group);
|
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-12-04 20:27:59 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
settings.beginGroup(con);
|
|
|
|
settings.setValue(key, value);
|
2012-12-04 20:27:59 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QVariant MirallConfigFile::retrieveData(const QString& group, const QString& key) const
|
2012-12-11 18:07:44 +04:00
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
const QString con(group.isEmpty() ? defaultConnection() : group);
|
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-12-11 18:07:44 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
settings.beginGroup(con);
|
|
|
|
return settings.value(key);
|
|
|
|
}
|
2012-12-11 18:07:44 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
void MirallConfigFile::removeData(const QString& group, const QString& key)
|
|
|
|
{
|
|
|
|
const QString con(group.isEmpty() ? defaultConnection() : group);
|
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-12-28 16:41:26 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
settings.beginGroup(con);
|
|
|
|
settings.remove(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MirallConfigFile::dataExists(const QString& group, const QString& key) const
|
|
|
|
{
|
|
|
|
const QString con(group.isEmpty() ? defaultConnection() : group);
|
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
|
|
|
|
|
|
|
settings.beginGroup(con);
|
|
|
|
return settings.contains(key);
|
2012-12-11 18:07:44 +04:00
|
|
|
}
|
|
|
|
|
2012-08-06 15:57:26 +04:00
|
|
|
QByteArray MirallConfigFile::caCerts( )
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
return settings.value( QLatin1String(caCertsKeyC) ).toByteArray();
|
2012-08-06 15:57:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setCaCerts( const QByteArray & certs )
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-08-06 15:57:26 +04:00
|
|
|
|
|
|
|
settings.setIniCodec( "UTF-8" );
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue( QLatin1String(caCertsKeyC), certs );
|
2012-08-06 15:57:26 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-17 18:54:39 +04:00
|
|
|
void MirallConfigFile::removeConnection( const QString& connection )
|
|
|
|
{
|
|
|
|
QString con( connection );
|
2012-02-18 20:02:10 +04:00
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
2012-02-17 18:54:39 +04:00
|
|
|
|
|
|
|
qDebug() << " removing the config file for connection " << con;
|
|
|
|
|
|
|
|
// Currently its just removing the entire config file
|
2013-07-29 16:28:19 +04:00
|
|
|
// TODO: Eh? Shouldn't it try to load a file under configFile() and set it to INI?
|
2013-07-19 18:27:54 +04:00
|
|
|
QSettings settings;
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-02-17 18:54:39 +04:00
|
|
|
settings.beginGroup( con );
|
2012-08-17 19:13:17 +04:00
|
|
|
settings.remove(QString::null); // removes all content from the group
|
2012-02-17 18:54:39 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
/*
|
|
|
|
* returns the configured owncloud url if its already configured, otherwise an empty
|
|
|
|
* string.
|
2012-02-18 20:02:10 +04:00
|
|
|
* The returned url always has a trailing hash.
|
2012-02-17 14:11:18 +04:00
|
|
|
*/
|
2013-06-20 18:56:25 +04:00
|
|
|
QString MirallConfigFile::ownCloudUrl( const QString& connection) const
|
2012-02-17 14:11:18 +04:00
|
|
|
{
|
|
|
|
QString con( connection );
|
2012-02-18 20:02:10 +04:00
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
2012-02-17 14:11:18 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-02-17 14:11:18 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
QString url = settings.value( QLatin1String(urlC) ).toString();
|
2012-03-14 12:56:47 +04:00
|
|
|
if( ! url.isEmpty() ) {
|
2012-08-17 19:13:17 +04:00
|
|
|
if( ! url.endsWith(QLatin1Char('/'))) url.append(QLatin1String("/"));
|
2012-03-14 12:56:47 +04:00
|
|
|
}
|
2012-02-17 14:11:18 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
return url;
|
2012-02-17 14:11:18 +04:00
|
|
|
}
|
|
|
|
|
2012-05-26 16:37:21 +04:00
|
|
|
int MirallConfigFile::remotePollInterval( const QString& connection ) const
|
|
|
|
{
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-05-26 16:37:21 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
int remoteInterval = settings.value( QLatin1String(remotePollIntervalC), DEFAULT_REMOTE_POLL_INTERVAL ).toInt();
|
2013-01-16 21:03:40 +04:00
|
|
|
if( remoteInterval < 5000) {
|
|
|
|
qDebug() << "Remote Interval is less than 5 seconds, reverting to" << DEFAULT_REMOTE_POLL_INTERVAL;
|
2012-05-26 16:37:21 +04:00
|
|
|
remoteInterval = DEFAULT_REMOTE_POLL_INTERVAL;
|
|
|
|
}
|
|
|
|
return remoteInterval;
|
|
|
|
}
|
|
|
|
|
2013-01-23 06:35:42 +04:00
|
|
|
void MirallConfigFile::setRemotePollInterval(int interval, const QString &connection )
|
2013-02-10 14:27:21 +04:00
|
|
|
{
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
|
|
|
|
if( interval < 5000 ) {
|
|
|
|
qDebug() << "Remote Poll interval of " << interval << " is below fife seconds.";
|
|
|
|
return;
|
|
|
|
}
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-02-10 14:27:21 +04:00
|
|
|
settings.beginGroup( con );
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue(QLatin1String(remotePollIntervalC), interval );
|
2013-02-10 14:27:21 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
2013-08-08 16:30:45 +04:00
|
|
|
quint64 MirallConfigFile::forceSyncInterval(const QString& connection) const
|
|
|
|
{
|
|
|
|
uint pollInterval = remotePollInterval(connection);
|
|
|
|
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
|
|
|
settings.beginGroup( con );
|
|
|
|
|
|
|
|
quint64 interval = settings.value( QLatin1String(forceSyncIntervalC), 10 * pollInterval ).toULongLong();
|
|
|
|
if( interval < pollInterval) {
|
|
|
|
qDebug() << "Force sync interval is less than the remote poll inteval, reverting to" << pollInterval;
|
|
|
|
interval = pollInterval;
|
|
|
|
}
|
|
|
|
return interval;
|
|
|
|
}
|
|
|
|
|
2012-05-14 18:22:30 +04:00
|
|
|
QString MirallConfigFile::ownCloudVersion() const
|
|
|
|
{
|
|
|
|
return _oCVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setOwnCloudVersion( const QString& ver)
|
|
|
|
{
|
|
|
|
qDebug() << "** Setting ownCloud Server version to " << ver;
|
|
|
|
_oCVersion = ver;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-02 22:10:29 +04:00
|
|
|
bool MirallConfigFile::ownCloudSkipUpdateCheck( const QString& connection ) const
|
|
|
|
{
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-04-02 22:10:29 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
bool skipIt = settings.value( QLatin1String(skipUpdateCheckC), false ).toBool();
|
2012-04-02 22:10:29 +04:00
|
|
|
|
|
|
|
return skipIt;
|
|
|
|
}
|
|
|
|
|
2013-02-18 19:17:03 +04:00
|
|
|
void MirallConfigFile::setOwnCloudSkipUpdateCheck( bool skip, const QString& connection )
|
|
|
|
{
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-02-18 19:17:03 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue( QLatin1String(skipUpdateCheckC), QVariant(skip) );
|
2013-02-18 19:17:03 +04:00
|
|
|
settings.sync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:11:29 +04:00
|
|
|
int MirallConfigFile::maxLogLines() const
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
return settings.value( QLatin1String(maxLogLinesC), DEFAULT_MAX_LOG_LINES ).toInt();
|
2012-06-05 17:11:29 +04:00
|
|
|
}
|
2012-04-02 22:10:29 +04:00
|
|
|
|
2013-02-18 19:17:03 +04:00
|
|
|
void MirallConfigFile::setMaxLogLines( int lines )
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue(QLatin1String(maxLogLinesC), lines);
|
2013-02-18 19:17:03 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
2012-06-12 14:27:02 +04:00
|
|
|
// remove a custom config file.
|
|
|
|
void MirallConfigFile::cleanupCustomConfig()
|
|
|
|
{
|
|
|
|
if( _customHandle.isEmpty() ) {
|
|
|
|
qDebug() << "SKipping to erase the main configuration.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString file = configFile();
|
|
|
|
if( QFile::exists( file ) ) {
|
|
|
|
QFile::remove( file );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// accept a config identified by the customHandle as general config.
|
|
|
|
void MirallConfigFile::acceptCustomConfig()
|
|
|
|
{
|
|
|
|
if( _customHandle.isEmpty() ) {
|
|
|
|
qDebug() << "WRN: Custom Handle is empty. Can not accept.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString srcConfig = configFile(); // this considers the custom handle
|
2012-12-09 01:56:48 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
credentialsPerConfig.insert(QString(), credentialsPerConfig[_customHandle]);
|
|
|
|
credentialsPerConfig.remove(_customHandle);
|
2012-06-12 14:27:02 +04:00
|
|
|
_customHandle.clear();
|
|
|
|
QString targetConfig = configFile();
|
|
|
|
QString targetBak = targetConfig + QLatin1String(".bak");
|
|
|
|
|
|
|
|
bool bakOk = false;
|
|
|
|
// remove an evtl existing old config backup.
|
|
|
|
if( QFile::exists( targetBak ) ) {
|
|
|
|
QFile::remove( targetBak );
|
|
|
|
}
|
|
|
|
// create a backup of the current config.
|
|
|
|
bakOk = QFile::rename( targetConfig, targetBak );
|
|
|
|
|
|
|
|
// move the custom config to the master place.
|
|
|
|
if( ! QFile::rename( srcConfig, targetConfig ) ) {
|
|
|
|
// if the move from custom to master failed, put old backup back.
|
|
|
|
if( bakOk ) {
|
|
|
|
QFile::rename( targetBak, targetConfig );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QFile::remove( targetBak );
|
2012-12-09 01:56:48 +04:00
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
credentialsPerConfig[QString()]->persistForUrl(ownCloudUrl());
|
2012-06-12 14:27:02 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 12:17:52 +04:00
|
|
|
void MirallConfigFile::setProxyType(int proxyType,
|
|
|
|
const QString& host,
|
2013-05-29 14:56:23 +04:00
|
|
|
int port, bool needsAuth,
|
2012-07-31 12:17:52 +04:00
|
|
|
const QString& user,
|
|
|
|
const QString& pass)
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2012-07-31 12:17:52 +04:00
|
|
|
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue(QLatin1String(proxyTypeC), proxyType);
|
2012-07-31 12:17:52 +04:00
|
|
|
|
2013-05-29 04:14:40 +04:00
|
|
|
if (proxyType == QNetworkProxy::HttpProxy ||
|
|
|
|
proxyType == QNetworkProxy::Socks5Proxy) {
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue(QLatin1String(proxyHostC), host);
|
|
|
|
settings.setValue(QLatin1String(proxyPortC), port);
|
|
|
|
settings.setValue(QLatin1String(proxyNeedsAuthC), needsAuth);
|
|
|
|
settings.setValue(QLatin1String(proxyUserC), user);
|
|
|
|
settings.setValue(QLatin1String(proxyPassC), pass.toUtf8().toBase64());
|
2013-05-29 03:41:04 +04:00
|
|
|
}
|
2012-07-31 12:17:52 +04:00
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
|
2013-07-24 21:53:05 +04:00
|
|
|
QVariant MirallConfigFile::getValue(const QString& param, const QString& group,
|
|
|
|
const QVariant& defaultValue) const
|
2012-07-31 12:17:52 +04:00
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
if (!group.isEmpty())
|
|
|
|
settings.beginGroup(group);
|
2012-07-31 12:17:52 +04:00
|
|
|
|
2013-07-24 21:53:05 +04:00
|
|
|
return settings.value(param, defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setValue(const QString& key, const QVariant &value)
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-24 21:53:05 +04:00
|
|
|
|
|
|
|
settings.setValue(key, value);
|
2012-07-31 12:17:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int MirallConfigFile::proxyType() const
|
|
|
|
{
|
2013-07-19 18:27:54 +04:00
|
|
|
return getValue(QLatin1String(proxyTypeC)).toInt();
|
2012-07-31 12:17:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MirallConfigFile::proxyHostName() const
|
|
|
|
{
|
2013-07-19 18:27:54 +04:00
|
|
|
return getValue(QLatin1String(proxyHostC)).toString();
|
2012-07-31 12:17:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int MirallConfigFile::proxyPort() const
|
|
|
|
{
|
2013-07-19 18:27:54 +04:00
|
|
|
return getValue(QLatin1String(proxyPortC)).toInt();
|
2012-02-17 14:11:18 +04:00
|
|
|
}
|
2012-06-12 14:27:02 +04:00
|
|
|
|
2013-05-29 14:56:23 +04:00
|
|
|
bool MirallConfigFile::proxyNeedsAuth() const
|
|
|
|
{
|
2013-07-19 18:27:54 +04:00
|
|
|
return getValue(QLatin1String(proxyNeedsAuthC)).toBool();
|
2013-05-29 14:56:23 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 12:17:52 +04:00
|
|
|
QString MirallConfigFile::proxyUser() const
|
|
|
|
{
|
2013-07-19 18:27:54 +04:00
|
|
|
return getValue(QLatin1String(proxyUserC)).toString();
|
2012-07-31 12:17:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MirallConfigFile::proxyPassword() const
|
|
|
|
{
|
2013-07-19 18:27:54 +04:00
|
|
|
QByteArray pass = getValue(proxyPassC).toByteArray();
|
2012-07-31 12:17:52 +04:00
|
|
|
return QString::fromUtf8(QByteArray::fromBase64(pass));
|
|
|
|
}
|
|
|
|
|
2013-07-24 21:53:05 +04:00
|
|
|
int MirallConfigFile::useUploadLimit() const
|
|
|
|
{
|
2013-08-22 14:26:34 +04:00
|
|
|
return getValue(useUploadLimitC, QString::null, 0).toInt();
|
2013-07-24 21:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MirallConfigFile::useDownloadLimit() const
|
|
|
|
{
|
|
|
|
return getValue(useDownloadLimitC, QString::null, false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setUseUploadLimit(int val)
|
|
|
|
{
|
|
|
|
setValue(useUploadLimitC, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setUseDownloadLimit(bool enable)
|
|
|
|
{
|
|
|
|
setValue(useDownloadLimitC, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MirallConfigFile::uploadLimit() const
|
|
|
|
{
|
|
|
|
return getValue(uploadLimitC, QString::null, 10).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
int MirallConfigFile::downloadLimit() const
|
|
|
|
{
|
|
|
|
return getValue(downloadLimitC, QString::null, 80).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setUploadLimit(int kbytes)
|
|
|
|
{
|
|
|
|
setValue(uploadLimitC, kbytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setDownloadLimit(int kbytes)
|
|
|
|
{
|
|
|
|
setValue(downloadLimitC, kbytes);
|
|
|
|
}
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
bool MirallConfigFile::monoIcons() const
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
return settings.value(QLatin1String(monoIconsC), false).toBool();
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MirallConfigFile::setMonoIcons(bool useMonoIcons)
|
|
|
|
{
|
2013-07-29 16:28:19 +04:00
|
|
|
QSettings settings(configFile(), QSettings::IniFormat);
|
|
|
|
settings.setIniCodec("UTF-8");
|
2013-07-19 18:27:54 +04:00
|
|
|
settings.setValue(QLatin1String(monoIconsC), useMonoIcons);
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 16:28:19 +04:00
|
|
|
AbstractCredentials* MirallConfigFile::getCredentials() const
|
|
|
|
{
|
2013-07-29 16:46:53 +04:00
|
|
|
return credentialsPerConfig[_customHandle].data();
|
2013-07-29 16:28:19 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 12:17:52 +04:00
|
|
|
}
|