]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/versioncontrol/versioncontrolobserver.h
For VCS-plugin interface added pure virtual function outOfVersionControlActions()
[dolphin.git] / src / views / versioncontrol / versioncontrolobserver.h
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef VERSIONCONTROLOBSERVER_H
21 #define VERSIONCONTROLOBSERVER_H
22
23 #include "dolphin_export.h"
24
25 #include "kversioncontrolplugin.h"
26
27 #include <KFileItem>
28
29 #include <QList>
30 #include <QObject>
31 #include <QString>
32 #include <QUrl>
33
34 class KFileItemList;
35 class KFileItemModel;
36 class KItemRangeList;
37 class QAction;
38 class QTimer;
39 class UpdateItemStatesThread;
40
41 class DolphinView;
42
43 /**
44 * @brief Observes all version control plugins.
45 *
46 * The items of the directory-model get updated automatically if the currently
47 * shown directory is under version control.
48 *
49 * @see VersionControlPlugin
50 */
51 class DOLPHIN_EXPORT VersionControlObserver : public QObject
52 {
53 Q_OBJECT
54
55 public:
56 explicit VersionControlObserver(QObject* parent = nullptr);
57 ~VersionControlObserver() override;
58
59 void setModel(KFileItemModel* model);
60 KFileItemModel* model() const;
61 void setView(DolphinView* view);
62 DolphinView* view() const;
63
64 QList<QAction*> actions(const KFileItemList& items) const;
65
66 signals:
67 /**
68 * Is emitted if an information message with the content \a msg
69 * should be shown.
70 */
71 void infoMessage(const QString& msg);
72
73 /**
74 * Is emitted if an error message with the content \a msg
75 * should be shown.
76 */
77 void errorMessage(const QString& msg);
78
79 /**
80 * Is emitted if an "operation completed" message with the content \a msg
81 * should be shown.
82 */
83 void operationCompletedMessage(const QString& msg);
84
85 private slots:
86 /**
87 * Invokes verifyDirectory() with a small delay. If delayedDirectoryVerification()
88 * is invoked before the delay has been exceeded, the delay will be reset. This
89 * assures that a lot of short requests for directory verification only result
90 * in one (expensive) call.
91 */
92 void delayedDirectoryVerification();
93
94 /**
95 * Invokes verifyDirectory() with a small delay. In opposite to
96 * delayedDirectoryVerification() it and assures that the verification of
97 * the directory is done silently without information messages.
98 */
99 void silentDirectoryVerification();
100
101 /**
102 * Invokes delayedDirectoryVerification() only if the itemsChanged() signal has not
103 * been triggered by the VCS plugin itself.
104 */
105 void slotItemsChanged(const KItemRangeList& itemRanges, const QSet<QByteArray>& roles);
106
107 void verifyDirectory();
108
109 /**
110 * Is invoked if the thread m_updateItemStatesThread has been finished
111 * and applys the item states.
112 */
113 void slotThreadFinished();
114
115 private:
116 typedef QPair<KFileItem, KVersionControlPlugin::ItemVersion> ItemState;
117 typedef QPair<KVersionControlPlugin*, QString> VCSPlugin;
118
119 void updateItemStates();
120
121 /**
122 * It creates a item state list for every expanded directory and stores
123 * this list together with the directory url in the \a itemStates map.
124 *
125 * @itemStates A map of item state lists for every expanded directory
126 * and its items, where the "key" is the directory url and
127 * the "value" is a list of ItemStates for every item
128 * within this directory.
129 * @firstIndex The index to start the processing from, this is needed
130 * because this function is recursively called.
131 *
132 * @return The number of (recursive) processed items.
133 */
134 int createItemStatesList(QMap<QString, QVector<ItemState> >& itemStates,
135 const int firstIndex = 0);
136
137 /**
138 * Returns a matching plugin for the given directory.
139 * 0 is returned, if no matching plugin has been found.
140 */
141 KVersionControlPlugin* searchPlugin(const QUrl& directory);
142
143 /**
144 * Returns true, if the directory contains a version control information.
145 */
146 bool isVersionControlled() const;
147
148 private:
149 bool m_pendingItemStatesUpdate;
150 bool m_versionedDirectory;
151 bool m_silentUpdate; // if true, no messages will be send during the update
152 // of version states
153
154 DolphinView* m_view;
155 KFileItemModel* m_model;
156
157 QTimer* m_dirVerificationTimer;
158
159 bool m_pluginsInitialized;
160 KVersionControlPlugin* m_plugin;
161 QList<VCSPlugin> m_plugins;
162 UpdateItemStatesThread* m_updateItemStatesThread;
163
164 friend class UpdateItemStatesThread;
165 };
166
167 #endif // REVISIONCONTROLOBSERVER_H
168