From 4c1a3965478889e5cc4f184284e2fc51a9a6a7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Tue, 17 Apr 2012 14:50:35 +0000 Subject: [PATCH] support bookmark-file; refs #116 --- src/browser.hxx | 58 +++++++++++++++---------- src/editbookmarks.hxx | 2 +- src/main.cxx | 7 ++- src/qbrowserlib/filestorage.hxx | 72 +++++++++++++++++++++++++++++++ src/qbrowserlib/qbrowserlib_de.ts | 69 ++++++++++++++++++----------- src/qbrowserlib/qbrowserlib_en.ts | 69 ++++++++++++++++++----------- src/qbrowserlib/qbrowserlib_fr.ts | 69 ++++++++++++++++++----------- src/qbrowserlib/qbrowserlib_it.ts | 69 ++++++++++++++++++----------- src/qbrowserlib/qmake.pro.in | 3 +- src/swissbrowser_de.ts | 2 + src/swissbrowser_en.ts | 2 + src/swissbrowser_fr.ts | 2 + src/swissbrowser_it.ts | 2 + 13 files changed, 305 insertions(+), 121 deletions(-) create mode 100644 src/qbrowserlib/filestorage.hxx diff --git a/src/browser.hxx b/src/browser.hxx index 90cc1f1..2516949 100644 --- a/src/browser.hxx +++ b/src/browser.hxx @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -66,7 +67,8 @@ class Browser: public QMainWindow, protected Ui::Browser { Browser(const QString& actlib, const QStringList& urls = QStringList(), QSettings* settings=0, Settings::MimeTypes mimeTypes = Settings::MimeTypes(), - bool kiosk = false, bool login = true, bool quirks=true): + bool kiosk = false, bool login = true, bool quirks=true, + QString bookmarkfile=QString()): _url(0), _find(new ButtonLineEdit), _kiosk(kiosk), _downloadManager(new DownloadManager), @@ -76,7 +78,8 @@ class Browser: public QMainWindow, protected Ui::Browser { _showErrorLog(0), _startUrl(urls.size()), _quirks(quirks), _search(new ButtonLineEdit), - _searchEngines(new QComboBox) { + _searchEngines(new QComboBox), + _bookmarkfile(bookmarkfile) { LOG<(_url)) - for (int i(0); i(_url)->count(); ++i) - urls<(_url)->itemText(i); - _settings()->setValue("Window/Urls", urls); + saveBookmarks(); QStringList tabs; for (int i(0); i<_tabs->count(); ++i) tabs<(_tabs->widget(i))->url().toString(); @@ -858,23 +857,19 @@ class Browser: public QMainWindow, protected Ui::Browser { _settings()->setValue("Window/WindowState", saveState()); } + void saveBookmarks() { + QStringList urls; + if (qobject_cast(_url)) + for (int i(0); i(_url)->count(); ++i) + urls<(_url)->itemText(i); + if (!(_bookmarkfile.writeable() && _bookmarkfile.write(urls)) + && _settings()) + _settings()->setValue("Window/Urls", urls); + } + void loadWin() { LOG; - QStringList urls(_settings()->value("Window/Urls").toStringList()); - urls.sort(); - urls.removeDuplicates(); - if (qobject_cast(_url)) { - qobject_cast(_url)->clear(); - qobject_cast(_url)->addItems(urls); - } - if (_bookmarks) { - _bookmarks->clear(); - for (QStringList::iterator it(urls.begin()); it!=urls.end(); ++it) { - QAction* a(_bookmarks->addAction(*it)); - a->setData(*it); - connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory())); - } - } + loadBookmarks(); QStringList tabs(_settings()->value("Window/Tabs").toStringList()); int oldCnt(_tabs->count()); for (QStringList::iterator it(tabs.begin()); it!=tabs.end(); ++it) { @@ -888,6 +883,24 @@ class Browser: public QMainWindow, protected Ui::Browser { restoreGeometry(_settings()->value("Window/Geometry").toByteArray()); restoreState(_settings()->value("Window/WindowState").toByteArray()); } + + void loadBookmarks() { + QStringList urls(_bookmarkfile.readable() + ?_bookmarkfile.read() + :_settings()->value("Window/Urls").toStringList()); + if (qobject_cast(_url)) { + qobject_cast(_url)->clear(); + qobject_cast(_url)->addItems(urls); + } + if (_bookmarks) { + _bookmarks->clear(); + for (QStringList::iterator it(urls.begin()); it!=urls.end(); ++it) { + QAction* a(_bookmarks->addAction(*it)); + a->setData(*it); + connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory())); + } + } + } //@name QWebView slots //@{ @@ -1549,6 +1562,7 @@ class Browser: public QMainWindow, protected Ui::Browser { bool _quirks; ButtonLineEdit* _search; QComboBox* _searchEngines; + FileStorage _bookmarkfile; }; //! @} diff --git a/src/editbookmarks.hxx b/src/editbookmarks.hxx index 70fad7d..e9bde02 100644 --- a/src/editbookmarks.hxx +++ b/src/editbookmarks.hxx @@ -32,7 +32,7 @@ class EditBookmarks: public QDialog, protected Ui::EditBookmarks { QString current(_url->currentText()); _url->clear(); _url->addItems(urls); - _url->lineEdit()->setText(current); + _url->setEditText(current); QDialog::accept(); } virtual void reject() { diff --git a/src/main.cxx b/src/main.cxx index 17b44d5..63785a3 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -333,6 +333,7 @@ int main(int argv, char** argc) try { bool quirks(false); bool login(false); Settings::MimeTypes mimetypes; + QString bookmarks; QStringList args(app.arguments()); std::auto_ptr settings (std::auto_ptr(new QSettings("SwissSign", "SwissBrowser"))); @@ -356,6 +357,8 @@ int main(int argv, char** argc) try { " -y, --key load local certificate key from \n" " -m, --mime \n" " start for mimetype \n" + " -b, --bookmarks \n" + " load and save bookmarks from and to \n" " optional full URL\n" "Environment:\n" " LANGUAGE \"de\", \"en\", ... (actual: %5)\n" @@ -382,6 +385,8 @@ int main(int argv, char** argc) try { login = true; } else if ((*it=="-l" || *it=="--lib") && ++it!=args.end()) { actlib = *it; + } else if ((*it=="-b" || *it=="--bookmarks") && ++it!=args.end()) { + bookmarks = *it; } else if ((*it=="-s" || *it=="--settings") && ++it!=args.end()) { settings = std::auto_ptr (new QSettings(*it, QSettings::IniFormat)); @@ -427,7 +432,7 @@ int main(int argv, char** argc) try { //............................................................................ if (env.contains("QTWEBKIT_PLUGIN_PATH")) qt_drt_overwritePluginDirectories(); Browser browser(actlib, urls, settings.get(), mimetypes, silent, - login, quirks); + login, quirks, bookmarks); return app.exec(); } catch (std::exception& x) { std::cerr<<"**** Error: "< +#include +#include +#include +#include + +#include + +class Storage: public QObject { + Q_OBJECT; + Q_SIGNALS: + void changed(); + public: + Storage() {} + bool valid() { + return readable() || writeable(); + } + operator bool() { + return valid(); + } + virtual bool readable() = 0; + virtual bool writeable() = 0; + virtual QStringList read() = 0; + virtual bool write(const QStringList& out) = 0; +}; + +class FileStorage: public Storage { + Q_OBJECT; + public: + FileStorage(QString file): _file(file) { + if (valid()) { + assert(connect(new QFileSystemWatcher(QStringList()<<_file.fileName(), + this), + SIGNAL(fileChanged(const QString&)), + SLOT(changed()))); + } + } + bool readable() { + return QFileInfo(_file).exists(); + } + bool writeable() { + return readable() || !_file.fileName().isEmpty(); + } + QStringList read() { + QStringList res; + if (readable()) { + if (_file.open(QIODevice::ReadOnly)) + res=QString::fromUtf8(_file.readAll()).split("\n"); + _file.close(); + } + return res; + } + bool write(const QStringList& out) { + bool res(false); + if (writeable()) { + if (_file.open(QIODevice::WriteOnly)) + if (_file.write(out.join("\n").toUtf8())>=0) res=true; + _file.close(); + } + return res; + } + private: + QFile _file; +}; + diff --git a/src/qbrowserlib/qbrowserlib_de.ts b/src/qbrowserlib/qbrowserlib_de.ts index 6f29764..671884c 100644 --- a/src/qbrowserlib/qbrowserlib_de.ts +++ b/src/qbrowserlib/qbrowserlib_de.ts @@ -5,81 +5,102 @@ SaveOrRun - File Exists + + Download - File already exists: - -%1 - -Overwrite? + + File: - Save File As ... + + + + ... - Open File With ... + + Type: - Dokumente - Documents folder in local language + + Source - Arbeitsfläche - Desktop folder in local language + + Save File - Download + + Save File As: - File: + + + browse ... - ... + + remember save path - Type: + + Open in External Application - Source + + Open File in: - Save File + + remember tool for this type - Save File As: + + File Exists - browse ... + + File already exists: + +%1 + +Overwrite? - remember save path + + Save File As ... - Open in External Application + + Open File With ... - Open File in: + + Dokumente + Documents folder in local language - remember tool for this type + + Arbeitsfläche + Desktop folder in local language diff --git a/src/qbrowserlib/qbrowserlib_en.ts b/src/qbrowserlib/qbrowserlib_en.ts index 933c010..af9b752 100644 --- a/src/qbrowserlib/qbrowserlib_en.ts +++ b/src/qbrowserlib/qbrowserlib_en.ts @@ -5,81 +5,102 @@ SaveOrRun - File Exists + + Download - File already exists: - -%1 - -Overwrite? + + File: - Save File As ... + + + + ... - Open File With ... + + Type: - Dokumente - Documents folder in local language + + Source - Arbeitsfläche - Desktop folder in local language + + Save File - Download + + Save File As: - File: + + + browse ... - ... + + remember save path - Type: + + Open in External Application - Source + + Open File in: - Save File + + remember tool for this type - Save File As: + + File Exists - browse ... + + File already exists: + +%1 + +Overwrite? - remember save path + + Save File As ... - Open in External Application + + Open File With ... - Open File in: + + Dokumente + Documents folder in local language - remember tool for this type + + Arbeitsfläche + Desktop folder in local language diff --git a/src/qbrowserlib/qbrowserlib_fr.ts b/src/qbrowserlib/qbrowserlib_fr.ts index e39e1b7..29a594e 100644 --- a/src/qbrowserlib/qbrowserlib_fr.ts +++ b/src/qbrowserlib/qbrowserlib_fr.ts @@ -5,81 +5,102 @@ SaveOrRun - File Exists + + Download - File already exists: - -%1 - -Overwrite? + + File: - Save File As ... + + + + ... - Open File With ... + + Type: - Dokumente - Documents folder in local language + + Source - Arbeitsfläche - Desktop folder in local language + + Save File - Download + + Save File As: - File: + + + browse ... - ... + + remember save path - Type: + + Open in External Application - Source + + Open File in: - Save File + + remember tool for this type - Save File As: + + File Exists - browse ... + + File already exists: + +%1 + +Overwrite? - remember save path + + Save File As ... - Open in External Application + + Open File With ... - Open File in: + + Dokumente + Documents folder in local language - remember tool for this type + + Arbeitsfläche + Desktop folder in local language diff --git a/src/qbrowserlib/qbrowserlib_it.ts b/src/qbrowserlib/qbrowserlib_it.ts index d6b37f8..b688233 100644 --- a/src/qbrowserlib/qbrowserlib_it.ts +++ b/src/qbrowserlib/qbrowserlib_it.ts @@ -5,81 +5,102 @@ SaveOrRun - File Exists + + Download - File already exists: - -%1 - -Overwrite? + + File: - Save File As ... + + + + ... - Open File With ... + + Type: - Dokumente - Documents folder in local language + + Source - Arbeitsfläche - Desktop folder in local language + + Save File - Download + + Save File As: - File: + + + browse ... - ... + + remember save path - Type: + + Open in External Application - Source + + Open File in: - Save File + + remember tool for this type - Save File As: + + File Exists - browse ... + + File already exists: + +%1 + +Overwrite? - remember save path + + Save File As ... - Open in External Application + + Open File With ... - Open File in: + + Dokumente + Documents folder in local language - remember tool for this type + + Arbeitsfläche + Desktop folder in local language diff --git a/src/qbrowserlib/qmake.pro.in b/src/qbrowserlib/qmake.pro.in index 5fdf1d9..c87b3a6 100644 --- a/src/qbrowserlib/qmake.pro.in +++ b/src/qbrowserlib/qmake.pro.in @@ -38,7 +38,8 @@ SOURCES = HEADERS = @srcdir@/swisswebview.hxx @srcdir@/swisswebpage.hxx \ @srcdir@/pluginfactory.hxx @srcdir@/saveorrun.hxx \ - @srcdir@/buttonlineedit.hxx + @srcdir@/buttonlineedit.hxx \ + @srcdir@/filestorage.hxx FORMS = @srcdir@/saveorrun.ui diff --git a/src/swissbrowser_de.ts b/src/swissbrowser_de.ts index 7f8052d..64fa2f9 100644 --- a/src/swissbrowser_de.ts +++ b/src/swissbrowser_de.ts @@ -730,6 +730,8 @@ Options: -y, --key <file> load local certificate key from <file> -m, --mime <mime> <ext> <tool> start <tool> for mimetype <mime> + -b, --bookmarks <file> + load and save bookmarks from and to <file> <url> optional full URL Environment: LANGUAGE "de", "en", ... (actual: %5) diff --git a/src/swissbrowser_en.ts b/src/swissbrowser_en.ts index 56e3c1f..0989fd4 100644 --- a/src/swissbrowser_en.ts +++ b/src/swissbrowser_en.ts @@ -730,6 +730,8 @@ Options: -y, --key <file> load local certificate key from <file> -m, --mime <mime> <ext> <tool> start <tool> for mimetype <mime> + -b, --bookmarks <file> + load and save bookmarks from and to <file> <url> optional full URL Environment: LANGUAGE "de", "en", ... (actual: %5) diff --git a/src/swissbrowser_fr.ts b/src/swissbrowser_fr.ts index 7f8052d..64fa2f9 100644 --- a/src/swissbrowser_fr.ts +++ b/src/swissbrowser_fr.ts @@ -730,6 +730,8 @@ Options: -y, --key <file> load local certificate key from <file> -m, --mime <mime> <ext> <tool> start <tool> for mimetype <mime> + -b, --bookmarks <file> + load and save bookmarks from and to <file> <url> optional full URL Environment: LANGUAGE "de", "en", ... (actual: %5) diff --git a/src/swissbrowser_it.ts b/src/swissbrowser_it.ts index c54fa5c..eeb9cbb 100644 --- a/src/swissbrowser_it.ts +++ b/src/swissbrowser_it.ts @@ -730,6 +730,8 @@ Options: -y, --key <file> load local certificate key from <file> -m, --mime <mime> <ext> <tool> start <tool> for mimetype <mime> + -b, --bookmarks <file> + load and save bookmarks from and to <file> <url> optional full URL Environment: LANGUAGE "de", "en", ... (actual: %5)