2 * dialer - Declarative Dialer UX Main Window.
3 * Copyright (c) 2011, Tom Swindell.
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
12 #include "dialerapplication.h"
14 #include "qmlcallitem.h"
15 #include "qmldialer.h"
17 #include "qmlmainwindow.h"
19 #include <QtDeclarative>
21 #define CONFIG_KEY_QML_LOAD_URL "/apps/dialer/qml/url"
23 #define DEFAULT_QML_LOAD_URL "file:///usr/share/hfdialer/qml/main.qml"
25 class QMLMainWindowPrivate
28 QMLMainWindowPrivate()
36 QDeclarativeEngine *engine;
37 QDeclarativeView *qdv;
39 QDeclarativeComponent *component;
40 QDeclarativeItem *item;
43 static void registerDataTypes()
46 qmlRegisterType<QMLDialer>("com.tizen.hfdialer", 1, 0, "Dialer");
48 qmlRegisterUncreatableType<QMLCallItem>("com.tizen.hfdialer", 1, 0, "CallItem", "");
51 QMLMainWindow::QMLMainWindow(QWidget *parent)
52 : QDeclarativeView(parent),
53 d(new QMLMainWindowPrivate)
56 DialerApplication *da = DialerApplication::instance();
57 CallManager *cm = ManagerProxy::instance()->callManager();
59 setResizeMode(QDeclarativeView::SizeRootObjectToView);
61 this->setWindowTitle(qtTrId("xx_window"));
65 da->setActiveWindow(this);
67 connect(this->engine(), SIGNAL(quit()), this, SLOT(close()));
70 QMLMainWindow::~QMLMainWindow()
76 QMLMainWindow* QMLMainWindow::instance()
79 static QMLMainWindow *_instance = NULL;
84 _instance = new QMLMainWindow;
91 QMLMainWindow* QMLMainWindow::instanceP(QWidget* parent)
94 static QMLMainWindow *_instance = NULL;
99 _instance = new QMLMainWindow(parent);
105 void QMLMainWindow::setupUi()
108 MGConfItem qmlUrl(CONFIG_KEY_QML_LOAD_URL);
110 d->engine = new QDeclarativeEngine(this);
112 d->engine->addImportPath("/usr/share/hfdialer/qml/base");
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());
122 if(d->component->isError())
124 qCritical() << "Failed to load QML Component:" << d->component->errorString();
128 d->item = qobject_cast<QDeclarativeItem*>(d->component->create());
131 qCritical() << "Failed to create item from component!";
136 void QMLMainWindow::tryToShow()
140 if (d->component->isReady())
142 DialerApplication *da = DialerApplication::instance();
143 da->setActiveWindow(this);
144 da->activeWindow()->show();
145 da->activeWindow()->activateWindow();
146 da->activeWindow()->raise();
151 void QMLMainWindow::hide()
154 QGraphicsView::hide();
157 void QMLMainWindow::closeEvent(QCloseEvent *event)
160 /* if(this->closeOnLazyShutdown())
162 this->setCloseOnLazyShutdown(false);
169 void QMLMainWindow::onGeometryChanged()
172 // d->item->setSize(d->widget->size());
175 void QMLMainWindow::setAdapter(QMLDialer *adapter)
178 d->adapter = adapter;