summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/oglobalsettings.cpp
authormickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
committer mickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
commit11304d02942e9fa493e4e80943a828f9c65f6772 (patch) (unidiff)
treea0223c10c067e1afc70d15c2b82be3f3c15e41ae /libopie2/opiecore/oglobalsettings.cpp
parentb271d575fa05cf570a1a829136517761bd47e69b (diff)
downloadopie-11304d02942e9fa493e4e80943a828f9c65f6772.zip
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.gz
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.bz2
skeleton and the start of libopie2, please read README, ROADMAP and STATUS and comment...
Diffstat (limited to 'libopie2/opiecore/oglobalsettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oglobalsettings.cpp547
1 files changed, 547 insertions, 0 deletions
diff --git a/libopie2/opiecore/oglobalsettings.cpp b/libopie2/opiecore/oglobalsettings.cpp
new file mode 100644
index 0000000..184ee69
--- a/dev/null
+++ b/libopie2/opiecore/oglobalsettings.cpp
@@ -0,0 +1,547 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Inspired by the KDE globalsettings which are
6 Copyright (C) 2000 David Faure <faure@kde.org>
7 =.
8 .=l.
9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details.
24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31*/
32
33/* OPIE */
34
35#include <opie2/oglobalsettings.h>
36#include <opie2/oconfig.h>
37#include <opie2/oglobal.h>
38
39/* QT */
40
41#include <qdir.h>
42#include <qpixmap.h>
43#include <qfontinfo.h>
44
45/* UNIX */
46
47#include <stdlib.h>
48
49QString* OGlobalSettings::s_desktopPath = 0;
50QString* OGlobalSettings::s_autostartPath = 0;
51QString* OGlobalSettings::s_trashPath = 0;
52QString* OGlobalSettings::s_documentPath = 0;
53QFont *OGlobalSettings::_generalFont = 0;
54QFont *OGlobalSettings::_fixedFont = 0;
55QFont *OGlobalSettings::_toolBarFont = 0;
56QFont *OGlobalSettings::_menuFont = 0;
57QFont *OGlobalSettings::_windowTitleFont = 0;
58QFont *OGlobalSettings::_taskbarFont = 0;
59
60QColor *OGlobalSettings::OpieGray = 0;
61QColor *OGlobalSettings::OpieHighlight = 0;
62QColor *OGlobalSettings::OpieAlternate = 0;
63
64OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0;
65
66//FIXME: Add manipulators to the accessors
67
68int OGlobalSettings::dndEventDelay()
69{
70 OConfig *c = OGlobal::config();
71 OConfigGroupSaver cgs( c, "General" );
72 return c->readNumEntry("DndDelay", 2);
73}
74
75bool OGlobalSettings::singleClick()
76{
77 OConfig *c = OGlobal::config();
78 OConfigGroupSaver cgs( c, "OPIE" );
79 return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK);
80}
81
82bool OGlobalSettings::insertTearOffHandle()
83{
84 OConfig *c = OGlobal::config();
85 OConfigGroupSaver cgs( c, "OPIE" );
86 return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES);
87}
88
89bool OGlobalSettings::changeCursorOverIcon()
90{
91 OConfig *c = OGlobal::config();
92 OConfigGroupSaver cgs( c, "OPIE" );
93 return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR);
94}
95
96bool OGlobalSettings::visualActivate()
97{
98 OConfig *c = OGlobal::config();
99 OConfigGroupSaver cgs( c, "OPIE" );
100 return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE);
101}
102
103unsigned int OGlobalSettings::visualActivateSpeed()
104{
105 OConfig *c = OGlobal::config();
106 OConfigGroupSaver cgs( c, "OPIE" );
107 return
108 c->readNumEntry(
109 "VisualActivateSpeed",
110 OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED
111 );
112}
113
114int OGlobalSettings::autoSelectDelay()
115{
116 OConfig *c = OGlobal::config();
117 OConfigGroupSaver cgs( c, "OPIE" );
118 return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY);
119}
120
121OGlobalSettings::Completion OGlobalSettings::completionMode()
122{
123 int completion;
124 OConfig *c = OGlobal::config();
125 OConfigGroupSaver cgs( c, "General" );
126 completion = c->readNumEntry("completionMode", -1);
127 if ((completion < (int) CompletionNone) ||
128 (completion > (int) CompletionPopupAuto))
129 {
130 completion = (int) CompletionPopup; // Default
131 }
132 return (Completion) completion;
133}
134
135
136bool OGlobalSettings::showContextMenusOnPress ()
137{
138 OConfig *c = OGlobal::config();
139 OConfigGroupSaver cgs (c, "ContextMenus");
140
141 return cgs.config()->readBoolEntry("ShowOnPress", true);
142}
143
144
145int OGlobalSettings::contextMenuKey ()
146{
147 OConfig *c = OGlobal::config();
148 OConfigGroupSaver cgs (c, "Shortcuts");
149
150 //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu"));
151 //return cut.keyCodeQt();
152
153 return 0; // FIXME
154}
155
156
157OGlobalSettings::Debug OGlobalSettings::debugMode()
158{
159 OConfig *c = OGlobal::config();
160 OConfigGroupSaver cgs( c, "General" );
161 int debug = c->readNumEntry( "debugMode", -1 );
162 if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) )
163 {
164 debug = (int) DebugStdErr; // Default
165 }
166 return (Debug) debug;
167}
168
169
170QString OGlobalSettings::debugOutput()
171{
172 OConfig *c = OGlobal::config();
173 OConfigGroupSaver cgs( c, "General" );
174 QString deflt = QString::null;
175 switch( debugMode() )
176 {
177 case DebugNone: break; // no additional information needed
178 case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in
179 case DebugMsgBox: break; // no additional information needed
180 case DebugStdErr: break; // no additional information needed
181 case DebugSysLog: break; // no additional information needed
182 case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to
183 }
184
185 return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt );
186}
187
188
189QColor OGlobalSettings::toolBarHighlightColor()
190{
191 initColors();
192 OConfig *c = OGlobal::config();
193 OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") );
194 return c->readColorEntry("HighlightColor", OpieHighlight);
195}
196
197QColor OGlobalSettings::inactiveTitleColor()
198{
199 if (!OpieGray) OpieGray = new QColor(220, 220, 220);
200 OConfig *c = OGlobal::config();
201 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
202 return c->readColorEntry( "inactiveBackground", OpieGray );
203}
204
205QColor OGlobalSettings::inactiveTextColor()
206{
207 OConfig *c = OGlobal::config();
208 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
209 return c->readColorEntry( "inactiveForeground", &Qt::darkGray );
210}
211
212QColor OGlobalSettings::activeTitleColor()
213{
214 initColors();
215 OConfig *c = OGlobal::config();
216 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
217 return c->readColorEntry( "activeBackground", OpieHighlight);
218}
219
220QColor OGlobalSettings::activeTextColor()
221{
222 OConfig *c = OGlobal::config();
223 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
224 return c->readColorEntry( "activeForeground", &Qt::white );
225}
226
227int OGlobalSettings::contrast()
228{
229 OConfig *c = OGlobal::config();
230 OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") );
231 return c->readNumEntry( "contrast", 7 );
232}
233
234// following functions should work in OPIE - how to sync with appearance changes?
235
236QColor OGlobalSettings::baseColor()
237{
238 OConfig *c = OGlobal::config();
239 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
240 return c->readColorEntry( "Base", &Qt::white );
241}
242
243QColor OGlobalSettings::textColor()
244{
245 OConfig *c = OGlobal::config();
246 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
247 return c->readColorEntry( "Text", &Qt::black );
248}
249
250QColor OGlobalSettings::highlightedTextColor()
251{
252 OConfig *c = OGlobal::config();
253 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
254 return c->readColorEntry( "HighlightedText", &Qt::white );
255}
256
257QColor OGlobalSettings::highlightColor()
258{
259 initColors();
260 OConfig *c = OGlobal::config();
261 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
262 return c->readColorEntry( "Highlight", OpieHighlight );
263}
264
265QColor OGlobalSettings::alternateBackgroundColor()
266{
267 initColors();
268 OConfig *c = OGlobal::config();
269 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
270 *OpieAlternate = calculateAlternateBackgroundColor( baseColor() );
271 return c->readColorEntry( "alternateBackground", OpieAlternate );
272}
273
274QColor OGlobalSettings::calculateAlternateBackgroundColor(const QColor& base)
275{
276 if (base == Qt::white)
277 return QColor(238,246,255);
278 else
279 {
280 int h, s, v;
281 base.hsv( &h, &s, &v );
282 if (v > 128)
283 return base.dark(106);
284 else if (base != Qt::black)
285 return base.light(110);
286
287 return QColor(32,32,32);
288 }
289}
290
291QColor OGlobalSettings::linkColor()
292{
293 initColors();
294 OConfig *c = OGlobal::config();
295 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
296 return c->readColorEntry( "linkColor", OpieGray );
297}
298
299QColor OGlobalSettings::visitedLinkColor()
300{
301 OConfig *c = OGlobal::config();
302 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
303 return c->readColorEntry( "visitedLinkColor", &Qt::magenta );
304}
305
306// FIXME: font stuff currently uses a different format in OPIE, so the
307// functions below are not yet applicable. The whole font stuff for OPIE
308// has to be revised anyway
309
310QFont OGlobalSettings::generalFont()
311{
312 if (_generalFont)
313 return *_generalFont;
314
315 _generalFont = new QFont("helvetica", 10);
316 _generalFont->setPixelSize(10);
317 _generalFont->setStyleHint(QFont::SansSerif);
318
319 OConfig *c = OGlobal::config();
320 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
321 *_generalFont = c->readFontEntry("font", _generalFont);
322
323 return *_generalFont;
324}
325
326QFont OGlobalSettings::fixedFont()
327{
328 if (_fixedFont)
329 return *_fixedFont;
330
331 _fixedFont = new QFont("courier", 12);
332 _fixedFont->setPixelSize(12);
333 _fixedFont->setStyleHint(QFont::TypeWriter);
334
335 OConfig *c = OGlobal::config();
336 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
337 *_fixedFont = c->readFontEntry("fixed", _fixedFont);
338
339 return *_fixedFont;
340}
341
342QFont OGlobalSettings::toolBarFont()
343{
344 if(_toolBarFont)
345 return *_toolBarFont;
346
347 _toolBarFont = new QFont("helvetica", 10);
348 _toolBarFont->setPixelSize(10);
349 _toolBarFont->setStyleHint(QFont::SansSerif);
350
351 OConfig *c = OGlobal::config();
352 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
353 *_toolBarFont = c->readFontEntry("toolBarFont", _toolBarFont);
354
355 return *_toolBarFont;
356}
357
358QFont OGlobalSettings::menuFont()
359{
360 if(_menuFont)
361 return *_menuFont;
362
363 _menuFont = new QFont("helvetica", 12);
364 _menuFont->setPixelSize(12);
365 _menuFont->setStyleHint(QFont::SansSerif);
366
367 OConfig *c = OGlobal::config();
368 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
369 *_menuFont = c->readFontEntry("menuFont", _menuFont);
370
371 return *_menuFont;
372}
373
374QFont OGlobalSettings::windowTitleFont()
375{
376 if(_windowTitleFont)
377 return *_windowTitleFont;
378
379 _windowTitleFont = new QFont("helvetica", 12, QFont::Bold);
380 _windowTitleFont->setPixelSize(12);
381 _windowTitleFont->setStyleHint(QFont::SansSerif);
382
383 OConfig *c = OGlobal::config();
384 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
385 *_windowTitleFont = c->readFontEntry("activeFont", _windowTitleFont); // inconsistency
386
387 return *_windowTitleFont;
388}
389
390QFont OGlobalSettings::taskbarFont()
391{
392 if(_taskbarFont)
393 return *_taskbarFont;
394
395 _taskbarFont = new QFont("helvetica", 8);
396 _taskbarFont->setPixelSize(8);
397 _taskbarFont->setStyleHint(QFont::SansSerif);
398
399 OConfig *c = OGlobal::config();
400 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
401 *_taskbarFont = c->readFontEntry("taskbarFont", _taskbarFont);
402
403 return *_taskbarFont;
404}
405
406// FIXME: the whole path stuff has to be revised for OPIE
407
408void OGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here.
409{
410 if ( s_desktopPath != 0 )
411 return;
412
413 s_desktopPath = new QString();
414 s_autostartPath = new QString();
415 s_trashPath = new QString();
416 s_documentPath = new QString();
417
418 OConfig *config = OGlobal::config();
419 //bool dollarExpansion = config->isDollarExpansion();
420 //config->setDollarExpansion(true);
421 OConfigGroupSaver cgs( config, "Paths" );
422
423 // Desktop Path
424 *s_desktopPath = QDir::homeDirPath() + "/" + "Desktop" + "/";
425 *s_desktopPath = config->readEntry( "Desktop", *s_desktopPath);
426 if ( (*s_desktopPath)[0] != '/' )
427 s_desktopPath->prepend( QDir::homeDirPath() + "/" );
428 *s_desktopPath = QDir::cleanDirPath( *s_desktopPath );
429 if ( s_desktopPath->right(1) != "/")
430 *s_desktopPath += "/";
431
432 // Trash Path
433 *s_trashPath = *s_desktopPath + QObject::tr("Trash") + "/";
434 *s_trashPath = config->readEntry( "Trash" , *s_trashPath);
435 if ( (*s_trashPath)[0] != '/' )
436 s_trashPath->prepend( QDir::homeDirPath() + "/" );
437 *s_trashPath = QDir::cleanDirPath( *s_trashPath );
438 if ( s_trashPath->right(1) != "/")
439 *s_trashPath += "/";
440 // We need to save it in any case, in case the language changes later on,
441 if ( !config->hasKey( "Trash" ) )
442 {
443 //config->writePathEntry( "Trash", *s_trashPath, true, true );
444 config->writeEntry( "Trash", *s_trashPath );
445 //config->sync();
446 }
447
448/* // Autostart Path
449 *s_autostartPath = OGlobal::dirs()->localkdedir() + "Autostart" + "/";
450 *s_autostartPath = config->readEntry( "Autostart" , *s_autostartPath);
451 if ( (*s_autostartPath)[0] != '/' )
452 s_autostartPath->prepend( QDir::homeDirPath() + "/" );
453 *s_autostartPath = QDir::cleanDirPath( *s_autostartPath );
454 if ( s_autostartPath->right(1) != "/")
455 *s_autostartPath += "/";
456*/
457 // Document Path
458 *s_documentPath = QString::null;
459 *s_documentPath = config->readEntry( "Documents" , *s_documentPath);
460 if ( (*s_documentPath)[0] != '/' )
461 s_documentPath->prepend( QDir::homeDirPath() + "/" );
462 *s_documentPath = QDir::cleanDirPath( *s_documentPath );
463 if ( s_documentPath->right(1) != "/")
464 *s_documentPath += "/";
465
466 //config->setDollarExpansion(dollarExpansion);
467
468 // Make sure this app gets the notifications about those paths
469 //if (kapp)
470 //kapp->addKipcEventMask(KIPC::SettingsChanged);
471}
472
473void OGlobalSettings::initColors()
474{
475 if ( not OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 );
476 if ( not OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 );
477 if ( not OpieGray ) OpieGray = new QColor( 220, 210, 215 );
478}
479
480void OGlobalSettings::rereadFontSettings()
481{
482 delete _generalFont;
483 _generalFont = 0L;
484 delete _fixedFont;
485 _fixedFont = 0L;
486 delete _menuFont;
487 _menuFont = 0L;
488 delete _toolBarFont;
489 _toolBarFont = 0L;
490 delete _windowTitleFont;
491 _windowTitleFont = 0L;
492 delete _taskbarFont;
493 _taskbarFont = 0L;
494}
495
496void OGlobalSettings::rereadPathSettings()
497{
498 qDebug( "OGlobalSettings::rereadPathSettings" );
499 delete s_autostartPath;
500 s_autostartPath = 0L;
501 delete s_trashPath;
502 s_trashPath = 0L;
503 delete s_desktopPath;
504 s_desktopPath = 0L;
505 delete s_documentPath;
506 s_documentPath = 0L;
507}
508
509OGlobalSettings::OMouseSettings & OGlobalSettings::mouseSettings()
510{
511 if ( ! s_mouseSettings )
512 {
513 s_mouseSettings = new OMouseSettings;
514 OMouseSettings & s = *s_mouseSettings; // for convenience
515
516 OConfigGroupSaver cgs( OGlobal::config(), "Mouse" );
517 QString setting = OGlobal::config()->readEntry("MouseButtonMapping");
518 if (setting == "RightHanded")
519 s.handed = OMouseSettings::RightHanded;
520 else if (setting == "LeftHanded")
521 s.handed = OMouseSettings::LeftHanded;
522 else
523 {
524
525 // FIXME: Implement for Opie / Qt Embedded
526
527 }
528 }
529 return *s_mouseSettings;
530}
531
532void OGlobalSettings::rereadMouseSettings()
533{
534 delete s_mouseSettings;
535 s_mouseSettings = 0L;
536}
537
538// FIXME: This won't be necessary, or will it? :-D
539
540bool OGlobalSettings::isMultiHead()
541{
542 QCString multiHead = getenv("OPIE_MULTIHEAD");
543 if (!multiHead.isEmpty()) {
544 return (multiHead.lower() == "true");
545 }
546 return false;
547}