1 /************************************************************************** 2 ** This file is part of LiteIDE 3 ** 4 ** Copyright (c) 2011-2019 LiteIDE. All rights reserved. 5 ** 6 ** This library is free software; you can redistribute it and/or 7 ** modify it under the terms of the GNU Lesser General Public 8 ** License as published by the Free Software Foundation; either 9 ** version 2.1 of the License, or (at your option) any later version. 10 ** 11 ** This library 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 GNU 14 ** Lesser General Public License for more details. 15 ** 16 ** In addition, as a special exception, that plugins developed for LiteIDE, 17 ** are allowed to remain closed sourced and can be distributed under any license . 18 ** These rights are included in the file LGPL_EXCEPTION.txt in this package. 19 ** 20 **************************************************************************/ 21 // Module: envmanager.h 22 // Creator: visualfc <visualfc@gmail.com> 23 24 #ifndef ENVMANAGER_H 25 #define ENVMANAGER_H 26 27 #include "liteenvapi/liteenvapi.h" 28 29 class QComboBox; 30 31 class EnvManager; 32 class GoEnvManager; 33 class Process; 34 class Env : public LiteApi::IEnv 35 { 36 Q_OBJECT 37 public: 38 Env(LiteApi::IApplication *app, QObject *parent = 0); 39 public: 40 virtual QString id() const; 41 virtual QString filePath() const; 42 virtual QProcessEnvironment& environment(); 43 virtual QStringList orgEnvLines() const; 44 virtual QMap<QString,QString> goEnvMap() const; 45 virtual void reload(); 46 void loadGoEnv(); 47 public: 48 void loadEnvFile(QIODevice *dev); 49 static void loadEnv(EnvManager *manager, const QString &filePath); 50 protected slots: 51 void readStdout(); 52 void readStderr(); 53 void finished(int code, QProcess::ExitStatus); 54 void error(QProcess::ProcessError error); 55 protected: 56 void updateIdeEnv(QProcessEnvironment &env); 57 protected: 58 LiteApi::IApplication *m_liteApp; 59 QString m_filePath; 60 QStringList m_orgEnvLines; 61 QString m_id; 62 QProcessEnvironment m_env; 63 QMap<QString,QString> m_ideEnvMap; 64 QMap<QString,QString> m_goEnvMap; 65 Process *m_process; 66 }; 67 68 class EnvManager : public LiteApi::IEnvManager 69 { 70 Q_OBJECT 71 public: 72 EnvManager(QObject *parent = 0); 73 ~EnvManager(); 74 public: 75 virtual bool initWithApp(LiteApi::IApplication *app); 76 virtual QList<LiteApi::IEnv*> envList() const; 77 virtual LiteApi::IEnv *findEnv(const QString &id, const QString &backup = "system") const; 78 virtual void setCurrentEnvId(const QString &id); 79 virtual LiteApi::IEnv *currentEnv() const; 80 virtual QProcessEnvironment currentEnvironment() const; 81 protected slots: 82 virtual void reloadCurrentEnv(); 83 void appLoaded(); 84 void envActivated(QString); 85 void editCurrentEnv(); 86 void editorSaved(LiteApi::IEditor*); 87 void goenvError(const QString &id, const QString &msg); 88 void goenvChanged(const QString &id); 89 void selectEnvAction(QAction* act); 90 public: 91 void setCurrentEnv(LiteApi::IEnv *env); 92 void addEnv(LiteApi::IEnv *build); 93 void removeEnv(LiteApi::IEnv *build); 94 void loadEnvFiles(const QString &path); 95 void emitEnvChanged(); 96 public slots: 97 void broadcast(QString module, QString id, QVariant); 98 protected: 99 QList<LiteApi::IEnv*> m_envList; 100 LiteApi::IEnv *m_curEnv; 101 QToolBar *m_toolBar; 102 QComboBox *m_envCmb; 103 bool m_appLoaded; 104 GoEnvManager *m_goEnvManager; 105 QActionGroup *m_selectActionGroup; 106 }; 107 108 #endif // ENVMANAGER_H 109