class library: Volume - remove debug message
[supercollider.git] / QtCollider / QcApplication.cpp
blob1c02025290f382411d18b73a6728d7fdf6b41062
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"
25 #include <PyrLexer.h>
26 #include <VMGlobals.h>
27 #include <PyrKernel.h>
28 #include <PyrSlot.h>
29 #include <GC.h>
31 #include <QThread>
32 #include <QFileOpenEvent>
33 #include <QIcon>
35 extern bool compiledOK;
37 QcApplication * QcApplication::_instance = 0;
38 QMutex QcApplication::_mutex;
40 #ifdef Q_WS_X11
41 #include <X11/Xlib.h>
42 #endif
45 /* on x11, we need to check, if we can actually connect to the X server */
46 static bool QtColliderUseGui(void)
48 #ifdef Q_WS_X11
49 Display *dpy = XOpenDisplay(NULL);
50 if (!dpy)
51 return false;
52 XCloseDisplay(dpy);
53 return true;
54 #else
55 return true;
56 #endif
59 QcApplication::QcApplication( int & argc, char ** argv )
60 : QApplication( argc, argv, QtColliderUseGui() )
62 _mutex.lock();
63 _instance = this;
64 _mutex.unlock();
65 qRegisterMetaType<VariantList>();
66 qRegisterMetaType<QcTreeWidget::ItemPtr>();
67 qRegisterMetaType< QVector<double> >();
68 qRegisterMetaType< QVector<int> >();
70 if (QtColliderUseGui()) { // avoid a crash on linux, if x is not available
71 QIcon icon;
72 icon.addFile(":/icons/sc-cube-128");
73 icon.addFile(":/icons/sc-cube-48");
74 icon.addFile(":/icons/sc-cube-32");
75 icon.addFile(":/icons/sc-cube-16");
76 setWindowIcon(icon);
80 QcApplication::~QcApplication()
82 _mutex.lock();
83 _instance = 0;
84 _mutex.unlock();
87 bool QcApplication::compareThread()
89 return gMainVMGlobals->canCallOS;
92 void QcApplication::interpret( const QString &str, bool print )
94 QtCollider::lockLang();
95 if( compiledOK ) {
96 VMGlobals *g = gMainVMGlobals;
98 PyrString *strObj = newPyrString( g->gc, str.toStdString().c_str(), 0, true );
100 SetObject(&slotRawInterpreter(&g->process->interpreter)->cmdLine, strObj);
101 g->gc->GCWrite(slotRawObject(&g->process->interpreter), strObj);
103 runLibrary( print ? SC_SYM(interpretPrintCmdLine) : SC_SYM(interpretCmdLine) );
105 QtCollider::unlockLang();
108 bool QcApplication::event( QEvent *e )
110 if( e->type() == QEvent::FileOpen ) {
111 // open the file dragged onto the application icon on Mac
112 QFileOpenEvent *fe = static_cast<QFileOpenEvent*>(e);
113 interpret( QString("Document.open(\"%1\")").arg(fe->file()), false );
115 return true;
118 return QApplication::event( e );