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