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>
24 #include <QInputDialog>
26 #include "listitemdetaildelegate.h"
28 MainWindow::MainWindow(QWidget *parent):
30 m_elv1db(new elv1db(parent))
33 detail_dlg = new QMainWindow(this);
34 detail_dlg->installEventFilter(this);
36 m_contact_detail = new QListWidget(detail_dlg);
37 m_contact_detail->setSelectionMode(QAbstractItemView::NoSelection);
38 m_contact_detail->setObjectName("m_contact_detail");
39 detail_dlg->setCentralWidget(m_contact_detail);
41 detail_dlg->setAttribute(Qt::WA_Maemo5StackedWindow);
45 this->setWindowTitle(QString::fromUtf8("VN Call History"));
47 m_contacts_widget = new QTableWidget(0, 3, this);
48 m_contacts_widget->setProperty( "FingerScrollable", true );
49 m_contacts_widget->setSelectionBehavior(QAbstractItemView::SelectRows);
50 m_contacts_widget->setSelectionMode(QAbstractItemView::SingleSelection);
51 m_contacts_widget->setIconSize( QSize( 48, 48 ) );
53 m_contacts_widget->horizontalHeader()->setDefaultSectionSize( 30 );
54 m_contacts_widget->horizontalHeader()->setResizeMode( 0, QHeaderView::Fixed );
55 m_contacts_widget->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );
56 m_contacts_widget->horizontalHeader()->setResizeMode( 2, QHeaderView::Fixed );
58 m_contacts_widget->verticalHeader()->hide();
59 m_contacts_widget->horizontalHeader()->hide();
61 connect(m_contacts_widget, SIGNAL(cellClicked(int,int)), this, SLOT(cellClicked(int,int)));
63 m_elv1db->m_type_query = 0;
66 m_type_query_temp = 0;
68 connect(m_elv1db, SIGNAL(group_by_finished()), this, SLOT(elv1db_finised()));
69 connect(m_elv1db, SIGNAL(detail_finished()), this, SLOT(elv1db_detail_finised()));
70 connect(m_elv1db, SIGNAL(start_indicator()), this, SLOT(start_indicator()));
71 connect(m_elv1db, SIGNAL(detail_start_indicator()), this, SLOT(detail_start_indicator()));
74 this->setup_menu_detail();
76 this->setCentralWidget(m_contacts_widget);
78 m_elv1db->m_call_type = ALL_CALL;
79 m_elv1db->m_all_call = false;
83 this->setAttribute(Qt::WA_Maemo5StackedWindow);
88 MainWindow::~MainWindow()
90 delete this->m_contacts_widget;
91 delete this->m_contact_detail;
92 delete this->m_elv1db;
93 delete this->m_no_search;
96 void MainWindow::cellClicked(int row, int col){
97 qDebug() << "cellClicked : " << row << ":" << col;
99 m_contact_detail->clear();
101 const elv1rec *ef= m_elv1db->m_records.at(row);
103 m_elv1db->m_contact_name = ef->contact_name();
105 detail_dlg->setWindowTitle(ef->contact_name());
108 m_elv1db->m_type_query = 1;
112 void MainWindow::elv1db_detail_finised(){
115 m_contact_detail->setItemDelegate(new listitemdetailDelegate(m_contact_detail));
117 foreach(elv1Detailrec *ef, m_elv1db->m_detail_records){
118 QString detail_format("%1 | %2 | Duration: %3");
119 QTime final_duration;
121 uint secs = ef->get_duration() % 60;
122 uint mins = ef->get_duration() / 60;
123 uint hours = ef->get_duration() / 3600;
125 final_duration.setHMS(hours,mins,secs);
127 if ((t_cache.day()!=ef->get_startdate().day()) ||
128 (t_cache.month()!=ef->get_startdate().month()) ||
129 (t_cache.year()!=ef->get_startdate().year()) ){
131 QListWidgetItem *header = new QListWidgetItem();
132 header->setData(Qt::DisplayRole, ef->get_startdate().toString().toUtf8());
133 m_contact_detail->addItem(header);
135 t_cache=ef->get_startdate();
138 QListWidgetItem *item = new QListWidgetItem();
139 item->setData(Qt::UserRole + 1, ef->get_phonenumber());
140 item->setData(Qt::UserRole + 2, detail_format.arg(ef->get_starttime().toString())
141 .arg(ef->get_endtime().toString())
142 .arg(final_duration.toString()));
143 item->setData(Qt::UserRole + 4, ef->get_icon());
144 item->setData(Qt::UserRole + 5, ef->get_type_call_icon());
145 m_contact_detail->addItem(item);
148 this->me_indicator(this->detail_dlg, false);
149 m_elv1db->m_type_query = 0;
152 void MainWindow::elv1db_finised(){
153 qDebug() << " Process the elv1 database is done";
155 m_contacts_widget->clear();
156 m_contacts_widget->setRowCount(0);
160 foreach(elv1rec *ef,m_elv1db->m_records){
161 QTableWidgetItem *m_thumbnail = new QTableWidgetItem;
162 m_thumbnail->setIcon(ef->avatar());
164 m_contacts_widget->insertRow(i);
165 m_contacts_widget->setItem(i,0, m_thumbnail);
167 QString _m_total_call(" (%1) ");
168 _m_total_call = _m_total_call.arg(ef->total_call());
170 QString _m_contact_name(" %1");
171 _m_contact_name = _m_contact_name.arg(ef->contact_name());
173 QLabel *m_total_call = new QLabel(_m_total_call);
174 m_total_call->setAlignment(Qt::AlignCenter);
176 m_contacts_widget->setCellWidget(i,1, new QLabel(_m_contact_name));
177 m_contacts_widget->setCellWidget(i,2, m_total_call);
181 m_contacts_widget->resizeRowsToContents();
182 m_contacts_widget->resizeColumnsToContents();
184 this->stop_indicator();
186 m_contacts_widget->setEnabled(true);
189 void MainWindow::start_indicator(){
190 this->me_indicator(this, true);
193 void MainWindow::stop_indicator(){
194 this->me_indicator(this, false);
197 void MainWindow::detail_start_indicator(){
198 this->me_indicator(this->detail_dlg, true);
201 void MainWindow::me_indicator(QMainWindow *qmw, bool m_show){
202 qmw->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, m_show);
205 void MainWindow::setup_menu(){
206 QActionGroup* m_type_group = new QActionGroup(this);
207 m_type_group->setExclusive(true);
208 m_type_group->setObjectName("m_type_group");
210 QAction* m_all_calls = new QAction(QString::fromUtf8("All call"), m_type_group );
211 m_all_calls->setCheckable(true);
212 m_all_calls->setObjectName( "m_all_calls" );
213 connect(m_all_calls, SIGNAL(triggered()), this, SLOT(select_all_call()));
215 QAction* m_gsm_calls = new QAction(QString::fromUtf8("GSM cellular"), m_type_group );
216 m_gsm_calls->setCheckable(true);
217 m_gsm_calls->setObjectName("m_gsm_calls");
218 connect(m_gsm_calls, SIGNAL(triggered()), this, SLOT(select_gsm_calls()));
220 m_gsm_calls->setChecked(true);
223 QActionGroup* m_type_group_af = new QActionGroup(this);
224 m_type_group_af->setExclusive(true);
225 m_type_group_af->setObjectName("m_type_group_detail");
227 QAction* m_all = new QAction(QString::fromUtf8("All"), m_type_group_af );
228 m_all->setCheckable(true);
229 m_all->setObjectName( "m_all" );
230 connect(m_all, SIGNAL(triggered()), this, SLOT(select_all_typecall()));
232 QAction* m_incoming = new QAction(QString::fromUtf8("Incoming"), m_type_group_af );
233 m_incoming->setCheckable(true);
234 m_incoming->setObjectName( "m_incoming" );
235 connect(m_incoming, SIGNAL(triggered()), this, SLOT(select_incoming_calls()));
237 QAction* m_outgoing = new QAction(QString::fromUtf8("Outgoing"), m_type_group_af );
238 m_outgoing->setCheckable(true);
239 m_outgoing->setObjectName( "m_outgoing" );
240 connect(m_outgoing, SIGNAL(triggered()), this, SLOT(select_outgoing_calls()));
242 QAction* m_missed = new QAction(QString::fromUtf8("Missed"), m_type_group_af );
243 m_missed->setCheckable(true);
244 m_missed->setObjectName( "m_missed" );
245 connect(m_missed, SIGNAL(triggered()), this, SLOT(select_missed_calls()));
247 m_all->setChecked(true);
249 this->menuBar()->addActions(m_type_group->actions());
250 this->menuBar()->addActions(m_type_group_af->actions());
252 /* QAction *m_clear_log = this->menuBar()->addAction("Clear Log");
253 QAction *m_options = this->menuBar()->addAction(QString::fromUtf8("Options"));
255 connect(m_clear_log,SIGNAL(triggered()), this, SLOT(clearLog()));
256 connect(m_options, SIGNAL(triggered()), this, SLOT(dlgOptions()));*/
258 QAction *m_search = this->menuBar()->addAction("Search");
259 connect(m_search,SIGNAL(triggered()), this, SLOT(dlgSearch()));
261 m_no_search = this->menuBar()->addAction("Search is Off");
262 connect(m_no_search,SIGNAL(triggered()), this, SLOT(noSearch()));
264 QAction *m_about = this->menuBar()->addAction("About");
265 QAction *m_about_qt = this->menuBar()->addAction("About Qt");
267 connect(m_about,SIGNAL(triggered()), this, SLOT(dlgAbout()));
268 connect(m_about_qt,SIGNAL(triggered()), qApp, SLOT(aboutQt()));
272 void MainWindow::noSearch(){
274 m_contacts_widget->setEnabled(false);
275 m_no_search->setText("Search is Off");
276 m_elv1db->m_type_query = m_type_query_temp;
282 void MainWindow::dlgSearch(){
284 QString text = QInputDialog::getText(this, tr("Search"),
285 tr("Give me a contact name to do a search :"), QLineEdit::Normal,
286 *m_elv1db->m_search_val, &ok);
287 if (ok && !text.isEmpty() && !text.trimmed().isEmpty()){
288 m_no_search->setText("Search is On");
290 this->doSearch(text);
294 void MainWindow::doSearch(QString val){
295 m_contacts_widget->setEnabled(false);
296 *m_elv1db->m_search_val = val;
297 m_elv1db->m_type_query = 2;
301 void MainWindow::select_all_call(){ //ring/tel/ring, spirit/skype, gabble/jabber
302 m_contacts_widget->setEnabled(false);
303 m_elv1db->m_all_call = true;
304 m_type_query_temp = 0;
308 void MainWindow::select_gsm_calls(){ //ring/tel/ring
309 m_contacts_widget->setEnabled(false);
310 m_elv1db->m_all_call = false;
311 m_type_query_temp = 0;
315 void MainWindow::select_all_typecall(){ //incoming, outgoing and missed calls
316 m_contacts_widget->setEnabled(false);
317 m_elv1db->m_call_type = ALL_CALL;
321 void MainWindow::select_incoming_calls(){
322 m_contacts_widget->setEnabled(false);
323 m_elv1db->m_call_type = INCOMING;
327 void MainWindow::select_outgoing_calls(){
328 m_contacts_widget->setEnabled(false);
329 m_elv1db->m_call_type = OUTGOING;
333 void MainWindow::select_missed_calls(){
334 m_contacts_widget->setEnabled(false);
335 m_elv1db->m_call_type = MISSED;
339 void MainWindow::clearLog(){
342 void MainWindow::setup_menu_detail(){
345 void MainWindow::dlgAbout(){
347 m_about.setWindowTitle("About");
349 "<font size=4>VN Call History</font><br>"
350 "<font size=3>Version : 0.0.2 (09/29/2011)</font><br>"
351 "Author : Cuong Le <a href=\"mailto:metacuong@gmail.com\">metacuong@gmail.com</a><br>"
353 "Homepage : <a href=\"http://vncallhistory.garage.maemo.org/\">http://vncallhistory.garage.maemo.org/</a><br>"
354 "Bugs report : <a href=\"https://garage.maemo.org/tracker/?group_id=2259\">https://garage.maemo.org/tracker/?group_id=2259</a><br>"
355 "License : GNU/GPL version 2"
361 void MainWindow::dlgOptions(){
362 dlg_options = new QMainWindow(this);
363 dlg_options->setWindowTitle(QString::fromUtf8("Options"));
364 dlg_options->installEventFilter(this);
366 dlg_options->setAttribute(Qt::WA_Maemo5StackedWindow);
371 void MainWindow::setOrientation(ScreenOrientation orientation)
373 #if defined(Q_OS_SYMBIAN)
374 // If the version of Qt on the device is < 4.7.2, that attribute won't work
375 if (orientation != ScreenOrientationAuto) {
376 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
377 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
378 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
382 #endif // Q_OS_SYMBIAN
384 Qt::WidgetAttribute attribute;
385 switch (orientation) {
386 #if QT_VERSION < 0x040702
387 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
388 case ScreenOrientationLockPortrait:
389 attribute = static_cast<Qt::WidgetAttribute>(128);
391 case ScreenOrientationLockLandscape:
392 attribute = static_cast<Qt::WidgetAttribute>(129);
395 case ScreenOrientationAuto:
396 attribute = static_cast<Qt::WidgetAttribute>(130);
398 #else // QT_VERSION < 0x040702
399 case ScreenOrientationLockPortrait:
400 attribute = Qt::WA_LockPortraitOrientation;
402 case ScreenOrientationLockLandscape:
403 attribute = Qt::WA_LockLandscapeOrientation;
406 case ScreenOrientationAuto:
407 attribute = Qt::WA_AutoOrientation;
409 #endif // QT_VERSION < 0x040702
411 setAttribute(attribute, true);
414 void MainWindow::showExpanded()
418 #elif defined(Q_WS_MAEMO_5)