TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kglobalsettings.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2000 David Faure <faure@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License version 2 as published by the Free Software Foundation.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public License
  11. along with this library; see the file COPYING.LIB. If not, write to
  12. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  13. Boston, MA 02110-1301, USA.
  14. */
  15. #include "config.h"
  16. #include "kglobalsettings.h"
  17. #include <tqdir.h>
  18. #include <tqpixmap.h>
  19. #include <tqfontdatabase.h>
  20. #include <tqcursor.h>
  21. #include <tdeconfig.h>
  22. #include <ksimpleconfig.h>
  23. #include <kapplication.h>
  24. #include <kipc.h>
  25. #ifdef Q_WS_WIN
  26. #include <windows.h>
  27. #include "qt_windows.h"
  28. #include <win32_utils.h>
  29. static QRgb qt_colorref2qrgb(COLORREF col)
  30. {
  31. return tqRgb(GetRValue(col),GetGValue(col),GetBValue(col));
  32. }
  33. #endif
  34. #include <kdebug.h>
  35. #include <kglobal.h>
  36. #include <kshortcut.h>
  37. #include <kstandarddirs.h>
  38. #include <kcharsets.h>
  39. #include <kaccel.h>
  40. #include <klocale.h>
  41. #include <tqfontinfo.h>
  42. #include <stdlib.h>
  43. #include <kprotocolinfo.h>
  44. #include <tqtextcodec.h>
  45. #include <tqtextstream.h>
  46. #include <tqfile.h>
  47. #ifdef Q_WS_X11
  48. #include <X11/Xlib.h>
  49. #endif
  50. TQString* TDEGlobalSettings::s_desktopPath = 0;
  51. TQString* TDEGlobalSettings::s_autostartPath = 0;
  52. TQString* TDEGlobalSettings::s_trashPath = 0;
  53. TQString* TDEGlobalSettings::s_documentPath = 0;
  54. TQFont *TDEGlobalSettings::_generalFont = 0;
  55. TQFont *TDEGlobalSettings::_fixedFont = 0;
  56. TQFont *TDEGlobalSettings::_toolBarFont = 0;
  57. TQFont *TDEGlobalSettings::_menuFont = 0;
  58. TQFont *TDEGlobalSettings::_windowTitleFont = 0;
  59. TQFont *TDEGlobalSettings::_taskbarFont = 0;
  60. TQFont *TDEGlobalSettings::_largeFont = 0;
  61. TQColor *TDEGlobalSettings::_trinity4Blue = 0;
  62. TQColor *TDEGlobalSettings::_inactiveBackground = 0;
  63. TQColor *TDEGlobalSettings::_inactiveForeground = 0;
  64. TQColor *TDEGlobalSettings::_activeBackground = 0;
  65. TQColor *TDEGlobalSettings::_buttonBackground = 0;
  66. TQColor *TDEGlobalSettings::_selectBackground = 0;
  67. TQColor *TDEGlobalSettings::_linkColor = 0;
  68. TQColor *TDEGlobalSettings::_visitedLinkColor = 0;
  69. TQColor *TDEGlobalSettings::alternateColor = 0;
  70. TDEGlobalSettings::KMouseSettings *TDEGlobalSettings::s_mouseSettings = 0;
  71. // helper function for reading xdg user dirs: it is required in order to take
  72. // care of locale stuff
  73. void readXdgUserDirs(TQString *desktop, TQString *documents)
  74. {
  75. TQFile f( TQDir::homeDirPath() + "/.config/user-dirs.dirs" );
  76. if (!f.open(IO_ReadOnly))
  77. return;
  78. // set the codec for the current locale
  79. TQTextStream s(&f);
  80. s.setCodec( TQTextCodec::codecForLocale() );
  81. TQString line = s.readLine();
  82. while (!line.isNull())
  83. {
  84. if (line.startsWith("XDG_DESKTOP_DIR="))
  85. *desktop = line.remove("XDG_DESKTOP_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
  86. else if (line.startsWith("XDG_DOCUMENTS_DIR="))
  87. *documents = line.remove("XDG_DOCUMENTS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
  88. line = s.readLine();
  89. }
  90. }
  91. int TDEGlobalSettings::dndEventDelay()
  92. {
  93. TDEConfigGroup g( TDEGlobal::config(), "General" );
  94. return g.readNumEntry("StartDragDist", TQApplication::startDragDistance());
  95. }
  96. bool TDEGlobalSettings::singleClick()
  97. {
  98. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  99. return g.readBoolEntry("SingleClick", KDE_DEFAULT_SINGLECLICK);
  100. }
  101. bool TDEGlobalSettings::iconUseRoundedRect()
  102. {
  103. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  104. return g.readBoolEntry("IconUseRoundedRect", KDE_DEFAULT_ICONTEXTROUNDED);
  105. }
  106. TDEGlobalSettings::TearOffHandle TDEGlobalSettings::insertTearOffHandle()
  107. {
  108. int tearoff;
  109. bool effectsenabled;
  110. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  111. effectsenabled = g.readBoolEntry( "EffectsEnabled", false);
  112. tearoff = g.readNumEntry("InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
  113. return effectsenabled ? (TearOffHandle) tearoff : Disable;
  114. }
  115. bool TDEGlobalSettings::changeCursorOverIcon()
  116. {
  117. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  118. return g.readBoolEntry("ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
  119. }
  120. bool TDEGlobalSettings::visualActivate()
  121. {
  122. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  123. return g.readBoolEntry("VisualActivate", KDE_DEFAULT_VISUAL_ACTIVATE);
  124. }
  125. unsigned int TDEGlobalSettings::visualActivateSpeed()
  126. {
  127. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  128. return
  129. g.readNumEntry(
  130. "VisualActivateSpeed",
  131. KDE_DEFAULT_VISUAL_ACTIVATE_SPEED
  132. );
  133. }
  134. int TDEGlobalSettings::autoSelectDelay()
  135. {
  136. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  137. return g.readNumEntry("AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
  138. }
  139. TDEGlobalSettings::Completion TDEGlobalSettings::completionMode()
  140. {
  141. int completion;
  142. TDEConfigGroup g( TDEGlobal::config(), "General" );
  143. completion = g.readNumEntry("completionMode", -1);
  144. if ((completion < (int) CompletionNone) ||
  145. (completion > (int) CompletionPopupAuto))
  146. {
  147. completion = (int) CompletionPopup; // Default
  148. }
  149. return (Completion) completion;
  150. }
  151. bool TDEGlobalSettings::showContextMenusOnPress ()
  152. {
  153. TDEConfigGroup g(TDEGlobal::config(), "ContextMenus");
  154. return g.readBoolEntry("ShowOnPress", true);
  155. }
  156. int TDEGlobalSettings::contextMenuKey ()
  157. {
  158. TDEConfigGroup g(TDEGlobal::config(), "Shortcuts");
  159. KShortcut cut (g.readEntry ("PopupMenuContext", "Menu"));
  160. return cut.keyCodeQt();
  161. }
  162. TQColor TDEGlobalSettings::toolBarHighlightColor()
  163. {
  164. initColors();
  165. TDEConfigGroup g( TDEGlobal::config(), "Toolbar style" );
  166. return g.readColorEntry("HighlightColor", _trinity4Blue);
  167. }
  168. TQColor TDEGlobalSettings::inactiveTitleColor()
  169. {
  170. #ifdef Q_WS_WIN
  171. return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
  172. #else
  173. if (!_inactiveBackground)
  174. _inactiveBackground = new TQColor(157, 170, 186);
  175. TDEConfigGroup g( TDEGlobal::config(), "WM" );
  176. return g.readColorEntry( "inactiveBackground", _inactiveBackground );
  177. #endif
  178. }
  179. TQColor TDEGlobalSettings::inactiveTextColor()
  180. {
  181. #ifdef Q_WS_WIN
  182. return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
  183. #else
  184. if (!_inactiveForeground)
  185. _inactiveForeground = new TQColor(221,221,221);
  186. TDEConfigGroup g( TDEGlobal::config(), "WM" );
  187. return g.readColorEntry( "inactiveForeground", _inactiveForeground );
  188. #endif
  189. }
  190. TQColor TDEGlobalSettings::activeTitleColor()
  191. {
  192. #ifdef Q_WS_WIN
  193. return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
  194. #else
  195. initColors();
  196. if (!_activeBackground)
  197. _activeBackground = new TQColor(65,142,220);
  198. TDEConfigGroup g( TDEGlobal::config(), "WM" );
  199. return g.readColorEntry( "activeBackground", _activeBackground);
  200. #endif
  201. }
  202. TQColor TDEGlobalSettings::activeTextColor()
  203. {
  204. #ifdef Q_WS_WIN
  205. return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
  206. #else
  207. TDEConfigGroup g( TDEGlobal::config(), "WM" );
  208. return g.readColorEntry( "activeForeground", tqwhiteptr );
  209. #endif
  210. }
  211. int TDEGlobalSettings::contrast()
  212. {
  213. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  214. return g.readNumEntry( "contrast", 7 );
  215. }
  216. TQColor TDEGlobalSettings::buttonBackground()
  217. {
  218. if (!_buttonBackground)
  219. _buttonBackground = new TQColor(221,223,228);
  220. TDEConfigGroup g( TDEGlobal::config(), "General" );
  221. return g.readColorEntry( "buttonBackground", _buttonBackground );
  222. }
  223. TQColor TDEGlobalSettings::buttonTextColor()
  224. {
  225. TDEConfigGroup g( TDEGlobal::config(), "General" );
  226. return g.readColorEntry( "buttonForeground", tqblackptr );
  227. }
  228. // IMPORTANT:
  229. // This function should be kept in sync with
  230. // TDEApplication::kdisplaySetPalette()
  231. TQColor TDEGlobalSettings::baseColor()
  232. {
  233. TDEConfigGroup g( TDEGlobal::config(), "General" );
  234. return g.readColorEntry( "windowBackground", tqwhiteptr );
  235. }
  236. // IMPORTANT:
  237. // This function should be kept in sync with
  238. // TDEApplication::kdisplaySetPalette()
  239. TQColor TDEGlobalSettings::textColor()
  240. {
  241. TDEConfigGroup g( TDEGlobal::config(), "General" );
  242. return g.readColorEntry( "windowForeground", tqblackptr );
  243. }
  244. // IMPORTANT:
  245. // This function should be kept in sync with
  246. // TDEApplication::kdisplaySetPalette()
  247. TQColor TDEGlobalSettings::highlightedTextColor()
  248. {
  249. TDEConfigGroup g( TDEGlobal::config(), "General" );
  250. return g.readColorEntry( "selectForeground", tqwhiteptr );
  251. }
  252. // IMPORTANT:
  253. // This function should be kept in sync with
  254. // TDEApplication::kdisplaySetPalette()
  255. TQColor TDEGlobalSettings::highlightColor()
  256. {
  257. initColors();
  258. if (!_selectBackground)
  259. _selectBackground = new TQColor(103,141,178);
  260. TDEConfigGroup g( TDEGlobal::config(), "General" );
  261. return g.readColorEntry( "selectBackground", _selectBackground );
  262. }
  263. TQColor TDEGlobalSettings::alternateBackgroundColor()
  264. {
  265. initColors();
  266. TDEConfigGroup g( TDEGlobal::config(), "General" );
  267. *alternateColor = calculateAlternateBackgroundColor( baseColor() );
  268. return g.readColorEntry( "alternateBackground", alternateColor );
  269. }
  270. TQColor TDEGlobalSettings::calculateAlternateBackgroundColor(const TQColor& base)
  271. {
  272. if (base == Qt::white)
  273. return TQColor(238,246,255);
  274. else
  275. {
  276. int h, s, v;
  277. base.hsv( &h, &s, &v );
  278. if (v > 128)
  279. return base.dark(106);
  280. else if (base != Qt::black)
  281. return base.light(110);
  282. return TQColor(32,32,32);
  283. }
  284. }
  285. bool TDEGlobalSettings::shadeSortColumn()
  286. {
  287. TDEConfigGroup g( TDEGlobal::config(), "General" );
  288. return g.readBoolEntry( "shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
  289. }
  290. TQColor TDEGlobalSettings::linkColor()
  291. {
  292. initColors();
  293. if (!_linkColor)
  294. _linkColor = new TQColor(0,0,238);
  295. TDEConfigGroup g( TDEGlobal::config(), "General" );
  296. return g.readColorEntry( "linkColor", _linkColor );
  297. }
  298. TQColor TDEGlobalSettings::visitedLinkColor()
  299. {
  300. if (!_visitedLinkColor)
  301. _visitedLinkColor = new TQColor(82,24,139);
  302. TDEConfigGroup g( TDEGlobal::config(), "General" );
  303. return g.readColorEntry( "visitedLinkColor", _visitedLinkColor );
  304. }
  305. TQFont TDEGlobalSettings::generalFont()
  306. {
  307. if (_generalFont)
  308. return *_generalFont;
  309. // Sync default with tdebase/kcontrol/fonts/fonts.cpp
  310. _generalFont = new TQFont("Sans Serif", 10);
  311. _generalFont->setPointSize(10);
  312. _generalFont->setStyleHint(TQFont::SansSerif);
  313. TDEConfigGroup g( TDEGlobal::config(), "General" );
  314. *_generalFont = g.readFontEntry("font", _generalFont);
  315. return *_generalFont;
  316. }
  317. TQFont TDEGlobalSettings::fixedFont()
  318. {
  319. if (_fixedFont)
  320. return *_fixedFont;
  321. // Sync default with tdebase/kcontrol/fonts/fonts.cpp
  322. _fixedFont = new TQFont("Monospace", 10);
  323. _fixedFont->setPointSize(10);
  324. _fixedFont->setStyleHint(TQFont::TypeWriter);
  325. TDEConfigGroup g( TDEGlobal::config(), "General" );
  326. *_fixedFont = g.readFontEntry("fixed", _fixedFont);
  327. return *_fixedFont;
  328. }
  329. TQFont TDEGlobalSettings::toolBarFont()
  330. {
  331. if(_toolBarFont)
  332. return *_toolBarFont;
  333. // Sync default with tdebase/kcontrol/fonts/fonts.cpp
  334. _toolBarFont = new TQFont("Sans Serif", 10);
  335. _toolBarFont->setPointSize(10);
  336. _toolBarFont->setStyleHint(TQFont::SansSerif);
  337. TDEConfigGroup g( TDEGlobal::config(), "General" );
  338. *_toolBarFont = g.readFontEntry("toolBarFont", _toolBarFont);
  339. return *_toolBarFont;
  340. }
  341. TQFont TDEGlobalSettings::menuFont()
  342. {
  343. if(_menuFont)
  344. return *_menuFont;
  345. // Sync default with tdebase/kcontrol/fonts/fonts.cpp
  346. _menuFont = new TQFont("Sans Serif", 10);
  347. _menuFont->setPointSize(10);
  348. _menuFont->setStyleHint(TQFont::SansSerif);
  349. TDEConfigGroup g( TDEGlobal::config(), "General" );
  350. *_menuFont = g.readFontEntry("menuFont", _menuFont);
  351. return *_menuFont;
  352. }
  353. TQFont TDEGlobalSettings::windowTitleFont()
  354. {
  355. if(_windowTitleFont)
  356. return *_windowTitleFont;
  357. // Sync default with tdebase/kcontrol/fonts/fonts.cpp
  358. _windowTitleFont = new TQFont("Sans Serif", 9, TQFont::Bold);
  359. _windowTitleFont->setPointSize(10);
  360. _windowTitleFont->setStyleHint(TQFont::SansSerif);
  361. TDEConfigGroup g( TDEGlobal::config(), "WM" );
  362. *_windowTitleFont = g.readFontEntry("activeFont", _windowTitleFont); // inconsistency
  363. return *_windowTitleFont;
  364. }
  365. TQFont TDEGlobalSettings::taskbarFont()
  366. {
  367. if(_taskbarFont)
  368. return *_taskbarFont;
  369. // Sync default with tdebase/kcontrol/fonts/fonts.cpp
  370. _taskbarFont = new TQFont("Sans Serif", 10);
  371. _taskbarFont->setPointSize(10);
  372. _taskbarFont->setStyleHint(TQFont::SansSerif);
  373. TDEConfigGroup g( TDEGlobal::config(), "General" );
  374. *_taskbarFont = g.readFontEntry("taskbarFont", _taskbarFont);
  375. return *_taskbarFont;
  376. }
  377. TQFont TDEGlobalSettings::largeFont(const TQString &text)
  378. {
  379. TQFontDatabase db;
  380. TQStringList fam = db.families();
  381. // Move a bunch of preferred fonts to the front.
  382. if (fam.remove("Arial"))
  383. fam.prepend("Arial");
  384. if (fam.remove("Verdana"))
  385. fam.prepend("Verdana");
  386. if (fam.remove("Tahoma"))
  387. fam.prepend("Tahoma");
  388. if (fam.remove("Lucida Sans"))
  389. fam.prepend("Lucida Sans");
  390. if (fam.remove("Lucidux Sans"))
  391. fam.prepend("Lucidux Sans");
  392. if (fam.remove("Nimbus Sans"))
  393. fam.prepend("Nimbus Sans");
  394. if (fam.remove("Gothic I"))
  395. fam.prepend("Gothic I");
  396. if (_largeFont)
  397. fam.prepend(_largeFont->family());
  398. for(TQStringList::ConstIterator it = fam.begin();
  399. it != fam.end(); ++it)
  400. {
  401. if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
  402. {
  403. TQFont font(*it);
  404. font.setPixelSize(75);
  405. TQFontMetrics metrics(font);
  406. int h = metrics.height();
  407. if ((h < 60) || ( h > 90))
  408. continue;
  409. bool ok = true;
  410. for(unsigned int i = 0; i < text.length(); i++)
  411. {
  412. if (!metrics.inFont(text[i]))
  413. {
  414. ok = false;
  415. break;
  416. }
  417. }
  418. if (!ok)
  419. continue;
  420. font.setPointSize(48);
  421. _largeFont = new TQFont(font);
  422. return *_largeFont;
  423. }
  424. }
  425. _largeFont = new TQFont(TDEGlobalSettings::generalFont());
  426. _largeFont->setPointSize(48);
  427. return *_largeFont;
  428. }
  429. void TDEGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here.
  430. {
  431. if ( s_desktopPath != 0 )
  432. return;
  433. s_desktopPath = new TQString();
  434. s_autostartPath = new TQString();
  435. s_trashPath = new TQString();
  436. s_documentPath = new TQString();
  437. TDEConfigGroup g( TDEGlobal::config(), "Paths" );
  438. // Read desktop and documents path using XDG_USER_DIRS
  439. readXdgUserDirs(s_desktopPath, s_documentPath);
  440. if (s_desktopPath->isEmpty() == true) {
  441. *s_desktopPath = TQDir::homeDirPath() + "/Desktop/";
  442. }
  443. *s_desktopPath = TQDir::cleanDirPath( *s_desktopPath );
  444. if ( !s_desktopPath->endsWith("/") )
  445. s_desktopPath->append('/');
  446. if (s_documentPath->isEmpty() == true) {
  447. #ifdef Q_WS_WIN
  448. *s_documentPath = getWin32ShellFoldersPath("Personal");
  449. #else
  450. *s_documentPath = TQDir::homeDirPath() + "/Documents/";
  451. #endif
  452. }
  453. *s_documentPath = TQDir::cleanDirPath( *s_documentPath );
  454. if ( !s_documentPath->endsWith("/"))
  455. s_documentPath->append('/');
  456. // Trash Path - TODO remove in KDE4 (tdeio_trash can't use it for interoperability reasons)
  457. *s_trashPath = *s_desktopPath + i18n("Trash") + "/";
  458. *s_trashPath = g.readPathEntry( "Trash" , *s_trashPath);
  459. *s_trashPath = TQDir::cleanDirPath( *s_trashPath );
  460. if ( !s_trashPath->endsWith("/") )
  461. s_trashPath->append('/');
  462. // We need to save it in any case, in case the language changes later on,
  463. if ( !g.hasKey( "Trash" ) )
  464. {
  465. g.writePathEntry( "Trash", *s_trashPath, true, true );
  466. g.sync();
  467. }
  468. // Autostart Path
  469. *s_autostartPath = TDEGlobal::dirs()->localtdedir() + "Autostart/";
  470. *s_autostartPath = g.readPathEntry( "Autostart" , *s_autostartPath);
  471. *s_autostartPath = TQDir::cleanDirPath( *s_autostartPath );
  472. if ( !s_autostartPath->endsWith("/") )
  473. s_autostartPath->append('/');
  474. // Make sure this app gets the notifications about those paths
  475. if (kapp)
  476. kapp->addKipcEventMask(KIPC::SettingsChanged);
  477. }
  478. void TDEGlobalSettings::initColors()
  479. {
  480. if (!_trinity4Blue) {
  481. if (TQPixmap::defaultDepth() > 8)
  482. _trinity4Blue = new TQColor(103,141,178);
  483. else
  484. _trinity4Blue = new TQColor(0, 0, 192);
  485. }
  486. if (!alternateColor)
  487. alternateColor = new TQColor(237, 244, 249);
  488. }
  489. void TDEGlobalSettings::rereadFontSettings()
  490. {
  491. delete _generalFont;
  492. _generalFont = 0L;
  493. delete _fixedFont;
  494. _fixedFont = 0L;
  495. delete _menuFont;
  496. _menuFont = 0L;
  497. delete _toolBarFont;
  498. _toolBarFont = 0L;
  499. delete _windowTitleFont;
  500. _windowTitleFont = 0L;
  501. delete _taskbarFont;
  502. _taskbarFont = 0L;
  503. }
  504. void TDEGlobalSettings::rereadPathSettings()
  505. {
  506. kdDebug() << "TDEGlobalSettings::rereadPathSettings" << endl;
  507. delete s_autostartPath;
  508. s_autostartPath = 0L;
  509. delete s_trashPath;
  510. s_trashPath = 0L;
  511. delete s_desktopPath;
  512. s_desktopPath = 0L;
  513. delete s_documentPath;
  514. s_documentPath = 0L;
  515. }
  516. TDEGlobalSettings::KMouseSettings & TDEGlobalSettings::mouseSettings()
  517. {
  518. if ( ! s_mouseSettings )
  519. {
  520. s_mouseSettings = new KMouseSettings;
  521. KMouseSettings & s = *s_mouseSettings; // for convenience
  522. #ifndef Q_WS_WIN
  523. TDEConfigGroup g( TDEGlobal::config(), "Mouse" );
  524. TQString setting = g.readEntry("MouseButtonMapping");
  525. if (setting == "RightHanded")
  526. s.handed = KMouseSettings::RightHanded;
  527. else if (setting == "LeftHanded")
  528. s.handed = KMouseSettings::LeftHanded;
  529. else
  530. {
  531. #ifdef Q_WS_X11
  532. // get settings from X server
  533. // This is a simplified version of the code in input/mouse.cpp
  534. // Keep in sync !
  535. s.handed = KMouseSettings::RightHanded;
  536. unsigned char map[20];
  537. int num_buttons = XGetPointerMapping(kapp->getDisplay(), map, 20);
  538. if( num_buttons == 2 )
  539. {
  540. if ( (int)map[0] == 1 && (int)map[1] == 2 )
  541. s.handed = KMouseSettings::RightHanded;
  542. else if ( (int)map[0] == 2 && (int)map[1] == 1 )
  543. s.handed = KMouseSettings::LeftHanded;
  544. }
  545. else if( num_buttons >= 3 )
  546. {
  547. if ( (int)map[0] == 1 && (int)map[2] == 3 )
  548. s.handed = KMouseSettings::RightHanded;
  549. else if ( (int)map[0] == 3 && (int)map[2] == 1 )
  550. s.handed = KMouseSettings::LeftHanded;
  551. }
  552. #else
  553. // FIXME(E): Implement in Qt Embedded
  554. #endif
  555. }
  556. #endif //Q_WS_WIN
  557. }
  558. #ifdef Q_WS_WIN
  559. //not cached
  560. s_mouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ? KMouseSettings::LeftHanded : KMouseSettings::RightHanded);
  561. #endif
  562. return *s_mouseSettings;
  563. }
  564. void TDEGlobalSettings::rereadMouseSettings()
  565. {
  566. #ifndef Q_WS_WIN
  567. delete s_mouseSettings;
  568. s_mouseSettings = 0L;
  569. #endif
  570. }
  571. bool TDEGlobalSettings::isMultiHead()
  572. {
  573. #ifdef Q_WS_WIN
  574. return GetSystemMetrics(SM_CMONITORS) > 1;
  575. #else
  576. TQCString multiHead = getenv("TDE_MULTIHEAD");
  577. if (!multiHead.isEmpty()) {
  578. return (multiHead.lower() == "true");
  579. }
  580. return false;
  581. #endif
  582. }
  583. bool TDEGlobalSettings::wheelMouseZooms()
  584. {
  585. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  586. return g.readBoolEntry( "WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
  587. }
  588. TQRect TDEGlobalSettings::splashScreenDesktopGeometry()
  589. {
  590. TQDesktopWidget *dw = TQApplication::desktop();
  591. if (dw->isVirtualDesktop()) {
  592. TDEConfigGroup group(TDEGlobal::config(), "Windows");
  593. int scr = group.readNumEntry("Unmanaged", -3);
  594. if (group.readBoolEntry("XineramaEnabled", true) && scr != -2) {
  595. if (scr == -3)
  596. scr = dw->screenNumber(TQCursor::pos());
  597. return dw->screenGeometry(scr);
  598. } else {
  599. return dw->geometry();
  600. }
  601. } else {
  602. return dw->geometry();
  603. }
  604. }
  605. TQRect TDEGlobalSettings::desktopGeometry(const TQPoint& point)
  606. {
  607. TQDesktopWidget *dw = TQApplication::desktop();
  608. if (dw->isVirtualDesktop()) {
  609. TDEConfigGroup group(TDEGlobal::config(), "Windows");
  610. if (group.readBoolEntry("XineramaEnabled", true) &&
  611. group.readBoolEntry("XineramaPlacementEnabled", true)) {
  612. return dw->screenGeometry(dw->screenNumber(point));
  613. } else {
  614. return dw->geometry();
  615. }
  616. } else {
  617. return dw->geometry();
  618. }
  619. }
  620. TQRect TDEGlobalSettings::desktopGeometry(TQWidget* w)
  621. {
  622. TQDesktopWidget *dw = TQApplication::desktop();
  623. if (dw->isVirtualDesktop()) {
  624. TDEConfigGroup group(TDEGlobal::config(), "Windows");
  625. if (group.readBoolEntry("XineramaEnabled", true) &&
  626. group.readBoolEntry("XineramaPlacementEnabled", true)) {
  627. if (w)
  628. return dw->screenGeometry(dw->screenNumber(w));
  629. else return dw->screenGeometry(-1);
  630. } else {
  631. return dw->geometry();
  632. }
  633. } else {
  634. return dw->geometry();
  635. }
  636. }
  637. bool TDEGlobalSettings::showIconsOnPushButtons()
  638. {
  639. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  640. return g.readBoolEntry("ShowIconsOnPushButtons",
  641. KDE_DEFAULT_ICON_ON_PUSHBUTTON);
  642. }
  643. bool TDEGlobalSettings::showFilePreview(const KURL &url)
  644. {
  645. TDEConfigGroup g(TDEGlobal::config(), "PreviewSettings");
  646. TQString protocol = url.protocol();
  647. bool defaultSetting = KProtocolInfo::showFilePreview( protocol );
  648. return g.readBoolEntry(protocol, defaultSetting );
  649. }
  650. bool TDEGlobalSettings::showKonqIconActivationEffect()
  651. {
  652. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  653. return g.readBoolEntry("ShowKonqIconActivationEffect",
  654. KDE_DEFAULT_KONQ_ACTIVATION_EFFECT);
  655. }
  656. bool TDEGlobalSettings::opaqueResize()
  657. {
  658. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  659. return g.readBoolEntry("OpaqueResize",
  660. KDE_DEFAULT_OPAQUE_RESIZE);
  661. }
  662. int TDEGlobalSettings::buttonLayout()
  663. {
  664. TDEConfigGroup g( TDEGlobal::config(), "KDE" );
  665. return g.readNumEntry("ButtonLayout",
  666. KDE_DEFAULT_BUTTON_LAYOUT);
  667. }