/*
 * Copyright (c) 2010 Nokia Corporation.
 */

#include <QtGui/QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
#include <QGraphicsObject>
#include "qmlcodeprovider.h"
#include "taskswitcher.h"

// Lock S60 orientation
#ifdef Q_WS_S60
    #include <eikenv.h>
    #include <eikappui.h>
    #include <aknenv.h>
    #include <aknappui.h>
#endif

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // Lock S60 orientation
#ifdef Q_WS_S60
    CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
    TRAP_IGNORE(
        if(appUi) {
            appUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
        }
    );
#endif

    QDeclarativeView view;
    view.engine()->addImportPath("./imports");        // use this if the WebView and Particles modules are somewhere else than under the Qt libraries
    view.rootContext()->setContextProperty("codeprovider", new QMLCodeProvider);
    view.setSource(QUrl("qrc:/demochooser.qml"));
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);

#ifdef Q_WS_MAEMO_5
    // Set the place where High score list of the SameGame demo is stored in Maemo
    view.engine()->setOfflineStoragePath("/home/user/MyDocs/");
#endif

    QObject *rootObject = dynamic_cast<QObject*>(view.rootObject());

    // Task switcher
    TaskSwitcher taskSwitcher;
    QObject::connect(rootObject, SIGNAL(minimizeApplication()), &taskSwitcher, SLOT(minimizeApplication()));
    QObject::connect((QObject*)view.engine(), SIGNAL(quit()), &a, SLOT(quit()));

    // Set the right resolution for each platform
#if defined(Q_WS_MAEMO_5)
    view.setGeometry(QRect(0,0,800,480));
    view.showFullScreen();
#elif defined(Q_WS_S60)
    view.setGeometry(QRect(0,0,640,360));
    view.showFullScreen();
#else
    view.setGeometry(QRect(100,100,800, 480));
    view.show();
#endif

    return a.exec();
}
