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