support bookmark-file; refs #116
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <ui_browser.h>
|
||||
|
||||
#include <qbrowserlib/buttonlineedit.hxx>
|
||||
#include <qbrowserlib/filestorage.hxx>
|
||||
#include <qbrowserlib/swisswebview.hxx>
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
@@ -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<<urls;
|
||||
_home = "about:blank";
|
||||
if (urls.size()) _home = urls.at(0);
|
||||
@@ -844,11 +847,7 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
void saveWin() {
|
||||
LOG<<"Save Window State";
|
||||
if (!_settings()) return;
|
||||
QStringList urls;
|
||||
if (qobject_cast<QComboBox*>(_url))
|
||||
for (int i(0); i<qobject_cast<QComboBox*>(_url)->count(); ++i)
|
||||
urls<<qobject_cast<QComboBox*>(_url)->itemText(i);
|
||||
_settings()->setValue("Window/Urls", urls);
|
||||
saveBookmarks();
|
||||
QStringList tabs;
|
||||
for (int i(0); i<_tabs->count(); ++i)
|
||||
tabs<<qobject_cast<QWebView*>(_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<QComboBox*>(_url))
|
||||
for (int i(0); i<qobject_cast<QComboBox*>(_url)->count(); ++i)
|
||||
urls<<qobject_cast<QComboBox*>(_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<QComboBox*>(_url)) {
|
||||
qobject_cast<QComboBox*>(_url)->clear();
|
||||
qobject_cast<QComboBox*>(_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<QComboBox*>(_url)) {
|
||||
qobject_cast<QComboBox*>(_url)->clear();
|
||||
qobject_cast<QComboBox*>(_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;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
Reference in New Issue
Block a user