Further cleanup of the build system
[profile/ivi/hfdialer.git] / src / main.cpp
1 /*
2  * hfdialer - Hands Free Voice Call Manager
3  * Copyright (c) 2012, Intel Corporation.
4  *
5  * This program is licensed under the terms and conditions of the
6  * Apache License, version 2.0.  The full text of the Apache License is at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  */
10
11 #include "dialercontext.h"
12 #include "dialerapplication.h"
13 #include "qmlmainwindow.h"
14 #include "common.h"
15
16 #include <QtGui>
17 #include <QApplication>
18 #include <QDeclarativeView>
19 #include <QFile>
20
21 int main(int argc, char *argv[])
22 {
23     TRACE
24     DialerApplication app(argc, argv);  
25
26     QMLMainWindow *qmw = QMLMainWindow::instance();
27     qmw->tryToShow();
28
29     return app.exec();
30 }
31
32 QString stripLineID(QString lineid)
33 {
34     TRACE
35     static QRegExp rx = QRegExp("([^0-9*#])");
36
37     if (lineid.indexOf('+') == 0) {
38         lineid.replace(rx, "");
39         return lineid.insert(0,"+");
40     }
41     else
42         return lineid.replace(rx, "");
43 }
44
45 bool currentPageIs(int pagenum)
46 {
47     DialerApplication *app = DialerApplication::instance();
48      return true;
49 }
50
51 // Returns a valid QDateTime if parsable as such, otherwise the result
52 // will be !isValid()
53 QDateTime qDateTimeFromOfono(const QString &val)
54 {
55     TRACE
56     QDateTime result;
57
58     if (val.isEmpty())
59         return result;
60
61     // NOTE: Ofono formats time to string with the following format spec:
62     //       %Y-%m-%dT%H:%M:%S%z (for example: "2001-10-19T10:32:30-05:00")
63
64     // Start by trying to parse this as an ISODate "YYYY-MM-DDTHH:MM:SSTZD"
65     result = QDateTime::fromString(val,Qt::ISODate);
66 #ifdef VERBOSE
67     qDebug() << QString("Converted %1 with Qt::ISODate: %2")
68                        .arg(val)
69                        .arg(result.toString());
70 #endif
71
72     if (!result.isValid()) {
73     // ISODate conversion has failed, fallback to manual method
74     // NOTE: QDateTime::fromString(val, Qt::ISODate) Fails since the date
75     //       format from Ofono is in RFC 822 form, but QDateTime can't parse it
76         struct tm time_tm;
77         QByteArray  bytes = val.toAscii();
78         const char *str = bytes.constData();
79         if (strptime(str, "%Y-%m-%dT%H:%M:%S%z", &time_tm) != NULL) {
80             time_t t = mktime(&time_tm);
81             if (t >= (time_t)(0)) {
82                 result.setTime_t(t);
83 #ifdef VERBOSE 
84                 qDebug() << QString("Converted %1 with strptime: %2")
85                                    .arg(val)
86                                    .arg(result.toString());
87 #endif
88             }
89         }
90
91         if (!result.isValid())
92             qCritical() << QString("Format error, unknown date/time: %1")
93                                   .arg(str);
94     }
95
96     return result;
97 }