CuteLogger
Fast and simple logging solution for Qt based applications
database.h
1 /*
2  * Copyright (c) 2013-2015 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef DATABASE_H
20 #define DATABASE_H
21 
22 #include <QThread>
23 #include <QImage>
24 #include <QMutex>
25 #include <QWaitCondition>
26 
27 struct DatabaseJob;
28 class QTimer;
29 class Database : public QThread
30 {
31  Q_OBJECT
32  explicit Database(QObject *parent = 0);
33 
34 public:
35  static Database& singleton(QWidget* parent = 0);
36 
37  bool upgradeVersion1();
38  bool putThumbnail(const QString& hash, const QImage& image);
39  QImage getThumbnail(const QString& hash);
40 
41 private slots:
42  void commitTransaction();
43 
44 private slots:
45  void shutdown();
46 
47 private:
48  void doJob(DatabaseJob * job);
49  void submitAndWaitForJob(DatabaseJob * job);
50  void deleteOldThumbnails();
51  void run();
52 
53  QList<DatabaseJob*> m_jobs;
54  QMutex m_mutex;
55  QWaitCondition m_waitForFinished;
56  QWaitCondition m_waitForNewJob;
57  QTimer * m_commitTimer;
58 };
59 
60 #define DB Database::singleton()
61 
62 #endif // DATABASE_H