summaryrefslogtreecommitdiff
path: root/src/adblock
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/adblock
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/adblock')
-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
5 files changed, 189 insertions, 26 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>