]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/versioncontrol/pendingthreadsmaintainer.h
Respect Shift- and Control-key for the rubberband selection
[dolphin.git] / src / views / versioncontrol / pendingthreadsmaintainer.h
1 /***************************************************************************
2 * Copyright (C) 2010 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 PENDINGTHREADSMAINTAINER_H
21 #define PENDINGTHREADSMAINTAINER_H
22
23 #include <libdolphin_export.h>
24
25 #include <QObject>
26
27 class QTimer;
28
29 /**
30 * TODO: Replace the PendingThreadMaintainer by a kind of
31 * VersionControlThreadFactory that is responsible for creating
32 * and deleting the threads. This would bypass the hack to poll
33 * for pending threads.
34 *
35 * If the creator of a thread gets deleted, although the thread is still
36 * working, usually QThread::wait() is invoked. The drawback of this
37 * approach is that the user interface gets blocked for an undefined amount
38 * of time. If the thread does not contain references to the creator, the
39 * deleting can be forwarded to the PendingThreadsMaintainer. In the following
40 * example it is assumed, that m_thread will be 0, if it has been deleted by the
41 * creator after receiving the signal QThread::finished():
42 *
43 * \code
44 * ThreadCreator::~ThreadCreator()
45 * {
46 * if (m_thread) {
47 * PendingThreadsMaintainer::instance().append(m_thread);
48 * m_thread = 0;
49 * }
50 * }
51 * \endcode
52 *
53 * The thread will get automatically deleted after it (or has already) been finished.
54 *
55 * Implementation note: Connecting to the signal QThread::finished() is
56 * not sufficient, as it is possible that the thread has already emitted
57 * the signal, but the signal has not been received yet by the thread creator.
58 * Because of this a polling is done each 5 seconds to check, whether the
59 * thread has been finished.
60 */
61 class LIBDOLPHINPRIVATE_EXPORT PendingThreadsMaintainer : public QObject
62 {
63 Q_OBJECT
64
65 public:
66 static PendingThreadsMaintainer& instance();
67 virtual ~PendingThreadsMaintainer();
68
69 /**
70 * Appends the thread \p thread to the maintainer. The thread
71 * will be deleted by the maintainer after it has been finished.
72 */
73 void append(QThread* thread);
74
75 protected:
76 PendingThreadsMaintainer();
77
78 private slots:
79 void cleanup();
80
81 private:
82 QList<QThread*> m_threads;
83 QTimer* m_timer;
84
85 friend class PendingThreadsMaintainerSingleton;
86 };
87
88 #endif