first commits to develop
[vncallhistory] / elv1db.h
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 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, see <http://www.gnu.org/licenses/>
16 */
17
18 #ifndef ELV1DB_H
19 #define ELV1DB_H
20
21 #include <QThread>
22 #include <QtSql/QSqlDatabase>
23 #include <QIcon>
24 #include <QDateTime>
25
26 #define H_TOTAL_GROUP_BY "select remote_name, count(*) from Events E, Remotes R where R.remote_uid=E.remote_uid and E.local_uid=R.local_uid %1 %2 group by remote_name order by start_time desc"
27 #define H_DEFAULT_SEARCH "select event_type_id, start_time, end_time, is_read, E.local_uid, E.remote_uid, free_text, outgoing, remote_name from Events E, Remotes R where R.remote_uid=E.remote_uid and E.local_uid=R.local_uid %1 order by start_time desc limit %2"
28
29 #define P_TYPE_GSM_NETWORK  "ring/tel/ring"
30 #define P_TYPE_SKYPE        "spirit/skype"
31 #define P_TYPE_JABBER       "gabble/jabber"
32
33 #define ICONS_ROOT_DIR "/usr/share/icons/hicolor/"
34
35 #define IMG_AVATAR      ICONS_ROOT_DIR "48x48/hildon/general_default_avatar.png"
36 #define IMG_OUTGOING    ICONS_ROOT_DIR "48x48/hildon/general_sent.png"
37 #define IMG_INCOMING    ICONS_ROOT_DIR "48x48/hildon/general_received.png"
38 #define IMG_MISSED      ICONS_ROOT_DIR "48x48/hildon/general_missed.png"
39
40 #define IMG_CELL        ICONS_ROOT_DIR "32x32/hildon/call_status_cellular.png"
41 #define IMG_SKYPE       ICONS_ROOT_DIR "32x32/hildon/general_skype.png"
42 #define IMG_GOOGLE      ICONS_ROOT_DIR "32x32/hildon/general_gtalk.png"
43 #define IMG_SIP         ICONS_ROOT_DIR "32x32/hildon/general_sip.png"
44 #define IMG_OVI         ICONS_ROOT_DIR "32x32/hildon/general_ovi.png"
45 #define IMG_JABBER      ICONS_ROOT_DIR "32x32/hildon/general_jabber.png"
46
47 /*
48   The record class for group by informations first screen
49   */
50 class elv1rec : public QObject
51 {
52     Q_OBJECT
53 public:
54
55     elv1rec():
56         m_avatar(QIcon::fromTheme( "general_default_avatar", QIcon(IMG_AVATAR)))
57     {
58     }
59
60     QString contact_name() const{
61         return m_contact_name;
62     }
63
64     QString total_call() const{
65         return m_total_call;
66     }
67
68     QIcon avatar() const{
69         return m_avatar;
70     }
71
72     void set_contact_name(QString contact_name){
73         m_contact_name = contact_name;
74     }
75
76     void set_total_call(QString total_call){
77         m_total_call = total_call;
78     }
79
80     void set_avatar(QIcon avatar){
81         m_avatar = avatar;
82     }
83
84 private:
85     QString m_contact_name;
86     QString m_total_call;
87     QIcon m_avatar;
88 };
89
90 /*
91   The record class for detail informations second screen
92   */
93 enum PhoneType { GSM_NETWORK = 0, SKYPE = 1, JABBER = 2, GOOGLE_TALK = 3, UNKNOW = 4};
94 enum CallType { OUTGOING = 0, INCOMING = 1, MISSED = 2, ALL_CALL = 3};
95
96 class elv1Detailrec : public QObject
97 {
98     Q_OBJECT
99
100 public:
101
102     elv1Detailrec()
103     {}
104
105     void set_phonenumber(QString phonenumber){ m_phonenumber = phonenumber;}
106     void set_starttime(uint starttime){ m_starttime.setTime_t(starttime);}
107     void set_endtime(uint endtime){ m_endtime.setTime_t(endtime);}
108     void set_calltype(CallType calltype){
109         m_calltype = calltype;
110         m_icon = QIcon::fromTheme(calltype==OUTGOING?
111                                       "general_sent":calltype==INCOMING?
112                                           "general_received":"general_missed", QIcon(calltype==OUTGOING?
113                                                                                          IMG_OUTGOING:calltype==INCOMING?
114                                                                                              IMG_INCOMING:IMG_MISSED));
115
116     }
117
118     void set_phonetype(PhoneType phonetype){
119         m_phonetype = phonetype;
120         QString _m_icon_meta;
121         QString _m_icon_path;
122         switch (phonetype){
123             case GSM_NETWORK:
124                 _m_icon_meta = "call_status_cellular";
125                 _m_icon_path = IMG_CELL;
126                 break;
127             case SKYPE:
128                 _m_icon_meta = "general_skype";
129                 _m_icon_path = IMG_SKYPE;
130                 break;
131             case JABBER:
132                 _m_icon_meta = "general_jabber";
133                 _m_icon_path = IMG_JABBER;
134                 break;
135             case GOOGLE_TALK:
136                 _m_icon_meta = "general_gtalk";
137                 _m_icon_path = IMG_GOOGLE;
138                 break;
139             default:
140                 _m_icon_meta = "call_status_unknow";
141                 _m_icon_path = "unknow";
142                 break;
143         }
144
145         m_type_call_icon = QIcon::fromTheme(_m_icon_meta, QIcon(_m_icon_path));
146     }
147
148     void set_callduration(uint callduration){ m_callduration = callduration;}
149
150     QString get_phonenumber() const { return m_phonenumber;}
151     QIcon get_icon() const { return m_icon;}
152     QIcon get_type_call_icon() const { return m_type_call_icon;}
153     QTime get_starttime() const { return m_starttime.time();}
154     QTime get_endtime() const { return m_endtime.time();}
155     QDate get_startdate() const { return m_starttime.date();}
156     QDate get_enddate() const { return m_endtime.date();}
157     CallType get_calltype() const { return m_calltype;}
158     uint get_duration() const { return m_callduration;}
159
160 private:
161     QIcon m_icon; //incoming/outgoing/missed call icons
162     QIcon m_type_call_icon; //cell/skype/sip/jingle/...
163     QString m_phonenumber;
164     QDateTime m_starttime;
165     QDateTime m_endtime;
166     CallType m_calltype;
167     PhoneType m_phonetype;
168     uint m_callduration;
169 };
170
171 /*
172   The main db management class
173   *MUST* be inherited QThread
174   */
175
176
177 class elv1db : public QThread
178 {
179     Q_OBJECT
180 public:
181     explicit elv1db(QObject *parent = 0);
182     ~elv1db();
183
184     void run();
185
186     void setQuery(QString o_query) {
187         m_query = o_query;
188     }
189
190     QString m_contact_name;
191
192     QList<elv1rec*> m_records;
193     QList<elv1Detailrec*> m_detail_records;
194
195     bool m_type_query;
196
197     bool m_all_call;
198     CallType m_call_type;
199
200 signals:
201     void start_indicator();
202     void group_by_finished();
203     void detail_finished();
204     void detail_start_indicator();
205
206 private:
207     QSqlDatabase m_db;
208     QString m_query;
209
210     PhoneType phonetype(QString metastr);
211     QString calltype();
212 };
213
214 #endif // ELV1DB_H