• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

kglobalsettings.cpp
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2000 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 #include "config.h"
00019 #include "kglobalsettings.h"
00020 
00021 #include <tqdir.h>
00022 #include <tqpixmap.h>
00023 #include <tqfontdatabase.h>
00024 #include <tqcursor.h>
00025 
00026 #include <kconfig.h>
00027 #include <ksimpleconfig.h>
00028 #include <kapplication.h>
00029 
00030 #include <kipc.h>
00031 
00032 #ifdef Q_WS_WIN
00033 #include <windows.h>
00034 #include "qt_windows.h"
00035 #include <win32_utils.h>
00036 static QRgb qt_colorref2qrgb(COLORREF col)
00037 {
00038     return tqRgb(GetRValue(col),GetGValue(col),GetBValue(col));
00039 }
00040 #endif
00041 
00042 #include <kdebug.h>
00043 #include <kglobal.h>
00044 #include <kshortcut.h>
00045 #include <kstandarddirs.h>
00046 #include <kcharsets.h>
00047 #include <kaccel.h>
00048 #include <klocale.h>
00049 #include <tqfontinfo.h>
00050 #include <stdlib.h>
00051 #include <kprotocolinfo.h>
00052 
00053 #include <tqtextcodec.h>
00054 #include <tqtextstream.h>
00055 #include <tqfile.h>
00056 
00057 #ifdef Q_WS_X11
00058 #include <X11/Xlib.h>
00059 #endif
00060 
00061 TQString* KGlobalSettings::s_desktopPath = 0;
00062 TQString* KGlobalSettings::s_autostartPath = 0;
00063 TQString* KGlobalSettings::s_trashPath = 0;
00064 TQString* KGlobalSettings::s_documentPath = 0;
00065 TQString* KGlobalSettings::s_videosPath = 0;
00066 TQString* KGlobalSettings::s_musicPath = 0;
00067 TQString* KGlobalSettings::s_downloadPath = 0;
00068 TQString* KGlobalSettings::s_picturesPath = 0;
00069 TQString* KGlobalSettings::s_templatesPath = 0;
00070 TQString* KGlobalSettings::s_publicSharePath = 0;
00071 TQFont *KGlobalSettings::_generalFont = 0;
00072 TQFont *KGlobalSettings::_fixedFont = 0;
00073 TQFont *KGlobalSettings::_toolBarFont = 0;
00074 TQFont *KGlobalSettings::_menuFont = 0;
00075 TQFont *KGlobalSettings::_windowTitleFont = 0;
00076 TQFont *KGlobalSettings::_taskbarFont = 0;
00077 TQFont *KGlobalSettings::_largeFont = 0;
00078 TQColor *KGlobalSettings::_trinity4Blue = 0;
00079 TQColor *KGlobalSettings::_inactiveBackground = 0;
00080 TQColor *KGlobalSettings::_inactiveForeground = 0;
00081 TQColor *KGlobalSettings::_activeBackground = 0;
00082 TQColor *KGlobalSettings::_buttonBackground = 0;
00083 TQColor *KGlobalSettings::_selectBackground = 0;
00084 TQColor *KGlobalSettings::_linkColor = 0;
00085 TQColor *KGlobalSettings::_visitedLinkColor = 0;
00086 TQColor *KGlobalSettings::alternateColor = 0;
00087 
00088 KGlobalSettings::KMouseSettings *KGlobalSettings::s_mouseSettings = 0;
00089 
00090 // Helper function for reading xdg user dirs.
00091 // Returns sane values in case the user dir file can't be read
00092 static void readXdgUserDirs(TQString *desktop, TQString *documents, TQString *download, TQString *music,
00093                      TQString *pictures, TQString *publicShare, TQString *templates, TQString *videos)
00094 {
00095     TQFile dirsFile(TQDir::homeDirPath() + "/.config/user-dirs.dirs");
00096     if (dirsFile.open(IO_ReadOnly))
00097     {
00098         // set the codec for the current locale
00099         TQTextStream stream(&dirsFile);
00100         stream.setCodec(TQTextCodec::codecForLocale());
00101 
00102         while (!stream.atEnd())
00103         {
00104             TQString line = stream.readLine();
00105             if (line.startsWith("XDG_DESKTOP_DIR="))
00106             {
00107                 *desktop = line.remove("XDG_DESKTOP_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00108             }
00109             else if (line.startsWith("XDG_DOCUMENTS_DIR="))
00110             {
00111                 *documents = line.remove("XDG_DOCUMENTS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00112             }
00113             else if (line.startsWith("XDG_DOWNLOAD_DIR="))
00114             {
00115                 *download = line.remove("XDG_DOWNLOAD_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00116             }
00117             else if (line.startsWith("XDG_MUSIC_DIR="))
00118             {
00119                 *music = line.remove("XDG_MUSIC_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00120             }
00121             else if (line.startsWith("XDG_PICTURES_DIR="))
00122             {
00123                 *pictures = line.remove("XDG_PICTURES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00124             }
00125             else if (line.startsWith("XDG_PUBLICSHARE_DIR="))
00126             {
00127                 *publicShare = line.remove("XDG_PUBLICSHARE_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00128             }
00129             else if (line.startsWith("XDG_TEMPLATES_DIR="))
00130             {
00131                 *templates = line.remove("XDG_TEMPLATES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00132             }
00133             else if (line.startsWith("XDG_VIDEOS_DIR="))
00134             {
00135                 *videos = line.remove("XDG_VIDEOS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
00136             }
00137         }
00138         dirsFile.close();
00139     }
00140 
00141     // Use sane values in case some paths are missing
00142     if (desktop->isEmpty())
00143     {
00144         *desktop = TQDir::homeDirPath() + "/" + "Desktop" + "/";
00145         if (!TQDir(*desktop).exists())
00146         {
00147             *desktop = TQDir::homeDirPath() + "/" + i18n("Desktop") + "/";
00148         }
00149     }
00150     if (documents->isEmpty())
00151     {
00152         *documents = TQDir::homeDirPath() + "/" + "Documents" + "/";
00153         if (!TQDir(*documents).exists())
00154         {
00155             *documents = TQDir::homeDirPath() + "/" + i18n("Documents") + "/";
00156         }
00157     }
00158     if (download->isEmpty())
00159     {
00160         *download = TQDir::homeDirPath() + "/" + "Downloads" + "/";
00161         if (!TQDir(*download).exists())
00162         {
00163             *download = TQDir::homeDirPath() + "/" + i18n("Downloads") + "/";
00164         }
00165     }
00166     if (music->isEmpty())
00167     {
00168         *music = TQDir::homeDirPath() + "/" + "Music" + "/";
00169         if (!TQDir(*music).exists())
00170         {
00171             *music = TQDir::homeDirPath() + "/" + i18n("Music") + "/";
00172         }
00173     }
00174     if (pictures->isEmpty())
00175     {
00176         *pictures = TQDir::homeDirPath() + "/" + "Pictures" + "/";
00177         if (!TQDir(*pictures).exists())
00178         {
00179             *pictures = TQDir::homeDirPath() + "/" + i18n("Pictures") + "/";
00180         }
00181     }
00182     if (publicShare->isEmpty())
00183     {
00184         *publicShare = TQDir::homeDirPath() + "/" + "Public" + "/";
00185         if (!TQDir(*publicShare).exists())
00186         {
00187             *publicShare = TQDir::homeDirPath() + "/" + i18n("Public") + "/";
00188         }
00189     }
00190     if (templates->isEmpty())
00191     {
00192         *templates = TQDir::homeDirPath() + "/" + "Templates" + "/";
00193         if (!TQDir(*templates).exists())
00194         {
00195             *templates = TQDir::homeDirPath() + "/" + i18n("Templates") + "/";
00196         }
00197     }
00198     if (videos->isEmpty())
00199     {
00200         *videos = TQDir::homeDirPath() + "/" + "Videos" + "/";
00201         if (!TQDir(*videos).exists())
00202         {
00203             *videos = TQDir::homeDirPath() + "/" + i18n("Videos") + "/";
00204         }
00205     }
00206 }
00207 
00208 static void checkAndCreateXdgFolder(const TQString &folder, const TQString &path, KConfig *config)
00209 {
00210     bool pathOk = true;
00211     if (!TQDir(path).exists())
00212     {
00213         if (!KStandardDirs::makeDir(path))
00214         {
00215             pathOk = false;
00216         }
00217     }
00218 
00219     if (pathOk)
00220     {
00221         config->writePathEntry(folder, '"' + path + '"', true, false, false, false );
00222     }
00223 }
00224 
00225 int KGlobalSettings::dndEventDelay()
00226 {
00227     KConfigGroup g( KGlobal::config(), "General" );
00228     return g.readNumEntry("StartDragDist", TQApplication::startDragDistance());
00229 }
00230 
00231 bool KGlobalSettings::singleClick()
00232 {
00233     KConfigGroup g( KGlobal::config(), "KDE" );
00234     return g.readBoolEntry("SingleClick", KDE_DEFAULT_SINGLECLICK);
00235 }
00236 
00237 bool KGlobalSettings::iconUseRoundedRect()
00238 {
00239     KConfigGroup g( KGlobal::config(), "KDE" );
00240     return g.readBoolEntry("IconUseRoundedRect", KDE_DEFAULT_ICONTEXTROUNDED);
00241 }
00242 
00243 KGlobalSettings::TearOffHandle KGlobalSettings::insertTearOffHandle()
00244 {
00245     int tearoff;
00246     bool effectsenabled;
00247     KConfigGroup g( KGlobal::config(), "KDE" );
00248     effectsenabled = g.readBoolEntry( "EffectsEnabled", false);
00249     tearoff = g.readNumEntry("InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
00250     return effectsenabled ? (TearOffHandle) tearoff : Disable;
00251 }
00252 
00253 bool KGlobalSettings::changeCursorOverIcon()
00254 {
00255     KConfigGroup g( KGlobal::config(), "KDE" );
00256     return g.readBoolEntry("ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
00257 }
00258 
00259 bool KGlobalSettings::visualActivate()
00260 {
00261     KConfigGroup g( KGlobal::config(), "KDE" );
00262     return g.readBoolEntry("VisualActivate", KDE_DEFAULT_VISUAL_ACTIVATE);
00263 }
00264 
00265 unsigned int KGlobalSettings::visualActivateSpeed()
00266 {
00267     KConfigGroup g( KGlobal::config(), "KDE" );
00268     return
00269         g.readNumEntry(
00270             "VisualActivateSpeed",
00271             KDE_DEFAULT_VISUAL_ACTIVATE_SPEED
00272         );
00273 }
00274 
00275 
00276 
00277 int KGlobalSettings::autoSelectDelay()
00278 {
00279     KConfigGroup g( KGlobal::config(), "KDE" );
00280     return g.readNumEntry("AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
00281 }
00282 
00283 KGlobalSettings::Completion KGlobalSettings::completionMode()
00284 {
00285     int completion;
00286     KConfigGroup g( KGlobal::config(), "General" );
00287     completion = g.readNumEntry("completionMode", -1);
00288     if ((completion < (int) CompletionNone) ||
00289         (completion > (int) CompletionPopupAuto))
00290       {
00291         completion = (int) CompletionPopup; // Default
00292       }
00293   return (Completion) completion;
00294 }
00295 
00296 bool KGlobalSettings::showContextMenusOnPress ()
00297 {
00298     KConfigGroup g(KGlobal::config(), "ContextMenus");
00299     return g.readBoolEntry("ShowOnPress", true);
00300 }
00301 
00302 int KGlobalSettings::contextMenuKey ()
00303 {
00304     KConfigGroup g(KGlobal::config(), "Shortcuts");
00305     KShortcut cut (g.readEntry ("PopupMenuContext", "Menu"));
00306     return cut.keyCodeQt();
00307 }
00308 
00309 TQColor KGlobalSettings::toolBarHighlightColor()
00310 {
00311     initColors();
00312     KConfigGroup g( KGlobal::config(), "Toolbar style" );
00313     return g.readColorEntry("HighlightColor", _trinity4Blue);
00314 }
00315 
00316 TQColor KGlobalSettings::inactiveTitleColor()
00317 {
00318 #ifdef Q_WS_WIN
00319     return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
00320 #else
00321     if (!_inactiveBackground)
00322         _inactiveBackground = new TQColor(157, 170, 186);
00323     KConfigGroup g( KGlobal::config(), "WM" );
00324     return g.readColorEntry( "inactiveBackground", _inactiveBackground );
00325 #endif
00326 }
00327 
00328 TQColor KGlobalSettings::inactiveTextColor()
00329 {
00330 #ifdef Q_WS_WIN
00331     return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
00332 #else
00333     if (!_inactiveForeground)
00334        _inactiveForeground = new TQColor(221,221,221);
00335     KConfigGroup g( KGlobal::config(), "WM" );
00336     return g.readColorEntry( "inactiveForeground", _inactiveForeground );
00337 #endif
00338 }
00339 
00340 TQColor KGlobalSettings::activeTitleColor()
00341 {
00342 #ifdef Q_WS_WIN
00343     return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
00344 #else
00345     initColors();
00346     if (!_activeBackground)
00347       _activeBackground = new TQColor(65,142,220);
00348     KConfigGroup g( KGlobal::config(), "WM" );
00349     return g.readColorEntry( "activeBackground", _activeBackground);
00350 #endif
00351 }
00352 
00353 TQColor KGlobalSettings::activeTextColor()
00354 {
00355 #ifdef Q_WS_WIN
00356     return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
00357 #else
00358     KConfigGroup g( KGlobal::config(), "WM" );
00359     return g.readColorEntry( "activeForeground", tqwhiteptr );
00360 #endif
00361 }
00362 
00363 int KGlobalSettings::contrast()
00364 {
00365     KConfigGroup g( KGlobal::config(), "KDE" );
00366     return g.readNumEntry( "contrast", 7 );
00367 }
00368 
00369 TQColor KGlobalSettings::buttonBackground()
00370 {
00371     if (!_buttonBackground)
00372       _buttonBackground = new TQColor(221,223,228);
00373     KConfigGroup g( KGlobal::config(), "General" );
00374     return g.readColorEntry( "buttonBackground", _buttonBackground );
00375 }
00376 
00377 TQColor KGlobalSettings::buttonTextColor()
00378 {
00379     KConfigGroup g( KGlobal::config(), "General" );
00380     return g.readColorEntry( "buttonForeground", tqblackptr );
00381 }
00382 
00383 // IMPORTANT:
00384 //  This function should be kept in sync with
00385 //   KApplication::kdisplaySetPalette()
00386 TQColor KGlobalSettings::baseColor()
00387 {
00388     KConfigGroup g( KGlobal::config(), "General" );
00389     return g.readColorEntry( "windowBackground", tqwhiteptr );
00390 }
00391 
00392 // IMPORTANT:
00393 //  This function should be kept in sync with
00394 //   KApplication::kdisplaySetPalette()
00395 TQColor KGlobalSettings::textColor()
00396 {
00397     KConfigGroup g( KGlobal::config(), "General" );
00398     return g.readColorEntry( "windowForeground", tqblackptr );
00399 }
00400 
00401 // IMPORTANT:
00402 //  This function should be kept in sync with
00403 //   KApplication::kdisplaySetPalette()
00404 TQColor KGlobalSettings::highlightedTextColor()
00405 {
00406     KConfigGroup g( KGlobal::config(), "General" );
00407     return g.readColorEntry( "selectForeground", tqwhiteptr );
00408 }
00409 
00410 // IMPORTANT:
00411 //  This function should be kept in sync with
00412 //   KApplication::kdisplaySetPalette()
00413 TQColor KGlobalSettings::highlightColor()
00414 {
00415     initColors();
00416     if (!_selectBackground)
00417         _selectBackground = new TQColor(103,141,178);
00418     KConfigGroup g( KGlobal::config(), "General" );
00419     return g.readColorEntry( "selectBackground", _selectBackground );
00420 }
00421 
00422 TQColor KGlobalSettings::alternateBackgroundColor()
00423 {
00424     initColors();
00425     KConfigGroup g( KGlobal::config(), "General" );
00426     *alternateColor = calculateAlternateBackgroundColor( baseColor() );
00427     return g.readColorEntry( "alternateBackground", alternateColor );
00428 }
00429 
00430 TQColor KGlobalSettings::calculateAlternateBackgroundColor(const TQColor& base)
00431 {
00432     if (base == Qt::white)
00433         return TQColor(238,246,255);
00434     else
00435     {
00436         int h, s, v;
00437         base.hsv( &h, &s, &v );
00438         if (v > 128)
00439             return base.dark(106);
00440         else if (base != Qt::black)
00441             return base.light(110);
00442 
00443         return TQColor(32,32,32);
00444     }
00445 }
00446 
00447 bool KGlobalSettings::shadeSortColumn()
00448 {
00449     KConfigGroup g( KGlobal::config(), "General" );
00450     return g.readBoolEntry( "shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
00451 }
00452 
00453 TQColor KGlobalSettings::linkColor()
00454 {
00455     initColors();
00456     if (!_linkColor)
00457         _linkColor = new TQColor(0,0,238);
00458     KConfigGroup g( KGlobal::config(), "General" );
00459     return g.readColorEntry( "linkColor", _linkColor );
00460 }
00461 
00462 TQColor KGlobalSettings::visitedLinkColor()
00463 {
00464     if (!_visitedLinkColor)
00465         _visitedLinkColor = new TQColor(82,24,139);
00466     KConfigGroup g( KGlobal::config(), "General" );
00467     return g.readColorEntry( "visitedLinkColor", _visitedLinkColor );
00468 }
00469 
00470 TQFont KGlobalSettings::generalFont()
00471 {
00472     if (_generalFont)
00473         return *_generalFont;
00474 
00475     // Sync default with kdebase/kcontrol/fonts/fonts.cpp
00476     _generalFont = new TQFont("Sans Serif", 10);
00477     _generalFont->setPointSize(10);
00478     _generalFont->setStyleHint(TQFont::SansSerif);
00479 
00480     KConfigGroup g( KGlobal::config(), "General" );
00481     *_generalFont = g.readFontEntry("font", _generalFont);
00482 
00483     return *_generalFont;
00484 }
00485 
00486 TQFont KGlobalSettings::fixedFont()
00487 {
00488     if (_fixedFont)
00489         return *_fixedFont;
00490 
00491     // Sync default with kdebase/kcontrol/fonts/fonts.cpp
00492     _fixedFont = new TQFont("Monospace", 10);
00493     _fixedFont->setPointSize(10);
00494     _fixedFont->setStyleHint(TQFont::TypeWriter);
00495 
00496     KConfigGroup g( KGlobal::config(), "General" );
00497     *_fixedFont = g.readFontEntry("fixed", _fixedFont);
00498 
00499     return *_fixedFont;
00500 }
00501 
00502 TQFont KGlobalSettings::toolBarFont()
00503 {
00504     if(_toolBarFont)
00505         return *_toolBarFont;
00506 
00507     // Sync default with kdebase/kcontrol/fonts/fonts.cpp
00508     _toolBarFont = new TQFont("Sans Serif", 10);
00509     _toolBarFont->setPointSize(10);
00510     _toolBarFont->setStyleHint(TQFont::SansSerif);
00511 
00512     KConfigGroup g( KGlobal::config(), "General" );
00513     *_toolBarFont = g.readFontEntry("toolBarFont", _toolBarFont);
00514 
00515     return *_toolBarFont;
00516 }
00517 
00518 TQFont KGlobalSettings::menuFont()
00519 {
00520     if(_menuFont)
00521         return *_menuFont;
00522 
00523     // Sync default with kdebase/kcontrol/fonts/fonts.cpp
00524     _menuFont = new TQFont("Sans Serif", 10);
00525     _menuFont->setPointSize(10);
00526     _menuFont->setStyleHint(TQFont::SansSerif);
00527 
00528     KConfigGroup g( KGlobal::config(), "General" );
00529     *_menuFont = g.readFontEntry("menuFont", _menuFont);
00530 
00531     return *_menuFont;
00532 }
00533 
00534 TQFont KGlobalSettings::windowTitleFont()
00535 {
00536     if(_windowTitleFont)
00537         return *_windowTitleFont;
00538 
00539     // Sync default with kdebase/kcontrol/fonts/fonts.cpp
00540     _windowTitleFont = new TQFont("Sans Serif", 9, TQFont::Bold);
00541     _windowTitleFont->setPointSize(10);
00542     _windowTitleFont->setStyleHint(TQFont::SansSerif);
00543 
00544     KConfigGroup g( KGlobal::config(), "WM" );
00545     *_windowTitleFont = g.readFontEntry("activeFont", _windowTitleFont); // inconsistency
00546 
00547     return *_windowTitleFont;
00548 }
00549 
00550 TQFont KGlobalSettings::taskbarFont()
00551 {
00552     if(_taskbarFont)
00553         return *_taskbarFont;
00554 
00555     // Sync default with kdebase/kcontrol/fonts/fonts.cpp
00556     _taskbarFont = new TQFont("Sans Serif", 10);
00557     _taskbarFont->setPointSize(10);
00558     _taskbarFont->setStyleHint(TQFont::SansSerif);
00559 
00560     KConfigGroup g( KGlobal::config(), "General" );
00561     *_taskbarFont = g.readFontEntry("taskbarFont", _taskbarFont);
00562 
00563     return *_taskbarFont;
00564 }
00565 
00566 
00567 TQFont KGlobalSettings::largeFont(const TQString &text)
00568 {
00569     TQFontDatabase db;
00570     TQStringList fam = db.families();
00571 
00572     // Move a bunch of preferred fonts to the front.
00573     if (fam.remove("Arial"))
00574        fam.prepend("Arial");
00575     if (fam.remove("Verdana"))
00576        fam.prepend("Verdana");
00577     if (fam.remove("Tahoma"))
00578        fam.prepend("Tahoma");
00579     if (fam.remove("Lucida Sans"))
00580        fam.prepend("Lucida Sans");
00581     if (fam.remove("Lucidux Sans"))
00582        fam.prepend("Lucidux Sans");
00583     if (fam.remove("Nimbus Sans"))
00584        fam.prepend("Nimbus Sans");
00585     if (fam.remove("Gothic I"))
00586        fam.prepend("Gothic I");
00587 
00588     if (_largeFont)
00589         fam.prepend(_largeFont->family());
00590 
00591     for(TQStringList::ConstIterator it = fam.begin();
00592         it != fam.end(); ++it)
00593     {
00594         if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
00595         {
00596             TQFont font(*it);
00597             font.setPixelSize(75);
00598             TQFontMetrics metrics(font);
00599             int h = metrics.height();
00600             if ((h < 60) || ( h > 90))
00601                 continue;
00602 
00603             bool ok = true;
00604             for(unsigned int i = 0; i < text.length(); i++)
00605             {
00606                 if (!metrics.inFont(text[i]))
00607                 {
00608                     ok = false;
00609                     break;
00610                 }
00611             }
00612             if (!ok)
00613                 continue;
00614 
00615             font.setPointSize(48);
00616             _largeFont = new TQFont(font);
00617             return *_largeFont;
00618         }
00619     }
00620     _largeFont = new TQFont(KGlobalSettings::generalFont());
00621     _largeFont->setPointSize(48);
00622     return *_largeFont;
00623 }
00624 
00625 void KGlobalSettings::initStatic()
00626 {
00627     // The method is primarily to ensure backward compatibility of the API.
00628     // Don't put anything else here.
00629     initPaths();
00630 }
00631 
00632 void KGlobalSettings::initPaths()
00633 {
00634     if (s_desktopPath)
00635     {
00636       return;
00637     }
00638 
00639     s_autostartPath = new TQString();
00640     s_trashPath = new TQString();
00641     s_desktopPath = new TQString();
00642     s_documentPath = new TQString();
00643     s_downloadPath = new TQString();
00644     s_musicPath = new TQString();
00645     s_picturesPath = new TQString();
00646     s_publicSharePath = new TQString();
00647     s_templatesPath = new TQString();
00648     s_videosPath = new TQString();
00649 
00650     KConfigGroup g( KGlobal::config(), "Paths" );
00651 
00652     // Read xdg folder paths
00653     readXdgUserDirs(s_desktopPath, s_documentPath, s_downloadPath, s_musicPath,
00654                     s_picturesPath, s_publicSharePath, s_templatesPath, s_videosPath);
00655 
00656     *s_desktopPath = TQDir::cleanDirPath(*s_desktopPath);
00657     if (!s_desktopPath->endsWith("/"))
00658       s_desktopPath->append('/');
00659 
00660     *s_documentPath = TQDir::cleanDirPath(*s_documentPath);
00661     if (!s_documentPath->endsWith("/"))
00662       s_documentPath->append('/');
00663 
00664     *s_downloadPath = TQDir::cleanDirPath(*s_downloadPath);
00665     if (!s_downloadPath->endsWith("/"))
00666       s_downloadPath->append('/');
00667 
00668     *s_musicPath = TQDir::cleanDirPath(*s_musicPath);
00669     if (!s_musicPath->endsWith("/"))
00670       s_musicPath->append('/');
00671 
00672     *s_picturesPath = TQDir::cleanDirPath(*s_picturesPath);
00673     if (!s_picturesPath->endsWith("/"))
00674       s_picturesPath->append('/');
00675 
00676     *s_publicSharePath = TQDir::cleanDirPath(*s_publicSharePath);
00677     if (!s_publicSharePath->endsWith("/"))
00678       s_publicSharePath->append('/');
00679 
00680     *s_templatesPath = TQDir::cleanDirPath(*s_templatesPath);
00681     if (!s_templatesPath->endsWith("/"))
00682       s_templatesPath->append('/');
00683 
00684     *s_videosPath = TQDir::cleanDirPath(*s_videosPath);
00685     if (!s_videosPath->endsWith("/"))
00686       s_videosPath->append('/');
00687 
00688     // Trash Path - TODO remove in KDE4 (kio_trash can't use it for interoperability reasons)
00689     *s_trashPath = *s_desktopPath + i18n("Trash") + "/";
00690     *s_trashPath = g.readPathEntry( "Trash" , *s_trashPath);
00691     *s_trashPath = TQDir::cleanDirPath( *s_trashPath );
00692     if ( !s_trashPath->endsWith("/") )
00693       s_trashPath->append('/');
00694     // We need to save it in any case, in case the language changes later on,
00695     if ( !g.hasKey( "Trash" ) )
00696     {
00697       g.writePathEntry( "Trash", *s_trashPath, true, true );
00698       g.sync();
00699     }
00700 
00701     // Create folders if they do not exists.
00702     KConfig *xdgconfig = new KConfig(TQDir::homeDirPath()+"/.config/user-dirs.dirs");
00703     checkAndCreateXdgFolder("XDG_DESKTOP_DIR", *s_desktopPath, xdgconfig);
00704     checkAndCreateXdgFolder("XDG_DOCUMENTS_DIR", *s_documentPath, xdgconfig);
00705     checkAndCreateXdgFolder("XDG_DOWNLOAD_DIR", *s_downloadPath, xdgconfig);
00706     checkAndCreateXdgFolder("XDG_MUSIC_DIR", *s_musicPath, xdgconfig);
00707     checkAndCreateXdgFolder("XDG_PICTURES_DIR", *s_picturesPath, xdgconfig);
00708     checkAndCreateXdgFolder("XDG_PUBLICSHARE_DIR", *s_publicSharePath, xdgconfig);
00709     checkAndCreateXdgFolder("XDG_TEMPLATES_DIR", *s_templatesPath, xdgconfig);
00710     checkAndCreateXdgFolder("XDG_VIDEOS_DIR", *s_videosPath, xdgconfig);
00711     xdgconfig->sync();
00712 
00713     // Autostart Path
00714     *s_autostartPath = KGlobal::dirs()->localkdedir() + "Autostart/";
00715     *s_autostartPath = g.readPathEntry( "Autostart" , *s_autostartPath);
00716     *s_autostartPath = TQDir::cleanDirPath( *s_autostartPath );
00717     if (!s_autostartPath->endsWith("/"))
00718     {
00719       s_autostartPath->append('/');
00720     }
00721     if (!TQDir(*s_autostartPath).exists())
00722     {
00723       KStandardDirs::makeDir(*s_autostartPath);
00724     }
00725 
00726     // Make sure this app gets the notifications about those paths
00727     if (kapp)
00728         kapp->addKipcEventMask(KIPC::SettingsChanged);
00729 }
00730 
00731 void KGlobalSettings::initColors()
00732 {
00733     if (!_trinity4Blue) {
00734       if (TQPixmap::defaultDepth() > 8)
00735         _trinity4Blue = new TQColor(103,141,178);
00736       else
00737         _trinity4Blue = new TQColor(0, 0, 192);
00738     }
00739     if (!alternateColor)
00740       alternateColor = new TQColor(237, 244, 249);
00741 }
00742 
00743 void KGlobalSettings::rereadFontSettings()
00744 {
00745     delete _generalFont;
00746     _generalFont = 0L;
00747     delete _fixedFont;
00748     _fixedFont = 0L;
00749     delete _menuFont;
00750     _menuFont = 0L;
00751     delete _toolBarFont;
00752     _toolBarFont = 0L;
00753     delete _windowTitleFont;
00754     _windowTitleFont = 0L;
00755     delete _taskbarFont;
00756     _taskbarFont = 0L;
00757 }
00758 
00759 void KGlobalSettings::rereadPathSettings()
00760 {
00761     kdDebug() << "KGlobalSettings::rereadPathSettings" << endl;
00762     delete s_autostartPath;
00763     s_autostartPath = 0L;
00764     delete s_trashPath;
00765     s_trashPath = 0L;
00766     delete s_desktopPath;
00767     s_desktopPath = 0L;
00768     delete s_documentPath;
00769     s_documentPath = 0L;
00770     delete s_downloadPath;
00771     s_downloadPath = 0L;
00772     delete s_musicPath;
00773     s_musicPath = 0L;
00774     delete s_picturesPath;
00775     s_picturesPath = 0L;
00776     delete s_publicSharePath;
00777     s_publicSharePath = 0L;
00778     delete s_templatesPath;
00779     s_templatesPath = 0L;
00780     delete s_videosPath;
00781     s_videosPath = 0L;
00782 }
00783 
00784 KGlobalSettings::KMouseSettings & KGlobalSettings::mouseSettings()
00785 {
00786     if ( ! s_mouseSettings )
00787     {
00788         s_mouseSettings = new KMouseSettings;
00789         KMouseSettings & s = *s_mouseSettings; // for convenience
00790 
00791 #ifndef Q_WS_WIN
00792         KConfigGroup g( KGlobal::config(), "Mouse" );
00793         TQString setting = g.readEntry("MouseButtonMapping");
00794         if (setting == "RightHanded")
00795             s.handed = KMouseSettings::RightHanded;
00796         else if (setting == "LeftHanded")
00797             s.handed = KMouseSettings::LeftHanded;
00798         else
00799         {
00800 #ifdef Q_WS_X11
00801             // get settings from X server
00802             // This is a simplified version of the code in input/mouse.cpp
00803             // Keep in sync !
00804             s.handed = KMouseSettings::RightHanded;
00805             unsigned char map[20];
00806             int num_buttons = XGetPointerMapping(kapp->getDisplay(), map, 20);
00807             if( num_buttons == 2 )
00808             {
00809                 if ( (int)map[0] == 1 && (int)map[1] == 2 )
00810                     s.handed = KMouseSettings::RightHanded;
00811                 else if ( (int)map[0] == 2 && (int)map[1] == 1 )
00812                     s.handed = KMouseSettings::LeftHanded;
00813             }
00814             else if( num_buttons >= 3 )
00815             {
00816                 if ( (int)map[0] == 1 && (int)map[2] == 3 )
00817                     s.handed = KMouseSettings::RightHanded;
00818                 else if ( (int)map[0] == 3 && (int)map[2] == 1 )
00819                     s.handed = KMouseSettings::LeftHanded;
00820             }
00821 #else
00822         // FIXME(E): Implement in Qt Embedded
00823 #endif
00824         }
00825 #endif //Q_WS_WIN
00826     }
00827 #ifdef Q_WS_WIN
00828     //not cached
00829     s_mouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ? KMouseSettings::LeftHanded : KMouseSettings::RightHanded);
00830 #endif
00831     return *s_mouseSettings;
00832 }
00833 
00834 void KGlobalSettings::rereadMouseSettings()
00835 {
00836 #ifndef Q_WS_WIN
00837     delete s_mouseSettings;
00838     s_mouseSettings = 0L;
00839 #endif
00840 }
00841 
00842 bool KGlobalSettings::isMultiHead()
00843 {
00844 #ifdef Q_WS_WIN
00845     return GetSystemMetrics(SM_CMONITORS) > 1;
00846 #else
00847     TQCString multiHead = getenv("KDE_MULTIHEAD");
00848     if (!multiHead.isEmpty()) {
00849         return (multiHead.lower() == "true");
00850     }
00851     return false;
00852 #endif
00853 }
00854 
00855 bool KGlobalSettings::wheelMouseZooms()
00856 {
00857     KConfigGroup g( KGlobal::config(), "KDE" );
00858     return g.readBoolEntry( "WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
00859 }
00860 
00861 TQRect KGlobalSettings::splashScreenDesktopGeometry()
00862 {
00863     TQDesktopWidget *dw = TQApplication::desktop();
00864 
00865     if (dw->isVirtualDesktop()) {
00866         KConfigGroup group(KGlobal::config(), "Windows");
00867         int scr = group.readNumEntry("Unmanaged", -3);
00868         if (group.readBoolEntry("XineramaEnabled", true) && scr != -2) {
00869             if (scr == -3)
00870                 scr = dw->screenNumber(TQCursor::pos());
00871             return dw->screenGeometry(scr);
00872         } else {
00873             return dw->geometry();
00874         }
00875     } else {
00876         return dw->geometry();
00877     }
00878 }
00879 
00880 TQRect KGlobalSettings::desktopGeometry(const TQPoint& point)
00881 {
00882     TQDesktopWidget *dw = TQApplication::desktop();
00883 
00884     if (dw->isVirtualDesktop()) {
00885         KConfigGroup group(KGlobal::config(), "Windows");
00886         if (group.readBoolEntry("XineramaEnabled", true) &&
00887             group.readBoolEntry("XineramaPlacementEnabled", true)) {
00888             return dw->screenGeometry(dw->screenNumber(point));
00889         } else {
00890             return dw->geometry();
00891         }
00892     } else {
00893         return dw->geometry();
00894     }
00895 }
00896 
00897 TQRect KGlobalSettings::desktopGeometry(TQWidget* w)
00898 {
00899     TQDesktopWidget *dw = TQApplication::desktop();
00900 
00901     if (dw->isVirtualDesktop()) {
00902         KConfigGroup group(KGlobal::config(), "Windows");
00903         if (group.readBoolEntry("XineramaEnabled", true) &&
00904             group.readBoolEntry("XineramaPlacementEnabled", true)) {
00905             if (w)
00906                 return dw->screenGeometry(dw->screenNumber(w));
00907             else return dw->screenGeometry(-1);
00908         } else {
00909             return dw->geometry();
00910         }
00911     } else {
00912         return dw->geometry();
00913     }
00914 }
00915 
00916 bool KGlobalSettings::showIconsOnPushButtons()
00917 {
00918     KConfigGroup g( KGlobal::config(), "KDE" );
00919     return g.readBoolEntry("ShowIconsOnPushButtons",
00920         KDE_DEFAULT_ICON_ON_PUSHBUTTON);
00921 }
00922 
00923 bool KGlobalSettings::showFilePreview(const KURL &url)
00924 {
00925     KConfigGroup g(KGlobal::config(), "PreviewSettings");
00926     TQString protocol = url.protocol();
00927     bool defaultSetting = KProtocolInfo::showFilePreview( protocol );
00928     return g.readBoolEntry(protocol, defaultSetting );
00929 }
00930 
00931 bool KGlobalSettings::showKonqIconActivationEffect()
00932 {
00933     KConfigGroup g( KGlobal::config(), "KDE" );
00934     return g.readBoolEntry("ShowKonqIconActivationEffect",
00935         KDE_DEFAULT_KONQ_ACTIVATION_EFFECT);
00936 }
00937 
00938 bool KGlobalSettings::opaqueResize()
00939 {
00940     KConfigGroup g( KGlobal::config(), "KDE" );
00941     return g.readBoolEntry("OpaqueResize",
00942         KDE_DEFAULT_OPAQUE_RESIZE);
00943 }
00944 
00945 int KGlobalSettings::buttonLayout()
00946 {
00947     KConfigGroup g( KGlobal::config(), "KDE" );
00948     return g.readNumEntry("ButtonLayout",
00949         KDE_DEFAULT_BUTTON_LAYOUT);
00950 }

kdecore

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

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |