summaryrefslogtreecommitdiffstats
path: root/konq-plugins
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2015-01-16 12:37:51 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2015-01-16 12:47:31 +0900
commitb98e5a4b8449b5f05a892a3bbbcc26ae72f07fea (patch)
treedc649089dcca6a0dedcf35bab6349e7a71a5be4b /konq-plugins
parentc3ab177a3844ea28e56357748c27f0708a678dbe (diff)
downloadtdeaddons-b98e5a4b8449b5f05a892a3bbbcc26ae72f07fea.tar.gz
tdeaddons-b98e5a4b8449b5f05a892a3bbbcc26ae72f07fea.zip
Added required refreshItems logic. This resolves bug 146.
(cherry picked from commit 064539d8a51f8f8ed4119b5286e077620a5ac8c5) Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'konq-plugins')
-rw-r--r--konq-plugins/dirfilter/dirfilterplugin.cpp135
-rw-r--r--konq-plugins/dirfilter/dirfilterplugin.h1
2 files changed, 119 insertions, 17 deletions
diff --git a/konq-plugins/dirfilter/dirfilterplugin.cpp b/konq-plugins/dirfilter/dirfilterplugin.cpp
index 6aaf2b1..c55b6e6 100644
--- a/konq-plugins/dirfilter/dirfilterplugin.cpp
+++ b/konq-plugins/dirfilter/dirfilterplugin.cpp
@@ -144,8 +144,6 @@ void SessionManager::loadSettings()
DirFilterPlugin::DirFilterPlugin (TQObject* parent, const char* name,
const TQStringList&)
:KParts::Plugin (parent, name),
- m_pFilterMenu(0),
- m_searchWidget(0),
m_oldFilterString("")
{
m_part = ::tqqt_cast<KonqDirPart*>(parent);
@@ -161,12 +159,14 @@ DirFilterPlugin::DirFilterPlugin (TQObject* parent, const char* name,
connect (m_pFilterMenu->popupMenu(), TQT_SIGNAL (aboutToShow()),
TQT_SLOT (slotShowPopup()));
- connect (m_part, TQT_SIGNAL (itemRemoved(const KFileItem*)),
+ connect (m_part, TQT_SIGNAL(itemRemoved(const KFileItem*)),
TQT_SLOT( slotItemRemoved (const KFileItem*)));
- connect (m_part, TQT_SIGNAL (itemsAdded(const KFileItemList&)),
+ connect (m_part, TQT_SIGNAL(itemsAdded(const KFileItemList&)),
TQT_SLOT (slotItemsAdded(const KFileItemList&)));
- connect (m_part, TQT_SIGNAL (itemsFilteredByMime(const KFileItemList&)),
+ connect (m_part, TQT_SIGNAL(itemsFilteredByMime(const KFileItemList&)),
TQT_SLOT (slotItemsAdded(const KFileItemList&)));
+ connect (m_part, TQT_SIGNAL(itemsRefresh(const KFileItemList&)),
+ TQT_SLOT (slotItemsRefresh(const KFileItemList&)));
connect (m_part, TQT_SIGNAL(aboutToOpenURL()), TQT_SLOT(slotOpenURL()));
// add a searchline filter for konqis icons/list views
@@ -189,7 +189,10 @@ DirFilterPlugin::DirFilterPlugin (TQObject* parent, const char* name,
m_searchWidget = new TDEIconViewSearchLine(hbox);
static_cast<TDEIconViewSearchLine*>(m_searchWidget)->setIconView(static_cast<TQIconView*>(m_part->scrollWidget()));
}
-
+ else
+ {
+ m_searchWidget=NULL;
+ }
if ( m_searchWidget )
{
@@ -407,7 +410,7 @@ void DirFilterPlugin::slotItemSelected (int id)
}
}
-void DirFilterPlugin::slotItemsAdded (const KFileItemList& list)
+void DirFilterPlugin::slotItemsAdded(const KFileItemList &list)
{
KURL url = m_part->url();
@@ -438,10 +441,10 @@ void DirFilterPlugin::slotItemsAdded (const KFileItemList& list)
continue;
TQString mimeType = mime->name();
- if (!m_pMimeInfo.contains (mimeType))
+ if (!m_pMimeInfo.contains(mimeType))
{
MimeInfo& mimeInfo = m_pMimeInfo[mimeType];
- TQStringList filters = m_part->mimeFilter ();
+ TQStringList filters = m_part->mimeFilter();
mimeInfo.useAsFilter = (!filters.isEmpty () && filters.contains (mimeType));
mimeInfo.mimeComment = mime->comment();
mimeInfo.iconName = mime->icon(KURL(), false);
@@ -454,7 +457,7 @@ void DirFilterPlugin::slotItemsAdded (const KFileItemList& list)
}
}
-void DirFilterPlugin::slotItemRemoved (const KFileItem* item)
+void DirFilterPlugin::slotItemRemoved(const KFileItem* item)
{
if (!item || !m_part)
return;
@@ -474,24 +477,122 @@ void DirFilterPlugin::slotItemRemoved (const KFileItem* item)
TQString mimeType = item->mimetype().stripWhiteSpace();
- if (m_pMimeInfo.contains (mimeType)) {
+ if (m_pMimeInfo.contains(mimeType)) {
MimeInfo info = m_pMimeInfo [mimeType];
if (info.filenames.size () > 1)
- m_pMimeInfo [mimeType].filenames.remove (item->name ());
+ m_pMimeInfo [mimeType].filenames.remove(item->name());
else {
if (info.useAsFilter) {
TQStringList filters = m_part->mimeFilter ();
- filters.remove (mimeType);
- m_part->setMimeFilter (filters);
- SessionManager::self()->save (m_part->url(), filters);
- TQTimer::singleShot( 0, this, TQT_SLOT(slotTimeout()) );
+ filters.remove(mimeType);
+ m_part->setMimeFilter(filters);
+ SessionManager::self()->save(m_part->url(), filters);
+ // Use 1ms delay to avoid possible race conditions
+ TQTimer::singleShot(1, this, TQT_SLOT(slotTimeout()));
}
- m_pMimeInfo.remove (mimeType);
+ m_pMimeInfo.remove(mimeType);
}
}
}
+void DirFilterPlugin::slotItemsRefresh(const KFileItemList &list)
+{
+ if (list.count() == 0 || !m_part || !m_part->nameFilter().isEmpty())
+ {
+ m_pFilterMenu->setEnabled (m_part->nameFilter().isEmpty());
+ return;
+ }
+ if ( ::tqqt_cast<TDEListView*>(m_part->scrollWidget()) )
+ {
+ static_cast<TDEListViewSearchLine*>(m_searchWidget)->updateSearch();
+ }
+ else if ( ::tqqt_cast<TQIconView*>(m_part->scrollWidget()) )
+ {
+ static_cast<TDEIconViewSearchLine*>(m_searchWidget)->updateSearch();
+ }
+
+ TQMap<TQString,bool> itemsMap;
+ if (::tqqt_cast<TDEListView*>(m_part->scrollWidget()))
+ {
+ TQListView *listview = ::tqqt_cast<TDEListView*>(m_part->scrollWidget());
+ for (TQListViewItemIterator lv_it(listview); lv_it.current(); ++lv_it)
+ {
+ itemsMap.insert(lv_it.current()->text(0), false);
+ }
+ }
+ else if ( ::tqqt_cast<TQIconView*>(m_part->scrollWidget()) )
+ {
+ TQIconView *iconview = ::tqqt_cast<TQIconView*>(m_part->scrollWidget());
+ for (TQIconViewItem *item = iconview->firstItem(); item; item = item->nextItem())
+ {
+ itemsMap.insert(item->text(), false);
+ }
+ }
+
+ MimeInfoIterator it;
+ for (it = m_pMimeInfo.begin(); it != m_pMimeInfo.end(); /*empty*/)
+ {
+ TQMap<TQString,bool>::iterator file_it;
+ for ( file_it = it.data().filenames.begin(); file_it != it.data().filenames.end(); /*empty*/)
+ {
+ if (!itemsMap.contains(file_it.key()))
+ {
+ // Remove mimeInfo for this file (the file was problably renamed)
+ TQMap<TQString,bool>::iterator del_fit = file_it;
+ ++file_it;
+ it.data().filenames.remove(del_fit);
+ }
+ else
+ ++file_it;
+ }
+
+ if (it.data().filenames.size() == 0)
+ {
+ if (it.data().useAsFilter) {
+ TQStringList filters = m_part->mimeFilter();
+ filters.remove(it.key());
+ m_part->setMimeFilter(filters);
+ SessionManager::self()->save(m_part->url(), filters);
+ // Use 1ms delay to avoid possible race conditions
+ TQTimer::singleShot(1, this, TQT_SLOT(slotTimeout()));
+ }
+ MimeInfoIterator del_mit = it;
+ ++it;
+ m_pMimeInfo.remove(del_mit);
+ }
+ else
+ ++it;
+ }
+
+ for (KFileItemListIterator fi_it(list); fi_it.current (); ++fi_it)
+ {
+ TQString name = fi_it.current()->name();
+ KMimeType::Ptr mime = fi_it.current()->mimeTypePtr(); // don't resolve mimetype if unknown
+ if (!mime)
+ continue;
+ TQString mimeType = mime->name();
+
+ if (!m_pMimeInfo.contains(mimeType))
+ {
+ MimeInfo &mimeInfo = m_pMimeInfo[mimeType];
+ TQStringList filters = m_part->mimeFilter();
+ mimeInfo.useAsFilter = (!filters.isEmpty () && filters.contains (mimeType));
+ mimeInfo.mimeComment = mime->comment();
+ mimeInfo.iconName = mime->icon(KURL(), false);
+ mimeInfo.filenames.insert(name, false);
+ }
+ else
+ {
+ MimeInfo &mimeInfo = m_pMimeInfo[mimeType];
+ if (!mimeInfo.filenames.contains(name))
+ {
+ mimeInfo.filenames.insert(name, false);
+ }
+ }
+ }
+}
+
void DirFilterPlugin::activateSearch()
{
// FIXME: If any of the files change while they are hidden in iconview mode, they will
diff --git a/konq-plugins/dirfilter/dirfilterplugin.h b/konq-plugins/dirfilter/dirfilterplugin.h
index 1bf914e..f4012ce 100644
--- a/konq-plugins/dirfilter/dirfilterplugin.h
+++ b/konq-plugins/dirfilter/dirfilterplugin.h
@@ -121,6 +121,7 @@ private slots:
void slotItemSelected(int);
void slotItemRemoved(const KFileItem *);
void slotItemsAdded(const KFileItemList &);
+ void slotItemsRefresh(const KFileItemList &);
void activateSearch();
void searchTextChanged(const TQString& newtext);
void reactivateRefreshTimer();