##// END OF EJS Templates
added QProgressBar auto deleter like QMutexLocker.
jeandet -
r14:e48ea0bd6fcc default
parent child
Show More
@@ -1,231 +1,232
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "socexplorerengine.h"
23 23 #include <proxy/socexplorerproxy.h>
24 24
25 25 SocExplorerEngine* SocExplorerEngine::_self = NULL;
26 26 socExplorerXmlModel* SocExplorerEngine::p_xmlmodel=NULL;
27 27 QMainWindow* SocExplorerEngine::mainWindow=NULL;
28 28 QList<SOCModel*>* SocExplorerEngine::SOCs=NULL;
29 29 int SocExplorerEngine::loglvl=1;
30 30
31 31 SocExplorerEngine::SocExplorerEngine(QObject *parent) :
32 32 QObject(parent)
33 33 {
34 34 if(SOCs==NULL)
35 35 {
36 36 SOCs = new QList<SOCModel*>;
37 37 }
38 38
39 39 }
40 40
41 41
42 42 void SocExplorerEngine::init()
43 43 {
44 44 QDir dir;
45 45 if(!_self)
46 46 {
47 47 _self= new SocExplorerEngine;
48 48 }
49 49 if(!dir.exists(configFolder()))
50 50 dir.mkdir(configFolder());
51 51 p_xmlmodel = new socExplorerXmlModel(_self);
52 52 p_xmlmodel->updateSOClist();
53 53 }
54 54
55 55 QString SocExplorerEngine::configFolder()
56 56 {
57 57 return QString(SOCEXPLORER_CONFIG_PATH);
58 58 }
59 59
60 60 SOCModel *SocExplorerEngine::plugin2Soc(socexplorerplugin *plugin)
61 61 {
62 62 if(!_self)
63 63 init();
64 64 if(plugin)
65 65 {
66 66 while (plugin->parent!=NULL) {
67 67 plugin = plugin->parent;
68 68 }
69 69 for(int i=0;i<SOCs->count();i++)
70 70 {
71 71 if(SOCs->at(i)->isRootDev(plugin))
72 72 return SOCs->at(i);
73 73 }
74 74 //no soc found so create a new one
75 75 SOCModel* soc=new SOCModel(plugin);
76 76 SOCs->append(soc);
77 77 return soc;
78 78 }
79 79 return NULL;
80 80 }
81 81
82 82
83 83 int SocExplorerEngine::addEnumDevice(socexplorerplugin* rootPlugin,int VID, int PID, qint32 baseAddress, const QString &name)
84 84 {
85 85 if(!_self)
86 86 init();
87 87 SOCModel* soc = plugin2Soc(rootPlugin);
88 88 if(soc && !soc->enumDeviceExists(baseAddress))
89 89 {
90 90 emit _self->enumDeviceAdded(soc->addEnumDevice(VID,PID,baseAddress,name));
91 91 return 1;
92 92 }
93 93 return 0;
94 94 }
95 95
96 96 QList<SOCModel *> *SocExplorerEngine::getSOCs()
97 97 {
98 98 if(!_self)
99 99 init();
100 100 return SOCs;
101 101 }
102 102
103 103 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(const QString& rootPlugin,int VID, int PID, int count)
104 104 {
105 105 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
106 106 if(plugin==NULL)return -1;
107 107 SOCModel* soc = plugin2Soc(plugin);
108 108 if(soc==NULL)
109 109 return -1;
110 110 return soc->getEnumDeviceBaseAddress(VID,PID,count);
111 111 }
112 112
113 113 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(socexplorerplugin *plugin, int VID, int PID, int count)
114 114 {
115 115 if(plugin==NULL)return -1;
116 116 SOCModel* soc = plugin2Soc(plugin);
117 117 if(soc==NULL)
118 118 return -1;
119 119 return soc->getEnumDeviceBaseAddress(VID,PID,count);
120 120 }
121 121
122 122 int SocExplorerEngine::addEnumDevice(const QString &rootPlugin, int VID, int PID, qint32 baseAddress, const QString &name)
123 123 {
124 124 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
125 125 if(plugin==NULL)return -1;
126 126 SOCModel* soc = plugin2Soc(plugin);
127 127 if(soc==NULL)
128 128 return -1;
129 129 soc->addEnumDevice(VID,PID,baseAddress,name);
130 130 return 1;
131 131 }
132 132
133 133
134 134 QString SocExplorerEngine::getDevName(int VID, int PID)
135 135 {
136 136 QList<QDomNodeList> list=p_xmlmodel->getAllNodes("peripheral");
137 137 for(int i=0;i<list.count();i++)
138 138 {
139 139 QDomNodeList nodes=list.at(i);
140 140 for(int l=0;l<nodes.count();l++)
141 141 {
142 142 QDomElement node=nodes.at(l).toElement();
143 143 int nodeVID=node.attribute("vid","0").toInt();
144 144 int nodePID=node.attribute("pid","0").toInt();
145 145 if((nodeVID==VID)&&(nodePID==PID))
146 146 {
147 147 return node.attribute("name","Unknow device");
148 148 }
149 149 }
150 150 }
151 151 return QString("Unknow device");
152 152 }
153 153
154 154 QString SocExplorerEngine::SocExplorerVersion(){return QString(SOCEXPLORER_VERSION);}
155 155
156 156 QString SocExplorerEngine::SocExplorerChangeset(){return QString(SOCEXPLORER_CHAGESET).split(" ").at(0);}
157 157
158 158 QString SocExplorerEngine::SocExplorerBranch(){return QString(SOCEXPLORER_BRANCH);}
159 159
160 160 socExplorerXmlModel *SocExplorerEngine::xmlModel()
161 161 {
162 162 if(!_self)
163 163 init();
164 164 return p_xmlmodel;
165 165 }
166 166
167 167 void SocExplorerEngine::setMainWindow(QMainWindow *Mainwindow)
168 168 {
169 169 if(!_self)
170 170 init();
171 171 mainWindow=Mainwindow;
172 172 }
173 173
174 174 QProgressBar *SocExplorerEngine::getProgressBar(const QString& format, int max)
175 175 {
176 176 if(!_self)
177 177 init();
178 178 QProgressBar* progressBar;
179 179 if(mainWindow!=NULL)
180 180 {
181 181 progressBar = new QProgressBar(mainWindow);
182 182 mainWindow->statusBar()->addWidget(progressBar);
183 183 }
184 184 else
185 185 {
186 186 progressBar = new QProgressBar();
187 187 }
188 188 progressBar->setMaximum(max);
189 189 progressBar->setFormat(format);
190 190 return progressBar;
191 191 }
192 192
193 193 void SocExplorerEngine::deleteProgressBar(QProgressBar *progressBar)
194 194 {
195 195 if(mainWindow!=NULL)
196 196 {
197 197 mainWindow->statusBar()->removeWidget(progressBar);
198 198 }
199 199 delete progressBar;
200 200 }
201 201
202 202 void SocExplorerEngine::addSOC(socexplorerplugin *rootPlugin)
203 203 {
204 204 plugin2Soc(rootPlugin);
205 205 }
206 206
207 207 void SocExplorerEngine::removeSOC(socexplorerplugin *rootPlugin)
208 208 {
209 209 SOCModel* soc=plugin2Soc(rootPlugin);
210 210 SOCs->removeAll(soc);
211 211 delete soc;
212 212 }
213 213
214 214 void SocExplorerEngine::message(socexplorerplugin *sender, const QString &message, int debugLevel)
215 215 {
216 216 // TODO add multi output message manager IE also log in files
217 217 if(!_self)
218 218 init();
219 219 if(loglvl>=debugLevel)
220 220 qDebug()<< QTime::currentTime().toString()+" " + sender->instanceName()+":"+message;
221 221 }
222 222
223 223 void SocExplorerEngine::setLogLevel(int level)
224 224 {
225 225 if(!_self)
226 226 init();
227 printf("Set log level to %d\n",level);
227 228 loglvl = level;
228 229 }
229 230
230 231
231 232
@@ -1,109 +1,134
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef SOCEXPLORERENGINE_H
23 23 #define SOCEXPLORERENGINE_H
24 24
25 25 #include <stdint.h>
26 26 #include <QObject>
27 27 #include <QtWidgets>
28 28 #include <QStringList>
29 29 #include <QDomDocument>
30 30 #include <QDomElement>
31 31 #include <QDomNodeList>
32 32 #include <QFile>
33 33 #include <QTextStream>
34 34 #include <QDir>
35 35 #include <QApplication>
36 36 #include <QtCore/qglobal.h>
37 37 #include <QFileDialog>
38 38 #include <socexplorerxmlfile.h>
39 39 #include <socexplorerenumdevice.h>
40 40 #include <XMLmodel.h>
41 41 #include <peripheralwidget.h>
42 42 #include <registerwidget.h>
43 43 #include <socmodel.h>
44 44
45 45 #if defined(SOCEXPLORER_SDK_BUILD)
46 46 # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT
47 47 #else
48 48 # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT
49 49 #endif
50 50
51 51
52 class SOCEXPLORER_SDK_EXPORT SocExplorerAutoProgressBar
53 {
54 public:
55 SocExplorerAutoProgressBar(QProgressBar* progressBar=NULL)
56 {
57 this->p_progressbar=progressBar;
58 }
59 ~SocExplorerAutoProgressBar()
60 {
61 if(p_progressbar)
62 {
63 delete p_progressbar;
64 }
65 }
66 void setProgressBar(QProgressBar* progressBar)
67 {
68 this->p_progressbar=progressBar;
69 }
70 void setValue(int value)
71 {
72 p_progressbar->setValue(value);
73 }
74 private:
75 QProgressBar* p_progressbar;
76 };
52 77
53 78 //! SocExplorerEngine is a pure static class which aims to provide services for both SocExplorer software and plugins.
54 79
55 80 class SOCEXPLORER_SDK_EXPORT SocExplorerEngine : public QObject
56 81 {
57 82 Q_OBJECT
58 83 private:
59 84 static SocExplorerEngine* _self;
60 85 SocExplorerEngine(QObject *parent = 0);
61 86 static void init();
62 87
63 88 public:
64 89 static SocExplorerEngine* self(){ if(!_self){_self= new SocExplorerEngine;}return _self;}
65 90 //! Return the configuration folder path, OS dependant.
66 91 SOCEXPLORER_SDK_EXPORT static QString configFolder();
67 92 //! Return the default plugin folder path, OS dependant.
68 93 static QString pluginFolder(){return QString(SOCEXPLORER_PLUGINS_INSTALL_PATH);}
69 94
70 95 static int addEnumDevice(socexplorerplugin* rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
71 96 static QList<SOCModel*>* getSOCs();
72 97 static QString getDevName(int VID, int PID);
73 98 static QString SocExplorerVersion();
74 99 static QString SocExplorerChangeset();
75 100 static QString SocExplorerBranch();
76 101 static socExplorerXmlModel* xmlModel();
77 102 static void setMainWindow(QMainWindow* Mainwindow);
78 103 static QProgressBar* getProgressBar(const QString &format, int max);
79 104 static void deleteProgressBar(QProgressBar* progressBar);
80 105 static void addSOC(socexplorerplugin* rootPlugin);
81 106 static void removeSOC(socexplorerplugin* rootPlugin);
82 107 static void message(socexplorerplugin* sender,const QString& message,int debugLevel=0);
83 108 static void setLogLevel(int level);
84 109 signals:
85 110 void enumDeviceAdded(socExplorerEnumDevice* device);
86 111 public slots:
87 112 QString getSocExplorerVersion(){return SocExplorerEngine::SocExplorerVersion();}
88 113 QString getSocExplorerChangeset(){return SocExplorerEngine::SocExplorerChangeset();}
89 114 QString getSocExplorerBranch(){return SocExplorerEngine::SocExplorerBranch();}
90 115 qint32 getEnumDeviceBaseAddress(const QString& rootPlugin,int VID,int PID,int count=0);
91 116 qint32 getEnumDeviceBaseAddress(socexplorerplugin* plugin,int VID,int PID,int count=0);
92 117 int addEnumDevice(const QString& rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
93 118
94 119 private:
95 120 static SOCModel* plugin2Soc(socexplorerplugin* plugin);
96 121 static socExplorerXmlModel* p_xmlmodel;
97 122 static QMainWindow* mainWindow;
98 123 static QList<SOCModel*>* SOCs;
99 124 static int loglvl;
100 125 };
101 126
102 127 #endif // SOCEXPLORERENGINE_H
103 128
104 129
105 130
106 131
107 132
108 133
109 134
@@ -1,69 +1,71
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include <QApplication>
23 23 #include "mainwindow.h"
24 24 #include <PythonQt.h>
25 25 #include <PythonQt_QtAll.h>
26 26 #include <gui/PythonQtScriptingConsole.h>
27 27 #include <socexplorerplugin.h>
28 28 #include <QStyle>
29 29 #include <QStyleFactory>
30 30 #include <QStringList>
31 31 #include <QFile>
32 32
33 33
34 34 int main(int argc, char *argv[])
35 35 {
36 36 // Q_INIT_RESOURCE(socexplorer);
37 37 #ifdef Q_OS_LINUX
38 38 // QApplication::setGraphicsSystem("raster");
39 39 #endif
40 40 QApplication a(argc, argv);
41 41 QString scriptToEval;
42 42 QStringList args= a.arguments();
43 43 for(int i=0;i<args.count()-1;i++)
44 44 {
45 45 if((args.at(i).compare("-e")==0) || (args.at(i).compare("--execute")==0))
46 46 {
47 47 scriptToEval = args.at(i+1);
48 48 if(!QFile::exists(scriptToEval))
49 49 {
50 50 scriptToEval.clear();
51 51 }
52 52 else
53 53 qDebug() << "Will execute" << scriptToEval;
54 54 break;
55 55 }
56 56 if((args.at(i).compare("-d")==0) || (args.at(i).compare("--debug-level")==0))
57 57 {
58 58 bool success;
59 59 int lvl;
60 60 lvl = args.at(i+1).toInt(&success,10);
61 61 if(success)
62 {
62 63 SocExplorerEngine::setLogLevel(lvl);
64 }
63 65 }
64 66 }
65 67
66 68 SocExplorerMainWindow w(scriptToEval);
67 69 w.show();
68 70 return a.exec();
69 71 }
General Comments 0
You need to be logged in to leave comments. Login now