diff options
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/bookmarkwidget.cpp | 172 | ||||
-rw-r--r-- | src/urlbar/bookmarkwidget.h | 63 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 2 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 2 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 49 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 3 |
6 files changed, 288 insertions, 3 deletions
diff --git a/src/urlbar/bookmarkwidget.cpp b/src/urlbar/bookmarkwidget.cpp new file mode 100644 index 00000000..3380ec57 --- /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 <yoann dot laissus at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +// Auto Includes +#include "bookmarkwidget.h" +#include "bookmarkwidget.moc" + +// Local includes +#include "application.h" +#include "bookmarksmanager.h" + +// KDE Includes +#include <KLocalizedString> +#include <KLineEdit> +#include <KMessageBox> + +// Qt Includes +#include <QtGui/QFormLayout> +#include <QtGui/QDialogButtonBox> +#include <QtGui/QLabel> +#include <QtGui/QPushButton> + + + +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()); + p.setY(pos.y() + 12); + 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 <yoann dot laissus at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#ifndef BOOKMARKWIDGET_H +#define BOOKMARKWIDGET_H + +// Rekonq Includes +#include "rekonq_defines.h" + +// KDE Includes +#include <KUrl> +#include <KBookmark> +#include <KLineEdit> + +// Qt Includes +#include <QtGui/QFrame> + + +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/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 2afc44b2..a9203bf7 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -34,7 +34,7 @@ // Local Includes #include "application.h" #include "urlresolver.h" -#include "search/searchengine.h" +#include "searchengine.h" #include "urlbar.h" // KDE Includes diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index a6258cb5..e9bb6fbb 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -36,7 +36,7 @@ #include "application.h" #include "websnap.h" #include "completionwidget.h" -#include "search/searchengine.h" +#include "searchengine.h" // KDE Includes #include <KIcon> diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index d924a30d..e2033120 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 <KCompletionBox> @@ -107,6 +109,11 @@ UrlBar::UrlBar(QWidget *parent) connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); connect(_tab->view(), SIGNAL(loadStarted()), this, SLOT(clearRightIcons())); + // bookmark icon + _icon->setIcon(KIcon("bookmarks").pixmap(32,32, QIcon::Disabled)); + connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(onBookmarksChanged())); + connect(_icon, SIGNAL(clicked(const QPoint &)), this, SLOT(showBookmarkInfo(const QPoint &))); + // load typed urls connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); @@ -138,7 +145,8 @@ void UrlBar::setQUrl(const QUrl& url) clearFocus(); KLineEdit::setUrl(url); setCursorPosition(0); - _icon->setIcon(Application::icon(url)); +// _icon->setIcon(Application::icon(url)); +// updateIcon(); } } @@ -300,6 +308,16 @@ void UrlBar::loadFinished() return; } + // setting bookmark icon + if (Application::bookmarkProvider()->bookmarkForUrl(_tab->url()).isNull()) + { + _icon->setIcon(KIcon("bookmarks").pixmap(32,32, QIcon::Disabled)); + } + else + { + _icon->setIcon(KIcon("bookmarks")); + } + // show KGet downloads?? if (ReKonfig::kgetList()) { @@ -330,6 +348,35 @@ void UrlBar::loadFinished() } +void UrlBar::showBookmarkInfo(const QPoint &pos) +{ + if( _tab->url().scheme() == QL1S("about") ) + return; + + KBookmark bookmark = Application::bookmarkProvider()->bookmarkForUrl(_tab->url()); + + IconButton *bt = qobject_cast<IconButton *>(this->sender()); + if (!bt) + return; + + if (bookmark.isNull()) + { + bookmark = Application::bookmarkProvider()->rootGroup().addBookmark(_tab->view()->title(), _tab->url()); + Application::bookmarkProvider()->bookmarkManager()->emitChanged(); + } + + BookmarkWidget *widget = new BookmarkWidget(bookmark, window()); + widget->showAt(pos); +} + + +void UrlBar::onBookmarksChanged() +{ + clearRightIcons(); + loadFinished(); +} + + void UrlBar::loadTyped(const QString &text) { activated( KUrl(text) ); diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 7fbe8bb4..d0e2b60e 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -104,6 +104,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); |