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