From 29cc7cf47d172773df321dda0a4fd8d8a9837be1 Mon Sep 17 00:00:00 2001 From: Franz Fellner Date: Mon, 10 Sep 2012 09:34:05 +0200 Subject: [PATCH] Rework the quick bookmark widget. * QupZilla is not firefox or chrome: QZ has speeddial by default, the latter ones only by extensions. So adding an url to the unsorted bookmarks by default when clicking the star is a no-go, as the user probably only wants to add a speed dial. The star is the only possibility to add speed dials. * Having a save and a remove-button possibly confuses the user (at least confused me ;)) Only take one button and change the text according to the state. * Disable the name-edit and folder-combo in the case the url is already bookmarked. Chosing another folder and press save will move the bookmark to another folder. Moving bookmarks IMHO is the job of the "organize bookmarks" tool (renaming them, too) *** In a future (post-1.3.5) I would like to see the bookmark-button an the folder-choser merged like it is done in Opera. (Opera HAS speed dial by default) But I am open for suggestions :) --- src/lib/bookmarks/bookmarkswidget.cpp | 69 +++++++++++++++------------ src/lib/bookmarks/bookmarkswidget.h | 1 - src/lib/bookmarks/bookmarkswidget.ui | 15 +----- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/src/lib/bookmarks/bookmarkswidget.cpp b/src/lib/bookmarks/bookmarkswidget.cpp index 5585e5b5e..e5646c99f 100644 --- a/src/lib/bookmarks/bookmarkswidget.cpp +++ b/src/lib/bookmarks/bookmarkswidget.cpp @@ -26,6 +26,7 @@ #include #include +#include BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* parent) : QMenu(parent) @@ -42,9 +43,15 @@ BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* pa // The locationbar's direction is direction of its text, // it dynamically changes and so, it's not good choice for this widget. setLayoutDirection(QApplication::layoutDirection()); + + m_bookmarkId = m_bookmarksModel->bookmarkId(m_url); - connect(ui->removeBookmark, SIGNAL(clicked()), this, SLOT(removeBookmark())); - connect(ui->save, SIGNAL(clicked()), this, SLOT(saveBookmark())); + if (m_bookmarkId > 0) { + connect(ui->saveRemove, SIGNAL(clicked()), this, SLOT(removeBookmark())); + ui->saveRemove->setText(tr("Remove")); + } else { + connect(ui->saveRemove, SIGNAL(clicked()), this, SLOT(saveBookmark())); + } connect(ui->speeddialButton, SIGNAL(clicked()), this, SLOT(toggleSpeedDial())); const SpeedDial::Page &page = m_speedDial->pageForUrl(m_url); @@ -57,52 +64,53 @@ BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* pa ui->label_2->setPalette(pal); ui->label_3->setPalette(pal); #endif - - addBookmark(); + + loadBookmark(); } void BookmarksWidget::loadBookmark() { - if (m_bookmarksModel->isBookmarked(m_url)) { - m_bookmarkId = m_bookmarksModel->bookmarkId(m_url); + // Bookmark folders + ui->folder->addItem(QIcon(":/icons/other/unsortedbookmarks.png"), _bookmarksUnsorted, "unsorted"); + ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu, "bookmarksMenu"); + ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, "bookmarksToolbar"); + QSqlQuery query; + query.exec("SELECT name FROM folders"); + while (query.next()) { + ui->folder->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), query.value(0).toString()); + } + + if (m_bookmarkId > 0) { BookmarksModel::Bookmark bookmark = m_bookmarksModel->getBookmark(m_bookmarkId); ui->name->setText(bookmark.title); - - // Bookmark folders - ui->folder->addItem(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted, "unsorted"); - ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu, "bookmarksMenu"); - ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, "bookmarksToolbar"); - QSqlQuery query; - query.exec("SELECT name FROM folders"); - while (query.next()) { - ui->folder->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), query.value(0).toString()); - } - ui->folder->setCurrentIndex(ui->folder->findData(bookmark.folder)); - ui->name->setCursorPosition(0); + + ui->name->setEnabled(false); + ui->folder->setEnabled(false); + } else { + ui->name->setText(m_view->title()); + ui->folder->setCurrentIndex(0); } + + ui->name->setCursorPosition(0); +} + +namespace { + const int hideDelay = 270; } void BookmarksWidget::removeBookmark() { m_bookmarksModel->removeBookmark(m_url); emit bookmarkDeleted(); - close(); + QTimer::singleShot(hideDelay, this, SLOT(close())); } void BookmarksWidget::saveBookmark() { - m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString()); - close(); -} - -void BookmarksWidget::addBookmark() -{ - if (!m_bookmarksModel->isBookmarked(m_url)) { - m_bookmarksModel->saveBookmark(m_view); - } - - loadBookmark(); +// m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString()); + m_bookmarksModel->saveBookmark(m_view, ui->folder->currentText()); + QTimer::singleShot(hideDelay, this, SLOT(close())); } void BookmarksWidget::toggleSpeedDial() @@ -119,6 +127,7 @@ void BookmarksWidget::toggleSpeedDial() ui->speeddialButton->setText(tr("Add to Speed Dial")); } + QTimer::singleShot(hideDelay, this, SLOT(close())); } void BookmarksWidget::showAt(QWidget* _parent) diff --git a/src/lib/bookmarks/bookmarkswidget.h b/src/lib/bookmarks/bookmarkswidget.h index 9c2d7f409..30e963f73 100644 --- a/src/lib/bookmarks/bookmarkswidget.h +++ b/src/lib/bookmarks/bookmarkswidget.h @@ -50,7 +50,6 @@ private slots: void removeBookmark(); void saveBookmark(); - void addBookmark(); void toggleSpeedDial(); private: diff --git a/src/lib/bookmarks/bookmarkswidget.ui b/src/lib/bookmarks/bookmarkswidget.ui index 5509bb4f4..257bb5eda 100644 --- a/src/lib/bookmarks/bookmarkswidget.ui +++ b/src/lib/bookmarks/bookmarkswidget.ui @@ -16,19 +16,6 @@ - - - - - 0 - 0 - - - - Remove - - - @@ -111,7 +98,7 @@ - + 0