summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-11-21 01:58:23 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-11-21 01:58:23 +0100
commit20a3df6c7d64d845009acc94ead1ddfbec4c413d (patch)
treeef36895b460d572f53c9dfa513a827c50575c9ce /src
parentAdBlock, first file (and first UI. Probably not last :) (diff)
downloadrekonq-20a3df6c7d64d845009acc94ead1ddfbec4c413d.tar.xz
A new kcmshell named "webkit adblock" to set... (guess what?!)
First bits work, seems enough for this evening
Diffstat (limited to 'src')
-rw-r--r--src/adblock/CMakeLists.txt5
-rw-r--r--src/adblock/kcmwebkitadblock.cpp132
-rw-r--r--src/adblock/kcmwebkitadblock.h17
-rw-r--r--src/adblock/webkitAdblock.desktop2
-rw-r--r--src/adblock/webkitadblock.ui59
-rw-r--r--src/settings/settingsdialog.cpp22
6 files changed, 204 insertions, 33 deletions
diff --git a/src/adblock/CMakeLists.txt b/src/adblock/CMakeLists.txt
index 8777bc50..f2785811 100644
--- a/src/adblock/CMakeLists.txt
+++ b/src/adblock/CMakeLists.txt
@@ -11,7 +11,10 @@ kde4_add_ui_files(kcm_webkitadblock_SRCS
kde4_add_plugin(kcm_webkitadblock ${kcm_webkitadblock_SRCS})
-target_link_libraries(kcm_webkitadblock ${KDE4_KDEUI_LIBS} )
+target_link_libraries(kcm_webkitadblock
+ ${KDE4_KDEUI_LIBS}
+ ${KDE4_KIO_LIBS}
+)
install(TARGETS kcm_webkitadblock DESTINATION ${PLUGIN_INSTALL_DIR} )
diff --git a/src/adblock/kcmwebkitadblock.cpp b/src/adblock/kcmwebkitadblock.cpp
index 28487b74..d114b30a 100644
--- a/src/adblock/kcmwebkitadblock.cpp
+++ b/src/adblock/kcmwebkitadblock.cpp
@@ -31,6 +31,15 @@
// KDE Includes
#include <KDE/KPluginFactory>
#include <KDE/KPluginLoader>
+#include <KDE/KAboutData>
+#include <KDE/KTemporaryFile>
+#include <KDE/KIO/NetAccess>
+#include <KDE/KDebug>
+
+// Qt Includes
+#include <QtCore/QTextStream>
+#include <QtGui/QWhatsThis>
+#include <QtGui/QListWidgetItem>
K_PLUGIN_FACTORY(RekonqPluginFactory,
@@ -42,8 +51,27 @@ K_EXPORT_PLUGIN(RekonqPluginFactory("kcmrekonqfactory"))
KCMWebkitAdblock::KCMWebkitAdblock(QWidget *parent, const QVariantList &args)
: KCModule(KGlobal::mainComponent(), parent, args)
+ , _isAdblockEnabled(false)
+ , _group("adblock")
{
+ KAboutData *about = new KAboutData( I18N_NOOP("kcmrekonqfactory"), 0,
+ ki18n( "rekonq Browsing Control Module" ), 0,
+ KLocalizedString(), KAboutData::License_GPL,
+ ki18n( "(c) 2009 Andrea Diamantini" ) );
+
+ about->addAuthor( ki18n("Andrea Diamantini"), KLocalizedString(), "adjam7@gmail.com" );
+ setAboutData( about );
+
setupUi(this);
+ connect(label, SIGNAL(linkActivated(const QString &)), SLOT(infoLinkActivated(const QString &)) );
+ connect(groupBox,SIGNAL(clicked(bool)), this, SLOT(stateChanged(bool)));
+ searchLine->setListWidget(listWidget);
+
+ connect(addButton,SIGNAL(clicked()),this,SLOT(addExpr()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeSelected()));
+ connect(importButton, SIGNAL(clicked()), this, SLOT(importExpr()));
+
+ _config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals);
}
@@ -54,14 +82,118 @@ KCMWebkitAdblock::~KCMWebkitAdblock()
void KCMWebkitAdblock::defaults()
{
+ searchLine->clear();
+ lineEdit->clear();
+ listWidget->clear();
+ groupBox->setChecked(false); // set also _isAdblockEnabled
}
void KCMWebkitAdblock::load()
{
+ KConfigGroup cg(_config, _group);
+ groupBox->setChecked( cg.readEntry("Enabled", false) );
+
+ int num = cg.readEntry("Count", 0);
+ for (int i = 0; i < num; ++i)
+ {
+ QString key = "Filter-" + QString::number(i);
+ QString filter = cg.readEntry( key, QString() );
+ listWidget->addItem(filter);
+ }
+// updateButton();
}
void KCMWebkitAdblock::save()
{
+ KConfigGroup cg(_config, _group);
+ cg.deleteGroup();
+ cg = KConfigGroup(_config, _group);
+
+ cg.writeEntry("Enabled", groupBox->isChecked());
+
+ for(int i = 0; i < listWidget->count(); ++i )
+ {
+ QString key = "Filter-" + QString::number(i);
+ cg.writeEntry(key, listWidget->item(i)->text());
+ }
+ cg.writeEntry("Count", listWidget->count());
+ cg.sync();
+}
+
+
+void KCMWebkitAdblock::infoLinkActivated(const QString &url)
+{
+ QString helpString = 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.");
+
+
+ if ( url == "filterhelp" )
+ QWhatsThis::showText( QCursor::pos(), helpString );
+}
+
+
+void KCMWebkitAdblock::stateChanged(bool state)
+{
+ _isAdblockEnabled = state;
+}
+
+
+bool KCMWebkitAdblock::isAdblockEnabled()
+{
+ return _isAdblockEnabled;
+}
+
+
+void KCMWebkitAdblock::addExpr()
+{
+ listWidget->addItem( lineEdit->text() );
+ lineEdit->clear();
+}
+
+
+void KCMWebkitAdblock::removeSelected()
+{
+ listWidget->takeItem(listWidget->currentRow());
+ searchLine->clear();
+}
+
+
+void KCMWebkitAdblock::importExpr()
+{
+
+ QString target;
+ KUrl url("http://adblockplus.mozdev.org/easylist/easylist.txt");
+
+ kDebug() << "downloading list..";
+
+ bool success = KIO::NetAccess::download(url, target, 0);
+ if(!success)
+ {
+ kDebug() << "not success";
+ return;
+ }
+
+ QFile temp(target);
+ if (!temp.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ kDebug() << "File not open";
+ return;
+ }
+
+ QTextStream stream(&temp);
+ QString line;
+ do
+ {
+ line = stream.readLine();
+ if(!line.startsWith('!') && !line.startsWith('['))
+ listWidget->addItem(line);
+ }
+ while (!line.isNull());
+
+ KIO::NetAccess::removeTempFile(target);
}
diff --git a/src/adblock/kcmwebkitadblock.h b/src/adblock/kcmwebkitadblock.h
index 01f0e653..15442ac7 100644
--- a/src/adblock/kcmwebkitadblock.h
+++ b/src/adblock/kcmwebkitadblock.h
@@ -33,6 +33,7 @@
// KDE Includes
#include <kcmodule.h>
+#include <ksharedconfig.h>
class KCMWebkitAdblock : public KCModule, private Ui::WebkitAdblock
@@ -47,6 +48,22 @@ public:
void defaults();
void load();
void save();
+
+ bool isAdblockEnabled();
+
+private slots:
+ void infoLinkActivated(const QString &url);
+ void stateChanged(bool state);
+
+ void addExpr();
+ void removeSelected();
+ void importExpr();
+
+private:
+ bool _isAdblockEnabled;
+
+ KSharedConfig::Ptr _config;
+ QString _group;
};
#endif
diff --git a/src/adblock/webkitAdblock.desktop b/src/adblock/webkitAdblock.desktop
index 22195b82..61fa99c0 100644
--- a/src/adblock/webkitAdblock.desktop
+++ b/src/adblock/webkitAdblock.desktop
@@ -9,6 +9,6 @@ X-KDE-Library=kcm_webkitadblock
X-KDE-PluginKeyword=webkitAdblock
X-KDE-ParentApp=kcontrol
-Name=Webkit AdBlock Settings
+Name=Webkit AdBlock
Categories=Qt;KDE;X-KDE-settings-webbrowsing;
diff --git a/src/adblock/webkitadblock.ui b/src/adblock/webkitadblock.ui
index 8d7ac25f..c75c0f0f 100644
--- a/src/adblock/webkitadblock.ui
+++ b/src/adblock/webkitadblock.ui
@@ -15,23 +15,37 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="QCheckBox" name="enableAdblock">
- <property name="text">
- <string>Enable adblock</string>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>enable adblock</string>
</property>
- <property name="checked">
+ <property name="checkable">
<bool>true</bool>
</property>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>adblock settings</string>
+ <property name="checked">
+ <bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="KListWidget" name="klistWidget"/>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Search:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KListWidgetSearchLine" name="searchLine">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="KListWidget" name="listWidget"/>
</item>
<item>
<widget class="QLabel" name="label">
@@ -41,10 +55,10 @@
</widget>
</item>
<item>
- <widget class="KListWidgetSearchLine" name="searchline"/>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="KLineEdit" name="lineEdit"/>
+ </item>
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
@@ -52,24 +66,21 @@
</property>
</widget>
</item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
- <string>Remove</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="searchButton">
- <property name="text">
- <string>Search</string>
+ <string>Remove Expr</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="importButton">
<property name="text">
- <string>Import</string>
+ <string>Import from...</string>
</property>
</widget>
</item>
diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp
index 1db38b96..1dde1196 100644
--- a/src/settings/settingsdialog.cpp
+++ b/src/settings/settingsdialog.cpp
@@ -70,6 +70,7 @@ private:
KCModuleProxy *ebrowsingModule;
KCModuleProxy *cookiesModule;
KCModuleProxy *cacheModule;
+ KCModuleProxy *adblockModule;
KShortcutsEditor *shortcutsEditor;
Private(SettingsDialog *parent);
@@ -124,6 +125,11 @@ Private::Private(SettingsDialog *parent)
KIcon webkitIcon = KIcon(QIcon(webkitIconPath));
pageItem->setIcon(webkitIcon);
+ KCModuleInfo adblockInfo("webkitAdblock.desktop");
+ adblockModule = new KCModuleProxy(adblockInfo,parent);
+ pageItem = parent->addPage(adblockModule, i18n(adblockInfo.moduleName().toLocal8Bit()));
+ pageItem->setIcon(KIcon(adblockInfo.icon()));
+
shortcutsEditor = new KShortcutsEditor(Application::instance()->mainWindow()->actionCollection(), parent);
pageItem = parent->addPage(shortcutsEditor , i18n("Shortcuts"));
pageItem->setIcon(KIcon("configure-shortcuts"));
@@ -133,7 +139,9 @@ Private::Private(SettingsDialog *parent)
pageItem = parent->addPage(ebrowsingModule, i18n(ebrowsingInfo.moduleName().toLocal8Bit()));
pageItem->setIcon(KIcon(ebrowsingInfo.icon()));
- parent->setMinimumSize(700,500);
+ // WARNING remember wheh changing here that the smaller netbooks
+ // have a 1024x576 resolution. So DONT bother that limits!!
+ parent->setMinimumSize(700,525);
}
@@ -144,22 +152,20 @@ SettingsDialog::SettingsDialog(QWidget *parent)
: KConfigDialog(parent, "rekonfig", ReKonfig::self())
, d(new Private(this))
{
- setFaceType(KPageDialog::Tree);
- showButtonSeparator(true);
-
- setWindowTitle(i18n("rekonfig..."));
+ showButtonSeparator(false);
+ setWindowTitle(i18n("Configure - rekonq"));
setModal(true);
readConfig();
-
connect(d->generalUi.setHomeToCurrentPageButton, SIGNAL(clicked()), this, SLOT(setHomeToCurrentPage()));
connect(d->ebrowsingModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
connect(d->cookiesModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
connect(d->proxyModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
connect(d->cacheModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
-
+ connect(d->adblockModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
+
connect(d->shortcutsEditor, SIGNAL(keyChange()), this, SLOT(updateButtons()));
connect(this, SIGNAL(applyClicked()), this, SLOT(saveSettings()));
@@ -209,6 +215,7 @@ void SettingsDialog::saveSettings()
d->proxyModule->save();
d->cacheModule->save();
d->shortcutsEditor->save();
+ d->adblockModule->save();
}
@@ -219,6 +226,7 @@ bool SettingsDialog::hasChanged()
|| d->cookiesModule->changed()
|| d->proxyModule->changed()
|| d->cacheModule->changed()
+ || d->adblockModule->changed()
|| d->shortcutsEditor->isModified();
;
}