2 * SPDX-FileCopyrightText: 2009 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef VERSIONCONTROLOBSERVER_H
8 #define VERSIONCONTROLOBSERVER_H
10 #include "dolphin_export.h"
12 #include "kversioncontrolplugin.h"
26 class UpdateItemStatesThread
;
31 * @brief Observes all version control plugins.
33 * The items of the directory-model get updated automatically if the currently
34 * shown directory is under version control.
36 * @see VersionControlPlugin
38 class DOLPHIN_EXPORT VersionControlObserver
: public QObject
43 explicit VersionControlObserver(QObject
* parent
= nullptr);
44 ~VersionControlObserver() override
;
46 void setModel(KFileItemModel
* model
);
47 KFileItemModel
* model() const;
48 void setView(DolphinView
* view
);
49 DolphinView
* view() const;
51 QList
<QAction
*> actions(const KFileItemList
& items
) const;
55 * Is emitted if an information message with the content \a msg
58 void infoMessage(const QString
& msg
);
61 * Is emitted if an error message with the content \a msg
64 void errorMessage(const QString
& msg
);
67 * Is emitted if an "operation completed" message with the content \a msg
70 void operationCompletedMessage(const QString
& msg
);
74 * Invokes verifyDirectory() with a small delay. If delayedDirectoryVerification()
75 * is invoked before the delay has been exceeded, the delay will be reset. This
76 * assures that a lot of short requests for directory verification only result
77 * in one (expensive) call.
79 void delayedDirectoryVerification();
82 * Invokes verifyDirectory() with a small delay. In opposite to
83 * delayedDirectoryVerification() it and assures that the verification of
84 * the directory is done silently without information messages.
86 void silentDirectoryVerification();
89 * Invokes delayedDirectoryVerification() only if the itemsChanged() signal has not
90 * been triggered by the VCS plugin itself.
92 void slotItemsChanged(const KItemRangeList
& itemRanges
, const QSet
<QByteArray
>& roles
);
94 void verifyDirectory();
97 * Is invoked if the thread m_updateItemStatesThread has been finished
98 * and applies the item states.
100 void slotThreadFinished();
103 typedef QPair
<KFileItem
, KVersionControlPlugin::ItemVersion
> ItemState
;
105 void updateItemStates();
108 * It creates a item state list for every expanded directory and stores
109 * this list together with the directory url in the \a itemStates map.
111 * @itemStates A map of item state lists for every expanded directory
112 * and its items, where the "key" is the directory url and
113 * the "value" is a list of ItemStates for every item
114 * within this directory.
115 * @firstIndex The index to start the processing from, this is needed
116 * because this function is recursively called.
118 * @return The number of (recursive) processed items.
120 int createItemStatesList(QMap
<QString
, QVector
<ItemState
> >& itemStates
,
121 const int firstIndex
= 0);
124 * Returns a matching plugin for the given directory.
125 * 0 is returned, if no matching plugin has been found.
127 KVersionControlPlugin
* searchPlugin(const QUrl
& directory
);
130 * Returns true, if the directory contains a version control information.
132 bool isVersionControlled() const;
137 bool m_pendingItemStatesUpdate
;
138 bool m_silentUpdate
; // if true, no messages will be send during the update
140 QString m_localRepoRoot
;
143 KFileItemModel
* m_model
;
145 QTimer
* m_dirVerificationTimer
;
147 bool m_pluginsInitialized
;
148 KVersionControlPlugin
* m_plugin
;
149 QList
<QPointer
<KVersionControlPlugin
>> m_plugins
;
150 UpdateItemStatesThread
* m_updateItemStatesThread
;
152 friend class UpdateItemStatesThread
;
155 #endif // REVISIONCONTROLOBSERVER_H