diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2013-04-23 00:16:11 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2013-04-23 00:16:11 +0200 |
commit | 3d4aa3076f50feb6ddeb2d855c01b7b9a427a664 (patch) | |
tree | 5faff1e048b937f81281ffe8d2da123adca35c2e | |
parent | Add support for TLSv1.1 & TLSv1.2 (diff) | |
download | rekonq-3d4aa3076f50feb6ddeb2d855c01b7b9a427a664.tar.xz |
Favorites (fast) management, the "opera" way
mimics Opera browser about right star icon management. Easier and
without the "love" icon always shown :)
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/urlbar/favoritewidget.cpp | 115 | ||||
-rw-r--r-- | src/urlbar/favoritewidget.h | 58 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 135 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 6 |
5 files changed, 83 insertions, 232 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f88c396f..59844589 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -86,7 +86,6 @@ set(rekonq_KDEINIT_SRCS urlbar/listitem.cpp urlbar/adblockwidget.cpp urlbar/bookmarkwidget.cpp - urlbar/favoritewidget.cpp urlbar/rsswidget.cpp urlbar/sslwidget.cpp urlbar/urlsuggester.cpp diff --git a/src/urlbar/favoritewidget.cpp b/src/urlbar/favoritewidget.cpp deleted file mode 100644 index 6a4ffaba..00000000 --- a/src/urlbar/favoritewidget.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011 by Andrea Diamantini <adjam7 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/>. -* -* ============================================================ */ - - -// Self Includes -#include "favoritewidget.h" -#include "favoritewidget.moc" - -// Auto Includes -#include "rekonq.h" - -// Local includes -#include "application.h" -#include "bookmarkmanager.h" -#include "bookmarkowner.h" -#include "webtab.h" - -// KDE Includes -#include <KLocalizedString> -#include <KIcon> -#include <KLineEdit> - -// Qt Includes -#include <QDialogButtonBox> -#include <QFormLayout> -#include <QLabel> -#include <QPushButton> - - -FavoriteWidget::FavoriteWidget(WebTab *tab, QWidget *parent) - : QMenu(parent) - , m_tab(tab) -{ - setAttribute(Qt::WA_DeleteOnClose); - setFixedWidth(350); - - QFormLayout *layout = new QFormLayout(this); - QVBoxLayout *vLay = new QVBoxLayout; - - // Favorite icon - QLabel *bookmarkIcon = new QLabel(this); - bookmarkIcon->setPixmap(KIcon("emblem-favorite").pixmap(32, 32)); - - // Title - QLabel *favoriteInfo = new QLabel(this); - favoriteInfo->setText(i18n("<h4>Remove this favorite?</h4>")); - vLay->addWidget(favoriteInfo); - - // Favorite name - QLabel *nameLabel = new QLabel(this); - nameLabel->setText(i18n("Name: %1", m_tab->view()->title())); - vLay->addWidget(nameLabel); - - // Favorite url - QLabel *urlLabel = new QLabel(this); - urlLabel->setText(i18n("URL: %1", m_tab->url().url())); - vLay->addWidget(urlLabel); - - layout->addRow(bookmarkIcon, vLay); - - // Ok & Cancel buttons - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); - layout->addWidget(buttonBox); -} - - -void FavoriteWidget::showAt(const QPoint &pos) -{ - adjustSize(); - - QPoint p(pos.x() - width(), pos.y() + 10); - move(p); - show(); -} - - -void FavoriteWidget::accept() -{ - QStringList urls = ReKonfig::previewUrls(); - if (urls.removeOne(m_tab->url().url())) - { - ReKonfig::setPreviewUrls(urls); - QStringList titles = ReKonfig::previewNames(); - titles.removeOne(m_tab->view()->title()); - ReKonfig::setPreviewNames(titles); - - emit updateIcon(); - } - - close(); -} diff --git a/src/urlbar/favoritewidget.h b/src/urlbar/favoritewidget.h deleted file mode 100644 index d0b05f14..00000000 --- a/src/urlbar/favoritewidget.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011 by Andrea Diamantini <adjam7 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 FAVORITE_WIDGET_H -#define FAVORITE_WIDGET_H - - -// Qt Includes -#include <QMenu> -#include <QCheckBox> - -// Forward Declarations -class WebTab; - - -class FavoriteWidget : public QMenu -{ - Q_OBJECT - -public: - explicit FavoriteWidget(WebTab *tab, QWidget *parent = 0); - - void showAt(const QPoint &pos); - -Q_SIGNALS: - void updateIcon(); - -private Q_SLOTS: - void accept(); - -private: - WebTab *m_tab; -}; - -#endif // FAVORITE_WIDGET_H diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 46b7889b..c0277c20 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -44,7 +44,6 @@ #include "adblockwidget.h" #include "bookmarkwidget.h" -#include "favoritewidget.h" #include "rsswidget.h" #include "completionwidget.h" @@ -380,11 +379,7 @@ void UrlBar::loadFinished() // show bookmark info IconButton *bt = addRightIcon(UrlBar::BK); - connect(bt, SIGNAL(clicked(QPoint)), this, SLOT(manageBookmarks())); - - // show favorite icon - IconButton *fbt = addRightIcon(UrlBar::Favorite); - connect(fbt, SIGNAL(clicked(QPoint)), this, SLOT(manageFavorites(QPoint))); + connect(bt, SIGNAL(clicked(QPoint)), this, SLOT(manageStarred(QPoint))); // show KGet downloads?? if (!KStandardDirs::findExe("kget").isNull() && ReKonfig::kgetList()) @@ -522,15 +517,14 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) rightIcon->setToolTip(i18n("List all available RSS feeds")); break; case UrlBar::BK: - if (BookmarkManager::self()->bookmarkForUrl(_tab->url()).isNull()) + if (BookmarkManager::self()->bookmarkForUrl(_tab->url()).isNull() && + !ReKonfig::previewUrls().contains(_tab->url().url())) { rightIcon->setIcon(KIcon("bookmarks").pixmap(32, 32, QIcon::Disabled)); - rightIcon->setToolTip(i18n("Bookmark this page")); } else { rightIcon->setIcon(KIcon("bookmarks")); - rightIcon->setToolTip(i18n("Edit this bookmark")); } break; case UrlBar::SearchEngine: @@ -544,18 +538,6 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) rightIcon->setToolTip(i18n("Add search engine")); break; } - case UrlBar::Favorite: - if (ReKonfig::previewUrls().contains(_tab->url().url())) - { - rightIcon->setIcon(KIcon("emblem-favorite")); - rightIcon->setToolTip(i18n("Remove from favorite")); - } - else - { - rightIcon->setIcon(KIcon("emblem-favorite").pixmap(32, 32, QIcon::Disabled)); - rightIcon->setToolTip(i18n("Add to favorites")); - } - break; case UrlBar::AdBlock: { QStringList hosts = ReKonfig::whiteReferer(); @@ -721,41 +703,6 @@ void UrlBar::manageBookmarks() } -void UrlBar::manageFavorites(QPoint pos) -{ - IconButton *bt = qobject_cast<IconButton *>(this->sender()); - if (!bt) - return; - - if (_tab->url().scheme() == QL1S("about")) - return; - - if (ReKonfig::previewUrls().contains(_tab->url().url())) - { - // remove site from favorites - FavoriteWidget *widget = new FavoriteWidget(_tab, window()); - connect(widget, SIGNAL(updateIcon()), this, SLOT(updateRightIcons())); - widget->showAt(pos); - return; - } - - // else, add as favorite - QStringList urls = ReKonfig::previewUrls(); - urls << _tab->url().url(); - ReKonfig::setPreviewUrls(urls); - - QStringList titles = ReKonfig::previewNames(); - titles << _tab->view()->title(); - ReKonfig::setPreviewNames(titles); - - // also, save a site snapshot - WebSnap *snap = new WebSnap(_tab->url(), this); - Q_UNUSED(snap); - - updateRightIcons(); -} - - void UrlBar::manageAdBlock(QPoint pos) { IconButton *bt = qobject_cast<IconButton *>(this->sender()); @@ -817,3 +764,79 @@ void UrlBar::showRSSInfo(const QPoint &pos) RSSWidget *widget = new RSSWidget(map, window()); widget->showAt(pos); } + + +void UrlBar::manageStarred(QPoint pos) +{ + KMenu menu; + KAction *a; + + // Bookmarks + if (BookmarkManager::self()->bookmarkForUrl(_tab->url()).isNull()) + { + a = new KAction(KIcon(KIcon("bookmarks").pixmap(32, 32, QIcon::Disabled)), i18n("Add Bookmark"), &menu); + connect(a, SIGNAL(triggered(bool)), this, SLOT(manageBookmarks())); + } + else + { + a = new KAction(KIcon("bookmarks"), i18n("Edit Bookmark"), &menu); + connect(a, SIGNAL(triggered(bool)), this, SLOT(manageBookmarks())); + } + menu.addAction(a); + + // Favorites + if (ReKonfig::previewUrls().contains(_tab->url().url())) + { + a = new KAction(KIcon("emblem-favorite"), i18n("Remove from Favorites"), &menu); + connect(a, SIGNAL(triggered(bool)), this, SLOT(removeFromFavorites())); + } + else + { + a = new KAction(KIcon(KIcon("emblem-favorite").pixmap(32, 32, QIcon::Disabled)), i18n("Add to Favorites"), &menu); + connect(a, SIGNAL(triggered(bool)), this, SLOT(addToFavorites())); + } + menu.addAction(a); + + QPoint p(pos.x() - menu.sizeHint().width() + 15, pos.y() + 15); + menu.exec(p); +} + + +void UrlBar::addToFavorites() +{ + if (_tab->url().scheme() == QL1S("about")) + return; + + // else, add as favorite + QStringList urls = ReKonfig::previewUrls(); + urls << _tab->url().url(); + ReKonfig::setPreviewUrls(urls); + + QStringList titles = ReKonfig::previewNames(); + titles << _tab->view()->title(); + ReKonfig::setPreviewNames(titles); + + // also, save a site snapshot + WebSnap *snap = new WebSnap(_tab->url(), this); + Q_UNUSED(snap); + + updateRightIcons(); +} + + +void UrlBar::removeFromFavorites() +{ + if (_tab->url().scheme() == QL1S("about")) + return; + + QStringList urls = ReKonfig::previewUrls(); + if (urls.removeOne(_tab->url().url())) + { + ReKonfig::setPreviewUrls(urls); + QStringList titles = ReKonfig::previewNames(); + titles.removeOne(_tab->view()->title()); + ReKonfig::setPreviewNames(titles); + + updateRightIcons(); + } +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 08651705..9c645f00 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -82,7 +82,6 @@ public: RSS = 0x00000010, BK = 0x00001000, SearchEngine = 0x00010000, - Favorite = 0x00100000, AdBlock = 0x01000000 }; @@ -110,8 +109,11 @@ private Q_SLOTS: void detectTypedString(const QString &); void suggest(); + void manageStarred(QPoint); void manageAdBlock(QPoint); - void manageFavorites(QPoint); + + void addToFavorites(); + void removeFromFavorites(); void refreshFavicon(); |