Back to index

kdeartwork  4.3.2
config.cpp
Go to the documentation of this file.
00001 /*
00002  *     $Id: config.cpp 570330 2006-08-06 13:12:39Z mlaurent $
00003  *
00004  *     This file contains the IceWM configuration widget
00005  *
00006  *     Copyright (c) 2001
00007  *            Karol Szwed <gallium@kde.org>
00008  *            http://gallium.n3.net/
00009  *
00010  *  This program is free software; you can redistribute it and/or
00011  *  modify it under the terms of the GNU General Public
00012  *  License as published by the Free Software Foundation; either
00013  *  version 2 of the License, or (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *  General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; see the file COPYING.  If not, write to
00022  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023  *  Boston, MA 02110-1301, USA.
00024  *
00025  */
00026 
00027 #include "config.h"
00028 #include <qdir.h>
00029 #include <qregexp.h>
00030 #include <q3vbox.h>
00031 
00032 //Added by qt3to4:
00033 #include <QLabel>
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 #include <kstandarddirs.h>
00037 #include <kdialog.h>
00038 #include <kdirwatch.h>
00039 #include <kapplication.h>
00040 #include <ktoolinvocation.h>
00041 
00042 
00043 extern "C"
00044 {
00045        KDE_EXPORT QObject* allocate_config( KConfig* conf, QWidget* parent )
00046        {
00047               return(new IceWMConfig(conf, parent));
00048        }
00049 }
00050 
00051 
00052 // NOTE:
00053 // ==========================================================================
00054 // 'conf'            is a pointer to the kwindecoration modules open kwin config,
00055 //                          and is by default set to the "Style" group.
00056 //
00057 // 'parent'          is the parent of the QObject, which is a VBox inside the
00058 //                          Configure tab in kwindecoration
00059 // ==========================================================================
00060 
00061 IceWMConfig::IceWMConfig( KConfig* conf, QWidget* parent )
00062        : QObject( parent )
00063 {
00064        icewmConfig = new KConfig("kwinicewmrc");
00065        KGlobal::locale()->insertCatalog("kwin_art_clients");
00066 
00067        mainWidget = new Q3VBox( parent );
00068        mainWidget->setSpacing( KDialog::spacingHint() );
00069 
00070        themeListBox = new Q3ListBox( mainWidget );
00071        themeListBox->setWhatsThis(
00072                             i18n("Make your IceWM selection by clicking on a theme here. ") );
00073 
00074        cbThemeTitleTextColors = new QCheckBox(
00075                             i18n("Use theme &title text colors"), mainWidget );
00076 
00077        cbThemeTitleTextColors->setWhatsThis(
00078                             i18n("When selected, titlebar colors will follow those set "
00079                             "in the IceWM theme. If not selected, the current KDE "
00080                             "titlebar colors will be used instead.") );
00081 
00082        cbTitleBarOnTop = new QCheckBox(
00083                             i18n("&Show title bar on top of windows"), mainWidget );
00084 
00085        cbTitleBarOnTop->setWhatsThis(
00086                             i18n("When selected, all window titlebars will be shown "
00087                             "at the top of each window, otherwise they will be "
00088                             "shown at the bottom.") );
00089 
00090        cbShowMenuButtonIcon = new QCheckBox(
00091                             i18n("&Menu button always shows application mini icon"), mainWidget );
00092 
00093        cbShowMenuButtonIcon->setWhatsThis(
00094                             i18n("When selected, all titlebar menu buttons will have "
00095                             "the application icon shown. If not selected, the current "
00096                             "theme's defaults are used instead.") );
00097 
00098        urlLabel = new KUrlLabel( mainWidget );
00099        urlLabel->setText( i18n("Open KDE's IceWM theme folder") );
00100 
00101        themeLabel = new QLabel(
00102                             i18n("Clicking on the link above will cause a window to appear "
00103                                 "showing the KDE IceWM theme folder. You can "
00104                             "add or remove native IceWM themes by "
00105                             "uncompressing <b>http://icewm.themes.org/</b> theme files "
00106                             "into this folder, or by creating folder symlinks to "
00107                             "existing IceWM themes on your system."), mainWidget );
00108 
00109        // Load configuration options
00110        load( conf );
00111 
00112        // Ensure we track user changes properly
00113        connect( themeListBox, SIGNAL(selectionChanged()),
00114                       this, SLOT(slotSelectionChanged()) );
00115 
00116        connect( urlLabel, SIGNAL(leftClickedUrl(const QString&)),
00117                       this, SLOT(callURL(const QString&)));
00118 
00119        connect( cbThemeTitleTextColors, SIGNAL(clicked()),
00120                       this, SLOT(slotSelectionChanged()) );
00121 
00122        connect( cbTitleBarOnTop, SIGNAL(clicked()),
00123                       this, SLOT(slotSelectionChanged()) );
00124 
00125        connect( cbShowMenuButtonIcon, SIGNAL(clicked()),
00126                       this, SLOT(slotSelectionChanged()) );
00127 
00128        // Create the theme directory (if not found) ... and obtain the path as we do so.
00129        localThemeString = KGlobal::dirs()->saveLocation("data", "kwin");
00130        localThemeString += "/icewm-themes";
00131        if (!QFile::exists(localThemeString))
00132               QDir().mkdir(localThemeString);
00133 
00134        // Watch the icewm theme directory for theme additions/removals
00135        KDirWatch::self()->addDir(localThemeString);
00136        connect( KDirWatch::self(), SIGNAL(dirty(const QString&)), this, SLOT(findIceWMThemes()) );
00137        connect( KDirWatch::self(), SIGNAL(created(const QString&)), this, SLOT(findIceWMThemes()) );
00138        connect( KDirWatch::self(), SIGNAL(deleted(const QString&)), this, SLOT(findIceWMThemes()) );
00139 
00140        // Set the konqui link url
00141        QString urlThemeString = QString("file://") + localThemeString;
00142        urlThemeString.replace( QRegExp("~"), "$HOME" );
00143        urlLabel->setURL( urlThemeString );
00144 
00145        // Make the widgets visible in kwindecoration
00146        mainWidget->show();
00147 
00148        KDirWatch::self()->startScan();
00149 }
00150 
00151 
00152 IceWMConfig::~IceWMConfig()
00153 {
00154        KDirWatch::self()->removeDir(localThemeString);
00155        KDirWatch::self()->stopScan();
00156        delete icewmConfig;
00157        delete mainWidget;
00158 }
00159 
00160 
00161 // Searches for all installed IceWM themes, and adds them to the listBox.
00162 void IceWMConfig::findIceWMThemes()
00163 {
00164        QStringList dirList = KGlobal::dirs()->findDirs("data", "kwin/icewm-themes");
00165        QStringList::ConstIterator it;
00166 
00167        // Remove any old themes in the list (if any)
00168        themeListBox->clear();
00169        themeListBox->insertItem( i18n("Infadel #2 (default)") );
00170 
00171        // Step through all kwin/icewm-themes directories...
00172        for( it = dirList.begin(); it != dirList.end(); it++)
00173        {
00174               // List all directory names only...
00175               QDir d(*it, QString("*"), QDir::Unsorted, QDir::Dirs | QDir::Readable );
00176               if (d.exists())
00177               {
00178                      QFileInfoListIterator it2( *d.entryInfoList() );
00179                      QFileInfo* finfo;
00180 
00181                      // Step through all directories within the kwin/icewm-themes directory
00182                      while( (finfo = it2.current()) )
00183                      {
00184                             // Ignore . and .. directories
00185                             if ( (finfo->fileName() == ".") || (finfo->fileName() == "..") )
00186                             {
00187                                    ++it2;
00188                                    continue;
00189                             }
00190 
00191                             if ( !themeListBox->findItem( finfo->fileName()) )
00192                                    themeListBox->insertItem( finfo->fileName() );
00193 
00194                             ++it2;
00195                      }
00196               }
00197        }
00198 
00199        // Sort the items
00200        themeListBox->sort();
00201 
00202        // Select the currently used IceWM theme
00203        QString themeName = icewmConfig->readEntry("CurrentTheme");
00204 
00205        // Provide a theme alias
00206        if (themeName == "default")
00207               themeName = "";
00208 
00209        if (themeName.isEmpty())
00210               themeListBox->setCurrentItem(
00211                      themeListBox->findItem( i18n("Infadel #2 (default)") ) );
00212        else
00213               themeListBox->setCurrentItem( themeListBox->findItem(themeName) );
00214 }
00215 
00216 
00217 void IceWMConfig::callURL( const QString& s )
00218 {
00219        KToolInvocation::invokeBrowser( s );
00220 }
00221 
00222 
00223 void IceWMConfig::slotSelectionChanged()
00224 {
00225        emit changed();
00226 }
00227 
00228 
00229 // Loads the configurable options from the kwinicewmrc config file
00230 void IceWMConfig::load( KConfig* )
00231 {
00232        icewmConfig->setGroup("General");
00233 
00234        bool override = icewmConfig->readEntry( "ThemeTitleTextColors", true );
00235        cbThemeTitleTextColors->setChecked( override );
00236 
00237        override = icewmConfig->readEntry( "TitleBarOnTop", true );
00238        cbTitleBarOnTop->setChecked( override );
00239 
00240        override = icewmConfig->readEntry( "ShowMenuButtonIcon", false );
00241        cbShowMenuButtonIcon->setChecked( override );
00242 
00243        findIceWMThemes();
00244 }
00245 
00246 
00247 // Saves the configurable options to the kwinicewmrc config file
00248 void IceWMConfig::save( KConfig* )
00249 {
00250        icewmConfig->setGroup("General");
00251        icewmConfig->writeEntry( "ThemeTitleTextColors", cbThemeTitleTextColors->isChecked() );
00252        icewmConfig->writeEntry( "TitleBarOnTop", cbTitleBarOnTop->isChecked() );
00253        icewmConfig->writeEntry( "ShowMenuButtonIcon", cbShowMenuButtonIcon->isChecked() );
00254 
00255        if (themeListBox->currentText() == i18n("Infadel #2 (default)"))
00256               icewmConfig->writeEntry("CurrentTheme", "default");
00257        else
00258               icewmConfig->writeEntry("CurrentTheme", themeListBox->currentText() );
00259 
00260        icewmConfig->sync();
00261 }
00262 
00263 
00264 // Sets UI widget defaults which must correspond to config defaults
00265 void IceWMConfig::defaults()
00266 {
00267        cbThemeTitleTextColors->setChecked( true );
00268        cbTitleBarOnTop->setChecked( true );
00269        cbShowMenuButtonIcon->setChecked( false );
00270        themeListBox->setCurrentItem( themeListBox->findItem(i18n("Infadel #2 (default)")) );
00271 }
00272 
00273 #include "config.moc"
00274 // vim: ts=4