2 * This file is a part of QComicBook.
4 * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
6 * QComicBook is free software; you can redestribute it and/or modify it
7 * under terms of GNU General Public License by Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY. See GPL for more details.
13 #include "cbsettings.h"
17 #include <qsettings.h>
21 #include <qtextstream.h>
22 #include <qmainwindow.h>
24 #define GRP_VIEW "/View"
25 #define OPT_TWOPAGES "/TwoPages"
26 #define OPT_JAPANESEMODE "/JapaneseMode"
27 #define OPT_SCROLLBARS "/Scrollbars"
28 //#define OPT_SCALING "/Scaling"
29 #define OPT_PAGESIZE "/PageSize"
30 #define OPT_BACKGROUND "/Background"
31 #define OPT_FULLSCREENHIDEMENU "/FullScreenHideMenu"
32 #define OPT_FULLSCREENHIDESTATUS "/FullScreenHideStatusbar"
33 #define OPT_FULLSCREENHIDETOOLBAR "/FullScreenHideToolbar"
34 #define OPT_STATUSBAR "/Statusbar"
35 #define OPT_FONT "/InfoFont"
36 #define OPT_SMALLCURSOR "/SmallCursor"
38 #define GRP_NAVI "/Navigation"
39 #define OPT_CONTSCROLL "/ContinuousScroll"
40 #define OPT_TWOPAGESSTEP "/TwoPagesStep"
42 #define OPT_STRIPMODE "/StripMode"
43 #define OPT_STRIPMAX "/StripMax"
45 #define GRP_WINDOW "/Window"
48 #define OPT_WIDTH "/Width"
49 #define OPT_HEIGHT "/Height"
50 #define OPT_DOCKLAYOUT "/DockLayout"
52 #define GRP_MISC "/Misc"
53 #define OPT_AUTOINFO "/InfoDialog"
54 #define OPT_LASTDIR "/LastDir"
55 #define OPT_RECENT "/RecentlyOpened"
56 #define OPT_CACHESIZE "/CacheSize"
57 #define OPT_THUMBSAGE "/ThumbnailsAge"
58 #define OPT_CACHETHUMBS "/CacheThumbnails"
59 #define OPT_PRELOAD "/Preload"
60 #define OPT_CONFIRMEXIT "/ConfirmExit"
61 #define OPT_SHOWSPLASH "/ShowSplashscreen"
62 #define OPT_INTBROWSER "/UseIntBrowser"
63 #define OPT_EXTBROWSER "/ExtBrowserCmd"
64 #define OPT_EDITING "/Editing"
65 #define OPT_TMPDIR "/TmpDir"
68 using namespace QComicBook;
70 QString ComicBookSettings::bkpath = QString::null;
71 QString ComicBookSettings::thpath = QString::null;
72 bool ComicBookSettings::dirsok = false;
74 const EnumMap<Size> ComicBookSettings::size2string[] = {
75 {"original", Original},
76 {"fitwidth", FitWidth},
77 {"fitheight", FitHeight},
78 {"wholepage", WholePage},
83 /*const EnumMap<Scaling> ComicBookSettings::scaling2string[] = {
89 ComicBookSettings& ComicBookSettings::instance()
91 static ComicBookSettings cfg;
95 ComicBookSettings::ComicBookSettings(): QObject()
97 cfg = new QSettings();
98 cfg->insertSearchPath(QSettings::Unix, QDir::homeDirPath() + "/.qcomicbook");
99 cfg->beginGroup("/QComicBook");
102 ComicBookSettings::~ComicBookSettings()
108 bool ComicBookSettings::checkDirs()
111 bkpath = QDir::homeDirPath() + "/.qcomicbook";
114 if (!dir.mkdir(bkpath))
117 dir.setPath(thpath = bkpath + "/cache");
119 if (!dir.mkdir(thpath))
121 return dirsok = true;
124 const QString& ComicBookSettings::bookmarksDir()
129 const QString& ComicBookSettings::thumbnailsDir()
134 void ComicBookSettings::load()
136 QString defbrowser(QString::null);
139 const char *browsers[] = {"firefox", "mozilla", "konqueror", "opera", NULL};
140 for (int i=0; browsers[i]; i++)
141 if (QString path = QComicBook::which(browsers[i]))
147 cfg->beginGroup(GRP_WINDOW);
148 x = cfg->readNumEntry(OPT_X, 0);
149 y = cfg->readNumEntry(OPT_Y, 0);
150 w = cfg->readNumEntry(OPT_WIDTH, 640);
151 h = cfg->readNumEntry(OPT_HEIGHT, 400);
152 docklayout = cfg->readEntry(OPT_DOCKLAYOUT, QString::null);
154 cfg->beginGroup(GRP_VIEW);
155 smallcursor = cfg->readBoolEntry(OPT_SMALLCURSOR, false);
156 twopages = cfg->readBoolEntry(OPT_TWOPAGES, false);
157 stripmode = cfg->readBoolEntry(OPT_STRIPMODE, true);
158 stripmax = cfg->readNumEntry(OPT_STRIPMAX, 7);
159 japanese = cfg->readBoolEntry(OPT_JAPANESEMODE, false);
160 scrollbars = cfg->readBoolEntry(OPT_SCROLLBARS, false);
161 //scaling = convert(scaling2string, cfg->readEntry(OPT_SCALING, size2string[0].str));
162 pagesize = convert(size2string, cfg->readEntry(OPT_PAGESIZE, size2string[0].str));
163 bgcolor.setNamedColor(cfg->readEntry(OPT_BACKGROUND, "#000000"));
164 fscrhidemenu = cfg->readBoolEntry(OPT_FULLSCREENHIDEMENU, true);
165 fscrhidestatus = cfg->readBoolEntry(OPT_FULLSCREENHIDESTATUS, true);
166 fscrhidetoolbar = cfg->readBoolEntry(OPT_FULLSCREENHIDETOOLBAR, false);
167 statusbar = cfg->readBoolEntry(OPT_STATUSBAR, true);
168 fontdesc = cfg->readEntry(OPT_FONT, QString::null);
169 if (fontdesc.isNull() || !font.fromString(fontdesc))
171 font.setFamily("Courier");
172 font.setPointSize(10);
175 cfg->beginGroup(GRP_NAVI);
176 contscroll = cfg->readBoolEntry(OPT_CONTSCROLL, true);
177 twopagesstep = cfg->readBoolEntry(OPT_TWOPAGESSTEP, true);
179 cfg->beginGroup(GRP_MISC);
180 lastdir = cfg->readEntry(OPT_LASTDIR, QString::null);
181 recent = cfg->readListEntry(OPT_RECENT);
182 cachesize = cfg->readNumEntry(OPT_CACHESIZE, 3);
185 preload = cfg->readBoolEntry(OPT_PRELOAD, true);
186 confirmexit = cfg->readBoolEntry(OPT_CONFIRMEXIT, true);
187 intbrowser = cfg->readBoolEntry(OPT_INTBROWSER, true);
188 extbrowser = cfg->readEntry(OPT_EXTBROWSER, defbrowser);
189 autoinfo = cfg->readBoolEntry(OPT_AUTOINFO, false);
190 showsplash = cfg->readBoolEntry(OPT_SHOWSPLASH, true);
191 thumbsage = cfg->readNumEntry(OPT_THUMBSAGE, 7);
192 cachethumbs = cfg->readBoolEntry(OPT_CACHETHUMBS, true);
193 editsupport = cfg->readBoolEntry(OPT_EDITING, false);
194 tmpdir = cfg->readEntry(OPT_TMPDIR, QString::null);
196 if (tmpdir.isNull() || !dir.exists())
201 bool ComicBookSettings::smallCursor() const
206 bool ComicBookSettings::twoPagesMode() const
211 bool ComicBookSettings::twoPagesStep() const
216 bool ComicBookSettings::japaneseMode() const
221 bool ComicBookSettings::continuousScrolling() const
226 bool ComicBookSettings::scrollbarsVisible() const
231 QRect ComicBookSettings::geometry() const
233 return QRect(x, y, w, h);
236 Size ComicBookSettings::pageSize() const
241 /*Scaling ComicBookSettings::pageScaling() const
246 QString ComicBookSettings::lastDir() const
251 const History& ComicBookSettings::recentlyOpened() const
256 QColor ComicBookSettings::background() const
261 int ComicBookSettings::cacheSize() const
266 bool ComicBookSettings::cacheThumbnails() const
271 int ComicBookSettings::thumbnailsAge() const
276 bool ComicBookSettings::preloadPages() const
281 bool ComicBookSettings::confirmExit() const
286 bool ComicBookSettings::autoInfo() const
291 bool ComicBookSettings::fullScreenHideMenu() const
296 bool ComicBookSettings::fullScreenHideStatusbar() const
298 return fscrhidestatus;
301 bool ComicBookSettings::fullScreenHideToolbar() const
303 return fscrhidetoolbar;
306 bool ComicBookSettings::showStatusbar() const
311 const QFont& ComicBookSettings::infoFont() const
316 bool ComicBookSettings::useInternalBrowser() const
321 QString ComicBookSettings::externalBrowser() const
326 bool ComicBookSettings::showSplash() const
331 void ComicBookSettings::restoreDockLayout(QMainWindow *w)
333 QTextStream str(&docklayout, IO_ReadOnly);
337 bool ComicBookSettings::editSupport() const
342 QString ComicBookSettings::tmpDir() const
347 void ComicBookSettings::smallCursor(bool f)
349 if (f != smallcursor)
351 cfg->writeEntry(GRP_VIEW OPT_SMALLCURSOR, smallcursor = f);
352 emit cursorChanged(f);
356 void ComicBookSettings::twoPagesMode(bool f)
359 cfg->writeEntry(GRP_VIEW OPT_TWOPAGES, twopages = f);
362 void ComicBookSettings::twoPagesStep(bool f)
364 if (f != twopagesstep)
365 cfg->writeEntry(GRP_NAVI OPT_TWOPAGESSTEP, twopagesstep = f);
368 void ComicBookSettings::japaneseMode(bool f)
371 cfg->writeEntry(GRP_VIEW OPT_JAPANESEMODE, japanese = f);
374 void ComicBookSettings::continuousScrolling(bool f)
377 cfg->writeEntry(GRP_NAVI OPT_CONTSCROLL, contscroll = f);
380 void ComicBookSettings::scrollbarsVisible(bool f)
383 cfg->writeEntry(GRP_VIEW OPT_SCROLLBARS, scrollbars = f);
386 void ComicBookSettings::geometry(const QRect g)
388 if (x != g.x() || y != g.y() || w != g.width() || h != g.height())
390 cfg->beginGroup(GRP_WINDOW);
391 cfg->writeEntry(OPT_X, x = g.x());
392 cfg->writeEntry(OPT_Y, y = g.y());
393 cfg->writeEntry(OPT_WIDTH, w = g.width());
394 cfg->writeEntry(OPT_HEIGHT, h = g.height());
399 void ComicBookSettings::pageSize(Size s)
402 cfg->writeEntry(GRP_VIEW OPT_PAGESIZE, convert(size2string, pagesize = s));
405 /*void ComicBookSettings::pageScaling(Scaling s)
409 cfg->writeEntry(GRP_VIEW OPT_SCALING, convert(scaling2string, scaling = s));
410 emit scalingMethodChanged(scaling);
414 void ComicBookSettings::lastDir(const QString &d)
417 cfg->writeEntry(GRP_MISC OPT_LASTDIR, lastdir = d);
420 void ComicBookSettings::recentlyOpened(const History &hist)
423 cfg->writeEntry(GRP_MISC OPT_RECENT, recent.getAll());
426 void ComicBookSettings::background(const QColor &color)
428 if (color != bgcolor)
431 cfg->writeEntry(GRP_VIEW OPT_BACKGROUND, bgcolor.name());
432 emit backgroundChanged(bgcolor);
436 void ComicBookSettings::cacheSize(int s)
442 cfg->writeEntry(GRP_MISC OPT_CACHESIZE, cachesize = s);
446 void ComicBookSettings::cacheThumbnails(bool f)
448 if (f != cachethumbs)
449 cfg->writeEntry(GRP_MISC OPT_CACHETHUMBS, cachethumbs = f);
452 void ComicBookSettings::thumbnailsAge(int n)
455 cfg->writeEntry(GRP_MISC OPT_THUMBSAGE, thumbsage = n);
458 void ComicBookSettings::preloadPages(bool f)
461 cfg->writeEntry(GRP_MISC OPT_PRELOAD, preload = f);
464 void ComicBookSettings::confirmExit(bool f)
466 if (f != confirmexit)
467 cfg->writeEntry(GRP_MISC OPT_CONFIRMEXIT, confirmexit = f);
470 void ComicBookSettings::autoInfo(bool f)
473 cfg->writeEntry(GRP_MISC OPT_AUTOINFO, autoinfo = f);
476 void ComicBookSettings::fullScreenHideMenu(bool f)
478 if (f != fscrhidemenu)
479 cfg->writeEntry(GRP_VIEW OPT_FULLSCREENHIDEMENU, fscrhidemenu = f);
482 void ComicBookSettings::fullScreenHideStatusbar(bool f)
484 if (f != fscrhidestatus)
485 cfg->writeEntry(GRP_VIEW OPT_FULLSCREENHIDESTATUS, fscrhidestatus = f);
488 void ComicBookSettings::fullScreenHideToolbar(bool f)
490 if (f != fscrhidetoolbar)
491 cfg->writeEntry(GRP_VIEW OPT_FULLSCREENHIDETOOLBAR, fscrhidetoolbar = f);
494 void ComicBookSettings::showStatusbar(bool f)
497 cfg->writeEntry(GRP_VIEW OPT_STATUSBAR, statusbar = f);
500 void ComicBookSettings::infoFont(const QFont &s)
505 cfg->writeEntry(GRP_VIEW OPT_FONT, font.toString());
509 void ComicBookSettings::useInternalBrowser(bool f)
512 cfg->writeEntry(GRP_MISC OPT_INTBROWSER, intbrowser = f);
515 void ComicBookSettings::externalBrowser(const QString& cmd)
517 if (cmd != extbrowser)
518 cfg->writeEntry(GRP_MISC OPT_EXTBROWSER, extbrowser = cmd);
521 void ComicBookSettings::saveDockLayout(QMainWindow *w)
524 QTextStream str(&tmp, IO_WriteOnly);
526 cfg->writeEntry(GRP_WINDOW OPT_DOCKLAYOUT, tmp);
529 void ComicBookSettings::editSupport(bool f)
531 if (f != editsupport)
532 cfg->writeEntry(GRP_MISC OPT_EDITING, editsupport = f);
535 void ComicBookSettings::showSplash(bool f)
538 cfg->writeEntry(GRP_MISC OPT_SHOWSPLASH, showsplash = f);
541 void ComicBookSettings::tmpDir(const QString &dir)
544 cfg->writeEntry(GRP_MISC OPT_TMPDIR, tmpdir = dir);
548 bool ComicBookSettings::stripMode() const
553 int ComicBookSettings::stripMax() const
558 void ComicBookSettings::stripMode(bool f)
561 cfg->writeEntry(GRP_VIEW OPT_STRIPMODE, stripmode = f);
564 void ComicBookSettings::stripMax(int sm)
567 cfg->writeEntry(GRP_VIEW OPT_STRIPMAX, stripmax = sm);
568 emit stripMaxChanged(sm);