Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / editors / sc-ide / core / main.hpp
blobce0522afdcce7ff8940560459408b13588279acb
1 /*
2 SuperCollider Qt IDE
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
21 #ifndef SCIDE_MAIN_HPP_INCLUDED
22 #define SCIDE_MAIN_HPP_INCLUDED
24 #include <QAction>
25 #include <QObject>
27 #include <QtNetwork/QLocalSocket>
28 #include <QtNetwork/QLocalServer>
30 #include "sc_process.hpp"
31 #include "sc_server.hpp"
32 #include "doc_manager.hpp"
33 #include "settings/manager.hpp"
35 namespace ScIDE {
37 class SessionManager;
39 // scide instances have a LocalServer. when called with an argument, it will try to reconnect
40 // to the instance with the lowest number.
41 class SingleInstanceGuard:
42 public QObject
44 Q_OBJECT
46 public:
47 bool tryConnect(QStringList const & arguments);
49 public Q_SLOTS:
50 void onNewIpcConnection()
52 mIpcSocket = mIpcServer->nextPendingConnection();
53 connect(mIpcSocket, SIGNAL(disconnected()), mIpcSocket, SLOT(deleteLater()));
54 connect(mIpcSocket, SIGNAL(readyRead()), this, SLOT(onIpcData()));
57 void onIpcData();
59 private:
60 QLocalServer * mIpcServer;
61 QLocalSocket * mIpcSocket;
64 class Main:
65 public QObject
67 Q_OBJECT
69 public:
70 static Main * instance(void)
72 static Main * singleton = new Main;
73 return singleton;
76 static SCProcess * scProcess() { return instance()->mSCProcess; }
77 static ScServer * scServer() { return instance()->mSCServer; }
78 static ScResponder * scResponder() { return instance()->mSCResponder; }
79 static SessionManager * sessionManager() { return instance()->mSessionManager; }
80 static DocumentManager * documentManager() { return instance()->mDocManager; }
81 static Settings::Manager *settings() { return instance()->mSettings; }
83 static void evaluateCode(QString const & text, bool silent = false)
85 instance()->scProcess()->evaluateCode(text, silent);
88 static bool openDocumentation(const QString & string)
90 // LATER: move to a new ScLanguage class
92 QString symbol = string.trimmed();
93 if (symbol.isEmpty())
94 return false;
96 QString code = QString("HelpBrowser.openHelpFor(\"%1\")").arg(symbol);
97 evaluateCode(code, true);
98 return true;
101 static bool openDocumentationForMethod(const QString & className, const QString & methodName)
103 QString code = QString("HelpBrowser.openHelpForMethod( %1.findMethod(\\%2) )").arg(className, methodName);
104 evaluateCode(code, true);
105 return true;
108 static void openDefinition(const QString &string, QWidget * parent);
109 static void findReferences(const QString &string, QWidget * parent);
111 public Q_SLOTS:
112 void storeSettings() {
113 Q_EMIT(storeSettingsRequest(mSettings));
114 mSettings->sync();
117 void applySettings() {
118 Q_EMIT(applySettingsRequest(mSettings));
121 void quit();
123 Q_SIGNALS:
124 void storeSettingsRequest(Settings::Manager *);
125 void applySettingsRequest(Settings::Manager *);
127 private:
128 Main(void);
129 bool eventFilter(QObject *obj, QEvent *event);
131 Settings::Manager *mSettings;
132 ScResponder * mSCResponder;
133 SCProcess * mSCProcess;
134 ScServer * mSCServer;
135 DocumentManager *mDocManager;
136 SessionManager *mSessionManager;
141 #endif