[Kstars-devel] [kstars] kstars: Using KSNotify namespace to be a universal method for playing notifications in KStars instead of requiring an instance to EKosManager.

Jasem Mutlaq mutlaqja at ikarustech.com
Thu Feb 12 19:51:29 UTC 2015


Git commit f81af19c2fb983acc780a9155f51afee34bd25f0 by Jasem Mutlaq.
Committed on 12/02/2015 at 19:50.
Pushed by mutlaqja into branch 'master'.

Using KSNotify namespace to be a universal method for playing notifications in KStars instead of requiring an instance to EKosManager.

CCMAIL:kstars-devel at kde.org

M  +1    -0    kstars/CMakeLists.txt
A  +44   -0    kstars/auxiliary/ksnotify.cpp     [License: UNKNOWN]  *
A  +13   -0    kstars/auxiliary/ksnotify.h     [License: UNKNOWN]  *
M  +4    -3    kstars/ekos/align.cpp
M  +3    -2    kstars/ekos/capture.cpp
M  +1    -27   kstars/ekos/ekosmanager.cpp
M  +0    -2    kstars/ekos/ekosmanager.h
M  +3    -2    kstars/ekos/focus.cpp
M  +2    -1    kstars/ekos/guide/guider.cpp
M  +10   -9    kstars/ekos/guide/rcalibration.cpp
M  +2    -1    kstars/indi/indiccd.cpp

The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


http://commits.kde.org/kstars/f81af19c2fb983acc780a9155f51afee34bd25f0

diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 8093b8a..369e5b9 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -381,6 +381,7 @@ set(kstars_projection_SRCS
 )
 
 set(kstars_extra_SRCS
+        auxiliary/ksnotify.cpp
         auxiliary/colorscheme.cpp
         auxiliary/dms.cpp
         auxiliary/fov.cpp
diff --git a/kstars/auxiliary/ksnotify.cpp b/kstars/auxiliary/ksnotify.cpp
new file mode 100644
index 0000000..d540132
--- /dev/null
+++ b/kstars/auxiliary/ksnotify.cpp
@@ -0,0 +1,44 @@
+#include <QDebug>
+#include <QUrl>
+#include <QStandardPaths>
+#include <QtMultimedia/QMediaPlayer>
+
+#include "ksnotify.h"
+
+
+namespace KSNotify
+{
+
+    namespace
+    {
+        QMediaPlayer player;
+        int lastType = -1;
+
+    }
+
+void play(Type type)
+{
+    if (lastType != type)
+    {
+        switch (type)
+        {
+            case NOTIFY_OK:
+                player.setMedia(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "ekos-ok.ogg" )));
+                break;
+
+            case NOTIFY_FILE_RECEIVED:
+                player.setMedia(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "ekos-fits.ogg" )));
+                break;
+
+            case NOTIFY_ERROR:
+                 player.setMedia(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "ekos-error.ogg" )));
+                 break;
+        }
+
+        lastType = type;
+    }
+
+    player.play();
+}
+
+}
diff --git a/kstars/auxiliary/ksnotify.h b/kstars/auxiliary/ksnotify.h
new file mode 100644
index 0000000..ff62eca
--- /dev/null
+++ b/kstars/auxiliary/ksnotify.h
@@ -0,0 +1,13 @@
+#ifndef KSNOTIFY_H
+#define KSNOTIFY_H
+
+namespace KSNotify
+{
+
+    typedef enum { NOTIFY_OK, NOTIFY_ERROR, NOTIFY_FILE_RECEIVED} Type;
+
+    void play(Type type);
+
+}
+
+#endif // KSNOTIFY_H
diff --git a/kstars/ekos/align.cpp b/kstars/ekos/align.cpp
index 7a62d23..3478f61 100644
--- a/kstars/ekos/align.cpp
+++ b/kstars/ekos/align.cpp
@@ -19,6 +19,7 @@
 #include <QFileDialog>
 #include <KMessageBox>
 
+#include "ksnotify.h"
 #include "QProgressIndicator.h"
 #include "indi/driverinfo.h"
 #include "indi/indicommon.h"
@@ -541,7 +542,7 @@ bool Align::captureAndSolve()
     {
         appendLogText(xi18n("Error: Lost connection to CCD."));
         if (Options::playAlignmentAlarm())
-                KStars::Instance()->ekosManager()->playError();
+                KSNotify::play(KSNotify::NOTIFY_ERROR);
         return false;
     }
 
@@ -667,7 +668,7 @@ void Align::solverFinished(double orientation, double ra, double dec)
      SolverDecOut->setText(dec_dms);
 
      if (Options::playAlignmentAlarm())
-             KStars::Instance()->ekosManager()->playOk();
+             KSNotify::play(KSNotify::NOTIFY_OK);
 
      m_isSolverComplete = true;
      m_isSolverSuccessful = true;
@@ -680,7 +681,7 @@ void Align::solverFinished(double orientation, double ra, double dec)
 void Align::solverFailed()
 {
     if (Options::playAlignmentAlarm())
-            KStars::Instance()->ekosManager()->playError();
+            KSNotify::play(KSNotify::NOTIFY_ERROR);
     pi->stopAnimation();
     stopB->setEnabled(false);
     solveB->setEnabled(true);
diff --git a/kstars/ekos/capture.cpp b/kstars/ekos/capture.cpp
index e181afb..e1d31e9 100644
--- a/kstars/ekos/capture.cpp
+++ b/kstars/ekos/capture.cpp
@@ -20,6 +20,7 @@
 
 #include "Options.h"
 
+#include "ksnotify.h"
 #include "kstars.h"
 #include "kstarsdata.h"
 
@@ -531,7 +532,7 @@ void Capture::stopSequence()
         if (activeJob->getStatus() == SequenceJob::JOB_BUSY)
         {
             if (Options::playCCDAlarm())
-                KStars::Instance()->ekosManager()->playError();
+                KSNotify::play(KSNotify::NOTIFY_ERROR);
             activeJob->abort();
         }
 
@@ -1005,7 +1006,7 @@ void Capture::newFITS(IBLOB *bp)
         else
         {
             if (Options::playCCDAlarm())
-                    KStars::Instance()->ekosManager()->playOk();
+                    KSNotify::play(KSNotify::NOTIFY_OK);
 
             if (parkCheck->isChecked() && currentTelescope && currentTelescope->canPark())
             {
diff --git a/kstars/ekos/ekosmanager.cpp b/kstars/ekos/ekosmanager.cpp
index 4e5b128..ddbbb7f 100644
--- a/kstars/ekos/ekosmanager.cpp
+++ b/kstars/ekos/ekosmanager.cpp
@@ -13,6 +13,7 @@
 
 #include "Options.h"
 #include "kstars.h"
+#include "auxiliary/ksnotify.h"
 
 #include <KMessageBox>
 #include <QComboBox>
@@ -102,14 +103,6 @@ EkosManager::EkosManager(QWidget *parent)
     else
         initRemoteDrivers();
 
-    playFITSFile  = new QMediaPlayer();
-    playFITSFile->setMedia(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "ekos-fits.ogg" )));
-
-    playOkFile    = new QMediaPlayer();
-    playOkFile->setMedia(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "ekos-ok.ogg" )));
-
-    playErrorFile = new QMediaPlayer();
-    playErrorFile->setMedia(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "ekos-error.ogg" )));
 }
 
 EkosManager::~EkosManager()
@@ -119,9 +112,6 @@ EkosManager::~EkosManager()
     delete guideProcess;
     delete alignProcess;
     delete mountProcess;
-    delete playFITSFile;
-    delete playOkFile;
-    delete playErrorFile;
 }
 
 void EkosManager::setConnectionMode(bool isLocal)
@@ -1671,22 +1661,6 @@ bool EkosManager::isRunning(const QString &process)
   return output.startsWith(process);
 }
 
-void EkosManager::playFITS()
-{
-    playFITSFile->play();
-}
-
-void EkosManager::playOk()
-{
-   playOkFile->play();
-
-}
-
-void EkosManager::playError()
-{
-   playErrorFile->play();
-}
-
 void EkosManager::setTelescope(const QString & telescopeName)
 {
     if (localMode)
diff --git a/kstars/ekos/ekosmanager.h b/kstars/ekos/ekosmanager.h
index 3058f29..e282b1b 100644
--- a/kstars/ekos/ekosmanager.h
+++ b/kstars/ekos/ekosmanager.h
@@ -225,8 +225,6 @@ public slots:
     QHash<QString, DriverInfo *> driversList;
     QStringList logText;
 
-    QMediaPlayer *playFITSFile, *playOkFile, *playErrorFile;
-
 };
 
 
diff --git a/kstars/ekos/focus.cpp b/kstars/ekos/focus.cpp
index fae5773..83540ae 100644
--- a/kstars/ekos/focus.cpp
+++ b/kstars/ekos/focus.cpp
@@ -26,6 +26,7 @@
 #include "fitsviewer/fitsview.h"
 #include "ekosmanager.h"
 
+#include "ksnotify.h"
 #include "kstars.h"
 #include "focusadaptor.h"
 
@@ -1721,9 +1722,9 @@ void Focus::updateFocusStatus(bool status)
     if (Options::playFocusAlarm())
     {
         if (status)
-            KStars::Instance()->ekosManager()->playOk();
+            KSNotify::play(KSNotify::NOTIFY_OK);
         else
-            KStars::Instance()->ekosManager()->playError();
+            KSNotify::play(KSNotify::NOTIFY_ERROR);
     }
 }
 
diff --git a/kstars/ekos/guide/guider.cpp b/kstars/ekos/guide/guider.cpp
index d4e76cf..1574f76 100644
--- a/kstars/ekos/guide/guider.cpp
+++ b/kstars/ekos/guide/guider.cpp
@@ -18,6 +18,7 @@
 #include <KMessageBox>
 #include <KLocalizedString>
 
+#include "ksnotify.h"
 #include "scroll_graph.h"
 #include "gmath.h"
 #include "fitsviewer/fitsview.h"
@@ -645,7 +646,7 @@ bool rguider::abort(bool silence)
             return rc;
 
         if (Options::playGuideAlarm())
-                KStars::Instance()->ekosManager()->playError();
+                KSNotify::play(KSNotify::NOTIFY_ERROR);
     }
 
     return true;
diff --git a/kstars/ekos/guide/rcalibration.cpp b/kstars/ekos/guide/rcalibration.cpp
index 41799c4..a6fb8e7 100644
--- a/kstars/ekos/guide/rcalibration.cpp
+++ b/kstars/ekos/guide/rcalibration.cpp
@@ -22,6 +22,7 @@
 #include "gmath.h"
 #include "vect.h"
 
+#include "ksnotify.h"
 #include "../guide.h"
 #include "../fitsviewer/fitsviewer.h"
 #include "../fitsviewer/fitsview.h"
@@ -427,7 +428,7 @@ void rcalibration::calibrateManualReticle( void )
 
                     pmain_wnd->appendLogText(xi18n("Calibration completed."));
                     if (Options::playGuideAlarm())
-                            KStars::Instance()->ekosManager()->playOk();
+                            KSNotify::play(KSNotify::NOTIFY_OK);
                     calibrationStage = CAL_FINISH;
                     emit calibrationCompleted(true);
 
@@ -452,7 +453,7 @@ void rcalibration::calibrateManualReticle( void )
                 pmain_wnd->appendLogText(xi18n("Calibration completed."));
                 emit calibrationCompleted(true);
                 if (Options::playGuideAlarm())
-                        KStars::Instance()->ekosManager()->playOk();
+                        KSNotify::play(KSNotify::NOTIFY_OK);
 			}
 			else
 			{
@@ -460,7 +461,7 @@ void rcalibration::calibrateManualReticle( void )
                 emit calibrationCompleted(false);
                 QMessageBox::warning( this, xi18n("Error"), xi18n("Calibration rejected. Start drift is too short."), QMessageBox::Ok );
                 if (Options::playGuideAlarm())
-                        KStars::Instance()->ekosManager()->playError();
+                        KSNotify::play(KSNotify::NOTIFY_ERROR);
 			}
 		}
 
@@ -592,7 +593,7 @@ void rcalibration::calibrateRADECRecticle( bool ra_only )
             emit calibrationCompleted(false);
             QMessageBox::warning( this, xi18n("Warning"), xi18np("GUIDE_RA: Scope cannot reach the start point after %1 iteration.\nPossible mount or drive problems...", "GUIDE_RA: Scope cannot reach the start point after %1 iterations.\nPossible mount or drive problems...", turn_back_time), QMessageBox::Ok );
             if (Options::playGuideAlarm())
-                    KStars::Instance()->ekosManager()->playError();
+                    KSNotify::play(KSNotify::NOTIFY_ERROR);
             reset();
             break;
         }
@@ -623,7 +624,7 @@ void rcalibration::calibrateRADECRecticle( bool ra_only )
             emit calibrationCompleted(true);
             ui.startCalibrationLED->setColor(okColor);
             if (Options::playGuideAlarm())
-                    KStars::Instance()->ekosManager()->playError();
+                    KSNotify::play(KSNotify::NOTIFY_ERROR);
             if (ui.autoCalibrationCheck->isChecked())
                 selectAutoStar(pmath->get_image());
         }
@@ -634,7 +635,7 @@ void rcalibration::calibrateRADECRecticle( bool ra_only )
             calibrationStage = CAL_ERROR;
             emit calibrationCompleted(false);
             if (Options::playGuideAlarm())
-                    KStars::Instance()->ekosManager()->playError();
+                    KSNotify::play(KSNotify::NOTIFY_ERROR);
         }
 
         reset();
@@ -710,7 +711,7 @@ void rcalibration::calibrateRADECRecticle( bool ra_only )
         emit calibrationCompleted(false);
         QMessageBox::warning( this, xi18n("Warning"), xi18np("GUIDE_DEC: Scope cannot reach the start point after %1 iteration.\nPossible mount or drive problems...", "GUIDE_DEC: Scope cannot reach the start point after %1 iterations.\nPossible mount or drive problems...", turn_back_time), QMessageBox::Ok );
         if (Options::playGuideAlarm())
-                KStars::Instance()->ekosManager()->playError();
+                KSNotify::play(KSNotify::NOTIFY_ERROR);
         reset();
         break;
     }
@@ -730,7 +731,7 @@ void rcalibration::calibrateRADECRecticle( bool ra_only )
         ui.startCalibrationLED->setColor(okColor);
         pmain_wnd->setDECSwap(swap_dec);
         if (Options::playGuideAlarm())
-                KStars::Instance()->ekosManager()->playOk();
+                KSNotify::play(KSNotify::NOTIFY_OK);
         if (ui.autoCalibrationCheck->isChecked())
             selectAutoStar(pmath->get_image());
 
@@ -742,7 +743,7 @@ void rcalibration::calibrateRADECRecticle( bool ra_only )
         ui.startCalibrationLED->setColor(alertColor);
         calibrationStage = CAL_ERROR;
         if (Options::playGuideAlarm())
-                KStars::Instance()->ekosManager()->playError();
+                KSNotify::play(KSNotify::NOTIFY_ERROR);
     }
 
     reset();
diff --git a/kstars/indi/indiccd.cpp b/kstars/indi/indiccd.cpp
index 8752a13..c37ff65 100644
--- a/kstars/indi/indiccd.cpp
+++ b/kstars/indi/indiccd.cpp
@@ -32,6 +32,7 @@
 
 #include <ekos/ekosmanager.h>
 
+#include "ksnotify.h"
 #include "imageviewer.h"
 #include "Options.h"
 
@@ -1164,7 +1165,7 @@ void CCD::processBLOB(IBLOB* bp)
         KStars::Instance()->statusBar()->showMessage( xi18n("%1 file saved to %2", QString(fmt).toUpper(), filename ), 0);
 
     if (Options::playFITSAlarm() && KStars::Instance()->ekosManager())
-        KStars::Instance()->ekosManager()->playFITS();
+        KSNotify::play(KSNotify::NOTIFY_FILE_RECEIVED);
 
     if (targetChip->showFITS() == false && targetChip->getCaptureMode() == FITS_NORMAL)
     {


More information about the Kstars-devel mailing list