Exemplo n.º 1
0
MirallConfigFile::MirallConfigFile( const QString& appendix, bool useOldConfig )
{

    if (useOldConfig && !appendix.isEmpty()) {
        QString oldConfigFile = configFile();
        _customHandle = appendix;
        QString newConfigFile = configFile();
        QFile::copy(oldConfigFile, newConfigFile);
    } else {
        _customHandle = appendix;
    }

    QSettings::setDefaultFormat(QSettings::IniFormat);
    if (! credentialsPerConfig.contains(_customHandle)) {
        QString con( _customHandle );
        if( _customHandle.isEmpty() ) con = defaultConnection();

        const QString config = configFile();
        qDebug() << "Loading config: " << config;


        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)));
    }
}
Exemplo n.º 2
0
QString MirallConfigFile::ownCloudPasswd( const QString& connection ) const
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings( configFile(), QSettings::IniFormat );
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );

    QByteArray pwdba = settings.value(QLatin1String("passwd")).toByteArray();
    if( !pwdba.isEmpty() ) {
        return QString::fromUtf8( QByteArray::fromBase64(pwdba) );
    }

    // check the password entry, cleartext from before
    // read it and convert to base64, delete the cleartext entry.
    QString p = settings.value(QLatin1String("password")).toString();

    if( ! p.isEmpty() ) {
        // its there, save base64-encoded and delete.
        pwdba = p.toUtf8();
        settings.setValue( QLatin1String("passwd"), QVariant(pwdba.toBase64()) );
        settings.remove( QLatin1String("password") );
        settings.sync();
    }
    return p;
}
Exemplo n.º 3
0
/*
 * returns the configured owncloud url if its already configured, otherwise an empty
 * string.
 * The returned url always has a trailing hash.
 * If webdav is true, the webdav-server url is returned.
 */
QString MirallConfigFile::ownCloudUrl( const QString& connection, bool webdav ) const
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings( configFile(), QSettings::IniFormat );
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );

    // 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! ########################";
    }

    QString url = settings.value( QLatin1String("url") ).toString();
    if( ! url.isEmpty() ) {
        if( ! url.endsWith(QLatin1Char('/'))) url.append(QLatin1String("/"));
        if( webdav ) url.append( QLatin1String("remote.php/webdav/") );
    }

    qDebug() << "Returning configured owncloud url: " << url;

  return url;
}
Exemplo n.º 4
0
QVariant ConfigFile::retrieveData(const QString& group, const QString& key) const
{
    const QString con(group.isEmpty() ? defaultConnection() : group);
    QSettings settings(configFile(), QSettings::IniFormat);

    settings.beginGroup(con);
    return settings.value(key);
}
Exemplo n.º 5
0
bool ConfigFile::dataExists(const QString& group, const QString& key) const
{
    const QString con(group.isEmpty() ? defaultConnection() : group);
    QSettings settings(configFile(), QSettings::IniFormat);

    settings.beginGroup(con);
    return settings.contains(key);
}
Exemplo n.º 6
0
void ConfigFile::removeData(const QString& group, const QString& key)
{
    const QString con(group.isEmpty() ? defaultConnection() : group);
    QSettings settings(configFile(), QSettings::IniFormat);

    settings.beginGroup(con);
    settings.remove(key);
}
Exemplo n.º 7
0
void ConfigFile::storeData(const QString& group, const QString& key, const QVariant& value)
{
    const QString con(group.isEmpty() ? defaultConnection() : group);
    QSettings settings(configFile(), QSettings::IniFormat);

    settings.beginGroup(con);
    settings.setValue(key, value);
    settings.sync();
}
Exemplo n.º 8
0
bool MirallConfigFile::connectionExists( const QString& conn )
{
    QString con = conn;
    if( conn.isEmpty() ) con = defaultConnection();

    QSettings settings( configFile(), QSettings::IniFormat);
    settings.setIniCodec( "UTF-8" );

    return settings.contains( QString::fromLatin1("%1/url").arg( conn ) );
}
Exemplo n.º 9
0
bool MirallConfigFile::connectionExists( const QString& conn )
{
    QString con = conn;
    if( conn.isEmpty() ) con = defaultConnection();

    QSettings settings(configFile(), QSettings::IniFormat);
    settings.setIniCodec("UTF-8");

    settings.beginGroup(conn);
    return settings.contains( QLatin1String(urlC) );
}
Exemplo n.º 10
0
bool ConfigFile::skipUpdateCheck( const QString& connection ) const
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QVariant fallback = getValue(QLatin1String(skipUpdateCheckC), con, false);
    fallback = getValue(QLatin1String(skipUpdateCheckC), QString(), fallback);

    QVariant value = getPolicySetting(QLatin1String(skipUpdateCheckC), fallback);
    return value.toBool();
}
Exemplo n.º 11
0
bool MirallConfigFile::passwordStorageAllowed( const QString& connection )
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings( configFile(), QSettings::IniFormat );
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );

    bool skipPwd = settings.value( QLatin1String("nostoredpassword"), false ).toBool();
    return !skipPwd;
}
Exemplo n.º 12
0
void ConfigFile::setSkipUpdateCheck( bool skip, const QString& connection )
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings(configFile(), QSettings::IniFormat);
    settings.beginGroup( con );

    settings.setValue( QLatin1String(skipUpdateCheckC), QVariant(skip) );
    settings.sync();

}
Exemplo n.º 13
0
bool MirallConfigFile::ownCloudSkipUpdateCheck( const QString& connection ) const
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings(configFile(), QSettings::IniFormat);
    settings.beginGroup( con );

    bool skipIt = settings.value( QLatin1String(skipUpdateCheckC), false ).toBool();

    return skipIt;
}
Exemplo n.º 14
0
MirallConfigFile::MirallConfigFile()
{
    QSettings::setDefaultFormat(QSettings::IniFormat);

    const QString config = configFile();


    QSettings settings(config, QSettings::IniFormat);
    settings.beginGroup( defaultConnection() );

    qDebug() << "Loading config: " << config << " (URL is " << settings.value("url").toString() << ")";
}
Exemplo n.º 15
0
void MirallConfigFile::setOwnCloudSkipUpdateCheck( bool skip, const QString& connection )
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings( configFile(), QSettings::IniFormat );
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );

    settings.setValue( QLatin1String("skipUpdateCheck"), QVariant(skip) );
    settings.sync();

}
Exemplo n.º 16
0
ConfigFile::ConfigFile()
{
    // QDesktopServices uses the application name to create a config path
    qApp->setApplicationName(Theme::instance()->appNameGUI());

    QSettings::setDefaultFormat(QSettings::IniFormat);

    const QString config = configFile();


    QSettings settings(config, QSettings::IniFormat);
    settings.beginGroup(defaultConnection());
}
Exemplo n.º 17
0
// This method is called after the password was successfully stored into the
// QKeyChain in CredentialStore.
void MirallConfigFile::clearPasswordFromConfig( const QString& connection )
{
    const QString file = configFile();
    QString con( defaultConnection() );
    if( !connection.isEmpty() )
        con = connection;

    QSettings settings( file, QSettings::IniFormat);
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );
    settings.remove(QLatin1String("passwd"));
    settings.remove(QLatin1String("password"));
    settings.sync();
}
Exemplo n.º 18
0
void MirallConfigFile::removeConnection( const QString& connection )
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    qDebug() << "    removing the config file for connection " << con;

    // Currently its just removing the entire config file
    QSettings settings( configFile(), QSettings::IniFormat);
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );
    settings.remove(QString::null);  // removes all content from the group
    settings.sync();
}
Exemplo n.º 19
0
QString MirallConfigFile::ownCloudUser( const QString& connection ) const
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings( configFile(), QSettings::IniFormat );
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );

    QString user = settings.value( QLatin1String("user") ).toString();
    // qDebug() << "Returning configured owncloud user: " << user;

    return user;
}
Exemplo n.º 20
0
void ConfigFile::setRemotePollInterval(int interval, const QString &connection )
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    if( interval < 5000 ) {
        qDebug() << "Remote Poll interval of " << interval << " is below fife seconds.";
        return;
    }
    QSettings settings(configFile(), QSettings::IniFormat);
    settings.beginGroup( con );
    settings.setValue(QLatin1String(remotePollIntervalC), interval );
    settings.sync();
}
Exemplo n.º 21
0
int MirallConfigFile::pollTimerExceedFactor( const QString& connection ) const
{
  QString con( connection );
  if( connection.isEmpty() ) con = defaultConnection();

  QSettings settings( configFile(), QSettings::IniFormat );
  settings.setIniCodec( "UTF-8" );
  settings.beginGroup( con );

  int pte = settings.value( QLatin1String("pollTimerExeedFactor"), DEFAULT_POLL_TIMER_EXEED).toInt();

  if( pte < 1 ) pte = DEFAULT_POLL_TIMER_EXEED;

  return pte;
}
Exemplo n.º 22
0
void MirallConfigFile::removeConnection( const QString& connection )
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    qDebug() << "    removing the config file for connection " << con;

    // Currently its just removing the entire config file
    // TODO: Eh? Shouldn't it try to load a file under configFile() and set it to INI?
    QSettings settings;
    settings.setIniCodec( "UTF-8" );
    settings.beginGroup( con );
    settings.remove(QString::null);  // removes all content from the group
    settings.sync();
}
Exemplo n.º 23
0
ConfigFile::ConfigFile()
{
    // QDesktopServices uses the application name to create a config path
    qApp->setApplicationName( Theme::instance()->appNameGUI() );

    QSettings::setDefaultFormat(QSettings::IniFormat);

    const QString config = configFile();


    QSettings settings(config, QSettings::IniFormat);
    settings.beginGroup( defaultConnection() );

    // qDebug() << Q_FUNC_INFO << "Loading config: " << config << " (URL is " << settings.value("url").toString() << ")";
}
Exemplo n.º 24
0
int ConfigFile::remotePollInterval( const QString& connection ) const
{
  QString con( connection );
  if( connection.isEmpty() ) con = defaultConnection();

  QSettings settings(configFile(), QSettings::IniFormat);
  settings.beginGroup( con );

  int remoteInterval = settings.value( QLatin1String(remotePollIntervalC), DEFAULT_REMOTE_POLL_INTERVAL ).toInt();
  if( remoteInterval < 5000) {
    qDebug() << "Remote Interval is less than 5 seconds, reverting to" << DEFAULT_REMOTE_POLL_INTERVAL;
    remoteInterval = DEFAULT_REMOTE_POLL_INTERVAL;
  }
  return remoteInterval;
}
Exemplo n.º 25
0
void ConfigFile::setRemotePollInterval(chrono::milliseconds interval, const QString &connection)
{
    QString con(connection);
    if (connection.isEmpty())
        con = defaultConnection();

    if (interval < chrono::seconds(5)) {
        qCWarning(lcConfigFile) << "Remote Poll interval of " << interval.count() << " is below five seconds.";
        return;
    }
    QSettings settings(configFile(), QSettings::IniFormat);
    settings.beginGroup(con);
    settings.setValue(QLatin1String(remotePollIntervalC), qlonglong(interval.count()));
    settings.sync();
}
Exemplo n.º 26
0
quint64 ConfigFile::notificationRefreshInterval(const QString &connection) const
{
    QString con(connection);
    if (connection.isEmpty())
        con = defaultConnection();
    QSettings settings(configFile(), QSettings::IniFormat);
    settings.beginGroup(con);

    quint64 defaultInterval = 5 * 60 * 1000ull; // 5 minutes
    quint64 interval = settings.value(QLatin1String(notificationRefreshIntervalC), defaultInterval).toULongLong();
    if (interval < 60 * 1000ull) {
        qCWarning(lcConfigFile) << "Notification refresh interval smaller than one minute, setting to one minute";
        interval = 60 * 1000ull;
    }
    return interval;
}
Exemplo n.º 27
0
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.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;
}
Exemplo n.º 28
0
chrono::milliseconds ConfigFile::notificationRefreshInterval(const QString &connection) const
{
    QString con(connection);
    if (connection.isEmpty())
        con = defaultConnection();
    QSettings settings(configFile(), QSettings::IniFormat);
    settings.beginGroup(con);

    auto defaultInterval = chrono::minutes(5);
    auto interval = millisecondsValue(settings, notificationRefreshIntervalC, defaultInterval);
    if (interval < chrono::minutes(1)) {
        qCWarning(lcConfigFile) << "Notification refresh interval smaller than one minute, setting to one minute";
        interval = chrono::minutes(1);
    }
    return interval;
}
Exemplo n.º 29
0
/*
 * returns the configured owncloud url if its already configured, otherwise an empty
 * string.
 * The returned url always has a trailing hash.
 */
QString MirallConfigFile::ownCloudUrl( const QString& connection) const
{
    QString con( connection );
    if( connection.isEmpty() ) con = defaultConnection();

    QSettings settings(configFile(), QSettings::IniFormat);
    settings.setIniCodec("UTF-8");
    settings.beginGroup( con );

    QString url = settings.value( QLatin1String(urlC) ).toString();
    if( ! url.isEmpty() ) {
        if( ! url.endsWith(QLatin1Char('/'))) url.append(QLatin1String("/"));
    }

    return url;
}
Exemplo n.º 30
0
bool MirallConfigFile::writePassword( const QString& passwd, const QString& connection )
{
    const QString file = configFile();
    QString pwd( passwd );
    QString con( defaultConnection() );
    if( !connection.isEmpty() )
        con = connection;

    QSettings settings( file, QSettings::IniFormat);
    settings.setIniCodec( "UTF-8" );

    // store password into settings file.
    settings.beginGroup( con );
    QByteArray pwdba = pwd.toUtf8();
    settings.setValue( QLatin1String("passwd"), QVariant(pwdba.toBase64()) );
    settings.sync();
}