diff --git a/src/browser.hxx b/src/browser.hxx index 2516949..498574b 100644 --- a/src/browser.hxx +++ b/src/browser.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(_url)) for (int i(0); i(_url)->count(); ++i) urls<(_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(_url)) { qobject_cast(_url)->clear(); qobject_cast(_url)->addItems(urls); diff --git a/src/editbookmarks.ui b/src/editbookmarks.ui index 9c459a1..15deda5 100644 --- a/src/editbookmarks.ui +++ b/src/editbookmarks.ui @@ -53,6 +53,9 @@ Use Drag/Drop to move, double-click to edit. + + QAbstractItemView::AllEditTriggers + true diff --git a/src/qbrowserlib/filestorage.hxx b/src/qbrowserlib/filestorage.hxx index a23b3d5..b29f7f7 100644 --- a/src/qbrowserlib/filestorage.hxx +++ b/src/qbrowserlib/filestorage.hxx @@ -6,6 +6,7 @@ // 45678901234567890123456789012345678901234567890123456789012345678901234567890 #include +#include #include #include #include @@ -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; };