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() +
"/" +
"Desktop" +
"/";
145 if (!TQDir(*desktop).exists())
147 *desktop = TQDir::homeDirPath() +
"/" +
i18n(
"Desktop") +
"/";
150 if (documents->isEmpty())
152 *documents = TQDir::homeDirPath() +
"/" +
"Documents" +
"/";
153 if (!TQDir(*documents).exists())
155 *documents = TQDir::homeDirPath() +
"/" +
i18n(
"Documents") +
"/";
158 if (download->isEmpty())
160 *download = TQDir::homeDirPath() +
"/" +
"Downloads" +
"/";
161 if (!TQDir(*download).exists())
163 *download = TQDir::homeDirPath() +
"/" +
i18n(
"Downloads") +
"/";
166 if (music->isEmpty())
168 *music = TQDir::homeDirPath() +
"/" +
"Music" +
"/";
169 if (!TQDir(*music).exists())
171 *music = TQDir::homeDirPath() +
"/" +
i18n(
"Music") +
"/";
174 if (pictures->isEmpty())
176 *pictures = TQDir::homeDirPath() +
"/" +
"Pictures" +
"/";
177 if (!TQDir(*pictures).exists())
179 *pictures = TQDir::homeDirPath() +
"/" +
i18n(
"Pictures") +
"/";
182 if (publicShare->isEmpty())
184 *publicShare = TQDir::homeDirPath() +
"/" +
"Public" +
"/";
185 if (!TQDir(*publicShare).exists())
187 *publicShare = TQDir::homeDirPath() +
"/" +
i18n(
"Public") +
"/";
190 if (templates->isEmpty())
192 *templates = TQDir::homeDirPath() +
"/" +
"Templates" +
"/";
193 if (!TQDir(*templates).exists())
195 *templates = TQDir::homeDirPath() +
"/" +
i18n(
"Templates") +
"/";
198 if (videos->isEmpty())
200 *videos = TQDir::homeDirPath() +
"/" +
"Videos" +
"/";
201 if (!TQDir(*videos).exists())
203 *videos = TQDir::homeDirPath() +
"/" +
i18n(
"Videos") +
"/";
208 static void checkAndCreateXdgFolder(
const TQString &folder,
const TQString &path,
TDEConfig *config)
211 if (!TQDir(path).exists())
221 config->
writePathEntry(folder,
'"' + path +
'"',
true,
false,
false,
false );
228 return g.
readNumEntry(
"StartDragDist", TQApplication::startDragDistance());
234 return g.
readBoolEntry(
"SingleClick", KDE_DEFAULT_SINGLECLICK);
240 return g.
readBoolEntry(
"IconUseRoundedRect", KDE_DEFAULT_ICONTEXTROUNDED);
249 tearoff = g.
readNumEntry(
"InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
256 return g.
readBoolEntry(
"ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
262 return g.
readBoolEntry(
"VisualActivate", KDE_DEFAULT_VISUAL_ACTIVATE);
270 "VisualActivateSpeed",
271 KDE_DEFAULT_VISUAL_ACTIVATE_SPEED
280 return g.
readNumEntry(
"AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
306 return cut.keyCodeQt();
319 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
321 if (!_inactiveBackground)
322 _inactiveBackground =
new TQColor(157, 170, 186);
324 return g.
readColorEntry(
"inactiveBackground", _inactiveBackground );
331 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
333 if (!_inactiveForeground)
334 _inactiveForeground =
new TQColor(221,221,221);
336 return g.
readColorEntry(
"inactiveForeground", _inactiveForeground );
343 return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
346 if (!_activeBackground)
347 _activeBackground =
new TQColor(65,142,220);
356 return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
371 if (!_buttonBackground)
372 _buttonBackground =
new TQColor(221,223,228);
416 if (!_selectBackground)
417 _selectBackground =
new TQColor(103,141,178);
432 if (base == Qt::white)
433 return TQColor(238,246,255);
437 base.hsv( &h, &s, &v );
439 return base.dark(106);
440 else if (base != Qt::black)
441 return base.light(110);
443 return TQColor(32,32,32);
450 return g.
readBoolEntry(
"shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
457 _linkColor =
new TQColor(0,0,238);
464 if (!_visitedLinkColor)
465 _visitedLinkColor =
new TQColor(82,24,139);
473 return *_generalFont;
476 _generalFont =
new TQFont(
"Sans Serif", 10);
477 _generalFont->setPointSize(10);
478 _generalFont->setStyleHint(TQFont::SansSerif);
483 return *_generalFont;
492 _fixedFont =
new TQFont(
"Monospace", 10);
493 _fixedFont->setPointSize(10);
494 _fixedFont->setStyleHint(TQFont::TypeWriter);
505 return *_toolBarFont;
508 _toolBarFont =
new TQFont(
"Sans Serif", 10);
509 _toolBarFont->setPointSize(10);
510 _toolBarFont->setStyleHint(TQFont::SansSerif);
513 *_toolBarFont = g.
readFontEntry(
"toolBarFont", _toolBarFont);
515 return *_toolBarFont;
524 _menuFont =
new TQFont(
"Sans Serif", 10);
525 _menuFont->setPointSize(10);
526 _menuFont->setStyleHint(TQFont::SansSerif);
537 return *_windowTitleFont;
540 _windowTitleFont =
new TQFont(
"Sans Serif", 9, TQFont::Bold);
541 _windowTitleFont->setPointSize(10);
542 _windowTitleFont->setStyleHint(TQFont::SansSerif);
545 *_windowTitleFont = g.
readFontEntry(
"activeFont", _windowTitleFont);
547 return *_windowTitleFont;
553 return *_taskbarFont;
556 _taskbarFont =
new TQFont(
"Sans Serif", 10);
557 _taskbarFont->setPointSize(10);
558 _taskbarFont->setStyleHint(TQFont::SansSerif);
561 *_taskbarFont = g.
readFontEntry(
"taskbarFont", _taskbarFont);
563 return *_taskbarFont;
570 TQStringList fam = db.families();
573 if (fam.remove(
"Arial"))
574 fam.prepend(
"Arial");
575 if (fam.remove(
"Verdana"))
576 fam.prepend(
"Verdana");
577 if (fam.remove(
"Tahoma"))
578 fam.prepend(
"Tahoma");
579 if (fam.remove(
"Lucida Sans"))
580 fam.prepend(
"Lucida Sans");
581 if (fam.remove(
"Lucidux Sans"))
582 fam.prepend(
"Lucidux Sans");
583 if (fam.remove(
"Nimbus Sans"))
584 fam.prepend(
"Nimbus Sans");
585 if (fam.remove(
"Gothic I"))
586 fam.prepend(
"Gothic I");
589 fam.prepend(_largeFont->family());
591 for(TQStringList::ConstIterator it = fam.begin();
592 it != fam.end(); ++it)
594 if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
597 font.setPixelSize(75);
598 TQFontMetrics metrics(font);
599 int h = metrics.height();
600 if ((h < 60) || ( h > 90))
604 for(
unsigned int i = 0; i < text.length(); i++)
606 if (!metrics.inFont(text[i]))
615 font.setPointSize(48);
616 _largeFont =
new TQFont(font);
621 _largeFont->setPointSize(48);
625 void TDEGlobalSettings::initStatic()
632 void TDEGlobalSettings::initPaths()
639 s_autostartPath =
new TQString();
640 s_trashPath =
new TQString();
641 s_desktopPath =
new TQString();
642 s_documentPath =
new TQString();
643 s_downloadPath =
new TQString();
644 s_musicPath =
new TQString();
645 s_picturesPath =
new TQString();
646 s_publicSharePath =
new TQString();
647 s_templatesPath =
new TQString();
648 s_videosPath =
new TQString();
653 readXdgUserDirs(s_desktopPath, s_documentPath, s_downloadPath, s_musicPath,
654 s_picturesPath, s_publicSharePath, s_templatesPath, s_videosPath);
656 *s_desktopPath = TQDir::cleanDirPath(*s_desktopPath);
657 if (!s_desktopPath->endsWith(
"/"))
658 s_desktopPath->append(
'/');
660 *s_documentPath = TQDir::cleanDirPath(*s_documentPath);
661 if (!s_documentPath->endsWith(
"/"))
662 s_documentPath->append(
'/');
664 *s_downloadPath = TQDir::cleanDirPath(*s_downloadPath);
665 if (!s_downloadPath->endsWith(
"/"))
666 s_downloadPath->append(
'/');
668 *s_musicPath = TQDir::cleanDirPath(*s_musicPath);
669 if (!s_musicPath->endsWith(
"/"))
670 s_musicPath->append(
'/');
672 *s_picturesPath = TQDir::cleanDirPath(*s_picturesPath);
673 if (!s_picturesPath->endsWith(
"/"))
674 s_picturesPath->append(
'/');
676 *s_publicSharePath = TQDir::cleanDirPath(*s_publicSharePath);
677 if (!s_publicSharePath->endsWith(
"/"))
678 s_publicSharePath->append(
'/');
680 *s_templatesPath = TQDir::cleanDirPath(*s_templatesPath);
681 if (!s_templatesPath->endsWith(
"/"))
682 s_templatesPath->append(
'/');
684 *s_videosPath = TQDir::cleanDirPath(*s_videosPath);
685 if (!s_videosPath->endsWith(
"/"))
686 s_videosPath->append(
'/');
689 *s_trashPath = *s_desktopPath + i18n(
"Trash") +
"/";
690 *s_trashPath = g.readPathEntry(
"Trash" , *s_trashPath);
691 *s_trashPath = TQDir::cleanDirPath( *s_trashPath );
692 if ( !s_trashPath->endsWith(
"/") )
693 s_trashPath->append(
'/');
695 if ( !g.hasKey(
"Trash" ) )
697 g.writePathEntry(
"Trash", *s_trashPath,
true,
true );
703 checkAndCreateXdgFolder(
"XDG_DESKTOP_DIR", *s_desktopPath, xdgconfig);
704 checkAndCreateXdgFolder(
"XDG_DOCUMENTS_DIR", *s_documentPath, xdgconfig);
705 checkAndCreateXdgFolder(
"XDG_DOWNLOAD_DIR", *s_downloadPath, xdgconfig);
706 checkAndCreateXdgFolder(
"XDG_MUSIC_DIR", *s_musicPath, xdgconfig);
707 checkAndCreateXdgFolder(
"XDG_PICTURES_DIR", *s_picturesPath, xdgconfig);
708 checkAndCreateXdgFolder(
"XDG_PUBLICSHARE_DIR", *s_publicSharePath, xdgconfig);
709 checkAndCreateXdgFolder(
"XDG_TEMPLATES_DIR", *s_templatesPath, xdgconfig);
710 checkAndCreateXdgFolder(
"XDG_VIDEOS_DIR", *s_videosPath, xdgconfig);
715 *s_autostartPath = g.readPathEntry(
"Autostart" , *s_autostartPath);
716 *s_autostartPath = TQDir::cleanDirPath( *s_autostartPath );
717 if (!s_autostartPath->endsWith(
"/"))
719 s_autostartPath->append(
'/');
721 if (!TQDir(*s_autostartPath).exists())
728 kapp->addKipcEventMask(KIPC::SettingsChanged);
731 void TDEGlobalSettings::initColors()
733 if (!_trinity4Blue) {
734 if (TQPixmap::defaultDepth() > 8)
735 _trinity4Blue =
new TQColor(103,141,178);
737 _trinity4Blue =
new TQColor(0, 0, 192);
740 alternateColor =
new TQColor(237, 244, 249);
743 void TDEGlobalSettings::rereadFontSettings()
753 delete _windowTitleFont;
754 _windowTitleFont = 0L;
759 void TDEGlobalSettings::rereadPathSettings()
761 kdDebug() <<
"TDEGlobalSettings::rereadPathSettings" <<
endl;
762 delete s_autostartPath;
763 s_autostartPath = 0L;
766 delete s_desktopPath;
768 delete s_documentPath;
770 delete s_downloadPath;
774 delete s_picturesPath;
776 delete s_publicSharePath;
777 s_publicSharePath = 0L;
778 delete s_templatesPath;
779 s_templatesPath = 0L;
786 if ( ! s_mouseSettings )
793 TQString setting = g.
readEntry(
"MouseButtonMapping");
794 if (setting ==
"RightHanded")
795 s.handed = KMouseSettings::RightHanded;
796 else if (setting ==
"LeftHanded")
797 s.handed = KMouseSettings::LeftHanded;
804 s.handed = KMouseSettings::RightHanded;
805 unsigned char map[20];
806 int num_buttons = XGetPointerMapping(kapp->getDisplay(), map, 20);
807 if( num_buttons == 2 )
809 if ( (
int)map[0] == 1 && (int)map[1] == 2 )
810 s.handed = KMouseSettings::RightHanded;
811 else if ( (
int)map[0] == 2 && (int)map[1] == 1 )
812 s.handed = KMouseSettings::LeftHanded;
814 else if( num_buttons >= 3 )
816 if ( (
int)map[0] == 1 && (int)map[2] == 3 )
817 s.handed = KMouseSettings::RightHanded;
818 else if ( (
int)map[0] == 3 && (int)map[2] == 1 )
819 s.handed = KMouseSettings::LeftHanded;
829 s_mouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ? KMouseSettings::LeftHanded : KMouseSettings::RightHanded);
831 return *s_mouseSettings;
834 void TDEGlobalSettings::rereadMouseSettings()
837 delete s_mouseSettings;
838 s_mouseSettings = 0L;
845 return GetSystemMetrics(SM_CMONITORS) > 1;
847 TQCString multiHead = getenv(
"TDE_MULTIHEAD");
848 if (!multiHead.isEmpty()) {
849 return (multiHead.lower() ==
"true");
858 return g.
readBoolEntry(
"WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
863 TQDesktopWidget *dw = TQApplication::desktop();
865 if (dw->isVirtualDesktop()) {
868 if (group.
readBoolEntry(
"XineramaEnabled",
true) && scr != -2) {
870 scr = dw->screenNumber(TQCursor::pos());
871 return dw->screenGeometry(scr);
873 return dw->geometry();
876 return dw->geometry();
882 TQDesktopWidget *dw = TQApplication::desktop();
884 if (dw->isVirtualDesktop()) {
888 return dw->screenGeometry(dw->screenNumber(point));
890 return dw->geometry();
893 return dw->geometry();
899 TQDesktopWidget *dw = TQApplication::desktop();
901 if (dw->isVirtualDesktop()) {
906 return dw->screenGeometry(dw->screenNumber(w));
907 else return dw->screenGeometry(-1);
909 return dw->geometry();
912 return dw->geometry();
920 KDE_DEFAULT_ICON_ON_PUSHBUTTON);
935 KDE_DEFAULT_KONQ_ACTIVATION_EFFECT);
942 KDE_DEFAULT_OPAQUE_RESIZE);
949 KDE_DEFAULT_BUTTON_LAYOUT);