--Boundary-00=_OxHnIPEWBdJkc/s Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_OxHnIPEWBdJkc/s Content-Type: text/x-diff; charset="utf-8"; name="dirfilterplugin.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dirfilterplugin.patch" 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 #include #include +#include +#include #include #include @@ -131,6 +133,7 @@ m_dirModel = qFindChild( 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

Clears the content of the filter field.

")); - -#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(search)->setIconView(static_cast(m_part->scrollWidget())); - } - else if ( m_part->scrollWidget()->inherits("K3ListView") ) - { - search = new K3ListViewSearchLine(hbox); - static_cast(search)->setListView(static_cast(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( m_part ); + proxyModel->setFilterRegExp(nextText); +} + typedef KGenericFactory 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 m_pMimeInfo; typedef QMap::Iterator MimeInfoIterator; --Boundary-00=_OxHnIPEWBdJkc/s--