| Home · All Namespaces · All Classes |
00001 /*************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of mhome. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 #include <sys/types.h> 00020 #include <signal.h> 00021 #include <unistd.h> 00022 #include <getopt.h> 00023 #include <QDBusMessage> 00024 #include <QDBusConnection> 00025 #include "homeapplication.h" 00026 #include "homescreenservice.h" 00027 #include "homescreenadaptor.h" 00028 #include "windowinfo.h" 00029 #include "xeventlistener.h" 00030 00034 static const QString MEEGO_CORE_HOME_SCREEN_SERVICE_NAME = "com.meego.core.HomeScreen"; 00035 static const QString MEEGO_CORE_HOME_SCREEN_OBJECT_PATH = "/homescreen"; 00036 00040 static const QString HOME_READY_SIGNAL_PATH = "/com/nokia/duihome"; 00041 static const QString HOME_READY_SIGNAL_INTERFACE = "com.nokia.duihome.readyNotifier"; 00042 static const QString HOME_READY_SIGNAL_NAME = "ready"; 00043 00054 static bool isUpstartMode(int argc, char *argv[]) 00055 { 00056 if (argc < 2) { 00057 return false; 00058 } 00059 static const char optChar = 'u'; 00060 static const char *optString = "u"; 00061 static struct option optLong[] = { 00062 { "upstart", 0, NULL, optChar }, 00063 { 0, 0, 0, 0 } 00064 }; 00065 opterr = 0; 00066 int c = 0; 00067 while ((c = getopt_long_only(argc, argv, 00068 optString, 00069 optLong, 00070 0)) != -1) { 00071 if (c == optChar) { 00072 return true; 00073 } 00074 } 00075 return false; 00076 } 00077 00078 HomeApplication::HomeApplication(int &argc, char **argv, const QString& appIdentifier) : 00079 MApplication(argc, argv, appIdentifier), 00080 homeScreenService(new HomeScreenService), 00081 xEventListeners(), 00082 iteratorActiveForEventListenerContainer(false), 00083 toBeRemovedEventListeners() 00084 { 00085 // Enable prestart mode 00086 MApplication::setPrestartMode(M::TerminateOnClose); 00087 00088 // launch a timer for sending a dbus-signal upstart when home is ready 00089 // and on screen 00090 upstartMode = isUpstartMode(argc, argv); 00091 connect(&startupNotificationTimer, SIGNAL(timeout()), 00092 this, SLOT(sendStartupNotifications())); 00093 startupNotificationTimer.setSingleShot(true); 00094 startupNotificationTimer.setInterval(0); 00095 startupNotificationTimer.start(); 00096 00097 new HomeScreenAdaptor(homeScreenService); 00098 00099 QDBusConnection connection = QDBusConnection::sessionBus(); 00100 00101 connection.registerService(MEEGO_CORE_HOME_SCREEN_SERVICE_NAME); 00102 connection.registerObject(MEEGO_CORE_HOME_SCREEN_OBJECT_PATH, homeScreenService); 00103 00104 connect(homeScreenService, SIGNAL(focusToLauncherApp(const QString&)), this, SIGNAL(focusToLauncherAppRequested(const QString &))); 00105 00106 // Initialize the X11 atoms used in the UI components 00107 WindowInfo::initializeAtoms(); 00108 } 00109 00110 HomeApplication::~HomeApplication() 00111 { 00112 delete homeScreenService; 00113 } 00114 00115 void HomeApplication::addXEventListener(XEventListener *listener) 00116 { 00117 if (listener != NULL && !xEventListeners.contains(listener)) { 00118 xEventListeners.append(listener); 00119 } 00120 } 00121 00122 void HomeApplication::removeXEventListener(XEventListener *listener) 00123 { 00124 if (iteratorActiveForEventListenerContainer) { 00125 toBeRemovedEventListeners.append(listener); 00126 } else { 00127 xEventListeners.removeOne(listener); 00128 } 00129 } 00130 00131 void HomeApplication::sendStartupNotifications() 00132 { 00133 static QDBusConnection systemBus = QDBusConnection::systemBus(); 00134 QDBusMessage homeReadySignal = 00135 QDBusMessage::createSignal(HOME_READY_SIGNAL_PATH, 00136 HOME_READY_SIGNAL_INTERFACE, 00137 HOME_READY_SIGNAL_NAME); 00138 systemBus.send(homeReadySignal); 00139 if (upstartMode) { 00140 static pid_t selfPid = getpid(); 00141 kill(selfPid, SIGSTOP); 00142 } 00143 } 00144 00145 bool HomeApplication::x11EventFilter(XEvent *event) 00146 { 00147 bool eventHandled = false; 00148 iteratorActiveForEventListenerContainer = true; 00149 foreach (XEventListener* listener, xEventListeners) { 00150 if (!toBeRemovedEventListeners.contains(listener)) { 00151 if (listener->handleXEvent(*event)) { 00152 eventHandled = true; 00153 } 00154 } 00155 } 00156 iteratorActiveForEventListenerContainer = false; 00157 00158 // Remove now any event listeners that got removed while going through the event listeners 00159 foreach (XEventListener* listener, toBeRemovedEventListeners) { 00160 xEventListeners.removeOne(listener); 00161 } 00162 toBeRemovedEventListeners.clear(); 00163 00164 if (!eventHandled) { 00165 eventHandled = MApplication::x11EventFilter(event); 00166 } 00167 00168 return eventHandled; 00169 }
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:20:42 Doxygen 1.7.1 |
MeeGo Touch |