19 #include "tdeglobalsettings.h"
23 #include <tqfontdatabase.h>
26 #include <tdeconfig.h>
27 #include <ksimpleconfig.h>
28 #include <tdeapplication.h>
34 #include "qt_windows.h"
35 #include <win32_utils.h>
36 static QRgb qt_colorref2qrgb(COLORREF col)
38 return tqRgb(GetRValue(col),GetGValue(col),GetBValue(col));
43 #include <tdeglobal.h>
44 #include <tdeshortcut.h>
45 #include <kstandarddirs.h>
46 #include <kcharsets.h>
49 #include <tqfontinfo.h>
51 #include <kprotocolinfo.h>
53 #include <tqtextcodec.h>
54 #include <tqtextstream.h>
61 TQString* TDEGlobalSettings::s_desktopPath = 0;
62 TQString* TDEGlobalSettings::s_autostartPath = 0;
63 TQString* TDEGlobalSettings::s_trashPath = 0;
64 TQString* TDEGlobalSettings::s_documentPath = 0;
65 TQString* TDEGlobalSettings::s_videosPath = 0;
66 TQString* TDEGlobalSettings::s_musicPath = 0;
67 TQString* TDEGlobalSettings::s_downloadPath = 0;
68 TQString* TDEGlobalSettings::s_picturesPath = 0;
69 TQFont *TDEGlobalSettings::_generalFont = 0;
70 TQFont *TDEGlobalSettings::_fixedFont = 0;
71 TQFont *TDEGlobalSettings::_toolBarFont = 0;
72 TQFont *TDEGlobalSettings::_menuFont = 0;
73 TQFont *TDEGlobalSettings::_windowTitleFont = 0;
74 TQFont *TDEGlobalSettings::_taskbarFont = 0;
75 TQFont *TDEGlobalSettings::_largeFont = 0;
76 TQColor *TDEGlobalSettings::_trinity4Blue = 0;
77 TQColor *TDEGlobalSettings::_inactiveBackground = 0;
78 TQColor *TDEGlobalSettings::_inactiveForeground = 0;
79 TQColor *TDEGlobalSettings::_activeBackground = 0;
80 TQColor *TDEGlobalSettings::_buttonBackground = 0;
81 TQColor *TDEGlobalSettings::_selectBackground = 0;
82 TQColor *TDEGlobalSettings::_linkColor = 0;
83 TQColor *TDEGlobalSettings::_visitedLinkColor = 0;
84 TQColor *TDEGlobalSettings::alternateColor = 0;
90 void readXdgUserDirs(TQString *desktop, TQString *documents, TQString *videos, TQString *music, TQString *download, TQString *pictures)
92 TQFile f( TQDir::homeDirPath() +
"/.config/user-dirs.dirs" );
94 if (!f.open(IO_ReadOnly))
99 s.setCodec( TQTextCodec::codecForLocale() );
101 TQString line = s.readLine();
102 while (!line.isNull())
104 if (line.startsWith(
"XDG_DESKTOP_DIR="))
105 *desktop = line.remove(
"XDG_DESKTOP_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
106 else if (line.startsWith(
"XDG_DOCUMENTS_DIR="))
107 *documents = line.remove(
"XDG_DOCUMENTS_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
108 else if (line.startsWith(
"XDG_MUSIC_DIR="))
109 *videos = line.remove(
"XDG_MUSIC_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
110 else if (line.startsWith(
"XDG_DOWNLOAD_DIR="))
111 *download = line.remove(
"XDG_DOWNLOAD_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
112 else if (line.startsWith(
"XDG_VIDEOS_DIR="))
113 *music = line.remove(
"XDG_VIDEOS_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
114 else if (line.startsWith(
"XDG_PICTURES_DIR="))
115 *pictures = line.remove(
"XDG_PICTURES_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
124 return g.
readNumEntry(
"StartDragDist", TQApplication::startDragDistance());
130 return g.
readBoolEntry(
"SingleClick", KDE_DEFAULT_SINGLECLICK);
136 return g.
readBoolEntry(
"IconUseRoundedRect", KDE_DEFAULT_ICONTEXTROUNDED);
145 tearoff = g.
readNumEntry(
"InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
152 return g.
readBoolEntry(
"ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
158 return g.
readBoolEntry(
"VisualActivate", KDE_DEFAULT_VISUAL_ACTIVATE);
166 "VisualActivateSpeed",
167 KDE_DEFAULT_VISUAL_ACTIVATE_SPEED
176 return g.
readNumEntry(
"AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
202 return cut.keyCodeQt();
215 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
217 if (!_inactiveBackground)
218 _inactiveBackground =
new TQColor(157, 170, 186);
220 return g.
readColorEntry(
"inactiveBackground", _inactiveBackground );
227 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
229 if (!_inactiveForeground)
230 _inactiveForeground =
new TQColor(221,221,221);
232 return g.
readColorEntry(
"inactiveForeground", _inactiveForeground );
239 return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
242 if (!_activeBackground)
243 _activeBackground =
new TQColor(65,142,220);
252 return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
267 if (!_buttonBackground)
268 _buttonBackground =
new TQColor(221,223,228);
312 if (!_selectBackground)
313 _selectBackground =
new TQColor(103,141,178);
328 if (base == Qt::white)
329 return TQColor(238,246,255);
333 base.hsv( &h, &s, &v );
335 return base.dark(106);
336 else if (base != Qt::black)
337 return base.light(110);
339 return TQColor(32,32,32);
346 return g.
readBoolEntry(
"shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
353 _linkColor =
new TQColor(0,0,238);
360 if (!_visitedLinkColor)
361 _visitedLinkColor =
new TQColor(82,24,139);
369 return *_generalFont;
372 _generalFont =
new TQFont(
"Sans Serif", 10);
373 _generalFont->setPointSize(10);
374 _generalFont->setStyleHint(TQFont::SansSerif);
379 return *_generalFont;
388 _fixedFont =
new TQFont(
"Monospace", 10);
389 _fixedFont->setPointSize(10);
390 _fixedFont->setStyleHint(TQFont::TypeWriter);
401 return *_toolBarFont;
404 _toolBarFont =
new TQFont(
"Sans Serif", 10);
405 _toolBarFont->setPointSize(10);
406 _toolBarFont->setStyleHint(TQFont::SansSerif);
409 *_toolBarFont = g.
readFontEntry(
"toolBarFont", _toolBarFont);
411 return *_toolBarFont;
420 _menuFont =
new TQFont(
"Sans Serif", 10);
421 _menuFont->setPointSize(10);
422 _menuFont->setStyleHint(TQFont::SansSerif);
433 return *_windowTitleFont;
436 _windowTitleFont =
new TQFont(
"Sans Serif", 9, TQFont::Bold);
437 _windowTitleFont->setPointSize(10);
438 _windowTitleFont->setStyleHint(TQFont::SansSerif);
441 *_windowTitleFont = g.
readFontEntry(
"activeFont", _windowTitleFont);
443 return *_windowTitleFont;
449 return *_taskbarFont;
452 _taskbarFont =
new TQFont(
"Sans Serif", 10);
453 _taskbarFont->setPointSize(10);
454 _taskbarFont->setStyleHint(TQFont::SansSerif);
457 *_taskbarFont = g.
readFontEntry(
"taskbarFont", _taskbarFont);
459 return *_taskbarFont;
466 TQStringList fam = db.families();
469 if (fam.remove(
"Arial"))
470 fam.prepend(
"Arial");
471 if (fam.remove(
"Verdana"))
472 fam.prepend(
"Verdana");
473 if (fam.remove(
"Tahoma"))
474 fam.prepend(
"Tahoma");
475 if (fam.remove(
"Lucida Sans"))
476 fam.prepend(
"Lucida Sans");
477 if (fam.remove(
"Lucidux Sans"))
478 fam.prepend(
"Lucidux Sans");
479 if (fam.remove(
"Nimbus Sans"))
480 fam.prepend(
"Nimbus Sans");
481 if (fam.remove(
"Gothic I"))
482 fam.prepend(
"Gothic I");
485 fam.prepend(_largeFont->family());
487 for(TQStringList::ConstIterator it = fam.begin();
488 it != fam.end(); ++it)
490 if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
493 font.setPixelSize(75);
494 TQFontMetrics metrics(font);
495 int h = metrics.height();
496 if ((h < 60) || ( h > 90))
500 for(
unsigned int i = 0; i < text.length(); i++)
502 if (!metrics.inFont(text[i]))
511 font.setPointSize(48);
512 _largeFont =
new TQFont(font);
517 _largeFont->setPointSize(48);
521 void TDEGlobalSettings::initStatic()
523 if ( s_desktopPath != 0 )
526 s_desktopPath =
new TQString();
527 s_autostartPath =
new TQString();
528 s_trashPath =
new TQString();
529 s_documentPath =
new TQString();
530 s_videosPath =
new TQString();
531 s_musicPath =
new TQString();
532 s_downloadPath =
new TQString();
533 s_picturesPath =
new TQString();
539 readXdgUserDirs(s_desktopPath, s_documentPath, s_musicPath, s_videosPath, s_downloadPath, s_picturesPath);
541 if (s_desktopPath->isEmpty() ==
true) {
542 *s_desktopPath = TQDir::homeDirPath() +
"/Desktop/";
545 *s_desktopPath = TQDir::cleanDirPath( *s_desktopPath );
546 if ( !s_desktopPath->endsWith(
"/") )
547 s_desktopPath->append(
'/');
549 *s_documentPath = TQDir::cleanDirPath( *s_documentPath );
550 if ( !s_documentPath->endsWith(
"/"))
551 s_documentPath->append(
'/');
553 *s_musicPath = TQDir::cleanDirPath( *s_musicPath );
554 if ( !s_musicPath->endsWith(
"/"))
555 s_musicPath->append(
'/');
557 *s_videosPath = TQDir::cleanDirPath( *s_videosPath );
558 if ( !s_videosPath->endsWith(
"/"))
559 s_videosPath->append(
'/');
561 *s_downloadPath = TQDir::cleanDirPath( *s_downloadPath );
562 if ( !s_downloadPath->endsWith(
"/"))
563 s_downloadPath->append(
'/');
565 *s_picturesPath = TQDir::cleanDirPath( *s_picturesPath );
566 if ( !s_picturesPath->endsWith(
"/"))
567 s_picturesPath->append(
'/');
570 *s_trashPath = *s_desktopPath + i18n(
"Trash") +
"/";
571 *s_trashPath = g.readPathEntry(
"Trash" , *s_trashPath);
572 *s_trashPath = TQDir::cleanDirPath( *s_trashPath );
573 if ( !s_trashPath->endsWith(
"/") )
574 s_trashPath->append(
'/');
576 if ( !g.hasKey(
"Trash" ) )
578 g.writePathEntry(
"Trash", *s_trashPath,
true,
true );
584 *s_autostartPath = g.readPathEntry(
"Autostart" , *s_autostartPath);
585 *s_autostartPath = TQDir::cleanDirPath( *s_autostartPath );
586 if ( !s_autostartPath->endsWith(
"/") )
587 s_autostartPath->append(
'/');
591 kapp->addKipcEventMask(KIPC::SettingsChanged);
594 void TDEGlobalSettings::initColors()
596 if (!_trinity4Blue) {
597 if (TQPixmap::defaultDepth() > 8)
598 _trinity4Blue =
new TQColor(103,141,178);
600 _trinity4Blue =
new TQColor(0, 0, 192);
603 alternateColor =
new TQColor(237, 244, 249);
606 void TDEGlobalSettings::rereadFontSettings()
616 delete _windowTitleFont;
617 _windowTitleFont = 0L;
622 void TDEGlobalSettings::rereadPathSettings()
624 kdDebug() <<
"TDEGlobalSettings::rereadPathSettings" <<
endl;
625 delete s_autostartPath;
626 s_autostartPath = 0L;
629 delete s_desktopPath;
631 delete s_documentPath;
635 delete s_picturesPath;
637 delete s_downloadPath;
645 if ( ! s_mouseSettings )
652 TQString setting = g.
readEntry(
"MouseButtonMapping");
653 if (setting ==
"RightHanded")
654 s.handed = KMouseSettings::RightHanded;
655 else if (setting ==
"LeftHanded")
656 s.handed = KMouseSettings::LeftHanded;
663 s.handed = KMouseSettings::RightHanded;
664 unsigned char map[20];
665 int num_buttons = XGetPointerMapping(kapp->getDisplay(), map, 20);
666 if( num_buttons == 2 )
668 if ( (
int)map[0] == 1 && (int)map[1] == 2 )
669 s.handed = KMouseSettings::RightHanded;
670 else if ( (
int)map[0] == 2 && (int)map[1] == 1 )
671 s.handed = KMouseSettings::LeftHanded;
673 else if( num_buttons >= 3 )
675 if ( (
int)map[0] == 1 && (int)map[2] == 3 )
676 s.handed = KMouseSettings::RightHanded;
677 else if ( (
int)map[0] == 3 && (int)map[2] == 1 )
678 s.handed = KMouseSettings::LeftHanded;
688 s_mouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ? KMouseSettings::LeftHanded : KMouseSettings::RightHanded);
690 return *s_mouseSettings;
693 void TDEGlobalSettings::rereadMouseSettings()
696 delete s_mouseSettings;
697 s_mouseSettings = 0L;
704 return GetSystemMetrics(SM_CMONITORS) > 1;
706 TQCString multiHead = getenv(
"TDE_MULTIHEAD");
707 if (!multiHead.isEmpty()) {
708 return (multiHead.lower() ==
"true");
717 return g.
readBoolEntry(
"WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
722 TQDesktopWidget *dw = TQApplication::desktop();
724 if (dw->isVirtualDesktop()) {
727 if (group.
readBoolEntry(
"XineramaEnabled",
true) && scr != -2) {
729 scr = dw->screenNumber(TQCursor::pos());
730 return dw->screenGeometry(scr);
732 return dw->geometry();
735 return dw->geometry();
741 TQDesktopWidget *dw = TQApplication::desktop();
743 if (dw->isVirtualDesktop()) {
747 return dw->screenGeometry(dw->screenNumber(point));
749 return dw->geometry();
752 return dw->geometry();
758 TQDesktopWidget *dw = TQApplication::desktop();
760 if (dw->isVirtualDesktop()) {
765 return dw->screenGeometry(dw->screenNumber(w));
766 else return dw->screenGeometry(-1);
768 return dw->geometry();
771 return dw->geometry();
779 KDE_DEFAULT_ICON_ON_PUSHBUTTON);
794 KDE_DEFAULT_KONQ_ACTIVATION_EFFECT);
801 KDE_DEFAULT_OPAQUE_RESIZE);
808 KDE_DEFAULT_BUTTON_LAYOUT);