[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    [Semi-patch] Konqueror dirfilterplugin
From:       Simon St James <kdedevel () etotheipiplusone ! com>
Date:       2008-08-08 17:03:10
Message-ID: 200808081803.10688.kdedevel () etotheipiplusone ! com
[Download RAW message or body]

Hi all,

Adrien's post, here

http://lists.kde.org/?l=kfm-devel&m=121803038920475&w=2

was interesting timing, as I think I'm running into similar issues.

I saw someone on the Dot who was apparently very upset that dirfilterplugin 
wasn't working for Konqueror 4.0, and so I had a go at fixing it (it's that 
plugin that puts a line editor in the Extra toolbar so that you can filter 
out files by filename).

It's mostly working, but I'm running into a few issues: the original 
dirfilterplugin used an interesting hack to get hold of some of the Konqueror 
internals (using qFindChild) and I've done the same here, but it feels rather 
naughty as I'm grabbing rather private parts of Dolphin and manipulating them 
without its permission, which I'm quite sure is illegal in most parts of the 
world.  It also doesn't work at all with column view, as this requires some 
additional hacks, as noted in the Dolphin source.

Any suggestions on how to proceed? I've added "HACK HACK HACK" markers to the 
relevant parts of the patch and my own suggestions but, again, I'm still 
pretty new to this :)

I'm a subscriber, so no need to CC me :)

Best Wishes,
Simon

["dirfilterplugin.patch" (text/x-diff)]

Index: konq-plugins/dirfilter/dirfilterplugin.cpp
===================================================================
--- konq-plugins/dirfilter/dirfilterplugin.cpp	(revision 843230)
+++ konq-plugins/dirfilter/dirfilterplugin.cpp	(working copy)
@@ -35,6 +35,8 @@
 #include <kmenu.h>
 #include <kmessagebox.h>
 #include <kiconloader.h>
+#include <klineedit.h>
+#include <kdirsortfilterproxymodel.h>
 
 #include <kdirlister.h>
 #include <kgenericfactory.h>
@@ -131,6 +133,7 @@
   m_dirModel = qFindChild<KDirLister*>( m_part );
   if ( !m_dirModel )
       return;
+
   m_pFilterMenu = new KActionMenu (KIcon("search-filter"),i18n("View F&ilter"),
                                    actionCollection());
   actionCollection()->addAction("filterdir", m_pFilterMenu);
@@ -149,40 +152,17 @@
            SLOT (slotItemsAdded(const KFileItemList&)));
   connect (m_part, SIGNAL(aboutToOpenURL()), SLOT(slotOpenURL()));
 
-  // add a searchline filter for konqis icons/list views
-  KHBox *hbox = new KHBox(m_part->widget());
-  hbox->hide();
+  // Create, add and connect the widget for editing the current filter string.
+  KLineEdit *filterEdit = new KLineEdit();
+  filterEdit->setMaximumWidth(150);
+  filterEdit->setClearButtonShown (true);
 
-  QAction *clear = actionCollection()->addAction("clear_filter");
-  clear->setText(i18n("Clear Filter Field"));
-  clear->setIcon(KIcon(QApplication::isRightToLeft() ? "clear-left" : \
                "locationbar-erase"));
-  clear->setWhatsThis(i18n("Clear filter field<p>Clears the content of the filter \
                field.</p>"));
-
-#if 0
-  QWidget *search = 0;
-  // TODO port to the non-q3 classes
-  if ( m_part->scrollWidget()->inherits("Q3IconView") ) // TODO qobject_cast
-  {
-    search = new K3IconViewSearchLine(hbox);
-    static_cast<K3IconViewSearchLine*>(search)->setIconView(static_cast<Q3IconView*>(m_part->scrollWidget()));
                
-  }
-  else if ( m_part->scrollWidget()->inherits("K3ListView") )
-  {
-    search = new K3ListViewSearchLine(hbox);
-    static_cast<K3ListViewSearchLine*>(search)->setListView(static_cast<K3ListView*>(m_part->scrollWidget()));
                
-  }
-
-  if ( search )
-  {
-    search->setWhatsThis( i18n("Enter here a text which an item in the view must \
                contain anywhere to be shown."));
-    connect(clear, SIGNAL(activated()), search, SLOT(clear()));
-  }
-#endif
-
   KAction *filterAction = actionCollection()->addAction("toolbar_filter_field");
   filterAction->setText(i18n("Filter Field"));
-  filterAction->setDefaultWidget( hbox );
+  filterAction->setDefaultWidget( filterEdit );
   filterAction->setShortcutConfigurable(false);
+
+  connect (filterEdit, SIGNAL(textEdited(const QString&)), this, \
SLOT(slotFilterTextEdited(const QString&)));  }
 
 DirFilterPlugin::~DirFilterPlugin()
@@ -194,7 +174,6 @@
 {
   KUrl url = m_part->url();
 
-  //kDebug(90190) << "DirFilterPlugin: New URL    : " << url.url();
   //kDebug(90190) << "DirFilterPlugin: Current URL: " << m_pURL.url();
 
   if (m_pURL != url)
@@ -293,6 +272,7 @@
 
   action = m_pFilterMenu->menu()->addAction (i18n("Reset"), this,
                                                SLOT(slotReset()));
+  disconnect(  m_pFilterMenu->menu(), SIGNAL( triggered ( QAction * ) ),this,SLOT( \
slotItemSelected( QAction* ) ) );  connect(  m_pFilterMenu->menu(), SIGNAL( triggered \
( QAction * ) ),this,SLOT( slotItemSelected( QAction* ) ) );  action->setEnabled( \
enableReset);  }
@@ -342,8 +322,14 @@
       m_dirModel->setMimeFilter (filters);
     }
 
+    // This change feels like a bit of a HACK HACK HACK,
+    // but the previous (commented-out) code didn't work.
+    // Again, maybe an extra  Q_PROPERTY in the DolphinPart
+    // for setting the mime filter ... ?
     KUrl url = m_part->url();
-    m_part->openUrl (url);
+    m_dirModel->openUrl (url);
+    //KUrl url = m_part->url();
+    //m_part->openUrl (url);
     globalSessionManager->save (url, filters);
   }
 }
@@ -454,6 +440,14 @@
     m_part->openUrl (m_part->url());
 }
 
+void DirFilterPlugin::slotFilterTextEdited(const QString& nextText)
+{
+    // HACK HACK HACK - probably need some additional Q_PROPERTIES (in addition to
+    // setNameFilter(...) added to DolphinPart.
+    KDirSortFilterProxyModel *proxyModel = qFindChild<KDirSortFilterProxyModel*>( \
m_part ); +    proxyModel->setFilterRegExp(nextText);
+}
+
 typedef KGenericFactory<DirFilterPlugin> DirFilterFactory;
 K_EXPORT_COMPONENT_FACTORY (libdirfilterplugin, DirFilterFactory("dirfilterplugin"))
 
Index: konq-plugins/dirfilter/dirfilterplugin.h
===================================================================
--- konq-plugins/dirfilter/dirfilterplugin.h	(revision 843230)
+++ konq-plugins/dirfilter/dirfilterplugin.h	(working copy)
@@ -103,12 +103,13 @@
   void slotItemSelected(QAction*);
   void slotItemRemoved(const KFileItem &);
   void slotItemsAdded(const KFileItemList &);
+  void slotFilterTextEdited(const QString &);
 
 private:
   KUrl m_pURL;
   KParts::ReadOnlyPart* m_part;
   KActionMenu* m_pFilterMenu;
-    KDirLister* m_dirModel;
+  KDirLister* m_dirModel;
 
   QMap<QString,MimeInfo> m_pMimeInfo;
   typedef QMap<QString,MimeInfo>::Iterator MimeInfoIterator;



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic