Polls for screen locked status
[ghostsoverboard] / seascene.cpp
index fa17ec2..9ee3925 100644 (file)
@@ -90,9 +90,14 @@ SeaScene::SeaScene(QObject *parent) :
     connect(pPauseAction_,SIGNAL(toggled(bool)),this,SLOT(pause(bool)));
 
 
+    deviceLockPollTimer_.setInterval(20*60); // 2s
+    connect(&deviceLockPollTimer_,SIGNAL(timeout()),this,SLOT(pollDeviceLocked()));
+    deviceLockPollTimer_.start();
+
+
     autopauseTimer.setSingleShot(true);
     autopauseTimer.setInterval(15*60*1000);
-    connect(&autopauseTimer,SIGNAL(timeout()),this,SLOT(forcePause()));
+    connect(&autopauseTimer,SIGNAL(timeout()),this,SLOT(turnPauseOn()));
 
 
 }
@@ -364,6 +369,7 @@ void SeaScene::pause(bool paused)
                 pPausetextItem_->hide();
 
             autopauseTimer.start(); //Start counting towards autopause
+            deviceLockPollTimer_.start(); //Start polling whether device is locked
         }
 
         else
@@ -380,6 +386,7 @@ void SeaScene::pause(bool paused)
 //                else qDebug() << "No pause text available";
 
             autopauseTimer.stop(); //No need to count toward autopause when already paused
+            deviceLockPollTimer_.stop(); //No need to check for unlock as no unpause anyway
         }
 }
 
@@ -528,7 +535,7 @@ void SeaScene::createMenuItems()
     prepareForMenu(pRestartLevelItem_);
 
     pSettingsItem_ = new QGraphicsTextItem;
-    QString vibraText(tr("Vibration <br> effects "));
+    QString vibraText(tr("Turn vibration <br> effects "));
     QString statusText;
     if (pVibrateAction_->isChecked())
     {
@@ -651,7 +658,7 @@ void SeaScene::createVictoryItems()
     pVictoryCongratulationsItem_ = new QGraphicsTextItem;
     pVictoryCongratulationsItem_->setHtml("<font size=\"6\" color = darkorange> Victory!");
     pVictoryCongratulationsItem_->hide();
-    pVictoryCongratulationsItem_->setPos(300,50);
+    pVictoryCongratulationsItem_->setPos(355,50);
     pVictoryCongratulationsItem_->setZValue(1000);
     addItem(pVictoryCongratulationsItem_);
 
@@ -707,3 +714,37 @@ void SeaScene::setItemPointersNull()
     pVictoryCongratulationsItem_ = NULL;
 
 }
+
+void SeaScene::turnPauseOn()
+{
+    pPauseAction_->setChecked(true);
+}
+
+void SeaScene::handleDeviceLocked(bool isLocked)
+{
+    //pauses if locked but does not unpause if unlocked
+    if(isLocked)
+    {
+        pPauseAction_->setChecked(true);
+    }
+}
+
+void SeaScene::pollDeviceLocked()
+{
+
+    bool locked = deviceInfo_.isDeviceLocked();
+
+    if (locked)
+    {
+        if (!alreadyLocked_)
+        {
+            pPauseAction_->setChecked(true);
+            alreadyLocked_ = true;
+        }
+
+    else
+        {
+            alreadyLocked_ = false;
+        }
+    }
+}