2 Copyright (C) 2011 by Cuong Le <metacuong@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, see <http://www.gnu.org/licenses/>
20 #include <QtSql/QSqlQuery>
21 #include <QtSql/QSqlRecord>
28 elv1db::elv1db(QObject *parent):
31 m_search_val(new QString("")),
32 m_db(QSqlDatabase::addDatabase("QSQLITE"))
34 m_db.setDatabaseName("/home/user/.rtcom-eventlogger/el-v1.db");
41 delete this->m_search_val;
44 PhoneType elv1db::phonetype(QString metastr){
45 if (metastr.contains("ring/tel/ring"))
47 else if (metastr.contains("spirit/skype"))
49 else if (metastr.contains("gabble/jabber") && metastr.contains("40gmail_2ecom0"))
51 else if (metastr.contains("gabble/jabber"))
56 QString elv1db::calltype(){
57 return this->m_call_type==ALL_CALL?"and (event_type_id = 1 or event_type_id = 2)":
58 this->m_call_type==INCOMING?"and event_type_id = 1 and outgoing = 0":
59 this->m_call_type==OUTGOING?"and event_type_id = 1 and outgoing = 1":"and event_type_id = 2";
63 if (this->m_type_query == 0 || this->m_type_query == 2)
64 emit start_indicator();
66 emit detail_start_indicator();
70 if (this->m_type_query == 0){ //all
71 QString m_group_by_call(H_TOTAL_GROUP_BY);
72 setQuery(m_group_by_call
73 .arg(this->m_all_call?"":"and E.local_uid='ring/tel/ring'")
76 else if (this->m_type_query == 2 ){ //doSearch
77 QString m_group_by_and_search_call(H_TOTAL_GROUP_BY_AND_SEARCH);
78 QString m_search_val_convert("and remote_name like '%%1%'");
79 m_search_val_convert = m_search_val_convert.arg(*this->m_search_val);
81 setQuery(m_group_by_and_search_call
82 .arg(this->m_all_call?"":"and E.local_uid='ring/tel/ring'")
84 .arg(m_search_val_convert));
86 else { // for contact details
87 QString m_filter(" and remote_name = '%1' %2 ");
88 m_filter = m_filter.arg(m_contact_name).arg(calltype());
89 QString m_default_search = QString(H_DEFAULT_SEARCH).arg(m_filter).arg(100);
90 setQuery(m_default_search);
93 QSqlQuery *query = new QSqlQuery(this->m_query);
94 QSqlRecord record = query->record();
95 if(record.count() > 0){
96 if (this->m_type_query == 0 || this->m_type_query == 2){
97 this->m_records.clear();
98 while (query->next()) {
99 elv1rec *ef=new elv1rec();
100 ef->set_contact_name(query->value(0).value<QString>());
101 ef->set_total_call(query->value(1).value<QString>());
102 this->m_records << ef;
107 this->m_detail_records.clear();
109 while (query->next()) {
110 elv1Detailrec *ef=new elv1Detailrec();
112 int calltype = query->value(0).value< int >();
114 if (calltype == 1 || calltype == 2){
115 ef->set_phonenumber(query->value(5).value<QString>());
116 ef->set_starttime(query->value(1).value<uint>());
117 ef->set_endtime(query->value(2).value<uint>());
118 if (query->value(2).value<uint>())
119 ef->set_callduration(query->value(2).value<uint>() - query->value(1).value<uint>());
121 ef->set_callduration(0);
122 if (calltype == 1) //call (outgoing/incoming)
123 ef->set_calltype(query->value(7).value<bool>()?OUTGOING:INCOMING);
124 else // call but missed
125 ef->set_calltype(MISSED);
128 this->phonetype(query->value(4).value<QString>())
131 this->m_detail_records << ef;
140 if (this->m_type_query == 0 || this->m_type_query == 2)
141 emit group_by_finished();
143 emit detail_finished();