1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program 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 General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #include "QcApplication.h"
23 #include "widgets/QcTreeWidget.h"
26 #include <VMGlobals.h>
27 #include <PyrKernel.h>
32 #include <QFileOpenEvent>
35 extern bool compiledOK
;
37 QcApplication
* QcApplication::_instance
= 0;
38 QMutex
QcApplication::_mutex
;
45 /* on x11, we need to check, if we can actually connect to the X server */
46 static bool QtColliderUseGui(void)
49 Display
*dpy
= XOpenDisplay(NULL
);
59 QcApplication::QcApplication( int & argc
, char ** argv
)
60 : QApplication( argc
, argv
, QtColliderUseGui() )
65 qRegisterMetaType
<VariantList
>();
66 qRegisterMetaType
<QcTreeWidget::ItemPtr
>();
68 if (QtColliderUseGui()) { // avoid a crash on linux, if x is not available
70 icon
.addFile(":/icons/sc-cube-128");
71 icon
.addFile(":/icons/sc-cube-48");
72 icon
.addFile(":/icons/sc-cube-32");
73 icon
.addFile(":/icons/sc-cube-16");
78 QcApplication::~QcApplication()
85 bool QcApplication::compareThread()
92 same
= QThread::currentThread() == _instance
->thread();
101 void QcApplication::interpret( const QString
&str
, bool print
)
103 QtCollider::lockLang();
105 VMGlobals
*g
= gMainVMGlobals
;
107 PyrString
*strObj
= newPyrString( g
->gc
, str
.toStdString().c_str(), 0, true );
109 SetObject(&slotRawInterpreter(&g
->process
->interpreter
)->cmdLine
, strObj
);
110 g
->gc
->GCWrite(slotRawObject(&g
->process
->interpreter
), strObj
);
112 runLibrary( print
? QtCollider::s_interpretPrintCmdLine
: QtCollider::s_interpretCmdLine
);
114 QtCollider::unlockLang();
117 bool QcApplication::event( QEvent
*e
)
119 if( e
->type() == QEvent::FileOpen
) {
120 // open the file dragged onto the application icon on Mac
121 QFileOpenEvent
*fe
= static_cast<QFileOpenEvent
*>(e
);
122 interpret( QString("Document.open(\"%1\")").arg(fe
->file()), false );
127 return QApplication::event( e
);