Exemplo n.º 1
0
bool AccountManager::restoreFromLegacySettings()
{
    // try to open the correctly themed settings
    auto settings = Account::settingsWithGroup(Theme::instance()->appName());

    bool migratedCreds = false;

    // if the settings file could not be opened, the childKeys list is empty
    // then try to load settings from a very old place
    if( settings->childKeys().isEmpty() ) {
        // Now try to open the original ownCloud settings to see if they exist.
        QString oCCfgFile = QDir::fromNativeSeparators( settings->fileName() );
        // replace the last two segments with ownCloud/owncloud.cfg
        oCCfgFile = oCCfgFile.left( oCCfgFile.lastIndexOf('/'));
        oCCfgFile = oCCfgFile.left( oCCfgFile.lastIndexOf('/'));
        oCCfgFile += QLatin1String("/ownCloud/owncloud.cfg");

        qDebug() << "Migrate: checking old config " << oCCfgFile;

        QFileInfo fi( oCCfgFile );
        if( fi.isReadable() ) {
            QSettings *oCSettings = new QSettings(oCCfgFile, QSettings::IniFormat);
            oCSettings->beginGroup(QLatin1String("ownCloud"));

            // Check the theme url to see if it is the same url that the oC config was for
            QString overrideUrl = Theme::instance()->overrideServerUrl();
            if( !overrideUrl.isEmpty() ) {
                if (overrideUrl.endsWith('/')) { overrideUrl.chop(1); }
                QString oCUrl = oCSettings->value(QLatin1String(urlC)).toString();
                if (oCUrl.endsWith('/')) { oCUrl.chop(1); }

                // in case the urls are equal reset the settings object to read from
                // the ownCloud settings object
                qDebug() << "Migrate oC config if " << oCUrl << " == " << overrideUrl << ":"
                         << (oCUrl == overrideUrl ? "Yes" : "No");
                if( oCUrl == overrideUrl ) {
                    migratedCreds = true;
                    settings.reset( oCSettings );
                } else {
                    delete oCSettings;
                }
            }
        }
    }

    // Try to load the single account.
    if (!settings->childKeys().isEmpty()) {
        if (auto acc = load(*settings)) {
            if (migratedCreds) {
                acc->setMigrated(true);
            }
            addAccount(acc);
            return true;
        }
    }
    return false;
}
Exemplo n.º 2
0
void CWizSettings::GetKeys(const QString& strSection, CWizStdStringArray& arrayAction)
{
    beginGroup(strSection);
    QStringList sl = childKeys();
    endGroup();
    arrayAction.assign(sl.begin(), sl.end());
}
Exemplo n.º 3
0
QVariantHash ImageUploader::loadSettings(const QString &uploaderType)
{
    auto globalSettings = ScreenshotManager::instance()->settings();
    globalSettings->beginGroup("upload/" + uploaderType);
    auto keys = globalSettings->childKeys();

    QVariantHash settings;

    for (auto key : qAsConst(keys)) {
        settings[key] = globalSettings->value(key);
    }

    globalSettings->endGroup();
    return settings;
}
Exemplo n.º 4
0
// Author & Date: Ehsan Azar       15 June 2010
// Purpose: Get current node value
// Inputs:
//   val - the default value
QVariant XmlFile::value(const QVariant & val)
{
    QVariant res = val;

    if (!m_nodes.isEmpty())
    {
        // Get the current node
        QDomElement node = m_nodes.last();
        if (!node.isNull())
        {
            // Array Type is how we distinguish lists
            if (node.attribute("Type").compare("Array", Qt::CaseInsensitive) == 0)
            {
                QVariantList varlist;
                QStringList keys = childKeys();
                for (int i = 0; i < keys.count(); ++i)
                {
                    QString key = keys[i];
                    if (i > 0 && key == keys[i - 1])
                        key = QString(key + "<%1>").arg(i);
                    // Recursively return the list
                    beginGroup(key);
                    QVariant nodevalue = value(QString());
                    endGroup();
                    // Make sure value is meaningful
                    if (nodevalue.isValid())
                        varlist += nodevalue; // add new value
                }
                if (!keys.isEmpty())
                    res = varlist;
            } else {
                QDomNode child = node.firstChild();
                if (!child.isNull())
                {
                    QDomText domText = child.toText();
                    if (!domText.isNull())
                        res = domText.data();
                    else
                        return toString();
                }
            }
        }
    }
    return res;
}
Exemplo n.º 5
0
// Author & Date: Ehsan Azar       6 April 2012
// Purpose: Get the first child element
// Outputs:
//   Returns the name of the first child element
QString XmlFile::firstChildKey() const
{
    QStringList list = childKeys(1);
    return list.last();
}
Exemplo n.º 6
0
void
dvbcut_settings::load_settings() {
  int version = readNumEntry("/version", 0);
  if (version >= 1) {
    // config format version 1 or later
    beginGroup("/wheel");
      wheel_increments[WHEEL_INCR_NORMAL] = readNumEntry("/incr_normal", 25*60);
      wheel_increments[WHEEL_INCR_SHIFT] = readNumEntry("/incr_shift", 25);
      wheel_increments[WHEEL_INCR_CTRL] = readNumEntry("/incr_ctrl", 1);
      wheel_increments[WHEEL_INCR_ALT] = readNumEntry("/incr_alt", 15*25*60);
      wheel_threshold = readNumEntry("/threshold", 24);
      // Note: delta is a multiple of 120 (see Qt documentation)
      wheel_delta = readNumEntry("/delta", 120);
      if (wheel_delta == 0)
	    wheel_delta = 1;	// avoid devide by zero
    endGroup();	// wheel
    beginGroup("/slider");
      jog_maximum = readNumEntry("/jog_maximum", 180000);
      jog_threshold = readNumEntry("/jog_threshold", 50);
      // to increase the "zero frames"-region of the jog-slider
      jog_offset = readDoubleEntry("/jog_offset", 0.4);
      // sub-intervals of jog_maximum
      jog_interval = readNumEntry("/jog_interval", 1);
      if (jog_interval < 0)
	    jog_interval = 0;
      lin_interval = readNumEntry("/lin_interval", 3600);
      if (lin_interval < 0)
	    lin_interval = 0;
    endGroup();	// slider
    beginGroup("/lastdir");
      lastdir = readEntry("/name", "");
      lastdir_update = readBoolEntry("/update", true);
    endGroup(); // lastdir
  }
  else {
    // old (unnumbered) config format
    wheel_increments[WHEEL_INCR_NORMAL] = readNumEntry("/wheel_incr_normal", 25*60);
    wheel_increments[WHEEL_INCR_SHIFT] = readNumEntry("/wheel_incr_shift", 25);
    wheel_increments[WHEEL_INCR_CTRL] = readNumEntry("/wheel_incr_ctrl", 1);
    wheel_increments[WHEEL_INCR_ALT] = readNumEntry("/wheel_incr_alt", 15*25*60);
    wheel_threshold = readNumEntry("/wheel_threshold", 24);
    // Note: delta is a multiple of 120 (see Qt documentation)
    wheel_delta = readNumEntry("/wheel_delta", 120);
    if (wheel_delta == 0)
      wheel_delta = 1;	// avoid devide by zero
    jog_maximum = readNumEntry("/jog_maximum", 180000);
    jog_threshold = readNumEntry("/jog_threshold", 50);
    // to increase the "zero frames"-region of the jog-slider
    jog_offset = readDoubleEntry("/jog_offset", 0.4);
    // sub-intervals of jog_maximum
    jog_interval = readNumEntry("/jog_interval", 1);
    if (jog_interval < 0)
      jog_interval = 0;
    lin_interval = readNumEntry("/lin_interval", 3600);
    if (lin_interval < 0)
      lin_interval = 0;
    lastdir = readEntry("/lastdir", "");
    lastdir_update = true;
    // remove old-style entries
    remove("/wheel_incr_normal");
    remove("/wheel_incr_shift");
    remove("/wheel_incr_ctrl");
    remove("/wheel_incr_alt");
    remove("/wheel_threshold");
    remove("/wheel_delta");
    remove("/jog_maximum");
    remove("/jog_threshold");
    remove("/jog_offset");
    remove("/jog_interval");
    remove("/lin_interval");
    remove("/lastdir");
    remove("/idxfilter");
    remove("/prjfilter");
    remove("/loadfilter");
  }
  if (version >= 2) {
    /* float view scale factor */
    beginGroup("/viewscalefactor");
      viewscalefactor = readNumEntry("/current", 1);
      viewscalefactor_custom = readDoubleEntry("/custom", 3.0);
    endGroup(); // viewscalefactor
  } 
  else {
    viewscalefactor = readNumEntry("/viewscalefactor", 1);
    viewscalefactor_custom = 3.0;
    remove("/viewscalefactor");
  }
  export_format = readNumEntry("/export_format", 0);
  beginGroup("/recentfiles");
    recentfiles_max = readNumEntry("/max", 5);
    recentfiles.clear();
    std::list<std::string> filenames;
    QStringList keys = childKeys();
    for (unsigned int i = 0; i < recentfiles_max; ++i) {
      QString key = "/" + QString::number(i);
      if (version < 1 && keys.size()>1) {
		// OLD format (2 keys per input file, NO subkeys!)
        QString filename = readEntry(key);
        if (filename.isEmpty())
		  continue;
        filenames.clear();
        filenames.push_back(filename.toStdString());
        QString idxfilename = readEntry(key + "-idx", "");
        recentfiles.push_back(
        std::pair<std::list<std::string>,std::string>(filenames, idxfilename.toStdString()));
      }
      else {
	// NEW format with subkeys and multiple files!
	beginGroup(key);
	  QString filename = readEntry("/0");
	  if (!filename.isEmpty()) {
		// multiple input files?  
		int j=0;
		filenames.clear();
		while(!filename.isEmpty()) {
		  filenames.push_back(filename.toStdString());
		  filename = readEntry("/" + QString::number(++j), "");
		}  
		QString idxfilename = readEntry("/idx", "");
		recentfiles.push_back(
		  std::pair<std::list<std::string>,std::string>(filenames, idxfilename.toStdString()));
	  }
	endGroup();	// key
      }
    }
  endGroup();	// recentfiles
  start_bof = readBoolEntry("/start_bof", true);
  stop_eof = readBoolEntry("/stop_eof", true);
  beginGroup("/snapshots");
    snapshot_type = readEntry("/type", "PNG");
    snapshot_quality = readNumEntry("/quality", -1);
    snapshot_prefix = readEntry("/prefix", "");
    snapshot_delimiter = readEntry("/delimiter", "_");
    snapshot_first = readNumEntry("/first", 1);
    snapshot_width = readNumEntry("/width", 3);
    snapshot_extension = readEntry("/extension", "png");
    snapshot_range = readNumEntry("/range", 0);
    snapshot_samples = readNumEntry("/samples", 1);
  endGroup();	// snapshots
  beginGroup("/pipe");
    pipe_command.clear();
    pipe_post.clear();
    pipe_label.clear();
    pipe_format.clear();
    beginGroup("/0");
      QString command = readEntry("/command", DVBCUT_DEFAULT_PIPE_COMMAND);
      QString post = readEntry("/post", DVBCUT_DEFAULT_PIPE_POST);
      QString label = readEntry("/label", DVBCUT_DEFAULT_PIPE_LABEL);
      int format = readNumEntry("/format", DVBCUT_DEFAULT_PIPE_FORMAT);
    endGroup();	// 0
    unsigned int i = 0;
    while(!command.isEmpty() && !label.isEmpty()) {
      if(format<0 || format>3) format = 0;
      pipe_command.push_back(command);
      pipe_post.push_back(post);
      pipe_label.push_back(label);
      pipe_format.push_back(format);
      QString key = "/" + QString::number(++i);
      beginGroup(key);
	command = readEntry("/command","");
	post = readEntry("/post","");
	label = readEntry("/label","");
	format = readNumEntry("/format", 0);
      endGroup();	// key
    }
  endGroup();	// pipe
  beginGroup("/chapters");
    // length (>0) or number (<0) of chapter(s)
    chapter_interval = readNumEntry("/interval", 600*25);
    // detection of scene changes is rather time comsuming... 
    //chapter_tolerance = readNumEntry("/tolerance", 10*25);
    //... better switch it off per default!
    chapter_tolerance = readNumEntry("/tolerance", 0);
    // average color distance needed for a scene change
    chapter_threshold = readDoubleEntry("/threshold", 50.);
    // minimal length of a chapter
    chapter_minimum = readNumEntry("/minimum", 200*25);
  endGroup();	// auto chapters
}
Exemplo n.º 7
0
void
dvbcut_settings::save_settings() {
  setValue("/version", 2);	// latest config version
  beginGroup("/wheel");
    setValue("/incr_normal", wheel_increments[WHEEL_INCR_NORMAL]);
    setValue("/incr_shift", wheel_increments[WHEEL_INCR_SHIFT]);
    setValue("/incr_ctrl", wheel_increments[WHEEL_INCR_CTRL]);
    setValue("/incr_alt", wheel_increments[WHEEL_INCR_ALT]);
    setValue("/threshold", wheel_threshold);
    setValue("/delta", wheel_delta);
  endGroup();	// wheel
  beginGroup("/slider");
    setValue("/jog_maximum", jog_maximum);
    setValue("/jog_threshold", jog_threshold);
    setValue("/jog_offset", jog_offset);
    setValue("/jog_interval", jog_interval);
    setValue("/lin_interval", lin_interval);
  endGroup();	// slider
  beginGroup("/lastdir");
    setValue("/name", lastdir);
    setValue("/update", lastdir_update);
  endGroup();	// lastdir
  beginGroup("/viewscalefactor");
    setValue("/current", viewscalefactor);
    setValue("/custom", viewscalefactor_custom);
  endGroup();	// viewscalefactor
  setValue("/export_format", export_format);
  beginGroup("/recentfiles");
    // first remove any OLD recentfiles entries to clean the settings file (<revision 108)!!!
    QStringList keys = childKeys();
    for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) 
      remove("/" + *it);
    // then remove ALL new recentfiles entries!!!
    // (otherwise it would be a mess with erased&inserted muliple file entries of different size)
    QStringList subkeys = childGroups();
    for ( QStringList::Iterator its = subkeys.begin(); its != subkeys.end(); ++its ) {
      beginGroup("/" + *its);
      QStringList keys = childKeys();
      endGroup();
      for ( QStringList::Iterator itk = keys.begin(); itk != keys.end(); ++itk ) 
        remove("/"  + *its + "/" + *itk);
    }    
    setValue("/max", int(recentfiles_max));
    // and NOW write the updated list from scratch!!!
    for (unsigned int i = 0; i < recentfiles.size(); ++i) {
      QString key = "/" + QString::number(i);
      beginGroup(key);
        int j=0;
        for(std::list<std::string>::iterator it=settings().recentfiles[i].first.begin();
                                             it!=settings().recentfiles[i].first.end(); it++, j++) 
          setValue("/" + QString::number(j), it->c_str());
        setValue("/idx", recentfiles[i].second.c_str());
      endGroup();	// key
    }
  endGroup();	// recentfiles
  setValue("/start_bof", start_bof);
  setValue("/stop_eof", stop_eof);
  beginGroup("/snapshots");
    setValue("/type", snapshot_type);
    setValue("/quality", snapshot_quality);
    setValue("/prefix", snapshot_prefix);
    setValue("/delimiter", snapshot_delimiter);
    setValue("/first", snapshot_first);
    setValue("/width", snapshot_width);
    setValue("/extension", snapshot_extension);
    setValue("/range", snapshot_range);
    setValue("/samples", snapshot_samples);
  endGroup();	// snapshots
  beginGroup("/pipe");
    for (unsigned int i = 0; i < pipe_command.size(); ++i) {
      QString key = "/" + QString::number(i);
      beginGroup(key);
	setValue("/command", pipe_command[i]);
	setValue("/post", pipe_post[i]);
	setValue("/label", pipe_label[i]);
	setValue("/format", pipe_format[i]);
      endGroup();	// key
    }
  endGroup();	// pipe
  beginGroup("/chapters");
    setValue("/interval", chapter_interval);
    setValue("/tolerance", chapter_tolerance);
    setValue("/threshold", chapter_threshold);
    setValue("/minimum", chapter_minimum);
  endGroup();	// auto chapters
}