homescreenapp/hsapplication/src/main.cpp
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/homescreenapp/hsapplication/src/main.cpp	Fri Mar 19 09:27:44 2010 +0200
@@ -0,0 +1,242 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Main.
+*
+*/
+#include <QTranslator>
+#include <QMessageBox>
+#include <hbapplication.h>
+#include <hbmainwindow.h>
+#include "hshomescreen.h"
+#include "hsapptranslator.h"
+#include "hstest_global.h"
+
+namespace
+{
+    const char TR_FILE_PATH[] = "resource/qt/translations";
+}
+
+#ifdef Q_OS_SYMBIAN
+
+#include <QFile>
+#include <QDir>
+#include <f32file.h>
+#include <eikenv.h>
+#include <e32debug.h>
+#include <apgwgnam.h>
+
+// it is temporary class used for getting notifcation about APA messages
+// it is used for processing message send by AVKON to activate Menu
+class HsMessageObserver: public MCoeMessageObserver {
+
+TMessageResponse HandleMessageL(TUint32 /*aClientHandleOfTargetWindowGroup*/,
+                                TUid /*aMessageUid*/,
+                                const TDesC8& /*aMessageParameters*/)
+    {
+    // move application to foreground
+    QApplication::topLevelAt(0,0)->raise();
+    return EMessageHandled;
+    }
+};
+
+void setHomescreenAsSystemAppL(CEikonEnv* eikonEnv)
+{
+    CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(eikonEnv->WsSession());
+    wgName->SetSystem(ETrue); // Allow only application with PowerManagement cap to shut us down
+    wgName->SetCaptionL(_L("HsApplication"));
+    wgName->SetAppUid(TUid::Uid(0x20022F35));
+    wgName->SetWindowGroupName(eikonEnv->RootWin());
+    CleanupStack::PopAndDestroy();
+}
+
+
+
+void myMessageOutput(QtMsgType type, const char *msg)
+{
+    switch (type) {
+
+    case QtDebugMsg:
+        RDebug::Printf("[HS] Debug: %s\n", msg);
+        break;
+
+    case QtWarningMsg:
+        RDebug::Printf("[HS] Warning: %s\n", msg);
+        break;
+
+    case QtCriticalMsg:
+        RDebug::Printf("[HS] Critical: %s\n", msg);
+        break;
+
+    case QtFatalMsg:
+        RDebug::Printf("[HS] Fatal: %s\n", msg);
+        abort();
+    }
+}
+
+#endif //Q_OS_SYMBIAN
+
+
+
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+int main(int argc, char *argv[])
+{
+#ifdef Q_OS_SYMBIAN
+     qInstallMsgHandler(myMessageOutput);
+#endif
+
+    HSTEST_FUNC_ENTRY("HS::main()");
+
+    HbApplication app(argc, argv);
+
+#ifdef Q_OS_SYMBIAN
+    QString currentPath = QString(argv[0]).left(2);
+    QDir::setCurrent(currentPath);
+    QString debugMsg = "HS::main() - HsApplication's current dir set to: " + currentPath;
+    HSDEBUG(debugMsg);
+#endif //Q_OS_SYMBIAN
+
+    HsAppTranslator *appTranslator = HsAppTranslator::instance();
+    appTranslator->setLanguage();
+
+    // add translator for homescreen and application library
+    QString locale = QLocale::system().name();
+
+    QTranslator hsTranslator;
+    QString hsTrFile = QString("homescreen_") + locale;
+
+    QTranslator alTranslator;
+    QString alTrFile = QString("hsapplibrary_") + locale;
+#ifdef Q_OS_SYMBIAN
+    // TRAP is must here, otherwise it crashes
+TRAP_IGNORE(
+    bool hsLoaded(false);
+    hsLoaded = hsTranslator.load(hsTrFile, QString("z:/") + TR_FILE_PATH);
+    if (!hsLoaded)
+        hsTranslator.load(hsTrFile, QString("c:/") + TR_FILE_PATH);
+
+    bool alLoaded(false);
+    alLoaded = alTranslator.load(alTrFile, QString("z:/") + TR_FILE_PATH);
+    if (!alLoaded)
+        alTranslator.load(alTrFile, QString("c:/") + TR_FILE_PATH);
+);
+#else
+    hsTranslator.load(hsTrFile, QString(TR_FILE_PATH) );
+    alTranslator.load(alTrFile, QString(TR_FILE_PATH) );
+#endif //Q_OS_SYMBIAN
+    app.installTranslator(&hsTranslator);
+    app.installTranslator(&alTranslator);
+
+#ifdef Q_OS_SYMBIAN
+    QFile file("c:/private/20022f35/homescreendb");
+    //If DB file does not exist copy default DB from z: (ROM)
+    if(!file.exists()) {
+        HSTEST("HS::main() - homescreendb not in c:");
+        file.setFileName("z:/private/20022f35/homescreendb");
+        if(!file.exists()) {
+            HSTEST("HS::main() - homescreendb not in ROM!");
+        }
+        else {
+            HSTEST("HS::main() - homescreendb found from z:");
+            //We need to first create private folder if not exists
+            QDir dir("c:/private/20022f35/");
+            if(!dir.exists()) {
+                HSTEST("HS::main() - c:/private/20022f35/ does not exist.");
+                RFs fsSession;
+                if(fsSession.Connect() != KErrNone){
+                    HSTEST("HS::main() - Homescreen private dir creation failed!");
+                }
+                fsSession.CreatePrivatePath(EDriveC);
+                HSTEST("HS::main() - c:/private/20022f35/ created.");
+                fsSession.Close();
+                if(!dir.exists()) {
+                    HSTEST("HS::main() - c:/private/20022f35/ creation failed.");
+                }
+            }
+            HSTEST("HS::main() - c:/private/20022f35/ exists.");
+            //Copy DB from z: to c:
+            if (!file.copy("c:/private/20022f35/homescreendb")) {
+                HSTEST("HS::main() - homescreendb copy from ROM to c: failed!");
+            }
+            HSTEST("HS::main() - homescreendb copied from ROM to c:!");
+            file.setFileName("c:/private/20022f35/homescreendb");
+            if(!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) {
+                HSTEST("HS::main() - homescreendb ReadWrite permission settings on c: failed!");
+            }
+            HSTEST("HS::main() - homescreendb permission set to ReadWrite!");
+        }
+    }
+#ifdef __WINS__
+    else if(!file.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) {
+        HSTEST("HS::main() - homescreendb ReadWrite permission settings on emulator's c: failed!");
+    }
+#endif
+    {
+    QDir dir("c:/private/20022f35/wallpapers");
+    if(!dir.exists()) {
+        dir.mkpath("c:/private/20022f35/wallpapers/");
+        QDir dir2("z:/private/20022f35/wallpapers");
+        dir2.setFilter(QDir::Files);
+        QStringList files = dir2.entryList();
+        foreach(QString file, files)
+        {
+            QString targetFile("c:/private/20022f35/wallpapers/" + file);
+            QFile::copy(dir2.absoluteFilePath(file), targetFile);
+            qDebug() << "image copied" << dir2.absoluteFilePath(file);
+            QFile createdFile(targetFile);
+            if(!createdFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) {
+                qDebug() << "read write permission set failed for file" << targetFile;
+            }
+        }
+
+    }
+
+
+    }
+
+#endif //Q_OS_SYMBIAN
+
+    HbMainWindow window;
+    window.setViewSwitchingEnabled(false);
+    
+    HsHomeScreen hs;
+    QObject::connect(&app, SIGNAL(aboutToQuit()) ,&hs, SLOT(stop()));
+    QObject::connect(&hs, SIGNAL(exit()), &app, SLOT(quit()),Qt::QueuedConnection);
+    hs.start();
+
+    app.installEventFilter(appTranslator);
+
+#ifdef Q_OS_SYMBIAN
+    CEikonEnv * env = CEikonEnv::Static();
+#ifdef S60APP_KEY
+    env->RootWin().CaptureKeyUpAndDowns( EStdKeyApplication0, 0, 0 );
+#endif //S60APP_KEY
+    TRAP_IGNORE(setHomescreenAsSystemAppL(env));
+    HsMessageObserver observer;
+    TRAP_IGNORE( env->AddMessageObserverL(observer));
+#endif //Q_OS_SYMBIAN
+
+    HSTEST("HS::main() call app.exec");
+    try {
+        app.exec();
+
+    } catch(...) {
+        HSTEST("HS::main() app.exec() catch");
+    }
+    return 0;
+}
+
+