1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef VERSIONCONTROLOBSERVER_H
21 #define VERSIONCONTROLOBSERVER_H
23 #include <libdolphin_export.h>
27 #include <kversioncontrolplugin2.h>
36 class UpdateItemStatesThread
;
39 * @brief Observes all version control plugins.
41 * The items of the directory-model get updated automatically if the currently
42 * shown directory is under version control.
44 * @see VersionControlPlugin
46 class LIBDOLPHINPRIVATE_EXPORT VersionControlObserver
: public QObject
51 explicit VersionControlObserver(QObject
* parent
= 0);
52 virtual ~VersionControlObserver();
54 void setModel(KFileItemModel
* model
);
55 KFileItemModel
* model() const;
57 QList
<QAction
*> actions(const KFileItemList
& items
) const;
61 * Is emitted if an information message with the content \a msg
64 void infoMessage(const QString
& msg
);
67 * Is emitted if an error message with the content \a msg
70 void errorMessage(const QString
& msg
);
73 * Is emitted if an "operation completed" message with the content \a msg
76 void operationCompletedMessage(const QString
& msg
);
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.
85 void delayedDirectoryVerification();
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.
92 void silentDirectoryVerification();
94 void verifyDirectory();
97 * Is invoked if the thread m_updateItemStatesThread has been finished
98 * and applys the item states.
100 void slotThreadFinished();
103 typedef QPair
<KFileItem
, KVersionControlPlugin2::ItemVersion
> ItemState
;
105 void updateItemStates();
108 * It creates a item state list for every expanded directory and stores
109 * this list together with the directory url in the \a itemStates map.
111 * @itemStates A map of item state lists for every expanded directory
112 * and its items, where the "key" is the directory url and
113 * the "value" is a list of ItemStates for every item
114 * within this directory.
115 * @firstIndex The index to start the processing from, this is needed
116 * because this function is recursively called.
118 * @return The number of (recursive) processed items.
120 int createItemStatesList(QMap
<QString
, QVector
<ItemState
> >& itemStates
,
121 const int firstIndex
= 0);
124 * Returns a matching plugin for the given directory.
125 * 0 is returned, if no matching plugin has been found.
127 KVersionControlPlugin
* searchPlugin(const QUrl
& directory
) const;
130 * Returns true, if the directory contains a version control information.
132 bool isVersioned() const;
135 bool m_pendingItemStatesUpdate
;
136 bool m_versionedDirectory
;
137 bool m_silentUpdate
; // if true, no messages will be send during the update
140 KFileItemModel
* m_model
;
142 QTimer
* m_dirVerificationTimer
;
144 KVersionControlPlugin
* m_plugin
;
145 UpdateItemStatesThread
* m_updateItemStatesThread
;
147 friend class UpdateItemStatesThread
;
150 #endif // REVISIONCONTROLOBSERVER_H