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