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