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
|
|
|
|
|
|
|
#include "mirall/mirallconfigfile.h"
|
|
|
|
#include "mirall/owncloudtheme.h"
|
|
|
|
#include "mirall/miralltheme.h"
|
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QtGui>
|
|
|
|
|
2012-04-01 17:09:04 +04:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#endif
|
|
|
|
|
2012-05-16 17:13:51 +04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
#endif
|
|
|
|
|
2012-05-26 16:37:21 +04:00
|
|
|
#define DEFAULT_REMOTE_POLL_INTERVAL 30000 // default remote poll time in milliseconds
|
|
|
|
#define DEFAULT_LOCAL_POLL_INTERVAL 10000 // default local poll time in milliseconds
|
|
|
|
#define DEFAULT_POLL_TIMER_EXEED 10
|
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
namespace Mirall {
|
|
|
|
|
2012-06-12 14:27:02 +04:00
|
|
|
QString MirallConfigFile::_passwd;
|
|
|
|
QString MirallConfigFile::_oCVersion;
|
2012-04-12 16:06:59 +04:00
|
|
|
bool MirallConfigFile::_askedUser = false;
|
|
|
|
|
2012-06-12 14:27:02 +04:00
|
|
|
MirallConfigFile::MirallConfigFile( const QString& appendix )
|
|
|
|
:_customHandle(appendix)
|
2012-02-17 14:11:18 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-28 13:26:51 +04:00
|
|
|
QString MirallConfigFile::configPath() const
|
|
|
|
{
|
|
|
|
QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
|
|
|
if( !dir.endsWith('/') ) dir.append('/');
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2012-03-28 14:23:34 +04:00
|
|
|
QString MirallConfigFile::excludeFile() const
|
|
|
|
{
|
2012-04-01 17:09:04 +04:00
|
|
|
const QString exclFile("exclude.lst");
|
2012-03-28 14:23:34 +04:00
|
|
|
QString dir = configPath();
|
2012-04-01 17:09:04 +04:00
|
|
|
dir += exclFile;
|
|
|
|
|
2012-03-28 14:23:34 +04:00
|
|
|
QFileInfo fi( dir );
|
|
|
|
if( fi.isReadable() ) {
|
|
|
|
return dir;
|
|
|
|
}
|
2012-04-01 17:09:04 +04:00
|
|
|
// Check alternative places...
|
2012-05-16 16:55:19 +04:00
|
|
|
#ifdef Q_OS_WIN32
|
2012-04-01 17:09:04 +04:00
|
|
|
/* For win32, try to copy the conf file from the directory from where the app was started. */
|
|
|
|
char buf[MAX_PATH+1];
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
/* Get the path from where the application was started */
|
|
|
|
len = GetModuleFileName(NULL, buf, MAX_PATH);
|
|
|
|
QString exePath = QString::fromLocal8Bit(buf);
|
|
|
|
exePath.remove("owncloud.exe");
|
|
|
|
fi.setFile(exePath, exclFile );
|
2012-05-16 16:55:19 +04:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_LINUX
|
2012-04-01 17:09:04 +04:00
|
|
|
fi.setFile( QString("/etc"), exclFile );
|
2012-05-16 16:55:19 +04:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_MAC
|
2012-05-16 17:13:51 +04:00
|
|
|
char buf[1024];
|
2012-05-16 16:55:19 +04:00
|
|
|
uint32_t size = sizeof(buf);
|
|
|
|
if (_NSGetExecutablePath(buf, &size) == 0) {
|
|
|
|
qDebug() << " Executable path: <" << buf;
|
|
|
|
QString execFile = QString::fromLocal8Bit(buf);
|
|
|
|
QFileInfo fi2(execFile);
|
|
|
|
fi.setFile( fi2.canonicalPath(), "../Resources/exclude.lst");
|
|
|
|
}
|
2012-04-01 17:09:04 +04:00
|
|
|
#endif
|
|
|
|
if( fi.isReadable() ) {
|
|
|
|
qDebug() << " ==> returning exclude file path: " << fi.absoluteFilePath();
|
|
|
|
return fi.absoluteFilePath();
|
|
|
|
}
|
|
|
|
qDebug() << "EMPTY exclude file path!";
|
2012-03-28 14:23:34 +04:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MirallConfigFile::configFile() const
|
2012-02-17 14:11:18 +04:00
|
|
|
{
|
|
|
|
#ifdef OWNCLOUD_CLIENT
|
|
|
|
ownCloudTheme theme;
|
|
|
|
#else
|
|
|
|
mirallTheme theme;
|
|
|
|
#endif
|
2012-02-17 15:16:48 +04:00
|
|
|
if( qApp->applicationName().isEmpty() ) {
|
|
|
|
qApp->setApplicationName( theme.appName() );
|
|
|
|
}
|
2012-06-12 14:27:02 +04:00
|
|
|
QString dir = configPath() + theme.configFileName();
|
|
|
|
if( !_customHandle.isEmpty() ) {
|
|
|
|
dir.append( QChar('_'));
|
|
|
|
dir.append( _customHandle );
|
|
|
|
qDebug() << " OO Custom config file in use: " << dir;
|
|
|
|
}
|
2012-02-17 14:11:18 +04:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return QString::fromLocal8Bit("ownCloud");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-03-28 14:23:34 +04:00
|
|
|
QSettings settings( configFile(), QSettings::IniFormat);
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-02-17 18:54:39 +04:00
|
|
|
|
|
|
|
return settings.contains( QString("%1/url").arg( conn ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
const QString& user,
|
|
|
|
const QString& passwd,
|
|
|
|
bool skipPwd )
|
2012-02-17 14:11:18 +04:00
|
|
|
{
|
2012-03-28 14:23:34 +04:00
|
|
|
const QString file = configFile();
|
2012-04-12 23:30:47 +04:00
|
|
|
qDebug() << "*** writing mirall config to " << file << " Skippwd: " << skipPwd;
|
2012-04-12 16:06:59 +04:00
|
|
|
QString pwd( passwd );
|
2012-03-13 20:52:23 +04:00
|
|
|
|
|
|
|
QSettings settings( file, QSettings::IniFormat);
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-02-17 14:11:18 +04:00
|
|
|
QString cloudsUrl( url );
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
if( !cloudsUrl.startsWith( QLatin1String("http")) )
|
|
|
|
cloudsUrl.prepend(QLatin1String("http://"));
|
2012-02-17 14:11:18 +04:00
|
|
|
|
|
|
|
settings.beginGroup( connection );
|
|
|
|
settings.setValue("url", cloudsUrl );
|
|
|
|
settings.setValue("user", user );
|
2012-04-12 16:06:59 +04:00
|
|
|
if( skipPwd ) {
|
2012-05-21 18:48:49 +04:00
|
|
|
pwd.clear();
|
2012-04-12 16:06:59 +04:00
|
|
|
}
|
2012-04-12 23:30:47 +04:00
|
|
|
|
|
|
|
QByteArray pwdba = pwd.toUtf8();
|
|
|
|
settings.setValue( "passwd", QVariant(pwdba.toBase64()) );
|
|
|
|
settings.setValue( "nostoredpassword", QVariant(skipPwd) );
|
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-02-17 14:11:18 +04:00
|
|
|
}
|
|
|
|
|
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
|
2012-03-28 14:23:34 +04:00
|
|
|
QSettings settings( configFile(), QSettings::IniFormat);
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-02-17 18:54:39 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
settings.remove(""); // removes all content from the group
|
|
|
|
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.
|
|
|
|
* If webdav is true, the webdav-server url is returned.
|
2012-02-17 14:11:18 +04:00
|
|
|
*/
|
2012-02-18 20:02:10 +04:00
|
|
|
QString MirallConfigFile::ownCloudUrl( const QString& connection, bool webdav ) 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
|
|
|
|
2012-03-28 14:23:34 +04:00
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-02-17 14:11:18 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
2012-05-14 18:22:30 +04:00
|
|
|
// For the WebDAV connect it is required to know which version the server is running
|
|
|
|
// because the url changed :-/
|
|
|
|
if( webdav && _oCVersion.isEmpty() ) {
|
|
|
|
qDebug() << "######## Config does not yet know the ownCloud server version #########";
|
|
|
|
qDebug() << "###################### THIS SHOULD NOT HAPPEN! ########################";
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
QString url = settings.value( "url" ).toString();
|
2012-03-14 12:56:47 +04:00
|
|
|
if( ! url.isEmpty() ) {
|
|
|
|
if( ! url.endsWith('/')) url.append('/');
|
|
|
|
if( webdav ) url.append( "files/webdav.php/" );
|
|
|
|
}
|
2012-02-17 14:11:18 +04:00
|
|
|
|
2012-04-30 10:56:56 +04:00
|
|
|
// qDebug() << "Returning configured owncloud url: " << url;
|
2012-02-17 14:11:18 +04:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MirallConfigFile::ownCloudUser( const QString& connection ) const
|
|
|
|
{
|
|
|
|
QString con( connection );
|
2012-02-18 20:02:10 +04:00
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
2012-02-17 14:11:18 +04:00
|
|
|
|
2012-03-28 14:23:34 +04:00
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-02-17 14:11:18 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
|
|
|
QString user = settings.value( "user" ).toString();
|
2012-04-30 10:56:56 +04:00
|
|
|
// qDebug() << "Returning configured owncloud user: " << user;
|
2012-02-17 14:11:18 +04:00
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
2012-05-26 16:37:21 +04:00
|
|
|
int MirallConfigFile::remotePollInterval( const QString& connection ) const
|
|
|
|
{
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
|
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-05-26 16:37:21 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
|
|
|
int remoteInterval = settings.value( "remotePollInterval", DEFAULT_REMOTE_POLL_INTERVAL ).toInt();
|
|
|
|
int localInterval = settings.value("localPollInterval", DEFAULT_LOCAL_POLL_INTERVAL ).toInt();
|
|
|
|
if( remoteInterval < 2*localInterval ) {
|
|
|
|
qDebug() << "WARN: remote poll Interval should at least be twice as local poll interval!";
|
|
|
|
}
|
|
|
|
if( remoteInterval < 5000 || remoteInterval < localInterval ) {
|
|
|
|
qDebug() << "Remote Interval is smaller than local Interval";
|
|
|
|
remoteInterval = DEFAULT_REMOTE_POLL_INTERVAL;
|
|
|
|
}
|
|
|
|
return remoteInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MirallConfigFile::localPollInterval( const QString& connection ) const
|
|
|
|
{
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
|
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-05-26 16:37:21 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
|
|
|
int remoteInterval = settings.value( "remotePollInterval", DEFAULT_REMOTE_POLL_INTERVAL ).toInt();
|
|
|
|
int localInterval = settings.value("localPollInterval", DEFAULT_LOCAL_POLL_INTERVAL ).toInt();
|
|
|
|
if( remoteInterval < 2*localInterval ) {
|
|
|
|
qDebug() << "WARN: remote poll Interval should at least be twice as local poll interval!";
|
|
|
|
}
|
|
|
|
if( localInterval < 2500 || remoteInterval < localInterval ) {
|
|
|
|
qDebug() << "Remote Interval is smaller than local Interval";
|
|
|
|
localInterval = DEFAULT_LOCAL_POLL_INTERVAL;
|
|
|
|
}
|
|
|
|
return localInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MirallConfigFile::pollTimerExceedFactor( const QString& connection ) const
|
|
|
|
{
|
|
|
|
QString con( connection );
|
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
|
|
|
|
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-05-26 16:37:21 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
|
|
|
int pte = settings.value( "pollTimerExeedFactor", DEFAULT_POLL_TIMER_EXEED).toInt();
|
|
|
|
|
|
|
|
if( pte < 1 ) pte = DEFAULT_POLL_TIMER_EXEED;
|
|
|
|
|
|
|
|
return pte;
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:11:18 +04:00
|
|
|
QString MirallConfigFile::ownCloudPasswd( const QString& connection ) const
|
|
|
|
{
|
|
|
|
QString con( connection );
|
2012-02-18 20:02:10 +04:00
|
|
|
if( connection.isEmpty() ) con = defaultConnection();
|
2012-02-17 14:11:18 +04:00
|
|
|
|
2012-03-28 14:23:34 +04:00
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-02-17 14:11:18 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
2012-04-12 16:06:59 +04:00
|
|
|
QString pwd;
|
|
|
|
|
|
|
|
bool boolfalse( false );
|
|
|
|
bool skipPwd = settings.value( "nostoredpassword", QVariant(boolfalse) ).toBool();
|
|
|
|
if( skipPwd ) {
|
|
|
|
if( ! _askedUser ) {
|
|
|
|
bool ok;
|
|
|
|
QString text = QInputDialog::getText(0, QObject::tr("ownCloud Password Required"),
|
|
|
|
QObject::tr("Please enter your ownCloud password:"), QLineEdit::Password,
|
|
|
|
QString(), &ok);
|
|
|
|
if( ok && !text.isEmpty() ) { // empty password is not allowed on ownCloud
|
|
|
|
_passwd = text;
|
|
|
|
_askedUser = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pwd = _passwd;
|
|
|
|
} else {
|
2012-04-12 23:30:47 +04:00
|
|
|
QByteArray pwdba = settings.value("passwd").toByteArray();
|
|
|
|
if( pwdba.isEmpty() ) {
|
|
|
|
// check the password entry, cleartext from before
|
|
|
|
// read it and convert to base64, delete the cleartext entry.
|
|
|
|
QString p = settings.value("password").toString();
|
|
|
|
|
|
|
|
if( ! p.isEmpty() ) {
|
|
|
|
// its there, save base64-encoded and delete.
|
|
|
|
|
|
|
|
pwdba = p.toUtf8();
|
|
|
|
settings.setValue( "passwd", QVariant(pwdba.toBase64()) );
|
|
|
|
settings.remove( "password" );
|
|
|
|
settings.sync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pwd = QString::fromUtf8( QByteArray::fromBase64(pwdba) );
|
2012-04-12 16:06:59 +04:00
|
|
|
}
|
2012-02-17 14:11:18 +04:00
|
|
|
|
|
|
|
return pwd;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-04-02 22:10:29 +04:00
|
|
|
settings.beginGroup( con );
|
|
|
|
|
|
|
|
bool skipIt = settings.value( "skipUpdateCheck", false ).toBool();
|
|
|
|
|
|
|
|
return skipIt;
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:11:29 +04:00
|
|
|
int MirallConfigFile::maxLogLines() const
|
|
|
|
{
|
|
|
|
QSettings settings( configFile(), QSettings::IniFormat );
|
2012-06-13 19:33:48 +04:00
|
|
|
settings.setIniCodec( "UTF-8" );
|
2012-06-05 17:11:29 +04:00
|
|
|
settings.beginGroup("Logging");
|
|
|
|
int logLines = settings.value( "maxLogLines", 20000 ).toInt();
|
|
|
|
return logLines;
|
|
|
|
}
|
2012-04-02 22:10:29 +04:00
|
|
|
|
2012-02-18 20:02:10 +04:00
|
|
|
QByteArray MirallConfigFile::basicAuthHeader() const
|
|
|
|
{
|
2012-05-21 18:48:49 +04:00
|
|
|
QString concatenated = ownCloudUser() + QChar(':') + ownCloudPasswd();
|
2012-02-18 20:02:10 +04:00
|
|
|
const QString b("Basic ");
|
|
|
|
QByteArray data = b.toLocal8Bit() + concatenated.toLocal8Bit().toBase64();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
_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-02-17 14:11:18 +04:00
|
|
|
}
|
2012-06-12 14:27:02 +04:00
|
|
|
|