Merge branch 'vibrationrecovery' into harmattan
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 26 Sep 2011 20:00:23 +0000 (23:00 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 27 Sep 2011 16:08:49 +0000 (19:08 +0300)
Vibration works again (did not work before with the beta2 firmware).
This time real vibration, not just a "tak tak" sound.

Conflicts:
seascene.cpp

ghostsoverboard.conf [new file with mode: 0644]
ghostsoverboard.pro
seascene.cpp
seascene.h
ship.cpp
ship.h

diff --git a/ghostsoverboard.conf b/ghostsoverboard.conf
new file mode 100644 (file)
index 0000000..fb92295
--- /dev/null
@@ -0,0 +1,2 @@
+[classify gaming]
+/opt/ghostsoverboard/bin/ghostsoverboard
index 039d296..f546741 100644 (file)
@@ -101,4 +101,12 @@ unix:!symbian:!maemo5 {
 }
 
 
+unix:!symbian:!maemo5 {
+    resourcepolicy.files = ghostsoverboard.conf
+    resourcepolicy.path = /usr/share/policy/etc/syspart.conf.d
+    INSTALLS += resourcepolicy
+
 
+    CONFIG +=  link_pkgconfig
+    PKGCONFIG += libresourceqt1
+}
index c957570..de57ba4 100644 (file)
@@ -35,6 +35,7 @@
 #include <QSettings>
 #include <QPixmap>
 
+
 const QString ghostImageFilename_ = ":/pix/aave.png";
 const QString rockImageFilename_ =":/pix/kari.png";
 const QString octopusImageFilename_= ":/pix/tursas.png";
@@ -105,6 +106,8 @@ SeaScene::SeaScene(QObject *parent) :
     connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()),Qt::QueuedConnection);
 
 
+
+
     pVibrateAction_ = new QAction(tr("Vibration effects"),this);
     pVibrateAction_->setCheckable(true);
     connect(pVibrateAction_,SIGNAL(toggled(bool)),this,SLOT(vibrationActivate(bool)));
@@ -121,6 +124,20 @@ SeaScene::SeaScene(QObject *parent) :
     autopauseTimer.setInterval(15*60*1000);
     connect(&autopauseTimer,SIGNAL(timeout()),this,SLOT(turnPauseOn()));
 
+    vibrationAllowed_ = false;
+    pResourceSet_ = new ResourcePolicy::ResourceSet("game",this);
+    ResourcePolicy::VibraResource * pVibraResource = new ResourcePolicy::VibraResource();
+    pVibraResource->setOptional(false); //The only resource of the set, so no sense for it to be optional
+    pResourceSet_->addResourceObject(pVibraResource);
+
+    connect(pResourceSet_,SIGNAL(resourcesGranted(const QList< ResourcePolicy::ResourceType >)),this,SLOT(resourcesAvailable()));
+    connect(pResourceSet_,SIGNAL(lostResources()),this,SLOT(resourcesLost()));
+
+    //To test whether resources were succesfully asked but not given
+    connect(pResourceSet_,SIGNAL(resourcesDenied()),this,SLOT(resourcesLost()));
+    pResourceSet_->setAlwaysReply();
+
+    pResourceSet_->acquire();
 
 }
 
@@ -250,6 +267,10 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
     connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
     connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
     connect(this,SIGNAL(vibrationActivated(bool)),pShip,SLOT(setVibrationActivate(bool)));
+    if (vibrationAllowed_)
+        pShip->allowVibration(); //Vibration is disallowed by default so only allowing needs to be done explicitly
+    connect(pResourceSet_,SIGNAL(resourcesGranted(const QList< ResourcePolicy::ResourceType >)),pShip,SLOT(allowVibration()));
+    connect(pResourceSet_,SIGNAL(lostResources()),pShip,SLOT(disallowVibration()));
     pShip->startMoving();
     movingItems_.append(pShip);
     connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
@@ -680,6 +701,7 @@ void SeaScene::restartLevel()
 
     vibrationActivate(pVibrateAction_->isChecked());  //Vibration effects are lost without this
    // qDebug() << pVibrateAction_->isChecked();
+
     autopauseTimer.start();  //reset counting towards autopause
 
 
@@ -866,6 +888,7 @@ void SeaScene::createLevelCompletedItems()
 
 void SeaScene::createSelectLevelsetFromListItems()
 {
+
     if (availableLevelsets_.isEmpty()) //Something is badly wrong in code if this is true...
             return;
 
@@ -876,6 +899,7 @@ void SeaScene::createSelectLevelsetFromListItems()
     pSelectLevelsetFromListItem_->setZValue(1000);
     pSelectLevelsetFromListItem_->hide();
 
+
     QString fontstring ("<font color = darkorange size = \"7\">");
 
     pSelectLevelsetFromListItem_->setHtml(tr("Choose a levelset").prepend(fontstring));
@@ -903,3 +927,17 @@ void SeaScene::createSelectLevelsetFromListItems()
     }
 
   }
+
+
+    void SeaScene::resourcesAvailable()
+    {
+        qDebug() << "Resources available";
+        vibrationAllowed_ = true;
+    }
+
+
+    void SeaScene::resourcesLost()
+    {
+        qDebug() << "Resources lost";
+        vibrationAllowed_ = false;
+    }
index c1e8aac..2593927 100644 (file)
@@ -32,6 +32,7 @@
 #include <QAction>
 #include <QTimer>
 #include <QTime>
+#include <policy/resource-set.h>
 
 class SeaScene : public QGraphicsScene
 {
@@ -46,6 +47,7 @@ signals:
     void pauseOff();
     void vibrationActivated(bool on);
 
+
 public slots:
 
     /*! Places all needed items for a level to (re)start.
@@ -86,6 +88,10 @@ public slots:
 
     void turnPauseOn();
 
+    void resourcesAvailable();
+
+    void resourcesLost();
+
 
 
 
@@ -161,6 +167,10 @@ protected:
     QTime scoreCounter_;
     int totalScore_;
     int levelScore_;
+
+    ResourcePolicy::ResourceSet * pResourceSet_;
+    bool vibrationAllowed_;
+
 };
 
 #endif // SEASCENE_H
index 8afc2d2..a061689 100644 (file)
--- a/ship.cpp
+++ b/ship.cpp
@@ -25,7 +25,7 @@
 #include <QDebug>
 #include <QDBusMessage>
 #include <QDBusConnection>
-#include <QFeedbackHapticsEffect>
+
 
 
 
@@ -38,8 +38,21 @@ Ship::Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent) :
     shipImages_ = pixmapList;
     ghostsAboard_ = 0;
     vibrationActive_ = false;
+    vibrationAllowed_ = false;
+
+    pVibrationEffect_ = new QFeedbackHapticsEffect();
+    pVibrationEffect_->setDuration(500);
+    pVibrationEffect_->setIntensity(1.0);
+
 }
 
+Ship::~Ship()
+{
+    if (pVibrationEffect_)
+      delete pVibrationEffect_;
+}
+
+
 bool Ship::handleCollisions()
 {
     QList<QGraphicsItem*>  collidesList = collidingItems();
@@ -98,7 +111,7 @@ void Ship::dropAllGhosts()
 
     //vibrate
 
-    if (vibrationActive_)
+    if (vibrationActive_ && vibrationAllowed_)
     {
 
  //       This is for fremantle
@@ -117,10 +130,8 @@ void Ship::dropAllGhosts()
 
         //This is for Harmattan
 
-        QFeedbackHapticsEffect vibrationEffect;
-        vibrationEffect.setDuration(1000);
-        vibrationEffect.setIntensity(1.0);
-        vibrationEffect.start();
+        pVibrationEffect_->start();
+
 
     }
 }
@@ -129,3 +140,13 @@ void Ship::setVibrationActivate(bool on)
 {
     vibrationActive_ = on;
 }
+
+void Ship::allowVibration()
+{
+    vibrationAllowed_ = true;
+}
+
+void Ship::disallowVibration()
+{
+    vibrationAllowed_ = false;
+}
diff --git a/ship.h b/ship.h
index 77cd334..ffdbfb7 100644 (file)
--- a/ship.h
+++ b/ship.h
@@ -24,6 +24,7 @@
 #define SHIP_H
 
 #include "orientationcontrolledgraphicspixmapobject.h"
+#include <QFeedbackHapticsEffect>
 
 class Ship : public OrientationControlledGraphicsPixmapObject
 {
@@ -32,6 +33,8 @@ class Ship : public OrientationControlledGraphicsPixmapObject
 public:
     explicit Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent = 0);
 
+    virtual ~Ship();
+
 signals:
 
     /*! Emitted when a ghost is hit */
@@ -48,7 +51,9 @@ public slots:
 
     void setVibrationActivate(bool on);
 
-protected:
+    void allowVibration();
+
+    void disallowVibration();
 
 protected:
     bool handleCollisions();
@@ -61,6 +66,10 @@ protected:
 
     bool vibrationActive_;
 
+    bool vibrationAllowed_;
+
+    QFeedbackHapticsEffect * pVibrationEffect_;
+
 
 };