1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Merge branch 'bookmarks_simplified_1.3.5' of git://github.com/ff2000/qupzilla into ff2000-bookmarks_simplified_1.3.5

This commit is contained in:
nowrep 2012-09-10 10:50:47 +02:00
commit 23dfe8b8a8
3 changed files with 40 additions and 45 deletions

View File

@ -26,6 +26,7 @@
#include <QToolTip> #include <QToolTip>
#include <QSqlQuery> #include <QSqlQuery>
#include <QTimer>
BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* parent) BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* parent)
: QMenu(parent) : QMenu(parent)
@ -43,8 +44,14 @@ BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* pa
// it dynamically changes and so, it's not good choice for this widget. // it dynamically changes and so, it's not good choice for this widget.
setLayoutDirection(QApplication::layoutDirection()); setLayoutDirection(QApplication::layoutDirection());
connect(ui->removeBookmark, SIGNAL(clicked()), this, SLOT(removeBookmark())); m_bookmarkId = m_bookmarksModel->bookmarkId(m_url);
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())); connect(ui->speeddialButton, SIGNAL(clicked()), this, SLOT(toggleSpeedDial()));
const SpeedDial::Page &page = m_speedDial->pageForUrl(m_url); const SpeedDial::Page &page = m_speedDial->pageForUrl(m_url);
@ -58,18 +65,13 @@ BookmarksWidget::BookmarksWidget(QupZilla* mainClass, WebView* view, QWidget* pa
ui->label_3->setPalette(pal); ui->label_3->setPalette(pal);
#endif #endif
addBookmark(); loadBookmark();
} }
void BookmarksWidget::loadBookmark() void BookmarksWidget::loadBookmark()
{ {
if (m_bookmarksModel->isBookmarked(m_url)) {
m_bookmarkId = m_bookmarksModel->bookmarkId(m_url);
BookmarksModel::Bookmark bookmark = m_bookmarksModel->getBookmark(m_bookmarkId);
ui->name->setText(bookmark.title);
// Bookmark folders // Bookmark folders
ui->folder->addItem(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted, "unsorted"); 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), _bookmarksMenu, "bookmarksMenu");
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, "bookmarksToolbar"); ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, "bookmarksToolbar");
QSqlQuery query; QSqlQuery query;
@ -78,31 +80,37 @@ void BookmarksWidget::loadBookmark()
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), query.value(0).toString()); 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);
ui->folder->setCurrentIndex(ui->folder->findData(bookmark.folder)); 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() void BookmarksWidget::removeBookmark()
{ {
m_bookmarksModel->removeBookmark(m_url); m_bookmarksModel->removeBookmark(m_url);
emit bookmarkDeleted(); emit bookmarkDeleted();
close(); QTimer::singleShot(hideDelay, this, SLOT(close()));
} }
void BookmarksWidget::saveBookmark() void BookmarksWidget::saveBookmark()
{ {
m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString()); // m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString());
close(); m_bookmarksModel->saveBookmark(m_view, ui->folder->currentText());
} QTimer::singleShot(hideDelay, this, SLOT(close()));
void BookmarksWidget::addBookmark()
{
if (!m_bookmarksModel->isBookmarked(m_url)) {
m_bookmarksModel->saveBookmark(m_view);
}
loadBookmark();
} }
void BookmarksWidget::toggleSpeedDial() void BookmarksWidget::toggleSpeedDial()
@ -119,6 +127,7 @@ void BookmarksWidget::toggleSpeedDial()
ui->speeddialButton->setText(tr("Add to Speed Dial")); ui->speeddialButton->setText(tr("Add to Speed Dial"));
} }
QTimer::singleShot(hideDelay, this, SLOT(close()));
} }
void BookmarksWidget::showAt(QWidget* _parent) void BookmarksWidget::showAt(QWidget* _parent)

View File

@ -50,7 +50,6 @@ private slots:
void removeBookmark(); void removeBookmark();
void saveBookmark(); void saveBookmark();
void addBookmark();
void toggleSpeedDial(); void toggleSpeedDial();
private: private:

View File

@ -16,19 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="removeBookmark">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
@ -111,7 +98,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="save"> <widget class="QPushButton" name="saveRemove">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>