tested except for the changed event; refs #116

master
Marc Wäckerlin 13 years ago
parent 60af8e2687
commit 9802fa5b1d
  1. 24
      src/browser.hxx
  2. 3
      src/editbookmarks.ui
  3. 28
      src/qbrowserlib/filestorage.hxx

@ -155,6 +155,8 @@ class Browser: public QMainWindow, protected Ui::Browser {
actionAddBookmark, SLOT(setDisabled(bool))));
assert(connect(_editbookmarks.get(), SIGNAL(endEdit(bool)),
actionAddBookmark, SLOT(setEnabled(bool))));
assert(connect(_editbookmarks.get(), SIGNAL(accepted()),
SLOT(saveBookmarks())));
} else {
QLineEdit* label(new QLineEdit(_toolbar));
_url = label;
@ -596,6 +598,7 @@ class Browser: public QMainWindow, protected Ui::Browser {
QAction* a(_bookmarks->addAction(url->currentText()));
a->setData(url->currentText());
connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory()));
saveBookmarks();
}
}
@ -858,13 +861,18 @@ class Browser: public QMainWindow, protected Ui::Browser {
}
void saveBookmarks() {
LOG<<"Saving Bookmarks ...";
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())
if (_bookmarkfile.writeable()) {
LOG<<"write to bookmark file";
_bookmarkfile.write(urls);
} else if (_settings()) {
LOG<<"write to settings";
_settings()->setValue("Window/Urls", urls);
} else LOG<<"bookmarks not saved";
}
void loadWin() {
@ -885,9 +893,15 @@ class Browser: public QMainWindow, protected Ui::Browser {
}
void loadBookmarks() {
QStringList urls(_bookmarkfile.readable()
?_bookmarkfile.read()
:_settings()->value("Window/Urls").toStringList());
LOG<<"Loading Bookmarks ...";
QStringList urls;
if (_bookmarkfile.readable()) {
LOG<<"load from file";
urls = _bookmarkfile.read();
} else if (_settings()) {
LOG<<"load from settings";
urls = _settings()->value("Window/Urls").toStringList();
}
if (qobject_cast<QComboBox*>(_url)) {
qobject_cast<QComboBox*>(_url)->clear();
qobject_cast<QComboBox*>(_url)->addItems(urls);

@ -53,6 +53,9 @@
<property name="toolTip">
<string>Use Drag/Drop to move, double-click to edit.</string>
</property>
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>

@ -6,6 +6,7 @@
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QString>
@ -35,18 +36,15 @@ 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())));
}
if (valid()) setupWatcher();
}
bool readable() {
return QFileInfo(_file).exists();
}
bool writeable() {
return readable() || !_file.fileName().isEmpty();
return readable() ||
(!_file.fileName().isEmpty() &&
QFileInfo(_file).absoluteDir().exists());
}
QStringList read() {
QStringList res;
@ -66,7 +64,23 @@ class FileStorage: public Storage {
}
return res;
}
private Q_SLOTS:
void setupWatcher() {
if (!_watcher) {
_watcher = new QFileSystemWatcher(this);
_watcher->addPath(QFileInfo(_file).absolutePath());
assert(connect(_watcher, SIGNAL(directoryChanged(const QString&)),
SLOT(setupWatcher())));
assert(connect(_watcher, SIGNAL(fileChanged(const QString&)),
SIGNAL(changed())));
}
if (readable()) {
_watcher->removePaths(_watcher->files());
_watcher->addPath(_file.fileName());
}
}
private:
QFile _file;
QFileSystemWatcher* _watcher;
};

Loading…
Cancel
Save