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