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_db(QSqlDatabase::addDatabase("QSQLITE"))
33 m_db.setDatabaseName("/home/user/.rtcom-eventlogger/el-v1.db");
42 PhoneType elv1db::phonetype(QString metastr){
43 if (metastr.contains("ring/tel/ring"))
45 else if (metastr.contains("spirit/skype"))
47 else if (metastr.contains("gabble/jabber") && metastr.contains("40gmail_2ecom0"))
49 else if (metastr.contains("gabble/jabber"))
54 QString elv1db::calltype(){
55 return this->m_call_type==ALL_CALL?"and (event_type_id = 1 or event_type_id = 3)":
56 this->m_call_type==INCOMING?"and event_type_id = 1 and outgoing = 0":
57 this->m_call_type==OUTGOING?"and event_type_id = 1 and outgoing = 1":"and event_type_id = 3";
61 if (this->m_type_query == 0)
62 emit start_indicator();
64 emit detail_start_indicator();
68 if (this->m_type_query == 0){
69 QString m_group_by_call(H_TOTAL_GROUP_BY);
70 setQuery(m_group_by_call
71 .arg(this->m_all_call?"":"and E.local_uid='ring/tel/ring'")
75 QString m_filter(" and remote_name = '%1' %2 ");
76 m_filter = m_filter.arg(m_contact_name).arg(calltype());
77 QString m_default_search = QString(H_DEFAULT_SEARCH).arg(m_filter).arg(100);
78 setQuery(m_default_search);
81 QSqlQuery *query = new QSqlQuery(this->m_query);
82 QSqlRecord record = query->record();
83 if(record.count() > 0){
84 if (this->m_type_query == 0){
85 this->m_records.clear();
86 while (query->next()) {
87 elv1rec *ef=new elv1rec();
88 ef->set_contact_name(query->value(0).value<QString>());
89 ef->set_total_call(query->value(1).value<QString>());
90 this->m_records << ef;
94 this->m_detail_records.clear();
96 while (query->next()) {
97 elv1Detailrec *ef=new elv1Detailrec();
99 int calltype = query->value(0).value< int >();
101 if (calltype == 1 || calltype == 3){
102 ef->set_phonenumber(query->value(5).value<QString>());
103 ef->set_starttime(query->value(1).value<uint>());
104 ef->set_endtime(query->value(2).value<uint>());
105 if (query->value(2).value<uint>())
106 ef->set_callduration(query->value(2).value<uint>() - query->value(1).value<uint>());
108 ef->set_callduration(0);
109 if (calltype == 1) //call (outgoing/incoming)
110 ef->set_calltype(query->value(7).value<bool>()?OUTGOING:INCOMING);
111 else // call but missed
112 ef->set_calltype(MISSED);
115 this->phonetype(query->value(4).value<QString>())
118 this->m_detail_records << ef;
127 if (this->m_type_query == 0)
128 emit group_by_finished();
130 emit detail_finished();