• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kglobalsettings.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2000, 2006 David Faure <faure@kde.org>
00003    Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kglobalsettings.h"
00021 #include <config.h>
00022 
00023 #include <kconfig.h>
00024 
00025 #include <kdebug.h>
00026 #include <kglobal.h>
00027 #include <kstandarddirs.h>
00028 #include <kcharsets.h>
00029 #include <klocale.h>
00030 #include <kprotocolinfo.h>
00031 #include <kcomponentdata.h>
00032 #include <kcolorscheme.h>
00033 #include <kapplication.h>
00034 
00035 #include <kstyle.h>
00036 
00037 #include <QtGui/QColor>
00038 #include <QtGui/QCursor>
00039 #include <QtGui/QDesktopWidget>
00040 #include <QtCore/QDir>
00041 #include <QtGui/QFont>
00042 #include <QtGui/QFontDatabase>
00043 #include <QtGui/QFontInfo>
00044 #include <QtGui/QKeySequence>
00045 #include <QtGui/QPixmap>
00046 #include <QtGui/QPixmapCache>
00047 #include <QApplication>
00048 #include <QtDBus/QtDBus>
00049 #include <QtGui/QStyleFactory>
00050 #include <QDesktopServices>
00051 
00052 // next two needed so we can set their palettes
00053 #include <QtGui/QToolTip>
00054 #include <QtGui/QWhatsThis>
00055 
00056 #ifdef Q_WS_WIN
00057 #include <windows.h>
00058 #include <kkernel_win.h>
00059 
00060 static QRgb qt_colorref2qrgb(COLORREF col)
00061 {
00062     return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));
00063 }
00064 #endif
00065 #ifdef Q_WS_X11
00066 #include <X11/Xlib.h>
00067 #ifdef HAVE_XCURSOR
00068 #include <X11/Xcursor/Xcursor.h>
00069 #endif
00070 #include "fixx11h.h"
00071 #include <QX11Info>
00072 #endif
00073 
00074 #include <stdlib.h>
00075 #include <kconfiggroup.h>
00076 
00077 
00078 //static QColor *_buttonBackground = 0;
00079 static KGlobalSettings::GraphicEffects _graphicEffects = KGlobalSettings::NoEffects;
00080 
00081 // KDE5: merge this with KGlobalSettings::Private
00082 // also think to make all methods static and not expose an object,
00083 // making KGlobalSettings rather a namespace
00084 class KGlobalSettingsData
00085 {
00086   public:
00087     // if adding a new type here also add an entry to DefaultFontData
00088     enum FontTypes
00089     {
00090         GeneralFont = 0,
00091         FixedFont,
00092         ToolbarFont,
00093         MenuFont,
00094         WindowTitleFont,
00095         TaskbarFont ,
00096         SmallestReadableFont,
00097         FontTypesCount
00098     };
00099 
00100   public:
00101     KGlobalSettingsData();
00102     ~KGlobalSettingsData();
00103 
00104   public:
00105     static KGlobalSettingsData* self();
00106 
00107   public: // access, is not const due to caching
00108     QFont font( FontTypes fontType );
00109     QFont largeFont( const QString& text );
00110     KGlobalSettings::KMouseSettings& mouseSettings();
00111 
00112   public:
00113     void dropFontSettingsCache();
00114     void dropMouseSettingsCache();
00115 
00116   protected:
00117     QFont* mFonts[FontTypesCount];
00118     QFont* mLargeFont;
00119     KGlobalSettings::KMouseSettings* mMouseSettings;
00120 };
00121 
00122 KGlobalSettingsData::KGlobalSettingsData()
00123   : mLargeFont( 0 ),
00124     mMouseSettings( 0 )
00125 {
00126     for( int i=0; i<FontTypesCount; ++i )
00127         mFonts[i] = 0;
00128 }
00129 
00130 KGlobalSettingsData::~KGlobalSettingsData()
00131 {
00132     for( int i=0; i<FontTypesCount; ++i )
00133         delete mFonts[i];
00134     delete mLargeFont;
00135 
00136     delete mMouseSettings;
00137 }
00138 
00139 K_GLOBAL_STATIC( KGlobalSettingsData, globalSettingsDataSingleton )
00140 
00141 inline KGlobalSettingsData* KGlobalSettingsData::self()
00142 {
00143     return globalSettingsDataSingleton;
00144 }
00145 
00146 
00147 class KGlobalSettings::Private
00148 {
00149     public:
00150         Private(KGlobalSettings *q)
00151             : q(q), activated(false)
00152         {
00153         }
00154 
00155         void _k_slotNotifyChange(int, int);
00156 
00157         void propagateQtSettings();
00158         void kdisplaySetPalette();
00159         void kdisplaySetStyle();
00160         void kdisplaySetFont();
00161         void applyGUIStyle();
00162 
00174         void applyCursorTheme();
00175 
00179         static void rereadOtherSettings();
00180 
00181         KGlobalSettings *q;
00182         bool activated;
00183 };
00184 
00185 KGlobalSettings* KGlobalSettings::self()
00186 {
00187     K_GLOBAL_STATIC(KGlobalSettings, s_self)
00188     return s_self;
00189 }
00190 
00191 KGlobalSettings::KGlobalSettings()
00192     : QObject(0), d(new Private(this))
00193 {
00194     QDBusConnection::sessionBus().connect( QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
00195                                            "notifyChange", this, SLOT(_k_slotNotifyChange(int,int)) );
00196 }
00197 
00198 KGlobalSettings::~KGlobalSettings()
00199 {
00200     delete d;
00201 }
00202 
00203 void KGlobalSettings::activate()
00204 {
00205     if (!d->activated) {
00206         d->activated = true;
00207 
00208         d->kdisplaySetStyle(); // implies palette setup
00209         d->kdisplaySetFont();
00210         d->propagateQtSettings();
00211     }
00212 }
00213 
00214 int KGlobalSettings::dndEventDelay()
00215 {
00216     KConfigGroup g( KGlobal::config(), "General" );
00217     return g.readEntry("StartDragDist", QApplication::startDragDistance());
00218 }
00219 
00220 bool KGlobalSettings::singleClick()
00221 {
00222     KConfigGroup g( KGlobal::config(), "KDE" );
00223     return g.readEntry("SingleClick", KDE_DEFAULT_SINGLECLICK );
00224 }
00225 
00226 bool KGlobalSettings::smoothScroll()
00227 {
00228     KConfigGroup g( KGlobal::config(), "KDE" );
00229     return g.readEntry("SmoothScroll", KDE_DEFAULT_SMOOTHSCROLL );
00230 }
00231 
00232 KGlobalSettings::TearOffHandle KGlobalSettings::insertTearOffHandle()
00233 {
00234     int tearoff;
00235     bool effectsenabled;
00236     KConfigGroup g( KGlobal::config(), "KDE" );
00237     effectsenabled = g.readEntry( "EffectsEnabled", false);
00238     tearoff = g.readEntry("InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
00239     return effectsenabled ? (TearOffHandle) tearoff : Disable;
00240 }
00241 
00242 bool KGlobalSettings::changeCursorOverIcon()
00243 {
00244     KConfigGroup g( KGlobal::config(), "KDE" );
00245     return g.readEntry("ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
00246 }
00247 
00248 int KGlobalSettings::autoSelectDelay()
00249 {
00250     KConfigGroup g( KGlobal::config(), "KDE" );
00251     return g.readEntry("AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
00252 }
00253 
00254 KGlobalSettings::Completion KGlobalSettings::completionMode()
00255 {
00256     int completion;
00257     KConfigGroup g( KGlobal::config(), "General" );
00258     completion = g.readEntry("completionMode", -1);
00259     if ((completion < (int) CompletionNone) ||
00260         (completion > (int) CompletionPopupAuto))
00261       {
00262         completion = (int) CompletionPopup; // Default
00263       }
00264   return (Completion) completion;
00265 }
00266 
00267 bool KGlobalSettings::showContextMenusOnPress ()
00268 {
00269     KConfigGroup g(KGlobal::config(), "ContextMenus");
00270     return g.readEntry("ShowOnPress", true);
00271 }
00272 
00273 int KGlobalSettings::contextMenuKey ()
00274 {
00275     KConfigGroup g(KGlobal::config(), "Shortcuts");
00276     QString s = g.readEntry ("PopupMenuContext", "Menu");
00277 
00278     // this is a bit of a code duplication with KShortcut,
00279     // but seeing as that is all in kdeui these days there's little choice.
00280     // this is faster for what we're really after here anyways
00281     // (less allocations, only processing the first item always, etc)
00282     if (s == QLatin1String("none")) {
00283         return QKeySequence()[0];
00284     }
00285 
00286     const QStringList shortCuts = s.split(';');
00287 
00288     if (shortCuts.count() < 1) {
00289         return QKeySequence()[0];
00290     }
00291 
00292     s = shortCuts.at(0);
00293 
00294     if ( s.startsWith( "default(" ) ) {
00295         s = s.mid( 8, s.length() - 9 );
00296     }
00297 
00298     return QKeySequence::fromString(s)[0];
00299 }
00300 
00301 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
00302 QColor KGlobalSettings::inactiveTitleColor()
00303 {
00304 #ifdef Q_WS_WIN
00305     return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
00306 #else
00307     KConfigGroup g( KGlobal::config(), "WM" );
00308     return g.readEntry( "inactiveBackground", QColor(224, 223, 222) );
00309 #endif
00310 }
00311 
00312 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
00313 QColor KGlobalSettings::inactiveTextColor()
00314 {
00315 #ifdef Q_WS_WIN
00316     return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
00317 #else
00318     KConfigGroup g( KGlobal::config(), "WM" );
00319     return g.readEntry( "inactiveForeground", QColor(20, 19, 18) );
00320 #endif
00321 }
00322 
00323 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
00324 QColor KGlobalSettings::activeTitleColor()
00325 {
00326 #ifdef Q_WS_WIN
00327     return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
00328 #else
00329     KConfigGroup g( KGlobal::config(), "WM" );
00330     return g.readEntry( "activeBackground", QColor(96, 148, 207));
00331 #endif
00332 }
00333 
00334 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
00335 QColor KGlobalSettings::activeTextColor()
00336 {
00337 #ifdef Q_WS_WIN
00338     return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
00339 #else
00340     KConfigGroup g( KGlobal::config(), "WM" );
00341     return g.readEntry( "activeForeground", QColor(255, 255, 255) );
00342 #endif
00343 }
00344 
00345 int KGlobalSettings::contrast()
00346 {
00347     KConfigGroup g( KGlobal::config(), "KDE" );
00348     return g.readEntry( "contrast", 7 );
00349 }
00350 
00351 qreal KGlobalSettings::contrastF(const KSharedConfigPtr &config)
00352 {
00353     if (config) {
00354         KConfigGroup g( config, "KDE" );
00355         return 0.1 * g.readEntry( "contrast", 7 );
00356     }
00357     return 0.1 * (qreal)contrast();
00358 }
00359 
00360 bool KGlobalSettings::shadeSortColumn()
00361 {
00362     KConfigGroup g( KGlobal::config(), "General" );
00363     return g.readEntry( "shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
00364 }
00365 
00366 bool KGlobalSettings::allowDefaultBackgroundImages()
00367 {
00368     KConfigGroup g( KGlobal::config(), "General" );
00369     return g.readEntry( "allowDefaultBackgroundImages", KDE_DEFAULT_ALLOW_DEFAULT_BACKGROUND_IMAGES );
00370 }
00371 
00372 struct KFontData
00373 {
00374     const char* ConfigGroupKey;
00375     const char* ConfigKey;
00376     const char* FontName;
00377     int Size;
00378     int Weight;
00379     QFont::StyleHint StyleHint;
00380 };
00381 
00382 // NOTE: keep in sync with kdebase/workspace/kcontrol/fonts/fonts.cpp
00383 static const char GeneralId[] =      "General";
00384 static const char DefaultFont[] =    "Sans Serif";
00385 #ifdef Q_WS_MAC
00386 static const char DefaultMacFont[] = "Lucida Grande";
00387 #endif
00388 
00389 static const KFontData DefaultFontData[KGlobalSettingsData::FontTypesCount] =
00390 {
00391 #ifdef Q_WS_MAC
00392     { GeneralId, "font",        DefaultMacFont, 13, -1, QFont::SansSerif },
00393     { GeneralId, "fixed",       "Monaco",       10, -1, QFont::TypeWriter },
00394     { GeneralId, "toolBarFont", DefaultMacFont, 11, -1, QFont::SansSerif },
00395     { GeneralId, "menuFont",    DefaultMacFont, 13, -1, QFont::SansSerif },
00396 #else
00397     { GeneralId, "font",        DefaultFont, 10, -1, QFont::SansSerif },
00398     { GeneralId, "fixed",       "Monospace", 10, -1, QFont::TypeWriter },
00399     { GeneralId, "toolBarFont", DefaultFont,  8, -1, QFont::SansSerif },
00400     { GeneralId, "menuFont",    DefaultFont, 10, -1, QFont::SansSerif },
00401 #endif
00402     { "WM",      "activeFont",           DefaultFont,  9, QFont::Bold, QFont::SansSerif },// inconsistency
00403     { GeneralId, "taskbarFont",          DefaultFont, 10, -1, QFont::SansSerif },
00404     { GeneralId, "smallestReadableFont", DefaultFont,  8, -1, QFont::SansSerif }
00405 };
00406 
00407 QFont KGlobalSettingsData::font( FontTypes fontType )
00408 {
00409     QFont* cachedFont = mFonts[fontType];
00410 
00411     if (!cachedFont)
00412     {
00413         const KFontData& fontData = DefaultFontData[fontType];
00414         cachedFont = new QFont( fontData.FontName, fontData.Size, fontData.Weight );
00415         cachedFont->setStyleHint( fontData.StyleHint );
00416 
00417         const KConfigGroup configGroup( KGlobal::config(), fontData.ConfigGroupKey );
00418         *cachedFont = configGroup.readEntry( fontData.ConfigKey, *cachedFont );
00419 
00420         mFonts[fontType] = cachedFont;
00421     }
00422 
00423     return *cachedFont;
00424 }
00425 
00426 QFont KGlobalSettings::generalFont()
00427 {
00428     return KGlobalSettingsData::self()->font( KGlobalSettingsData::GeneralFont );
00429 }
00430 QFont KGlobalSettings::fixedFont()
00431 {
00432     return KGlobalSettingsData::self()->font( KGlobalSettingsData::FixedFont );
00433 }
00434 QFont KGlobalSettings::toolBarFont()
00435 {
00436     return KGlobalSettingsData::self()->font( KGlobalSettingsData::ToolbarFont );
00437 }
00438 QFont KGlobalSettings::menuFont()
00439 {
00440     return KGlobalSettingsData::self()->font( KGlobalSettingsData::MenuFont );
00441 }
00442 QFont KGlobalSettings::windowTitleFont()
00443 {
00444     return KGlobalSettingsData::self()->font( KGlobalSettingsData::WindowTitleFont );
00445 }
00446 QFont KGlobalSettings::taskbarFont()
00447 {
00448     return KGlobalSettingsData::self()->font( KGlobalSettingsData::TaskbarFont );
00449 }
00450 QFont KGlobalSettings::smallestReadableFont()
00451 {
00452     return KGlobalSettingsData::self()->font( KGlobalSettingsData::SmallestReadableFont );
00453 }
00454 
00455 
00456 QFont KGlobalSettingsData::largeFont( const QString& text )
00457 {
00458     QFontDatabase db;
00459     QStringList fam = db.families();
00460 
00461     // Move a bunch of preferred fonts to the front.
00462     // most preferred last
00463     static const char* const PreferredFontNames[] =
00464     {
00465         "Arial",
00466         "Sans Serif",
00467         "Verdana",
00468         "Tahoma",
00469         "Lucida Sans",
00470         "Lucidux Sans",
00471         "Nimbus Sans",
00472         "Gothic I"
00473     };
00474     static const unsigned int PreferredFontNamesCount = sizeof(PreferredFontNames)/sizeof(const char*);
00475     for( unsigned int i=0; i<PreferredFontNamesCount; ++i )
00476     {
00477         const QString fontName (PreferredFontNames[i]);
00478         if (fam.removeAll(fontName)>0)
00479             fam.prepend(fontName);
00480     }
00481 
00482     if (mLargeFont) {
00483         fam.prepend(mLargeFont->family());
00484         delete mLargeFont;
00485     }
00486 
00487     for(QStringList::ConstIterator it = fam.constBegin();
00488         it != fam.constEnd(); ++it)
00489     {
00490         if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
00491         {
00492             QFont font(*it);
00493             font.setPixelSize(75);
00494             QFontMetrics metrics(font);
00495             int h = metrics.height();
00496             if ((h < 60) || ( h > 90))
00497                 continue;
00498 
00499             bool ok = true;
00500             for(int i = 0; i < text.length(); i++)
00501             {
00502                 if (!metrics.inFont(text[i]))
00503                 {
00504                     ok = false;
00505                     break;
00506                 }
00507             }
00508             if (!ok)
00509                 continue;
00510 
00511             font.setPointSize(48);
00512             mLargeFont = new QFont(font);
00513             return *mLargeFont;
00514         }
00515     }
00516     mLargeFont = new QFont( font(GeneralFont) );
00517     mLargeFont->setPointSize(48);
00518     return *mLargeFont;
00519 }
00520 QFont KGlobalSettings::largeFont( const QString& text )
00521 {
00522     return KGlobalSettingsData::self()->largeFont( text );
00523 }
00524 
00525 void KGlobalSettingsData::dropFontSettingsCache()
00526 {
00527     for( int i=0; i<FontTypesCount; ++i )
00528     {
00529         delete mFonts[i];
00530         mFonts[i] = 0;
00531     }
00532     delete mLargeFont;
00533     mLargeFont = 0;
00534 }
00535 
00536 KGlobalSettings::KMouseSettings& KGlobalSettingsData::mouseSettings()
00537 {
00538     if (!mMouseSettings)
00539     {
00540         mMouseSettings = new KGlobalSettings::KMouseSettings;
00541         KGlobalSettings::KMouseSettings& s = *mMouseSettings; // for convenience
00542 
00543 #ifndef Q_WS_WIN
00544         KConfigGroup g( KGlobal::config(), "Mouse" );
00545         QString setting = g.readEntry("MouseButtonMapping");
00546         if (setting == "RightHanded")
00547             s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00548         else if (setting == "LeftHanded")
00549             s.handed = KGlobalSettings::KMouseSettings::LeftHanded;
00550         else
00551         {
00552 #ifdef Q_WS_X11
00553             // get settings from X server
00554             // This is a simplified version of the code in input/mouse.cpp
00555             // Keep in sync !
00556             s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00557             unsigned char map[20];
00558             int num_buttons = XGetPointerMapping(QX11Info::display(), map, 20);
00559             if( num_buttons == 2 )
00560             {
00561                 if ( (int)map[0] == 1 && (int)map[1] == 2 )
00562                     s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00563                 else if ( (int)map[0] == 2 && (int)map[1] == 1 )
00564                     s.handed = KGlobalSettings::KMouseSettings::LeftHanded;
00565             }
00566             else if( num_buttons >= 3 )
00567             {
00568                 if ( (int)map[0] == 1 && (int)map[2] == 3 )
00569                     s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00570                 else if ( (int)map[0] == 3 && (int)map[2] == 1 )
00571                     s.handed = KGlobalSettings::KMouseSettings::LeftHanded;
00572             }
00573 #else
00574         // FIXME: Implement on other platforms
00575 #endif
00576         }
00577 #endif //Q_WS_WIN
00578     }
00579 #ifdef Q_WS_WIN
00580     //not cached
00581     mMouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ?
00582         KGlobalSettings::KMouseSettings::LeftHanded :
00583         KGlobalSettings::KMouseSettings::RightHanded);
00584 #endif
00585     return *mMouseSettings;
00586 }
00587 // KDE5: make this a const return?
00588 KGlobalSettings::KMouseSettings & KGlobalSettings::mouseSettings()
00589 {
00590     return KGlobalSettingsData::self()->mouseSettings();
00591 }
00592 
00593 void KGlobalSettingsData::dropMouseSettingsCache()
00594 {
00595 #ifndef Q_WS_WIN
00596     delete mMouseSettings;
00597     mMouseSettings = 0;
00598 #endif
00599 }
00600 
00601 QString KGlobalSettings::desktopPath()
00602 {
00603     QString path = QDesktopServices::storageLocation( QDesktopServices::DesktopLocation );
00604     return path.isEmpty() ? QDir::homePath() : path;
00605 }
00606 
00607 // Autostart is not a XDG path, so we have our own code for it.
00608 QString KGlobalSettings::autostartPath()
00609 {
00610     QString s_autostartPath;
00611     KConfigGroup g( KGlobal::config(), "Paths" );
00612     s_autostartPath = KGlobal::dirs()->localkdedir() + "Autostart/";
00613     s_autostartPath = g.readPathEntry( "Autostart" , s_autostartPath );
00614     s_autostartPath = QDir::cleanPath( s_autostartPath );
00615     if ( !s_autostartPath.endsWith( '/' ) ) {
00616         s_autostartPath.append( QLatin1Char( '/' ) );
00617     }
00618     return s_autostartPath;
00619 }
00620 
00621 QString KGlobalSettings::documentPath()
00622 {
00623     QString path = QDesktopServices::storageLocation( QDesktopServices::DocumentsLocation );
00624     return path.isEmpty() ? QDir::homePath() : path;
00625 }
00626 
00627 QString KGlobalSettings::downloadPath()
00628 {
00629     // Qt 4.4.1 does not have DOWNLOAD, so we based on old code for now
00630     QString downloadPath = QDir::homePath();
00631 #ifndef Q_WS_WIN
00632     const QString xdgUserDirs = KGlobal::dirs()->localxdgconfdir() + QLatin1String( "user-dirs.dirs" );
00633     if( QFile::exists( xdgUserDirs ) ) {
00634         KConfig xdgUserConf( xdgUserDirs, KConfig::SimpleConfig );
00635         KConfigGroup g( &xdgUserConf, "" );
00636         downloadPath  = g.readPathEntry( "XDG_DOWNLOAD_DIR", downloadPath ).remove(  '"' );
00637     }
00638 #endif
00639     downloadPath = QDir::cleanPath( downloadPath );
00640     if ( !downloadPath.endsWith( '/' ) ) {
00641         downloadPath.append( QLatin1Char(  '/' ) );
00642     }
00643     return downloadPath;
00644 }
00645 
00646 QString KGlobalSettings::videosPath()
00647 {
00648     QString path = QDesktopServices::storageLocation( QDesktopServices::MoviesLocation );
00649     return path.isEmpty() ? QDir::homePath() : path;
00650 }
00651 
00652 QString KGlobalSettings::picturesPath()
00653 {
00654     QString path = QDesktopServices::storageLocation( QDesktopServices::PicturesLocation );
00655     return path.isEmpty() ? QDir::homePath() :path;
00656 }
00657 
00658 QString KGlobalSettings::musicPath()
00659 {
00660     QString path = QDesktopServices::storageLocation( QDesktopServices::MusicLocation );
00661     return path.isEmpty() ? QDir::homePath() : path;
00662 }
00663 
00664 bool KGlobalSettings::isMultiHead()
00665 {
00666 #ifdef Q_WS_WIN
00667     return GetSystemMetrics(SM_CMONITORS) > 1;
00668 #else
00669     QByteArray multiHead = qgetenv("KDE_MULTIHEAD");
00670     if (!multiHead.isEmpty()) {
00671         return (multiHead.toLower() == "true");
00672     }
00673     return false;
00674 #endif
00675 }
00676 
00677 bool KGlobalSettings::wheelMouseZooms()
00678 {
00679     KConfigGroup g( KGlobal::config(), "KDE" );
00680     return g.readEntry( "WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
00681 }
00682 
00683 QRect KGlobalSettings::splashScreenDesktopGeometry()
00684 {
00685     QDesktopWidget *dw = QApplication::desktop();
00686 
00687     if (dw->isVirtualDesktop()) {
00688         KConfigGroup group(KGlobal::config(), "Windows");
00689         int scr = group.readEntry("Unmanaged", -3);
00690         if (group.readEntry("XineramaEnabled", true) && scr != -2) {
00691             if (scr == -3)
00692                 scr = dw->screenNumber(QCursor::pos());
00693             return dw->screenGeometry(scr);
00694         } else {
00695             return dw->geometry();
00696         }
00697     } else {
00698         return dw->geometry();
00699     }
00700 }
00701 
00702 QRect KGlobalSettings::desktopGeometry(const QPoint& point)
00703 {
00704     QDesktopWidget *dw = QApplication::desktop();
00705 
00706     if (dw->isVirtualDesktop()) {
00707         KConfigGroup group(KGlobal::config(), "Windows");
00708         if (group.readEntry("XineramaEnabled", true) &&
00709             group.readEntry("XineramaPlacementEnabled", true)) {
00710             return dw->screenGeometry(dw->screenNumber(point));
00711         } else {
00712             return dw->geometry();
00713         }
00714     } else {
00715         return dw->geometry();
00716     }
00717 }
00718 
00719 QRect KGlobalSettings::desktopGeometry(const QWidget* w)
00720 {
00721     QDesktopWidget *dw = QApplication::desktop();
00722 
00723     if (dw->isVirtualDesktop()) {
00724         KConfigGroup group(KGlobal::config(), "Windows");
00725         if (group.readEntry("XineramaEnabled", true) &&
00726             group.readEntry("XineramaPlacementEnabled", true)) {
00727             if (w)
00728                 return dw->screenGeometry(dw->screenNumber(w));
00729             else return dw->screenGeometry(-1);
00730         } else {
00731             return dw->geometry();
00732         }
00733     } else {
00734         return dw->geometry();
00735     }
00736 }
00737 
00738 bool KGlobalSettings::showIconsOnPushButtons()
00739 {
00740     KConfigGroup g( KGlobal::config(), "KDE" );
00741     return g.readEntry("ShowIconsOnPushButtons",
00742                        KDE_DEFAULT_ICON_ON_PUSHBUTTON);
00743 }
00744 
00745 KGlobalSettings::GraphicEffects KGlobalSettings::graphicEffectsLevel()
00746 {
00747     // This variable stores whether _graphicEffects has the default value because it has not been
00748     // loaded yet, or if it has been loaded from the user settings or defaults and contains a valid
00749     // value.
00750     static bool _graphicEffectsInitialized = false;
00751 
00752     if (!_graphicEffectsInitialized) {
00753         _graphicEffectsInitialized = true;
00754         Private::rereadOtherSettings();
00755     }
00756 
00757     return _graphicEffects;
00758 }
00759 
00760 KGlobalSettings::GraphicEffects KGlobalSettings::graphicEffectsLevelDefault()
00761 {
00762     // For now, let always enable animations by default. The plan is to make
00763     // this code a bit smarter. (ereslibre)
00764 
00765     return ComplexAnimationEffects;
00766 }
00767 
00768 bool KGlobalSettings::showFilePreview(const KUrl &url)
00769 {
00770     KConfigGroup g(KGlobal::config(), "PreviewSettings");
00771     QString protocol = url.protocol();
00772     bool defaultSetting = KProtocolInfo::showFilePreview( protocol );
00773     return g.readEntry(protocol, defaultSetting );
00774 }
00775 
00776 bool KGlobalSettings::opaqueResize()
00777 {
00778     KConfigGroup g( KGlobal::config(), "KDE" );
00779     return g.readEntry("OpaqueResize", KDE_DEFAULT_OPAQUE_RESIZE);
00780 }
00781 
00782 int KGlobalSettings::buttonLayout()
00783 {
00784     KConfigGroup g( KGlobal::config(), "KDE" );
00785     return g.readEntry("ButtonLayout", KDE_DEFAULT_BUTTON_LAYOUT);
00786 }
00787 
00788 void KGlobalSettings::emitChange(ChangeType changeType, int arg)
00789 {
00790     QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange" );
00791     QList<QVariant> args;
00792     args.append(static_cast<int>(changeType));
00793     args.append(arg);
00794     message.setArguments(args);
00795     QDBusConnection::sessionBus().send(message);
00796 #ifdef Q_WS_X11
00797     if (qApp && qApp->type() != QApplication::Tty) {
00798         //notify non-kde qt applications of the change
00799         extern void qt_x11_apply_settings_in_all_apps();
00800         qt_x11_apply_settings_in_all_apps();
00801     }
00802 #endif
00803 }
00804 
00805 void KGlobalSettings::Private::_k_slotNotifyChange(int changeType, int arg)
00806 {
00807     switch(changeType) {
00808     case StyleChanged:
00809         if (activated) {
00810             KGlobal::config()->reparseConfiguration();
00811             kdisplaySetStyle();
00812         }
00813         break;
00814 
00815     case ToolbarStyleChanged:
00816         KGlobal::config()->reparseConfiguration();
00817         emit q->toolbarAppearanceChanged(arg);
00818         break;
00819 
00820     case PaletteChanged:
00821         if (activated) {
00822             KGlobal::config()->reparseConfiguration();
00823             kdisplaySetPalette();
00824         }
00825         break;
00826 
00827     case FontChanged:
00828         KGlobal::config()->reparseConfiguration();
00829         KGlobalSettingsData::self()->dropFontSettingsCache();
00830         if (activated) {
00831             kdisplaySetFont();
00832         }
00833         break;
00834 
00835     case SettingsChanged: {
00836         KGlobal::config()->reparseConfiguration();
00837         rereadOtherSettings();
00838         SettingsCategory category = static_cast<SettingsCategory>(arg);
00839         if (category == SETTINGS_MOUSE) {
00840             KGlobalSettingsData::self()->dropMouseSettingsCache();
00841         }
00842         if (category == SETTINGS_QT) {
00843             if (activated) {
00844                 propagateQtSettings();
00845             }
00846         } else {
00847             emit q->settingsChanged(category);
00848         }
00849         break;
00850     }
00851     case IconChanged:
00852         QPixmapCache::clear();
00853         KGlobal::config()->reparseConfiguration();
00854         emit q->iconChanged(arg);
00855         break;
00856 
00857     case CursorChanged:
00858         applyCursorTheme();
00859         break;
00860 
00861     case BlockShortcuts:
00862         // FIXME KAccel port
00863         //KGlobalAccel::blockShortcuts(arg);
00864         emit q->blockShortcuts(arg); // see kwin
00865         break;
00866 
00867     default:
00868         kWarning(101) << "Unknown type of change in KGlobalSettings::slotNotifyChange: " << changeType;
00869     }
00870 }
00871 
00872 // Set by KApplication
00873 QString kde_overrideStyle;
00874 
00875 void KGlobalSettings::Private::applyGUIStyle()
00876 {
00877     const QLatin1String currentStyleName(qApp->style()->metaObject()->className());
00878 
00879     if (kde_overrideStyle.isEmpty()) {
00880         const QString &defaultStyle = KStyle::defaultStyle();
00881         const KConfigGroup pConfig(KGlobal::config(), "General");
00882         const QString &styleStr = pConfig.readEntry("widgetStyle4", pConfig.readEntry("widgetStyle", defaultStyle));
00883 
00884         if (styleStr.isEmpty() ||
00885                 // check whether we already use the correct style to return then
00886                 // (workaround for Qt misbehavior to avoid double style initialization)
00887                 0 == (styleStr + QLatin1String("Style")).compare(currentStyleName, Qt::CaseInsensitive) ||
00888                 0 == styleStr.compare(currentStyleName, Qt::CaseInsensitive)) {
00889             return;
00890         }
00891 
00892         QStyle* sp = QStyleFactory::create( styleStr );
00893         if (sp && currentStyleName == sp->metaObject()->className()) {
00894             delete sp;
00895             return;
00896         }
00897 
00898         // If there is no default style available, try falling back any available style
00899         if ( !sp && styleStr != defaultStyle)
00900             sp = QStyleFactory::create( defaultStyle );
00901         if ( !sp )
00902             sp = QStyleFactory::create( QStyleFactory::keys().first() );
00903         qApp->setStyle(sp);
00904     } else if (0 != kde_overrideStyle.compare(currentStyleName, Qt::CaseInsensitive) &&
00905             0 != (kde_overrideStyle + QLatin1String("Style")).compare(currentStyleName, Qt::CaseInsensitive)) {
00906         qApp->setStyle(kde_overrideStyle);
00907     }
00908     emit q->kdisplayStyleChanged();
00909 }
00910 
00911 QPalette KGlobalSettings::createApplicationPalette(const KSharedConfigPtr &config)
00912 {
00913     QPalette palette;
00914 
00915     QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
00916                                        QPalette::Disabled };
00917 
00918     // TT thinks tooltips shouldn't use active, so we use our active colors for all states
00919     KColorScheme schemeTooltip(QPalette::Active, KColorScheme::Tooltip, config);
00920 
00921     for ( int i = 0; i < 3 ; i++ ) {
00922         QPalette::ColorGroup state = states[i];
00923         KColorScheme schemeView(state, KColorScheme::View, config);
00924         KColorScheme schemeWindow(state, KColorScheme::Window, config);
00925         KColorScheme schemeButton(state, KColorScheme::Button, config);
00926         KColorScheme schemeSelection(state, KColorScheme::Selection, config);
00927 
00928         palette.setBrush( state, QPalette::WindowText, schemeWindow.foreground() );
00929         palette.setBrush( state, QPalette::Window, schemeWindow.background() );
00930         palette.setBrush( state, QPalette::Base, schemeView.background() );
00931         palette.setBrush( state, QPalette::Text, schemeView.foreground() );
00932         palette.setBrush( state, QPalette::Button, schemeButton.background() );
00933         palette.setBrush( state, QPalette::ButtonText, schemeButton.foreground() );
00934         palette.setBrush( state, QPalette::Highlight, schemeSelection.background() );
00935         palette.setBrush( state, QPalette::HighlightedText, schemeSelection.foreground() );
00936         palette.setBrush( state, QPalette::ToolTipBase, schemeTooltip.background() );
00937         palette.setBrush( state, QPalette::ToolTipText, schemeTooltip.foreground() );
00938 
00939         palette.setColor( state, QPalette::Light, schemeWindow.shade( KColorScheme::LightShade ) );
00940         palette.setColor( state, QPalette::Midlight, schemeWindow.shade( KColorScheme::MidlightShade ) );
00941         palette.setColor( state, QPalette::Mid, schemeWindow.shade( KColorScheme::MidShade ) );
00942         palette.setColor( state, QPalette::Dark, schemeWindow.shade( KColorScheme::DarkShade ) );
00943         palette.setColor( state, QPalette::Shadow, schemeWindow.shade( KColorScheme::ShadowShade ) );
00944 
00945         palette.setBrush( state, QPalette::AlternateBase, schemeView.background( KColorScheme::AlternateBackground) );
00946         palette.setBrush( state, QPalette::Link, schemeView.foreground( KColorScheme::LinkText ) );
00947         palette.setBrush( state, QPalette::LinkVisited, schemeView.foreground( KColorScheme::VisitedText ) );
00948     }
00949 
00950     return palette;
00951 }
00952 
00953 void KGlobalSettings::Private::kdisplaySetPalette()
00954 {
00955     // Added by Sam/Harald (TT) for Mac OS X initially, but why?
00956     KConfigGroup cg( KGlobal::config(), "General" );
00957     if (cg.readEntry("nopaletteChange", false))
00958         return;
00959 
00960     if (qApp->type() == QApplication::GuiClient) {
00961         QApplication::setPalette( q->createApplicationPalette() );
00962     }
00963     emit q->kdisplayPaletteChanged();
00964     emit q->appearanceChanged();
00965 }
00966 
00967 
00968 void KGlobalSettings::Private::kdisplaySetFont()
00969 {
00970     if (qApp->type() == QApplication::GuiClient) {
00971         KGlobalSettingsData* data = KGlobalSettingsData::self();
00972 
00973         QApplication::setFont( data->font(KGlobalSettingsData::GeneralFont) );
00974         const QFont menuFont = data->font( KGlobalSettingsData::MenuFont );
00975         QApplication::setFont( menuFont, "QMenuBar" );
00976         QApplication::setFont( menuFont, "QMenu" );
00977         QApplication::setFont( menuFont, "KPopupTitle" );
00978         QApplication::setFont( data->font(KGlobalSettingsData::ToolbarFont), "QToolBar" );
00979     }
00980     emit q->kdisplayFontChanged();
00981     emit q->appearanceChanged();
00982 }
00983 
00984 
00985 void KGlobalSettings::Private::kdisplaySetStyle()
00986 {
00987     if (qApp->type() == QApplication::GuiClient) {
00988         applyGUIStyle();
00989 
00990         // Reread palette from config file.
00991         kdisplaySetPalette();
00992     }
00993 }
00994 
00995 
00996 void KGlobalSettings::Private::rereadOtherSettings()
00997 {
00998     KConfigGroup g( KGlobal::config(), "KDE-Global GUI Settings" );
00999 
01000     // Asking for hasKey we do not ask for graphicEffectsLevelDefault() that can
01001     // contain some very slow code. If we can save that time, do it. (ereslibre)
01002 
01003     if (g.hasKey("GraphicEffectsLevel")) {
01004         _graphicEffects = ((GraphicEffects) g.readEntry("GraphicEffectsLevel", QVariant((int) NoEffects)).toInt());
01005 
01006         return;
01007     }
01008 
01009     _graphicEffects = KGlobalSettings::graphicEffectsLevelDefault();
01010 }
01011 
01012 
01013 void KGlobalSettings::Private::applyCursorTheme()
01014 {
01015 #if defined(Q_WS_X11) && defined(HAVE_XCURSOR)
01016     KConfig config("kcminputrc");
01017     KConfigGroup g(&config, "Mouse");
01018 
01019     QString theme = g.readEntry("cursorTheme", QString());
01020     int size      = g.readEntry("cursorSize", -1);
01021 
01022     // Default cursor size is 16 points
01023     if (size == -1)
01024     {
01025         QApplication *app = static_cast<QApplication*>(QApplication::instance());
01026         size = app->desktop()->screen(0)->logicalDpiY() * 16 / 72;
01027     }
01028 
01029     // Note that in X11R7.1 and earlier, calling XcursorSetTheme()
01030     // with a NULL theme would cause Xcursor to use "default", but
01031     // in 7.2 and later it will cause it to revert to the theme that
01032     // was configured when the application was started.
01033     XcursorSetTheme(QX11Info::display(), theme.isNull() ?
01034                     "default" : QFile::encodeName(theme));
01035     XcursorSetDefaultSize(QX11Info::display(), size);
01036 
01037     emit q->cursorChanged();
01038 #endif
01039 }
01040 
01041 
01042 void KGlobalSettings::Private::propagateQtSettings()
01043 {
01044     KConfigGroup cg( KGlobal::config(), "KDE" );
01045 
01046     int num = cg.readEntry("CursorBlinkRate", QApplication::cursorFlashTime());
01047     if ((num != 0) && (num < 200))
01048         num = 200;
01049     if (num > 2000)
01050         num = 2000;
01051     QApplication::setCursorFlashTime(num);
01052     num = cg.readEntry("DoubleClickInterval", QApplication::doubleClickInterval());
01053     QApplication::setDoubleClickInterval(num);
01054     num = cg.readEntry("StartDragTime", QApplication::startDragTime());
01055     QApplication::setStartDragTime(num);
01056     num = cg.readEntry("StartDragDist", QApplication::startDragDistance());
01057     QApplication::setStartDragDistance(num);
01058     num = cg.readEntry("WheelScrollLines", QApplication::wheelScrollLines());
01059     QApplication::setWheelScrollLines(num);
01060 
01061     // KDE5: this seems fairly pointless
01062     emit q->settingsChanged(SETTINGS_QT);
01063 }
01064 
01065 #include "kglobalsettings.moc"

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal