1 /******************************************************************* 2 3 Part of the Fritzing project - http://fritzing.org 4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de 5 6 Fritzing 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 3 of the License, or 9 (at your option) any later version. 10 11 Fritzing 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. 15 16 You should have received a copy of the GNU General Public License 17 along with Fritzing. If not, see <http://www.gnu.org/licenses/>. 18 19 ******************************************************************** 20 21 $Revision: 6940 $: 22 $Author: irascibl@gmail.com $: 23 $Date: 2013-03-26 14:00:34 +0100 (Di, 26. Mrz 2013) $ 24 25 ********************************************************************/ 26 27 #ifndef FAPPLICATION_H 28 #define FAPPLICATION_H 29 30 #include <QApplication> 31 #include <QTranslator> 32 #include <QPixmap> 33 #include <QFileDialog> 34 #include <QPointer> 35 #include <QWidget> 36 #include <QTimer> 37 #include <QTcpServer> 38 #include <QTcpSocket> 39 #include <QMutex> 40 #include <QThread> 41 #include <QNetworkReply> 42 #include <QNetworkAccessManager> 43 44 class FServer : public QTcpServer 45 { 46 Q_OBJECT 47 48 public: 49 FServer(QObject *parent = 0); 50 51 signals: 52 void newConnection(int socketDescriptor); 53 54 protected: 55 void incomingConnection(int socketDescriptor); 56 }; 57 58 class FServerThread : public QThread 59 { 60 Q_OBJECT 61 62 public: 63 FServerThread(int socketDescriptor, QObject *parent); 64 65 void run(); 66 void setDone(); 67 68 signals: 69 void error(QTcpSocket::SocketError socketError); 70 void doCommand(const QString & command, const QString & params, QString & result, int & status); 71 72 protected: 73 void writeResponse(QTcpSocket *, int code, const QString & codeString, const QString & mimeType, const QString & message); 74 75 protected: 76 int m_socketDescriptor; 77 bool m_done; 78 79 protected: 80 static QMutex m_busy; 81 82 }; 83 84 class FApplication : public QApplication 85 { 86 Q_OBJECT 87 88 public: 89 FApplication(int & argc, char ** argv); 90 ~FApplication(void); 91 92 public: 93 bool init(); 94 int startup(); 95 int serviceStartup(); 96 void finish(); 97 class ReferenceModel * loadReferenceModel(const QString & databaseName, bool fullLoad); 98 void registerFonts(); 99 class MainWindow * openWindowForService(bool lockFiles, int initialTab); 100 bool runAsService(); 101 102 public: 103 static bool spaceBarIsPressed(); 104 105 signals: 106 void spaceBarIsPressedSignal(bool); 107 108 public slots: 109 void preferences(); 110 void preferencesAfter(); 111 void checkForUpdates(); 112 void checkForUpdates(bool atUserRequest); 113 void enableCheckUpdates(bool enabled); 114 void createUserDataStoreFolderStructure(); 115 void changeActivation(bool activate, QWidget * originator); 116 void updateActivation(); 117 void topLevelWidgetDestroyed(QObject *); 118 void closeAllWindows2(); 119 void loadedPart(int loaded, int total); 120 void externalProcessSlot(QString & name, QString & path, QStringList & args); 121 void gotOrderFab(QNetworkReply *); 122 void newConnection(int socketDescriptor); 123 void doCommand(const QString & command, const QString & params, QString & result, int & status); 124 125 protected: 126 bool eventFilter(QObject *obj, QEvent *event); 127 bool event(QEvent *event); 128 bool findTranslator(const QString & translationsPath); 129 void loadNew(QString path); 130 void loadOne(class MainWindow *, QString path, int loaded); 131 void initSplash(class FSplashScreen & splash); 132 void registerFont(const QString &fontFile, bool reallyRegister); 133 void clearModels(); 134 bool notify(QObject *receiver, QEvent *e); 135 void initService(); 136 void runDRCService(); 137 void runGedaService(); 138 void runDatabaseService(); 139 void runKicadFootprintService(); 140 void runKicadSchematicService(); 141 void runGerberService(); 142 void runGerberServiceAux(); 143 void runSvgService(); 144 void runSvgServiceAux(); 145 void runPanelizerService(); 146 void runInscriptionService(); 147 void runExampleService(); 148 void runExampleService(QDir &); 149 QList<class MainWindow *> recoverBackups(); 150 QList<MainWindow *> loadLastOpenSketch(); 151 void doLoadPrevious(MainWindow *); 152 void loadSomething(const QString & previousVersion); 153 void initFilesToLoad(); 154 void initBackups(); 155 void cleanupBackups(); 156 void updatePrefs(class PrefsDialog & prefsDialog); 157 QList<MainWindow *> orderedTopLevelMainWindows(); 158 void cleanFzzs(); 159 void initServer(); 160 161 enum ServiceType { 162 PanelizerService = 1, 163 InscriptionService, 164 GerberService, 165 GedaService, 166 KicadSchematicService, 167 KicadFootprintService, 168 ExampleService, 169 DatabaseService, 170 SvgService, 171 PortService, 172 DRCService, 173 NoService 174 }; 175 176 protected: 177 bool m_spaceBarIsPressed; 178 bool m_mousePressed; 179 QTranslator m_translator; 180 class ReferenceModel * m_referenceModel; 181 bool m_started; 182 QStringList m_filesToLoad; 183 QString m_libPath; 184 QString m_translationPath; 185 class UpdateDialog * m_updateDialog; 186 QTimer m_activationTimer; 187 QPointer<class FritzingWindow> m_lastTopmostWindow; 188 QList<QWidget *> m_orderedTopLevelWidgets; 189 QStringList m_arguments; 190 QStringList m_externalProcessArgs; 191 QString m_externalProcessName; 192 QString m_externalProcessPath; 193 ServiceType m_serviceType; 194 int m_progressIndex; 195 class FSplashScreen * m_splash; 196 QString m_outputFolder; 197 QString m_portRootFolder; 198 QString m_panelFilename; 199 QHash<QString, struct LockedFile *> m_lockedFiles; 200 bool m_panelizerCustom; 201 int m_portNumber; 202 FServer * m_fServer; 203 QString m_buildType; 204 }; 205 206 207 #endif 208