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 "dolphin_export.h"
25 #include "kversioncontrolplugin.h"
39 class UpdateItemStatesThread
;
44 * @brief Observes all version control plugins.
46 * The items of the directory-model get updated automatically if the currently
47 * shown directory is under version control.
49 * @see VersionControlPlugin
51 class DOLPHIN_EXPORT VersionControlObserver
: public QObject
56 explicit VersionControlObserver(QObject
* parent
= nullptr);
57 ~VersionControlObserver() override
;
59 void setModel(KFileItemModel
* model
);
60 KFileItemModel
* model() const;
61 void setView(DolphinView
* view
);
62 DolphinView
* view() const;
64 QList
<QAction
*> actions(const KFileItemList
& items
) const;
68 * Is emitted if an information message with the content \a msg
71 void infoMessage(const QString
& msg
);
74 * Is emitted if an error message with the content \a msg
77 void errorMessage(const QString
& msg
);
80 * Is emitted if an "operation completed" message with the content \a msg
83 void operationCompletedMessage(const QString
& msg
);
87 * Invokes verifyDirectory() with a small delay. If delayedDirectoryVerification()
88 * is invoked before the delay has been exceeded, the delay will be reset. This
89 * assures that a lot of short requests for directory verification only result
90 * in one (expensive) call.
92 void delayedDirectoryVerification();
95 * Invokes verifyDirectory() with a small delay. In opposite to
96 * delayedDirectoryVerification() it and assures that the verification of
97 * the directory is done silently without information messages.
99 void silentDirectoryVerification();
102 * Invokes delayedDirectoryVerification() only if the itemsChanged() signal has not
103 * been triggered by the VCS plugin itself.
105 void slotItemsChanged(const KItemRangeList
& itemRanges
, const QSet
<QByteArray
>& roles
);
107 void verifyDirectory();
110 * Is invoked if the thread m_updateItemStatesThread has been finished
111 * and applys the item states.
113 void slotThreadFinished();
116 typedef QPair
<KFileItem
, KVersionControlPlugin::ItemVersion
> ItemState
;
117 typedef QPair
<KVersionControlPlugin
*, QString
> VCSPlugin
;
119 void updateItemStates();
122 * It creates a item state list for every expanded directory and stores
123 * this list together with the directory url in the \a itemStates map.
125 * @itemStates A map of item state lists for every expanded directory
126 * and its items, where the "key" is the directory url and
127 * the "value" is a list of ItemStates for every item
128 * within this directory.
129 * @firstIndex The index to start the processing from, this is needed
130 * because this function is recursively called.
132 * @return The number of (recursive) processed items.
134 int createItemStatesList(QMap
<QString
, QVector
<ItemState
> >& itemStates
,
135 const int firstIndex
= 0);
138 * Returns a matching plugin for the given directory.
139 * 0 is returned, if no matching plugin has been found.
141 KVersionControlPlugin
* searchPlugin(const QUrl
& directory
);
144 * Returns true, if the directory contains a version control information.
146 bool isVersionControlled() const;
149 bool m_pendingItemStatesUpdate
;
150 bool m_versionedDirectory
;
151 bool m_silentUpdate
; // if true, no messages will be send during the update
155 KFileItemModel
* m_model
;
157 QTimer
* m_dirVerificationTimer
;
159 bool m_pluginsInitialized
;
160 KVersionControlPlugin
* m_plugin
;
161 QList
<VCSPlugin
> m_plugins
;
162 UpdateItemStatesThread
* m_updateItemStatesThread
;
164 friend class UpdateItemStatesThread
;
167 #endif // REVISIONCONTROLOBSERVER_H