┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMéven Car <[email protected]>2021-04-24 09:00:31 +0000
committerMéven Car <[email protected]>2021-04-24 09:00:31 +0000
commit6cec386192e58089b4572996a265c9696cdcb3c0 (patch)
tree4a32fc3ac2feef856774247d01c0f3d13cb4209c
parent020ba2c3fc94336545f6b8d7c13c9a615000482a (diff)
InformationPanel: Allow to refresh the panel when its displayed content changes
BUG: 430095 BUG: 412902 FIXED-IN: 21.08
-rw-r--r--src/dolphinmainwindow.cpp5
-rw-r--r--src/dolphinmainwindow.h11
-rw-r--r--src/kitemviews/kfileitemmodel.cpp14
-rw-r--r--src/kitemviews/kfileitemmodel.h6
-rw-r--r--src/panels/information/informationpanel.cpp10
-rw-r--r--src/panels/information/informationpanel.h2
-rw-r--r--src/views/dolphinview.cpp1
-rw-r--r--src/views/dolphinview.h2
8 files changed, 49 insertions, 2 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index a126a0bf4..f14849e6d 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -24,7 +24,6 @@
#include "panels/folders/folderspanel.h"
#include "panels/places/placesitemmodel.h"
#include "panels/places/placespanel.h"
-#include "panels/information/informationpanel.h"
#include "panels/terminal/terminalpanel.h"
#include "settings/dolphinsettingsdialog.h"
#include "statusbar/dolphinstatusbar.h"
@@ -1788,6 +1787,8 @@ void DolphinMainWindow::setupDockWidgets()
infoPanel, &InformationPanel::setSelection);
connect(this, &DolphinMainWindow::requestItemInfo,
infoPanel, &InformationPanel::requestDelayedItemInfo);
+ connect(this, &DolphinMainWindow::fileItemsChanged,
+ infoPanel, &InformationPanel::slotFilesItemChanged);
#endif
// i18n: This is the last paragraph for the "What's This"-texts of all four panels.
@@ -2173,6 +2174,8 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
this, &DolphinMainWindow::slotSelectionChanged);
connect(view, &DolphinView::requestItemInfo,
this, &DolphinMainWindow::requestItemInfo);
+ connect(view, &DolphinView::fileItemsChanged,
+ this, &DolphinMainWindow::fileItemsChanged);
connect(view, &DolphinView::tabRequested,
this, &DolphinMainWindow::openNewTab);
connect(view, &DolphinView::requestContextMenu,
diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h
index 396afbd90..f351cc992 100644
--- a/src/dolphinmainwindow.h
+++ b/src/dolphinmainwindow.h
@@ -15,6 +15,10 @@
#include <KSortableList>
#include <kxmlguiwindow.h>
+#ifdef HAVE_BALOO
+ #include "panels/information/informationpanel.h"
+#endif
+
#include <QIcon>
#include <QList>
#include <QMenu>
@@ -193,6 +197,12 @@ Q_SIGNALS:
void requestItemInfo(const KFileItem& item);
/**
+ * It is emitted when in the current view, files are changed,
+ * or dirs have files/removed from them.
+ */
+ void fileItemsChanged(const KFileItemList &changedFileItems);
+
+ /**
* Is emitted if the settings have been changed.
*/
void settingsChanged();
@@ -656,7 +666,6 @@ private:
QMetaObject::Connection m_updateHistoryConnection;
QMenu m_searchTools;
-
};
inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index da15ccbdd..fa101f89a 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -1015,6 +1015,8 @@ void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemLis
// emitted during the maximum update interval.
m_maximumUpdateIntervalTimer->start();
}
+
+ Q_EMIT fileItemsChanged({KFileItem(directoryUrl)});
}
void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
@@ -1023,6 +1025,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
QVector<int> indexesToRemove;
indexesToRemove.reserve(items.count());
+ KFileItemList dirsChanged;
for (const KFileItem& item : items) {
const int indexForItem = index(item);
@@ -1036,6 +1039,11 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
m_filteredItems.erase(it);
}
}
+
+ QUrl parentUrl = item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash);
+ if (dirsChanged.findByUrl(parentUrl).isNull()) {
+ dirsChanged << KFileItem(parentUrl);
+ }
}
std::sort(indexesToRemove.begin(), indexesToRemove.end());
@@ -1063,6 +1071,8 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
const KItemRangeList itemRanges = KItemRangeList::fromSortedContainer(indexesToRemove);
removeFilteredChildren(itemRanges);
removeItems(itemRanges, DeleteItemData);
+
+ Q_EMIT fileItemsChanged(dirsChanged);
}
void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items)
@@ -1077,6 +1087,7 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
indexes.reserve(items.count());
QSet<QByteArray> changedRoles;
+ KFileItemList changedFiles;
QListIterator<QPair<KFileItem, KFileItem> > it(items);
while (it.hasNext()) {
@@ -1102,6 +1113,7 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
m_items.remove(oldItem.url());
m_items.insert(newItem.url(), indexForItem);
+ changedFiles.append(newItem);
indexes.append(indexForItem);
} else {
// Check if 'oldItem' is one of the filtered items.
@@ -1130,6 +1142,8 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
std::sort(indexes.begin(), indexes.end());
const KItemRangeList itemRangeList = KItemRangeList::fromSortedContainer(indexes);
emitItemsChangedAndTriggerResorting(itemRangeList, changedRoles);
+
+ Q_EMIT fileItemsChanged(changedFiles);
}
void KFileItemModel::slotClear()
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index 886a1c6de..acf4b761c 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -245,6 +245,12 @@ Q_SIGNALS:
*/
void urlIsFileError(const QUrl& url);
+ /**
+ * It is emitted for files when they change and
+ * for dirs when files are added or removed.
+ */
+ void fileItemsChanged(const KFileItemList &changedFileItems);
+
protected:
void onGroupedSortingChanged(bool current) override;
void onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems = true) override;
diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp
index f843e7f46..9a6fc3708 100644
--- a/src/panels/information/informationpanel.cpp
+++ b/src/panels/information/informationpanel.cpp
@@ -242,6 +242,7 @@ void InformationPanel::showItemInfo()
connect(m_folderStatJob, &KIO::Job::result,
this, &InformationPanel::slotFolderStatFinished);
} else {
+ m_shownUrl = item.url();
m_content->showItem(item);
}
}
@@ -303,6 +304,15 @@ void InformationPanel::slotFilesAdded(const QString& directory)
}
}
+void InformationPanel::slotFilesItemChanged(const KFileItemList &changedFileItems)
+{
+ const auto item = changedFileItems.findByUrl(m_shownUrl);
+ if (!item.isNull()) {
+ m_fileItem = item;
+ showItemInfo();
+ }
+}
+
void InformationPanel::slotFilesChanged(const QStringList& files)
{
for (const QString& fileName : files) {
diff --git a/src/panels/information/informationpanel.h b/src/panels/information/informationpanel.h
index debd88e46..d7f89bc9c 100644
--- a/src/panels/information/informationpanel.h
+++ b/src/panels/information/informationpanel.h
@@ -46,6 +46,8 @@ public Q_SLOTS:
*/
void requestDelayedItemInfo(const KFileItem& item);
+ void slotFilesItemChanged(const KFileItemList &changedFileItems);
+
protected:
/** @see Panel::urlChanged() */
bool urlChanged() override;
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 987066419..ce77dd325 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -179,6 +179,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
connect(m_model, &KFileItemModel::errorMessage, this, &DolphinView::errorMessage);
connect(m_model, &KFileItemModel::directoryRedirection, this, &DolphinView::slotDirectoryRedirection);
connect(m_model, &KFileItemModel::urlIsFileError, this, &DolphinView::urlIsFileError);
+ connect(m_model, &KFileItemModel::fileItemsChanged, this, &DolphinView::fileItemsChanged);
connect(this, &DolphinView::itemCountChanged,
this, &DolphinView::updatePlaceholderLabel);
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index be8263917..bb093774f 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -593,6 +593,8 @@ Q_SIGNALS:
void goUpRequested();
+ void fileItemsChanged(const KFileItemList &changedFileItems);
+
protected:
/** Changes the zoom level if Control is pressed during a wheel event. */
void wheelEvent(QWheelEvent* event) override;