3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
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 2 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "settings/manager.hpp"
23 #include "session_manager.hpp"
24 #include "../widgets/main_window.hpp"
25 #include "../widgets/code_editor/highlighter.hpp"
26 #include "SC_DirUtils.h"
28 #include <QApplication>
31 #include <QDataStream>
33 #include <QFileOpenEvent>
34 #include <QLibraryInfo>
35 #include <QTranslator>
37 using namespace ScIDE
;
39 int main( int argc
, char *argv
[] )
41 QApplication
app(argc
, argv
);
43 QStringList
arguments (QApplication::arguments());
44 arguments
.pop_front(); // application path
46 SingleInstanceGuard guard
;
47 if (!arguments
.empty()) {
48 if (guard
.tryConnect(arguments
))
52 QTranslator qtTranslator
;
53 qtTranslator
.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath
));
54 app
.installTranslator(&qtTranslator
);
56 QTranslator scideTranslator
;
57 scideTranslator
.load("scide_" + QLocale::system().name());
58 app
.installTranslator(&scideTranslator
);
60 Main
* main
= Main::instance();
62 MainWindow
*win
= new MainWindow(main
);
64 // NOTE: load session after GUI is created, so that GUI can respond
65 QString lastSession
= main
->sessionManager()->lastSession();
66 if (!lastSession
.isEmpty()) {
67 main
->sessionManager()->openSession(lastSession
);
71 main
->sessionManager()->newSession();
75 foreach (QString argument
, arguments
) {
76 main
->documentManager()->open(argument
);
79 bool startInterpreter
= main
->settings()->value("IDE/interpreter/autoStart").toBool();
81 main
->scProcess()->start();
87 bool SingleInstanceGuard::tryConnect(QStringList
const & arguments
)
89 QLocalSocket
* mSocket
= new QLocalSocket(this);
90 mSocket
->connectToServer("SuperColliderIDESingleton");
91 if (mSocket
->waitForConnected(500)) {
92 QDataStream
stream(mSocket
);
93 stream
.setVersion(QDataStream::Qt_4_6
);
95 stream
<< QString("open");
102 mIpcServer
= new QLocalServer(this);
103 mIpcServer
->listen("SuperColliderIDESingleton");
104 connect(mIpcServer
, SIGNAL(newConnection()), this, SLOT(onNewIpcConnection()));
108 void SingleInstanceGuard::onIpcData()
110 QByteArray ipcData
= mIpcSocket
->readAll();
112 QBuffer
receivedData ( &ipcData
);
113 receivedData
.open ( QIODevice::ReadOnly
);
115 QDataStream
in ( &receivedData
);
116 in
.setVersion ( QDataStream::Qt_4_6
);
119 if ( in
.status() != QDataStream::Ok
)
124 if ( in
.status() != QDataStream::Ok
)
127 if (id
== QString("open")) {
128 foreach (QString path
, message
)
129 Main::instance()->documentManager()->open(path
);
134 static QString
getSettingsFile()
136 char config_dir
[PATH_MAX
];
137 sc_GetUserConfigDirectory(config_dir
, PATH_MAX
);
138 return QString(config_dir
) + SC_PATH_DELIMITER
+ "sc_ide_conf.yaml";
141 // NOTE: mSettings must be the first to initialize,
142 // because other members use it!
145 mSettings( new Settings::Manager( getSettingsFile(), this ) ),
146 mSCResponder( new ScResponder(this) ),
147 mSCProcess( new SCProcess(this) ),
148 mSCServer( new ScServer(this) ),
149 mDocManager( new DocumentManager(this) ),
150 mSessionManager( new SessionManager(mDocManager
, this) )
152 new SyntaxHighlighterGlobals(this);
154 connect(mSCProcess
, SIGNAL(response(QString
,QString
)), mSCResponder
, SLOT(onResponse(QString
,QString
)));
155 connect(mSCResponder
, SIGNAL(serverRunningChanged(bool,QString
,int)), mSCServer
, SLOT(onServerRunningChanged(bool,QString
,int)));
157 qApp
->installEventFilter(this);
161 mSessionManager
->saveSession();
163 QApplication::quit();
166 bool Main::eventFilter(QObject
*object
, QEvent
*event
)
168 if (event
->type() == QEvent::FileOpen
) {
169 // open the file dragged onto the application icon on Mac
170 QFileOpenEvent
*openEvent
= static_cast<QFileOpenEvent
*>(event
);
171 mDocManager
->open(openEvent
->file());
174 return QObject::eventFilter(object
, event
);