File indexing completed on 2024-04-14 14:08:56

0001 /*
0002     SPDX-FileCopyrightText: 2016 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "ksnotification.h"
0008 #include "config-kstars.h"
0009 #include "Options.h"
0010 
0011 #ifdef KSTARS_LITE
0012 #include "kstarslite.h"
0013 #else
0014 #include <QPointer>
0015 #include <QTimer>
0016 #include <KNotification>
0017 
0018 #include "ksmessagebox.h"
0019 
0020 #ifdef HAVE_INDI
0021 #ifdef HAVE_CFITSIO
0022 #include "kstars.h"
0023 #include "ekos/manager.h"
0024 #endif
0025 #endif
0026 #endif // KSTARS_LITE
0027 
0028 namespace KSNotification
0029 {
0030 void error(const QString &message, const QString &title, uint32_t timeout)
0031 {
0032 #ifdef KSTARS_LITE
0033     Q_UNUSED(title);
0034     KStarsLite::Instance()->notificationMessage(message);
0035 #else
0036     KSMessageBox::Instance()->error(message, title, timeout);
0037 #endif
0038 }
0039 
0040 void sorry(const QString &message, const QString &title, uint32_t timeout)
0041 {
0042 #ifdef KSTARS_LITE
0043     Q_UNUSED(title);
0044     KStarsLite::Instance()->notificationMessage(message);
0045 #else
0046     KSMessageBox::Instance()->sorry(message, title, timeout);
0047 #endif
0048 }
0049 
0050 void info(const QString &message, const QString &title, uint32_t timeout)
0051 {
0052 #ifdef KSTARS_LITE
0053     Q_UNUSED(title);
0054     KStarsLite::Instance()->notificationMessage(message);
0055 #else
0056     KSMessageBox::Instance()->info(message, title, timeout);
0057 #endif
0058 }
0059 
0060 void transient(const QString &message, const QString &title)
0061 {
0062 #ifdef KSTARS_LITE
0063     Q_UNUSED(title);
0064     KStarsLite::Instance()->notificationMessage(message);
0065 #else
0066     QPointer<QMessageBox> msgBox = new QMessageBox();
0067     msgBox->setAttribute(Qt::WA_DeleteOnClose);
0068     msgBox->setWindowTitle(title);
0069     msgBox->setText(message);
0070     msgBox->setModal(false);
0071     msgBox->setIcon(QMessageBox::Warning);
0072     msgBox->show();
0073     QTimer::singleShot(10000, msgBox, [msgBox]()
0074     {
0075         if (msgBox) msgBox->close();
0076     });
0077 #endif
0078 }
0079 
0080 void event(const QLatin1String &name, const QString &message, EventSource source, EventType type)
0081 {
0082     Q_UNUSED(name)
0083     Q_UNUSED(message)
0084     Q_UNUSED(type)
0085 #ifndef KSTARS_LITE
0086     KNotification::event(name, message);
0087 
0088 #ifdef HAVE_INDI
0089 #ifdef HAVE_CFITSIO
0090     Ekos::Manager::Instance()->announceEvent(message, source, type);
0091 #endif
0092 #endif
0093 
0094 #endif
0095 }
0096 
0097 }