Merge branch 'develop'
[vietkaralist] / dbthread.cpp
1 /*
2 Copyright (C) 2011  by Cuong Le <metacuong@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 3 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, see <http://www.gnu.org/licenses/>
16 */
17
18 #include <QtSql/QSqlDatabase>
19 #include <QtSql/QSqlQuery>
20 #include <QtSql/QSqlRecord>
21 #include <QDebug>
22 #include <QVariant>
23 #include <QString>
24
25 #include "dbthread.h"
26
27 DBThread::DBThread()
28 {
29     db = QSqlDatabase::addDatabase("QSQLITE");
30 #if defined(Q_WS_MAEMO_5)
31     db.setDatabaseName("/opt/vietkaralist/db/vietkaralist.sqlite");
32 #else
33     db.setDatabaseName("/home/cuonglb/vietkaralist.sqlite");
34 #endif
35     db.open();
36 }
37
38 DBThread::~DBThread(){
39     db.close();
40 }
41
42 void DBThread::run(){
43
44     QSqlQuery query(this->mm_query);
45     QSqlRecord record = query.record();
46
47     if (record.count() > 0) {
48         emit removeOldSongs();
49         while (query.next()) {
50             emit addSong(query.value(0).toString(),query.value(1).toString(), query.value(4).toString(), query.value(5).toString());
51         }
52     }
53
54     emit stopSearch();
55
56 }
57
58 void DBThread::slotExecQuery(const QString& m_query){
59     this->mm_query = m_query;
60     this->start();
61 }