Removing defunct keepalive script and cleaning out dead entries from
[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 #define CONFIG_KEY_TARGET_UX "/apps/dialer/ux"
22
23 #if !defined(CONFIG_DEFAULT_TARGET_UX)
24 #  define CONFIG_DEFAULT_TARGET_UX "tizen-ux-components"
25 #endif
26
27 int main(int argc, char *argv[])
28 {
29     TRACE
30     DialerApplication app(argc, argv);  
31
32     QMLMainWindow *qmw = QMLMainWindow::instance();
33     qmw->tryToShow();
34
35     return app.exec();
36 }
37
38 QString stripLineID(QString lineid)
39 {
40     TRACE
41     static QRegExp rx = QRegExp("([^0-9*#])");
42
43     if (lineid.indexOf('+') == 0) {
44         lineid.replace(rx, "");
45         return lineid.insert(0,"+");
46     }
47     else
48         return lineid.replace(rx, "");
49 }
50
51 bool currentPageIs(int pagenum)
52 {
53     DialerApplication *app = DialerApplication::instance();
54      return true;
55 }
56
57 // Returns a valid QDateTime if parsable as such, otherwise the result
58 // will be !isValid()
59 QDateTime qDateTimeFromOfono(const QString &val)
60 {
61     TRACE
62     QDateTime result;
63
64     if (val.isEmpty())
65         return result;
66
67     // NOTE: Ofono formats time to string with the following format spec:
68     //       %Y-%m-%dT%H:%M:%S%z (for example: "2001-10-19T10:32:30-05:00")
69
70     // Start by trying to parse this as an ISODate "YYYY-MM-DDTHH:MM:SSTZD"
71     result = QDateTime::fromString(val,Qt::ISODate);
72 #ifdef VERBOSE
73     qDebug() << QString("Converted %1 with Qt::ISODate: %2")
74                        .arg(val)
75                        .arg(result.toString());
76 #endif
77
78     if (!result.isValid()) {
79     // ISODate conversion has failed, fallback to manual method
80     // NOTE: QDateTime::fromString(val, Qt::ISODate) Fails since the date
81     //       format from Ofono is in RFC 822 form, but QDateTime can't parse it
82         struct tm time_tm;
83         QByteArray  bytes = val.toAscii();
84         const char *str = bytes.constData();
85         if (strptime(str, "%Y-%m-%dT%H:%M:%S%z", &time_tm) != NULL) {
86             time_t t = mktime(&time_tm);
87             if (t >= (time_t)(0)) {
88                 result.setTime_t(t);
89 #ifdef VERBOSE 
90                 qDebug() << QString("Converted %1 with strptime: %2")
91                                    .arg(val)
92                                    .arg(result.toString());
93 #endif
94             }
95         }
96
97         if (!result.isValid())
98             qCritical() << QString("Format error, unknown date/time: %1")
99                                   .arg(str);
100     }
101
102     return result;
103 }