src/hbservers/hbthemeserver/hbthemeserverapplication.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 6 c3690ec91ef8
--- a/src/hbservers/hbthemeserver/hbthemeserverapplication.cpp	Fri May 14 16:09:54 2010 +0300
+++ b/src/hbservers/hbthemeserver/hbthemeserverapplication.cpp	Thu May 27 13:10:59 2010 +0300
@@ -30,6 +30,7 @@
 #include <QWindowsStyle>
 #include <QLibrary>
 #include <QDebug>
+#include <QDir>
 
 #if defined (Q_OS_SYMBIAN)
 #include "hbthemecommon_symbian_p.h"
@@ -48,7 +49,7 @@
 bool HbThemeServerApplication::Options::start = false;
 bool HbThemeServerApplication::Options::stop = false;
 bool HbThemeServerApplication::Options::persistent = false;
-QString HbThemeServerApplication::Options::error = QString();
+QString HbThemeServerApplication::Options::error;
 
 HbThemeServerApplication::HbThemeServerApplication(int &argc, char *argv[]) :
     QtSingleApplication(argc, argv), server(0)
@@ -60,10 +61,6 @@
     setStyle(new QWindowsStyle);
 #endif // QT_DEBUG
 
-#if QT_VERSION >= 0x040601
-    setAttribute(Qt::AA_S60DontConstructApplicationPanes);
-#endif // QT_VERSION
-
     // ignore command line arguments on Symbian
 #ifdef Q_OS_SYMBIAN
     Options::start = true;
@@ -76,7 +73,8 @@
     Options::start = args.removeAll(QLatin1String("-start")) || restart;
     Options::stop = args.removeAll(QLatin1String("-stop")) || restart;
     Options::persistent = args.removeAll(QLatin1String("-persistent"));
-    Options::help = args.removeAll(QLatin1String("-help")) || args.removeAll(QLatin1String("-h")) || !args.isEmpty() || wasEmpty;
+    Options::help = args.removeAll(QLatin1String("-help"))
+                    || args.removeAll(QLatin1String("-h")) || !args.isEmpty() || wasEmpty;
     if (!args.isEmpty()) {
         Options::error = tr("Unknown option(s): '%1'").arg(args.join(QLatin1String(" ")));
     }
@@ -93,21 +91,19 @@
 #if defined (Q_OS_SYMBIAN)
     CEikonEnv * env = CEikonEnv::Static();
     if ( env ) {
-        CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(env->WsSession());
+        _LIT(KHbThemeServer, "HbThemeServer");
+        CApaWindowGroupName *wgName = CApaWindowGroupName::NewLC(env->WsSession());
         env->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront); // avoid coming to foreground
         wgName->SetHidden(ETrue); // hides us from FSW and protects us from OOM FW etc.
         wgName->SetSystem(ETrue); // Allow only application with PowerManagement cap to shut us down    
-        wgName->SetCaptionL(_L("HbThemeServer")); // TODO: use QCoreApplication::applicationName()
+        wgName->SetCaptionL(KHbThemeServer);
         wgName->SetAppUid(KNullUid);
         wgName->SetWindowGroupName(env->RootWin());
         CleanupStack::PopAndDestroy();
-        RThread::RenameMe(_L("HbThemeServer")); // TODO: use QCoreApplication::applicationName()
+        RThread::RenameMe(KHbThemeServer);
     }
 #endif
 
-    // as for theme initialization, an instance needs to be created before starting the server
-    HbTheme::instance();
-
     // load resource libraries in order to make binary resources accessible
     bool result = loadLibrary(RESOURCE_LIB_NAME);
 #ifdef HB_DEVELOPER
@@ -139,12 +135,34 @@
 #endif // Q_OS_SYMBIAN
 }
 
+static bool hb_loadLibraryHelper(const QString &name)
+{
+    QLibrary library(name);
+    // rely on dynamic loader (LD_LIBRARY_PATH)
+    bool result = library.load();
+    if (!result) {
+        // try from prefix/lib dir
+        library.setFileName(QDir(HB_LIB_DIR).filePath(name));
+        result = library.load();
+        if (!result) {
+            // try from build/lib dir
+            QString path = QLatin1String(HB_BUILD_DIR) + QDir::separator() + QLatin1String("lib");
+            library.setFileName(QDir(path).filePath(name));
+            result = library.load();
+        }
+    }
+#ifdef THEME_SERVER_TRACES
+    if (!result) {
+        qDebug() << "hb_loadLibraryHelper():" << library.errorString();
+    }
+#endif
+    return result;
+}
+
 bool HbThemeServerApplication::loadLibrary(const QString &name)
 {
     // To load resources embedded in hb library
-    QLibrary library(name);
-    bool result = library.load();
-
+    bool result = hb_loadLibraryHelper(name);
     if (!result) {
         // Library may not be loaded, if it was built in debug mode and the name in debug mode is
         // different, change the name to debug version in that scenario
@@ -156,8 +174,9 @@
 #endif
         // On symbian library name in debug mode is same as that in release mode,
         // so no need to do anything for that
-        library.setFileName(alternateName);
-        result = library.load();
+        if (alternateName != name) {
+            result = hb_loadLibraryHelper(alternateName);
+        }
     }
 #ifdef THEME_SERVER_TRACES
     if (result) {
@@ -173,8 +192,9 @@
 
 void HbThemeServerApplication::receiveMessage(const QString &message)
 {
-    if (!server)
+    if (!server) {
         return;
+    }
 
     if (message == STOP_MESSAGE) {
         server->stopServer();
@@ -219,10 +239,13 @@
 #else
     return true;
 #endif
-
-
 }
-
+void HbThemeServerApplication::setPriority()
+{
+#ifdef Q_OS_SYMBIAN
+    RProcess().SetPriority(EPriorityHigh);
+#endif
+}
 
 #ifdef Q_OS_SYMBIAN
 Lock::Lock()