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/>
18 #include "mainwindow.h"
21 #include <QtCore/QCoreApplication>
25 #include "listitemdetaildelegate.h"
27 MainWindow::MainWindow(QWidget *parent):
29 m_elv1db(new elv1db(parent))
32 detail_dlg = new QMainWindow(this);
33 detail_dlg->installEventFilter(this);
35 m_contact_detail = new QListWidget(detail_dlg);
36 m_contact_detail->setSelectionMode(QAbstractItemView::NoSelection);
37 m_contact_detail->setObjectName("m_contact_detail");
38 detail_dlg->setCentralWidget(m_contact_detail);
40 detail_dlg->setAttribute(Qt::WA_Maemo5StackedWindow);
44 this->setWindowTitle(QString::fromUtf8("VN Call History"));
46 m_contacts_widget = new QTableWidget(0, 3, this);
47 m_contacts_widget->setProperty( "FingerScrollable", true );
48 m_contacts_widget->setSelectionBehavior(QAbstractItemView::SelectRows);
49 m_contacts_widget->setSelectionMode(QAbstractItemView::SingleSelection);
50 m_contacts_widget->setIconSize( QSize( 48, 48 ) );
52 m_contacts_widget->horizontalHeader()->setDefaultSectionSize( 30 );
53 m_contacts_widget->horizontalHeader()->setResizeMode( 0, QHeaderView::Fixed );
54 m_contacts_widget->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );
55 m_contacts_widget->horizontalHeader()->setResizeMode( 2, QHeaderView::Fixed );
57 m_contacts_widget->verticalHeader()->hide();
58 m_contacts_widget->horizontalHeader()->hide();
60 connect(m_contacts_widget, SIGNAL(cellClicked(int,int)), this, SLOT(cellClicked(int,int)));
62 m_elv1db->m_type_query = 0;
64 connect(m_elv1db, SIGNAL(group_by_finished()), this, SLOT(elv1db_finised()));
65 connect(m_elv1db, SIGNAL(detail_finished()), this, SLOT(elv1db_detail_finised()));
66 connect(m_elv1db, SIGNAL(start_indicator()), this, SLOT(start_indicator()));
67 connect(m_elv1db, SIGNAL(detail_start_indicator()), this, SLOT(detail_start_indicator()));
70 this->setup_menu_detail();
72 this->setCentralWidget(m_contacts_widget);
74 m_elv1db->m_call_type = ALL_CALL;
75 m_elv1db->m_all_call = false;
79 this->setAttribute(Qt::WA_Maemo5StackedWindow);
84 MainWindow::~MainWindow()
86 delete this->m_contacts_widget;
87 delete this->m_contact_detail;
88 delete this->m_elv1db;
91 void MainWindow::cellClicked(int row, int col){
92 qDebug() << "cellClicked : " << row << ":" << col;
94 m_contact_detail->clear();
96 const elv1rec *ef= m_elv1db->m_records.at(row);
98 m_elv1db->m_contact_name = ef->contact_name();
100 detail_dlg->setWindowTitle(ef->contact_name());
103 m_elv1db->m_type_query = 1;
107 void MainWindow::elv1db_detail_finised(){
110 m_contact_detail->setItemDelegate(new listitemdetailDelegate(m_contact_detail));
112 foreach(elv1Detailrec *ef, m_elv1db->m_detail_records){
113 QString detail_format("%1 | %2 | Duration: %3");
114 QTime final_duration;
116 uint secs = ef->get_duration() % 60;
117 uint mins = ef->get_duration() / 60;
118 uint hours = ef->get_duration() / 3600;
120 final_duration.setHMS(hours,mins,secs);
122 if ((t_cache.day()!=ef->get_startdate().day()) ||
123 (t_cache.month()!=ef->get_startdate().month()) ||
124 (t_cache.year()!=ef->get_startdate().year()) ){
126 QListWidgetItem *header = new QListWidgetItem();
127 header->setData(Qt::DisplayRole, ef->get_startdate().toString());
128 m_contact_detail->addItem(header);
130 t_cache=ef->get_startdate();
133 QListWidgetItem *item = new QListWidgetItem();
134 item->setData(Qt::UserRole + 1, ef->get_phonenumber());
135 item->setData(Qt::UserRole + 2, detail_format.arg(ef->get_starttime().toString())
136 .arg(ef->get_endtime().toString())
137 .arg(final_duration.toString()));
138 item->setData(Qt::UserRole + 4, ef->get_icon());
139 item->setData(Qt::UserRole + 5, ef->get_type_call_icon());
140 m_contact_detail->addItem(item);
143 this->me_indicator(this->detail_dlg, false);
144 m_elv1db->m_type_query = 0;
147 void MainWindow::elv1db_finised(){
148 qDebug() << " Process the elv1 database is done";
150 m_contacts_widget->clear();
151 m_contacts_widget->setRowCount(0);
155 foreach(elv1rec *ef,m_elv1db->m_records){
156 QTableWidgetItem *m_thumbnail = new QTableWidgetItem;
157 m_thumbnail->setIcon(ef->avatar());
159 m_contacts_widget->insertRow(i);
160 m_contacts_widget->setItem(i,0, m_thumbnail);
162 QString _m_total_call(" (%1) ");
163 _m_total_call = _m_total_call.arg(ef->total_call());
165 QString _m_contact_name(" %1");
166 _m_contact_name = _m_contact_name.arg(ef->contact_name());
168 QLabel *m_total_call = new QLabel(_m_total_call);
169 m_total_call->setAlignment(Qt::AlignCenter);
171 m_contacts_widget->setCellWidget(i,1, new QLabel(_m_contact_name));
172 m_contacts_widget->setCellWidget(i,2, m_total_call);
176 m_contacts_widget->resizeRowsToContents();
177 m_contacts_widget->resizeColumnsToContents();
179 this->stop_indicator();
181 m_contacts_widget->setEnabled(true);
184 void MainWindow::start_indicator(){
185 this->me_indicator(this, true);
188 void MainWindow::stop_indicator(){
189 this->me_indicator(this, false);
192 void MainWindow::detail_start_indicator(){
193 this->me_indicator(this->detail_dlg, true);
196 void MainWindow::me_indicator(QMainWindow *qmw, bool m_show){
197 qmw->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, m_show);
200 void MainWindow::setup_menu(){
201 QActionGroup* m_type_group = new QActionGroup(this);
202 m_type_group->setExclusive(true);
203 m_type_group->setObjectName("m_type_group");
205 QAction* m_all_calls = new QAction(QString::fromUtf8("All call"), m_type_group );
206 m_all_calls->setCheckable(true);
207 m_all_calls->setObjectName( "m_all_calls" );
208 connect(m_all_calls, SIGNAL(triggered()), this, SLOT(select_all_call()));
210 QAction* m_gsm_calls = new QAction(QString::fromUtf8("GSM cellular"), m_type_group );
211 m_gsm_calls->setCheckable(true);
212 m_gsm_calls->setObjectName("m_gsm_calls");
213 connect(m_gsm_calls, SIGNAL(triggered()), this, SLOT(select_gsm_calls()));
215 m_gsm_calls->setChecked(true);
218 QActionGroup* m_type_group_af = new QActionGroup(this);
219 m_type_group_af->setExclusive(true);
220 m_type_group_af->setObjectName("m_type_group_detail");
222 QAction* m_all = new QAction(QString::fromUtf8("All"), m_type_group_af );
223 m_all->setCheckable(true);
224 m_all->setObjectName( "m_all" );
225 connect(m_all, SIGNAL(triggered()), this, SLOT(select_all_typecall()));
227 QAction* m_incoming = new QAction(QString::fromUtf8("Incoming"), m_type_group_af );
228 m_incoming->setCheckable(true);
229 m_incoming->setObjectName( "m_incoming" );
230 connect(m_incoming, SIGNAL(triggered()), this, SLOT(select_incoming_calls()));
232 QAction* m_outgoing = new QAction(QString::fromUtf8("Outgoing"), m_type_group_af );
233 m_outgoing->setCheckable(true);
234 m_outgoing->setObjectName( "m_outgoing" );
235 connect(m_outgoing, SIGNAL(triggered()), this, SLOT(select_outgoing_calls()));
237 QAction* m_missed = new QAction(QString::fromUtf8("Missed"), m_type_group_af );
238 m_missed->setCheckable(true);
239 m_missed->setObjectName( "m_missed" );
240 connect(m_missed, SIGNAL(triggered()), this, SLOT(select_missed_calls()));
242 m_all->setChecked(true);
244 this->menuBar()->addActions(m_type_group->actions());
245 this->menuBar()->addActions(m_type_group_af->actions());
247 /* QAction *m_clear_log = this->menuBar()->addAction("Clear Log");
248 QAction *m_options = this->menuBar()->addAction(QString::fromUtf8("Options"));
250 connect(m_clear_log,SIGNAL(triggered()), this, SLOT(clearLog()));
251 connect(m_options, SIGNAL(triggered()), this, SLOT(dlgOptions()));*/
253 QAction *m_about = this->menuBar()->addAction("About");
254 QAction *m_about_qt = this->menuBar()->addAction("About Qt");
256 connect(m_about,SIGNAL(triggered()), this, SLOT(dlgAbout()));
257 connect(m_about_qt,SIGNAL(triggered()), qApp, SLOT(aboutQt()));
261 void MainWindow::select_all_call(){ //ring/tel/ring, spirit/skype, gabble/jabber
262 m_contacts_widget->setEnabled(false);
263 m_elv1db->m_all_call = true;
267 void MainWindow::select_gsm_calls(){ //ring/tel/ring
268 m_contacts_widget->setEnabled(false);
269 m_elv1db->m_all_call = false;
273 void MainWindow::select_all_typecall(){ //incoming, outgoing and missed calls
274 m_contacts_widget->setEnabled(false);
275 m_elv1db->m_call_type = ALL_CALL;
279 void MainWindow::select_incoming_calls(){
280 m_contacts_widget->setEnabled(false);
281 m_elv1db->m_call_type = INCOMING;
285 void MainWindow::select_outgoing_calls(){
286 m_contacts_widget->setEnabled(false);
287 m_elv1db->m_call_type = OUTGOING;
291 void MainWindow::select_missed_calls(){
292 m_contacts_widget->setEnabled(false);
293 m_elv1db->m_call_type = MISSED;
297 void MainWindow::clearLog(){
300 void MainWindow::setup_menu_detail(){
303 void MainWindow::dlgAbout(){
305 m_about.setWindowTitle("About");
307 "<font size=4>VN Call History</font><br>"
308 "<font size=3>Version : 0.0.1 (09/28/2011)</font><br>"
309 "Author : Cuong Le <a href=\"mailto:metacuong@gmail.com\">metacuong@gmail.com</a><br>"
311 "Homepage : <a href=\"http://vncallhistory.garage.maemo.org/\">http://vncallhistory.garage.maemo.org/</a><br>"
312 "Bugs report : <a href=\"https://garage.maemo.org/tracker/?group_id=2259\">https://garage.maemo.org/tracker/?group_id=2259</a><br>"
313 "License : GNU/GPL version 2"
319 void MainWindow::dlgOptions(){
320 dlg_options = new QMainWindow(this);
321 dlg_options->setWindowTitle(QString::fromUtf8("Options"));
322 dlg_options->installEventFilter(this);
324 dlg_options->setAttribute(Qt::WA_Maemo5StackedWindow);
329 void MainWindow::setOrientation(ScreenOrientation orientation)
331 #if defined(Q_OS_SYMBIAN)
332 // If the version of Qt on the device is < 4.7.2, that attribute won't work
333 if (orientation != ScreenOrientationAuto) {
334 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
335 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
336 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
340 #endif // Q_OS_SYMBIAN
342 Qt::WidgetAttribute attribute;
343 switch (orientation) {
344 #if QT_VERSION < 0x040702
345 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
346 case ScreenOrientationLockPortrait:
347 attribute = static_cast<Qt::WidgetAttribute>(128);
349 case ScreenOrientationLockLandscape:
350 attribute = static_cast<Qt::WidgetAttribute>(129);
353 case ScreenOrientationAuto:
354 attribute = static_cast<Qt::WidgetAttribute>(130);
356 #else // QT_VERSION < 0x040702
357 case ScreenOrientationLockPortrait:
358 attribute = Qt::WA_LockPortraitOrientation;
360 case ScreenOrientationLockLandscape:
361 attribute = Qt::WA_LockLandscapeOrientation;
364 case ScreenOrientationAuto:
365 attribute = Qt::WA_AutoOrientation;
367 #endif // QT_VERSION < 0x040702
369 setAttribute(attribute, true);
372 void MainWindow::showExpanded()
376 #elif defined(Q_WS_MAEMO_5)