AstRawDark
Manage your astrophoto dark frames
 All Classes Functions Variables Enumerations Enumerator Pages
main.cpp
1 /*
2  * AstRawDark
3  *
4  * Copyright (C) 2015 - Frédéric CORNU
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
49 #include "gui/mainWindow.h"
50 #include "data/dto/imageInfo.h"
51 #include "data/dataStore.h"
52 #include "globals.h"
53 #include "helpers/localeHelper.h"
54 
55 #include <QApplication>
56 #include <QSettings>
57 #include <QTranslator>
58 
59 #ifdef Q_OS_MAC
60 #include <QLibraryInfo>
61 #endif
62 
63 #ifndef QT_NO_DEBUG
64 #include <QDebug>
65 #endif
66 
67 void installTranslator( QApplication& app, QString& filePrefix, QString& folderPath, QString locale );
68 
69 int main(int argc, char *argv[])
70 {
71  QApplication a(argc, argv);
72 
73  QCoreApplication::setOrganizationName("wardsback");
74  QCoreApplication::setOrganizationDomain("wardsback.org");
75  QCoreApplication::setApplicationName("AstRawDark");
76  QSettings settings;
77 
78  qRegisterMetaType< QList<ImageInfo> >("QList<ImageInfo>");
79 
80  QString appTransfilePrefix = "astrawdark_";
81  QString appTransFolderPath = ":/i18n";
82  installTranslator( a, appTransfilePrefix, appTransFolderPath, LocaleHelper::getLocale() );
83 
84 #ifdef Q_OS_MAC
85 
86  /*
87  * on Mac :
88  *
89  * - some menu entries are merged into the "application menu" and their translations are
90  * provided by a Qt specific translation file
91  *
92  * - no icons are shown next to menu items
93  */
94 
95  // install translator for Qt itself
96  QString qtTransfilePrefix= "qt_";
97  QString qtTransFolderPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
98  installTranslator(a, qtTransfilePrefix, qtTransFolderPath, LocaleHelper::getLocale());
99 
100  // Don't show icons for menu items on Mac
101  a.setAttribute(Qt::AA_DontShowIconsInMenus);
102 #endif
103 
104  MainWindow w;
105 
106  if ( DataStore::getInstance()->getRememberWindowGeometry() ) {
107 
108  if ( settings.value(Globals::SETTINGKEY_WINDOW_MAXIMIZED, false).toBool() ) {
109 
110  w.setWindowState( w.windowState() | Qt::WindowMaximized );
111 
112  } else {
113 
114  if ( settings.contains(Globals::SETTINGKEY_WINDOW_GEOMETRY) ) {
115 
116  w.setGeometry(settings.value(Globals::SETTINGKEY_WINDOW_GEOMETRY).toRect());
117  }
118  }
119 
120  }
121 
122 
123 #ifndef QT_NO_DEBUG
124  qDebug() << "Showing main window";
125 #endif
126  w.show();
127 
128  int nRet = a.exec();
129 
130  if ( DataStore::getInstance()->getRememberWindowGeometry() ) {
131 
132  settings.setValue(Globals::SETTINGKEY_WINDOW_GEOMETRY, w.geometry());
133  settings.setValue(Globals::SETTINGKEY_WINDOW_MAXIMIZED, Qt::WindowMaximized == w.windowState());
134  }
135 
136  settings.sync();
137 
138  return nRet;
139 }
140 
141 void installTranslator( QApplication& app, QString& filePrefix, QString& folderPath, QString locale ) {
142 
143  QTranslator* pTranslator = new QTranslator();
144  bool isTransLoaded = pTranslator->load( filePrefix + locale, folderPath );
145 
146  if( isTransLoaded ) {
147 
148 #ifndef QT_NO_DEBUG
149  qDebug() << "Translation file loaded successfully :" << filePrefix + locale;
150 #endif
151 
152  app.installTranslator( pTranslator );
153 
154  } else {
155 
156  qWarning( "Failed to load translation file : %s%s", filePrefix.toStdString().c_str(),
157  locale.toStdString().c_str() );
158  }
159 
160 }