diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2011-08-04 11:43:23 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-08-04 11:48:57 +0200 |
commit | 309cd39927b613c378346a29330333be727c2a99 (patch) | |
tree | 994c7b1b0f189eddb530c5d83688b9c6016ac9a9 /src | |
parent | action to search with default searchEnine in marked text's context menu. REVI... (diff) | |
download | rekonq-309cd39927b613c378346a29330333be727c2a99.tar.xz |
Tools Action Menu
- Removed showDeveloperTools action
- Moved adblock GUI to adblock part
- renamed toolsMenu and developerMenu to reflect their real/new roles
- Added UserAgent action to the tools menu
REVIEW:102170
REVIEWED-BY: fritz_van_tom
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/adblock/adblockmanager.cpp | 15 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 1 | ||||
-rw-r--r-- | src/adblock/adblockwidget.cpp | 200 | ||||
-rw-r--r-- | src/adblock/adblockwidget.h (renamed from src/settings/adblockwidget.h) | 0 | ||||
-rw-r--r-- | src/adblock/settings_adblock.ui (renamed from src/settings/settings_adblock.ui) | 0 | ||||
-rw-r--r-- | src/mainwindow.cpp | 76 | ||||
-rw-r--r-- | src/mainwindow.h | 4 | ||||
-rw-r--r-- | src/rekonq.kcfg | 3 | ||||
-rw-r--r-- | src/settings/adblockwidget.cpp | 2 | ||||
-rw-r--r-- | src/settings/settings_webkit.ui | 7 | ||||
-rw-r--r-- | src/settings/settingsdialog.cpp | 11 | ||||
-rw-r--r-- | src/webview.cpp | 13 |
13 files changed, 267 insertions, 69 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 09c75312..d1012b2e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,7 +46,6 @@ SET( rekonq_KDEINIT_SRCS history/historypanel.cpp #---------------------------------------- settings/settingsdialog.cpp - settings/adblockwidget.cpp settings/appearancewidget.cpp settings/generalwidget.cpp settings/tabswidget.cpp @@ -67,6 +66,7 @@ SET( rekonq_KDEINIT_SRCS adblock/adblockrulefallbackimpl.cpp adblock/adblockrulenullimpl.cpp adblock/adblockruletextmatchimpl.cpp + adblock/adblockwidget.cpp #---------------------------------------- urlbar/stackedurlbar.cpp urlbar/urlbar.cpp @@ -99,7 +99,7 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS settings/settings_tabs.ui settings/settings_appearance.ui settings/settings_webkit.ui - settings/settings_adblock.ui + adblock/settings_adblock.ui cleardata.ui sslinfo.ui useragent/useragentsettings.ui diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 6a4a3827..ff09fdc7 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -33,6 +33,7 @@ // Local Includes #include "adblocknetworkreply.h" +#include "adblockwidget.h" #include "webpage.h" // KDE Includes @@ -362,3 +363,17 @@ void AdBlockManager::addSubscription(const QString &title, const QString &locati ReKonfig::setSubscriptionTitles(titles); ReKonfig::setSubscriptionLocations(locations); } + + +void AdBlockManager::showSettings() +{ + QPointer<KDialog> dialog = new KDialog(); + dialog->setCaption(i18nc("@title:window", "Ad Block Settings")); + dialog->setButtons(KDialog::Ok); + + AdBlockWidget widget; + dialog->setMainWidget(&widget); + dialog->exec(); + + dialog->deleteLater(); +} diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 1f716c6d..ac62c508 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -142,6 +142,7 @@ public: public slots: void loadSettings(bool checkUpdateDate = true); + void showSettings(); private: void updateNextSubscription(); diff --git a/src/adblock/adblockwidget.cpp b/src/adblock/adblockwidget.cpp new file mode 100644 index 00000000..ad8bd599 --- /dev/null +++ b/src/adblock/adblockwidget.cpp @@ -0,0 +1,200 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010-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 "adblockwidget.h" +#include "adblockwidget.moc" + +// Auto Includes +#include "rekonq.h" + +// KDE Includes +#include <KSharedConfig> +#include <KIcon> +#include <KDebug> + +// Qt Includes +#include <QString> +#include <QWhatsThis> +#include <QListWidgetItem> + + +AdBlockWidget::AdBlockWidget(QWidget *parent) + : QWidget(parent) + , _changed(false) +{ + setupUi(this); + + hintLabel->setText(i18n("<qt>Filter expression (e.g. <tt>http://www.example.com/ad/*</tt>, <a href=\"filterhelp\">more information</a>):")); + connect(hintLabel, SIGNAL(linkActivated(const QString &)), this, SLOT(slotInfoLinkActivated(const QString &))); + + listWidget->setSortingEnabled(true); + listWidget->setSelectionMode(QAbstractItemView::SingleSelection); + + searchLine->setListWidget(listWidget); + + insertButton->setIcon(KIcon("list-add")); + connect(insertButton, SIGNAL(clicked()), this, SLOT(insertRule())); + + removeButton->setIcon(KIcon("list-remove")); + connect(removeButton, SIGNAL(clicked()), this, SLOT(removeRule())); + + load(); + + spinBox->setSuffix(ki18np(" day", " days")); + + // emit changed signal + connect(insertButton, SIGNAL(clicked()), this, SLOT(hasChanged())); + connect(removeButton, SIGNAL(clicked()), this, SLOT(hasChanged())); + connect(checkEnableAdblock, SIGNAL(stateChanged(int)), this, SLOT(hasChanged())); + connect(checkHideAds, SIGNAL(stateChanged(int)), this, SLOT(hasChanged())); + connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(hasChanged())); +} + + +void AdBlockWidget::slotInfoLinkActivated(const QString &url) +{ + Q_UNUSED(url) + + QString hintHelpString = i18n("<qt><p>Enter an expression to filter. Filters can be defined as either:" + "<ul><li>a shell-style wildcard, e.g. <tt>http://www.example.com/ads*</tt>, the wildcards <tt>*?[]</tt> may be used</li>" + "<li>a full regular expression by surrounding the string with '<tt>/</tt>', e.g. <tt>/\\/(ad|banner)\\./</tt></li></ul>" + "<p>Any filter string can be preceded by '<tt>@@</tt>' to whitelist (allow) any matching URL, " + "which takes priority over any blacklist (blocking) filter."); + + QWhatsThis::showText(QCursor::pos(), hintHelpString); +} + + +void AdBlockWidget::insertRule() +{ + QString rule = addFilterLineEdit->text(); + if (rule.isEmpty()) + return; + + listWidget->addItem(rule); + addFilterLineEdit->clear(); +} + + +void AdBlockWidget::removeRule() +{ + listWidget->takeItem(listWidget->currentRow()); +} + + +void AdBlockWidget::load() +{ + bool isAdBlockEnabled = ReKonfig::adBlockEnabled(); + checkEnableAdblock->setChecked(isAdBlockEnabled); + // update enabled status + checkHideAds->setEnabled(checkEnableAdblock->isChecked()); + tabWidget->setEnabled(checkEnableAdblock->isChecked()); + + bool areImageFiltered = ReKonfig::hideAdsEnabled(); + checkHideAds->setChecked(areImageFiltered); + + int days = ReKonfig::updateInterval(); + spinBox->setValue(days); + + QStringList subscriptions = ReKonfig::subscriptionTitles(); + + // load automatic rules + foreach(const QString & sub, subscriptions) + { + QTreeWidgetItem *subItem = new QTreeWidgetItem(treeWidget); + subItem->setText(0, sub); + loadRules(subItem); + } + + // load local rules + KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); + KConfigGroup localGroup(config, "rules"); + QStringList rules = localGroup.readEntry("local-rules" , QStringList()); + foreach(const QString & rule, rules) + { + listWidget->addItem(rule); + } +} + + +void AdBlockWidget::loadRules(QTreeWidgetItem *item) +{ + KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); + KConfigGroup localGroup(config, "rules"); + + QString str = item->text(0) + "-rules"; + QStringList rules = localGroup.readEntry(str , QStringList()); + + foreach(const QString & rule, rules) + { + QTreeWidgetItem *subItem = new QTreeWidgetItem(item); + subItem->setText(0, rule); + } +} + + +void AdBlockWidget::save() +{ + int n; + + // local rules + KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); + KConfigGroup localGroup(config , "rules"); + + QStringList localRules; + + n = listWidget->count(); + for (int i = 0; i < n; ++i) + { + QListWidgetItem *item = listWidget->item(i); + localRules << item->text(); + } + localGroup.writeEntry("local-rules" , localRules); + + ReKonfig::setAdBlockEnabled(checkEnableAdblock->isChecked()); + ReKonfig::setHideAdsEnabled(checkHideAds->isChecked()); + ReKonfig::setUpdateInterval(spinBox->value()); + + _changed = false; + emit changed(false); +} + + +void AdBlockWidget::hasChanged() +{ + // update enabled status + checkHideAds->setEnabled(checkEnableAdblock->isChecked()); + tabWidget->setEnabled(checkEnableAdblock->isChecked()); + _changed = true; + emit changed(true); +} + + +bool AdBlockWidget::changed() +{ + return _changed; +} diff --git a/src/settings/adblockwidget.h b/src/adblock/adblockwidget.h index 08194ada..08194ada 100644 --- a/src/settings/adblockwidget.h +++ b/src/adblock/adblockwidget.h diff --git a/src/settings/settings_adblock.ui b/src/adblock/settings_adblock.ui index 68fcf520..68fcf520 100644 --- a/src/settings/settings_adblock.ui +++ b/src/adblock/settings_adblock.ui diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9d2f0ff4..c0085d50 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -35,6 +35,7 @@ #include "rekonq.h" // Local Includes +#include "adblockmanager.h" #include "analyzerpanel.h" #include "application.h" #include "bookmarkprovider.h" @@ -114,8 +115,8 @@ MainWindow::MainWindow() , m_bookmarksBar(0) , m_popup(new KPassivePopup(this)) , m_hidePopupTimer(new QTimer(this)) - , m_toolsMenu(0) - , m_developerMenu(0) + , m_rekonqMenu(0) + , m_toolsActionMenu(0) { // creating a centralWidget containing panel, m_view and the hidden findbar QWidget *centralWidget = new QWidget; @@ -223,56 +224,57 @@ void MainWindow::configureToolbars() void MainWindow::updateToolsMenu() { - if (m_toolsMenu->isEmpty()) + if (m_rekonqMenu->isEmpty()) { - m_toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Open))); - m_toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::SaveAs))); - m_toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Print))); - m_toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Find))); + m_rekonqMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Open))); + m_rekonqMenu->addAction(actionByName(KStandardAction::name(KStandardAction::SaveAs))); + m_rekonqMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Print))); + m_rekonqMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Find))); QAction *action = actionByName(KStandardAction::name(KStandardAction::Zoom)); action->setCheckable(true); connect(m_zoomBar, SIGNAL(visibilityChanged(bool)), action, SLOT(setChecked(bool))); - m_toolsMenu->addAction(action); + m_rekonqMenu->addAction(action); - m_toolsMenu->addAction(actionByName(QL1S("useragent"))); + m_rekonqMenu->addSeparator(); - m_toolsMenu->addSeparator(); + m_rekonqMenu->addAction(actionByName(QL1S("private_browsing"))); + m_rekonqMenu->addAction(actionByName(QL1S("clear_private_data"))); - m_toolsMenu->addAction(actionByName(QL1S("private_browsing"))); - m_toolsMenu->addAction(actionByName(QL1S("clear_private_data"))); + m_rekonqMenu->addSeparator(); - m_toolsMenu->addSeparator(); + // tools Action Menu + m_toolsActionMenu = new KActionMenu(KIcon("preferences-other"), i18n("Tools"), this); + m_toolsActionMenu->addAction(actionByName(QL1S("web_inspector"))); + m_toolsActionMenu->addAction(actionByName(QL1S("page_source"))); + m_toolsActionMenu->addAction(actionByName(QL1S("net_analyzer"))); + m_toolsActionMenu->addAction(actionByName(QL1S("set_editable"))); - m_developerMenu = new KActionMenu(KIcon("applications-development-web"), i18n("Development"), this); - m_developerMenu->addAction(actionByName(QL1S("web_inspector"))); - m_developerMenu->addAction(actionByName(QL1S("page_source"))); - m_developerMenu->addAction(actionByName(QL1S("net_analyzer"))); - m_developerMenu->addAction(actionByName(QL1S("set_editable"))); + m_toolsActionMenu->addSeparator(); - m_toolsMenu->addAction(m_developerMenu); - if (!ReKonfig::showDeveloperTools()) - m_developerMenu->setVisible(false); + m_toolsActionMenu->addAction(actionByName(QL1S("useragent"))); + m_toolsActionMenu->addAction(actionByName(QL1S("adblock"))); - m_toolsMenu->addSeparator(); + m_rekonqMenu->addAction(m_toolsActionMenu); + // ----------------------------------------------------------------------------------------- + + m_rekonqMenu->addSeparator(); action = m_bookmarksBar->toolBar()->toggleViewAction(); action->setText(i18n("Bookmarks Toolbar")); action->setIcon(KIcon("bookmarks-bar")); - m_toolsMenu->addAction(action); + m_rekonqMenu->addAction(action); - m_toolsMenu->addAction(actionByName(QL1S("show_history_panel"))); - m_toolsMenu->addAction(actionByName(QL1S("show_bookmarks_panel"))); - m_toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::FullScreen))); + m_rekonqMenu->addAction(actionByName(QL1S("show_history_panel"))); + m_rekonqMenu->addAction(actionByName(QL1S("show_bookmarks_panel"))); + m_rekonqMenu->addAction(actionByName(KStandardAction::name(KStandardAction::FullScreen))); - m_toolsMenu->addSeparator(); + m_rekonqMenu->addSeparator(); helpMenu()->setIcon(KIcon("help-browser")); - m_toolsMenu->addAction(helpMenu()->menuAction()); - m_toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Preferences))); + m_rekonqMenu->addAction(helpMenu()->menuAction()); + m_rekonqMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Preferences))); } - - m_developerMenu->setVisible(ReKonfig::showDeveloperTools()); } @@ -549,10 +551,16 @@ void MainWindow::setupActions() actionCollection()->addAction(QL1S("UserAgentSettings"), a); connect(a, SIGNAL(triggered(bool)), this, SLOT(showUserAgentSettings())); + // Editable Page a = new KAction(KIcon(""), i18n("set editable"), this); a->setCheckable(true); actionCollection()->addAction(QL1S("set_editable"), a); connect(a, SIGNAL(triggered(bool)), this, SLOT(setEditable(bool))); + + // Adblock + a = new KAction(KIcon("preferences-web-browser-adblock"), i18n("Ad Block"), this); + actionCollection()->addAction(QL1S("adblock"), a); + connect(a, SIGNAL(triggered(bool)), rApp->adblockManager(), SLOT(showSettings())); } @@ -562,9 +570,9 @@ void MainWindow::setupTools() toolsAction->setDelayed(false); toolsAction->setShortcutConfigurable(true); toolsAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_T)); - m_toolsMenu = new KMenu(this); - toolsAction->setMenu(m_toolsMenu); // dummy menu to have the dropdown arrow - connect(m_toolsMenu, SIGNAL(aboutToShow()), this, SLOT(updateToolsMenu())); + m_rekonqMenu = new KMenu(this); + toolsAction->setMenu(m_rekonqMenu); // dummy menu to have the dropdown arrow + connect(m_rekonqMenu, SIGNAL(aboutToShow()), this, SLOT(updateToolsMenu())); // adding rekonq_tools to rekonq actionCollection actionCollection()->addAction(QL1S("rekonq_tools"), toolsAction); diff --git a/src/mainwindow.h b/src/mainwindow.h index e7a52074..d8b5538e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -211,8 +211,8 @@ private: KPassivePopup *m_popup; QTimer *m_hidePopupTimer; - KMenu *m_toolsMenu; - KActionMenu *m_developerMenu; + KMenu *m_rekonqMenu; + KActionMenu *m_toolsActionMenu; }; #endif // MAINWINDOW_H diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index 762fe946..4050c4a0 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -30,9 +30,6 @@ <entry name="recoverOnCrash" type="Int"> <default>0</default> </entry> - <entry name="showDeveloperTools" type="Bool"> - <default>false</default> - </entry> </group> diff --git a/src/settings/adblockwidget.cpp b/src/settings/adblockwidget.cpp index ad8bd599..3c7ec38f 100644 --- a/src/settings/adblockwidget.cpp +++ b/src/settings/adblockwidget.cpp @@ -175,7 +175,7 @@ void AdBlockWidget::save() } localGroup.writeEntry("local-rules" , localRules); - ReKonfig::setAdBlockEnabled(checkEnableAdblock->isChecked()); + ReKonfig::setAdBlockEnabled(checkEnableAdblock->isChecked()); // TODO: REMOVE ME!!!! ReKonfig::setHideAdsEnabled(checkHideAds->isChecked()); ReKonfig::setUpdateInterval(spinBox->value()); diff --git a/src/settings/settings_webkit.ui b/src/settings/settings_webkit.ui index 00bced99..58fbe459 100644 --- a/src/settings/settings_webkit.ui +++ b/src/settings/settings_webkit.ui @@ -120,13 +120,6 @@ </property> </widget> </item> - <item row="7" column="0"> - <widget class="QCheckBox" name="kcfg_showDeveloperTools"> - <property name="text"> - <string>Show web developer tools</string> - </property> - </widget> - </item> </layout> </widget> </item> diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp index a8d5f5b0..061430d3 100644 --- a/src/settings/settingsdialog.cpp +++ b/src/settings/settingsdialog.cpp @@ -40,7 +40,6 @@ #include "opensearchmanager.h" // Widget Includes -#include "adblockwidget.h" #include "networkwidget.h" #include "generalwidget.h" #include "appearancewidget.h" @@ -70,7 +69,6 @@ private: AppearanceWidget *appearanceWidg; WebKitWidget *webkitWidg; NetworkWidget *networkWidg; - AdBlockWidget *adBlockWidg; KCModuleProxy *ebrowsingModule; @@ -116,12 +114,6 @@ Private::Private(SettingsDialog *parent) pageItem = parent->addPage(networkWidg , i18n("Network")); pageItem->setIcon(KIcon("preferences-system-network")); - // -- 6 - adBlockWidg = new AdBlockWidget(parent); - adBlockWidg->layout()->setMargin(0); - pageItem = parent->addPage(adBlockWidg , i18n("Ad Block")); - pageItem->setIcon(KIcon("preferences-web-browser-adblock")); - // -- 7 shortcutsEditor = new KShortcutsEditor(rApp->mainWindow()->actionCollection(), parent); pageItem = parent->addPage(shortcutsEditor , i18n("Shortcuts")); @@ -164,7 +156,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) connect(d->appearanceWidg, SIGNAL(changed(bool)), this, SLOT(updateButtons())); connect(d->webkitWidg, SIGNAL(changed(bool)), this, SLOT(updateButtons())); connect(d->networkWidg, SIGNAL(changed(bool)), this, SLOT(updateButtons())); - connect(d->adBlockWidg, SIGNAL(changed(bool)), this, SLOT(updateButtons())); connect(d->ebrowsingModule, SIGNAL(changed(bool)), this, SLOT(updateButtons())); connect(d->shortcutsEditor, SIGNAL(keyChange()), this, SLOT(updateButtons())); @@ -199,7 +190,6 @@ void SettingsDialog::saveSettings() d->appearanceWidg->save(); d->webkitWidg->save(); d->networkWidg->save(); - d->adBlockWidg->save(); d->shortcutsEditor->save(); d->ebrowsingModule->save(); @@ -219,7 +209,6 @@ bool SettingsDialog::hasChanged() || d->appearanceWidg->changed() || d->webkitWidg->changed() || d->networkWidg->changed() - || d->adBlockWidg->changed() || d->ebrowsingModule->changed() || d->shortcutsEditor->isModified(); ; diff --git a/src/webview.cpp b/src/webview.cpp index f31d2343..d8325543 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -263,8 +263,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addSeparator(); - if (ReKonfig::showDeveloperTools()) - menu.addAction(inspectAction); + menu.addAction(inspectAction); // TODO Add translate, show translation } @@ -289,8 +288,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addSeparator(); - if (ReKonfig::showDeveloperTools()) - menu.addAction(inspectAction); + menu.addAction(inspectAction); } // page actions @@ -347,11 +345,8 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addAction(a); } - if (ReKonfig::showDeveloperTools()) - { - menu.addAction(mainwindow->actionByName("page_source")); - menu.addAction(inspectAction); - } + menu.addAction(mainwindow->actionByName("page_source")); + menu.addAction(inspectAction); a = rApp->bookmarkProvider()->actionByName("rekonq_add_bookmark"); menu.addAction(a); |