summaryrefslogtreecommitdiffstats
path: root/konq-plugins/adblock/adblockdialogue.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-11 16:46:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-11 16:46:50 +0000
commit33c3e5147d3fb1a0949e800049eb9db0852bd3c3 (patch)
treeaf3b7fe2d56a00b9a81123e2676af1e5742e42c2 /konq-plugins/adblock/adblockdialogue.cpp
parent67661736baddc666cf1ed47c0ca3284dc34e1b85 (diff)
downloadtdeaddons-33c3e5147d3fb1a0949e800049eb9db0852bd3c3.tar.gz
tdeaddons-33c3e5147d3fb1a0949e800049eb9db0852bd3c3.zip
Added missing adblock plugin files
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1073116 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'konq-plugins/adblock/adblockdialogue.cpp')
-rw-r--r--konq-plugins/adblock/adblockdialogue.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/konq-plugins/adblock/adblockdialogue.cpp b/konq-plugins/adblock/adblockdialogue.cpp
new file mode 100644
index 0000000..5de6efa
--- /dev/null
+++ b/konq-plugins/adblock/adblockdialogue.cpp
@@ -0,0 +1,163 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ Copyright (C) 2006 Daniele Galdi <daniele.galdi@gmail.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)
+ any later version.
+
+ 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, write to the Free Software Foundation, Inc., 51
+ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "adblock.h"
+#include "adblockdialogue.h"
+
+#include <kdebug.h>
+#include <kpopupmenu.h>
+#include <klocale.h>
+
+#include <qcursor.h>
+#include <qlabel.h>
+#include <qvbox.h>
+#include <qlineedit.h>
+#include <qcolor.h>
+#include <qfont.h>
+#include <qpainter.h>
+
+AdBlockDlg::AdBlockDlg(QWidget *parent, AdElementList &elements) :
+ KDialogBase( parent, "Adblock dialogue", true, "Adblock - able Items", Ok|Cancel, Ok, true )
+{
+ QVBox *page = makeVBoxMainWidget();
+ m_label1 = new QLabel( i18n("All blockable items in this page:"), page, "label1" );
+
+ m_list = new QListView(page);
+ m_list->setAllColumnsShowFocus( true );
+
+ m_list->addColumn( i18n("Source") );
+ m_list->addColumn( i18n("Category") );
+ m_list->addColumn( i18n("Node Name") );
+
+ m_list->setColumnWidthMode(0, QListView::Manual);
+ m_list->setColumnWidthMode(1, QListView::Manual);
+ m_list->setColumnWidthMode(2, QListView::Manual);
+
+ m_list->setColumnWidth(0, 600);
+ m_list->setColumnWidth(1, 90);
+ m_list->setColumnWidth(2, 90);
+
+ AdElementList::iterator it;
+ for ( it = elements.begin(); it != elements.end(); ++it )
+ {
+ AdElement &element = (*it);
+
+ QString url = element.url();
+
+ ListViewItem *item = new ListViewItem( m_list, url, element.category(), element.type() );
+ item->setBlocked(element.isBlocked());
+ }
+
+ m_label2 = new QLabel( i18n("New filter (use * as a wildcard):"), page, "label2" );
+
+ m_filter = new QLineEdit( "", page, "lineedit" );
+
+ connect(this, SIGNAL( okClicked() ), this, SLOT( validateFilter() ));
+ connect(m_list, SIGNAL( doubleClicked(QListViewItem *, const QPoint &, int) ), this, SLOT(updateFilter(QListViewItem *)) );
+
+ m_menu = new KPopupMenu(this);
+ m_menu->insertItem(i18n("Filter this item"), this, SLOT(filterItem()));
+ m_menu->insertItem(i18n("Filter all items at same path"), this, SLOT(filterPath()));
+
+ connect(m_list,
+ SIGNAL( contextMenuRequested( QListViewItem *, const QPoint& , int ) ),
+ this,
+ SLOT( showContextMenu(QListViewItem *, const QPoint &) ) );
+}
+
+void AdBlockDlg::updateFilter(QListViewItem *selected)
+{
+ ListViewItem *item = dynamic_cast<ListViewItem *>(selected);
+
+ if (item->isBlocked())
+ {
+ m_filter->setText("");
+ return;
+ }
+
+ m_filter->setText( item->text(0) );
+}
+
+void AdBlockDlg::validateFilter()
+{
+ const QString text = m_filter->text().stripWhiteSpace();
+
+ if (!text.isEmpty())
+ emit notEmptyFilter(text);
+
+ delayedDestruct();
+}
+
+void AdBlockDlg::showContextMenu(QListViewItem *item, const QPoint &point)
+{
+ if (!item) return;
+ m_menu->popup(point);
+}
+
+void AdBlockDlg::filterItem()
+{
+ QListViewItem* item = m_list->selectedItem();
+ m_filter->setText( item->text(0) );
+}
+
+void AdBlockDlg::filterPath()
+{
+ QListViewItem* item = m_list->selectedItem();
+ QString value = item->text(0);
+ m_filter->setText( value.section( '/', 0, -2 ).append("/*") );
+}
+
+AdBlockDlg::~AdBlockDlg()
+{
+ delete m_label1;
+ delete m_label2;
+ delete m_filter;
+ delete m_list;
+}
+
+// ----------------------------------------------------------------------------
+
+void ListViewItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int align)
+{
+ p->save();
+ QColorGroup g( cg );
+
+ if ( isBlocked() )
+ {
+ g.setColor(QColorGroup::Text, red);
+ QFont font;
+ font.setItalic(true);
+ p->setFont(font);
+ }
+
+ QListViewItem::paintCell(p, g, column, width, align);
+ p->restore();
+}
+
+inline bool ListViewItem::isBlocked()
+{
+ return m_blocked;
+}
+
+inline void ListViewItem::setBlocked(bool blocked)
+{
+ m_blocked = blocked;
+}
+
+#include "adblockdialogue.moc"