File indexing completed on 2024-05-12 05:47:52

0001 /*
0002  * SPDX-FileCopyrightText: 2009 Peter Penz <peter.penz19@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef UPDATEITEMSTATESTHREAD_H
0008 #define UPDATEITEMSTATESTHREAD_H
0009 
0010 #include "dolphin_export.h"
0011 #include "views/versioncontrol/versioncontrolobserver.h"
0012 
0013 #include <QMutex>
0014 #include <QThread>
0015 
0016 /**
0017  * The performance of updating the version state of items depends
0018  * on the used plugin. To prevent that Dolphin gets blocked by a
0019  * slow plugin, the updating is delegated to a thread.
0020  */
0021 class DOLPHIN_EXPORT UpdateItemStatesThread : public QThread
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     /**
0027      * @param plugin     Version control plugin that is used to update the
0028      *                   state of the items. Whenever the plugin is accessed
0029      *                   from the thread creator after starting the thread,
0030      *                   UpdateItemStatesThread::lockPlugin() and
0031      *                   UpdateItemStatesThread::unlockPlugin() must be used.
0032      * @param itemStates List of items, where the states get updated.
0033      */
0034     UpdateItemStatesThread(KVersionControlPlugin *plugin, const QMap<QString, QVector<VersionControlObserver::ItemState>> &itemStates);
0035     ~UpdateItemStatesThread() override;
0036 
0037     QMap<QString, QVector<VersionControlObserver::ItemState>> itemStates() const;
0038 
0039 protected:
0040     void run() override;
0041 
0042 private:
0043     QMutex *m_globalPluginMutex; // Protects the m_plugin globally
0044     KVersionControlPlugin *m_plugin;
0045 
0046     QMap<QString, QVector<VersionControlObserver::ItemState>> m_itemStates;
0047 };
0048 
0049 #endif // UPDATEITEMSTATESTHREAD_H