Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
main.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
50 
51 #include <QTranslator>
52 #include <QLibraryInfo>
53 #include <QMessageBox>
54 #include "tunerapplication.h"
55 #include "qdebug.h"
56 #include "../core/config.h"
57 #include "../core/system/serverinfo.h"
58 #include "qtconfig.h"
59 #include "../core/system/eptexception.h"
60 #include "settingsforqt.h"
61 #include "platformtools.h"
62 #include "runguard.h"
63 
64 int main(int argc, char *argv[])
65 {
66 
67  // only single instance also on desktop (on mobile platforms this is handled already)
68 #ifdef Q_OS_DESKTOP
69  RunGuard guard("entropypianotuner_runguard");
70  if ( !guard.tryToRun() ) {
71  // a QApplication is required for showing message boxes
72  QApplication q(argc, argv);
73  QMessageBox::warning(nullptr, q.tr("Application can not be started"), q.tr("The Entropy Piano Tuner could not be started because another instance is already running."));
74  return 0;
75  }
76 #endif
77 
78  int exitCode = -1;
79 
80  // setup platformtools
81 
82  // required if no platform specific platform tools
83  std::unique_ptr<PlatformTools> defaultPlatformTools;
85  defaultPlatformTools.reset(new PlatformTools());
86  // no platform specific platform tools, use default ones
87  }
88 
89  // basic application properties (needed for settings)
90  QCoreApplication::setOrganizationName("tp3");
91  QCoreApplication::setOrganizationDomain(serverinfo::SERVER_DOMAIN.c_str());
92  QCoreApplication::setApplicationName("Entropy Piano Tuner");
93 
94  try {
95  // create settings
96  (new SettingsForQt())->load();
97  // increase run count
99 
100  // create our application object
101  TunerApplication a(argc, argv);
102 
103  // install language files
104  QTranslator qtTranslator;
105 
106  QString localeName(QString::fromStdString(SettingsForQt::getSingleton().getLanguageId()));
107  if (localeName.isEmpty()) {
108  // system language
109  localeName = QLocale::system().name();
110  }
111  // set default to be sure that this is not "C"
112  QLocale::setDefault(QLocale(localeName));
113 
114  // Qt translation
115  qtTranslator.load(QLocale(), "qt", "_", ":/languages/translations");
116  a.installTranslator(&qtTranslator);
117 
118  // application translation
119  QTranslator myappTranslator;
120  myappTranslator.load(QLocale(), "piano_tuner", "_", ":/languages/translations");
121  a.installTranslator(&myappTranslator);
122 
123  a.playStartupSound();
124 
125  // init all components
126  a.init();
127 
128  // start the application
129  a.start();
130 
131  // execute the application
132  exitCode = a.exec();
133  }
134  catch (const EptException &e) {
135  qCritical() << "Unhandled exception: ";
136  qCritical() << QString::fromStdString(e.getFullDescription());
137  exitCode = EXIT_FAILURE;
138  }
139  catch (const std::exception &e) {
140  qCritical() << "Unhandled exception: ";
141  qCritical() << QString::fromStdString(e.what());
142  exitCode = EXIT_FAILURE;
143  }
144  catch (...) {
145  qCritical() << "Unhandled exception: ";
146  qCritical() << "unknown exception";
147  exitCode = EXIT_FAILURE;
148  }
149 
151 
152  return exitCode;
153 }
static PlatformTools * getSingleton()
Definition: platformtools.h:38
The main application singleton class.
void start()
Function to start the MainWindow and the Core.
void playStartupSound()
Function to play the startup sound.
bool tryToRun()
Try to run the applicaiton, return false if another instance is running.
Definition: runguard.cpp:122
Qt specific settings.
Definition: settingsforqt.h:32
static const std::string SERVER_DOMAIN
Definition: serverinfo.h:28
void increaseApplicationRuns()
Increments mApplicationRuns.
void init()
Function to initialise the application.
Class for checking whether the application is already running.
Definition: runguard.h:42
virtual void enableScreensaver()
Function to enable the screen saver.
Definition: platformtools.h:70
static SettingsForQt & getSingleton()
Getter function for the singleton.
int main(int argc, char *argv[])
Definition: main.cpp:64
virtual const std::string & getFullDescription(void) const
Returns a string with the full description of this error.