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 applys the item states.
100 void slotThreadFinished();
103 typedef QPair
<KFileItem
, KVersionControlPlugin::ItemVersion
> ItemState
;
104 typedef QPair
<KVersionControlPlugin
*, QString
> VCSPlugin
;
106 void updateItemStates();
109 * It creates a item state list for every expanded directory and stores
110 * this list together with the directory url in the \a itemStates map.
112 * @itemStates A map of item state lists for every expanded directory
113 * and its items, where the "key" is the directory url and
114 * the "value" is a list of ItemStates for every item
115 * within this directory.
116 * @firstIndex The index to start the processing from, this is needed
117 * because this function is recursively called.
119 * @return The number of (recursive) processed items.
121 int createItemStatesList(QMap
<QString
, QVector
<ItemState
> >& itemStates
,
122 const int firstIndex
= 0);
125 * Returns a matching plugin for the given directory.
126 * 0 is returned, if no matching plugin has been found.
128 KVersionControlPlugin
* searchPlugin(const QUrl
& directory
);
131 * Returns true, if the directory contains a version control information.
133 bool isVersionControlled() const;
136 bool m_pendingItemStatesUpdate
;
137 bool m_versionedDirectory
;
138 bool m_silentUpdate
; // if true, no messages will be send during the update
142 KFileItemModel
* m_model
;
144 QTimer
* m_dirVerificationTimer
;
146 bool m_pluginsInitialized
;
147 KVersionControlPlugin
* m_plugin
;
148 QList
<VCSPlugin
> m_plugins
;
149 UpdateItemStatesThread
* m_updateItemStatesThread
;
151 friend class UpdateItemStatesThread
;
154 #endif // REVISIONCONTROLOBSERVER_H