Back to index

kdeartwork  4.3.2
kxsitem.cpp
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 // KDE xscreensaver configuration dialog
00004 //
00005 // Copyright (c)  Martin R. Jones <mjones@kde.org> 1999
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public
00009 // License as published by the Free Software Foundation;
00010 // version 2 of the License.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; see the file COPYING.  If not, write to
00019 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020 // Boston, MA 02110-1301, USA.
00021 
00022 #include "kxsconfig.h"
00023 #include <klocale.h>
00024 #include <qxml.h>
00025 
00026 //===========================================================================
00027 KXSConfigItem::KXSConfigItem(const QString &name, KConfig &config)
00028   : mName(name)
00029 {
00030   KConfigGroup grp = config.group(name);
00031   mLabel = i18n(grp.readEntry("Label").toUtf8());
00032 }
00033 
00034 KXSConfigItem::KXSConfigItem(const QString &name, const QXmlAttributes &attr )
00035   : mName(name)
00036 {
00037   mLabel = attr.value("_label");
00038 }
00039 
00040 //===========================================================================
00041 KXSRangeItem::KXSRangeItem(const QString &name, KConfig &config)
00042   : KXSConfigItem(name, config), mInvert(false)
00043 {
00044   KConfigGroup grp(&config, name);
00045   mMinimum = grp.readEntry("Minimum",0);
00046   mMaximum = grp.readEntry("Maximum",0);
00047   mValue   = grp.readEntry("Value",0);
00048   mSwitch  = grp.readEntry("Switch",0);
00049 }
00050 
00051 KXSRangeItem::KXSRangeItem(const QString &name, const QXmlAttributes &attr )
00052   : KXSConfigItem(name, attr), mInvert(false)
00053 {
00054   mMinimum = attr.value("low").toInt();
00055   mMaximum = attr.value("high").toInt();
00056   mValue   = attr.value("default").toInt();
00057   mSwitch  = attr.value("arg");
00058   int pos = mSwitch.indexOf( '%' );
00059   if (pos >= 0)
00060     mSwitch.insert(pos+1, '1');
00061   if ( attr.value("convert") == "invert" )
00062     mInvert = true;
00063   if (mInvert)
00064     mValue = mMaximum-(mValue-mMinimum);
00065 }
00066 
00067 QString KXSRangeItem::command()
00068 {
00069   return mSwitch.arg(mInvert?mMaximum-(mValue-mMinimum):mValue);
00070 }
00071 
00072 void KXSRangeItem::read(KConfig &config)
00073 {
00074   KConfigGroup grp = config.group(mName);
00075   if (grp.hasKey("Value"))
00076       mValue = grp.readEntry("Value",0);
00077 }
00078 
00079 void KXSRangeItem::save(KConfig &config)
00080 {
00081   KConfigGroup grp = config.group(mName);
00082   grp.writeEntry("Value", mValue);
00083 }
00084 
00085 //===========================================================================
00086 KXSDoubleRangeItem::KXSDoubleRangeItem(const QString &name, KConfig &config)
00087   : KXSConfigItem(name, config), mInvert(false)
00088 {
00089  KConfigGroup grp(&config, name);
00090   mMinimum = grp.readEntry("Minimum",0.0);
00091   mMaximum = grp.readEntry("Maximum",0.0);
00092   mValue   = grp.readEntry("Value",0.0);
00093   mSwitch  = grp.readEntry("Switch");
00094 }
00095 
00096 KXSDoubleRangeItem::KXSDoubleRangeItem(const QString &name, const QXmlAttributes &attr)
00097   : KXSConfigItem(name, attr), mInvert(false)
00098 {
00099   mMinimum = attr.value("low").toDouble();
00100   mMaximum = attr.value("high").toDouble();
00101   mValue   = attr.value("default").toDouble();
00102   mSwitch  = attr.value("arg");
00103   int pos = mSwitch.indexOf( '%' );
00104   if (pos >= 0)
00105     mSwitch.insert(pos+1, '1');
00106   if ( attr.value("convert") == "invert" )
00107     mInvert = true;
00108   if (mInvert)
00109     mValue = mMaximum-(mValue-mMinimum);
00110 }
00111 
00112 QString KXSDoubleRangeItem::command()
00113 {
00114   return mSwitch.arg(mInvert?mMaximum-(mValue-mMinimum):mValue);
00115 }
00116 
00117 void KXSDoubleRangeItem::read(KConfig &config)
00118 {
00119   KConfigGroup grp = config.group(mName);
00120   if (grp.hasKey("Value"))
00121       mValue = grp.readEntry("Value",0.0);
00122 }
00123 
00124 void KXSDoubleRangeItem::save(KConfig &config)
00125 {
00126   KConfigGroup grp = config.group(mName);
00127   grp.writeEntry("Value", mValue);
00128 }
00129 
00130 
00131 //===========================================================================
00132 KXSBoolItem::KXSBoolItem(const QString &name, KConfig &config)
00133   : KXSConfigItem(name, config)
00134 {
00135   KConfigGroup grp(&config, name);
00136   mValue = grp.readEntry("Value",0);
00137   mSwitchOn  = grp.readEntry("SwitchOn");
00138   mSwitchOff = grp.readEntry("SwitchOff");
00139 }
00140 
00141 KXSBoolItem::KXSBoolItem(const QString &name, const QXmlAttributes &attr )
00142   : KXSConfigItem(name, attr)
00143 {
00144   mSwitchOn  = attr.value("arg-set");
00145   mSwitchOff = attr.value("arg-unset");
00146   mValue = mSwitchOn.isEmpty() ? true : false;
00147 }
00148 
00149 QString KXSBoolItem::command()
00150 {
00151   return mValue ? mSwitchOn : mSwitchOff;
00152 }
00153 
00154 void KXSBoolItem::read(KConfig &config)
00155 {
00156   KConfigGroup grp = config.group(mName);
00157   if (grp.hasKey("Value"))
00158       mValue = grp.readEntry("Value", false);
00159 }
00160 
00161 void KXSBoolItem::save(KConfig &config)
00162 {
00163   KConfigGroup grp = config.group(mName);
00164   grp.writeEntry("Value", mValue);
00165 }
00166 
00167 //===========================================================================
00168 KXSSelectItem::KXSSelectItem(const QString &name, KConfig &config)
00169   : KXSConfigItem(name, config)
00170 {
00171   KConfigGroup grp(&config, name);
00172   mOptions = grp.readEntry("Options",QStringList());
00173   mSwitches = grp.readEntry("Switches",QStringList());
00174   mValue = grp.readEntry("Value",0);
00175 }
00176 
00177 KXSSelectItem::KXSSelectItem(const QString &name, const QXmlAttributes &attr )
00178   : KXSConfigItem(name, attr), mValue(0)
00179 {
00180 }
00181 
00182 void KXSSelectItem::addOption( const QXmlAttributes &attr )
00183 {
00184     QString opt = attr.value("_label");
00185     QString arg = attr.value("arg-set");
00186     if ( arg.isEmpty() )
00187        mValue = mSwitches.count();
00188     mOptions += opt;
00189     mSwitches += arg;
00190 }
00191 
00192 QString KXSSelectItem::command()
00193 {
00194   QString tmp = mSwitches.at(mValue);
00195   return tmp;
00196 }
00197 
00198 void KXSSelectItem::read(KConfig &config)
00199 {
00200   KConfigGroup grp = config.group(mName);
00201   if (grp.hasKey("Value"))
00202       mValue = grp.readEntry("Value",0);
00203 }
00204 
00205 void KXSSelectItem::save(KConfig &config)
00206 {
00207   KConfigGroup grp = config.group(mName);
00208   grp.writeEntry("Value", mValue);
00209 }
00210 
00211 
00212 //===========================================================================
00213 KXSStringItem::KXSStringItem(const QString &name, KConfig &config)
00214   : KXSConfigItem(name, config)
00215 {
00216   KConfigGroup grp(&config, name);
00217   mValue = grp.readEntry("Value");
00218   mSwitch = grp.readEntry("Switch");
00219   int pos = mSwitch.indexOf( '%' );
00220   if (pos >= 0) {
00221     mSwitch.insert(pos+1, "\"");
00222     mSwitch.insert(pos, "\"");
00223   }
00224 }
00225 
00226 KXSStringItem::KXSStringItem(const QString &name, const QXmlAttributes &attr )
00227   : KXSConfigItem(name, attr)
00228 {
00229   mSwitch = attr.value("arg");
00230   int pos = mSwitch.indexOf( '%' );
00231   if (pos >= 0) {
00232     mSwitch.insert(pos+1, "1\"");
00233     mSwitch.insert(pos, "\"");
00234   }
00235 }
00236 
00237 QString KXSStringItem::command()
00238 {
00239   if (!mValue.isEmpty())
00240       return mSwitch.arg(mValue);
00241   return "";
00242 }
00243 
00244 void KXSStringItem::read(KConfig &config)
00245 {
00246   KConfigGroup grp = config.group(mName);
00247   if (grp.hasKey("Value"))
00248       mValue = grp.readEntry("Value");
00249 }
00250 
00251 void KXSStringItem::save(KConfig &config)
00252 {
00253   KConfigGroup grp = config.group(mName);
00254   grp.writeEntry("Value", mValue);
00255 }
00256