]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/versioncontrol/versioncontrolobserver.h
2c2fe2940c3ebf793f33be689ef18ad08dde9f6d
[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 <QUrl>
30 #include <QList>
31 #include <QObject>
32 #include <QString>
33
34 class KFileItemList;
35 class KFileItemModel;
36 class QAction;
37 class QTimer;
38 class UpdateItemStatesThread;
39
40 /**
41 * @brief Observes all version control plugins.
42 *
43 * The items of the directory-model get updated automatically if the currently
44 * shown directory is under version control.
45 *
46 * @see VersionControlPlugin
47 */
48 class DOLPHIN_EXPORT VersionControlObserver : public QObject
49 {
50 Q_OBJECT
51
52 public:
53 explicit VersionControlObserver(QObject* parent = nullptr);
54 ~VersionControlObserver() override;
55
56 void setModel(KFileItemModel* model);
57 KFileItemModel* model() const;
58
59 QList<QAction*> actions(const KFileItemList& items) const;
60
61 signals:
62 /**
63 * Is emitted if an information message with the content \a msg
64 * should be shown.
65 */
66 void infoMessage(const QString& msg);
67
68 /**
69 * Is emitted if an error message with the content \a msg
70 * should be shown.
71 */
72 void errorMessage(const QString& msg);
73
74 /**
75 * Is emitted if an "operation completed" message with the content \a msg
76 * should be shown.
77 */
78 void operationCompletedMessage(const QString& msg);
79
80 private slots:
81 /**
82 * Invokes verifyDirectory() with a small delay. If delayedDirectoryVerification()
83 * is invoked before the delay has been exceeded, the delay will be reset. This
84 * assures that a lot of short requests for directory verification only result
85 * in one (expensive) call.
86 */
87 void delayedDirectoryVerification();
88
89 /**
90 * Invokes verifyDirectory() with a small delay. In opposite to
91 * delayedDirectoryVerification() it and assures that the verification of
92 * the directory is done silently without information messages.
93 */
94 void silentDirectoryVerification();
95
96 void verifyDirectory();
97
98 /**
99 * Is invoked if the thread m_updateItemStatesThread has been finished
100 * and applys the item states.
101 */
102 void slotThreadFinished();
103
104 private:
105 typedef QPair<KFileItem, KVersionControlPlugin::ItemVersion> ItemState;
106
107 void updateItemStates();
108
109 /**
110 * It creates a item state list for every expanded directory and stores
111 * this list together with the directory url in the \a itemStates map.
112 *
113 * @itemStates A map of item state lists for every expanded directory
114 * and its items, where the "key" is the directory url and
115 * the "value" is a list of ItemStates for every item
116 * within this directory.
117 * @firstIndex The index to start the processing from, this is needed
118 * because this function is recursively called.
119 *
120 * @return The number of (recursive) processed items.
121 */
122 int createItemStatesList(QMap<QString, QVector<ItemState> >& itemStates,
123 const int firstIndex = 0);
124
125 /**
126 * Returns a matching plugin for the given directory.
127 * 0 is returned, if no matching plugin has been found.
128 */
129 KVersionControlPlugin* searchPlugin(const QUrl& directory) const;
130
131 /**
132 * Returns true, if the directory contains a version control information.
133 */
134 bool isVersioned() const;
135
136 private:
137 bool m_pendingItemStatesUpdate;
138 bool m_versionedDirectory;
139 bool m_silentUpdate; // if true, no messages will be send during the update
140 // of version states
141
142 KFileItemModel* m_model;
143
144 QTimer* m_dirVerificationTimer;
145
146 KVersionControlPlugin* m_plugin;
147 UpdateItemStatesThread* m_updateItemStatesThread;
148
149 friend class UpdateItemStatesThread;
150 };
151
152 #endif // REVISIONCONTROLOBSERVER_H
153