00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <opie2/oglobalsettings.h>
00036 #include <opie2/oconfig.h>
00037 #include <opie2/odebug.h>
00038 #include <opie2/oglobal.h>
00039
00040
00041
00042 #include <qdir.h>
00043
00044
00045
00046 #include <stdlib.h>
00047
00048
00049 using namespace Opie::Core;
00050
00051 QString* OGlobalSettings::s_desktopPath = 0;
00052 QString* OGlobalSettings::s_autostartPath = 0;
00053 QString* OGlobalSettings::s_trashPath = 0;
00054 QString* OGlobalSettings::s_documentPath = 0;
00055 QFont *OGlobalSettings::_generalFont = 0;
00056 QFont *OGlobalSettings::_fixedFont = 0;
00057 QFont *OGlobalSettings::_toolBarFont = 0;
00058 QFont *OGlobalSettings::_menuFont = 0;
00059 QFont *OGlobalSettings::_windowTitleFont = 0;
00060 QFont *OGlobalSettings::_taskbarFont = 0;
00061
00062 QColor *OGlobalSettings::OpieGray = 0;
00063 QColor *OGlobalSettings::OpieHighlight = 0;
00064 QColor *OGlobalSettings::OpieAlternate = 0;
00065
00066 OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0;
00067
00068
00069
00070 int OGlobalSettings::dndEventDelay()
00071 {
00072 OConfig *c = OGlobal::config();
00073 OConfigGroupSaver cgs( c, "General" );
00074 return c->readNumEntry("DndDelay", 2);
00075 }
00076
00077 bool OGlobalSettings::singleClick()
00078 {
00079 OConfig *c = OGlobal::config();
00080 OConfigGroupSaver cgs( c, "OPIE" );
00081 return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK);
00082 }
00083
00084 bool OGlobalSettings::insertTearOffHandle()
00085 {
00086 OConfig *c = OGlobal::config();
00087 OConfigGroupSaver cgs( c, "OPIE" );
00088 return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES);
00089 }
00090
00091 bool OGlobalSettings::changeCursorOverIcon()
00092 {
00093 OConfig *c = OGlobal::config();
00094 OConfigGroupSaver cgs( c, "OPIE" );
00095 return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR);
00096 }
00097
00098 bool OGlobalSettings::visualActivate()
00099 {
00100 OConfig *c = OGlobal::config();
00101 OConfigGroupSaver cgs( c, "OPIE" );
00102 return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE);
00103 }
00104
00105 unsigned int OGlobalSettings::visualActivateSpeed()
00106 {
00107 OConfig *c = OGlobal::config();
00108 OConfigGroupSaver cgs( c, "OPIE" );
00109 return
00110 c->readNumEntry(
00111 "VisualActivateSpeed",
00112 OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED
00113 );
00114 }
00115
00116 int OGlobalSettings::autoSelectDelay()
00117 {
00118 OConfig *c = OGlobal::config();
00119 OConfigGroupSaver cgs( c, "OPIE" );
00120 return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY);
00121 }
00122
00123 OGlobalSettings::Completion OGlobalSettings::completionMode()
00124 {
00125 int completion;
00126 OConfig *c = OGlobal::config();
00127 OConfigGroupSaver cgs( c, "General" );
00128 completion = c->readNumEntry("completionMode", -1);
00129 if ((completion < (int) CompletionNone) ||
00130 (completion > (int) CompletionPopupAuto))
00131 {
00132 completion = (int) CompletionPopup;
00133 }
00134 return (Completion) completion;
00135 }
00136
00137
00138 bool OGlobalSettings::showContextMenusOnPress ()
00139 {
00140 OConfig *c = OGlobal::config();
00141 OConfigGroupSaver cgs (c, "ContextMenus");
00142
00143 return cgs.config()->readBoolEntry("ShowOnPress", true);
00144 }
00145
00146
00147 int OGlobalSettings::contextMenuKey ()
00148 {
00149 OConfig *c = OGlobal::config();
00150 OConfigGroupSaver cgs (c, "Shortcuts");
00151
00152
00153
00154
00155 return 0;
00156 }
00157
00158
00159 OGlobalSettings::Debug OGlobalSettings::debugMode()
00160 {
00161 OConfig *c = OGlobal::config();
00162 OConfigGroupSaver cgs( c, "General" );
00163 int debug = c->readNumEntry( "debugMode", ODEBUG_STDERR );
00164 if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) )
00165 {
00166 debug = (int) DebugStdErr;
00167 }
00168 return (Debug) debug;
00169 }
00170
00171
00172 QString OGlobalSettings::debugOutput()
00173 {
00174 OConfig *c = OGlobal::config();
00175 OConfigGroupSaver cgs( c, "General" );
00176 QString deflt = QString::null;
00177 switch( debugMode() )
00178 {
00179 case DebugNone: break;
00180 case DebugFiles: deflt = "/var/log/opiedebug.log"; break;
00181 case DebugMsgBox: break;
00182 case DebugStdErr: break;
00183 case DebugSysLog: break;
00184 case DebugSocket: deflt = "127.0.0.1:8913"; break;
00185 }
00186
00187 return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt );
00188 }
00189
00190
00191 QColor OGlobalSettings::toolBarHighlightColor()
00192 {
00193 initColors();
00194 OConfig *c = OGlobal::config();
00195 OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") );
00196 return c->readColorEntry("HighlightColor", OpieHighlight);
00197 }
00198
00199 QColor OGlobalSettings::inactiveTitleColor()
00200 {
00201 if (!OpieGray) OpieGray = new QColor(220, 220, 220);
00202 OConfig *c = OGlobal::config();
00203 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
00204 return c->readColorEntry( "inactiveBackground", OpieGray );
00205 }
00206
00207 QColor OGlobalSettings::inactiveTextColor()
00208 {
00209 OConfig *c = OGlobal::config();
00210 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
00211 return c->readColorEntry( "inactiveForeground", &Qt::darkGray );
00212 }
00213
00214 QColor OGlobalSettings::activeTitleColor()
00215 {
00216 initColors();
00217 OConfig *c = OGlobal::config();
00218 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
00219 return c->readColorEntry( "activeBackground", OpieHighlight);
00220 }
00221
00222 QColor OGlobalSettings::activeTextColor()
00223 {
00224 OConfig *c = OGlobal::config();
00225 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
00226 return c->readColorEntry( "activeForeground", &Qt::white );
00227 }
00228
00229 int OGlobalSettings::contrast()
00230 {
00231 OConfig *c = OGlobal::config();
00232 OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") );
00233 return c->readNumEntry( "contrast", 7 );
00234 }
00235
00236
00237
00238 QColor OGlobalSettings::baseColor()
00239 {
00240 OConfig *c = OGlobal::config();
00241 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00242 return c->readColorEntry( "Base", &Qt::white );
00243 }
00244
00245 QColor OGlobalSettings::textColor()
00246 {
00247 OConfig *c = OGlobal::config();
00248 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00249 return c->readColorEntry( "Text", &Qt::black );
00250 }
00251
00252 QColor OGlobalSettings::highlightedTextColor()
00253 {
00254 OConfig *c = OGlobal::config();
00255 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00256 return c->readColorEntry( "HighlightedText", &Qt::white );
00257 }
00258
00259 QColor OGlobalSettings::highlightColor()
00260 {
00261 initColors();
00262 OConfig *c = OGlobal::config();
00263 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00264 return c->readColorEntry( "Highlight", OpieHighlight );
00265 }
00266
00267 QColor OGlobalSettings::alternateBackgroundColor()
00268 {
00269 initColors();
00270 OConfig *c = OGlobal::config();
00271 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00272 *OpieAlternate = calculateAlternateBackgroundColor( baseColor() );
00273 return c->readColorEntry( "alternateBackground", OpieAlternate );
00274 }
00275
00276 QColor OGlobalSettings::calculateAlternateBackgroundColor(const QColor& base)
00277 {
00278 if (base == Qt::white)
00279 return QColor(238,246,255);
00280 else
00281 {
00282 int h, s, v;
00283 base.hsv( &h, &s, &v );
00284 if (v > 128)
00285 return base.dark(106);
00286 else if (base != Qt::black)
00287 return base.light(110);
00288
00289 return QColor(32,32,32);
00290 }
00291 }
00292
00293 QColor OGlobalSettings::linkColor()
00294 {
00295 initColors();
00296 OConfig *c = OGlobal::config();
00297 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00298 return c->readColorEntry( "linkColor", OpieGray );
00299 }
00300
00301 QColor OGlobalSettings::visitedLinkColor()
00302 {
00303 OConfig *c = OGlobal::config();
00304 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00305 return c->readColorEntry( "visitedLinkColor", &Qt::magenta );
00306 }
00307
00308
00309
00310
00311
00312 QFont OGlobalSettings::generalFont()
00313 {
00314 if (_generalFont)
00315 return *_generalFont;
00316
00317 _generalFont = new QFont("helvetica", 10);
00318 _generalFont->setPixelSize(10);
00319 _generalFont->setStyleHint(QFont::SansSerif);
00320
00321 OConfig *c = OGlobal::config();
00322 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
00323 *_generalFont = c->readFontEntry("font", _generalFont);
00324
00325 return *_generalFont;
00326 }
00327
00328 QFont OGlobalSettings::fixedFont()
00329 {
00330 if (_fixedFont)
00331 return *_fixedFont;
00332
00333 _fixedFont = new QFont("courier", 12);
00334 _fixedFont->setPixelSize(12);
00335 _fixedFont->setStyleHint(QFont::TypeWriter);
00336
00337 OConfig *c = OGlobal::config();
00338 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
00339 *_fixedFont = c->readFontEntry("fixed", _fixedFont);
00340
00341 return *_fixedFont;
00342 }
00343
00344 QFont OGlobalSettings::toolBarFont()
00345 {
00346 if(_toolBarFont)
00347 return *_toolBarFont;
00348
00349 _toolBarFont = new QFont("helvetica", 10);
00350 _toolBarFont->setPixelSize(10);
00351 _toolBarFont->setStyleHint(QFont::SansSerif);
00352
00353 OConfig *c = OGlobal::config();
00354 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
00355 *_toolBarFont = c->readFontEntry("toolBarFont", _toolBarFont);
00356
00357 return *_toolBarFont;
00358 }
00359
00360 QFont OGlobalSettings::menuFont()
00361 {
00362 if(_menuFont)
00363 return *_menuFont;
00364
00365 _menuFont = new QFont("helvetica", 12);
00366 _menuFont->setPixelSize(12);
00367 _menuFont->setStyleHint(QFont::SansSerif);
00368
00369 OConfig *c = OGlobal::config();
00370 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
00371 *_menuFont = c->readFontEntry("menuFont", _menuFont);
00372
00373 return *_menuFont;
00374 }
00375
00376 QFont OGlobalSettings::windowTitleFont()
00377 {
00378 if(_windowTitleFont)
00379 return *_windowTitleFont;
00380
00381 _windowTitleFont = new QFont("helvetica", 12, QFont::Bold);
00382 _windowTitleFont->setPixelSize(12);
00383 _windowTitleFont->setStyleHint(QFont::SansSerif);
00384
00385 OConfig *c = OGlobal::config();
00386 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
00387 *_windowTitleFont = c->readFontEntry("activeFont", _windowTitleFont);
00388
00389 return *_windowTitleFont;
00390 }
00391
00392 QFont OGlobalSettings::taskbarFont()
00393 {
00394 if(_taskbarFont)
00395 return *_taskbarFont;
00396
00397 _taskbarFont = new QFont("helvetica", 8);
00398 _taskbarFont->setPixelSize(8);
00399 _taskbarFont->setStyleHint(QFont::SansSerif);
00400
00401 OConfig *c = OGlobal::config();
00402 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
00403 *_taskbarFont = c->readFontEntry("taskbarFont", _taskbarFont);
00404
00405 return *_taskbarFont;
00406 }
00407
00408
00409
00410 void OGlobalSettings::initStatic()
00411 {
00412 if ( s_desktopPath != 0 )
00413 return;
00414
00415 s_desktopPath = new QString();
00416 s_autostartPath = new QString();
00417 s_trashPath = new QString();
00418 s_documentPath = new QString();
00419
00420 OConfig *config = OGlobal::config();
00421
00422
00423 OConfigGroupSaver cgs( config, "Paths" );
00424
00425
00426 *s_desktopPath = QDir::homeDirPath() + "/" + "Desktop" + "/";
00427 *s_desktopPath = config->readEntry( "Desktop", *s_desktopPath);
00428 if ( (*s_desktopPath)[0] != '/' )
00429 s_desktopPath->prepend( QDir::homeDirPath() + "/" );
00430 *s_desktopPath = QDir::cleanDirPath( *s_desktopPath );
00431 if ( s_desktopPath->right(1) != "/")
00432 *s_desktopPath += "/";
00433
00434
00435 *s_trashPath = *s_desktopPath + QObject::tr("Trash") + "/";
00436 *s_trashPath = config->readEntry( "Trash" , *s_trashPath);
00437 if ( (*s_trashPath)[0] != '/' )
00438 s_trashPath->prepend( QDir::homeDirPath() + "/" );
00439 *s_trashPath = QDir::cleanDirPath( *s_trashPath );
00440 if ( s_trashPath->right(1) != "/")
00441 *s_trashPath += "/";
00442
00443 if ( !config->hasKey( "Trash" ) )
00444 {
00445
00446 config->writeEntry( "Trash", *s_trashPath );
00447
00448 }
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 *s_documentPath = QString::null;
00461 *s_documentPath = config->readEntry( "Documents" , *s_documentPath);
00462 if ( (*s_documentPath)[0] != '/' )
00463 s_documentPath->prepend( QDir::homeDirPath() + "/" );
00464 *s_documentPath = QDir::cleanDirPath( *s_documentPath );
00465 if ( s_documentPath->right(1) != "/")
00466 *s_documentPath += "/";
00467
00468
00469
00470
00471
00472
00473 }
00474
00475 void OGlobalSettings::initColors()
00476 {
00477 if ( !OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 );
00478 if ( !OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 );
00479 if ( !OpieGray ) OpieGray = new QColor( 220, 210, 215 );
00480 }
00481
00482 void OGlobalSettings::rereadFontSettings()
00483 {
00484 delete _generalFont;
00485 _generalFont = 0L;
00486 delete _fixedFont;
00487 _fixedFont = 0L;
00488 delete _menuFont;
00489 _menuFont = 0L;
00490 delete _toolBarFont;
00491 _toolBarFont = 0L;
00492 delete _windowTitleFont;
00493 _windowTitleFont = 0L;
00494 delete _taskbarFont;
00495 _taskbarFont = 0L;
00496 }
00497
00498 void OGlobalSettings::rereadPathSettings()
00499 {
00500 qDebug( "OGlobalSettings::rereadPathSettings" );
00501 delete s_autostartPath;
00502 s_autostartPath = 0L;
00503 delete s_trashPath;
00504 s_trashPath = 0L;
00505 delete s_desktopPath;
00506 s_desktopPath = 0L;
00507 delete s_documentPath;
00508 s_documentPath = 0L;
00509 }
00510
00511 OGlobalSettings::OMouseSettings & OGlobalSettings::mouseSettings()
00512 {
00513 if ( ! s_mouseSettings )
00514 {
00515 s_mouseSettings = new OMouseSettings;
00516 OMouseSettings & s = *s_mouseSettings;
00517
00518 OConfigGroupSaver cgs( OGlobal::config(), "Mouse" );
00519 QString setting = OGlobal::config()->readEntry("MouseButtonMapping");
00520 if (setting == "RightHanded")
00521 s.handed = OMouseSettings::RightHanded;
00522 else if (setting == "LeftHanded")
00523 s.handed = OMouseSettings::LeftHanded;
00524 else
00525 {
00526
00527
00528
00529 }
00530 }
00531 return *s_mouseSettings;
00532 }
00533
00534 void OGlobalSettings::rereadMouseSettings()
00535 {
00536 delete s_mouseSettings;
00537 s_mouseSettings = 0L;
00538 }
00539
00540
00541
00542 bool OGlobalSettings::isMultiHead()
00543 {
00544 QCString multiHead = getenv("OPIE_MULTIHEAD");
00545 if (!multiHead.isEmpty()) {
00546 return (multiHead.lower() == "true");
00547 }
00548 return false;
00549 }