┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views/dolphinview.h
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2021-02-08 21:32:10 +0000
committerElvis Angelaccio <[email protected]>2021-02-08 21:32:10 +0000
commita825e1bd74246dc97dde3f48b1d9ead7a214b744 (patch)
tree57158cf021f5db25b1f3740ec7db870569d2f622 /src/views/dolphinview.h
parent7eae6bba5f2c9dbd9e40e1194e8455e9e4ed3f6d (diff)
Avoid KJob::exec() in DolphinView
This commit replaces an error-prone usage of KIO::StatJob::exec() in DolphinView with the recommended KIO::StatJob::start(). The containing method DolphinView::statusBarText() is changed to be a method without return value: requestStatusBarText() The new status bar text is instead returned through a new setStatusBarText() signal that will be emitted asynchronously if necessary. The calling code that deals with status bar text is refactored to correctly work despite the new asynchronicity. The helper method calculateItemCount() is moved into requestStatusBarText() and some other code from requestStatusBarText() is moved into a new helper method emitStatusBarText(). The documentation of KIO::KJob::exec() explains why it should be avoided. A reproducible crash is the reason for this commit.
Diffstat (limited to 'src/views/dolphinview.h')
-rw-r--r--src/views/dolphinview.h48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index d0285da85..ab3e86f15 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -19,6 +19,7 @@
#include <kparts/part.h>
#include <QMimeData>
+#include <QPointer>
#include <QUrl>
#include <QWidget>
@@ -240,10 +241,13 @@ public:
QStringList mimeTypeFilters() const;
/**
- * Returns a textual representation of the state of the current
+ * Tells the view to generate an updated status bar text. The result
+ * is returned through the statusBarTextChanged(QString statusBarText) signal.
+ * It will carry a textual representation of the state of the current
* folder or selected items, suitable for use in the status bar.
+ * Any pending requests of status bar text are killed.
*/
- QString statusBarText() const;
+ void requestStatusBarText();
/**
* Returns the version control actions that are provided for the items \p items.
@@ -450,6 +454,10 @@ signals:
/** Is emitted if the 'grouped sorting' property has been changed. */
void groupedSortingChanged(bool groupedSorting);
+ /** Is emmited in reaction to a requestStatusBarText() call.
+ * @see requestStatusBarText() */
+ void statusBarTextChanged(QString statusBarText);
+
/** Is emitted if the sorting by name, size or date has been changed. */
void sortRoleChanged(const QByteArray& role);
@@ -643,6 +651,15 @@ private slots:
void emitSelectionChangedSignal();
/**
+ * Helper method for DolphinView::requestStatusBarText().
+ * Calculates the amount of folders and files and their total size in
+ * response to a KStatJob::result(), then calls emitStatusBarText().
+ * @see requestStatusBarText()
+ * @see emitStatusBarText()
+ */
+ void slotStatJobResult(KJob *job);
+
+ /**
* Updates the view properties of the current URL to the
* sorting given by \a role.
*/
@@ -735,16 +752,6 @@ private slots:
*/
void slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl);
- /**
- * Calculates the number of currently shown files into
- * \a fileCount and the number of folders into \a folderCount.
- * The size of all files is written into \a totalFileSize.
- * It is recommend using this method instead of asking the
- * directory lister or the model directly, as it takes
- * filtering and hierarchical previews into account.
- */
- void calculateItemCount(int& fileCount, int& folderCount, KIO::filesize_t& totalFileSize) const;
-
void slotTwoClicksRenamingTimerTimeout();
private:
@@ -769,6 +776,21 @@ private:
*/
void applyModeToView();
+ enum Selection {
+ HasSelection,
+ NoSelection
+ };
+ /**
+ * Helper method for DolphinView::requestStatusBarText().
+ * Generates the status bar text from the parameters and
+ * then emits statusBarTextChanged().
+ * @param totalFileSize the sum of the sizes of the files
+ * @param selection if HasSelection is passed, the emitted status bar text will say
+ * that the folders and files which are counted here are selected.
+ */
+ void emitStatusBarText(const int folderCount, const int fileCount,
+ KIO::filesize_t totalFileSize, const Selection selection);
+
/**
* Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
* Pastes the clipboard data into the URL \a url.
@@ -829,6 +851,8 @@ private:
Mode m_mode;
QList<QByteArray> m_visibleRoles;
+ QPointer<KIO::StatJob> m_statJobForStatusBarText;
+
QVBoxLayout* m_topLayout;
KFileItemModel* m_model;