1 /*
2  * main.cpp
3  *
4  * Created by Christophe Daudin on 12/05/09.
5  * Copyright 2009 Grame. All rights reserved.
6  *
7  * GNU Lesser General Public License Usage
8  * Alternatively, this file may be used under the terms of the GNU Lesser
9  * General Public License version 2.1 as published by the Free Software
10  * Foundation and appearing in the file LICENSE.LGPL included in the
11  * packaging of this file.  Please review the following information to
12  * ensure the GNU Lesser General Public License version 2.1 requirements
13  * will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
14  *
15  *
16  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  */
19 #include <QApplication>
20 #include <QFileOpenEvent>
21 #include <QString>
22 #include <QFontDatabase>
23 #include <QFile>
24 #include <QtDebug>
25 
26 #include "MainWindow.h"
27 
28 #ifdef GUIDO_CALCULUS_APP
29 #define APP_NAME "GuidoCalculus"
30 #else
31 #define APP_NAME "GuidoSceneComposer"
32 #endif
33 #define COMPANY_NAME "GRAME"
34 
35 
36 #define GUIDO_FONT_FILE "guido2.ttf"
37 #ifdef Q_WS_MAC
38 #include <CoreFoundation/CoreFoundation.h>
getGuidoFontPath()39 static QString getGuidoFontPath()
40 {
41 	QString guidoFontPath = QString(APP_NAME) + ".app/Contents/Resources/" + GUIDO_FONT_FILE;
42 
43 	if ( QFile::exists(guidoFontPath) )
44 		return guidoFontPath ;
45 	else
46 	{
47 		if ( QFile::exists(GUIDO_FONT_FILE) )
48 			return GUIDO_FONT_FILE;
49 		else
50 			return  "";
51 	}
52 }
53 #else
getGuidoFontPath()54 static QString getGuidoFontPath()
55 {
56 	return GUIDO_FONT_FILE;
57 }
58 #endif
59 
60 
installGuidoFont()61 static void installGuidoFont()
62 {
63 	QString fileName = getGuidoFontPath();
64 	if ( !fileName.isEmpty() )
65 		QFontDatabase::addApplicationFont ( fileName );
66 }
67 
68 #define Stringify(x) #x
69 
main(int argc,char * argv[])70 int main(int argc, char *argv[])
71 {
72 	QApplication app(argc, argv);
73 	Q_INIT_RESOURCE( application );
74 #ifdef USES_GUIDO_AR
75 	Q_INIT_RESOURCE( guidoar );
76 #endif
77 
78  	QCoreApplication::setOrganizationName(COMPANY_NAME);
79 	QCoreApplication::setApplicationName(APP_NAME);
80 
81 	installGuidoFont();
82 
83 	GraphicsSceneMainWindowSettings s;
84 	s.mLanguageNameLong = "Guido Music Notation";
85 	s.mLanguageNameShort = "Guido";
86 	s.mLanguageFileExtension = "gmn";
87 	s.mSceneFileExtension = "gsc";
88 	s.mDefaultLanguageCode = "[\\meter<\"4/4\"> c2 b1 a g f e d c]";
89 	s.mLanguageCommandsFile = ":/GuidoCommands.xml";
90 #ifdef USES_GUIDO_AR
91 	s.mHasStorage = true;
92 	s.mHasHistory = true;
93 #else
94 	s.mHasStorage = false;
95 	s.mHasHistory = false;
96 #endif
97 	s.mMaxItemSize = QSize(200,200);
98 
99 	GraphicsSceneMainWindow::initApplicationSettings( s );
100 	MainWindow mainWin;
101 	QApplication::instance()->installEventFilter( &mainWin );
102 
103 	if ( argc >= 2 )
104 	{
105 		QString fileName( argv[1] );
106 		QFileOpenEvent fileOpenEvent( fileName );
107 		QApplication::sendEvent( &mainWin , &fileOpenEvent );
108 	}
109 
110 	mainWin.show();
111 	int result = app.exec();
112 	return result;
113 }
114