Debian Codegraph @

src/main.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2008, 2009 Andres Cabrera
3 [email protected]
4
5 This file is part of CsoundQt.
6
7 CsoundQt is free software; you can redistribute it
8 and/or modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 CsoundQt is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with Csound; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA
21 */
22
23 #include <QApplication>
24 #include <QSplashScreen>
25 #include "qutecsound.h"
26 #include <QLocalSocket>
27
28 #ifdef WIN32
29 #include <tchar.h>
30 #include <windows.h>
31
32 namespace {
33
34 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
35 LPFN_ISWOW64PROCESS fnIsWow64Process;
36
37 } // namespace
38
39 // Detect whether the operating system is a 64-bit.
40 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684139%28v=vs.85%29.aspx
41 BOOL IsWow64() {
42 BOOL bIsWow64 = FALSE;
43 fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
44 GetModuleHandle(TEXT("kernel32")),
45 "IsWow64Process");
46 if (NULL != fnIsWow64Process) {
47 if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) {
48 // handle error
49 }
50 }
51 return bIsWow64;
52 }
53 #endif
54
55 int main(int argc, char *argv[])
56 {
57 int result = 0;
58
59 // Set a global template for ALL qDebug messages.
60 qSetMessagePattern("[%{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}][%{file}:%{line} %{function}] %{message}");
61
62
63 #ifdef USE_QT_GT_55
64 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // TO test if this solved hight DPI problems
65 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
66 #endif
67 QStringList fileNames;
68 QApplication qapp(argc, argv);
69
70 #ifdef Q_OS_OSX
71 if (csoundGetVersion()<6090) { // this build does not work with older Csound on OSX
72 qDebug()<<"Csound version too old: "<< VERSION;
73 QMessageBox::warning(NULL, QObject::tr("Csound version mismatch"), QObject::tr("This version of CsoundQt requires Csound 6.09 or newer. Please download it from <br>") +"<a href=http://csound.github.io/download>http://csound.github.io/download</a>" );
74 return(0);
75 }
76 #endif
77
78 bool autoplay = false;
79 QStringList args = qapp.arguments();
80 args.removeAt(0); // Remove program name
81 for(int i=0; i < args.size(); i++) {
82 auto arg = args[i];
83 if(arg == "--help") {
84 QTextStream out(stdout);
85 out << "\n\n";
86 out << "Options:" << endl;
87 out << " --play Autoplay the last file passed via command line" << endl;
88 out << " --help This message" << endl;
89 out << endl;
90 exit(0);
91 }
92 if(arg == "--play") {
93 autoplay = true;
94 }
95 }
96
97 foreach (QString arg, args) {
98 if (!arg.startsWith("-")) {// avoid OS X arguments
99 fileNames.append(arg);
100 }
101 }
102 // check if another instance is already running. If yes, ask it to open the file in new tab and quit
103 QLocalSocket * socket = new QLocalSocket();
104 socket->connectToServer("csoundqt");
105 if (socket->waitForConnected(500)) {
106 // wait for max 0.5 seconds, returns true if the server in other instance is listening
107 if (!fileNames.isEmpty()) {
108 qDebug()<<"Opening file(s) in already running instance";
109 QString message = "open ***" + fileNames.join("***"); // use a separator that is probably not in the file name
110 socket->write(message.toLocal8Bit());
111 socket->waitForBytesWritten(1000);
112 socket->close();
113 return 0; // exit and leave the other instance open the file
114 } else {
115 socket->close();
116 //qDebug()<<"Another instance already running.";
117 int answer = QMessageBox::warning(NULL, QObject::tr("CsoundQt"),
118 QObject::tr("Another instance is already running. "
119 "Are you sure you want to open a new"
120 " window?"),
121 QMessageBox::Open|QMessageBox::Cancel,
122 QMessageBox::Cancel);
123 if (answer==QMessageBox::Cancel) {
124 return 0;
125 }
126 }
127 }
128 // forming filenames was here before. now before localSocket
129 FileOpenEater filterObj;
130 qapp.installEventFilter(&filterObj);
131
132 #ifdef QCS_USE_NEW_ICON
133 QPixmap pixmap(":/images/splashscreen-alt.png");
134 #else
135 QPixmap pixmap(":/images/splashscreen.png");
136 #endif
137
138 QSplashScreen *splash = new QSplashScreen(pixmap);
139 splash->showMessage(QString("Version %1").arg(QCS_VERSION),
140 Qt::AlignCenter | Qt::AlignBottom, Qt::white);
141 splash->show();
142 splash->raise();
143 qapp.processEvents();
144 QSettings qsettings("csound", "qutecsound");
145 qsettings.beginGroup("GUI");
146 QString language = qsettings.value("language", QLocale::system().name()).toString();
147 qsettings.endGroup();
148 QTranslator translator;
149 translator.load(QString(":/translations/qutecsound_") + language);
150 qapp.installTranslator(&translator);
151 CsoundQt *csoundQt = new CsoundQt(fileNames);
152 if (!csoundQt->startServer())
153 qDebug()<<"Could not start local server.";
154 splash->finish(csoundQt);
155 delete splash;
156 csoundQt->show();
157 if(autoplay && !fileNames.isEmpty())
158 csoundQt->play();
159
160 filterObj.setMainWindow(csoundQt);
161 QDEBUG << "Starting qapp exec";
162 result = qapp.exec();
163 return result;
164 }