void ArtworkCalligraphyOptionWidget::removeProfile(const QString &name) { kDebug(38000) << "removing profile" << name; int index = profilePosition(name); if (index < 0) return; // no such profile // remove the file from the config file KConfig config(KGlobal::mainComponent(), RCFILENAME); int deletedIndex = m_profiles[name]->index; QString deletedGroup = "Profile" + QString::number(deletedIndex); kDebug(38000) << deletedGroup; config.deleteGroup(deletedGroup); config.sync(); // and from profiles m_profiles.remove(name); m_comboBox->removeItem(index); // now in the config file there is value ProfileN missing, // where N = configIndex, so put the last one there if (m_profiles.isEmpty()) return; int lastN = -1; Profile *profile = 0; // profile to be moved, will be the last one foreach(Profile *p, m_profiles) { if (p->index > lastN) { lastN = p->index; profile = p; } } Q_ASSERT(profile != 0); // do nothing if the deleted group was the last one if (deletedIndex > lastN) return; QString lastGroup = "Profile" + QString::number(lastN); config.deleteGroup(lastGroup); KConfigGroup profileGroup(&config, deletedGroup); profileGroup.writeEntry("name", profile->name); profileGroup.writeEntry("usePath", profile->usePath); profileGroup.writeEntry("usePressure", profile->usePressure); profileGroup.writeEntry("useAngle", profile->useAngle); profileGroup.writeEntry("width", profile->width); profileGroup.writeEntry("thinning", profile->thinning); profileGroup.writeEntry("angle", profile->angle); profileGroup.writeEntry("fixation", profile->fixation); profileGroup.writeEntry("caps", profile->caps); profileGroup.writeEntry("mass", profile->mass); profileGroup.writeEntry("drag", profile->drag); config.sync(); profile->index = deletedIndex; }
void ArtworkCalligraphyOptionWidget::loadProfiles() { KConfig config(KGlobal::mainComponent(), RCFILENAME); // load profiles as long as they are present int i = 0; while (1) { // forever KConfigGroup profileGroup(&config, "Profile" + QString::number(i)); // invalid profile, assume we reached the last one if (! profileGroup.hasKey("name")) break; Profile *profile = new Profile; profile->index = i; profile->name = profileGroup.readEntry("name", QString()); profile->usePath = profileGroup.readEntry("usePath", false); profile->usePressure = profileGroup.readEntry("usePressure", false); profile->useAngle = profileGroup.readEntry("useAngle", false); profile->width = profileGroup.readEntry("width", 30.0); profile->thinning = profileGroup.readEntry("thinning", 0.2); profile->angle = profileGroup.readEntry("angle", 30); profile->fixation = profileGroup.readEntry("fixation", 0.0); profile->caps = profileGroup.readEntry("caps", 0.0); profile->mass = profileGroup.readEntry("mass", 3.0); profile->drag = profileGroup.readEntry("drag", 0.7); m_profiles.insert(profile->name, profile); ++i; } m_changingProfile = true; ProfileMap::const_iterator it = m_profiles.constBegin(); ProfileMap::const_iterator lastIt = m_profiles.constEnd(); for (; it != lastIt; ++it) { m_comboBox->addItem(it.key()); } m_changingProfile = false; loadCurrentProfile(); }
KonqProfileMap KonqProfileDlg::readAllProfiles() { KonqProfileMap mapProfiles; const QStringList profiles = KGlobal::dirs()->findAllResources( "data", "konqueror/profiles/*", KStandardDirs::NoDuplicates ); QStringList::ConstIterator pIt = profiles.constBegin(); QStringList::ConstIterator pEnd = profiles.constEnd(); for (; pIt != pEnd; ++pIt ) { QFileInfo info( *pIt ); QString profileName = KIO::decodeFileName( info.baseName() ); KConfig cfg( *pIt, KConfig::SimpleConfig); if ( cfg.hasGroup( "Profile" ) ) { KConfigGroup profileGroup( &cfg, "Profile" ); if ( profileGroup.hasKey( "Name" ) ) profileName = profileGroup.readEntry( "Name" ); mapProfiles.insert( profileName, *pIt ); } } return mapProfiles; }
void ArtworkCalligraphyOptionWidget::saveProfile(const QString &name) { kDebug(38000) << name; Profile *profile = new Profile; profile->name = name; profile->usePath = m_usePath->isChecked(); profile->usePressure = m_usePressure->isChecked(); profile->useAngle = m_useAngle->isChecked(); profile->width = m_widthBox->value(); profile->thinning = m_thinningBox->value(); profile->angle = m_angleBox->value(); profile->fixation = m_fixationBox->value(); profile->caps = m_capsBox->value(); profile->mass = m_massBox->value(); profile->drag = m_dragBox->value(); if (m_profiles.contains(name)) { // there is already a profile with the same name, overwrite profile->index = m_profiles[name]->index; m_profiles.insert(name, profile); } else { // it is a new profile profile->index = m_profiles.count(); m_profiles.insert(name, profile); // add the profile to the combobox kDebug(38000) << "BEFORE:"; QString dbg; for (int i = 0; i < m_comboBox->count(); ++i) dbg += m_comboBox->itemText(i) + ' '; kDebug(38000) << dbg; int pos = profilePosition(name); m_changingProfile = true; m_comboBox->insertItem(pos, name); m_changingProfile = false; kDebug(38000) << "AFTER:"; for (int i = 0; i < m_comboBox->count(); ++i) dbg += m_comboBox->itemText(i) + ' '; kDebug(38000) << dbg; kDebug(38000) << "new at" << pos << m_comboBox->itemText(pos) << name; } KConfig config(KGlobal::mainComponent(), RCFILENAME); QString str = "Profile" + QString::number(profile->index); KConfigGroup profileGroup(&config, str); profileGroup.writeEntry("name", name); profileGroup.writeEntry("usePath", profile->usePath); profileGroup.writeEntry("usePressure", profile->usePressure); profileGroup.writeEntry("useAngle", profile->useAngle); profileGroup.writeEntry("width", profile->width); profileGroup.writeEntry("thinning", profile->thinning); profileGroup.writeEntry("angle", profile->angle); profileGroup.writeEntry("fixation", profile->fixation); profileGroup.writeEntry("caps", profile->caps); profileGroup.writeEntry("mass", profile->mass); profileGroup.writeEntry("drag", profile->drag); KConfigGroup generalGroup(&config, "General"); generalGroup.writeEntry("profile", name); config.sync(); kDebug(38000) << name; int pos = profilePosition(name); kDebug(38000) << "adding in" << pos << m_comboBox->itemText(pos); m_comboBox->setCurrentIndex(profilePosition(name)); kDebug(38000) << m_comboBox->currentText(); }