From 1ed00f9949c9507768db0973c61b9648a8a58575 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 28 Jul 2010 00:16:59 +0200 Subject: Manually importing Yoann merge 2260 PLease, check if I did something wrong.. --- src/urlbar/bookmarkwidget.cpp | 172 ++++++++++++++++++++++++++++++++++++++++++ src/urlbar/bookmarkwidget.h | 63 ++++++++++++++++ src/urlbar/urlbar.cpp | 46 +++++++++++ src/urlbar/urlbar.h | 4 + 4 files changed, 285 insertions(+) create mode 100644 src/urlbar/bookmarkwidget.cpp create mode 100644 src/urlbar/bookmarkwidget.h (limited to 'src/urlbar') diff --git a/src/urlbar/bookmarkwidget.cpp b/src/urlbar/bookmarkwidget.cpp new file mode 100644 index 00000000..f9ef5cd6 --- /dev/null +++ b/src/urlbar/bookmarkwidget.cpp @@ -0,0 +1,172 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 by Yoann Laissus +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +// Auto Includes +#include "bookmarkwidget.h" +#include "bookmarkwidget.moc" + +// Local includes +#include "application.h" +#include "bookmarksmanager.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include +#include +#include +#include + + + +BookmarkWidget::BookmarkWidget(const KBookmark &bookmark, QWidget *parent) + : QFrame(parent, Qt::Popup) + , m_bookmark(bookmark) +{ + setAttribute(Qt::WA_DeleteOnClose); + setFixedWidth(350); + setFrameStyle(QFrame::Panel); + + QFormLayout *layout = new QFormLayout(this); + setLayout(layout); + + QHBoxLayout *hLayout = new QHBoxLayout(); + + QLabel *bookmarkIcon = new QLabel(this); + bookmarkIcon->setPixmap(KIcon("bookmarks").pixmap(32, 32)); + hLayout->addWidget(bookmarkIcon); + hLayout->setSpacing(10); + + QVBoxLayout *vLayout = new QVBoxLayout(); + + QLabel *bookmarkInfo = new QLabel(this); + bookmarkInfo->setText(i18n("Edit this Bookmark")); + QFont font; + font.setPointSize(font.pointSize() + 2); + bookmarkInfo->setFont(font); + + vLayout->addWidget(bookmarkInfo); + + QPushButton *removeButton = new QPushButton(this); + removeButton->setText(i18n("Remove this Bookmark")); + connect(removeButton, SIGNAL(clicked()), this, SLOT(removeBookmark())); + + vLayout->addWidget(removeButton); + hLayout->addLayout(vLayout); + layout->addItem(hLayout); + + + QLabel *nameLabel = new QLabel(this); + nameLabel->setText(i18n("Name:")); + + m_name = new KLineEdit(this); + if (m_bookmark.isNull()) + { + m_name->setEnabled(false); + } + else + { + m_name->setText(m_bookmark.text()); + m_name->setFocus(); + } + + layout->addRow(nameLabel, m_name); + + QLabel *urlLabel = new QLabel(this); + urlLabel->setText("URL:"); + + KLineEdit *url = new KLineEdit(this); + url->setText(m_bookmark.url().url()); + url->setEnabled(false); + + layout->addRow(urlLabel, url); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Done")); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + layout->addWidget(buttonBox); +} + + +BookmarkWidget::~BookmarkWidget() +{ + delete m_name; +} + + +void BookmarkWidget::accept() +{ + if (!m_bookmark.isNull() && m_name->text() != m_bookmark.fullText()) + { + m_bookmark.setFullText(m_name->text()); + Application::bookmarkProvider()->bookmarkManager()->emitChanged(); + } + reject(); +} + + +void BookmarkWidget::reject() +{ + close(); + deleteLater(); +} + + +void BookmarkWidget::showAt(const QPoint &pos) +{ + QPoint p; + p.setX(pos.x() - 350); + p.setY(pos.y() + 10); + move(p); + show(); +} + + +void BookmarkWidget::removeBookmark() +{ + bool folder = m_bookmark.isGroup(); + + if (KMessageBox::warningContinueCancel( + QApplication::activeWindow(), + folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", m_bookmark.text()) + : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", m_bookmark.text()), + folder ? i18n("Bookmark Folder Deletion") + : i18n("Bookmark Deletion"), + KStandardGuiItem::del()) + == KMessageBox::Continue + ) + { + m_bookmark.parentGroup().deleteBookmark(m_bookmark); + Application::bookmarkProvider()->bookmarkManager()->emitChanged(); + } + + reject(); +} diff --git a/src/urlbar/bookmarkwidget.h b/src/urlbar/bookmarkwidget.h new file mode 100644 index 00000000..cdab328e --- /dev/null +++ b/src/urlbar/bookmarkwidget.h @@ -0,0 +1,63 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 by Yoann Laissus +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +#ifndef BOOKMARKWIDGET_H +#define BOOKMARKWIDGET_H + +// Rekonq Includes +#include "rekonq_defines.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include + + +class BookmarkWidget : public QFrame +{ + Q_OBJECT + +public: + BookmarkWidget(const KBookmark &bookmark, QWidget *parent = 0); + ~BookmarkWidget(); + + void showAt(const QPoint &pos); + +private slots: + void accept(); + void reject(); + void removeBookmark(); + +private: + KBookmark m_bookmark; + KLineEdit *m_name; + +}; + +#endif // BOOKMARKWIDGET_H diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index d924a30d..4936d18f 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -41,6 +41,8 @@ #include "webpage.h" #include "webview.h" #include "completionwidget.h" +#include "bookmarksmanager.h" +#include "bookmarkwidget.h" // KDE Includes #include @@ -107,6 +109,8 @@ UrlBar::UrlBar(QWidget *parent) connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); connect(_tab->view(), SIGNAL(loadStarted()), this, SLOT(clearRightIcons())); + connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(onBookmarksChanged())); + // load typed urls connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); @@ -321,6 +325,10 @@ void UrlBar::loadFinished() connect(bt, SIGNAL(clicked(QPoint)), _tab->page(), SLOT(showSSLInfo(QPoint))); } + // show bookmark info + IconButton *bt = addRightIcon(UrlBar::BK); + connect(bt, SIGNAL(clicked(const QPoint &)), this, SLOT(showBookmarkInfo(const QPoint &))); + // we need to update urlbar after the right icon settings // removing this code (where setStyleSheet automatically calls update) needs adding again // an update call @@ -330,6 +338,34 @@ void UrlBar::loadFinished() } +void UrlBar::showBookmarkInfo(const QPoint &pos) +{ + KBookmark bookmark = Application::bookmarkProvider()->bookmarkForUrl(_tab->url()); + + IconButton *bt = qobject_cast(this->sender()); + if (!bt) + return; + + if (bookmark.isNull()) + { + Application::bookmarkProvider()->rootGroup().addBookmark(_tab->view()->title(), _tab->url()); + Application::bookmarkProvider()->bookmarkManager()->emitChanged(); + } + else + { + BookmarkWidget *widget = new BookmarkWidget(bookmark, window()); + widget->showAt(pos); + } +} + + +void UrlBar::onBookmarksChanged() +{ + clearRightIcons(); + loadFinished(); +} + + void UrlBar::loadTyped(const QString &text) { activated( KUrl(text) ); @@ -383,6 +419,16 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) rightIcon->setIcon(KIcon("object-locked")); rightIcon->setToolTip(i18n("Show SSL Info")); break; + case UrlBar::BK: + if (Application::bookmarkProvider()->bookmarkForUrl(_tab->url()).isNull()) + { + rightIcon->setIcon(KIcon("bookmarks").pixmap(32,32, QIcon::Disabled)); + } + else + { + rightIcon->setIcon(KIcon("bookmarks")); + } + break; default: kDebug() << "ERROR.. default non extant case!!"; break; diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 7fbe8bb4..8808661b 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -83,6 +83,7 @@ public: KGet = 0x00000001, RSS = 0x00000010, SSL = 0x00000100, + BK = 0x00001000 }; explicit UrlBar(QWidget *parent = 0); @@ -104,6 +105,9 @@ private slots: void detectTypedString(const QString &); void suggest(); + void showBookmarkInfo(const QPoint &pos); + void onBookmarksChanged(); + protected: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent *event); -- cgit v1.2.1