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 ); } }
/****************************************************************************** * If the preferences were written by a previous version of KAlarm, do any * necessary conversions. */ void Preferences::convertOldPrefs() { KConfig *config = KGlobal::config(); config->setGroup(GENERAL_SECTION); int version = KAlarm::getVersionNumber(config->readEntry(VERSION_NUM)); if(version >= KAlarm::Version(1, 4, 22)) return; // config format is up to date if(version <= KAlarm::Version(1, 4, 21)) { // Convert KAlarm 1.4.21 preferences static const QString OLD_REMIND_UNITS = QString::fromLatin1("DefRemindUnits"); config->setGroup(DEFAULTS_SECTION); int intUnit = config->readNumEntry(OLD_REMIND_UNITS, 0); QString strUnit = (intUnit == 1) ? QString::fromLatin1("Days") : (intUnit == 2) ? QString::fromLatin1("Weeks") : QString::fromLatin1("HoursMinutes"); config->deleteEntry(OLD_REMIND_UNITS); config->writeEntry(DEF_REMIND_UNITS, strUnit); } if(version <= KAlarm::Version(1, 4, 20)) { // Convert KAlarm 1.4.20 preferences static const QString VIEW_SECTION = QString::fromLatin1("View"); static const QString SHOW_ARCHIVED_ALARMS = QString::fromLatin1("ShowArchivedAlarms"); static const QString SHOW_EXPIRED_ALARMS = QString::fromLatin1("ShowExpiredAlarms"); static const QString SHOW_ALARM_TIME = QString::fromLatin1("ShowAlarmTime"); static const QString SHOW_TIME_TO_ALARM = QString::fromLatin1("ShowTimeToAlarm"); config->setGroup(GENERAL_SECTION); bool showExpired = config->readBoolEntry(SHOW_EXPIRED_ALARMS, false); bool showTime = config->readBoolEntry(SHOW_ALARM_TIME, true); bool showTimeTo = config->readBoolEntry(SHOW_TIME_TO_ALARM, false); config->deleteEntry(SHOW_EXPIRED_ALARMS); config->deleteEntry(SHOW_ALARM_TIME); config->deleteEntry(SHOW_TIME_TO_ALARM); config->setGroup(VIEW_SECTION); config->writeEntry(SHOW_ARCHIVED_ALARMS, showExpired); config->writeEntry(SHOW_ALARM_TIME, showTime); config->writeEntry(SHOW_TIME_TO_ALARM, showTimeTo); } if(version <= KAlarm::Version(1, 4, 5)) { // Convert KAlarm 1.4.5 preferences static const QString DEF_SOUND = QString::fromLatin1("DefSound"); config->setGroup(DEFAULTS_SECTION); bool sound = config->readBoolEntry(DEF_SOUND, false); if(!sound) config->writeEntry(DEF_SOUND_TYPE, SoundPicker::NONE); config->deleteEntry(DEF_SOUND); } if(version < KAlarm::Version(1, 3, 0)) { // Convert KAlarm pre-1.3 preferences static const QString EMAIL_ADDRESS = QString::fromLatin1("EmailAddress"); static const QString EMAIL_USE_CTRL_CENTRE = QString::fromLatin1("EmailUseControlCenter"); static const QString EMAIL_BCC_USE_CTRL_CENTRE = QString::fromLatin1("EmailBccUseControlCenter"); QMap<QString, QString> entries = config->entryMap(GENERAL_SECTION); if(entries.find(EMAIL_FROM) == entries.end() && entries.find(EMAIL_USE_CTRL_CENTRE) != entries.end()) { // Preferences were written by KAlarm pre-1.2.1 config->setGroup(GENERAL_SECTION); bool useCC = false; bool bccUseCC = false; const bool default_emailUseControlCentre = true; const bool default_emailBccUseControlCentre = true; useCC = config->readBoolEntry(EMAIL_USE_CTRL_CENTRE, default_emailUseControlCentre); // EmailBccUseControlCenter was missing in preferences written by KAlarm pre-0.9.5 bccUseCC = config->hasKey(EMAIL_BCC_USE_CTRL_CENTRE) ? config->readBoolEntry(EMAIL_BCC_USE_CTRL_CENTRE, default_emailBccUseControlCentre) : useCC; config->writeEntry(EMAIL_FROM, (useCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_ADDRESS))); config->writeEntry(EMAIL_BCC_ADDRESS, (bccUseCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_BCC_ADDRESS))); config->deleteEntry(EMAIL_ADDRESS); config->deleteEntry(EMAIL_BCC_USE_CTRL_CENTRE); config->deleteEntry(EMAIL_USE_CTRL_CENTRE); } // Convert KAlarm 1.2 preferences static const QString DEF_CMD_XTERM = QString::fromLatin1("DefCmdXterm"); config->setGroup(DEFAULTS_SECTION); if(config->hasKey(DEF_CMD_XTERM)) { config->writeEntry(DEF_CMD_LOG_TYPE, (config->readBoolEntry(DEF_CMD_XTERM, false) ? EditAlarmDlg::EXEC_IN_TERMINAL : EditAlarmDlg::DISCARD_OUTPUT)); config->deleteEntry(DEF_CMD_XTERM); } } config->setGroup(GENERAL_SECTION); config->writeEntry(VERSION_NUM, KALARM_VERSION); config->sync(); }
void doTests() { // the data file to use. // first determine the path used to call this program, // and then prepend that to the data file name. QString path = myName.section('/', 0, -3); QString datafile = path; datafile.append("/healpix_example_sm.fits"); // create a temporary config file to use QString cfgfile = "testhealpix.temp"; KConfig *cfg = new KConfig(cfgfile, false, false); cfg->setGroup("Healpix General"); cfg->setGroup(datafile); cfg->writeEntry("Matrix X Dimension", XDIM); cfg->writeEntry("Matrix Y Dimension", YDIM); cfg->writeEntry("Theta Autoscale", true); cfg->writeEntry("Theta Units", 0); cfg->writeEntry("Theta Min", 0.0); cfg->writeEntry("Theta Max", 1.0); cfg->writeEntry("Phi Autoscale", true); cfg->writeEntry("Phi Units", 0); cfg->writeEntry("Phi Min", 0.0); cfg->writeEntry("Phi Max", 1.0); cfg->writeEntry("Vector Theta", 1); cfg->writeEntry("Vector Phi", 2); cfg->writeEntry("Vector Degrade Factor", DEGRADE); cfg->writeEntry("Vector Magnitude Autoscale", true); cfg->writeEntry("Vector Max Magnitude", 1.0); cfg->writeEntry("Vector is QU", true); // use the C functions to test for healpix support int verstehen = understands_healpix(cfg, datafile); if (verstehen) { kstdDebug() << "Data file " << datafile << " is supported" << endl; QString suggestion; bool complete; QStringList matrices = matrixList_healpix(cfg, datafile, "HEALPIX", &suggestion, &complete); kstdDebug() << "Available matrices are:" << endl; for ( QStringList::Iterator it = matrices.begin(); it != matrices.end(); ++it ) { kstdDebug() << " " << *it << endl; } kstdDebug() << " suggestion = " << suggestion << endl; kstdDebug() << " complete = " << complete << endl; QStringList fields = fieldList_healpix(cfg, datafile, "HEALPIX", &suggestion, &complete); kstdDebug() << "Available fields are:" << endl; for ( QStringList::Iterator it = fields.begin(); it != fields.end(); ++it ) { kstdDebug() << " " << *it << endl; } kstdDebug() << " suggestion = " << suggestion << endl; kstdDebug() << " complete = " << complete << endl; // actually create HealpixSource HealpixSource *hpx = new HealpixSource(cfg, datafile, "HEALPIX"); // test that saveConfig produces the same as the // original input configuration QString cfgfile2 = "testhealpix.temp2"; KConfig *chk = new KConfig(cfgfile2, false, false); hpx->saveConfig(chk); StringMap cfgmap = cfg->entryMap(datafile); StringMap chkmap = chk->entryMap(datafile); /* kstdDebug() << cfgmap["Matrix X Dimension"] << " " << chkmap["Matrix X Dimension"] << endl; kstdDebug() << cfgmap["Matrix Y Dimension"] << " " << chkmap["Matrix Y Dimension"] << endl; kstdDebug() << cfgmap["Theta Autoscale"] << " " << chkmap["Theta Autoscale"] << endl; kstdDebug() << cfgmap["Theta Units"] << " " << chkmap["Theta Units"] << endl; kstdDebug() << cfgmap["Theta Min"] << " " << chkmap["Theta Min"] << endl; kstdDebug() << cfgmap["Theta Max"] << " " << chkmap["Theta Max"] << endl; kstdDebug() << cfgmap["Phi Autoscale"] << " " << chkmap["Phi Autoscale"] << endl; kstdDebug() << cfgmap["Phi Units"] << " " << chkmap["Phi Units"] << endl; kstdDebug() << cfgmap["Phi Min"] << " " << chkmap["Phi Min"] << endl; kstdDebug() << cfgmap["Phi Max"] << " " << chkmap["Phi Max"] << endl; kstdDebug() << cfgmap["Vector Theta"] << " " << chkmap["Vector Theta"] << endl; kstdDebug() << cfgmap["Vector Phi"] << " " << chkmap["Vector Phi"] << endl; kstdDebug() << cfgmap["Vector Degrade Factor"] << " " << chkmap["Vector Degrade Factor"] << endl; kstdDebug() << cfgmap["Vector Magnitude Autoscale"] << " " << chkmap["Vector Magnitude Autoscale"] << endl; kstdDebug() << cfgmap["Vector Max Magnitude"] << " " << chkmap["Vector Max Magnitude"] << endl; kstdDebug() << cfgmap["Vector is QU"] << " " << chkmap["Vector is QU"] << endl; */ if (cfgmap["Matrix X Dimension"] != chkmap["Matrix X Dimension"]) { QString msg = "Matrix X Dimension integrity"; testAssert(false, msg); } if (cfgmap["Matrix Y Dimension"] != chkmap["Matrix Y Dimension"]) { QString msg = "Matrix Y Dimension integrity"; testAssert(false, msg); } if (cfgmap["Theta Autoscale"] != chkmap["Theta Autoscale"]) { QString msg = "Theta Autoscale integrity"; testAssert(false, msg); } if (cfgmap["Theta Units"] != chkmap["Theta Units"]) { QString msg = "Theta Units integrity"; testAssert(false, msg); } if (cfgmap["Theta Min"] != chkmap["Theta Min"]) { QString msg = "Theta Min integrity"; testAssert(false, msg); } if (cfgmap["Theta Max"] != chkmap["Theta Max"]) { QString msg = "Theta Max integrity"; testAssert(false, msg); } if (cfgmap["Phi Autoscale"] != chkmap["Phi Autoscale"]) { QString msg = "Phi Autoscale integrity"; testAssert(false, msg); } if (cfgmap["Phi Units"] != chkmap["Phi Units"]) { QString msg = "Phi Units integrity"; testAssert(false, msg); } if (cfgmap["Phi Min"] != chkmap["Phi Min"]) { QString msg = "Phi Min integrity"; testAssert(false, msg); } if (cfgmap["Phi Max"] != chkmap["Phi Max"]) { QString msg = "Phi Max integrity"; testAssert(false, msg); } if (cfgmap["Vector Theta"] != chkmap["Vector Theta"]) { QString msg = "Vector Theta integrity"; testAssert(false, msg); } if (cfgmap["Vector Phi"] != chkmap["Vector Phi"]) { QString msg = "Vector Phi integrity"; testAssert(false, msg); } if (cfgmap["Vector Degrade Factor"] != chkmap["Vector Degrade Factor"]) { QString msg = "Vector Degrade Factor integrity"; testAssert(false, msg); } if (cfgmap["Vector Magnitude Autoscale"] != chkmap["Vector Magnitude Autoscale"]) { QString msg = "Vector Magnitude Autoscale integrity"; testAssert(false, msg); } if (cfgmap["Vector Max Magnitude"] != chkmap["Vector Max Magnitude"]) { QString msg = "Vector Max Magnitude integrity"; testAssert(false, msg); } if (cfgmap["Vector is QU"] != chkmap["Vector is QU"]) { QString msg = "Vector is QU integrity"; testAssert(false, msg); } kstdDebug() << "Save/Load config is consistent." << endl; // print _metaData and compute NSIDE and number // of samples in the vectors int nside = 0; int nvec; QString key; KstString *data; kstdDebug() << "Checking metaData:" << endl; QDict<KstString> metamap = hpx->metaData(); QDictIterator<KstString> it(metamap); for ( ; it.current(); ++it ) { key = it.currentKey(); data = it.current(); if (data) { kstdDebug() << " " << key.latin1() << " = " << data->value().latin1() << endl; if (key == "NSIDE") { nside = data->value().toInt(); } } } kstdDebug() << "Data file has nside = " << nside << endl; testAssert(nside != 0, "data file NSIDE"); for (int i = 0; i < DEGRADE; i++) { nside = (int)(nside/2); } nvec = 12*nside*nside; kstdDebug() << "Degraded vectorfield has nside = " << nside << " and " << nvec << " full-sphere pixels" << endl; // check that all returned fields are valid, and that // optionally field number names are valid. kstdDebug() << "Checking matrix validity:" << endl; int num = 1; int xdim, ydim, nframe, sampframe; for ( QStringList::Iterator it = matrices.begin(); it != matrices.end(); ++it ) { if (hpx->isValidMatrix(*it)) { kstdDebug() << " \"" << *it << "\" is VALID" << endl; hpx->matrixDimensions(*it, &xdim, &ydim); kstdDebug() << " and has dimensions " << xdim << "x" << ydim << endl; testAssert((xdim == XDIM)&&(ydim == YDIM), "dimension integrity"); } else { QString msg = (*it); msg.append(" validity"); testAssert(false, msg); } QString numfield = QString("%1").arg(num); if (hpx->isValidMatrix(numfield)) { kstdDebug() << " \"" << numfield << "\" is VALID" << endl; hpx->matrixDimensions(numfield, &xdim, &ydim); kstdDebug() << " and has dimensions " << xdim << "x" << ydim << endl; testAssert((xdim == XDIM)&&(ydim == YDIM), "dimension integrity"); } else { QString msg = numfield; msg.append(" validity"); testAssert(false, msg); } num++; } kstdDebug() << "Checking field validity:" << endl; num = 1; for ( QStringList::Iterator it = fields.begin(); it != fields.end(); ++it ) { if (hpx->isValidField(*it)) { kstdDebug() << " \"" << *it << "\" is VALID" << endl; nframe = hpx->frameCount(*it); sampframe = hpx->samplesPerFrame(*it); kstdDebug() << " and has " << nframe << " frames of " << sampframe << " sample(s) each" << endl; testAssert(sampframe == 1, "samples per frame"); testAssert(nframe == nvec, "number of frames"); } else { QString msg = (*it); msg.append(" validity"); testAssert(false, msg); } QString numfield = QString("%1").arg(num); if (hpx->isValidField(numfield)) { kstdDebug() << " \"" << numfield << "\" is VALID" << endl; nframe = hpx->frameCount(numfield); sampframe = hpx->samplesPerFrame(numfield); kstdDebug() << " and has " << nframe << " frames of " << sampframe << " sample(s) each" << endl; testAssert(sampframe == 1, "samples per frame"); testAssert(nframe == nvec, "number of frames"); } else { QString msg = numfield; msg.append(" validity"); testAssert(false, msg); } num++; } // check reset function if (hpx->reset()) { kstdDebug() << "Reset function is implemented." << endl; } else { testAssert(false, "reset"); } } else { testAssert(false, "understanding"); } }