1 /*
2     SPDX-FileCopyrightText: 2016 Jasem Mutlaq <mutlaqja@ikarustech.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "ksnotification.h"
8 #include "config-kstars.h"
9 #include "Options.h"
10 
11 #ifdef KSTARS_LITE
12 #include "kstarslite.h"
13 #else
14 #include <QPointer>
15 #include <QTimer>
16 #include <KNotification>
17 
18 #include "ksmessagebox.h"
19 
20 #ifdef HAVE_INDI
21 #ifdef HAVE_CFITSIO
22 #include "kstars.h"
23 #include "ekos/manager.h"
24 #endif
25 #endif
26 #endif // KSTARS_LITE
27 
28 namespace KSNotification
29 {
error(const QString & message,const QString & title,uint32_t timeout)30 void error(const QString &message, const QString &title, uint32_t timeout)
31 {
32 #ifdef KSTARS_LITE
33     Q_UNUSED(title);
34     KStarsLite::Instance()->notificationMessage(message);
35 #else
36     KSMessageBox::Instance()->error(message, title, timeout);
37 #endif
38 }
39 
sorry(const QString & message,const QString & title,uint32_t timeout)40 void sorry(const QString &message, const QString &title, uint32_t timeout)
41 {
42 #ifdef KSTARS_LITE
43     Q_UNUSED(title);
44     KStarsLite::Instance()->notificationMessage(message);
45 #else
46     KSMessageBox::Instance()->sorry(message, title, timeout);
47 #endif
48 }
49 
info(const QString & message,const QString & title,uint32_t timeout)50 void info(const QString &message, const QString &title, uint32_t timeout)
51 {
52 #ifdef KSTARS_LITE
53     Q_UNUSED(title);
54     KStarsLite::Instance()->notificationMessage(message);
55 #else
56     KSMessageBox::Instance()->info(message, title, timeout);
57 #endif
58 }
59 
transient(const QString & message,const QString & title)60 void transient(const QString &message, const QString &title)
61 {
62 #ifdef KSTARS_LITE
63     Q_UNUSED(title);
64     KStarsLite::Instance()->notificationMessage(message);
65 #else
66     QPointer<QMessageBox> msgBox = new QMessageBox();
67     msgBox->setAttribute(Qt::WA_DeleteOnClose);
68     msgBox->setWindowTitle(title);
69     msgBox->setText(message);
70     msgBox->setModal(false);
71     msgBox->setIcon(QMessageBox::Warning);
72     msgBox->show();
73     QTimer::singleShot(10000, msgBox, [msgBox]()
74     {
75         if (msgBox) msgBox->close();
76     });
77 #endif
78 }
79 
event(const QLatin1String & name,const QString & message,EventType type)80 void event(const QLatin1String &name, const QString &message, EventType type)
81 {
82     Q_UNUSED(name)
83     Q_UNUSED(message)
84     Q_UNUSED(type)
85 #ifndef KSTARS_LITE
86     KNotification::event(name, message);
87 
88 #ifdef HAVE_INDI
89 #ifdef HAVE_CFITSIO
90     Ekos::Manager::Instance()->announceEvent(message, type);
91 #endif
92 #endif
93 
94 #endif
95 }
96 
97 }
98