Added the ability to edit the PID number using the number pad.
[profile/ivi/hfdialer.git] / src / qmlmainwindow.cpp
1 /*
2  * dialer - Declarative Dialer UX Main Window.
3  * Copyright (c) 2011, Tom Swindell.
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 "common.h"
12 #include "dialerapplication.h"
13
14 #include "qmlcallitem.h"
15 #include "qmldialer.h"
16
17 #include "qmlmainwindow.h"
18
19 #include <QtDeclarative>
20
21 #define CONFIG_KEY_QML_LOAD_URL "/apps/dialer/qml/url"
22
23 #define DEFAULT_QML_LOAD_URL "file:///usr/share/hfdialer/qml/main.qml"
24
25 class QMLMainWindowPrivate
26 {
27 public:
28     QMLMainWindowPrivate()
29         : adapter(NULL),
30           engine(NULL),
31           component(NULL),
32           item(NULL)
33     { TRACE }
34
35     QMLDialer               *adapter;
36     QDeclarativeEngine      *engine;
37     QDeclarativeView        *qdv; 
38     
39     QDeclarativeComponent   *component;
40     QDeclarativeItem        *item;
41 };
42
43 static void registerDataTypes()
44 {
45     TRACE
46     qmlRegisterType<QMLDialer>("com.tizen.hfdialer", 1, 0, "Dialer");
47
48     qmlRegisterUncreatableType<QMLCallItem>("com.tizen.hfdialer", 1, 0, "CallItem", "");
49 }
50
51 QMLMainWindow::QMLMainWindow(QWidget *parent)
52     : QDeclarativeView(parent),
53       d(new QMLMainWindowPrivate)
54 {
55     TRACE
56     DialerApplication *da = DialerApplication::instance();
57     CallManager *cm = ManagerProxy::instance()->callManager();
58
59     setResizeMode(QDeclarativeView::SizeRootObjectToView);
60
61     this->setWindowTitle(qtTrId("xx_window"));
62
63     this->setupUi();
64
65     da->setActiveWindow(this);
66
67     connect(this->engine(), SIGNAL(quit()), this, SLOT(close()));
68 }
69
70 QMLMainWindow::~QMLMainWindow()
71 {
72     TRACE
73     delete this->d;
74 }
75
76 QMLMainWindow* QMLMainWindow::instance()
77 {
78     TRACE
79     static QMLMainWindow *_instance = NULL;
80
81     if(_instance == NULL)
82     {
83         registerDataTypes();
84         _instance = new QMLMainWindow;
85     }
86
87     return _instance;
88 }
89
90
91 QMLMainWindow* QMLMainWindow::instanceP(QWidget* parent)
92 {
93     TRACE
94     static QMLMainWindow *_instance = NULL;
95
96     if(_instance == NULL)
97     {
98         registerDataTypes();
99         _instance = new QMLMainWindow(parent);
100     }
101
102     return _instance;
103 }
104
105 void QMLMainWindow::setupUi()
106 {
107     TRACE
108     MGConfItem qmlUrl(CONFIG_KEY_QML_LOAD_URL);
109
110     d->engine = new QDeclarativeEngine(this);
111
112     d->engine->addImportPath("/usr/share/hfdialer/qml/base");
113
114     d->engine->rootContext()->setContextProperty("controller", this); //TODO: Remove
115    // d->engine->rootContext()->setContextProperty("History", DialerApplication::instance()->historyProxy());
116     this->setSource(QUrl::fromLocalFile("/usr/share/hfdialer/qml/main.qml"));
117     //this->setResizeMode(QDeclarativeView::SizeRootObjectToView);
118     //this->setSize(this->geometry);
119     d->component = new QDeclarativeComponent(d->engine, this);
120     d->component->loadUrl(qmlUrl.value(DEFAULT_QML_LOAD_URL).toString());
121
122     if(d->component->isError())
123     {
124         qCritical() << "Failed to load QML Component:" << d->component->errorString();
125         return;
126     }
127
128     d->item = qobject_cast<QDeclarativeItem*>(d->component->create());
129     if(!d->item)
130     {
131         qCritical() << "Failed to create item from component!";
132         return;
133     }
134 }
135
136 void QMLMainWindow::tryToShow()
137 {
138     TRACE
139      
140    if (d->component->isReady())
141     {
142         DialerApplication *da = DialerApplication::instance();
143         da->setActiveWindow(this);
144         da->activeWindow()->show();
145         da->activeWindow()->activateWindow();
146         da->activeWindow()->raise();
147         this->show();
148     }
149  
150 }
151 void QMLMainWindow::hide()
152 {
153     TRACE
154     QGraphicsView::hide();
155 }
156
157 void QMLMainWindow::closeEvent(QCloseEvent *event)
158 {
159     TRACE
160 /*    if(this->closeOnLazyShutdown())
161     {
162         this->setCloseOnLazyShutdown(false);
163     }
164 */
165     event->accept();
166
167 }
168
169 void QMLMainWindow::onGeometryChanged()
170 {
171     TRACE
172    // d->item->setSize(d->widget->size());
173 }
174
175 void QMLMainWindow::setAdapter(QMLDialer *adapter)
176 {
177     TRACE
178     d->adapter = adapter;
179 }