24 #include <QMediaPlayer>
27 #include <QFileOpenEvent>
28 #include <QStandardPaths>
30 #include <QMessageBox>
31 #include "../core/config.h"
32 #include "../core/messages/messagehandler.h"
38 #include "../core/system/eptexception.h"
44 : QApplication(argc, argv),
45 mMessageHandlerTimerId(0),
52 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() <<
":/media" <<
":/media/icons");
54 if (primaryScreen()->devicePixelRatio() >= 1.5) {
55 setAttribute(Qt::AA_UseHighDpiPixmaps);
62 mLastExitCode = settings.value(
"application/lastExitCode", EXIT_SUCCESS).toInt();
64 settings.setValue(
"application/lastExitCode", EXIT_FAILURE);
66 QObject::connect(
this, SIGNAL(aboutToQuit()),
this, SLOT(
onAboutToQuit()));
91 settings.setValue(
"application/lastExitCode", errorcode);
97 if (QMessageBox::information(
nullptr, tr(
"Crash handler"), tr(
"The application exited unexpectedly on the last run. Do you want to view the last log?"), QMessageBox::Yes | QMessageBox::No)
98 == QMessageBox::Yes) {
108 mMainWindow->setFixedSize(primaryScreen()->size());
113 LogI(
"Number of arguments: %d", arguments().size());
114 LogI(
"Program arguments: %s", arguments().join(
", ").toStdString().c_str());
142 if (!
mCore) {
return;}
152 QObject::connect(
this, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
168 if (!
mCore) {
return;}
175 QString fileName=
"startup_sound.ogg";
177 QString fileName=
"startup_sound.mp3";
182 QFile audioFile(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
"/" + fileName);
183 if (!audioFile.exists()) {
185 QFile::copy(
":/media/audio/" + fileName, audioFile.fileName());
187 if (audioFile.size() != QResource(
":/media/audio/" + fileName).size()) {
190 QFile::copy(
":/media/audio/" + fileName, audioFile.fileName());
195 EptAssert(audioFile.exists(),
"Audio file should exist now");
198 QMediaPlayer *player =
new QMediaPlayer(
this);
199 player->setMedia(QUrl::fromLocalFile(audioFile.fileName()));
200 player->setVolume(50);
202 if (player->error() != QMediaPlayer::NoError) {
203 LogW(
"Error in QMediaPlayer: %s", player->errorString().toStdString().c_str());
208 if (!
mCore || !
mCore->getProjectManager() || !
mCore->isInitialized()) {
210 LogI(
"Storing startup file: %s", filePath.toStdString().c_str());
219 case QEvent::FileOpen:
221 return openFile(static_cast<QFileOpenEvent *>(e)->file(),
false);
223 return QApplication::event(e);
234 return QApplication::notify(receiver, event);
237 qCritical() <<
"Unhandled exception: ";
241 catch (
const std::exception &e) {
242 qCritical() <<
"Unhandled exception: ";
243 qCritical() << QString::fromStdString(e.what());
246 qCritical() <<
"Unhandled exception: ";
247 qCritical() <<
"unknown exception";
297 if (state & Qt::ApplicationSuspended) {
299 LogI(
"Application suspended: exiting core");
303 }
else if (state & Qt::ApplicationActive) {
305 LogI(
"Application gone active: starting core");
309 }
else if (state & Qt::ApplicationHidden ) {
311 LogI(
"Application gone hidden: exiting core");
313 }
else if (state & Qt::ApplicationInactive) {
315 #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_WINPHONE)
316 LogI(
"Application gone inactive: stopping core");
bool notify(QObject *receiver, QEvent *event)
Reimplemented to catch exceptions.
static TunerApplication * mSingleton
The one and only instance.
int mMessageHandlerTimerId
Id of the timer that progresses the MessageHandler.
bool openFile(QString filePath, bool cached)
Open the given file.
QString mStartupFile
Absolute path to the startup file or an empty string.
static MessageHandler & getSingleton()
get a reference to the singleton class
AudioRecorderForQt mAudioRecorder
Instance of the Qt audio recorder.
Implementation of the ProjectManagerAdapter in Qt.
TunerApplication(int &argc, char **argv)
Constructor for the application.
std::shared_ptr< MainWindow > mMainWindow
Shared pointer of the MainWindow.
The main application singleton class.
void start()
Function to start the MainWindow and the Core.
static TunerApplication & getSingleton()
Getter for the singleton instance.
static TunerApplication * getSingletonPtr()
Getter for the singleton instance.
void playStartupSound()
Function to play the startup sound.
AudioPlayerForQt mAudioPlayer
Instance of the Qt audio player.
void exit()
Function called upon exitting the application.
std::shared_ptr< Core > mCore
Shared pointer of the Core.
void stop()
Function to stop the MainWindow and the Core.
int mLastExitCode
last exit code to detect if the application crashed
void stopCore()
Stop the core.
void initCore()
Initialising of the core.
void process()
Main task, processing the events in the queue.
Implementation of the core initializ.
void init()
Function to initialise the application.
CORE : Class managing the core.
Implementation of the FileManager for Qt.
void timerEvent(QTimerEvent *event)
Called when the internal timer was shot.
void startCore()
Start the core.
Implementation for the log in Qt.
virtual ~TunerApplication()
Destructor of the application.
bool event(QEvent *e)
Handling of general events.
void exitCore()
Exit from the core.
static void setApplicationExitState(int errorcode=EXIT_SUCCESS)
This is sets the exit code if the app would be terminated now.
void onApplicationStateChanged(Qt::ApplicationState state)
Depending on the application state the core will be started or stopped.
virtual const std::string & getFullDescription(void) const
Returns a string with the full description of this error.