diff --git a/src/browser.hxx b/src/browser.hxx index bfc47ff..4b57c66 100644 --- a/src/browser.hxx +++ b/src/browser.hxx @@ -68,7 +68,6 @@ class Browser: public QMainWindow, protected Ui::Browser { _url(0), _find(new qbrowserlib::ButtonLineEdit), _kiosk(kiosk), _downloadManager(new DownloadManager), - _settings(mimeTypes, this, settings, !kiosk), _errorLog(this), _logincertificate(this), _proxy("http://swisssign.com", this), _showErrorLog(0), @@ -77,7 +76,7 @@ class Browser: public QMainWindow, protected Ui::Browser { _searchEngines(new QComboBox), _bookmarkfile(bookmarkfile) { TRC; LOG<(_url)) qobject_cast(_url)->lineEdit()->setText(page); @@ -584,8 +588,8 @@ class Browser: public QMainWindow, protected Ui::Browser { void newSettings() { _searchEngines->clear(); for (qbrowserlib::Settings::SearchEngines::const_iterator - it(_settings.searchEngines().begin()); - it!=_settings.searchEngines().end(); it++) + it(qbrowserlib::Settings::instance().searchEngines().begin()); + it!=qbrowserlib::Settings::instance().searchEngines().end(); it++) if (QFile(":/icons/"+it.key()).exists()) _searchEngines->addItem(QIcon(":/icons/"+it.key()), "", it.value()); else @@ -854,7 +858,7 @@ class Browser: public QMainWindow, protected Ui::Browser { } void on_actionSettings_triggered() { - _settings.show(); + qbrowserlib::Settings::instance().show(); } void on_actionSaveWindowState_triggered() { @@ -868,14 +872,17 @@ class Browser: public QMainWindow, protected Ui::Browser { void saveWin() { TRC; LOG<<"Save Window State"; saveBookmarks(); - if (!_settings()) return; + if (!qbrowserlib::Settings::instance()()) return; QStringList tabs; for (int i(0); i<_tabs->count(); ++i) tabs<(_tabs->widget(i))->url().toString(); - _settings()->setValue("Window/Tabs", tabs); - _settings()->setValue("Window/CurrentTab", _tabs->currentIndex()); - _settings()->setValue("Window/Geometry", saveGeometry()); - _settings()->setValue("Window/WindowState", saveState()); + qbrowserlib::Settings::instance()()->setValue("Window/Tabs", tabs); + qbrowserlib::Settings::instance()() + ->setValue("Window/CurrentTab", _tabs->currentIndex()); + qbrowserlib::Settings::instance()() + ->setValue("Window/Geometry", saveGeometry()); + qbrowserlib::Settings::instance()() + ->setValue("Window/WindowState", saveState()); } void saveBookmarks() { @@ -889,17 +896,17 @@ class Browser: public QMainWindow, protected Ui::Browser { if (_bookmarkfile.writeable()) { LOG<<"write to bookmark file"<<_bookmarkfile.name(); _bookmarkfile.write(urls); - } else if (_settings()) { + } else if (qbrowserlib::Settings::instance()()) { LOG<<"write to settings"; - _settings()->setValue("Window/Urls", urls); + qbrowserlib::Settings::instance()()->setValue("Window/Urls", urls); } else LOG<<"bookmarks not saved"; } void loadWin() { TRC; loadBookmarks(); - if (!_settings()) return; - QStringList tabs(_settings()->value("Window/Tabs").toStringList()); + if (!qbrowserlib::Settings::instance()()) return; + QStringList tabs(qbrowserlib::Settings::instance()()->value("Window/Tabs").toStringList()); int oldCnt(_tabs->count()); for (QStringList::iterator it(tabs.begin()); it!=tabs.end(); ++it) { LOG<<"-------------------------------------------------------------"; @@ -909,9 +916,12 @@ class Browser: public QMainWindow, protected Ui::Browser { for (int i(0); icount()>1; ++i) _tabs->removeTab(0); _tabs->setTabsClosable(_tabs->count()>1); //_tabs->tabBar()->setShown(_tabs->count()>1); - _tabs->setCurrentIndex(_settings()->value("Window/CurrentTab").toInt()); - restoreGeometry(_settings()->value("Window/Geometry").toByteArray()); - restoreState(_settings()->value("Window/WindowState").toByteArray()); + _tabs->setCurrentIndex(qbrowserlib::Settings::instance()() + ->value("Window/CurrentTab").toInt()); + restoreGeometry(qbrowserlib::Settings::instance()() + ->value("Window/Geometry").toByteArray()); + restoreState(qbrowserlib::Settings::instance()() + ->value("Window/WindowState").toByteArray()); } void loadBookmarks() { @@ -920,9 +930,10 @@ class Browser: public QMainWindow, protected Ui::Browser { if (_bookmarkfile.readable()) { LOG<<"load from file"<<_bookmarkfile.name(); urls = _bookmarkfile.read(); - } else if (_settings()) { + } else if (qbrowserlib::Settings::instance()()) { LOG<<"load from settings"; - urls = _settings()->value("Window/Urls").toStringList(); + urls = qbrowserlib::Settings::instance()() + ->value("Window/Urls").toStringList(); } urls.removeAll(""); urls.removeDuplicates(); @@ -1369,7 +1380,7 @@ class Browser: public QMainWindow, protected Ui::Browser { } LOG<<"Filename:"<header(QNetworkRequest::ContentTypeHeader).toString(), filename)); } @@ -1524,7 +1535,6 @@ class Browser: public QMainWindow, protected Ui::Browser { QPrinter _printer; SslClientAuthNetworkAccessManager _networkManager; QSharedPointer _downloadManager; - qbrowserlib::Settings _settings; ErrorLog _errorLog; LoginCertificate _logincertificate; gui::Proxy _proxy; diff --git a/src/qbrowserlib/executor.hxx b/src/qbrowserlib/executor.hxx index 9d071c3..a1fa7d2 100644 --- a/src/qbrowserlib/executor.hxx +++ b/src/qbrowserlib/executor.hxx @@ -31,13 +31,13 @@ namespace qbrowserlib { private: - Executor(Settings* settings=0): _settings(settings) {} // singleton + Executor() {} // singleton Executor(const Executor&); // singleton public: - static Executor& instance(Settings* settings=0) { - static Executor _instance(settings); + static Executor& instance() { + static Executor _instance; return _instance; } @@ -46,10 +46,11 @@ namespace qbrowserlib { for (DownloadProcesses::iterator it(_downloadProcesses.begin()); it!=_downloadProcesses.end(); ++it) { LOG<<"cleanup:"<second->fileName(); - it->second->setAutoRemove(_settings && _settings->flag("CloseApps")); + it->second->setAutoRemove(qbrowserlib::Settings::instance() + .flag("CloseApps")); delete it->second; it->second = 0; - if (_settings && _settings->flag("CloseApps")) { + if (qbrowserlib::Settings::instance().flag("CloseApps")) { LOG<<"terminate process"; it->first->terminate(); delete it->first; @@ -57,10 +58,6 @@ namespace qbrowserlib { } } - Settings* settings() { - return _settings; - } - public Q_SLOTS: void run(QNetworkReply* reply, QString filename, QString command) { @@ -107,7 +104,8 @@ namespace qbrowserlib { == _downloadProcesses.end()) return; if (_downloadProcesses[qobject_cast(sender())]) _downloadProcesses[qobject_cast(sender())] - ->setAutoRemove(_settings && _settings->flag("CloseApps")); + ->setAutoRemove(qbrowserlib::Settings::instance() + .flag("CloseApps")); delete _downloadProcesses[qobject_cast(sender())]; _downloadProcesses.erase(qobject_cast(sender())); applicationFinished(); @@ -117,7 +115,6 @@ namespace qbrowserlib { typedef std::map DownloadProcesses; DownloadProcesses _downloadProcesses; - Settings* _settings; QNetworkReply* _reply; QString _filename; QString _command; diff --git a/src/qbrowserlib/saveorrun.hxx b/src/qbrowserlib/saveorrun.hxx index b1ce0ee..fe9ddd6 100644 --- a/src/qbrowserlib/saveorrun.hxx +++ b/src/qbrowserlib/saveorrun.hxx @@ -60,7 +60,7 @@ namespace qbrowserlib { TRC; QString filename(remoteFilename()); QStringList type - (qbrowserlib::Executor::instance().settings()->mimetype + (qbrowserlib::Settings::instance().mimetype (_reply->header(QNetworkRequest::ContentTypeHeader).toString(), filename)); if (!type.isEmpty()) { diff --git a/src/qbrowserlib/settings.hxx b/src/qbrowserlib/settings.hxx index 9ef2512..2283835 100644 --- a/src/qbrowserlib/settings.hxx +++ b/src/qbrowserlib/settings.hxx @@ -36,6 +36,17 @@ namespace qbrowserlib { public: + //! Singleton + static Settings& instance(MimeTypes mimetypes=MimeTypes(), QWidget* p=0, + QSettings* settings=0, bool autoWrite=true) { + static Settings _instance(mimetypes, p, settings, autoWrite); + return _instance; + } + + private: + + Settings(const Settings&); // singleton + Settings(MimeTypes mimetypes, QWidget* p=0, QSettings* settings=0, bool autoWrite=true): QDialog(p), _settings(settings), @@ -114,6 +125,8 @@ namespace qbrowserlib { on__buttons_rejected(); } + public: + static bool DEBUG; void setSettings(QSettings* settings) {