menu or some application dialog is open too long.
Added doxygen comment for setAvatarImage
Reviewed by: Jussi Laitinen
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <QX11Info>
+#include <QDebug>
+
+#include "application.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#ifdef Q_WS_HILDON
+ #define ACTIVE_APP_ATOM "_MB_CURRENT_APP_WINDOW"
+#else
+ #define ACTIVE_APP_ATOM "_NET_ACTIVE_WINDOW"
+#endif
+
+Application::Application(int &argc, char **argv)
+ : QApplication(argc, argv),
+ m_topmost(false)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void Application::registerWindow(WId window)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_windows.append(window);
+}
+
+void Application::unregisterWindow(WId window)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_windows.removeOne(window);
+}
+
+WId Application::activeDesktopWindow(Display *display, WId rootWindow)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ Atom realType;
+ int format, status;
+ unsigned long n, extra;
+ unsigned char *data = 0;
+ WId activeWindow;
+ Atom atom = XInternAtom(display, ACTIVE_APP_ATOM, false);
+
+ status = XGetWindowProperty(display, rootWindow, atom, 0L, 16L,
+ 0, XA_WINDOW, &realType, &format,
+ &n, &extra, &data);
+ if (status == Success && realType == XA_WINDOW &&
+ format == 32 && n == 1 && data != NULL)
+ activeWindow = ((WId*)data)[0];
+ else
+ activeWindow = None;
+
+ if (data != 0)
+ XFree(data);
+
+ return activeWindow;
+}
+
+bool Application::x11EventFilter(XEvent *event)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ static Qt::HANDLE rootWindow = QX11Info::appRootWindow();
+ static Atom activeAppAtom = XInternAtom(QX11Info::display(),
+ ACTIVE_APP_ATOM, false);
+
+ if (event->type == PropertyNotify) {
+ XPropertyEvent *pevent = (XPropertyEvent*)event;
+ if (pevent->window == rootWindow) {
+ if (pevent->atom == activeAppAtom) {
+ WId activeWindow = activeDesktopWindow(pevent->display,
+ rootWindow);
+
+ if(m_topmost != m_windows.contains(activeWindow)) {
+ m_topmost = !m_topmost;
+ qWarning() << "Application is topmost " << m_topmost;
+ emit topmostChanged(!m_topmost);
+ }
+ }
+ }
+ }
+ return false;
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#ifndef APPLICATION_H
+#define APPLICATION_H
+
+#include <QApplication>
+
+/**
+* @brief Application class is a subclass of QApplication
+*
+* This class handles X11 events
+*/
+class Application : public QApplication
+{
+ Q_OBJECT
+public:
+
+ /**
+ * @brief Constructor
+ *
+ * @param argc number of arguments
+ * @param argv arguments
+ */
+ Application(int &argc, char **argv);
+
+ /**
+ * @brief Registers window
+ *
+ * @param wId window id
+ */
+ void registerWindow(WId wId);
+
+ /**
+ * @brief Unregisters window
+ *
+ * @param wId window id
+ */
+ void unregisterWindow(WId wId);
+
+private:
+
+ /**
+ * @brief Return active window
+ *
+ * @param display display
+ * @param rootWindow rootwindow
+ * @return WId window id
+ */
+ WId activeDesktopWindow(Display *display, WId rootWindow);
+
+ /**
+ * @brief Event filter for window
+ *
+ * @param event window event
+ * @return bool Return true if you want to stop the event from being processed.
+ * Return false for normal event dispatching
+ */
+ bool x11EventFilter(XEvent *event);
+
+signals:
+
+ /**
+ * @brief Signals when window state is changed
+ *
+ * @param topmost true for topmost either false
+ */
+ void topmostChanged(bool topmost);
+
+private:
+
+ bool m_topmost; ///< Flag for topmost
+
+ QList<WId> m_windows; ///< List of window ids
+};
+
+#endif // APPLICATION_H
#include <QMessageBox>
#include <QNetworkReply>
+#ifdef Q_WS_MAEMO_5
+#include "application.h"
+#endif
#include "common.h"
#include "facebookservice/facebookauthentication.h"
#include "gps/gpsposition.h"
const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
-SituareEngine::SituareEngine(QMainWindow *parent)
- : QObject(parent),
- m_autoCenteringEnabled(false),
+SituareEngine::SituareEngine()
+ : m_autoCenteringEnabled(false),
m_automaticUpdateFirstStart(true),
m_automaticUpdateRequest(false),
m_userMoved(false),
m_lastUpdatedGPSPosition(QPointF())
{
qDebug() << __PRETTY_FUNCTION__;
+
m_ui = new MainWindow;
m_ui->updateItemVisibility();
+#ifdef Q_WS_MAEMO_5
+ m_app = static_cast<Application *>(qApp);
+ m_app->registerWindow(m_ui->winId());
+
+ connect(m_app, SIGNAL(topmostChanged(bool)),
+ this, SLOT(enablePowerSave(bool)));
+#endif
+
m_networkAccessManager = NetworkAccessManager::instance();
// build MapEngine
initializeGpsAndAutocentering();
m_mce = new MCE(this);
- connect(m_mce, SIGNAL(displayStateChanged(bool)), this, SLOT(displayStateChanged(bool)));
+ connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(enablePowerSave(bool)));
}
SituareEngine::~SituareEngine()
m_ui->buildInformationBox(tr("Auto centering disabled"));
}
-void SituareEngine::displayStateChanged(bool enabled)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_gps->enablePowerSave(!enabled);
-
- if (m_autoCenteringEnabled)
- enableAutoCentering(enabled);
-}
-
void SituareEngine::enableAutoCentering(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
}
}
+void SituareEngine::enablePowerSave(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_gps->enablePowerSave(enabled);
+
+ if(m_autoCenteringEnabled)
+ m_mapEngine->setAutoCentering(!enabled);
+}
+
void SituareEngine::error(const int context, const int error)
{
qDebug() << __PRETTY_FUNCTION__;
#include <QTime>
#include <QPointF>
-class QMainWindow;
-
+#ifdef Q_WS_MAEMO_5
+class Application;
+#endif
class FacebookAuthentication;
class FacebookCredentials;
class GPSPosition;
*
* @param parent
*/
- SituareEngine(QMainWindow *parent = 0);
+ SituareEngine();
/**
* @brief Destructor
void disableAutoCentering();
/**
- * @brief Slot for display state changed.
- *
- * @param enabled true if enabled, false otherwise
- */
- void displayStateChanged(bool enabled);
-
- /**
* @brief Slot for auto centering enabling.
*
* Calls gps to send last known position
void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
/**
+ * @brief Slot for enabling power saving.
+ *
+ * @param enabled true if enabled, false otherwise
+ */
+ void enablePowerSave(bool enabled);
+
+ /**
* @brief Slot to intercept signal when user's/friend's image is downloaded
*
* @param user Instance of user/friend
bool m_automaticUpdateRequest; ///< Flag for automatic update request
bool m_userMoved; ///< Flag for user move
-
+#ifdef Q_WS_MAEMO_5
+ Application *m_app; ///< Pointer to Application
+#endif
FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
GPSPosition *m_gps; ///< Instance of the gps position
MainWindow *m_ui; ///< Instance of the MainWindow UI
QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
QPointF m_lastUpdatedGPSPosition; ///< Last updated GPS position
+
};
#endif // ENGINE_H
******************************************************************************/
signals:
/**
- * @brief Signal for the display state change.
+ * @brief Signal for the display off.
*
- * @param on true if on, false if off
+ * @param on true if off, false if on
*/
- void displayStateChanged(bool on);
+ void displayOff(bool off);
/*******************************************************************************
* DATA MEMBERS
if (!state.isEmpty()) {
if (state == MCE_DISPLAY_ON_STRING) {
m_displayOn = true;
- emit m_parent->displayStateChanged(true);
+ emit m_parent->displayOff(false);
}
else if (state == MCE_DISPLAY_OFF_STRING) {
m_displayOn = false;
- emit m_parent->displayStateChanged(false);
+ emit m_parent->displayOff(true);
}
}
}
#include "gpspositionprivateliblocation.h"
#include "liblocationwrapper.h"
-const int POWER_SAVE_START_DELAY_MS = 1000*10;
+const int POWER_SAVE_START_DELAY_MS = 1000*60; // 60 seconds
GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
: QObject(parent),
#include <QTranslator>
#include <QLocale>
#include "engine/engine.h"
+#ifdef Q_WS_MAEMO_5
+#include "application.h"
+#endif
int main(int argc, char *argv[])
{
+#ifdef Q_WS_MAEMO_5
+ Application a(argc, argv);
+#else
QApplication a(argc, argv);
+#endif
+ SituareEngine engine;
// QTranslator translator;
// bool loaded = translator.load(":/res/languages/situare_" + QLocale::system().name());
// QString locale = QLocale::system().name();
// qDebug() << "Localization" << locale << "loaded:" << loaded;
- SituareEngine engine;
- int appRet = a.exec();
- return appRet;
+ return a.exec();
}
../languages.qrc
TRANSLATIONS += ../res/languages/situare_fi.ts
SOURCES += main.cpp \
+ application.cpp \
engine/engine.cpp \
facebookservice/facebookauthentication.cpp \
facebookservice/facebookcredentials.cpp \
user/user.cpp \
ui/fullscreenbutton.cpp \
engine/mce.cpp
-HEADERS += common.h \
+HEADERS += application.h \
+ common.h \
engine/engine.h \
facebookservice/facebookauthentication.h \
facebookservice/facebookcommon.h \
*/
void setData(User *user);
+ /**
+ * @brief Sets avatar image for this item.
+ *
+ * @param image image
+ */
void setAvatarImage(const QPixmap &image);
private: