00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kglobalsettings.h"
00020 #include <config.h>
00021
00022 #include <kconfig.h>
00023
00024 #include <kdebug.h>
00025 #include <kglobal.h>
00026 #include <kstandarddirs.h>
00027 #include <kcharsets.h>
00028 #include <klocale.h>
00029 #include <kprotocolinfo.h>
00030 #include <kcomponentdata.h>
00031 #include <kcolorscheme.h>
00032
00033 #ifdef Q_WS_X11
00034 #include <kstyle.h>
00035 #endif
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
00048 #include <QApplication>
00049 #include <QtDBus/QtDBus>
00050 #include <QtGui/QStyleFactory>
00051
00052
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 static QString* s_desktopPath = 0;
00078 static QString* s_autostartPath = 0;
00079 static QString* s_documentPath = 0;
00080 static QFont *_generalFont = 0;
00081 static QFont *_fixedFont = 0;
00082 static QFont *_toolBarFont = 0;
00083 static QFont *_menuFont = 0;
00084 static QFont *_windowTitleFont = 0;
00085 static QFont *_taskbarFont = 0;
00086 static QFont *_largeFont = 0;
00087 static QFont *_smallestReadableFont = 0;
00088
00089 static KGlobalSettings::GraphicEffects _graphicEffects = KGlobalSettings::NoEffects;
00090
00091 static KGlobalSettings::KMouseSettings *s_mouseSettings = 0;
00092
00093 class KGlobalSettings::Private
00094 {
00095 public:
00096 Private(KGlobalSettings *q)
00097 : q(q)
00098 {
00099 }
00100
00101 void _k_slotNotifyChange(int, int);
00102
00103 void propagateSettings(SettingsCategory category);
00104 void kdisplaySetPalette();
00105 void kdisplaySetStyle();
00106 void kdisplaySetFont();
00107 void applyGUIStyle();
00108
00120 void applyCursorTheme();
00121
00125 static void initPaths();
00129 static void rereadFontSettings();
00133 static void rereadPathSettings();
00137 static void rereadMouseSettings();
00141 static void rereadOtherSettings();
00142
00143 KGlobalSettings *q;
00144 };
00145
00146 KGlobalSettings* KGlobalSettings::self()
00147 {
00148 K_GLOBAL_STATIC(KGlobalSettings, s_self)
00149 return s_self;
00150 }
00151
00152 KGlobalSettings::KGlobalSettings()
00153 : QObject(0), d(new Private(this))
00154 {
00155 d->kdisplaySetStyle();
00156 d->kdisplaySetFont();
00157 d->propagateSettings(SETTINGS_QT);
00158
00159 QDBusConnection::sessionBus().connect( QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
00160 "notifyChange", this, SLOT(_k_slotNotifyChange(int,int)) );
00161 }
00162
00163 KGlobalSettings::~KGlobalSettings()
00164 {
00165 delete d;
00166 }
00167
00168 int KGlobalSettings::dndEventDelay()
00169 {
00170 KConfigGroup g( KGlobal::config(), "General" );
00171 return g.readEntry("StartDragDist", QApplication::startDragDistance());
00172 }
00173
00174 bool KGlobalSettings::singleClick()
00175 {
00176 KConfigGroup g( KGlobal::config(), "KDE" );
00177 return g.readEntry("SingleClick", KDE_DEFAULT_SINGLECLICK );
00178 }
00179
00180 KGlobalSettings::TearOffHandle KGlobalSettings::insertTearOffHandle()
00181 {
00182 int tearoff;
00183 bool effectsenabled;
00184 KConfigGroup g( KGlobal::config(), "KDE" );
00185 effectsenabled = g.readEntry( "EffectsEnabled", false);
00186 tearoff = g.readEntry("InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
00187 return effectsenabled ? (TearOffHandle) tearoff : Disable;
00188 }
00189
00190 bool KGlobalSettings::changeCursorOverIcon()
00191 {
00192 KConfigGroup g( KGlobal::config(), "KDE" );
00193 return g.readEntry("ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
00194 }
00195
00196 int KGlobalSettings::autoSelectDelay()
00197 {
00198 KConfigGroup g( KGlobal::config(), "KDE" );
00199 return g.readEntry("AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
00200 }
00201
00202 KGlobalSettings::Completion KGlobalSettings::completionMode()
00203 {
00204 int completion;
00205 KConfigGroup g( KGlobal::config(), "General" );
00206 completion = g.readEntry("completionMode", -1);
00207 if ((completion < (int) CompletionNone) ||
00208 (completion > (int) CompletionPopupAuto))
00209 {
00210 completion = (int) CompletionPopup;
00211 }
00212 return (Completion) completion;
00213 }
00214
00215 bool KGlobalSettings::showContextMenusOnPress ()
00216 {
00217 KConfigGroup g(KGlobal::config(), "ContextMenus");
00218 return g.readEntry("ShowOnPress", true);
00219 }
00220
00221 int KGlobalSettings::contextMenuKey ()
00222 {
00223 KConfigGroup g(KGlobal::config(), "Shortcuts");
00224 QString s = g.readEntry ("PopupMenuContext", "Menu");
00225
00226
00227
00228
00229
00230 if (s == QLatin1String("none")) {
00231 return QKeySequence()[0];
00232 }
00233
00234 const QStringList shortCuts = s.split(';');
00235
00236 if (shortCuts.count() < 1) {
00237 return QKeySequence()[0];
00238 }
00239
00240 s = shortCuts.at(0);
00241
00242 if ( s.startsWith( "default(" ) ) {
00243 s = s.mid( 8, s.length() - 9 );
00244 }
00245
00246 return QKeySequence::fromString(s)[0];
00247 }
00248
00249
00250 QColor KGlobalSettings::inactiveTitleColor()
00251 {
00252 #ifdef Q_WS_WIN
00253 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
00254 #else
00255 KConfigGroup g( KGlobal::config(), "WM" );
00256 return g.readEntry( "inactiveBackground", QColor(224, 223, 222) );
00257 #endif
00258 }
00259
00260
00261 QColor KGlobalSettings::inactiveTextColor()
00262 {
00263 #ifdef Q_WS_WIN
00264 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
00265 #else
00266 KConfigGroup g( KGlobal::config(), "WM" );
00267 return g.readEntry( "inactiveForeground", QColor(20, 19, 18) );
00268 #endif
00269 }
00270
00271
00272 QColor KGlobalSettings::activeTitleColor()
00273 {
00274 #ifdef Q_WS_WIN
00275 return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
00276 #else
00277 KConfigGroup g( KGlobal::config(), "WM" );
00278 return g.readEntry( "activeBackground", QColor(96, 148, 207));
00279 #endif
00280 }
00281
00282
00283 QColor KGlobalSettings::activeTextColor()
00284 {
00285 #ifdef Q_WS_WIN
00286 return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
00287 #else
00288 KConfigGroup g( KGlobal::config(), "WM" );
00289 return g.readEntry( "activeForeground", QColor(255, 255, 255) );
00290 #endif
00291 }
00292
00293 int KGlobalSettings::contrast()
00294 {
00295 KConfigGroup g( KGlobal::config(), "KDE" );
00296 return g.readEntry( "contrast", 7 );
00297 }
00298
00299 qreal KGlobalSettings::contrastF(const KSharedConfigPtr &config)
00300 {
00301 if (config) {
00302 KConfigGroup g( config, "KDE" );
00303 return 0.1 * g.readEntry( "contrast", 7 );
00304 }
00305 return 0.1 * (qreal)contrast();
00306 }
00307
00308 bool KGlobalSettings::shadeSortColumn()
00309 {
00310 KConfigGroup g( KGlobal::config(), "General" );
00311 return g.readEntry( "shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
00312 }
00313
00314 bool KGlobalSettings::allowDefaultBackgroundImages()
00315 {
00316 KConfigGroup g( KGlobal::config(), "General" );
00317 return g.readEntry( "allowDefaultBackgroundImages", KDE_DEFAULT_ALLOW_DEFAULT_BACKGROUND_IMAGES );
00318 }
00319
00320 QFont KGlobalSettings::generalFont()
00321 {
00322 if (_generalFont)
00323 return *_generalFont;
00324
00325 #ifdef Q_WS_MAC
00326 _generalFont = new QFont("Lucida Grande", 13);
00327 #else
00328
00329 _generalFont = new QFont("Sans Serif", 10);
00330 #endif
00331 _generalFont->setStyleHint(QFont::SansSerif);
00332
00333 KConfigGroup g( KGlobal::config(), "General" );
00334 *_generalFont = g.readEntry("font", *_generalFont);
00335
00336 return *_generalFont;
00337 }
00338
00339 QFont KGlobalSettings::fixedFont()
00340 {
00341 if (_fixedFont)
00342 return *_fixedFont;
00343
00344 #ifdef Q_WS_MAC
00345 _fixedFont = new QFont("Monaco", 10);
00346 #else
00347
00348 _fixedFont = new QFont("Monospace", 10);
00349 #endif
00350 _fixedFont->setStyleHint(QFont::TypeWriter);
00351
00352 KConfigGroup g( KGlobal::config(), "General" );
00353 *_fixedFont = g.readEntry("fixed", *_fixedFont);
00354
00355 return *_fixedFont;
00356 }
00357
00358 QFont KGlobalSettings::toolBarFont()
00359 {
00360 if(_toolBarFont)
00361 return *_toolBarFont;
00362
00363 #ifdef Q_WS_MAC
00364 _toolBarFont = new QFont("Lucida Grande", 11);
00365 #else
00366
00367 _toolBarFont = new QFont("Sans Serif", 8);
00368 #endif
00369 _toolBarFont->setStyleHint(QFont::SansSerif);
00370
00371 KConfigGroup g( KGlobal::config(), "General" );
00372 *_toolBarFont = g.readEntry("toolBarFont", *_toolBarFont);
00373
00374 return *_toolBarFont;
00375 }
00376
00377 QFont KGlobalSettings::menuFont()
00378 {
00379 if(_menuFont)
00380 return *_menuFont;
00381
00382 #ifdef Q_WS_MAC
00383 _menuFont = new QFont("Lucida Grande", 13);
00384 #else
00385
00386 _menuFont = new QFont("Sans Serif", 10);
00387 #endif
00388 _menuFont->setStyleHint(QFont::SansSerif);
00389
00390 KConfigGroup g( KGlobal::config(), "General" );
00391 *_menuFont = g.readEntry("menuFont", *_menuFont);
00392
00393 return *_menuFont;
00394 }
00395
00396 QFont KGlobalSettings::windowTitleFont()
00397 {
00398 if(_windowTitleFont)
00399 return *_windowTitleFont;
00400
00401
00402 _windowTitleFont = new QFont("Sans Serif", 9, QFont::Bold);
00403 _windowTitleFont->setStyleHint(QFont::SansSerif);
00404
00405 KConfigGroup g( KGlobal::config(), "WM" );
00406 *_windowTitleFont = g.readEntry("activeFont", *_windowTitleFont);
00407
00408 return *_windowTitleFont;
00409 }
00410
00411 QFont KGlobalSettings::taskbarFont()
00412 {
00413 if(_taskbarFont)
00414 return *_taskbarFont;
00415
00416
00417 _taskbarFont = new QFont("Sans Serif", 10);
00418 _taskbarFont->setStyleHint(QFont::SansSerif);
00419
00420 KConfigGroup g( KGlobal::config(), "General" );
00421 *_taskbarFont = g.readEntry("taskbarFont", *_taskbarFont);
00422
00423 return *_taskbarFont;
00424 }
00425
00426
00427 QFont KGlobalSettings::largeFont(const QString &text)
00428 {
00429 QFontDatabase db;
00430 QStringList fam = db.families();
00431
00432
00433 if (fam.removeAll("Arial")>0)
00434 fam.prepend("Arial");
00435 if (fam.removeAll("Verdana")>0)
00436 fam.prepend("Verdana");
00437 if (fam.removeAll("Tahoma")>0)
00438 fam.prepend("Tahoma");
00439 if (fam.removeAll("Lucida Sans")>0)
00440 fam.prepend("Lucida Sans");
00441 if (fam.removeAll("Lucidux Sans")>0)
00442 fam.prepend("Lucidux Sans");
00443 if (fam.removeAll("Nimbus Sans")>0)
00444 fam.prepend("Nimbus Sans");
00445 if (fam.removeAll("Gothic I")>0)
00446 fam.prepend("Gothic I");
00447
00448 if (_largeFont)
00449 fam.prepend(_largeFont->family());
00450
00451 for(QStringList::ConstIterator it = fam.begin();
00452 it != fam.end(); ++it)
00453 {
00454 if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
00455 {
00456 QFont font(*it);
00457 font.setPixelSize(75);
00458 QFontMetrics metrics(font);
00459 int h = metrics.height();
00460 if ((h < 60) || ( h > 90))
00461 continue;
00462
00463 bool ok = true;
00464 for(int i = 0; i < text.length(); i++)
00465 {
00466 if (!metrics.inFont(text[i]))
00467 {
00468 ok = false;
00469 break;
00470 }
00471 }
00472 if (!ok)
00473 continue;
00474
00475 font.setPointSize(48);
00476 _largeFont = new QFont(font);
00477 return *_largeFont;
00478 }
00479 }
00480 _largeFont = new QFont(KGlobalSettings::generalFont());
00481 _largeFont->setPointSize(48);
00482 return *_largeFont;
00483 }
00484
00485 QFont KGlobalSettings::smallestReadableFont()
00486 {
00487 if(_smallestReadableFont)
00488 return *_smallestReadableFont;
00489
00490
00491 _smallestReadableFont = new QFont("Sans Serif", 8);
00492 _smallestReadableFont->setStyleHint(QFont::SansSerif);
00493
00494 KConfigGroup g( KGlobal::config(), "General" );
00495 *_smallestReadableFont = g.readEntry("smallestReadableFont", *_smallestReadableFont);
00496
00497 return *_smallestReadableFont;
00498 }
00499
00500 void KGlobalSettings::Private::initPaths()
00501 {
00502
00503
00504 if ( s_desktopPath != 0 )
00505 return;
00506
00507 KGlobalSettings::self();
00508
00509 s_desktopPath = new QString();
00510 s_autostartPath = new QString();
00511 s_documentPath = new QString();
00512
00513 KConfigGroup g( KGlobal::config(), "Paths" );
00514
00515
00516 *s_desktopPath = QDir::homePath() + "/Desktop/";
00517 *s_desktopPath = g.readPathEntry( "Desktop", *s_desktopPath);
00518 *s_desktopPath = QDir::cleanPath( *s_desktopPath );
00519 if ( !s_desktopPath->endsWith('/') ) {
00520 s_desktopPath->append( QLatin1Char( '/' ) );
00521 }
00522
00523
00524 *s_autostartPath = KGlobal::dirs()->localkdedir() + "Autostart/";
00525 *s_autostartPath = g.readPathEntry( "Autostart" , *s_autostartPath);
00526 *s_autostartPath = QDir::cleanPath( *s_autostartPath );
00527 if ( !s_autostartPath->endsWith('/') ) {
00528 s_autostartPath->append( QLatin1Char( '/' ) );
00529 }
00530
00531
00532 *s_documentPath = g.readPathEntry( "Documents",
00533 #ifdef Q_WS_WIN
00534 getWin32ShellFoldersPath("Personal")
00535 #else
00536 QDir::homePath()
00537 #endif
00538 );
00539 *s_documentPath = QDir::cleanPath( *s_documentPath );
00540 if ( !s_documentPath->endsWith('/')) {
00541 s_documentPath->append( QLatin1Char( '/' ) );
00542 }
00543 }
00544
00545 void KGlobalSettings::Private::rereadFontSettings()
00546 {
00547 delete _generalFont;
00548 _generalFont = 0L;
00549 delete _fixedFont;
00550 _fixedFont = 0L;
00551 delete _menuFont;
00552 _menuFont = 0L;
00553 delete _toolBarFont;
00554 _toolBarFont = 0L;
00555 delete _windowTitleFont;
00556 _windowTitleFont = 0L;
00557 delete _taskbarFont;
00558 _taskbarFont = 0L;
00559 delete _smallestReadableFont;
00560 _smallestReadableFont = 0L;
00561 }
00562
00563 void KGlobalSettings::Private::rereadPathSettings()
00564 {
00565 delete s_autostartPath;
00566 s_autostartPath = 0L;
00567 delete s_desktopPath;
00568 s_desktopPath = 0L;
00569 delete s_documentPath;
00570 s_documentPath = 0L;
00571 }
00572
00573 KGlobalSettings::KMouseSettings & KGlobalSettings::mouseSettings()
00574 {
00575 if ( ! s_mouseSettings )
00576 {
00577 s_mouseSettings = new KMouseSettings;
00578 KMouseSettings & s = *s_mouseSettings;
00579
00580 #ifndef Q_WS_WIN
00581 KConfigGroup g( KGlobal::config(), "Mouse" );
00582 QString setting = g.readEntry("MouseButtonMapping");
00583 if (setting == "RightHanded")
00584 s.handed = KMouseSettings::RightHanded;
00585 else if (setting == "LeftHanded")
00586 s.handed = KMouseSettings::LeftHanded;
00587 else
00588 {
00589 #ifdef Q_WS_X11
00590
00591
00592
00593 s.handed = KMouseSettings::RightHanded;
00594 unsigned char map[20];
00595 int num_buttons = XGetPointerMapping(QX11Info::display(), map, 20);
00596 if( num_buttons == 2 )
00597 {
00598 if ( (int)map[0] == 1 && (int)map[1] == 2 )
00599 s.handed = KMouseSettings::RightHanded;
00600 else if ( (int)map[0] == 2 && (int)map[1] == 1 )
00601 s.handed = KMouseSettings::LeftHanded;
00602 }
00603 else if( num_buttons >= 3 )
00604 {
00605 if ( (int)map[0] == 1 && (int)map[2] == 3 )
00606 s.handed = KMouseSettings::RightHanded;
00607 else if ( (int)map[0] == 3 && (int)map[2] == 1 )
00608 s.handed = KMouseSettings::LeftHanded;
00609 }
00610 #else
00611
00612 #endif
00613 }
00614 #endif //Q_WS_WIN
00615 }
00616 #ifdef Q_WS_WIN
00617
00618 s_mouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ? KMouseSettings::LeftHanded : KMouseSettings::RightHanded);
00619 #endif
00620 return *s_mouseSettings;
00621 }
00622
00623 void KGlobalSettings::Private::rereadMouseSettings()
00624 {
00625 #ifndef Q_WS_WIN
00626 delete s_mouseSettings;
00627 s_mouseSettings = 0L;
00628 #endif
00629 }
00630
00631 QString KGlobalSettings::desktopPath()
00632 {
00633 Private::initPaths();
00634 return *s_desktopPath;
00635 }
00636
00637 QString KGlobalSettings::autostartPath()
00638 {
00639 Private::initPaths();
00640 return *s_autostartPath;
00641 }
00642
00643 QString KGlobalSettings::documentPath()
00644 {
00645 Private::initPaths();
00646 return *s_documentPath;
00647 }
00648
00649 bool KGlobalSettings::isMultiHead()
00650 {
00651 #ifdef Q_WS_WIN
00652 return GetSystemMetrics(SM_CMONITORS) > 1;
00653 #else
00654 QByteArray multiHead = qgetenv("KDE_MULTIHEAD");
00655 if (!multiHead.isEmpty()) {
00656 return (multiHead.toLower() == "true");
00657 }
00658 return false;
00659 #endif
00660 }
00661
00662 bool KGlobalSettings::wheelMouseZooms()
00663 {
00664 KConfigGroup g( KGlobal::config(), "KDE" );
00665 return g.readEntry( "WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
00666 }
00667
00668 QRect KGlobalSettings::splashScreenDesktopGeometry()
00669 {
00670 QDesktopWidget *dw = QApplication::desktop();
00671
00672 if (dw->isVirtualDesktop()) {
00673 KConfigGroup group(KGlobal::config(), "Windows");
00674 int scr = group.readEntry("Unmanaged", -3);
00675 if (group.readEntry("XineramaEnabled", true) && scr != -2) {
00676 if (scr == -3)
00677 scr = dw->screenNumber(QCursor::pos());
00678 return dw->screenGeometry(scr);
00679 } else {
00680 return dw->geometry();
00681 }
00682 } else {
00683 return dw->geometry();
00684 }
00685 }
00686
00687 QRect KGlobalSettings::desktopGeometry(const QPoint& point)
00688 {
00689 QDesktopWidget *dw = QApplication::desktop();
00690
00691 if (dw->isVirtualDesktop()) {
00692 KConfigGroup group(KGlobal::config(), "Windows");
00693 if (group.readEntry("XineramaEnabled", true) &&
00694 group.readEntry("XineramaPlacementEnabled", true)) {
00695 return dw->screenGeometry(dw->screenNumber(point));
00696 } else {
00697 return dw->geometry();
00698 }
00699 } else {
00700 return dw->geometry();
00701 }
00702 }
00703
00704 QRect KGlobalSettings::desktopGeometry(const QWidget* w)
00705 {
00706 QDesktopWidget *dw = QApplication::desktop();
00707
00708 if (dw->isVirtualDesktop()) {
00709 KConfigGroup group(KGlobal::config(), "Windows");
00710 if (group.readEntry("XineramaEnabled", true) &&
00711 group.readEntry("XineramaPlacementEnabled", true)) {
00712 if (w)
00713 return dw->screenGeometry(dw->screenNumber(w));
00714 else return dw->screenGeometry(-1);
00715 } else {
00716 return dw->geometry();
00717 }
00718 } else {
00719 return dw->geometry();
00720 }
00721 }
00722
00723 bool KGlobalSettings::showIconsOnPushButtons()
00724 {
00725 KConfigGroup g( KGlobal::config(), "KDE" );
00726 return g.readEntry("ShowIconsOnPushButtons",
00727 KDE_DEFAULT_ICON_ON_PUSHBUTTON);
00728 }
00729
00730 KGlobalSettings::GraphicEffects KGlobalSettings::graphicEffectsLevel()
00731 {
00732
00733
00734
00735 static bool _graphicEffectsInitialized = false;
00736
00737 if (!_graphicEffectsInitialized) {
00738 _graphicEffectsInitialized = true;
00739 Private::rereadOtherSettings();
00740 }
00741
00742 return _graphicEffects;
00743 }
00744
00745 KGlobalSettings::GraphicEffects KGlobalSettings::graphicEffectsLevelDefault()
00746 {
00747
00748
00749
00750 return ComplexAnimationEffects;
00751 }
00752
00753 bool KGlobalSettings::showFilePreview(const KUrl &url)
00754 {
00755 KConfigGroup g(KGlobal::config(), "PreviewSettings");
00756 QString protocol = url.protocol();
00757 bool defaultSetting = KProtocolInfo::showFilePreview( protocol );
00758 return g.readEntry(protocol, defaultSetting );
00759 }
00760
00761 bool KGlobalSettings::opaqueResize()
00762 {
00763 KConfigGroup g( KGlobal::config(), "KDE" );
00764 return g.readEntry("OpaqueResize", KDE_DEFAULT_OPAQUE_RESIZE);
00765 }
00766
00767 int KGlobalSettings::buttonLayout()
00768 {
00769 KConfigGroup g( KGlobal::config(), "KDE" );
00770 return g.readEntry("ButtonLayout", KDE_DEFAULT_BUTTON_LAYOUT);
00771 }
00772
00773 void KGlobalSettings::emitChange(ChangeType changeType, int arg)
00774 {
00775 QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange" );
00776 QList<QVariant> args;
00777 args.append(static_cast<int>(changeType));
00778 args.append(arg);
00779 message.setArguments(args);
00780 QDBusConnection::sessionBus().send(message);
00781 }
00782
00783 void KGlobalSettings::Private::_k_slotNotifyChange(int changeType, int arg)
00784 {
00785 switch(changeType) {
00786 case StyleChanged:
00787 KGlobal::config()->reparseConfiguration();
00788 kdisplaySetStyle();
00789 break;
00790
00791 case ToolbarStyleChanged:
00792 KGlobal::config()->reparseConfiguration();
00793 emit q->toolbarAppearanceChanged(arg);
00794 break;
00795
00796 case PaletteChanged:
00797 KGlobal::config()->reparseConfiguration();
00798 kdisplaySetPalette();
00799 break;
00800
00801 case FontChanged:
00802 KGlobal::config()->reparseConfiguration();
00803 KGlobalSettings::Private::rereadFontSettings();
00804 kdisplaySetFont();
00805 break;
00806
00807 case SettingsChanged: {
00808 KGlobal::config()->reparseConfiguration();
00809 rereadOtherSettings();
00810 SettingsCategory category = static_cast<SettingsCategory>(arg);
00811 if (category == SETTINGS_PATHS) {
00812 KGlobalSettings::Private::rereadPathSettings();
00813 } else if (category == SETTINGS_MOUSE) {
00814 KGlobalSettings::Private::rereadMouseSettings();
00815 }
00816 propagateSettings(category);
00817 break;
00818 }
00819 case IconChanged:
00820 QPixmapCache::clear();
00821 KGlobal::config()->reparseConfiguration();
00822 emit q->iconChanged(arg);
00823 break;
00824
00825 case CursorChanged:
00826 applyCursorTheme();
00827 break;
00828
00829 case BlockShortcuts:
00830
00831
00832 emit q->blockShortcuts(arg);
00833 break;
00834
00835 default:
00836 kWarning(101) << "Unknown type of change in KGlobalSettings::slotNotifyChange: " << changeType;
00837 }
00838 }
00839
00840
00841 QString kde_overrideStyle;
00842
00843 void KGlobalSettings::Private::applyGUIStyle()
00844 {
00845 #ifdef Q_WS_X11
00846 QString defaultStyle = KStyle::defaultStyle();
00847 #else
00848 QString defaultStyle;
00849 #endif
00850 KConfigGroup pConfig (KGlobal::config(), "General");
00851 QString styleStr = pConfig.readEntry("widgetStyle", defaultStyle);
00852
00853 if (kde_overrideStyle.isEmpty()) {
00854 if (styleStr.isEmpty())
00855 return;
00856
00857
00858
00859 QStyle* sp = QStyleFactory::create( styleStr );
00860
00861
00862 if ( !sp && styleStr != defaultStyle)
00863 sp = QStyleFactory::create( defaultStyle );
00864 if ( !sp )
00865 sp = QStyleFactory::create( QStyleFactory::keys().first() );
00866 qApp->setStyle(sp);
00867 }
00868 else
00869 qApp->setStyle(kde_overrideStyle);
00870
00871 kdisplaySetPalette();
00872 }
00873
00874 QPalette KGlobalSettings::createApplicationPalette(const KSharedConfigPtr &config)
00875 {
00876 QPalette palette;
00877
00878 QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
00879 QPalette::Disabled };
00880
00881
00882 KColorScheme schemeTooltip(QPalette::Active, KColorScheme::Tooltip, config);
00883
00884 for ( int i = 0; i < 3 ; i++ ) {
00885 QPalette::ColorGroup state = states[i];
00886 KColorScheme schemeView(state, KColorScheme::View, config);
00887 KColorScheme schemeWindow(state, KColorScheme::Window, config);
00888 KColorScheme schemeButton(state, KColorScheme::Button, config);
00889 KColorScheme schemeSelection(state, KColorScheme::Selection, config);
00890
00891 palette.setBrush( state, QPalette::WindowText, schemeWindow.foreground() );
00892 palette.setBrush( state, QPalette::Window, schemeWindow.background() );
00893 palette.setBrush( state, QPalette::Base, schemeView.background() );
00894 palette.setBrush( state, QPalette::Text, schemeView.foreground() );
00895 palette.setBrush( state, QPalette::Button, schemeButton.background() );
00896 palette.setBrush( state, QPalette::ButtonText, schemeButton.foreground() );
00897 palette.setBrush( state, QPalette::Highlight, schemeSelection.background() );
00898 palette.setBrush( state, QPalette::HighlightedText, schemeSelection.foreground() );
00899 palette.setBrush( state, QPalette::ToolTipBase, schemeTooltip.background() );
00900 palette.setBrush( state, QPalette::ToolTipText, schemeTooltip.foreground() );
00901
00902 palette.setColor( state, QPalette::Light, schemeWindow.shade( KColorScheme::LightShade ) );
00903 palette.setColor( state, QPalette::Midlight, schemeWindow.shade( KColorScheme::MidlightShade ) );
00904 palette.setColor( state, QPalette::Mid, schemeWindow.shade( KColorScheme::MidShade ) );
00905 palette.setColor( state, QPalette::Dark, schemeWindow.shade( KColorScheme::DarkShade ) );
00906 palette.setColor( state, QPalette::Shadow, schemeWindow.shade( KColorScheme::ShadowShade ) );
00907
00908 palette.setBrush( state, QPalette::AlternateBase, schemeView.background( KColorScheme::AlternateBackground) );
00909 palette.setBrush( state, QPalette::Link, schemeView.foreground( KColorScheme::LinkText ) );
00910 palette.setBrush( state, QPalette::LinkVisited, schemeView.foreground( KColorScheme::VisitedText ) );
00911 }
00912
00913 return palette;
00914 }
00915
00916 void KGlobalSettings::Private::kdisplaySetPalette()
00917 {
00918
00919 KConfigGroup cg( KGlobal::config(), "General" );
00920 if (cg.readEntry("nopaletteChange", false))
00921 return;
00922
00923 if (qApp && qApp->type() == QApplication::GuiClient) {
00924 QApplication::setPalette( q->createApplicationPalette() );
00925 emit q->kdisplayPaletteChanged();
00926 emit q->appearanceChanged();
00927 }
00928 }
00929
00930
00931 void KGlobalSettings::Private::kdisplaySetFont()
00932 {
00933 if (qApp && qApp->type() == QApplication::GuiClient) {
00934 QApplication::setFont(KGlobalSettings::generalFont());
00935 QApplication::setFont(KGlobalSettings::menuFont(), "QMenuBar");
00936 QApplication::setFont(KGlobalSettings::menuFont(), "QMenu");
00937 QApplication::setFont(KGlobalSettings::menuFont(), "KPopupTitle");
00938 QApplication::setFont(KGlobalSettings::toolBarFont(), "QToolBar");
00939
00940 #if 0
00941
00942 Q3StyleSheet* sheet = Q3StyleSheet::defaultSheet();
00943 sheet->item (QLatin1String("pre"))->setFontFamily (KGlobalSettings::fixedFont().family());
00944 sheet->item (QLatin1String("code"))->setFontFamily (KGlobalSettings::fixedFont().family());
00945 sheet->item (QLatin1String("tt"))->setFontFamily (KGlobalSettings::fixedFont().family());
00946 #endif
00947
00948 emit q->kdisplayFontChanged();
00949 emit q->appearanceChanged();
00950 }
00951 }
00952
00953
00954 void KGlobalSettings::Private::kdisplaySetStyle()
00955 {
00956 if (qApp && qApp->type() == QApplication::GuiClient) {
00957 applyGUIStyle();
00958 emit q->kdisplayStyleChanged();
00959
00960
00961 }
00962 }
00963
00964
00965 void KGlobalSettings::Private::rereadOtherSettings()
00966 {
00967 KConfigGroup g( KGlobal::config(), "KDE-Global GUI Settings" );
00968
00969
00970
00971
00972 if (g.hasKey("GraphicEffectsLevel")) {
00973 _graphicEffects = ((GraphicEffects) g.readEntry("GraphicEffectsLevel", QVariant((int) NoEffects)).toInt());
00974
00975 return;
00976 }
00977
00978 _graphicEffects = KGlobalSettings::graphicEffectsLevelDefault();
00979 }
00980
00981
00982 void KGlobalSettings::Private::applyCursorTheme()
00983 {
00984 #if defined(Q_WS_X11) && defined(HAVE_XCURSOR)
00985 KConfig config("kcminputrc");
00986 KConfigGroup g(&config, "Mouse");
00987
00988 QString theme = g.readEntry("cursorTheme", QString());
00989 int size = g.readEntry("cursorSize", -1);
00990
00991
00992 if (size == -1)
00993 {
00994 QApplication *app = static_cast<QApplication*>(QApplication::instance());
00995 size = app->desktop()->screen(0)->logicalDpiY() * 16 / 72;
00996 }
00997
00998
00999
01000
01001
01002 XcursorSetTheme(QX11Info::display(), theme.isNull() ?
01003 "default" : QFile::encodeName(theme));
01004 XcursorSetDefaultSize(QX11Info::display(), size);
01005
01006 emit q->cursorChanged();
01007 #endif
01008 }
01009
01010
01011 void KGlobalSettings::Private::propagateSettings(SettingsCategory arg)
01012 {
01013 KConfigGroup cg( KGlobal::config(), "KDE" );
01014
01015 int num = cg.readEntry("CursorBlinkRate", QApplication::cursorFlashTime());
01016 if ((num != 0) && (num < 200))
01017 num = 200;
01018 if (num > 2000)
01019 num = 2000;
01020 QApplication::setCursorFlashTime(num);
01021 num = cg.readEntry("DoubleClickInterval", QApplication::doubleClickInterval());
01022 QApplication::setDoubleClickInterval(num);
01023 num = cg.readEntry("StartDragTime", QApplication::startDragTime());
01024 QApplication::setStartDragTime(num);
01025 num = cg.readEntry("StartDragDist", QApplication::startDragDistance());
01026 QApplication::setStartDragDistance(num);
01027 num = cg.readEntry("WheelScrollLines", QApplication::wheelScrollLines());
01028 QApplication::setWheelScrollLines(num);
01029
01030 bool b = cg.readEntry("EffectAnimateMenu", false);
01031 QApplication::setEffectEnabled( Qt::UI_AnimateMenu, b);
01032 b = cg.readEntry("EffectFadeMenu", false);
01033 QApplication::setEffectEnabled( Qt::UI_FadeMenu, b);
01034 b = cg.readEntry("EffectAnimateCombo", false);
01035 QApplication::setEffectEnabled( Qt::UI_AnimateCombo, b);
01036 b = cg.readEntry("EffectAnimateTooltip", false);
01037 QApplication::setEffectEnabled( Qt::UI_AnimateTooltip, b);
01038 b = cg.readEntry("EffectFadeTooltip", false);
01039 QApplication::setEffectEnabled( Qt::UI_FadeTooltip, b);
01040
01041
01042
01043 emit q->settingsChanged(arg);
01044 }
01045
01046 #include "kglobalsettings.moc"