| 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 00020 #include "mainwindow.h" 00021 #include "home.h" 00022 00023 #include <QGLWidget> 00024 #include <QDBusInterface> 00025 #include <MApplication> 00026 #include <MSceneManager> 00027 #include "x11wrapper.h" 00028 00029 MainWindow *MainWindow::mainWindowInstance = NULL; 00030 QGLContext *MainWindow::openGLContext = NULL; 00031 const QString MainWindow::CONTENT_SEARCH_DBUS_SERVICE = "com.nokia.maemo.meegotouch.ContentSearch"; 00032 const QString MainWindow::CONTENT_SEARCH_DBUS_PATH = "/"; 00033 const QString MainWindow::CONTENT_SEARCH_DBUS_INTERFACE = "com.nokia.maemo.meegotouch.ContentSearchInterface"; 00034 const QString MainWindow::CONTENT_SEARCH_DBUS_METHOD = "launch"; 00035 00036 const QString MainWindow::CALL_UI_DBUS_SERVICE = "com.nokia.telephony.callhistory"; 00037 const QString MainWindow::CALL_UI_DBUS_PATH = "/callhistory"; 00038 const QString MainWindow::CALL_UI_DBUS_INTERFACE = "com.nokia.telephony.callhistory"; 00039 const QString MainWindow::CALL_UI_DBUS_METHOD = "dialer"; 00040 00041 MainWindow::MainWindow(QWidget *parent) : 00042 MWindow(parent), 00043 home(NULL), 00044 externalServiceService(NULL), 00045 externalServicePath(NULL), 00046 externalServiceInterface(NULL), 00047 externalServiceMethod(NULL) 00048 { 00049 mainWindowInstance = this; 00050 if (qgetenv("MEEGOHOME_DESKTOP") != "0") { 00051 // Dont Set the window type to desktop if MEEGOHOME_DESKTOP is set to 0 00052 setAttribute(Qt::WA_X11NetWmWindowTypeDesktop); 00053 } 00054 00055 if (!MApplication::softwareRendering()) { 00056 // Get GL context 00057 QGLWidget *w = dynamic_cast<QGLWidget *>(viewport()); 00058 if (w != NULL) { 00059 openGLContext = const_cast<QGLContext *>(w->context()); 00060 } 00061 } 00062 00063 #ifdef Q_WS_X11 00064 // Visibility change messages are required to make the appVisible() signal work 00065 WId window = winId(); 00066 XWindowAttributes attributes; 00067 Display *display = QX11Info::display(); 00068 X11Wrapper::XGetWindowAttributes(display, window, &attributes); 00069 X11Wrapper::XSelectInput(display, window, attributes.your_event_mask | VisibilityChangeMask); 00070 #endif 00071 00072 // Create Home; the scene manager must be created before this 00073 home = new Home; 00074 sceneManager()->appearSceneWindowNow(home); 00075 00076 setBackgroundBrush(Qt::black); 00077 00078 excludeFromTaskBar(); 00079 } 00080 00081 MainWindow::~MainWindow() 00082 { 00083 mainWindowInstance = NULL; 00084 openGLContext = NULL; 00085 delete home; 00086 } 00087 00088 MainWindow *MainWindow::instance(bool create) 00089 { 00090 if (mainWindowInstance == NULL && create) { 00091 // The static instance variable is set in the constructor 00092 new MainWindow; 00093 } 00094 00095 return mainWindowInstance; 00096 } 00097 00098 QGLContext *MainWindow::glContext() 00099 { 00100 return openGLContext; 00101 } 00102 00103 void MainWindow::excludeFromTaskBar() 00104 { 00105 // Tell the window to not to be shown in the switcher 00106 Atom skipTaskbarAtom = X11Wrapper::XInternAtom(QX11Info::display(), "_NET_WM_STATE_SKIP_TASKBAR", False); 00107 changeNetWmState(true, skipTaskbarAtom); 00108 00109 // Also set the _NET_WM_STATE window property to ensure Home doesn't try to 00110 // manage this window in case the window manager fails to set the property in time 00111 Atom netWmStateAtom = X11Wrapper::XInternAtom(QX11Info::display(), "_NET_WM_STATE", False); 00112 QVector<Atom> atoms; 00113 atoms.append(skipTaskbarAtom); 00114 X11Wrapper::XChangeProperty(QX11Info::display(), internalWinId(), netWmStateAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *)atoms.data(), atoms.count()); 00115 } 00116 00117 void MainWindow::changeNetWmState(bool set, Atom one, Atom two) 00118 { 00119 XEvent e; 00120 e.xclient.type = ClientMessage; 00121 Display *display = QX11Info::display(); 00122 Atom netWmStateAtom = X11Wrapper::XInternAtom(display, "_NET_WM_STATE", FALSE); 00123 e.xclient.message_type = netWmStateAtom; 00124 e.xclient.display = display; 00125 e.xclient.window = internalWinId(); 00126 e.xclient.format = 32; 00127 e.xclient.data.l[0] = set ? 1 : 0; 00128 e.xclient.data.l[1] = one; 00129 e.xclient.data.l[2] = two; 00130 e.xclient.data.l[3] = 0; 00131 e.xclient.data.l[4] = 0; 00132 X11Wrapper::XSendEvent(display, RootWindow(display, x11Info().screen()), FALSE, (SubstructureNotifyMask | SubstructureRedirectMask), &e); 00133 X11Wrapper::XSync(display, FALSE); 00134 } 00135 00136 bool MainWindow::isCallUILaunchingKey(int key) 00137 { 00138 // Numbers, *, + and # will launch the call UI 00139 return ((key >= Qt::Key_0 && key <= Qt::Key_9) || key == Qt::Key_Asterisk || key == Qt::Key_Plus || key == Qt::Key_NumberSign); 00140 } 00141 00142 void MainWindow::keyPressEvent(QKeyEvent *event) 00143 { 00144 int key = event->key(); 00145 if (key < Qt::Key_Escape && !event->modifiers().testFlag(Qt::ControlModifier)) { 00146 // Special keys and CTRL-anything should do nothing 00147 QString keyPresses = event->text(); 00148 if (!keyPresses.isEmpty()) { 00149 // Append keypresses to the presses to be sent 00150 keyPressesToBeSent.append(keyPresses); 00151 00152 if (keyPressesBeingSent.isEmpty()) { 00153 // Select the service to send the keypresses to 00154 if (isCallUILaunchingKey(key)) { 00155 setupExternalService(CALL_UI_DBUS_SERVICE, CALL_UI_DBUS_PATH, CALL_UI_DBUS_INTERFACE, CALL_UI_DBUS_METHOD); 00156 } else { 00157 setupExternalService(CONTENT_SEARCH_DBUS_SERVICE, CONTENT_SEARCH_DBUS_PATH, CONTENT_SEARCH_DBUS_INTERFACE, CONTENT_SEARCH_DBUS_METHOD); 00158 } 00159 00160 // Call the external service 00161 sendKeyPresses(); 00162 } 00163 } 00164 } 00165 } 00166 00167 void MainWindow::closeEvent(QCloseEvent *event) 00168 { 00169 // Don't allow closing the main window 00170 event->ignore(); 00171 } 00172 00173 void MainWindow::setupExternalService(const QString &service, const QString &path, const QString &interface, const QString &method) 00174 { 00175 externalServiceService = &service; 00176 externalServicePath = &path; 00177 externalServiceInterface = &interface; 00178 externalServiceMethod = &method; 00179 } 00180 00181 void MainWindow::sendKeyPresses() 00182 { 00183 // Only one external service launch may be active at a time 00184 if (keyPressesBeingSent.isEmpty() && !keyPressesToBeSent.isEmpty() && externalServiceService != NULL && externalServicePath != NULL && externalServiceInterface != NULL && externalServiceMethod != NULL) { 00185 // Make an asynchronous call to the external service and send the keypresses to be sent 00186 QDBusInterface interface(*externalServiceService, *externalServicePath, *externalServiceInterface, QDBusConnection::sessionBus()); 00187 interface.callWithCallback(*externalServiceMethod, (QList<QVariant>() << keyPressesToBeSent), this, SLOT(markKeyPressesSentAndSendRemainingKeyPresses()), SLOT(markKeyPressesNotSent())); 00188 00189 // Keypresses that need to be sent are now being sent 00190 keyPressesBeingSent = keyPressesToBeSent; 00191 keyPressesToBeSent.clear(); 00192 } 00193 } 00194 00195 void MainWindow::markKeyPressesSentAndSendRemainingKeyPresses() 00196 { 00197 // The keypresses that were being sent have now been sent 00198 keyPressesBeingSent.clear(); 00199 00200 // Send the remaining keypresses still to be sent (if any) 00201 sendKeyPresses(); 00202 } 00203 00204 void MainWindow::markKeyPressesNotSent() 00205 { 00206 // Since the external service didn't launch prepend the sent keypresses to the keypresses to be sent but don't retry 00207 keyPressesToBeSent.prepend(keyPressesBeingSent); 00208 keyPressesBeingSent.clear(); 00209 }
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:20:42 Doxygen 1.7.1 |
MeeGo Touch |