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 TQString* TDEGlobalSettings::s_templatesPath = 0;
70 TQString* TDEGlobalSettings::s_publicSharePath = 0;
71 TQFont *TDEGlobalSettings::_generalFont = 0;
72 TQFont *TDEGlobalSettings::_fixedFont = 0;
73 TQFont *TDEGlobalSettings::_toolBarFont = 0;
74 TQFont *TDEGlobalSettings::_menuFont = 0;
75 TQFont *TDEGlobalSettings::_windowTitleFont = 0;
76 TQFont *TDEGlobalSettings::_taskbarFont = 0;
77 TQFont *TDEGlobalSettings::_largeFont = 0;
78 TQColor *TDEGlobalSettings::_trinity4Blue = 0;
79 TQColor *TDEGlobalSettings::_inactiveBackground = 0;
80 TQColor *TDEGlobalSettings::_inactiveForeground = 0;
81 TQColor *TDEGlobalSettings::_activeBackground = 0;
82 TQColor *TDEGlobalSettings::_buttonBackground = 0;
83 TQColor *TDEGlobalSettings::_selectBackground = 0;
84 TQColor *TDEGlobalSettings::_linkColor = 0;
85 TQColor *TDEGlobalSettings::_visitedLinkColor = 0;
86 TQColor *TDEGlobalSettings::alternateColor = 0;
92 static void readXdgUserDirs(TQString *desktop, TQString *documents, TQString *download, TQString *music,
93 TQString *pictures, TQString *publicShare, TQString *templates, TQString *videos)
95 TQFile dirsFile(TQDir::homeDirPath() +
"/.config/user-dirs.dirs");
96 if (dirsFile.open(IO_ReadOnly))
99 TQTextStream stream(&dirsFile);
100 stream.setCodec(TQTextCodec::codecForLocale());
102 while (!stream.atEnd())
104 TQString line = stream.readLine();
105 if (line.startsWith(
"XDG_DESKTOP_DIR="))
107 *desktop = line.remove(
"XDG_DESKTOP_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
109 else if (line.startsWith(
"XDG_DOCUMENTS_DIR="))
111 *documents = line.remove(
"XDG_DOCUMENTS_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
113 else if (line.startsWith(
"XDG_DOWNLOAD_DIR="))
115 *download = line.remove(
"XDG_DOWNLOAD_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
117 else if (line.startsWith(
"XDG_MUSIC_DIR="))
119 *music = line.remove(
"XDG_MUSIC_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
121 else if (line.startsWith(
"XDG_PICTURES_DIR="))
123 *pictures = line.remove(
"XDG_PICTURES_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
125 else if (line.startsWith(
"XDG_PUBLICSHARE_DIR="))
127 *publicShare = line.remove(
"XDG_PUBLICSHARE_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
129 else if (line.startsWith(
"XDG_TEMPLATES_DIR="))
131 *templates = line.remove(
"XDG_TEMPLATES_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
133 else if (line.startsWith(
"XDG_VIDEOS_DIR="))
135 *videos = line.remove(
"XDG_VIDEOS_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
142 if (desktop->isEmpty())
144 *desktop = TQDir::homeDirPath() +
"/" +
i18n(
"Desktop") +
"/";
146 if (documents->isEmpty())
148 *documents = TQDir::homeDirPath() +
"/" +
i18n(
"Documents") +
"/";
150 if (download->isEmpty())
152 *download = TQDir::homeDirPath() +
"/" +
i18n(
"Downloads") +
"/";
154 if (music->isEmpty())
156 *music = TQDir::homeDirPath() +
"/" +
i18n(
"Music") +
"/";
158 if (pictures->isEmpty())
160 *pictures = TQDir::homeDirPath() +
"/" +
i18n(
"Pictures") +
"/";
162 if (publicShare->isEmpty())
164 *publicShare = TQDir::homeDirPath() +
"/" +
i18n(
"Public") +
"/";
166 if (templates->isEmpty())
168 *templates = TQDir::homeDirPath() +
"/" +
i18n(
"Templates") +
"/";
170 if (videos->isEmpty())
172 *videos = TQDir::homeDirPath() +
"/" +
i18n(
"Videos") +
"/";
176 static void checkAndCreateXdgFolder(
const TQString &folder,
const TQString &path,
TDEConfig *config)
179 if (!TQDir(path).exists())
189 config->
writePathEntry(folder,
'"' + path +
'"',
true,
false,
false,
false );
196 return g.
readNumEntry(
"StartDragDist", TQApplication::startDragDistance());
202 return g.
readBoolEntry(
"SingleClick", KDE_DEFAULT_SINGLECLICK);
208 return g.
readBoolEntry(
"IconUseRoundedRect", KDE_DEFAULT_ICONTEXTROUNDED);
217 tearoff = g.
readNumEntry(
"InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
224 return g.
readBoolEntry(
"ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
230 return g.
readBoolEntry(
"VisualActivate", KDE_DEFAULT_VISUAL_ACTIVATE);
238 "VisualActivateSpeed",
239 KDE_DEFAULT_VISUAL_ACTIVATE_SPEED
248 return g.
readNumEntry(
"AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
274 return cut.keyCodeQt();
287 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
289 if (!_inactiveBackground)
290 _inactiveBackground =
new TQColor(157, 170, 186);
292 return g.
readColorEntry(
"inactiveBackground", _inactiveBackground );
299 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
301 if (!_inactiveForeground)
302 _inactiveForeground =
new TQColor(221,221,221);
304 return g.
readColorEntry(
"inactiveForeground", _inactiveForeground );
311 return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
314 if (!_activeBackground)
315 _activeBackground =
new TQColor(65,142,220);
324 return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
339 if (!_buttonBackground)
340 _buttonBackground =
new TQColor(221,223,228);
384 if (!_selectBackground)
385 _selectBackground =
new TQColor(103,141,178);
400 if (base == Qt::white)
401 return TQColor(238,246,255);
405 base.hsv( &h, &s, &v );
407 return base.dark(106);
408 else if (base != Qt::black)
409 return base.light(110);
411 return TQColor(32,32,32);
418 return g.
readBoolEntry(
"shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
425 _linkColor =
new TQColor(0,0,238);
432 if (!_visitedLinkColor)
433 _visitedLinkColor =
new TQColor(82,24,139);
441 return *_generalFont;
444 _generalFont =
new TQFont(
"Sans Serif", 10);
445 _generalFont->setPointSize(10);
446 _generalFont->setStyleHint(TQFont::SansSerif);
451 return *_generalFont;
460 _fixedFont =
new TQFont(
"Monospace", 10);
461 _fixedFont->setPointSize(10);
462 _fixedFont->setStyleHint(TQFont::TypeWriter);
473 return *_toolBarFont;
476 _toolBarFont =
new TQFont(
"Sans Serif", 10);
477 _toolBarFont->setPointSize(10);
478 _toolBarFont->setStyleHint(TQFont::SansSerif);
481 *_toolBarFont = g.
readFontEntry(
"toolBarFont", _toolBarFont);
483 return *_toolBarFont;
492 _menuFont =
new TQFont(
"Sans Serif", 10);
493 _menuFont->setPointSize(10);
494 _menuFont->setStyleHint(TQFont::SansSerif);
505 return *_windowTitleFont;
508 _windowTitleFont =
new TQFont(
"Sans Serif", 9, TQFont::Bold);
509 _windowTitleFont->setPointSize(10);
510 _windowTitleFont->setStyleHint(TQFont::SansSerif);
513 *_windowTitleFont = g.
readFontEntry(
"activeFont", _windowTitleFont);
515 return *_windowTitleFont;
521 return *_taskbarFont;
524 _taskbarFont =
new TQFont(
"Sans Serif", 10);
525 _taskbarFont->setPointSize(10);
526 _taskbarFont->setStyleHint(TQFont::SansSerif);
529 *_taskbarFont = g.
readFontEntry(
"taskbarFont", _taskbarFont);
531 return *_taskbarFont;
538 TQStringList fam = db.families();
541 if (fam.remove(
"Arial"))
542 fam.prepend(
"Arial");
543 if (fam.remove(
"Verdana"))
544 fam.prepend(
"Verdana");
545 if (fam.remove(
"Tahoma"))
546 fam.prepend(
"Tahoma");
547 if (fam.remove(
"Lucida Sans"))
548 fam.prepend(
"Lucida Sans");
549 if (fam.remove(
"Lucidux Sans"))
550 fam.prepend(
"Lucidux Sans");
551 if (fam.remove(
"Nimbus Sans"))
552 fam.prepend(
"Nimbus Sans");
553 if (fam.remove(
"Gothic I"))
554 fam.prepend(
"Gothic I");
557 fam.prepend(_largeFont->family());
559 for(TQStringList::ConstIterator it = fam.begin();
560 it != fam.end(); ++it)
562 if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
565 font.setPixelSize(75);
566 TQFontMetrics metrics(font);
567 int h = metrics.height();
568 if ((h < 60) || ( h > 90))
572 for(
unsigned int i = 0; i < text.length(); i++)
574 if (!metrics.inFont(text[i]))
583 font.setPointSize(48);
584 _largeFont =
new TQFont(font);
589 _largeFont->setPointSize(48);
593 void TDEGlobalSettings::initStatic()
600 void TDEGlobalSettings::initPaths()
607 s_autostartPath =
new TQString();
608 s_trashPath =
new TQString();
609 s_desktopPath =
new TQString();
610 s_documentPath =
new TQString();
611 s_downloadPath =
new TQString();
612 s_musicPath =
new TQString();
613 s_picturesPath =
new TQString();
614 s_publicSharePath =
new TQString();
615 s_templatesPath =
new TQString();
616 s_videosPath =
new TQString();
621 readXdgUserDirs(s_desktopPath, s_documentPath, s_downloadPath, s_musicPath,
622 s_picturesPath, s_publicSharePath, s_templatesPath, s_videosPath);
624 *s_desktopPath = TQDir::cleanDirPath(*s_desktopPath);
625 if (!s_desktopPath->endsWith(
"/"))
626 s_desktopPath->append(
'/');
628 *s_documentPath = TQDir::cleanDirPath(*s_documentPath);
629 if (!s_documentPath->endsWith(
"/"))
630 s_documentPath->append(
'/');
632 *s_downloadPath = TQDir::cleanDirPath(*s_downloadPath);
633 if (!s_downloadPath->endsWith(
"/"))
634 s_downloadPath->append(
'/');
636 *s_musicPath = TQDir::cleanDirPath(*s_musicPath);
637 if (!s_musicPath->endsWith(
"/"))
638 s_musicPath->append(
'/');
640 *s_picturesPath = TQDir::cleanDirPath(*s_picturesPath);
641 if (!s_picturesPath->endsWith(
"/"))
642 s_picturesPath->append(
'/');
644 *s_publicSharePath = TQDir::cleanDirPath(*s_publicSharePath);
645 if (!s_publicSharePath->endsWith(
"/"))
646 s_publicSharePath->append(
'/');
648 *s_templatesPath = TQDir::cleanDirPath(*s_templatesPath);
649 if (!s_templatesPath->endsWith(
"/"))
650 s_templatesPath->append(
'/');
652 *s_videosPath = TQDir::cleanDirPath(*s_videosPath);
653 if (!s_videosPath->endsWith(
"/"))
654 s_videosPath->append(
'/');
657 *s_trashPath = *s_desktopPath + i18n(
"Trash") +
"/";
658 *s_trashPath = g.readPathEntry(
"Trash" , *s_trashPath);
659 *s_trashPath = TQDir::cleanDirPath( *s_trashPath );
660 if ( !s_trashPath->endsWith(
"/") )
661 s_trashPath->append(
'/');
663 if ( !g.hasKey(
"Trash" ) )
665 g.writePathEntry(
"Trash", *s_trashPath,
true,
true );
671 checkAndCreateXdgFolder(
"XDG_DESKTOP_DIR", *s_desktopPath, xdgconfig);
672 checkAndCreateXdgFolder(
"XDG_DOCUMENTS_DIR", *s_documentPath, xdgconfig);
673 checkAndCreateXdgFolder(
"XDG_DOWNLOAD_DIR", *s_downloadPath, xdgconfig);
674 checkAndCreateXdgFolder(
"XDG_MUSIC_DIR", *s_musicPath, xdgconfig);
675 checkAndCreateXdgFolder(
"XDG_PICTURES_DIR", *s_picturesPath, xdgconfig);
676 checkAndCreateXdgFolder(
"XDG_PUBLICSHARE_DIR", *s_publicSharePath, xdgconfig);
677 checkAndCreateXdgFolder(
"XDG_TEMPLATES_DIR", *s_templatesPath, xdgconfig);
678 checkAndCreateXdgFolder(
"XDG_VIDEOS_DIR", *s_videosPath, xdgconfig);
683 *s_autostartPath = g.readPathEntry(
"Autostart" , *s_autostartPath);
684 *s_autostartPath = TQDir::cleanDirPath( *s_autostartPath );
685 if (!s_autostartPath->endsWith(
"/"))
687 s_autostartPath->append(
'/');
689 if (!TQDir(*s_autostartPath).exists())
696 kapp->addKipcEventMask(KIPC::SettingsChanged);
699 void TDEGlobalSettings::initColors()
701 if (!_trinity4Blue) {
702 if (TQPixmap::defaultDepth() > 8)
703 _trinity4Blue =
new TQColor(103,141,178);
705 _trinity4Blue =
new TQColor(0, 0, 192);
708 alternateColor =
new TQColor(237, 244, 249);
711 void TDEGlobalSettings::rereadFontSettings()
721 delete _windowTitleFont;
722 _windowTitleFont = 0L;
727 void TDEGlobalSettings::rereadPathSettings()
729 kdDebug() <<
"TDEGlobalSettings::rereadPathSettings" <<
endl;
730 delete s_autostartPath;
731 s_autostartPath = 0L;
734 delete s_desktopPath;
736 delete s_documentPath;
738 delete s_downloadPath;
742 delete s_picturesPath;
744 delete s_publicSharePath;
745 s_publicSharePath = 0L;
746 delete s_templatesPath;
747 s_templatesPath = 0L;
754 if ( ! s_mouseSettings )
761 TQString setting = g.
readEntry(
"MouseButtonMapping");
762 if (setting ==
"RightHanded")
763 s.handed = KMouseSettings::RightHanded;
764 else if (setting ==
"LeftHanded")
765 s.handed = KMouseSettings::LeftHanded;
772 s.handed = KMouseSettings::RightHanded;
773 unsigned char map[20];
774 int num_buttons = XGetPointerMapping(kapp->getDisplay(), map, 20);
775 if( num_buttons == 2 )
777 if ( (
int)map[0] == 1 && (int)map[1] == 2 )
778 s.handed = KMouseSettings::RightHanded;
779 else if ( (
int)map[0] == 2 && (int)map[1] == 1 )
780 s.handed = KMouseSettings::LeftHanded;
782 else if( num_buttons >= 3 )
784 if ( (
int)map[0] == 1 && (int)map[2] == 3 )
785 s.handed = KMouseSettings::RightHanded;
786 else if ( (
int)map[0] == 3 && (int)map[2] == 1 )
787 s.handed = KMouseSettings::LeftHanded;
797 s_mouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ? KMouseSettings::LeftHanded : KMouseSettings::RightHanded);
799 return *s_mouseSettings;
802 void TDEGlobalSettings::rereadMouseSettings()
805 delete s_mouseSettings;
806 s_mouseSettings = 0L;
813 return GetSystemMetrics(SM_CMONITORS) > 1;
815 TQCString multiHead = getenv(
"TDE_MULTIHEAD");
816 if (!multiHead.isEmpty()) {
817 return (multiHead.lower() ==
"true");
826 return g.
readBoolEntry(
"WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
831 TQDesktopWidget *dw = TQApplication::desktop();
833 if (dw->isVirtualDesktop()) {
836 if (group.
readBoolEntry(
"XineramaEnabled",
true) && scr != -2) {
838 scr = dw->screenNumber(TQCursor::pos());
839 return dw->screenGeometry(scr);
841 return dw->geometry();
844 return dw->geometry();
850 TQDesktopWidget *dw = TQApplication::desktop();
852 if (dw->isVirtualDesktop()) {
856 return dw->screenGeometry(dw->screenNumber(point));
858 return dw->geometry();
861 return dw->geometry();
867 TQDesktopWidget *dw = TQApplication::desktop();
869 if (dw->isVirtualDesktop()) {
874 return dw->screenGeometry(dw->screenNumber(w));
875 else return dw->screenGeometry(-1);
877 return dw->geometry();
880 return dw->geometry();
888 KDE_DEFAULT_ICON_ON_PUSHBUTTON);
903 KDE_DEFAULT_KONQ_ACTIVATION_EFFECT);
910 KDE_DEFAULT_OPAQUE_RESIZE);
917 KDE_DEFAULT_BUTTON_LAYOUT);