tested except for the changed event; refs #116
This commit is contained in:
@@ -155,6 +155,8 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
|||||||
actionAddBookmark, SLOT(setDisabled(bool))));
|
actionAddBookmark, SLOT(setDisabled(bool))));
|
||||||
assert(connect(_editbookmarks.get(), SIGNAL(endEdit(bool)),
|
assert(connect(_editbookmarks.get(), SIGNAL(endEdit(bool)),
|
||||||
actionAddBookmark, SLOT(setEnabled(bool))));
|
actionAddBookmark, SLOT(setEnabled(bool))));
|
||||||
|
assert(connect(_editbookmarks.get(), SIGNAL(accepted()),
|
||||||
|
SLOT(saveBookmarks())));
|
||||||
} else {
|
} else {
|
||||||
QLineEdit* label(new QLineEdit(_toolbar));
|
QLineEdit* label(new QLineEdit(_toolbar));
|
||||||
_url = label;
|
_url = label;
|
||||||
@@ -596,6 +598,7 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
|||||||
QAction* a(_bookmarks->addAction(url->currentText()));
|
QAction* a(_bookmarks->addAction(url->currentText()));
|
||||||
a->setData(url->currentText());
|
a->setData(url->currentText());
|
||||||
connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory()));
|
connect(a, SIGNAL(triggered(bool)), SLOT(loadFromHistory()));
|
||||||
|
saveBookmarks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,13 +861,18 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void saveBookmarks() {
|
void saveBookmarks() {
|
||||||
|
LOG<<"Saving Bookmarks ...";
|
||||||
QStringList urls;
|
QStringList urls;
|
||||||
if (qobject_cast<QComboBox*>(_url))
|
if (qobject_cast<QComboBox*>(_url))
|
||||||
for (int i(0); i<qobject_cast<QComboBox*>(_url)->count(); ++i)
|
for (int i(0); i<qobject_cast<QComboBox*>(_url)->count(); ++i)
|
||||||
urls<<qobject_cast<QComboBox*>(_url)->itemText(i);
|
urls<<qobject_cast<QComboBox*>(_url)->itemText(i);
|
||||||
if (!(_bookmarkfile.writeable() && _bookmarkfile.write(urls))
|
if (_bookmarkfile.writeable()) {
|
||||||
&& _settings())
|
LOG<<"write to bookmark file";
|
||||||
|
_bookmarkfile.write(urls);
|
||||||
|
} else if (_settings()) {
|
||||||
|
LOG<<"write to settings";
|
||||||
_settings()->setValue("Window/Urls", urls);
|
_settings()->setValue("Window/Urls", urls);
|
||||||
|
} else LOG<<"bookmarks not saved";
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadWin() {
|
void loadWin() {
|
||||||
@@ -885,9 +893,15 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loadBookmarks() {
|
void loadBookmarks() {
|
||||||
QStringList urls(_bookmarkfile.readable()
|
LOG<<"Loading Bookmarks ...";
|
||||||
?_bookmarkfile.read()
|
QStringList urls;
|
||||||
:_settings()->value("Window/Urls").toStringList());
|
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)) {
|
if (qobject_cast<QComboBox*>(_url)) {
|
||||||
qobject_cast<QComboBox*>(_url)->clear();
|
qobject_cast<QComboBox*>(_url)->clear();
|
||||||
qobject_cast<QComboBox*>(_url)->addItems(urls);
|
qobject_cast<QComboBox*>(_url)->addItems(urls);
|
||||||
|
@@ -53,6 +53,9 @@
|
|||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Use Drag/Drop to move, double-click to edit.</string>
|
<string>Use Drag/Drop to move, double-click to edit.</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::AllEditTriggers</set>
|
||||||
|
</property>
|
||||||
<property name="dragEnabled">
|
<property name="dragEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||||
|
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QFileSystemWatcher>
|
#include <QtCore/QFileSystemWatcher>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
@@ -35,18 +36,15 @@ class FileStorage: public Storage {
|
|||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
public:
|
public:
|
||||||
FileStorage(QString file): _file(file) {
|
FileStorage(QString file): _file(file) {
|
||||||
if (valid()) {
|
if (valid()) setupWatcher();
|
||||||
assert(connect(new QFileSystemWatcher(QStringList()<<_file.fileName(),
|
|
||||||
this),
|
|
||||||
SIGNAL(fileChanged(const QString&)),
|
|
||||||
SLOT(changed())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bool readable() {
|
bool readable() {
|
||||||
return QFileInfo(_file).exists();
|
return QFileInfo(_file).exists();
|
||||||
}
|
}
|
||||||
bool writeable() {
|
bool writeable() {
|
||||||
return readable() || !_file.fileName().isEmpty();
|
return readable() ||
|
||||||
|
(!_file.fileName().isEmpty() &&
|
||||||
|
QFileInfo(_file).absoluteDir().exists());
|
||||||
}
|
}
|
||||||
QStringList read() {
|
QStringList read() {
|
||||||
QStringList res;
|
QStringList res;
|
||||||
@@ -66,7 +64,23 @@ class FileStorage: public Storage {
|
|||||||
}
|
}
|
||||||
return res;
|
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:
|
private:
|
||||||
QFile _file;
|
QFile _file;
|
||||||
|
QFileSystemWatcher* _watcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user