void KMFolder::setUserWhoField( const QString& whoField, bool writeConfig ) { if ( mUserWhoField == whoField && !whoField.isEmpty() ) return; if ( whoField.isEmpty() ) { // default setting const KPIMIdentities::Identity & identity = kmkernel->identityManager()->identityForUoidOrDefault( mIdentity ); QString identityfcc, identitydrafts, identitytemplates; { /* KPIMIdentities::Identity::fcc(), KPIMIdentities::Identity::drafts() and KPIMIdentities::Identity::templates() using akonadi, so read values from config file directly */ const KConfig config( "emailidentities" ); const QStringList identities = config.groupList().filter( QRegExp( "^Identity #\\d+$" ) ); for ( QStringList::const_iterator group = identities.constBegin(); group != identities.constEnd(); ++group ) { const KConfigGroup configGroup( &config, *group ); if ( configGroup.readEntry( "uoid", 0U ) == identity.uoid() ) { identityfcc = configGroup.readEntry( "Fcc2", QString() ); identitydrafts = configGroup.readEntry( "Drafts2", QString() ); identitytemplates = configGroup.readEntry( "Templates2", QString() ); break; } } } if ( isSystemFolder() && folderType() != KMFolderTypeImap ) { // local system folders if ( this == kmkernel->inboxFolder() || this == kmkernel->trashFolder() ) mWhoField = "From"; if ( this == kmkernel->outboxFolder() || this == kmkernel->sentFolder() || this == kmkernel->templatesFolder() || this == kmkernel->draftsFolder() ) mWhoField = "To"; } else if ( identitydrafts == idString() || identitytemplates == idString() || identityfcc == idString() ) // drafts, templates or sent of the identity mWhoField = "To"; else mWhoField = "From"; } else if ( whoField == "From" || whoField == "To" ) // set the whoField according to the user-setting mWhoField = whoField; else { // this should not happen... kDebug() << "Illegal setting" << whoField << "for userWhoField!"; return; // don't use the value } mUserWhoField = whoField; if ( writeConfig ) { mStorage->writeConfig(); emit viewConfigChanged(); } }
/****************************************************************************** * Read the configuration file. * Create the client list and open all calendar files. */ void ADConfigData::readConfig() { kdDebug(5900) << "ADConfigData::readConfig()" << endl; ClientInfo::clear(); KConfig *config = KGlobal::config(); QStringList clients = config->groupList().grep(CLIENT_GROUP_SEARCH); for(QStringList::Iterator cl = clients.begin(); cl != clients.end(); ++cl) { // Read this client's configuration config->setGroup(*cl); QString client = *cl; client.remove(CLIENT_GROUP_SEARCH); QString title = config->readEntry(TITLE_KEY, client); // read app title (default = app name) QCString dcopObject = config->readEntry(DCOP_OBJECT_KEY).local8Bit(); bool startClient = config->readBoolEntry(START_CLIENT_KEY, false); QString calendar = config->readPathEntry(CALENDAR_KEY); // Verify the configuration bool ok = false; if(client.isEmpty() || KStandardDirs::findExe(client).isNull()) kdError(5900) << "ADConfigData::readConfig(): group '" << *cl << "' deleted (client app not found)\n"; else if(calendar.isEmpty()) kdError(5900) << "ADConfigData::readConfig(): no calendar specified for '" << client << "'\n"; else if(dcopObject.isEmpty()) kdError(5900) << "ADConfigData::readConfig(): no DCOP object specified for '" << client << "'\n"; else { ADCalendar *cal = ADCalendar::getCalendar(calendar); if(cal) kdError(5900) << "ADConfigData::readConfig(): calendar registered by multiple clients: " << calendar << endl; else ok = true; } if(!ok) { config->deleteGroup(*cl, true); continue; } // Create the client and calendar objects new ClientInfo(client.local8Bit(), title, dcopObject, calendar, startClient); kdDebug(5900) << "ADConfigData::readConfig(): client " << client << " : calendar " << calendar << endl; } // Remove obsolete CheckInterval entry (if it exists) config->setGroup("General"); config->deleteEntry("CheckInterval"); // Save any updates config->sync(); }
void MainWindow::slotLoadProfile( const QString& id ) { const QString path = Kontact::ProfileManager::self()->profileById( id ).saveLocation(); if ( path.isNull() ) return; KConfig* const cfg = Prefs::self()->config(); Prefs::self()->writeConfig(); saveMainWindowSettings( cfg ); saveSettings(); const KConfig profile( path+"/kontactrc", /*read-only=*/false, /*useglobals=*/false ); const QStringList groups = profile.groupList(); for ( QStringList::ConstIterator it = groups.begin(), end = groups.end(); it != end; ++it ) { cfg->setGroup( *it ); typedef QMap<QString, QString> StringMap; const StringMap entries = profile.entryMap( *it ); for ( StringMap::ConstIterator it2 = entries.begin(), end = entries.end(); it2 != end; ++it2 ) { if ( it2.data() == "KONTACT_PROFILE_DELETE_KEY" ) cfg->deleteEntry( it2.key() ); else cfg->writeEntry( it2.key(), it2.data() ); } } cfg->sync(); Prefs::self()->readConfig(); applyMainWindowSettings( cfg ); KIconTheme::reconfigure(); const WId wid = winId(); KIPC::sendMessage( KIPC::PaletteChanged, wid ); KIPC::sendMessage( KIPC::FontChanged, wid ); KIPC::sendMessage( KIPC::StyleChanged, wid ); KIPC::sendMessage( KIPC::SettingsChanged, wid ); for ( int i = 0; i < KIcon::LastGroup; ++i ) KIPC::sendMessage( KIPC::IconChanged, wid, i ); loadSettings(); for ( PluginList::Iterator it = mPlugins.begin(); it != mPlugins.end(); ++it ) { if ( !(*it)->isRunningStandalone() ) { kdDebug() << "Ensure loaded: " << (*it)->identifier() << endl; (*it)->part(); } (*it)->loadProfile( path ); } }
void KonfUpdate::gotAllGroups() { if (!m_oldConfig1) { logFileError() << "AllGroups without previous File specification" << endl; return; } const QStringList allGroups = m_oldConfig1->groupList(); for (QStringList::ConstIterator it = allGroups.begin(); it != allGroups.end(); ++it) { m_oldGroup = QStringList() << *it; m_newGroup = m_oldGroup; gotAllKeys(); } }
bool Settings::read_settings(KConfig &cfg_P, bool include_disabled_P, ImportType import_P) { if(actions == NULL) actions = new Action_data_group(NULL, "should never see", "should never see", NULL, Action_data_group::SYSTEM_ROOT, true); if(cfg_P.groupList().count() == 0) // empty return false; cfg_P.setGroup("Main"); // main group if(import_P == ImportNone) // reading main cfg file already_imported = cfg_P.readListEntry("AlreadyImported"); else { QString import_id = cfg_P.readEntry("ImportId"); if(!import_id.isEmpty()) { if(already_imported.contains(import_id)) { if(import_P == ImportSilent || KMessageBox::warningContinueCancel(NULL, i18n("This \"actions\" file has already been imported before. " "Are you sure you want to import it again?")) != KMessageBox::Continue) return true; // import "successful" } else already_imported.append(import_id); } else { if(import_P != ImportSilent && KMessageBox::warningContinueCancel(NULL, i18n("This \"actions\" file has no ImportId field and therefore it cannot be determined " "whether or not it has been imported already. Are you sure you want to import it?")) == KMessageBox::Cancel) return true; } } int version = cfg_P.readNumEntry("Version", -1234576); switch(version) { case 1: read_settings_v1(cfg_P); break; case 2: read_settings_v2(cfg_P, include_disabled_P); break; default: kdWarning(1217) << "Unknown cfg. file version\n"; return false; case -1234576: // no config file if(import_P) // if importing, this is an error return false; break; } if(import_P != ImportNone) return true; // don't read global settings cfg_P.setGroup("Main"); // main group daemon_disabled = cfg_P.readBoolEntry("Disabled", false); cfg_P.setGroup("Gestures"); gestures_disabled_globally = cfg_P.readBoolEntry("Disabled", true); gesture_mouse_button = cfg_P.readNumEntry("MouseButton", 2); gesture_mouse_button = KCLAMP(gesture_mouse_button, 2, 9); gesture_timeout = cfg_P.readNumEntry("Timeout", 300); cfg_P.setGroup("GesturesExclude"); delete gestures_exclude; gestures_exclude = new Windowdef_list(cfg_P); cfg_P.setGroup("Voice"); voice_shortcut = KShortcut(cfg_P.readEntry("Shortcut", "")); return true; }
// // read the types from config file and update the internal list // void KateModeManager::update () { KConfig config ("katemoderc", KConfig::NoGlobals); QStringList g (config.groupList()); qDeleteAll (m_types); m_types.clear (); m_name2Type.clear (); for (int z=0; z < g.count(); z++) { KConfigGroup cg(&config, g[z]); KateFileType *type = new KateFileType (); type->number = z; type->name = g[z]; type->section = cg.readEntry ("Section"); type->wildcards = cg.readXdgListEntry ("Wildcards"); type->mimetypes = cg.readXdgListEntry ("Mimetypes"); type->priority = cg.readEntry ("Priority", 0); type->varLine = cg.readEntry ("Variables"); type->indenter = cg.readEntry ("Indenter"); type->hl = cg.readEntry ("Highlighting"); // only for generated types... type->hlGenerated = cg.readEntry ("Highlighting Generated", false); type->version = cg.readEntry ("Highlighting Version"); // insert into the list + hash... m_types.append(type); m_name2Type.insert (type->name, type); } // try if the hl stuff is up to date... const KateSyntaxModeList &modes = KateHlManager::self()->syntaxDocument()->modeList(); for (int i = 0; i < modes.size(); ++i) { KateFileType *type = 0; bool newType = false; if (m_name2Type.contains (modes[i]->name)) type = m_name2Type[modes[i]->name]; else { newType = true; type = new KateFileType (); type->name = modes[i]->name; type->priority = 0; m_types.append (type); m_name2Type.insert (type->name, type); } if (newType || type->version != modes[i]->version) { type->name = modes[i]->name; type->section = modes[i]->section; type->wildcards = modes[i]->extension.split (';', QString::SkipEmptyParts); type->mimetypes = modes[i]->mimetype.split (';', QString::SkipEmptyParts); type->priority = modes[i]->priority.toInt(); type->version = modes[i]->version; type->indenter = modes[i]->indenter; type->hl = modes[i]->name; type->hlGenerated = true; } } // sort the list... QList<KateFileType *> newList; for (int i=0; i < m_types.count(); i++) { KateFileType *t = m_types[i]; int insert = 0; for (; insert <= newList.count(); insert++) { if (insert == newList.count()) break; if ( QString(newList.at(insert)->section + newList.at(insert)->name).toLower() > QString(t->section + t->name).toLower() ) break; } newList.insert (insert, t); } // replace old list with new sorted list... m_types = newList; // add the none type... KateFileType *t = new KateFileType (); // DO NOT TRANSLATE THIS, DONE LATER, marked by hlGenerated t->name = "Normal"; t->hl = "None"; t->hlGenerated = true; m_types.prepend (t); }
void KonfUpdate::gotScript(const QString &_script) { QString script, interpreter; int i = _script.indexOf(','); if (i == -1) { script = _script.trimmed(); } else { script = _script.left(i).trimmed(); interpreter = _script.mid(i + 1).trimmed(); } if (script.isEmpty()) { logFileError() << "Script fails to specify filename"; m_skip = true; return; } QString path = KStandardDirs::locate("data", "kconf_update/" + script); if (path.isEmpty()) { if (interpreter.isEmpty()) { path = KStandardDirs::locate("lib", "kconf_update_bin/" + script); } if (path.isEmpty()) { logFileError() << "Script '" << script << "' not found" << endl; m_skip = true; return; } } if (!m_arguments.isNull()) { log() << m_currentFilename << ": Running script '" << script << "' with arguments '" << m_arguments << "'" << endl; } else { log() << m_currentFilename << ": Running script '" << script << "'" << endl; } QString cmd; if (interpreter.isEmpty()) { cmd = path; } else { cmd = interpreter + ' ' + path; } if (!m_arguments.isNull()) { cmd += ' '; cmd += m_arguments; } KTemporaryFile scriptIn; scriptIn.open(); KTemporaryFile scriptOut; scriptOut.open(); KTemporaryFile scriptErr; scriptErr.open(); int result; if (m_oldConfig1) { if (m_debug) { scriptIn.setAutoRemove(false); log() << "Script input stored in " << scriptIn.fileName() << endl; } KConfig cfg(scriptIn.fileName(), KConfig::SimpleConfig); if (m_oldGroup.isEmpty()) { // Write all entries to tmpFile; const QStringList grpList = m_oldConfig1->groupList(); for (QStringList::ConstIterator it = grpList.begin(); it != grpList.end(); ++it) { copyGroup(m_oldConfig1, *it, &cfg, *it); } } else { KConfigGroup cg1 = KConfigUtils::openGroup(m_oldConfig1, m_oldGroup); KConfigGroup cg2(&cfg, QString()); copyGroup(cg1, cg2); } cfg.sync(); #ifndef _WIN32_WCE result = system(QFile::encodeName(QString("%1 < %2 > %3 2> %4").arg(cmd, scriptIn.fileName(), scriptOut.fileName(), scriptErr.fileName()))); #else QString path_ = QDir::convertSeparators ( QFileInfo ( cmd ).absoluteFilePath() ); QString file_ = QFileInfo ( cmd ).fileName(); SHELLEXECUTEINFO execInfo; memset ( &execInfo,0,sizeof ( execInfo ) ); execInfo.cbSize = sizeof ( execInfo ); execInfo.fMask = SEE_MASK_FLAG_NO_UI; execInfo.lpVerb = L"open"; execInfo.lpFile = (LPCWSTR) path_.utf16(); execInfo.lpDirectory = (LPCWSTR) file_.utf16(); execInfo.lpParameters = (LPCWSTR) QString(" < %1 > %2 2> %3").arg( scriptIn.fileName(), scriptOut.fileName(), scriptErr.fileName()).utf16(); result = ShellExecuteEx ( &execInfo ); if (result != 0) { result = 0; } else { result = -1; } #endif } else { // No config file #ifndef _WIN32_WCE result = system(QFile::encodeName(QString("%1 2> %2").arg(cmd, scriptErr.fileName()))); #else QString path_ = QDir::convertSeparators ( QFileInfo ( cmd ).absoluteFilePath() ); QString file_ = QFileInfo ( cmd ).fileName(); SHELLEXECUTEINFO execInfo; memset ( &execInfo,0,sizeof ( execInfo ) ); execInfo.cbSize = sizeof ( execInfo ); execInfo.fMask = SEE_MASK_FLAG_NO_UI; execInfo.lpVerb = L"open"; execInfo.lpFile = (LPCWSTR) path_.utf16(); execInfo.lpDirectory = (LPCWSTR) file_.utf16(); execInfo.lpParameters = (LPCWSTR) QString(" 2> %1").arg( scriptErr.fileName()).utf16(); result = ShellExecuteEx ( &execInfo ); if (result != 0) { result = 0; } else { result = -1; } #endif } // Copy script stderr to log file { QFile output(scriptErr.fileName()); if (output.open(QIODevice::ReadOnly)) { QTextStream ts(&output); ts.setCodec(QTextCodec::codecForName("UTF-8")); while (!ts.atEnd()) { QString line = ts.readLine(); log() << "[Script] " << line << endl; } } } if (result) { log() << m_currentFilename << ": !! An error occurred while running '" << cmd << "'" << endl; return; } if (!m_oldConfig1) { return; // Nothing to merge } if (m_debug) { scriptOut.setAutoRemove(false); log() << "Script output stored in " << scriptOut.fileName() << endl; } // Deleting old entries { QStringList group = m_oldGroup; QFile output(scriptOut.fileName()); if (output.open(QIODevice::ReadOnly)) { QTextStream ts(&output); ts.setCodec(QTextCodec::codecForName("UTF-8")); while (!ts.atEnd()) { QString line = ts.readLine(); if (line.startsWith('[')) { group = parseGroupString(line); } else if (line.startsWith(QLatin1String("# DELETE "))) { QString key = line.mid(9); if (key[0] == '[') { int j = key.lastIndexOf(']') + 1; if (j > 0) { group = parseGroupString(key.left(j)); key = key.mid(j); } } KConfigGroup cg = KConfigUtils::openGroup(m_oldConfig2, group); cg.deleteEntry(key); log() << m_currentFilename << ": Script removes " << m_oldFile << ":" << group << ":" << key << endl; /*if (m_oldConfig2->deleteGroup(group, KConfig::Normal)) { // Delete group if empty. log() << m_currentFilename << ": Removing empty group " << m_oldFile << ":" << group << endl; } (this should be automatic)*/ } else if (line.startsWith(QLatin1String("# DELETEGROUP"))) { QString str = line.mid(13).trimmed(); if (!str.isEmpty()) { group = parseGroupString(str); } KConfigGroup cg = KConfigUtils::openGroup(m_oldConfig2, group); cg.deleteGroup(); log() << m_currentFilename << ": Script removes group " << m_oldFile << ":" << group << endl; } } } } // Merging in new entries. KConfig scriptOutConfig(scriptOut.fileName(), KConfig::NoGlobals); if (m_newGroup.isEmpty()) { // Copy "default" keys as members of "default" keys copyGroup(&scriptOutConfig, QString(), m_newConfig, QString()); } else { // Copy default keys as members of m_newGroup KConfigGroup srcCg = KConfigUtils::openGroup(&scriptOutConfig, QStringList()); KConfigGroup dstCg = KConfigUtils::openGroup(m_newConfig, m_newGroup); copyGroup(srcCg, dstCg); } Q_FOREACH(const QString &group, scriptOutConfig.groupList()) { copyGroup(&scriptOutConfig, group, m_newConfig, group); } }
void KonfUpdate::gotFile(const QString &_file) { // Reset group gotGroup(QString()); if (!m_oldFile.isEmpty()) { // Close old file. delete m_oldConfig1; m_oldConfig1 = 0; KConfigGroup cg(m_oldConfig2, "$Version"); QStringList ids = cg.readEntry("update_info", QStringList()); QString cfg_id = m_currentFilename + ':' + m_id; if (!ids.contains(cfg_id) && !m_skip) { ids.append(cfg_id); cg.writeEntry("update_info", ids); } cg.sync(); delete m_oldConfig2; m_oldConfig2 = 0; QString file = KStandardDirs::locateLocal("config", m_oldFile); KDE_struct_stat s_buf; if (KDE::stat(file, &s_buf) == 0) { if (s_buf.st_size == 0) { // Delete empty file. QFile::remove(file); } } m_oldFile.clear(); } if (!m_newFile.isEmpty()) { // Close new file. KConfigGroup cg(m_newConfig, "$Version"); QStringList ids = cg.readEntry("update_info", QStringList()); QString cfg_id = m_currentFilename + ':' + m_id; if (!ids.contains(cfg_id) && !m_skip) { ids.append(cfg_id); cg.writeEntry("update_info", ids); } m_newConfig->sync(); delete m_newConfig; m_newConfig = 0; m_newFile.clear(); } m_newConfig = 0; int i = _file.indexOf(','); if (i == -1) { m_oldFile = _file.trimmed(); } else { m_oldFile = _file.left(i).trimmed(); m_newFile = _file.mid(i + 1).trimmed(); if (m_oldFile == m_newFile) { m_newFile.clear(); } } if (!m_oldFile.isEmpty()) { m_oldConfig2 = new KConfig(m_oldFile, KConfig::NoGlobals); QString cfg_id = m_currentFilename + ':' + m_id; KConfigGroup cg(m_oldConfig2, "$Version"); QStringList ids = cg.readEntry("update_info", QStringList()); if (ids.contains(cfg_id)) { m_skip = true; m_newFile.clear(); log() << m_currentFilename << ": Skipping update '" << m_id << "'" << endl; } if (!m_newFile.isEmpty()) { m_newConfig = new KConfig(m_newFile, KConfig::NoGlobals); KConfigGroup cg(m_newConfig, "$Version"); ids = cg.readEntry("update_info", QStringList()); if (ids.contains(cfg_id)) { m_skip = true; log() << m_currentFilename << ": Skipping update '" << m_id << "'" << endl; } } else { m_newConfig = m_oldConfig2; } m_oldConfig1 = new KConfig(m_oldFile, KConfig::NoGlobals); } else { m_newFile.clear(); } m_newFileName = m_newFile; if (m_newFileName.isEmpty()) { m_newFileName = m_oldFile; } m_skipFile = false; if (!m_oldFile.isEmpty()) { // if File= is specified, it doesn't exist, is empty or contains only kconf_update's [$Version] group, skip if (m_oldConfig1 != NULL && (m_oldConfig1->groupList().isEmpty() || (m_oldConfig1->groupList().count() == 1 && m_oldConfig1->groupList().first() == "$Version"))) { log() << m_currentFilename << ": File '" << m_oldFile << "' does not exist or empty, skipping" << endl; m_skipFile = true; } } }