Copied needed bits blindly from harmattan
authorMohammed Sameer <msameer@foolab.org>
Sun, 4 Aug 2013 16:36:29 +0000 (19:36 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sun, 4 Aug 2013 16:36:29 +0000 (19:36 +0300)
15 files changed:
src/sailfish/batteryinfo.cpp [new file with mode: 0644]
src/sailfish/batteryinfo.h [new file with mode: 0644]
src/sailfish/compass.cpp [new file with mode: 0644]
src/sailfish/compass.h [new file with mode: 0644]
src/sailfish/devicekeys.cpp [new file with mode: 0644]
src/sailfish/devicekeys.h [new file with mode: 0644]
src/sailfish/displaystate.cpp [new file with mode: 0644]
src/sailfish/displaystate.h [new file with mode: 0644]
src/sailfish/fsmonitor.cpp [new file with mode: 0644]
src/sailfish/fsmonitor.h [new file with mode: 0644]
src/sailfish/mountprotector.cpp [new file with mode: 0644]
src/sailfish/mountprotector.h [new file with mode: 0644]
src/sailfish/orientation.cpp [new file with mode: 0644]
src/sailfish/orientation.h [new file with mode: 0644]
src/sailfish/sailfish.pri

diff --git a/src/sailfish/batteryinfo.cpp b/src/sailfish/batteryinfo.cpp
new file mode 100644 (file)
index 0000000..95ffe19
--- /dev/null
@@ -0,0 +1,88 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "batteryinfo.h"
+#include <qmbattery.h>
+#if defined(QT4)
+#include <QDeclarativeInfo>
+#elif defined(QT5)
+#include <QQmlInfo>
+#endif
+
+BatteryInfo::BatteryInfo(QObject *parent) :
+  QObject(parent), m_battery(0) {
+
+}
+
+BatteryInfo::~BatteryInfo() {
+  setActive(false);
+}
+
+bool BatteryInfo::isCharging() const {
+  if (!m_battery) {
+    qmlInfo(this) << "BatteryInfo has to be activated first";
+    return false;
+  }
+
+  if (m_battery->getChargingState() == MeeGo::QmBattery::StateCharging) {
+    return true;
+  }
+
+  return false;
+}
+
+bool BatteryInfo::isCritical() const {
+  if (!m_battery) {
+    qmlInfo(this) << "BatteryInfo has to be activated first";
+    return true;
+  }
+
+  MeeGo::QmBattery::BatteryState state = m_battery->getBatteryState();
+
+  if (state == MeeGo::QmBattery::StateOK || state == MeeGo::QmBattery::StateFull) {
+    return false;
+  }
+
+  return true;
+}
+
+bool BatteryInfo::isActive() const {
+  return m_battery != 0;
+}
+
+void BatteryInfo::setActive(bool active) {
+  if (isActive() == active) {
+    return;
+  }
+
+  if (!active) {
+    m_battery->deleteLater();
+    m_battery = 0;
+  }
+  else {
+    m_battery = new MeeGo::QmBattery(this);
+    QObject::connect(m_battery, SIGNAL(batteryStateChanged(MeeGo::QmBattery::BatteryState)),
+                    this, SIGNAL(chargingChanged()));
+    QObject::connect(m_battery, SIGNAL(chargingStateChanged(MeeGo::QmBattery::ChargingState)),
+                    this, SIGNAL(chargingChanged()));
+  }
+
+  emit activeChanged();
+}
diff --git a/src/sailfish/batteryinfo.h b/src/sailfish/batteryinfo.h
new file mode 100644 (file)
index 0000000..ac673ad
--- /dev/null
@@ -0,0 +1,58 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef BATTERY_INFO_H
+#define BATTERY_INFO_H
+
+#include <QObject>
+
+namespace MeeGo {
+  class QmBattery;
+};
+
+class BatteryInfo : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(bool charging READ isCharging NOTIFY chargingChanged);
+  Q_PROPERTY(bool critical READ isCritical NOTIFY criticalChanged);
+  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+
+public:
+  BatteryInfo(QObject *parent = 0);
+  ~BatteryInfo();
+
+  bool isCharging() const;
+  bool isCritical() const;
+
+  bool isActive() const;
+  void setActive(bool active);
+
+signals:
+  void chargingChanged();
+  void criticalChanged();
+  void activeChanged();
+
+private:
+  MeeGo::QmBattery *m_battery;
+};
+
+#endif /* BATTERY_INFO_H */
diff --git a/src/sailfish/compass.cpp b/src/sailfish/compass.cpp
new file mode 100644 (file)
index 0000000..5a2482c
--- /dev/null
@@ -0,0 +1,90 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "compass.h"
+#include <qmcompass.h>
+#include <QDebug>
+
+Compass::Compass(QObject *parent) :
+  QObject(parent),
+  m_compass(new MeeGo::QmCompass(this)),
+  m_degree(-1),
+  m_valid(false) {
+
+  m_compass->setUseDeclination(true);
+
+  QObject::connect(m_compass, SIGNAL(dataAvailable(const MeeGo::QmCompassReading&)),
+                  this, SLOT(dataAvailable(const MeeGo::QmCompassReading&)));
+
+  if (m_compass->requestSession(MeeGo::QmSensor::SessionTypeListen)
+      == MeeGo::QmSensor::SessionTypeNone) {
+    qDebug() << "Failed to get listen session:" << m_compass->lastError();
+  }
+}
+
+Compass::~Compass() {
+  m_compass->stop();
+}
+
+bool Compass::isActive() const {
+  return m_compass->isRunning();
+}
+
+void Compass::setActive(bool active) {
+  if (active == isActive()) {
+    return;
+  }
+
+  if (active) {
+    m_compass->start();
+  }
+  else {
+    m_compass->stop();
+
+    m_valid = false;
+    emit directionValidChanged();
+  }
+
+  emit activeChanged();
+}
+
+int Compass::direction() const {
+  return m_degree;
+}
+
+bool Compass::isDirectionValid() const {
+  return m_valid;
+}
+
+void Compass::dataAvailable(const MeeGo::QmCompassReading& value) {
+  bool degreeChanged = (m_degree != value.degrees);
+  bool validityChanged = m_valid != (value.level >= 2);
+
+  m_degree = value.degrees;
+  m_valid = (value.level >= 2);
+
+  if (validityChanged) {
+    emit directionValidChanged();
+  }
+
+  if (degreeChanged) {
+    emit directionChanged();
+  }
+}
diff --git a/src/sailfish/compass.h b/src/sailfish/compass.h
new file mode 100644 (file)
index 0000000..4547829
--- /dev/null
@@ -0,0 +1,64 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef COMPASS_H
+#define COMPASS_H
+
+#include <QObject>
+
+namespace MeeGo {
+  class QmCompass;
+  class QmCompassReading;
+};
+
+class Compass : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+  Q_PROPERTY(int direction READ direction NOTIFY directionChanged);
+  Q_PROPERTY(bool directionValid READ isDirectionValid NOTIFY directionValidChanged);
+
+public:
+  Compass(QObject *parent = 0);
+  ~Compass();
+
+  bool isActive() const;
+  void setActive(bool active);
+
+  int direction() const;
+  bool isDirectionValid() const;
+
+signals:
+  void activeChanged();
+  void directionChanged();
+  void directionValidChanged();
+
+private slots:
+  void dataAvailable(const MeeGo::QmCompassReading& value);
+
+private:
+  MeeGo::QmCompass *m_compass;
+  int m_degree;
+  bool m_valid;
+};
+
+#endif /* COMPASS_H */
diff --git a/src/sailfish/devicekeys.cpp b/src/sailfish/devicekeys.cpp
new file mode 100644 (file)
index 0000000..7025805
--- /dev/null
@@ -0,0 +1,108 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "devicekeys.h"
+#include <QDebug>
+
+DeviceKeys::DeviceKeys(QObject *parent) :
+  QObject(parent),
+  m_keys(0),
+  m_repeating(true) {
+
+}
+
+DeviceKeys::~DeviceKeys() {
+  setActive(false);
+}
+
+bool DeviceKeys::isActive() const {
+  return m_keys != 0;
+}
+
+void DeviceKeys::setActive(bool active) {
+  if (active == isActive()) {
+    return;
+  }
+
+  if (!active) {
+    m_keys->deleteLater();
+    m_keys = 0;
+    m_stats.clear();
+  }
+  else {
+    m_keys = new MeeGo::QmKeys(this);
+    QObject::connect(m_keys, SIGNAL(keyEvent(MeeGo::QmKeys::Key, MeeGo::QmKeys::State)),
+                    this, SLOT(keyEvent(MeeGo::QmKeys::Key, MeeGo::QmKeys::State)));
+  }
+
+  emit activeChanged();
+}
+
+void DeviceKeys::keyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) {
+  if (!setStats(key, state)) {
+    return;
+  }
+
+  if (key == MeeGo::QmKeys::VolumeUp) {
+    if (state == MeeGo::QmKeys::KeyUp) {
+      emit volumeUpReleased();
+    }
+    else if (state == MeeGo::QmKeys::KeyDown) {
+      emit volumeUpPressed();
+    }
+  }
+  else if (key == MeeGo::QmKeys::VolumeDown) {
+    if (state == MeeGo::QmKeys::KeyUp) {
+      emit volumeDownReleased();
+    }
+    else if (state == MeeGo::QmKeys::KeyDown) {
+      emit volumeDownPressed();
+    }
+  }
+}
+
+bool DeviceKeys::setStats(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) {
+  if (m_repeating) {
+    return true;
+  }
+
+  if (!m_stats.contains(key)) {
+    m_stats.insert(key, state);
+    return true;
+  }
+
+  if (m_stats[key] != state) {
+    m_stats[key] = state;
+    return true;
+  }
+
+  return false;
+}
+
+bool DeviceKeys::isRepeating() {
+  return m_repeating;
+}
+
+void DeviceKeys::doRepeat(bool repeat) {
+  if (repeat != m_repeating) {
+    m_repeating = repeat;
+    emit repeatChanged();
+  }
+}
diff --git a/src/sailfish/devicekeys.h b/src/sailfish/devicekeys.h
new file mode 100644 (file)
index 0000000..3478132
--- /dev/null
@@ -0,0 +1,65 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef DEVICE_KEYS_H
+#define DEVICE_KEYS_H
+
+#include <QObject>
+#include <qmkeys.h>
+#include <QMap>
+
+class DeviceKeys : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+  Q_PROPERTY(bool repeat READ isRepeating WRITE doRepeat NOTIFY repeatChanged);
+
+public:
+  DeviceKeys(QObject *parent = 0);
+  ~DeviceKeys();
+
+  bool isActive() const;
+  void setActive(bool active);
+
+  bool isRepeating();
+  void doRepeat(bool repeat);
+
+signals:
+  void activeChanged();
+  void volumeUpPressed();
+  void volumeUpReleased();
+  void volumeDownPressed();
+  void volumeDownReleased();
+  void repeatChanged();
+
+private slots:
+  void keyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state);
+
+private:
+  bool setStats(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state);
+
+  MeeGo::QmKeys *m_keys;
+  QMap<MeeGo::QmKeys::Key, MeeGo::QmKeys::State> m_stats;
+  bool m_repeating;
+};
+
+#endif /* DEVICE_KEYS_H */
diff --git a/src/sailfish/displaystate.cpp b/src/sailfish/displaystate.cpp
new file mode 100644 (file)
index 0000000..cb612bc
--- /dev/null
@@ -0,0 +1,71 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "displaystate.h"
+#include <qmdisplaystate.h>
+#include <QTimer>
+#include <QDebug>
+
+DisplayState::DisplayState(QObject *parent) :
+  QObject(parent), m_state(new MeeGo::QmDisplayState(this)), m_timer(new QTimer(this)) {
+
+  m_timer->setSingleShot(false);
+  m_timer->setInterval(50 * 1000);
+
+  QObject::connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
+}
+
+DisplayState::~DisplayState() {
+  setInhibitDim(false);
+}
+
+bool DisplayState::isDimInhibited() const {
+  return m_timer->isActive();
+}
+
+void DisplayState::setInhibitDim(bool inhibit) {
+  if (m_timer->isActive() == inhibit) {
+    return;
+  }
+
+  if (!inhibit) {
+    if (!m_state->cancelBlankingPause()) {
+      qWarning() << "Failed to cancel display dimming!";
+    }
+
+    m_timer->stop();
+  }
+  else {
+    if (!m_state->setBlankingPause()) {
+      qWarning() << "Failed to inhibit display dimming!";
+      return;
+    }
+
+    m_timer->start();
+  }
+
+  emit inhibitDimChanged();
+}
+
+void DisplayState::timeout() {
+  if (!m_state->setBlankingPause()) {
+    qWarning() << "Failed to inhibit display dimming!";
+  }
+}
diff --git a/src/sailfish/displaystate.h b/src/sailfish/displaystate.h
new file mode 100644 (file)
index 0000000..4fd527e
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef DISPLAY_STATE_H
+#define DISPLAY_STATE_H
+
+#include <QObject>
+
+class QTimer;
+namespace MeeGo {
+  class QmDisplayState;
+};
+
+class DisplayState : public QObject {
+  Q_OBJECT
+  Q_PROPERTY(bool inhibitDim READ isDimInhibited WRITE setInhibitDim NOTIFY inhibitDimChanged);
+
+public:
+  DisplayState(QObject *parent = 0);
+  ~DisplayState();
+
+  bool isDimInhibited() const;
+  void setInhibitDim(bool inhibit);
+
+signals:
+  void inhibitDimChanged();
+
+private slots:
+  void timeout();
+
+private:
+  MeeGo::QmDisplayState *m_state;
+  QTimer *m_timer;
+};
+
+#endif /* DISPLAY_STATE_H */
diff --git a/src/sailfish/fsmonitor.cpp b/src/sailfish/fsmonitor.cpp
new file mode 100644 (file)
index 0000000..1b812bf
--- /dev/null
@@ -0,0 +1,71 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "fsmonitor.h"
+#include <qmusbmode.h>
+#include <sys/statvfs.h>
+#include <cstdio>
+
+#define MIN_SPACE 100 * 1024 * 1024 // 100 MB
+
+FSMonitor::FSMonitor(QObject *parent) :
+  QObject(parent), m_mode(new MeeGo::QmUSBMode(this)) {
+
+  QObject::connect(m_mode, SIGNAL(modeChanged(MeeGo::QmUSBMode::Mode)),
+                  this, SLOT(modeChanged()));
+
+  m_available =
+    m_mode->mountStatus(MeeGo::QmUSBMode::DocumentDirectoryMount)
+    .testFlag(MeeGo::QmUSBMode::ReadWriteMount);
+}
+
+FSMonitor::~FSMonitor() {
+
+}
+
+bool FSMonitor::isAvailable() const {
+  return m_available;
+}
+
+void FSMonitor::setAvailable(bool available) {
+  if (m_available != available) {
+    m_available = available;
+    emit availabilityChanged();
+  }
+}
+
+void FSMonitor::modeChanged() {
+  setAvailable(m_mode->mountStatus(MeeGo::QmUSBMode::DocumentDirectoryMount)
+              .testFlag(MeeGo::QmUSBMode::ReadWriteMount));
+}
+
+bool FSMonitor::hasFreeSpace(const QString& path) {
+  struct statvfs buf;
+
+  if (statvfs(path.toLocal8Bit().data(), &buf) == -1) {
+    std::perror("statvfs");
+    return false;
+  }
+
+  // If the user has a lot of free space (8 GB for example)
+  // then we will overflow the unsigned long int thus we use a 64 bits "int"
+  quint64 freeSpace = (quint64)buf.f_bsize * (quint64)buf.f_bavail;
+  return (freeSpace >= MIN_SPACE);
+}
diff --git a/src/sailfish/fsmonitor.h b/src/sailfish/fsmonitor.h
new file mode 100644 (file)
index 0000000..8195106
--- /dev/null
@@ -0,0 +1,57 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef FS_MONITOR_H
+#define FS_MONITOR_H
+
+#include <QObject>
+
+namespace MeeGo {
+  class QmUSBMode;
+};
+
+class FSMonitor : public QObject {
+  Q_OBJECT
+  Q_PROPERTY(bool available READ isAvailable NOTIFY availabilityChanged)
+
+public:
+  FSMonitor(QObject *parent = 0);
+  ~FSMonitor();
+
+  bool isAvailable() const;
+
+  void setAvailable(bool available);
+
+  Q_INVOKABLE bool hasFreeSpace(const QString& path);
+
+signals:
+  void availabilityChanged();
+
+private slots:
+  void modeChanged();
+
+private:
+  bool m_available;
+  MeeGo::QmUSBMode *m_mode;
+};
+
+#endif /* FS_MONITOR_H */
diff --git a/src/sailfish/mountprotector.cpp b/src/sailfish/mountprotector.cpp
new file mode 100644 (file)
index 0000000..ad7d135
--- /dev/null
@@ -0,0 +1,81 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "mountprotector.h"
+#include <QDir>
+#include <QTemporaryFile>
+#if defined(QT4)
+#include <QDeclarativeInfo>
+#elif defined(QT5)
+#include <QQmlInfo>
+#endif
+
+MountProtector::MountProtector(QObject *parent) :
+  QObject(parent), m_file(0) {
+
+}
+
+MountProtector::~MountProtector() {
+  unlock();
+}
+
+QString MountProtector::path() const {
+  return m_path;
+}
+
+void MountProtector::setPath(const QString& path) {
+  if (m_path != path) {
+    m_path = path;
+    emit pathChanged();
+  }
+}
+
+bool MountProtector::lock() {
+  if (m_file) {
+    return true;
+  }
+
+  if (m_path.isEmpty()) {
+    return false;
+  }
+
+  QString path = QString("%1%2.cameraplus_tmp_XXXXXX").arg(m_path).arg(QDir::separator());
+  m_file = new QTemporaryFile(path);
+  m_file->setAutoRemove(true);
+  if (!m_file->open()) {
+    qmlInfo(this) << "Failed to lock" << m_file->errorString();
+    delete m_file;
+    m_file = 0;
+    return false;
+  }
+
+  if (!QFile::remove(m_file->fileName())) {
+    qmlInfo(this) << "Failed to remove temporarily file" << m_file->fileName();
+  }
+
+  return true;
+}
+
+void MountProtector::unlock() {
+  if (m_file) {
+    delete m_file;
+    m_file = 0;
+  }
+}
diff --git a/src/sailfish/mountprotector.h b/src/sailfish/mountprotector.h
new file mode 100644 (file)
index 0000000..4449e78
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef MOUNT_PROTECTOR_H
+#define MOUNT_PROTECTOR_H
+
+#include <QObject>
+class QTemporaryFile;
+
+class MountProtector : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged);
+
+public:
+  MountProtector(QObject *parent = 0);
+  ~MountProtector();
+
+  QString path() const;
+  void setPath(const QString& path);
+
+  Q_INVOKABLE bool lock();
+
+public slots:
+  void unlock();
+
+signals:
+  void pathChanged();
+
+private:
+  QString m_path;
+  QTemporaryFile *m_file;
+};
+
+#endif /* MOUNT_PROTECTOR_H */
diff --git a/src/sailfish/orientation.cpp b/src/sailfish/orientation.cpp
new file mode 100644 (file)
index 0000000..c439950
--- /dev/null
@@ -0,0 +1,100 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "orientation.h"
+#include <qmorientation.h>
+#include <QDebug>
+
+Orientation::Orientation(QObject *parent) :
+  QObject(parent),
+  m_orientation(new MeeGo::QmOrientation(this)),
+  m_direction(Unknown) {
+
+  QObject::connect(m_orientation, SIGNAL(orientationChanged(const MeeGo::QmOrientationReading&)),
+                  this, SLOT(onOrientationChanged(const MeeGo::QmOrientationReading&)));
+
+  if (m_orientation->requestSession(MeeGo::QmSensor::SessionTypeListen)
+      == MeeGo::QmSensor::SessionTypeNone) {
+    qDebug() << "Failed to get listen session:" << m_orientation->lastError();
+  }
+}
+
+Orientation::~Orientation() {
+  m_orientation->stop();
+}
+
+bool Orientation::isActive() const {
+  return m_orientation->isRunning();
+}
+
+void Orientation::setActive(bool active) {
+  if (active == isActive()) {
+    return;
+  }
+
+  if (active) {
+    m_orientation->start();
+    onOrientationChanged(m_orientation->orientation());
+  }
+  else {
+    m_orientation->stop();
+    m_direction = Unknown;
+
+    emit orientationChanged();
+  }
+
+  emit activeChanged();
+}
+
+Orientation::OrientationDirection Orientation::orientation() const {
+  return m_direction;
+}
+
+void Orientation::onOrientationChanged(const MeeGo::QmOrientationReading& value) {
+  OrientationDirection direction = Unknown;
+
+  switch (value.value) {
+  case MeeGo::QmOrientation::BottomUp:
+    direction = InvertedLandscape;
+    break;
+
+  case MeeGo::QmOrientation::BottomDown:
+    direction = Landscape;
+    break;
+
+  case MeeGo::QmOrientation::LeftUp:
+    direction = Portrait;
+    break;
+
+  case MeeGo::QmOrientation::RightUp:
+    direction = InvertedPortrait;
+    break;
+
+  default:
+    direction = Unknown;
+    break;
+  }
+
+  if (direction != m_direction) {
+    m_direction = direction;
+
+    emit orientationChanged();
+  }
+}
diff --git a/src/sailfish/orientation.h b/src/sailfish/orientation.h
new file mode 100644 (file)
index 0000000..183ffd1
--- /dev/null
@@ -0,0 +1,71 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef ORIENTATION_H
+#define ORIENTATION_H
+
+#include <QObject>
+
+namespace MeeGo {
+  class QmOrientation;
+  class QmOrientationReading;
+};
+
+class Orientation : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+  Q_PROPERTY(OrientationDirection orientation READ orientation NOTIFY orientationChanged);
+
+  Q_ENUMS(OrientationDirection);
+
+public:
+  Orientation(QObject *parent = 0);
+  ~Orientation();
+
+  // Make sure they are synced with metadata.
+  typedef enum {
+    Unknown = -1,
+    Landscape = 0,
+    Portrait = 1,
+    InvertedLandscape = 2,
+    InvertedPortrait = 3
+  } OrientationDirection;
+
+  bool isActive() const;
+  void setActive(bool active);
+
+  OrientationDirection orientation() const;
+
+signals:
+  void activeChanged();
+  void orientationChanged();
+
+private slots:
+  void onOrientationChanged(const MeeGo::QmOrientationReading& value);
+
+private:
+  MeeGo::QmOrientation *m_orientation;
+  OrientationDirection m_direction;
+};
+
+#endif /* ORIENTATION_H */
index 925c023..23d4380 100644 (file)
@@ -3,5 +3,24 @@ INCLUDEPATH += sailfish .
 
 PKGCONFIG += Qt5SystemInfo Qt5Location
 
-HEADERS += sailfish/soundvolumecontrol.h sailfish/deviceinfo.h sailfish/geocode.h
-SOURCES += sailfish/soundvolumecontrol.cpp sailfish/deviceinfo.cpp sailfish/geocode.cpp
+HEADERS += sailfish/soundvolumecontrol.h \
+           sailfish/deviceinfo.h \
+           sailfish/geocode.h \
+           sailfish/displaystate.h \
+           sailfish/fsmonitor.h \
+           sailfish/compass.h \
+           sailfish/orientation.h \
+           sailfish/mountprotector.h \
+           sailfish/batteryinfo.h \
+           sailfish/devicekeys.h
+
+SOURCES += sailfish/soundvolumecontrol.cpp \
+           sailfish/deviceinfo.cpp \
+           sailfish/geocode.cpp \
+           sailfish/displaystate.cpp \
+           sailfish/fsmonitor.cpp \
+           sailfish/compass.cpp \
+           sailfish/orientation.cpp \
+           sailfish/mountprotector.cpp \
+           sailfish/batteryinfo.cpp \
+           sailfish/devicekeys.cpp