1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,237 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | #include "filedownloader.h" | |||
|
24 | #include <QFile> | |||
|
25 | #include <QIcon> | |||
|
26 | #include <qlopsettings.h> | |||
|
27 | #include <QHostInfo> | |||
|
28 | ||||
|
29 | FileDownloader* FileDownloader::_self=NULL; | |||
|
30 | QNetworkAccessManager* FileDownloader::m_WebCtrl=NULL; | |||
|
31 | QList<FileDownloaderTask*>* FileDownloader::m_pendingTasks=NULL; | |||
|
32 | QDockWidget* FileDownloader::m_gui=NULL; | |||
|
33 | DownLoadHistory* FileDownloader::m_DownLoadHistory=NULL; | |||
|
34 | FileDowloaderSettingsGUI* FileDownloader::m_SettingsGui=NULL; | |||
|
35 | QLopNetworkProxyFactory* FileDownloader::m_ProxyFactory=NULL; | |||
|
36 | ||||
|
37 | #define _INIT if(Q_UNLIKELY(_self==NULL)){ init();} | |||
|
38 | ||||
|
39 | ||||
|
40 | ||||
|
41 | int FileDownloader::downloadFile(QUrl fileUrl, const QString &name) | |||
|
42 | { | |||
|
43 | _INIT | |||
|
44 | if(QFile::exists(name)|| QFile::exists(name+".part")) | |||
|
45 | { | |||
|
46 | return -1; | |||
|
47 | } | |||
|
48 | int ID=_self->getTaskId(); | |||
|
49 | if(ID!=-1) | |||
|
50 | { | |||
|
51 | QNetworkRequest request(fileUrl); | |||
|
52 | QNetworkReply* reply = m_WebCtrl->head(request); | |||
|
53 | if(reply && (reply->error()==QNetworkReply::NoError)) | |||
|
54 | { | |||
|
55 | FileDownloaderTask*task=new FileDownloaderTask(reply,ID,name,_self); | |||
|
56 | m_pendingTasks->append(task); | |||
|
57 | connect(task, SIGNAL(gotHead(FileDownloaderTask*,QNetworkReply*)), _self, SLOT(gotHead(FileDownloaderTask*,QNetworkReply*))); | |||
|
58 | if(!_self->m_noGui) | |||
|
59 | { | |||
|
60 | m_DownLoadHistory->addElement(new DownloadHistoryElement(task)); | |||
|
61 | } | |||
|
62 | } | |||
|
63 | else | |||
|
64 | { | |||
|
65 | return -1; | |||
|
66 | } | |||
|
67 | } | |||
|
68 | return ID; | |||
|
69 | } | |||
|
70 | ||||
|
71 | int FileDownloader::downloadFile(QString fileUrl, const QString &name) | |||
|
72 | { | |||
|
73 | return downloadFile(QUrl(fileUrl),name); | |||
|
74 | } | |||
|
75 | ||||
|
76 | QDockWidget *FileDownloader::getGUI() | |||
|
77 | { | |||
|
78 | if(!_self->m_noGui && (m_gui==NULL)) | |||
|
79 | { | |||
|
80 | m_DownLoadHistory=new DownLoadHistory(); | |||
|
81 | m_gui=new QDockWidget("Download History"); | |||
|
82 | m_gui->setWidget(m_DownLoadHistory); | |||
|
83 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |||
|
84 | m_SettingsGui = new FileDowloaderSettingsGUI(); | |||
|
85 | QLopSettings::registerConfigEntry(this->m_SettingsGui,QIcon(":/img/Gnome-emblem-downloads.svg"),"Qlop Downloader"); | |||
|
86 | } | |||
|
87 | return (QDockWidget*) m_gui; | |||
|
88 | } | |||
|
89 | ||||
|
90 | const QString &FileDownloader::serviceName() | |||
|
91 | { | |||
|
92 | return m_serviceName; | |||
|
93 | } | |||
|
94 | ||||
|
95 | int FileDownloader::download_file(QUrl fileUrl, const QString &name) | |||
|
96 | { | |||
|
97 | return downloadFile(fileUrl,name); | |||
|
98 | } | |||
|
99 | ||||
|
100 | int FileDownloader::download_file(QString fileUrl, const QString &name) | |||
|
101 | { | |||
|
102 | return downloadFile(fileUrl,name); | |||
|
103 | } | |||
|
104 | ||||
|
105 | void FileDownloader::gotHead(FileDownloaderTask* task,QNetworkReply* headerreply) | |||
|
106 | { | |||
|
107 | QNetworkReply* reply; | |||
|
108 | QByteArray rangeHeaderValue; | |||
|
109 | bool acceptRestart=false; | |||
|
110 | int DownloadTotalFileSize = headerreply->header(QNetworkRequest::ContentLengthHeader).toInt(); | |||
|
111 | if (headerreply->hasRawHeader("Accept-Ranges")) | |||
|
112 | { | |||
|
113 | QString qstrAcceptRanges = headerreply->rawHeader("Accept-Ranges"); | |||
|
114 | acceptRestart = (qstrAcceptRanges.compare("bytes", Qt::CaseInsensitive) == 0); | |||
|
115 | rangeHeaderValue = "bytes=" + QByteArray::number(task->startPosition()) + "-"; | |||
|
116 | if (DownloadTotalFileSize > 0) | |||
|
117 | { | |||
|
118 | rangeHeaderValue += QByteArray::number(DownloadTotalFileSize); | |||
|
119 | } | |||
|
120 | } | |||
|
121 | QNetworkRequest request(headerreply->request()); | |||
|
122 | delete headerreply; | |||
|
123 | request.setRawHeader("Connection", "Keep-Alive"); | |||
|
124 | if(acceptRestart) | |||
|
125 | request.setRawHeader("Range", rangeHeaderValue); | |||
|
126 | request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); | |||
|
127 | reply = m_WebCtrl->get(request); | |||
|
128 | task->restart(reply,acceptRestart); | |||
|
129 | } | |||
|
130 | ||||
|
131 | void FileDownloader::configureProxy() | |||
|
132 | { | |||
|
133 | // QString proxyType = QLopSettings::value(FileDownloader::self(),"proxy/type","none").toString(); | |||
|
134 | // if(proxyType=="none") | |||
|
135 | // { | |||
|
136 | // QNetworkProxy proxy; | |||
|
137 | // proxy.setType(QNetworkProxy::Socks5Proxy); | |||
|
138 | // proxy.setHostName("proxy.example.com"); | |||
|
139 | // proxy.setPort(1080); | |||
|
140 | // proxy.setUser("username"); | |||
|
141 | // proxy.setPassword("password"); | |||
|
142 | // QNetworkProxy::setApplicationProxy(proxy); | |||
|
143 | // } | |||
|
144 | // QNetworkProxyQuery q(QUrl(QLatin1String("http://www.google.com"))); | |||
|
145 | // QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(q); | |||
|
146 | // foreach ( QNetworkProxy loopItem, proxies ) { | |||
|
147 | // qDebug() << "proxyUsed:" << loopItem.hostName(); | |||
|
148 | // } | |||
|
149 | // if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ) | |||
|
150 | // QNetworkProxy::setApplicationProxy(proxies[0]); | |||
|
151 | // else | |||
|
152 | // qDebug("No proxy server selected"); | |||
|
153 | } | |||
|
154 | ||||
|
155 | FileDownloaderTask* FileDownloader::getDownloadTask(int ID) | |||
|
156 | { | |||
|
157 | _INIT | |||
|
158 | for(int i=0;i<m_pendingTasks->count();i++) | |||
|
159 | { | |||
|
160 | if(m_pendingTasks->at(i)->ID()==ID) | |||
|
161 | return m_pendingTasks->at(i); | |||
|
162 | } | |||
|
163 | return NULL; | |||
|
164 | } | |||
|
165 | ||||
|
166 | bool FileDownloader::taskIsCompleted(int ID) | |||
|
167 | { | |||
|
168 | return getDownloadTask(ID)->downloadComplete(); | |||
|
169 | } | |||
|
170 | ||||
|
171 | FileDownloader *FileDownloader::self() | |||
|
172 | { | |||
|
173 | _INIT | |||
|
174 | ||||
|
175 | return _self; | |||
|
176 | ||||
|
177 | } | |||
|
178 | ||||
|
179 | void FileDownloader::reloadConfig() | |||
|
180 | { | |||
|
181 | m_ProxyFactory->reloadConfig(); | |||
|
182 | } | |||
|
183 | ||||
|
184 | int FileDownloader::getTaskId() | |||
|
185 | { | |||
|
186 | for(unsigned int i=0;i<INT_MAX;i++) | |||
|
187 | { | |||
|
188 | bool idValid=true; | |||
|
189 | for(int j=0;j<m_pendingTasks->count();j++) | |||
|
190 | { | |||
|
191 | if(m_pendingTasks->at(j)->ID()==(int)i) | |||
|
192 | idValid=false; | |||
|
193 | } | |||
|
194 | if(idValid) | |||
|
195 | return (int)i; | |||
|
196 | } | |||
|
197 | return -1; | |||
|
198 | } | |||
|
199 | ||||
|
200 | void FileDownloader::init(bool noGUI, QObject *parent) | |||
|
201 | { | |||
|
202 | if(Q_UNLIKELY(_self==NULL)) | |||
|
203 | { | |||
|
204 | _self=new FileDownloader(noGUI,parent); | |||
|
205 | _self->reloadConfig(); | |||
|
206 | } | |||
|
207 | } | |||
|
208 | /*for gnome: | |||
|
209 | * | |||
|
210 | * gsettings list-recursively org.gnome.system.proxy | |||
|
211 | * gsettings get org.gnome.system.proxy.http host | |||
|
212 | * | |||
|
213 | * To detect desktop $XDG_CURRENT_DESKTOP | |||
|
214 | */ | |||
|
215 | FileDownloader::FileDownloader(bool noGUI,QObject *parent) : QLopService(parent) | |||
|
216 | { | |||
|
217 | m_ProxyFactory = new QLopNetworkProxyFactory(); | |||
|
218 | // configureProxy(); | |||
|
219 | m_WebCtrl = new QNetworkAccessManager(this); | |||
|
220 | m_WebCtrl->setProxyFactory(m_ProxyFactory); | |||
|
221 | m_pendingTasks = new QList<FileDownloaderTask*>(); | |||
|
222 | m_noGui=noGUI; | |||
|
223 | m_serviceName="FileDownloader"; | |||
|
224 | } | |||
|
225 | ||||
|
226 | FileDownloader::~FileDownloader() | |||
|
227 | { | |||
|
228 | if(!m_noGui) | |||
|
229 | delete m_gui; | |||
|
230 | while (m_pendingTasks->count()) | |||
|
231 | { | |||
|
232 | FileDownloaderTask* task=m_pendingTasks->last(); | |||
|
233 | m_pendingTasks->removeLast(); | |||
|
234 | delete task; | |||
|
235 | } | |||
|
236 | delete m_WebCtrl; | |||
|
237 | } |
@@ -0,0 +1,78 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | #ifndef FILEDOWNLOADER_H | |||
|
24 | #define FILEDOWNLOADER_H | |||
|
25 | ||||
|
26 | #include <QObject> | |||
|
27 | #include <QNetworkAccessManager> | |||
|
28 | #include <QNetworkReply> | |||
|
29 | #include <QNetworkProxy> | |||
|
30 | #include <QList> | |||
|
31 | #include <QHash> | |||
|
32 | #include <filedownloadertask.h> | |||
|
33 | #include <downloadhistory.h> | |||
|
34 | #include <qlopservice.h> | |||
|
35 | #include <QDockWidget> | |||
|
36 | #include <filedowloadersettingsgui.h> | |||
|
37 | #include <qlopsettings.h> | |||
|
38 | #include <QHostAddress> | |||
|
39 | #include <qlopnetworkproxyfactory.h> | |||
|
40 | ||||
|
41 | class FileDownloader : public QLopService | |||
|
42 | { | |||
|
43 | Q_OBJECT | |||
|
44 | private: | |||
|
45 | static FileDownloader* _self; | |||
|
46 | static QNetworkAccessManager* m_WebCtrl; | |||
|
47 | static QList<FileDownloaderTask*>* m_pendingTasks; | |||
|
48 | static DownLoadHistory* m_DownLoadHistory; | |||
|
49 | static QDockWidget* m_gui; | |||
|
50 | static QLopNetworkProxyFactory* m_ProxyFactory; | |||
|
51 | static FileDowloaderSettingsGUI* m_SettingsGui; | |||
|
52 | FileDownloader(bool noGUI=false,QObject *parent = 0); | |||
|
53 | ~FileDownloader(); | |||
|
54 | ||||
|
55 | public: | |||
|
56 | static void init(bool noGUI=false,QObject *parent = 0); | |||
|
57 | static int downloadFile(QUrl fileUrl,const QString& name); | |||
|
58 | static int downloadFile(QString fileUrl,const QString& name); | |||
|
59 | static FileDownloaderTask *getDownloadTask(int ID); | |||
|
60 | static bool taskIsCompleted(int ID); | |||
|
61 | static FileDownloader *self(); | |||
|
62 | void reloadConfig(); | |||
|
63 | // QLopService methodes | |||
|
64 | QDockWidget* getGUI(); | |||
|
65 | const QString& serviceName(); | |||
|
66 | signals: | |||
|
67 | ||||
|
68 | public slots: | |||
|
69 | int download_file(QUrl fileUrl,const QString& name); | |||
|
70 | int download_file(QString fileUrl,const QString& name); | |||
|
71 | private slots: | |||
|
72 | void gotHead(FileDownloaderTask *task, QNetworkReply *headerreply); | |||
|
73 | private: | |||
|
74 | void configureProxy(); | |||
|
75 | int getTaskId(); | |||
|
76 | }; | |||
|
77 | ||||
|
78 | #endif // FILEDOWNLOADER_H |
@@ -0,0 +1,97 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | #include "filedownloadertask.h" | |||
|
24 | ||||
|
25 | FileDownloaderTask::FileDownloaderTask(QNetworkReply *headerreply, int ID, const QString &fileName, QObject *parent) | |||
|
26 | : QObject(parent),p_acceptRestart(false) | |||
|
27 | { | |||
|
28 | this->m_Reply = headerreply; | |||
|
29 | this->m_downloadComplete = false; | |||
|
30 | this->m_FileName = fileName; | |||
|
31 | this->m_taskId = ID; | |||
|
32 | this->m_file = new QFile(fileName+".part"); | |||
|
33 | this->m_file->open(QIODevice::WriteOnly|QIODevice::Append); | |||
|
34 | this->m_startPos = this->m_file->size(); | |||
|
35 | this->m_startDateTime = QDateTime::currentDateTime(); | |||
|
36 | this->m_URL = m_Reply->url().toString(); | |||
|
37 | connect(this->m_Reply,SIGNAL(finished()),this,SLOT(gotHead())); | |||
|
38 | } | |||
|
39 | ||||
|
40 | FileDownloaderTask::~FileDownloaderTask() | |||
|
41 | { | |||
|
42 | delete m_file; | |||
|
43 | delete m_Reply; | |||
|
44 | } | |||
|
45 | ||||
|
46 | int FileDownloaderTask::ID(){return m_taskId;} | |||
|
47 | ||||
|
48 | const QString &FileDownloaderTask::fileName(){return m_FileName;} | |||
|
49 | ||||
|
50 | const QString &FileDownloaderTask::url(){return m_URL;} | |||
|
51 | ||||
|
52 | const QDateTime &FileDownloaderTask::startDateTime(){return m_startDateTime;} | |||
|
53 | ||||
|
54 | bool FileDownloaderTask::downloadComplete(){return m_downloadComplete;} | |||
|
55 | ||||
|
56 | void FileDownloaderTask::restart(QNetworkReply *reply, bool acceptRestart) | |||
|
57 | { | |||
|
58 | if(!acceptRestart) | |||
|
59 | this->m_file->seek(0); | |||
|
60 | this->p_acceptRestart = acceptRestart; | |||
|
61 | this->m_Reply = reply; | |||
|
62 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); | |||
|
63 | connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SIGNAL(updateProgress(qint64,qint64))); | |||
|
64 | connect(this->m_Reply,SIGNAL(readyRead()),this,SLOT(readReady())); | |||
|
65 | connect(this->m_Reply,SIGNAL(finished()),this,SLOT(downloadFinished())); | |||
|
66 | } | |||
|
67 | ||||
|
68 | int FileDownloaderTask::startPosition() | |||
|
69 | { | |||
|
70 | return m_startPos; | |||
|
71 | } | |||
|
72 | ||||
|
73 | void FileDownloaderTask::gotHead() | |||
|
74 | { | |||
|
75 | emit gotHead(this,m_Reply); | |||
|
76 | } | |||
|
77 | ||||
|
78 | ||||
|
79 | void FileDownloaderTask::downloadProgress(qint64 bytesSent, qint64 bytesTotal) | |||
|
80 | { | |||
|
81 | if(bytesTotal!=0) | |||
|
82 | emit updateProgress((100*bytesSent)/bytesTotal); | |||
|
83 | } | |||
|
84 | ||||
|
85 | void FileDownloaderTask::readReady() | |||
|
86 | { | |||
|
87 | this->m_file->write(this->m_Reply->readAll()); | |||
|
88 | } | |||
|
89 | ||||
|
90 | void FileDownloaderTask::downloadFinished() | |||
|
91 | { | |||
|
92 | this->m_downloadComplete = true; | |||
|
93 | this->m_file->write(this->m_Reply->readAll()); | |||
|
94 | this->m_file->close(); | |||
|
95 | this->m_file->rename(this->m_FileName); | |||
|
96 | } | |||
|
97 |
@@ -0,0 +1,73 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | ||||
|
23 | #ifndef FILEDOWNLOADERTASK_H | |||
|
24 | #define FILEDOWNLOADERTASK_H | |||
|
25 | ||||
|
26 | #include <QObject> | |||
|
27 | #include <QByteArray> | |||
|
28 | #include <QNetworkAccessManager> | |||
|
29 | #include <QNetworkRequest> | |||
|
30 | #include <QNetworkReply> | |||
|
31 | #include <QFile> | |||
|
32 | #include <QDateTime> | |||
|
33 | ||||
|
34 | // TODO add download speed and remaining time. | |||
|
35 | ||||
|
36 | class FileDownloaderTask : public QObject | |||
|
37 | { | |||
|
38 | Q_OBJECT | |||
|
39 | public: | |||
|
40 | explicit FileDownloaderTask(QNetworkReply* headerreply, int ID, const QString& fileName, QObject *parent = 0); | |||
|
41 | ~FileDownloaderTask(); | |||
|
42 | int ID(); | |||
|
43 | const QString& fileName(); | |||
|
44 | const QString& url(); | |||
|
45 | const QDateTime& startDateTime(); | |||
|
46 | bool downloadComplete(); | |||
|
47 | void restart(QNetworkReply* reply,bool acceptRestart=false); | |||
|
48 | int startPosition(); | |||
|
49 | signals: | |||
|
50 | void updateProgress(int percent); | |||
|
51 | void updateProgress(qint64 bytesSent, qint64 bytesTotal); | |||
|
52 | void gotHead(FileDownloaderTask* task,QNetworkReply* headerreply); | |||
|
53 | public slots: | |||
|
54 | ||||
|
55 | private slots: | |||
|
56 | void gotHead(); | |||
|
57 | void downloadProgress(qint64 bytesSent, qint64 bytesTotal); | |||
|
58 | void readReady(); | |||
|
59 | void downloadFinished(); | |||
|
60 | private: | |||
|
61 | int m_taskId; | |||
|
62 | QNetworkReply* m_Reply; | |||
|
63 | QByteArray m_DownloadedData; | |||
|
64 | bool m_downloadComplete; | |||
|
65 | QFile* m_file; | |||
|
66 | QString m_FileName; | |||
|
67 | QString m_URL; | |||
|
68 | QDateTime m_startDateTime; | |||
|
69 | int m_startPos; | |||
|
70 | bool p_acceptRestart; | |||
|
71 | }; | |||
|
72 | ||||
|
73 | #endif // FILEDOWNLOADERTASK_H |
This diff has been collapsed as it changes many lines, (693 lines changed) Show them Hide them | |||||
@@ -0,0 +1,693 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | // based on Based on qt-examples: https://gitorious.org/qt-examples/qt-examples/blobs/master/pac-files | |||
|
23 | // and also KDE's KIO kpac source code: https://projects.kde.org/projects/frameworks/kio/repository/revisions/master/show/src/kpac | |||
|
24 | // specially https://projects.kde.org/projects/frameworks/kio/repository/revisions/master/entry/src/kpac/script.cpp | |||
|
25 | ||||
|
26 | #include "proxypacparser.h" | |||
|
27 | #include <QHostAddress> | |||
|
28 | #include <QHostInfo> | |||
|
29 | #include <QNetworkInterface> | |||
|
30 | #include <QDateTime> | |||
|
31 | ||||
|
32 | ||||
|
33 | class Address | |||
|
34 | { | |||
|
35 | public: | |||
|
36 | struct Error {}; | |||
|
37 | static Address resolve(const QString &host) | |||
|
38 | { | |||
|
39 | return Address(host); | |||
|
40 | } | |||
|
41 | ||||
|
42 | QList<QHostAddress> addresses() const | |||
|
43 | { | |||
|
44 | return m_addressList; | |||
|
45 | } | |||
|
46 | ||||
|
47 | QHostAddress address() const | |||
|
48 | { | |||
|
49 | if (m_addressList.isEmpty()) { | |||
|
50 | return QHostAddress(); | |||
|
51 | } | |||
|
52 | ||||
|
53 | return m_addressList.first(); | |||
|
54 | } | |||
|
55 | ||||
|
56 | private: | |||
|
57 | Address(const QString &host) | |||
|
58 | { | |||
|
59 | // Always try to see if it's already an IP first, to avoid Qt doing a | |||
|
60 | // needless reverse lookup | |||
|
61 | QHostAddress address(host); | |||
|
62 | if (address.isNull()) { | |||
|
63 | QHostInfo hostInfo; | |||
|
64 | if (hostInfo.hostName().isEmpty() || hostInfo.error() != QHostInfo::NoError) { | |||
|
65 | hostInfo = QHostInfo::fromName(host); | |||
|
66 | } | |||
|
67 | m_addressList = hostInfo.addresses(); | |||
|
68 | } else { | |||
|
69 | m_addressList.clear(); | |||
|
70 | m_addressList.append(address); | |||
|
71 | } | |||
|
72 | } | |||
|
73 | ||||
|
74 | QList<QHostAddress> m_addressList; | |||
|
75 | }; | |||
|
76 | ||||
|
77 | ProxyPacParser::ProxyPacParser(QObject *parent) | |||
|
78 | { | |||
|
79 | engine = new QScriptEngine(this); | |||
|
80 | QScriptValue globalObject = engine->globalObject(); | |||
|
81 | ||||
|
82 | globalObject.setProperty(QString("isPlainHostName"), engine->newFunction(isPlainHostName)); | |||
|
83 | globalObject.setProperty(QString("dnsDomainIs"), engine->newFunction(dnsDomainIs)); | |||
|
84 | globalObject.setProperty(QString("localHostOrDomainIs"), engine->newFunction(localHostOrDomainIs)); | |||
|
85 | globalObject.setProperty(QString("isResolvable"), engine->newFunction(isResolvable)); | |||
|
86 | globalObject.setProperty(QString("isInNet"), engine->newFunction(isInNet)); | |||
|
87 | ||||
|
88 | //Related utility functions: | |||
|
89 | globalObject.setProperty(QString("dnsResolve"), engine->newFunction(dnsResolve)); | |||
|
90 | globalObject.setProperty(QString("myIpAddress"), engine->newFunction(myIpAddress)); | |||
|
91 | globalObject.setProperty(QString("dnsDomainLevels"), engine->newFunction(dnsDomainLevels)); | |||
|
92 | ||||
|
93 | //URL/hostname based conditions: | |||
|
94 | globalObject.setProperty(QString("shExpMatch"), engine->newFunction(shExpMatch)); | |||
|
95 | ||||
|
96 | // Time based conditions: | |||
|
97 | globalObject.setProperty(QString("weekdayRange"), engine->newFunction(weekdayRange)); | |||
|
98 | globalObject.setProperty(QString("dateRange"), engine->newFunction(dateRange)); | |||
|
99 | globalObject.setProperty(QString("timeRange"), engine->newFunction(timeRange)); | |||
|
100 | ||||
|
101 | //Implementation of Microsoft's IPv6 Extension for PAC | |||
|
102 | globalObject.setProperty(QString("isResolvableEx"), engine->newFunction(isResolvableEx)); | |||
|
103 | globalObject.setProperty(QString("isInNetEx"), engine->newFunction(isInNetEx)); | |||
|
104 | globalObject.setProperty(QString("dnsResolveEx"), engine->newFunction(dnsResolveEx)); | |||
|
105 | globalObject.setProperty(QString("myIpAddressEx"), engine->newFunction(myIpAddressEx)); | |||
|
106 | globalObject.setProperty(QString("sortIpAddressList"), engine->newFunction(sortIpAddressList)); | |||
|
107 | ||||
|
108 | ||||
|
109 | } | |||
|
110 | ||||
|
111 | ProxyPacParser::~ProxyPacParser() | |||
|
112 | { | |||
|
113 | // delete engine; | |||
|
114 | } | |||
|
115 | ||||
|
116 | void ProxyPacParser::setPacFile(const QString &fileContent) | |||
|
117 | { | |||
|
118 | engine->evaluate(fileContent); | |||
|
119 | } | |||
|
120 | ||||
|
121 | QString ProxyPacParser::findProxyForUrl(const QString &url, const QString &host) | |||
|
122 | { | |||
|
123 | QScriptValue global = engine->globalObject(); | |||
|
124 | QScriptValue fun = global.property("FindProxyForURL"); | |||
|
125 | if ( !fun.isFunction() ) { | |||
|
126 | return QString("DIRECT"); | |||
|
127 | } | |||
|
128 | ||||
|
129 | QScriptValueList args; | |||
|
130 | args << engine->toScriptValue( url ) << engine->toScriptValue( host ); | |||
|
131 | ||||
|
132 | QScriptValue val = fun.call( global, args ); | |||
|
133 | ||||
|
134 | return val.toString(); | |||
|
135 | } | |||
|
136 | ||||
|
137 | template <typename T> | |||
|
138 | static bool checkRange(T value, T min, T max) | |||
|
139 | { | |||
|
140 | return ((min <= max && value >= min && value <= max) || | |||
|
141 | (min > max && (value <= min || value >= max))); | |||
|
142 | } | |||
|
143 | ||||
|
144 | ||||
|
145 | static bool isLocalHostAddress(const QHostAddress &address) | |||
|
146 | { | |||
|
147 | if (address == QHostAddress::LocalHost) { | |||
|
148 | return true; | |||
|
149 | } | |||
|
150 | ||||
|
151 | if (address == QHostAddress::LocalHostIPv6) { | |||
|
152 | return true; | |||
|
153 | } | |||
|
154 | ||||
|
155 | return false; | |||
|
156 | } | |||
|
157 | ||||
|
158 | static bool isIPv6Address(const QHostAddress &address) | |||
|
159 | { | |||
|
160 | return address.protocol() == QAbstractSocket::IPv6Protocol; | |||
|
161 | } | |||
|
162 | ||||
|
163 | static bool isIPv4Address(const QHostAddress &address) | |||
|
164 | { | |||
|
165 | return (address.protocol() == QAbstractSocket::IPv4Protocol); | |||
|
166 | } | |||
|
167 | ||||
|
168 | static bool isSpecialAddress(const QHostAddress &address) | |||
|
169 | { | |||
|
170 | // Catch all the special addresses and return false. | |||
|
171 | if (address == QHostAddress::Null) { | |||
|
172 | return true; | |||
|
173 | } | |||
|
174 | ||||
|
175 | if (address == QHostAddress::Any) { | |||
|
176 | return true; | |||
|
177 | } | |||
|
178 | ||||
|
179 | if (address == QHostAddress::AnyIPv6) { | |||
|
180 | return true; | |||
|
181 | } | |||
|
182 | ||||
|
183 | if (address == QHostAddress::Broadcast) { | |||
|
184 | return true; | |||
|
185 | } | |||
|
186 | ||||
|
187 | return false; | |||
|
188 | } | |||
|
189 | ||||
|
190 | ||||
|
191 | static bool addressLessThanComparison(const QHostAddress &addr1, const QHostAddress &addr2) | |||
|
192 | { | |||
|
193 | if (addr1.protocol() == QAbstractSocket::IPv4Protocol && | |||
|
194 | addr2.protocol() == QAbstractSocket::IPv4Protocol) { | |||
|
195 | return addr1.toIPv4Address() < addr2.toIPv4Address(); | |||
|
196 | } | |||
|
197 | ||||
|
198 | if (addr1.protocol() == QAbstractSocket::IPv6Protocol && | |||
|
199 | addr2.protocol() == QAbstractSocket::IPv6Protocol) { | |||
|
200 | const Q_IPV6ADDR ipv6addr1 = addr1.toIPv6Address(); | |||
|
201 | const Q_IPV6ADDR ipv6addr2 = addr2.toIPv6Address(); | |||
|
202 | for (int i = 0; i < 16; ++i) { | |||
|
203 | if (ipv6addr1[i] != ipv6addr2[i]) { | |||
|
204 | return ((ipv6addr1[i] & 0xff) - (ipv6addr2[i] & 0xff)); | |||
|
205 | } | |||
|
206 | } | |||
|
207 | } | |||
|
208 | ||||
|
209 | return false; | |||
|
210 | } | |||
|
211 | ||||
|
212 | static QString addressListToString(const QList<QHostAddress> &addressList, | |||
|
213 | const QHash<QString, QString> &actualEntryMap) | |||
|
214 | { | |||
|
215 | QString result; | |||
|
216 | Q_FOREACH (const QHostAddress &address, addressList) { | |||
|
217 | if (!result.isEmpty()) { | |||
|
218 | result += QLatin1Char(';'); | |||
|
219 | } | |||
|
220 | result += actualEntryMap.value(address.toString()); | |||
|
221 | } | |||
|
222 | return result; | |||
|
223 | } | |||
|
224 | ||||
|
225 | const QDateTime ProxyPacParser::getTime(QScriptContext *context) | |||
|
226 | { | |||
|
227 | const QString tz = context->argument(context->argumentCount() - 1).toString(); | |||
|
228 | if (tz.compare(QLatin1String("gmt"), Qt::CaseInsensitive) == 0) { | |||
|
229 | return QDateTime::currentDateTimeUtc(); | |||
|
230 | } | |||
|
231 | return QDateTime::currentDateTime(); | |||
|
232 | } | |||
|
233 | ||||
|
234 | int ProxyPacParser::findString(const QString &s, const char *const *values) | |||
|
235 | { | |||
|
236 | int index = 0; | |||
|
237 | const QString lower = s.toLower(); | |||
|
238 | for (const char *const *p = values; *p; ++p, ++index) { | |||
|
239 | if (s.compare(QLatin1String(*p), Qt::CaseInsensitive) == 0) { | |||
|
240 | return index; | |||
|
241 | } | |||
|
242 | } | |||
|
243 | return -1; | |||
|
244 | } | |||
|
245 | ||||
|
246 | QScriptValue ProxyPacParser::myIpAddress(QScriptContext *context, QScriptEngine *engine) | |||
|
247 | { | |||
|
248 | if ( context->argumentCount() != 0 ) | |||
|
249 | return context->throwError("myIpAddress takes no arguments"); | |||
|
250 | ||||
|
251 | foreach( QHostAddress address, QNetworkInterface::allAddresses() ) { | |||
|
252 | if ( address != QHostAddress::LocalHost | |||
|
253 | && address != QHostAddress::LocalHostIPv6 ) | |||
|
254 | return QScriptValue( engine, address.toString() ); | |||
|
255 | } | |||
|
256 | ||||
|
257 | return engine->undefinedValue(); | |||
|
258 | } | |||
|
259 | ||||
|
260 | // dnsDomainLevels(host) | |||
|
261 | // @returns the number of dots ('.') in @p host | |||
|
262 | QScriptValue ProxyPacParser::dnsDomainLevels(QScriptContext *context, QScriptEngine *engine) | |||
|
263 | { | |||
|
264 | if (context->argumentCount() != 1) { | |||
|
265 | return engine->undefinedValue(); | |||
|
266 | } | |||
|
267 | const QString host = context->argument(0).toString(); | |||
|
268 | if (host.isNull()) { | |||
|
269 | return engine->toScriptValue(0); | |||
|
270 | } | |||
|
271 | return engine->toScriptValue(host.count(QLatin1Char('.'))); | |||
|
272 | } | |||
|
273 | ||||
|
274 | QScriptValue ProxyPacParser::isInNet(QScriptContext *context, QScriptEngine *engine) | |||
|
275 | { | |||
|
276 | if ( context->argumentCount() != 3 ) | |||
|
277 | return context->throwError("isInNet takes three arguments"); | |||
|
278 | ||||
|
279 | QHostAddress addr( context->argument(0).toString() ); | |||
|
280 | QHostAddress netaddr( context->argument(1).toString() ); | |||
|
281 | QHostAddress netmask( context->argument(2).toString() ); | |||
|
282 | ||||
|
283 | if ( (netaddr.toIPv4Address() & netmask.toIPv4Address()) == (addr.toIPv4Address() & netmask.toIPv4Address()) ) | |||
|
284 | return QScriptValue( engine, true ); | |||
|
285 | ||||
|
286 | return QScriptValue( engine, false ); | |||
|
287 | } | |||
|
288 | ||||
|
289 | QScriptValue ProxyPacParser::shExpMatch(QScriptContext *context, QScriptEngine *engine) | |||
|
290 | { | |||
|
291 | if ( context->argumentCount() != 2 ) | |||
|
292 | return context->throwError("shExpMatch takes two arguments"); | |||
|
293 | ||||
|
294 | QRegExp re( context->argument(1).toString(), Qt::CaseSensitive, QRegExp::Wildcard ); | |||
|
295 | if ( re.exactMatch( context->argument(0).toString() ) ) | |||
|
296 | return QScriptValue( engine, true ); | |||
|
297 | ||||
|
298 | return QScriptValue( engine, false ); | |||
|
299 | } | |||
|
300 | ||||
|
301 | // weekdayRange(day [, "GMT" ]) | |||
|
302 | // weekdayRange(day1, day2 [, "GMT" ]) | |||
|
303 | // @returns true if the current day equals day or between day1 and day2 resp. | |||
|
304 | // If the last argument is "GMT", GMT timezone is used, otherwise local time | |||
|
305 | QScriptValue ProxyPacParser::weekdayRange(QScriptContext *context, QScriptEngine *engine) | |||
|
306 | { | |||
|
307 | if (context->argumentCount() < 1 || context->argumentCount() > 3) { | |||
|
308 | return engine->undefinedValue(); | |||
|
309 | } | |||
|
310 | ||||
|
311 | static const char *const days[] = { "sun", "mon", "tue", "wed", "thu", "fri", "sat", 0 }; | |||
|
312 | ||||
|
313 | const int d1 = findString(context->argument(0).toString(), days); | |||
|
314 | if (d1 == -1) { | |||
|
315 | return engine->undefinedValue(); | |||
|
316 | } | |||
|
317 | ||||
|
318 | int d2 = findString(context->argument(1).toString(), days); | |||
|
319 | if (d2 == -1) { | |||
|
320 | d2 = d1; | |||
|
321 | } | |||
|
322 | ||||
|
323 | // Adjust the days of week coming from QDateTime since it starts | |||
|
324 | // counting with Monday as 1 and ends with Sunday as day 7. | |||
|
325 | int dayOfWeek = getTime(context).date().dayOfWeek(); | |||
|
326 | if (dayOfWeek == 7) { | |||
|
327 | dayOfWeek = 0; | |||
|
328 | } | |||
|
329 | return engine->toScriptValue(checkRange(dayOfWeek, d1, d2)); | |||
|
330 | } | |||
|
331 | ||||
|
332 | // dateRange(day [, "GMT" ]) | |||
|
333 | // dateRange(day1, day2 [, "GMT" ]) | |||
|
334 | // dateRange(month [, "GMT" ]) | |||
|
335 | // dateRange(month1, month2 [, "GMT" ]) | |||
|
336 | // dateRange(year [, "GMT" ]) | |||
|
337 | // dateRange(year1, year2 [, "GMT" ]) | |||
|
338 | // dateRange(day1, month1, day2, month2 [, "GMT" ]) | |||
|
339 | // dateRange(month1, year1, month2, year2 [, "GMT" ]) | |||
|
340 | // dateRange(day1, month1, year1, day2, month2, year2 [, "GMT" ]) | |||
|
341 | // @returns true if the current date (GMT or local time according to | |||
|
342 | // presence of "GMT" as last argument) is within the given range | |||
|
343 | QScriptValue ProxyPacParser::dateRange(QScriptContext *context, QScriptEngine *engine) | |||
|
344 | { | |||
|
345 | if (context->argumentCount() < 1 || context->argumentCount() > 7) { | |||
|
346 | return engine->undefinedValue(); | |||
|
347 | } | |||
|
348 | ||||
|
349 | static const char *const months[] = { "jan", "feb", "mar", "apr", "may", "jun", | |||
|
350 | "jul", "aug", "sep", "oct", "nov", "dec", 0 | |||
|
351 | }; | |||
|
352 | ||||
|
353 | QVector<int> values; | |||
|
354 | for (int i = 0; i < context->argumentCount(); ++i) { | |||
|
355 | int value = -1; | |||
|
356 | if (context->argument(i).isNumber()) { | |||
|
357 | value = context->argument(i).toInt32(); | |||
|
358 | } else { | |||
|
359 | // QDate starts counting months from 1, so we add 1 here. | |||
|
360 | value = findString(context->argument(i).toString(), months) + 1; | |||
|
361 | } | |||
|
362 | ||||
|
363 | if (value > 0) { | |||
|
364 | values.append(value); | |||
|
365 | } else { | |||
|
366 | break; | |||
|
367 | } | |||
|
368 | } | |||
|
369 | ||||
|
370 | const QDate now = getTime(context).date(); | |||
|
371 | ||||
|
372 | // day1, month1, year1, day2, month2, year2 | |||
|
373 | if (values.size() == 6) { | |||
|
374 | const QDate d1(values[2], values[1], values[0]); | |||
|
375 | const QDate d2(values[5], values[4], values[3]); | |||
|
376 | return engine->toScriptValue(checkRange(now, d1, d2)); | |||
|
377 | } | |||
|
378 | // day1, month1, day2, month2 | |||
|
379 | else if (values.size() == 4 && values[ 1 ] < 13 && values[ 3 ] < 13) { | |||
|
380 | const QDate d1(now.year(), values[1], values[0]); | |||
|
381 | const QDate d2(now.year(), values[3], values[2]); | |||
|
382 | return engine->toScriptValue(checkRange(now, d1, d2)); | |||
|
383 | } | |||
|
384 | // month1, year1, month2, year2 | |||
|
385 | else if (values.size() == 4) { | |||
|
386 | const QDate d1(values[1], values[0], now.day()); | |||
|
387 | const QDate d2(values[3], values[2], now.day()); | |||
|
388 | return engine->toScriptValue(checkRange(now, d1, d2)); | |||
|
389 | } | |||
|
390 | // year1, year2 | |||
|
391 | else if (values.size() == 2 && values[0] >= 1000 && values[1] >= 1000) { | |||
|
392 | return engine->toScriptValue(checkRange(now.year(), values[0], values[1])); | |||
|
393 | } | |||
|
394 | // day1, day2 | |||
|
395 | else if (values.size() == 2 && context->argument(0).isNumber() && context->argument(1).isNumber()) { | |||
|
396 | return engine->toScriptValue(checkRange(now.day(), values[0], values[1])); | |||
|
397 | } | |||
|
398 | // month1, month2 | |||
|
399 | else if (values.size() == 2) { | |||
|
400 | return engine->toScriptValue(checkRange(now.month(), values[0], values[1])); | |||
|
401 | } | |||
|
402 | // year | |||
|
403 | else if (values.size() == 1 && values[ 0 ] >= 1000) { | |||
|
404 | return engine->toScriptValue(checkRange(now.year(), values[0], values[0])); | |||
|
405 | } | |||
|
406 | // day | |||
|
407 | else if (values.size() == 1 && context->argument(0).isNumber()) { | |||
|
408 | return engine->toScriptValue(checkRange(now.day(), values[0], values[0])); | |||
|
409 | } | |||
|
410 | // month | |||
|
411 | else if (values.size() == 1) { | |||
|
412 | return engine->toScriptValue(checkRange(now.month(), values[0], values[0])); | |||
|
413 | } | |||
|
414 | ||||
|
415 | return engine->undefinedValue(); | |||
|
416 | } | |||
|
417 | ||||
|
418 | // timeRange(hour [, "GMT" ]) | |||
|
419 | // timeRange(hour1, hour2 [, "GMT" ]) | |||
|
420 | // timeRange(hour1, min1, hour2, min2 [, "GMT" ]) | |||
|
421 | // timeRange(hour1, min1, sec1, hour2, min2, sec2 [, "GMT" ]) | |||
|
422 | // @returns true if the current time (GMT or local based on presence | |||
|
423 | // of "GMT" argument) is within the given range | |||
|
424 | QScriptValue ProxyPacParser::timeRange(QScriptContext *context, QScriptEngine *engine) | |||
|
425 | { | |||
|
426 | if (context->argumentCount() < 1 || context->argumentCount() > 7) { | |||
|
427 | return engine->undefinedValue(); | |||
|
428 | } | |||
|
429 | ||||
|
430 | QVector<int> values; | |||
|
431 | for (int i = 0; i < context->argumentCount(); ++i) { | |||
|
432 | if (!context->argument(i).isNumber()) { | |||
|
433 | break; | |||
|
434 | } | |||
|
435 | values.append(context->argument(i).toNumber()); | |||
|
436 | } | |||
|
437 | ||||
|
438 | const QTime now = getTime(context).time(); | |||
|
439 | ||||
|
440 | // hour1, min1, sec1, hour2, min2, sec2 | |||
|
441 | if (values.size() == 6) { | |||
|
442 | const QTime t1(values[0], values[1], values[2]); | |||
|
443 | const QTime t2(values[3], values[4], values[5]); | |||
|
444 | return engine->toScriptValue(checkRange(now, t1, t2)); | |||
|
445 | } | |||
|
446 | // hour1, min1, hour2, min2 | |||
|
447 | else if (values.size() == 4) { | |||
|
448 | const QTime t1(values[0], values[1]); | |||
|
449 | const QTime t2(values[2], values[3]); | |||
|
450 | return engine->toScriptValue(checkRange(now, t1, t2)); | |||
|
451 | } | |||
|
452 | // hour1, hour2 | |||
|
453 | else if (values.size() == 2) { | |||
|
454 | return engine->toScriptValue(checkRange(now.hour(), values[0], values[1])); | |||
|
455 | } | |||
|
456 | // hour | |||
|
457 | else if (values.size() == 1) { | |||
|
458 | return engine->toScriptValue(checkRange(now.hour(), values[0], values[0])); | |||
|
459 | } | |||
|
460 | ||||
|
461 | return engine->undefinedValue(); | |||
|
462 | } | |||
|
463 | ||||
|
464 | QScriptValue ProxyPacParser::dnsResolve(QScriptContext *context, QScriptEngine *engine) | |||
|
465 | { | |||
|
466 | if ( context->argumentCount() != 1 ) | |||
|
467 | return context->throwError("dnsResolve takes one arguments"); | |||
|
468 | ||||
|
469 | QHostInfo info = QHostInfo::fromName( context->argument(0).toString() ); | |||
|
470 | QList<QHostAddress> addresses = info.addresses(); | |||
|
471 | if ( addresses.isEmpty() ) | |||
|
472 | return engine->nullValue(); // TODO: Should this be undefined or an exception? check other implementations | |||
|
473 | ||||
|
474 | return QScriptValue( engine, addresses.first().toString() ); | |||
|
475 | } | |||
|
476 | ||||
|
477 | QScriptValue ProxyPacParser::dnsDomainIs(QScriptContext *context, QScriptEngine *engine) | |||
|
478 | { | |||
|
479 | if ( context->argumentCount() != 2 ) | |||
|
480 | return context->throwError("dnsDomainIs takes two arguments"); | |||
|
481 | ||||
|
482 | QHostInfo info = QHostInfo::fromName( context->argument(0).toString() ); | |||
|
483 | QString domain = info.localDomainName(); | |||
|
484 | QString argDomain = context->argument(1).toString(); | |||
|
485 | ||||
|
486 | if ( !domain.compare(argDomain) || !argDomain.compare("."+domain)) | |||
|
487 | return QScriptValue( engine, true ); | |||
|
488 | return QScriptValue( engine, false); | |||
|
489 | } | |||
|
490 | ||||
|
491 | // localHostOrDomainIs(host, fqdn) | |||
|
492 | // @returns true if @p host is unqualified or equals @p fqdn | |||
|
493 | QScriptValue ProxyPacParser::localHostOrDomainIs(QScriptContext *context, QScriptEngine *engine) | |||
|
494 | { | |||
|
495 | if (context->argumentCount() != 2) { | |||
|
496 | return engine->undefinedValue(); | |||
|
497 | } | |||
|
498 | ||||
|
499 | const QString host = context->argument(0).toString(); | |||
|
500 | if (!host.contains(QLatin1Char('.'))) { | |||
|
501 | return engine->toScriptValue(true); | |||
|
502 | } | |||
|
503 | const QString fqdn = context->argument(1).toString(); | |||
|
504 | return engine->toScriptValue((host.compare(fqdn, Qt::CaseInsensitive) == 0)); | |||
|
505 | } | |||
|
506 | ||||
|
507 | // isResolvable(host) | |||
|
508 | // @returns true if host is resolvable to a IPv4 address. | |||
|
509 | QScriptValue ProxyPacParser::isResolvable(QScriptContext *context, QScriptEngine *engine) | |||
|
510 | { | |||
|
511 | if (context->argumentCount() != 1) { | |||
|
512 | return engine->undefinedValue(); | |||
|
513 | } | |||
|
514 | ||||
|
515 | try { | |||
|
516 | const Address info = Address::resolve(context->argument(0).toString()); | |||
|
517 | bool hasResolvableIPv4Address = false; | |||
|
518 | ||||
|
519 | Q_FOREACH (const QHostAddress &address, info.addresses()) { | |||
|
520 | if (!isSpecialAddress(address) && isIPv4Address(address)) { | |||
|
521 | hasResolvableIPv4Address = true; | |||
|
522 | break; | |||
|
523 | } | |||
|
524 | } | |||
|
525 | ||||
|
526 | return engine->toScriptValue(hasResolvableIPv4Address); | |||
|
527 | } catch (const Address::Error &) { | |||
|
528 | return engine->toScriptValue(false); | |||
|
529 | } | |||
|
530 | } | |||
|
531 | ||||
|
532 | // isPlainHostName(host) | |||
|
533 | // @returns true if @p host doesn't contains a domain part | |||
|
534 | QScriptValue ProxyPacParser::isPlainHostName(QScriptContext *context, QScriptEngine *engine) | |||
|
535 | { | |||
|
536 | if (context->argumentCount() != 1) { | |||
|
537 | return engine->undefinedValue(); | |||
|
538 | } | |||
|
539 | return engine->toScriptValue(context->argument(0).toString().indexOf(QLatin1Char('.')) == -1); | |||
|
540 | } | |||
|
541 | ||||
|
542 | ||||
|
543 | // isResolvableEx(host) | |||
|
544 | // @returns true if host is resolvable to an IPv4 or IPv6 address. | |||
|
545 | QScriptValue ProxyPacParser::isResolvableEx(QScriptContext *context, QScriptEngine *engine) | |||
|
546 | { | |||
|
547 | if (context->argumentCount() != 1) { | |||
|
548 | return engine->undefinedValue(); | |||
|
549 | } | |||
|
550 | ||||
|
551 | try { | |||
|
552 | const Address info = Address::resolve(context->argument(0).toString()); | |||
|
553 | bool hasResolvableIPAddress = false; | |||
|
554 | Q_FOREACH (const QHostAddress &address, info.addresses()) { | |||
|
555 | if (isIPv4Address(address) || isIPv6Address(address)) { | |||
|
556 | hasResolvableIPAddress = true; | |||
|
557 | break; | |||
|
558 | } | |||
|
559 | } | |||
|
560 | return engine->toScriptValue(hasResolvableIPAddress); | |||
|
561 | } catch (const Address::Error &) { | |||
|
562 | return engine->toScriptValue(false); | |||
|
563 | } | |||
|
564 | } | |||
|
565 | ||||
|
566 | // isInNetEx(ipAddress, ipPrefix ) | |||
|
567 | // @returns true if ipAddress is within the specified ipPrefix. | |||
|
568 | QScriptValue ProxyPacParser::isInNetEx(QScriptContext *context, QScriptEngine *engine) | |||
|
569 | { | |||
|
570 | if (context->argumentCount() != 2) { | |||
|
571 | return engine->undefinedValue(); | |||
|
572 | } | |||
|
573 | ||||
|
574 | try { | |||
|
575 | const Address info = Address::resolve(context->argument(0).toString()); | |||
|
576 | bool isInSubNet = false; | |||
|
577 | const QString subnetStr = context->argument(1).toString(); | |||
|
578 | const QPair<QHostAddress, int> subnet = QHostAddress::parseSubnet(subnetStr); | |||
|
579 | ||||
|
580 | Q_FOREACH (const QHostAddress &address, info.addresses()) { | |||
|
581 | if (isSpecialAddress(address)) { | |||
|
582 | continue; | |||
|
583 | } | |||
|
584 | ||||
|
585 | if (address.isInSubnet(subnet)) { | |||
|
586 | isInSubNet = true; | |||
|
587 | break; | |||
|
588 | } | |||
|
589 | } | |||
|
590 | return engine->toScriptValue(isInSubNet); | |||
|
591 | } catch (const Address::Error &) { | |||
|
592 | return engine->toScriptValue(false); | |||
|
593 | } | |||
|
594 | } | |||
|
595 | ||||
|
596 | ||||
|
597 | // dnsResolveEx(host) | |||
|
598 | // @returns a semi-colon delimited string containing IPv6 and IPv4 addresses | |||
|
599 | // for host or an empty string if host is not resolvable. | |||
|
600 | QScriptValue ProxyPacParser::dnsResolveEx(QScriptContext *context, QScriptEngine *engine) | |||
|
601 | { | |||
|
602 | if (context->argumentCount() != 1) { | |||
|
603 | return engine->undefinedValue(); | |||
|
604 | } | |||
|
605 | ||||
|
606 | try { | |||
|
607 | const Address info = Address::resolve(context->argument(0).toString()); | |||
|
608 | ||||
|
609 | QStringList addressList; | |||
|
610 | QString resolvedAddress(QLatin1String("")); | |||
|
611 | ||||
|
612 | Q_FOREACH (const QHostAddress &address, info.addresses()) { | |||
|
613 | if (!isSpecialAddress(address)) { | |||
|
614 | addressList << address.toString(); | |||
|
615 | } | |||
|
616 | } | |||
|
617 | if (!addressList.isEmpty()) { | |||
|
618 | resolvedAddress = addressList.join(QLatin1String(";")); | |||
|
619 | } | |||
|
620 | ||||
|
621 | return engine->toScriptValue(resolvedAddress); | |||
|
622 | } catch (const Address::Error &) { | |||
|
623 | return engine->toScriptValue(QString(QLatin1String(""))); | |||
|
624 | } | |||
|
625 | } | |||
|
626 | ||||
|
627 | // myIpAddressEx() | |||
|
628 | // @returns a semi-colon delimited string containing all IP addresses for localhost (IPv6 and/or IPv4), | |||
|
629 | // or an empty string if unable to resolve localhost to an IP address. | |||
|
630 | QScriptValue ProxyPacParser::myIpAddressEx(QScriptContext *context, QScriptEngine *engine) | |||
|
631 | { | |||
|
632 | if (context->argumentCount()) { | |||
|
633 | return engine->undefinedValue(); | |||
|
634 | } | |||
|
635 | ||||
|
636 | QStringList ipAddressList; | |||
|
637 | const QList<QHostAddress> addresses = QNetworkInterface::allAddresses(); | |||
|
638 | Q_FOREACH (const QHostAddress address, addresses) { | |||
|
639 | if (!isSpecialAddress(address) && !isLocalHostAddress(address)) { | |||
|
640 | ipAddressList << address.toString(); | |||
|
641 | } | |||
|
642 | } | |||
|
643 | ||||
|
644 | return engine->toScriptValue(ipAddressList.join(QLatin1String(";"))); | |||
|
645 | } | |||
|
646 | ||||
|
647 | // sortIpAddressList(ipAddressList) | |||
|
648 | // @returns a sorted ipAddressList. If both IPv4 and IPv6 addresses are present in | |||
|
649 | // the list. The sorted IPv6 addresses will precede the sorted IPv4 addresses. | |||
|
650 | QScriptValue ProxyPacParser::sortIpAddressList(QScriptContext *context, QScriptEngine *engine) | |||
|
651 | { | |||
|
652 | if (context->argumentCount() != 1) { | |||
|
653 | return engine->undefinedValue(); | |||
|
654 | } | |||
|
655 | ||||
|
656 | QHash<QString, QString> actualEntryMap; | |||
|
657 | QList<QHostAddress> ipV4List, ipV6List; | |||
|
658 | const QStringList ipAddressList = context->argument(0).toString().split(QLatin1Char(';')); | |||
|
659 | ||||
|
660 | Q_FOREACH (const QString &ipAddress, ipAddressList) { | |||
|
661 | QHostAddress address(ipAddress); | |||
|
662 | switch (address.protocol()) { | |||
|
663 | case QAbstractSocket::IPv4Protocol: | |||
|
664 | ipV4List << address; | |||
|
665 | actualEntryMap.insert(address.toString(), ipAddress); | |||
|
666 | break; | |||
|
667 | case QAbstractSocket::IPv6Protocol: | |||
|
668 | ipV6List << address; | |||
|
669 | actualEntryMap.insert(address.toString(), ipAddress); | |||
|
670 | break; | |||
|
671 | default: | |||
|
672 | break; | |||
|
673 | } | |||
|
674 | } | |||
|
675 | ||||
|
676 | QString sortedAddress(QLatin1String("")); | |||
|
677 | ||||
|
678 | if (!ipV6List.isEmpty()) { | |||
|
679 | qSort(ipV6List.begin(), ipV6List.end(), addressLessThanComparison); | |||
|
680 | sortedAddress += addressListToString(ipV6List, actualEntryMap); | |||
|
681 | } | |||
|
682 | ||||
|
683 | if (!ipV4List.isEmpty()) { | |||
|
684 | qSort(ipV4List.begin(), ipV4List.end(), addressLessThanComparison); | |||
|
685 | if (!sortedAddress.isEmpty()) { | |||
|
686 | sortedAddress += QLatin1Char(';'); | |||
|
687 | } | |||
|
688 | sortedAddress += addressListToString(ipV4List, actualEntryMap); | |||
|
689 | } | |||
|
690 | ||||
|
691 | return engine->toScriptValue(sortedAddress); | |||
|
692 | ||||
|
693 | } |
@@ -0,0 +1,89 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | #ifndef PROXYPACPARSER_H | |||
|
23 | #define PROXYPACPARSER_H | |||
|
24 | ||||
|
25 | #include <QObject> | |||
|
26 | #include <QScriptContext> | |||
|
27 | #include <QScriptEngine> | |||
|
28 | ||||
|
29 | class ProxyPacParser : public QObject | |||
|
30 | { | |||
|
31 | Q_OBJECT | |||
|
32 | Q_PROPERTY( QString PacFile WRITE setPacFile ) | |||
|
33 | ||||
|
34 | public: | |||
|
35 | ProxyPacParser(QObject *parent = 0); | |||
|
36 | ~ProxyPacParser(); | |||
|
37 | void setPacFile(const QString& fileContent); | |||
|
38 | Q_SCRIPTABLE QString findProxyForUrl( const QString &url, const QString &host ); | |||
|
39 | ||||
|
40 | signals: | |||
|
41 | ||||
|
42 | public slots: | |||
|
43 | private: | |||
|
44 | ||||
|
45 | //Hostname based conditions: | |||
|
46 | static QScriptValue isPlainHostName( QScriptContext *context, QScriptEngine *engine ); | |||
|
47 | static QScriptValue dnsDomainIs( QScriptContext *context, QScriptEngine *engine ); | |||
|
48 | static QScriptValue localHostOrDomainIs( QScriptContext *context, QScriptEngine *engine ); | |||
|
49 | static QScriptValue isResolvable( QScriptContext *context, QScriptEngine *engine ); | |||
|
50 | static QScriptValue isInNet( QScriptContext *context, QScriptEngine *engine ); | |||
|
51 | ||||
|
52 | //Related utility functions: | |||
|
53 | static QScriptValue dnsResolve( QScriptContext *context, QScriptEngine *engine ); | |||
|
54 | static QScriptValue myIpAddress( QScriptContext *context, QScriptEngine *engine ); | |||
|
55 | static QScriptValue dnsDomainLevels( QScriptContext *context, QScriptEngine *engine ); | |||
|
56 | ||||
|
57 | //URL/hostname based conditions: | |||
|
58 | static QScriptValue shExpMatch( QScriptContext *context, QScriptEngine *engine ); | |||
|
59 | ||||
|
60 | // Time based conditions: | |||
|
61 | static QScriptValue weekdayRange(QScriptContext *context, QScriptEngine *engine ); | |||
|
62 | static QScriptValue dateRange(QScriptContext *context, QScriptEngine *engine ); | |||
|
63 | static QScriptValue timeRange(QScriptContext *context, QScriptEngine *engine ); | |||
|
64 | ||||
|
65 | /* | |||
|
66 | * Implementation of Microsoft's IPv6 Extension for PAC | |||
|
67 | * | |||
|
68 | * Documentation: | |||
|
69 | * http://msdn.microsoft.com/en-us/library/gg308477(v=vs.85).aspx | |||
|
70 | * http://msdn.microsoft.com/en-us/library/gg308478(v=vs.85).aspx | |||
|
71 | * http://msdn.microsoft.com/en-us/library/gg308474(v=vs.85).aspx | |||
|
72 | * http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx | |||
|
73 | * | |||
|
74 | * taken from KDE KIO kpac source code :) | |||
|
75 | */ | |||
|
76 | static QScriptValue isResolvableEx(QScriptContext *context, QScriptEngine *engine); | |||
|
77 | static QScriptValue isInNetEx(QScriptContext *context, QScriptEngine *engine); | |||
|
78 | static QScriptValue dnsResolveEx(QScriptContext *context, QScriptEngine *engine); | |||
|
79 | static QScriptValue myIpAddressEx(QScriptContext *context, QScriptEngine *engine); | |||
|
80 | static QScriptValue sortIpAddressList(QScriptContext *context, QScriptEngine *engine); | |||
|
81 | ||||
|
82 | ||||
|
83 | QScriptEngine* engine; | |||
|
84 | ||||
|
85 | static int findString(const QString &s, const char * const *values); | |||
|
86 | static const QDateTime getTime(QScriptContext *context); | |||
|
87 | }; | |||
|
88 | ||||
|
89 | #endif // PROXYPACPARSER_H |
@@ -0,0 +1,171 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | #include "qlopnetworkproxyfactory.h" | |||
|
23 | #include <QHostInfo> | |||
|
24 | #include <qlopsettings.h> | |||
|
25 | #include <filedownloader.h> | |||
|
26 | ||||
|
27 | QLopNetworkProxyFactory::QLopNetworkProxyFactory() | |||
|
28 | :QNetworkProxyFactory() | |||
|
29 | { | |||
|
30 | p_pacParser = new ProxyPacParser(); | |||
|
31 | } | |||
|
32 | ||||
|
33 | QLopNetworkProxyFactory::~QLopNetworkProxyFactory() | |||
|
34 | { | |||
|
35 | ||||
|
36 | } | |||
|
37 | ||||
|
38 | ||||
|
39 | QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query) | |||
|
40 | { | |||
|
41 | QList<QNetworkProxy> result; | |||
|
42 | switch (proxyCfgType) | |||
|
43 | { | |||
|
44 | case none: | |||
|
45 | result << QNetworkProxy(QNetworkProxy::NoProxy); | |||
|
46 | return result; | |||
|
47 | break; | |||
|
48 | case manual: | |||
|
49 | return queryProxy_manual(query); | |||
|
50 | break; | |||
|
51 | case system: | |||
|
52 | return queryProxy_system(query); | |||
|
53 | break; | |||
|
54 | case automatic: | |||
|
55 | return queryProxy_auto(query); | |||
|
56 | break; | |||
|
57 | default: | |||
|
58 | result << QNetworkProxy(QNetworkProxy::DefaultProxy); | |||
|
59 | return result; | |||
|
60 | break; | |||
|
61 | } | |||
|
62 | } | |||
|
63 | ||||
|
64 | ||||
|
65 | //should hanlde ignored hosts | |||
|
66 | QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy_manual(const QNetworkProxyQuery &query) | |||
|
67 | { | |||
|
68 | QList<QNetworkProxy> result; | |||
|
69 | QString scheme = query.url().scheme(); | |||
|
70 | QHostInfo peerHost = QHostInfo::fromName(query.peerHostName()); | |||
|
71 | if(scheme=="http") | |||
|
72 | { | |||
|
73 | result.append(p_http_proxy); | |||
|
74 | } | |||
|
75 | if(scheme=="https") | |||
|
76 | { | |||
|
77 | result.append(p_https_proxy); | |||
|
78 | } | |||
|
79 | if(scheme=="ftp") | |||
|
80 | { | |||
|
81 | result.append(p_ftp_proxy); | |||
|
82 | } | |||
|
83 | result << QNetworkProxy(QNetworkProxy::DefaultProxy); | |||
|
84 | return result; | |||
|
85 | } | |||
|
86 | ||||
|
87 | QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy_system(const QNetworkProxyQuery &query) | |||
|
88 | { | |||
|
89 | QList<QNetworkProxy> result; | |||
|
90 | result << QNetworkProxy(QNetworkProxy::DefaultProxy); | |||
|
91 | return result; | |||
|
92 | } | |||
|
93 | ||||
|
94 | QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy_auto(const QNetworkProxyQuery &query) | |||
|
95 | { | |||
|
96 | QList<QNetworkProxy> result; | |||
|
97 | QString config=p_pacParser->findProxyForUrl(query.url().toString(),QHostInfo::localHostName()); | |||
|
98 | QStringList proxyList=config.split(";"); | |||
|
99 | for(int i=0;i<proxyList.count();i++) | |||
|
100 | { | |||
|
101 | QStringList line = proxyList.at(i).split(" "); | |||
|
102 | if(line.count()>=2) | |||
|
103 | { //TODO check correct syntax for pac returned proxy cfg | |||
|
104 | if(line.at(0).compare("PROXY",Qt::CaseInsensitive)) | |||
|
105 | { | |||
|
106 | QStringList proxyArgs=line.at(1).split(":"); | |||
|
107 | if(proxyArgs.count()>=2) | |||
|
108 | { | |||
|
109 | result << QNetworkProxy(QNetworkProxy::HttpProxy,proxyArgs.at(0),proxyArgs.at(1).toUInt()); | |||
|
110 | } | |||
|
111 | } | |||
|
112 | else if (line.at(0).compare("SOCKS",Qt::CaseInsensitive)) | |||
|
113 | { | |||
|
114 | QStringList proxyArgs=line.at(1).split(":"); | |||
|
115 | if(proxyArgs.count()>=2) | |||
|
116 | { | |||
|
117 | result << QNetworkProxy(QNetworkProxy::Socks5Proxy,proxyArgs.at(0),proxyArgs.at(1).toUInt()); | |||
|
118 | } | |||
|
119 | } | |||
|
120 | else | |||
|
121 | { | |||
|
122 | result << QNetworkProxy(QNetworkProxy::NoProxy); | |||
|
123 | } | |||
|
124 | } | |||
|
125 | else | |||
|
126 | { | |||
|
127 | result << QNetworkProxy(QNetworkProxy::NoProxy); | |||
|
128 | } | |||
|
129 | } | |||
|
130 | return result; | |||
|
131 | } | |||
|
132 | ||||
|
133 | void QLopNetworkProxyFactory::reloadConfig() | |||
|
134 | { | |||
|
135 | QString proxyType = QLopSettings::value(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,CFG_PROXY_TYPE_VALUE_NONE).toString(); | |||
|
136 | if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_NONE)) | |||
|
137 | { | |||
|
138 | this->proxyCfgType = none; | |||
|
139 | } | |||
|
140 | else | |||
|
141 | if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_MANUAL)) | |||
|
142 | { | |||
|
143 | this->proxyCfgType = manual; | |||
|
144 | QString host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY).toString(); | |||
|
145 | QString port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY).toString(); | |||
|
146 | this->p_http_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt()); | |||
|
147 | ||||
|
148 | host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY).toString(); | |||
|
149 | port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY).toString(); | |||
|
150 | this->p_https_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt()); | |||
|
151 | ||||
|
152 | host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY).toString(); | |||
|
153 | port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY).toString(); | |||
|
154 | this->p_ftp_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt()); | |||
|
155 | ||||
|
156 | host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY).toString(); | |||
|
157 | port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY).toString(); | |||
|
158 | this->p_socks_proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy,host,port.toUInt()); | |||
|
159 | ||||
|
160 | } | |||
|
161 | else | |||
|
162 | if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_SYSTEM)) | |||
|
163 | { | |||
|
164 | this->proxyCfgType = system; | |||
|
165 | } | |||
|
166 | else | |||
|
167 | if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_AUTOMATIC)) | |||
|
168 | { | |||
|
169 | this->proxyCfgType = automatic; | |||
|
170 | } | |||
|
171 | } |
@@ -0,0 +1,78 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the QLop Software | |||
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | ----------------------------------------------------------------------------*/ | |||
|
22 | #ifndef QLOPNETWORKPROXYFACTORY_H | |||
|
23 | #define QLOPNETWORKPROXYFACTORY_H | |||
|
24 | ||||
|
25 | #include <QObject> | |||
|
26 | #include <QNetworkProxyFactory> | |||
|
27 | #include <QHostAddress> | |||
|
28 | #include <proxypacparser.h> | |||
|
29 | ||||
|
30 | #define CFG_PROXY_TYPE_ENTRY "proxy/type" | |||
|
31 | #define CFG_PROXY_TYPE_VALUE_NONE "none" | |||
|
32 | #define CFG_PROXY_TYPE_VALUE_MANUAL "manual" | |||
|
33 | #define CFG_PROXY_TYPE_VALUE_SYSTEM "system" | |||
|
34 | #define CFG_PROXY_TYPE_VALUE_AUTOMATIC "automatic" | |||
|
35 | #define CFG_PROXY_HTTP_HOST_ENTRY "proxy/http/host" | |||
|
36 | #define CFG_PROXY_HTTP_PORT_ENTRY "proxy/http/port" | |||
|
37 | #define CFG_PROXY_HTTPS_HOST_ENTRY "proxy/https/host" | |||
|
38 | #define CFG_PROXY_HTTPS_PORT_ENTRY "proxy/https/port" | |||
|
39 | #define CFG_PROXY_FTP_HOST_ENTRY "proxy/ftp/host" | |||
|
40 | #define CFG_PROXY_FTP_PORT_ENTRY "proxy/ftp/port" | |||
|
41 | #define CFG_PROXY_SOCKS_HOST_ENTRY "proxy/socks/host" | |||
|
42 | #define CFG_PROXY_SOCKS_PORT_ENTRY "proxy/socks/port" | |||
|
43 | ||||
|
44 | #define CFG_PROXY_IGNORE_HOSTS_ENTRY "proxy/ignore_hosts" | |||
|
45 | ||||
|
46 | ||||
|
47 | ||||
|
48 | class QLopNetworkProxyFactory : public QNetworkProxyFactory | |||
|
49 | { | |||
|
50 | public: | |||
|
51 | QLopNetworkProxyFactory(); | |||
|
52 | ~QLopNetworkProxyFactory(); | |||
|
53 | ||||
|
54 | QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()); | |||
|
55 | QList<QNetworkProxy> queryProxy_manual(const QNetworkProxyQuery &query = QNetworkProxyQuery()); | |||
|
56 | QList<QNetworkProxy> queryProxy_system(const QNetworkProxyQuery &query = QNetworkProxyQuery()); | |||
|
57 | QList<QNetworkProxy> queryProxy_auto(const QNetworkProxyQuery &query = QNetworkProxyQuery()); | |||
|
58 | ||||
|
59 | void reloadConfig(); | |||
|
60 | private: | |||
|
61 | typedef enum proxyCfgType_t | |||
|
62 | { | |||
|
63 | none=0, | |||
|
64 | manual=1, | |||
|
65 | system=2, | |||
|
66 | automatic=3 | |||
|
67 | }proxyCfgType_t; | |||
|
68 | proxyCfgType_t proxyCfgType; | |||
|
69 | ||||
|
70 | //======================================================================= | |||
|
71 | // MANUAL PROXY CFG | |||
|
72 | //======================================================================= | |||
|
73 | QNetworkProxy p_http_proxy,p_https_proxy,p_ftp_proxy,p_socks_proxy; | |||
|
74 | QList<QHostAddress> p_ignoreHosts; | |||
|
75 | ProxyPacParser* p_pacParser; | |||
|
76 | }; | |||
|
77 | ||||
|
78 | #endif // QLOPNETWORKPROXYFACTORY_H |
@@ -1,164 +1,170 | |||||
1 | #------------------------------------------------- |
|
1 | #------------------------------------------------- | |
2 | # |
|
2 | # | |
3 | # Project created by QtCreator 2015-01-07T02:41:29 |
|
3 | # Project created by QtCreator 2015-01-07T02:41:29 | |
4 | # |
|
4 | # | |
5 | #------------------------------------------------- |
|
5 | #------------------------------------------------- | |
6 |
|
6 | |||
7 | QT += core gui network xml svg |
|
7 | QT += core gui network xml svg script | |
8 | CONFIG += pythonqt |
|
8 | CONFIG += pythonqt | |
9 |
|
9 | |||
10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport |
|
10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport | |
11 |
|
11 | |||
12 | MOC_DIR = moc |
|
12 | MOC_DIR = moc | |
13 | UI_DIR = ui |
|
13 | UI_DIR = ui | |
14 | OBJECTS_DIR = obj |
|
14 | OBJECTS_DIR = obj | |
15 |
|
15 | |||
16 | DESTDIR =./bin |
|
16 | DESTDIR =./bin | |
17 |
|
17 | |||
18 | TARGET = QLop |
|
18 | TARGET = QLop | |
19 | TEMPLATE = app |
|
19 | TEMPLATE = app | |
20 |
|
20 | |||
21 | LIBS+=-lfftw3_threads -lfftw3 |
|
21 | LIBS+=-lfftw3_threads -lfftw3 | |
22 |
|
22 | |||
23 | INCLUDEPATH += src/QCustomPlot \ |
|
23 | INCLUDEPATH += src/QCustomPlot \ | |
24 | src src/Cassini \ |
|
24 | src src/Cassini \ | |
|
25 | src/Core/network \ | |||
25 | src/Core src/Core/Widgets \ |
|
26 | src/Core src/Core/Widgets \ | |
26 | src/Core/Widgets/PyWdgt |
|
27 | src/Core/Widgets/PyWdgt | |
27 |
|
28 | |||
28 | defined(QLOP_DEBUG,var){ |
|
29 | defined(QLOP_DEBUG,var){ | |
|
30 | message("building without optimisation") | |||
29 | QMAKE_CXXFLAGS += -O0 -fopenmp |
|
31 | QMAKE_CXXFLAGS += -O0 -fopenmp | |
30 | QMAKE_LFLAGS += -O0 -fopenmp |
|
32 | QMAKE_LFLAGS += -O0 -fopenmp | |
31 | } |
|
33 | } | |
32 | !defined(QLOP_DEBUG,var){ |
|
34 | !defined(QLOP_DEBUG,var){ | |
33 | QMAKE_CXXFLAGS += -O5 -fopenmp |
|
35 | QMAKE_CXXFLAGS += -O5 -fopenmp | |
34 | QMAKE_LFLAGS += -O5 -fopenmp |
|
36 | QMAKE_LFLAGS += -O5 -fopenmp | |
35 | } |
|
37 | } | |
36 |
|
38 | |||
37 |
|
39 | |||
38 | SOURCES += src/main.cpp\ |
|
40 | SOURCES += src/main.cpp\ | |
39 | src/mainwindow.cpp \ |
|
41 | src/mainwindow.cpp \ | |
40 | src/SocExplorerPlot.cpp \ |
|
42 | src/SocExplorerPlot.cpp \ | |
41 | src/QCustomPlot/qcustomplot.cpp \ |
|
43 | src/QCustomPlot/qcustomplot.cpp \ | |
42 | src/toolbarcontainer.cpp \ |
|
44 | src/toolbarcontainer.cpp \ | |
43 | src/Core/abstractfileloader.cpp \ |
|
45 | src/Core/abstractfileloader.cpp \ | |
44 | src/Core/filedownloader.cpp \ |
|
46 | src/Core/network/filedownloader.cpp \ | |
45 | src/Core/filedownloadertask.cpp \ |
|
47 | src/Core/network/filedownloadertask.cpp \ | |
46 | src/Core/Widgets/downloadhistory.cpp \ |
|
48 | src/Core/Widgets/downloadhistory.cpp \ | |
47 | src/Core/Widgets/downloadhistoryelement.cpp \ |
|
49 | src/Core/Widgets/downloadhistoryelement.cpp \ | |
48 | src/Core/qlopservice.cpp \ |
|
50 | src/Core/qlopservice.cpp \ | |
49 | src/Cassini/expxmldownloader.cpp \ |
|
51 | src/Cassini/expxmldownloader.cpp \ | |
50 | src/Cassini/cassinidatadownloader.cpp \ |
|
52 | src/Cassini/cassinidatadownloader.cpp \ | |
51 | src/Cassini/cassinidatafile.cpp \ |
|
53 | src/Cassini/cassinidatafile.cpp \ | |
52 | src/Cassini/cassiniindexfile.cpp \ |
|
54 | src/Cassini/cassiniindexfile.cpp \ | |
53 | src/Cassini/cassiniindexfileviewer.cpp \ |
|
55 | src/Cassini/cassiniindexfileviewer.cpp \ | |
54 | src/Cassini/cassinitools.cpp \ |
|
56 | src/Cassini/cassinitools.cpp \ | |
55 | src/Cassini/cassinitoolsgui.cpp \ |
|
57 | src/Cassini/cassinitoolsgui.cpp \ | |
56 | src/Core/Widgets/qlopplots.cpp \ |
|
58 | src/Core/Widgets/qlopplots.cpp \ | |
57 | src/Core/qlopdata.cpp \ |
|
59 | src/Core/qlopdata.cpp \ | |
58 | src/Core/Widgets/PyWdgt/pythonconsole.cpp \ |
|
60 | src/Core/Widgets/PyWdgt/pythonconsole.cpp \ | |
59 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.cpp \ |
|
61 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.cpp \ | |
60 | src/QCustomPlot/qcpdocumentobject.cpp \ |
|
62 | src/QCustomPlot/qcpdocumentobject.cpp \ | |
61 | src/Core/Widgets/filebrowser.cpp \ |
|
63 | src/Core/Widgets/filebrowser.cpp \ | |
62 | src/Core/Widgets/filesystemmodel.cpp \ |
|
64 | src/Core/Widgets/filesystemmodel.cpp \ | |
63 | src/Core/Widgets/qcustomplotvect.cpp \ |
|
65 | src/Core/Widgets/qcustomplotvect.cpp \ | |
64 | src/Core/qlopdatabase.cpp \ |
|
66 | src/Core/qlopdatabase.cpp \ | |
65 | src/Core/Widgets/qlopdatabaseviewer.cpp \ |
|
67 | src/Core/Widgets/qlopdatabaseviewer.cpp \ | |
66 | src/Core/Widgets/qlopdatabaseviewermodel.cpp \ |
|
68 | src/Core/Widgets/qlopdatabaseviewermodel.cpp \ | |
67 | src/Cassini/exptimetabledownloader.cpp \ |
|
69 | src/Cassini/exptimetabledownloader.cpp \ | |
68 | src/Core/qlopsettings.cpp \ |
|
70 | src/Core/qlopsettings.cpp \ | |
69 | src/Core/Widgets/filedowloadersettingsgui.cpp \ |
|
71 | src/Core/Widgets/filedowloadersettingsgui.cpp \ | |
70 | src/Core/qlopgui.cpp \ |
|
72 | src/Core/qlopgui.cpp \ | |
71 | src/Core/Widgets/manualproxycfg_gui.cpp \ |
|
73 | src/Core/Widgets/manualproxycfg_gui.cpp \ | |
72 | src/Core/Widgets/qlopsettingsdialog.cpp \ |
|
74 | src/Core/Widgets/qlopsettingsdialog.cpp \ | |
73 | src/Cassini/cassinitoolssettingsgui.cpp |
|
75 | src/Cassini/cassinitoolssettingsgui.cpp \ | |
|
76 | src/Core/network/proxypacparser.cpp \ | |||
|
77 | src/Core/network/qlopnetworkproxyfactory.cpp | |||
74 |
|
78 | |||
75 | HEADERS += src/mainwindow.h \ |
|
79 | HEADERS += src/mainwindow.h \ | |
76 | src/SocExplorerPlot.h \ |
|
80 | src/SocExplorerPlot.h \ | |
77 | src/QCustomPlot/qcustomplot.h \ |
|
81 | src/QCustomPlot/qcustomplot.h \ | |
78 | src/toolbarcontainer.h \ |
|
82 | src/toolbarcontainer.h \ | |
79 | src/Core/abstractfileloader.h \ |
|
83 | src/Core/abstractfileloader.h \ | |
80 | src/Core/filedownloader.h \ |
|
84 | src/Core/network/filedownloader.h \ | |
81 | src/Core/filedownloadertask.h \ |
|
85 | src/Core/network/filedownloadertask.h \ | |
82 | src/Core/Widgets/downloadhistory.h \ |
|
86 | src/Core/Widgets/downloadhistory.h \ | |
83 | src/Core/Widgets/downloadhistoryelement.h \ |
|
87 | src/Core/Widgets/downloadhistoryelement.h \ | |
84 | src/Core/qlopservice.h \ |
|
88 | src/Core/qlopservice.h \ | |
85 | src/Cassini/expxmldownloader.h \ |
|
89 | src/Cassini/expxmldownloader.h \ | |
86 | src/Cassini/cassinidatadownloader.h \ |
|
90 | src/Cassini/cassinidatadownloader.h \ | |
87 | src/Cassini/cassinidatafile.h \ |
|
91 | src/Cassini/cassinidatafile.h \ | |
88 | src/Cassini/cassiniindexfile.h \ |
|
92 | src/Cassini/cassiniindexfile.h \ | |
89 | src/Cassini/cassiniindexfileviewer.h \ |
|
93 | src/Cassini/cassiniindexfileviewer.h \ | |
90 | src/Cassini/cassinitools.h \ |
|
94 | src/Cassini/cassinitools.h \ | |
91 | src/Cassini/cassinitoolsgui.h \ |
|
95 | src/Cassini/cassinitoolsgui.h \ | |
92 | src/Core/Widgets/qlopplots.h \ |
|
96 | src/Core/Widgets/qlopplots.h \ | |
93 | src/Core/qlopdata.h \ |
|
97 | src/Core/qlopdata.h \ | |
94 | src/Core/Widgets/PyWdgt/pythonconsole.h \ |
|
98 | src/Core/Widgets/PyWdgt/pythonconsole.h \ | |
95 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.h \ |
|
99 | src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.h \ | |
96 | src/Core/qlop.h \ |
|
100 | src/Core/qlop.h \ | |
97 | src/Core/pyqlop.h \ |
|
101 | src/Core/pyqlop.h \ | |
98 | src/QCustomPlot/qcpdocumentobject.h \ |
|
102 | src/QCustomPlot/qcpdocumentobject.h \ | |
99 | src/Core/Widgets/filebrowser.h \ |
|
103 | src/Core/Widgets/filebrowser.h \ | |
100 | src/Core/Widgets/filesystemmodel.h \ |
|
104 | src/Core/Widgets/filesystemmodel.h \ | |
101 | src/Core/Widgets/qcustomplotvect.h \ |
|
105 | src/Core/Widgets/qcustomplotvect.h \ | |
102 | src/Core/qlopdatabase.h \ |
|
106 | src/Core/qlopdatabase.h \ | |
103 | src/Core/Widgets/qlopdatabaseviewer.h \ |
|
107 | src/Core/Widgets/qlopdatabaseviewer.h \ | |
104 | src/Core/Widgets/qlopdatabaseviewermodel.h \ |
|
108 | src/Core/Widgets/qlopdatabaseviewermodel.h \ | |
105 | src/Cassini/exptimetabledownloader.h \ |
|
109 | src/Cassini/exptimetabledownloader.h \ | |
106 | src/Core/qlopsettings.h \ |
|
110 | src/Core/qlopsettings.h \ | |
107 | src/Core/Widgets/filedowloadersettingsgui.h \ |
|
111 | src/Core/Widgets/filedowloadersettingsgui.h \ | |
108 | src/Core/qlopgui.h \ |
|
112 | src/Core/qlopgui.h \ | |
109 | src/Core/Widgets/manualproxycfg_gui.h \ |
|
113 | src/Core/Widgets/manualproxycfg_gui.h \ | |
110 | src/Core/Widgets/qlopsettingsdialog.h \ |
|
114 | src/Core/Widgets/qlopsettingsdialog.h \ | |
111 | src/Cassini/cassinitoolssettingsgui.h |
|
115 | src/Cassini/cassinitoolssettingsgui.h \ | |
|
116 | src/Core/network/proxypacparser.h \ | |||
|
117 | src/Core/network/qlopnetworkproxyfactory.h | |||
112 |
|
118 | |||
113 | FORMS += src/mainwindow.ui \ |
|
119 | FORMS += src/mainwindow.ui \ | |
114 | src/Core/Widgets/downloadhistory.ui \ |
|
120 | src/Core/Widgets/downloadhistory.ui \ | |
115 | src/Core/Widgets/downloadhistoryelement.ui \ |
|
121 | src/Core/Widgets/downloadhistoryelement.ui \ | |
116 | src/Cassini/cassinidatadownloader.ui \ |
|
122 | src/Cassini/cassinidatadownloader.ui \ | |
117 | src/Cassini/cassiniindexfileviewer.ui \ |
|
123 | src/Cassini/cassiniindexfileviewer.ui \ | |
118 | src/Cassini/cassinitoolsgui.ui \ |
|
124 | src/Cassini/cassinitoolsgui.ui \ | |
119 | src/Core/Widgets/filebrowser.ui \ |
|
125 | src/Core/Widgets/filebrowser.ui \ | |
120 | src/Core/Widgets/qlopdatabaseviewer.ui \ |
|
126 | src/Core/Widgets/qlopdatabaseviewer.ui \ | |
121 | src/Core/Widgets/filedowloadersettingsgui.ui \ |
|
127 | src/Core/Widgets/filedowloadersettingsgui.ui \ | |
122 | src/Core/Widgets/manualproxycfg_gui.ui \ |
|
128 | src/Core/Widgets/manualproxycfg_gui.ui \ | |
123 | src/Core/Widgets/qlopsettingsdialog.ui \ |
|
129 | src/Core/Widgets/qlopsettingsdialog.ui \ | |
124 | src/Cassini/cassinitoolssettingsgui.ui |
|
130 | src/Cassini/cassinitoolssettingsgui.ui | |
125 |
|
131 | |||
126 | RESOURCES += \ |
|
132 | RESOURCES += \ | |
127 | resources/qlop.qrc |
|
133 | resources/qlop.qrc | |
128 |
|
134 | |||
129 | include(src/Core/Widgets/NicePyConsole/NicePyConsole.pri) |
|
135 | include(src/Core/Widgets/NicePyConsole/NicePyConsole.pri) | |
130 | include(src/Core/pythonQtOut/generated_cpp/PyQLop/PyQLop.pri) |
|
136 | include(src/Core/pythonQtOut/generated_cpp/PyQLop/PyQLop.pri) | |
131 |
|
137 | |||
132 | win32 { |
|
138 | win32 { | |
133 | DEFINES += WIN32 |
|
139 | DEFINES += WIN32 | |
134 | } |
|
140 | } | |
135 |
|
141 | |||
136 | unix { |
|
142 | unix { | |
137 | DEFINES += UNIX |
|
143 | DEFINES += UNIX | |
138 | } |
|
144 | } | |
139 |
|
145 | |||
140 | unix{ |
|
146 | unix{ | |
141 | target.path = /usr/bin |
|
147 | target.path = /usr/bin | |
142 | INSTALLS += target |
|
148 | INSTALLS += target | |
143 | } |
|
149 | } | |
144 |
|
150 | |||
145 |
|
151 | |||
146 | unix{ |
|
152 | unix{ | |
147 | QLopLauncher.path = /usr/share/applications/ |
|
153 | QLopLauncher.path = /usr/share/applications/ | |
148 | QLopLauncher.files = linux/QLop.desktop |
|
154 | QLopLauncher.files = linux/QLop.desktop | |
149 | QLopAppData.path = /usr/share/appdata/ |
|
155 | QLopAppData.path = /usr/share/appdata/ | |
150 | QLopAppData.files = linux/QLop.appdata.xml |
|
156 | QLopAppData.files = linux/QLop.appdata.xml | |
151 | share.path = /usr/share/QLop |
|
157 | share.path = /usr/share/QLop | |
152 | share.files = resources/QLop.svg \ |
|
158 | share.files = resources/QLop.svg \ | |
153 | resources/QLop.png |
|
159 | resources/QLop.png | |
154 |
|
160 | |||
155 | INSTALLS+= QLopLauncher share QLopAppData |
|
161 | INSTALLS+= QLopLauncher share QLopAppData | |
156 | } |
|
162 | } | |
157 |
|
163 | |||
158 | DISTFILES += \ |
|
164 | DISTFILES += \ | |
159 | src/Core/pythongenerator.sh \ |
|
165 | src/Core/pythongenerator.sh \ | |
160 | src/Core/pythonQtgeneratorCfg.txt \ |
|
166 | src/Core/pythonQtgeneratorCfg.txt \ | |
161 | linux/QLop.spec \ |
|
167 | linux/QLop.spec \ | |
162 | linux/QLop.desktop \ |
|
168 | linux/QLop.desktop \ | |
163 | linux/QLop.appdata.xml |
|
169 | linux/QLop.appdata.xml | |
164 |
|
170 |
@@ -1,15 +1,18 | |||||
1 | <RCC> |
|
1 | <RCC> | |
2 | <qresource prefix="/img"> |
|
2 | <qresource prefix="/img"> | |
3 | <file>Gnome-view-refresh.svg</file> |
|
3 | <file>Gnome-view-refresh.svg</file> | |
4 | <file>Gnome-list-add.svg</file> |
|
4 | <file>Gnome-list-add.svg</file> | |
5 | <file>ListView.svg</file> |
|
5 | <file>ListView.svg</file> | |
6 | <file>TreeView.svg</file> |
|
6 | <file>TreeView.svg</file> | |
7 | <file>Gnome-go-up.svg</file> |
|
7 | <file>Gnome-go-up.svg</file> | |
8 | <file>QLop.svg</file> |
|
8 | <file>QLop.svg</file> | |
9 | <file>Gnome-emblem-downloads.svg</file> |
|
9 | <file>Gnome-emblem-downloads.svg</file> | |
10 | <file>cassini.gif</file> |
|
10 | <file>cassini.gif</file> | |
|
11 | <file>restart.png</file> | |||
|
12 | <file>start.png</file> | |||
|
13 | <file>stop.png</file> | |||
11 | </qresource> |
|
14 | </qresource> | |
12 | <qresource prefix="/"> |
|
15 | <qresource prefix="/"> | |
13 | <file>QLop.png</file> |
|
16 | <file>QLop.png</file> | |
14 | </qresource> |
|
17 | </qresource> | |
15 | </RCC> |
|
18 | </RCC> |
@@ -1,26 +1,26 | |||||
1 | #include "cassinitoolssettingsgui.h" |
|
1 | #include "cassinitoolssettingsgui.h" | |
2 | #include "ui_cassinitoolssettingsgui.h" |
|
2 | #include "ui_cassinitoolssettingsgui.h" | |
3 |
|
3 | |||
4 | CassiniToolsSettingsGUI::CassiniToolsSettingsGUI(QWidget *parent) : |
|
4 | CassiniToolsSettingsGUI::CassiniToolsSettingsGUI(QWidget *parent) : | |
5 |
Q |
|
5 | QLopSettingsItem(parent), | |
6 | ui(new Ui::CassiniToolsSettingsGUI) |
|
6 | ui(new Ui::CassiniToolsSettingsGUI) | |
7 | { |
|
7 | { | |
8 | ui->setupUi(this); |
|
8 | ui->setupUi(this); | |
9 | } |
|
9 | } | |
10 |
|
10 | |||
11 | CassiniToolsSettingsGUI::~CassiniToolsSettingsGUI() |
|
11 | CassiniToolsSettingsGUI::~CassiniToolsSettingsGUI() | |
12 | { |
|
12 | { | |
13 | delete ui; |
|
13 | delete ui; | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | void CassiniToolsSettingsGUI::changeEvent(QEvent *e) |
|
16 | void CassiniToolsSettingsGUI::changeEvent(QEvent *e) | |
17 | { |
|
17 | { | |
18 | QWidget::changeEvent(e); |
|
18 | QWidget::changeEvent(e); | |
19 | switch (e->type()) { |
|
19 | switch (e->type()) { | |
20 | case QEvent::LanguageChange: |
|
20 | case QEvent::LanguageChange: | |
21 | ui->retranslateUi(this); |
|
21 | ui->retranslateUi(this); | |
22 | break; |
|
22 | break; | |
23 | default: |
|
23 | default: | |
24 | break; |
|
24 | break; | |
25 | } |
|
25 | } | |
26 | } |
|
26 | } |
@@ -1,25 +1,27 | |||||
1 | #ifndef CASSINITOOLSSETTINGSGUI_H |
|
1 | #ifndef CASSINITOOLSSETTINGSGUI_H | |
2 | #define CASSINITOOLSSETTINGSGUI_H |
|
2 | #define CASSINITOOLSSETTINGSGUI_H | |
3 |
|
3 | |||
4 | #include <QWidget> |
|
4 | #include <QWidget> | |
5 |
|
5 | #include <qlopsettingsdialog.h> | ||
6 | namespace Ui { |
|
6 | namespace Ui { | |
7 | class CassiniToolsSettingsGUI; |
|
7 | class CassiniToolsSettingsGUI; | |
8 | } |
|
8 | } | |
9 |
|
9 | |||
10 |
class CassiniToolsSettingsGUI : public Q |
|
10 | class CassiniToolsSettingsGUI : public QLopSettingsItem | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 |
|
13 | |||
14 | public: |
|
14 | public: | |
15 | explicit CassiniToolsSettingsGUI(QWidget *parent = 0); |
|
15 | explicit CassiniToolsSettingsGUI(QWidget *parent = 0); | |
16 | ~CassiniToolsSettingsGUI(); |
|
16 | ~CassiniToolsSettingsGUI(); | |
17 |
|
17 | |||
|
18 | public slots: | |||
|
19 | void accept(){} | |||
18 | protected: |
|
20 | protected: | |
19 | void changeEvent(QEvent *e); |
|
21 | void changeEvent(QEvent *e); | |
20 |
|
22 | |||
21 | private: |
|
23 | private: | |
22 | Ui::CassiniToolsSettingsGUI *ui; |
|
24 | Ui::CassiniToolsSettingsGUI *ui; | |
23 | }; |
|
25 | }; | |
24 |
|
26 | |||
25 | #endif // CASSINITOOLSSETTINGSGUI_H |
|
27 | #endif // CASSINITOOLSSETTINGSGUI_H |
@@ -1,58 +1,71 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>DownloadHistoryElement</class> |
|
3 | <class>DownloadHistoryElement</class> | |
4 | <widget class="QWidget" name="DownloadHistoryElement"> |
|
4 | <widget class="QWidget" name="DownloadHistoryElement"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>724</width> |
|
9 | <width>724</width> | |
10 | <height>74</height> |
|
10 | <height>74</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="sizePolicy"> |
|
13 | <property name="sizePolicy"> | |
14 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> |
|
14 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | |
15 | <horstretch>0</horstretch> |
|
15 | <horstretch>0</horstretch> | |
16 | <verstretch>0</verstretch> |
|
16 | <verstretch>0</verstretch> | |
17 | </sizepolicy> |
|
17 | </sizepolicy> | |
18 | </property> |
|
18 | </property> | |
19 | <property name="windowTitle"> |
|
19 | <property name="windowTitle"> | |
20 | <string>Form</string> |
|
20 | <string>Form</string> | |
21 | </property> |
|
21 | </property> | |
22 | <property name="styleSheet"> |
|
22 | <property name="styleSheet"> | |
23 | <string notr="true"/> |
|
23 | <string notr="true"/> | |
24 | </property> |
|
24 | </property> | |
25 | <layout class="QGridLayout" name="gridLayout"> |
|
25 | <layout class="QGridLayout" name="gridLayout"> | |
26 | <item row="0" column="0" rowspan="2"> |
|
26 | <item row="0" column="0" rowspan="2"> | |
27 | <widget class="QLabel" name="DownloadDate"> |
|
27 | <widget class="QLabel" name="DownloadDate"> | |
28 | <property name="text"> |
|
28 | <property name="text"> | |
29 | <string>TextLabel</string> |
|
29 | <string>TextLabel</string> | |
30 | </property> |
|
30 | </property> | |
31 | </widget> |
|
31 | </widget> | |
32 | </item> |
|
32 | </item> | |
33 | <item row="1" column="2"> |
|
33 | <item row="1" column="2"> | |
34 | <widget class="QProgressBar" name="progressBar"> |
|
34 | <widget class="QProgressBar" name="progressBar"> | |
35 | <property name="value"> |
|
35 | <property name="value"> | |
36 | <number>0</number> |
|
36 | <number>0</number> | |
37 | </property> |
|
37 | </property> | |
38 | </widget> |
|
38 | </widget> | |
39 | </item> |
|
39 | </item> | |
40 | <item row="1" column="1"> |
|
40 | <item row="1" column="1"> | |
41 | <widget class="QLabel" name="linkLbl"> |
|
41 | <widget class="QLabel" name="linkLbl"> | |
42 | <property name="text"> |
|
42 | <property name="text"> | |
43 | <string>TextLabel</string> |
|
43 | <string>TextLabel</string> | |
44 | </property> |
|
44 | </property> | |
45 | </widget> |
|
45 | </widget> | |
46 | </item> |
|
46 | </item> | |
47 | <item row="0" column="1" colspan="2"> |
|
47 | <item row="0" column="1" colspan="2"> | |
48 | <widget class="QLabel" name="FileNameLbl"> |
|
48 | <widget class="QLabel" name="FileNameLbl"> | |
49 | <property name="text"> |
|
49 | <property name="text"> | |
50 | <string>TextLabel</string> |
|
50 | <string>TextLabel</string> | |
51 | </property> |
|
51 | </property> | |
52 | </widget> |
|
52 | </widget> | |
53 | </item> |
|
53 | </item> | |
|
54 | <item row="1" column="3"> | |||
|
55 | <widget class="QPushButton" name="pauseQpb"> | |||
|
56 | <property name="text"> | |||
|
57 | <string/> | |||
|
58 | </property> | |||
|
59 | <property name="icon"> | |||
|
60 | <iconset resource="../../../resources/qlop.qrc"> | |||
|
61 | <normaloff>:/img/stop.png</normaloff>:/img/stop.png</iconset> | |||
|
62 | </property> | |||
|
63 | </widget> | |||
|
64 | </item> | |||
54 | </layout> |
|
65 | </layout> | |
55 | </widget> |
|
66 | </widget> | |
56 |
<resources |
|
67 | <resources> | |
|
68 | <include location="../../../resources/qlop.qrc"/> | |||
|
69 | </resources> | |||
57 | <connections/> |
|
70 | <connections/> | |
58 | </ui> |
|
71 | </ui> |
@@ -1,61 +1,79 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "filedowloadersettingsgui.h" |
|
22 | #include "filedowloadersettingsgui.h" | |
23 | #include "ui_filedowloadersettingsgui.h" |
|
23 | #include "ui_filedowloadersettingsgui.h" | |
|
24 | #include <qlopsettings.h> | |||
|
25 | #include <filedownloader.h> | |||
|
26 | #include <QDir> | |||
|
27 | #include <qlopnetworkproxyfactory.h> | |||
24 |
|
28 | |||
25 | FileDowloaderSettingsGUI::FileDowloaderSettingsGUI(QWidget *parent) : |
|
29 | FileDowloaderSettingsGUI::FileDowloaderSettingsGUI(QWidget *parent) : | |
26 |
Q |
|
30 | QLopSettingsItem(parent), | |
27 | ui(new Ui::FileDowloaderSettingsGUI) |
|
31 | ui(new Ui::FileDowloaderSettingsGUI) | |
28 | { |
|
32 | { | |
29 | ui->setupUi(this); |
|
33 | ui->setupUi(this); | |
30 | this->manualProxyCFG_GUI = new ManualProxyCFG_GUI(); |
|
34 | this->manualProxyCFG_GUI = new ManualProxyCFG_GUI(); | |
31 | lastWidget = NULL; |
|
35 | lastWidget = NULL; | |
32 | connect(this->ui->comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(proxyMethodChanged(QString))); |
|
36 | connect(this->ui->comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(proxyMethodChanged(QString))); | |
|
37 | QString proxyType = QLopSettings::value(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,CFG_PROXY_TYPE_VALUE_NONE).toString(); | |||
|
38 | for(int i=0;i<ui->comboBox->count();i++) | |||
|
39 | { | |||
|
40 | if(!this->ui->comboBox->itemText(i).compare(proxyType)) | |||
|
41 | this->ui->comboBox->setCurrentIndex(i); | |||
|
42 | } | |||
|
43 | this->ui->defaultDestPath->setText(QLopSettings::value(FileDownloader::self(),"default_path",QDir::homePath()+"/Downloads").toString()); | |||
33 | } |
|
44 | } | |
34 |
|
45 | |||
35 | FileDowloaderSettingsGUI::~FileDowloaderSettingsGUI() |
|
46 | FileDowloaderSettingsGUI::~FileDowloaderSettingsGUI() | |
36 | { |
|
47 | { | |
37 | delete ui; |
|
48 | delete ui; | |
38 | } |
|
49 | } | |
39 |
|
50 | |||
40 | void FileDowloaderSettingsGUI::changeEvent(QEvent *e) |
|
51 | void FileDowloaderSettingsGUI::changeEvent(QEvent *e) | |
41 | { |
|
52 | { | |
42 | QWidget::changeEvent(e); |
|
53 | QWidget::changeEvent(e); | |
43 | switch (e->type()) { |
|
54 | switch (e->type()) { | |
44 | case QEvent::LanguageChange: |
|
55 | case QEvent::LanguageChange: | |
45 | ui->retranslateUi(this); |
|
56 | ui->retranslateUi(this); | |
46 | break; |
|
57 | break; | |
47 | default: |
|
58 | default: | |
48 | break; |
|
59 | break; | |
49 | } |
|
60 | } | |
50 | } |
|
61 | } | |
51 |
|
62 | |||
|
63 | void FileDowloaderSettingsGUI::accept() | |||
|
64 | { | |||
|
65 | QLopSettings::setValue(FileDownloader::self(),"default_path",this->ui->defaultDestPath->text()); | |||
|
66 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,this->ui->comboBox->currentText()); | |||
|
67 | manualProxyCFG_GUI->saveConfig(); | |||
|
68 | } | |||
|
69 | ||||
52 | void FileDowloaderSettingsGUI::proxyMethodChanged(const QString &text) |
|
70 | void FileDowloaderSettingsGUI::proxyMethodChanged(const QString &text) | |
53 | { |
|
71 | { | |
54 | this->ui->gridLayout->removeWidget(this->lastWidget); |
|
72 | this->ui->gridLayout->removeWidget(this->lastWidget); | |
55 | if(text=="manual") |
|
73 | if(text==CFG_PROXY_TYPE_VALUE_MANUAL) | |
56 | { |
|
74 | { | |
57 | this->ui->gridLayout->addWidget(this->manualProxyCFG_GUI,1,0,1,-1); |
|
75 | this->ui->gridLayout->addWidget(this->manualProxyCFG_GUI,1,0,1,-1); | |
58 | this->lastWidget = this->manualProxyCFG_GUI; |
|
76 | this->lastWidget = this->manualProxyCFG_GUI; | |
59 | return; |
|
77 | return; | |
60 | } |
|
78 | } | |
61 | } |
|
79 | } |
@@ -1,51 +1,52 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef FILEDOWLOADERSETTINGSGUI_H |
|
22 | #ifndef FILEDOWLOADERSETTINGSGUI_H | |
23 | #define FILEDOWLOADERSETTINGSGUI_H |
|
23 | #define FILEDOWLOADERSETTINGSGUI_H | |
24 |
|
24 | |||
25 | #include <QWidget> |
|
25 | #include <QWidget> | |
26 | #include "manualproxycfg_gui.h" |
|
26 | #include "manualproxycfg_gui.h" | |
|
27 | #include <qlopsettingsdialog.h> | |||
27 |
|
28 | |||
28 | namespace Ui { |
|
29 | namespace Ui { | |
29 | class FileDowloaderSettingsGUI; |
|
30 | class FileDowloaderSettingsGUI; | |
30 | } |
|
31 | } | |
31 |
|
32 | |||
32 |
class FileDowloaderSettingsGUI : public Q |
|
33 | class FileDowloaderSettingsGUI : public QLopSettingsItem | |
33 | { |
|
34 | { | |
34 | Q_OBJECT |
|
35 | Q_OBJECT | |
35 |
|
36 | |||
36 | public: |
|
37 | public: | |
37 | explicit FileDowloaderSettingsGUI(QWidget *parent = 0); |
|
38 | explicit FileDowloaderSettingsGUI(QWidget *parent = 0); | |
38 | ~FileDowloaderSettingsGUI(); |
|
39 | ~FileDowloaderSettingsGUI(); | |
39 |
|
||||
40 | protected: |
|
40 | protected: | |
41 | void changeEvent(QEvent *e); |
|
41 | void changeEvent(QEvent *e); | |
42 |
|
42 | public slots: | ||
|
43 | void accept(); | |||
43 | private slots: |
|
44 | private slots: | |
44 | void proxyMethodChanged(const QString & text); |
|
45 | void proxyMethodChanged(const QString & text); | |
45 | private: |
|
46 | private: | |
46 | ManualProxyCFG_GUI* manualProxyCFG_GUI; |
|
47 | ManualProxyCFG_GUI* manualProxyCFG_GUI; | |
47 | Ui::FileDowloaderSettingsGUI *ui; |
|
48 | Ui::FileDowloaderSettingsGUI *ui; | |
48 | QWidget* lastWidget; |
|
49 | QWidget* lastWidget; | |
49 | }; |
|
50 | }; | |
50 |
|
51 | |||
51 | #endif // FILEDOWLOADERSETTINGSGUI_H |
|
52 | #endif // FILEDOWLOADERSETTINGSGUI_H |
@@ -1,74 +1,74 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>FileDowloaderSettingsGUI</class> |
|
3 | <class>FileDowloaderSettingsGUI</class> | |
4 | <widget class="QWidget" name="FileDowloaderSettingsGUI"> |
|
4 | <widget class="QWidget" name="FileDowloaderSettingsGUI"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>318</width> |
|
9 | <width>318</width> | |
10 | <height>128</height> |
|
10 | <height>128</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QFormLayout" name="formLayout"> |
|
16 | <layout class="QFormLayout" name="formLayout"> | |
17 | <item row="0" column="0"> |
|
17 | <item row="0" column="0"> | |
18 | <widget class="QLabel" name="label"> |
|
18 | <widget class="QLabel" name="label"> | |
19 | <property name="text"> |
|
19 | <property name="text"> | |
20 | <string>Default destination path</string> |
|
20 | <string>Default destination path</string> | |
21 | </property> |
|
21 | </property> | |
22 | </widget> |
|
22 | </widget> | |
23 | </item> |
|
23 | </item> | |
24 | <item row="0" column="1"> |
|
24 | <item row="0" column="1"> | |
25 |
<widget class="QLineEdit" name=" |
|
25 | <widget class="QLineEdit" name="defaultDestPath"/> | |
26 | </item> |
|
26 | </item> | |
27 | <item row="1" column="0" colspan="2"> |
|
27 | <item row="1" column="0" colspan="2"> | |
28 | <widget class="QGroupBox" name="groupBox"> |
|
28 | <widget class="QGroupBox" name="groupBox"> | |
29 | <property name="title"> |
|
29 | <property name="title"> | |
30 | <string>Proxy server</string> |
|
30 | <string>Proxy server</string> | |
31 | </property> |
|
31 | </property> | |
32 | <layout class="QGridLayout" name="gridLayout"> |
|
32 | <layout class="QGridLayout" name="gridLayout"> | |
33 | <item row="0" column="0"> |
|
33 | <item row="0" column="0"> | |
34 | <widget class="QLabel" name="label_2"> |
|
34 | <widget class="QLabel" name="label_2"> | |
35 | <property name="text"> |
|
35 | <property name="text"> | |
36 | <string>Method</string> |
|
36 | <string>Method</string> | |
37 | </property> |
|
37 | </property> | |
38 | <property name="alignment"> |
|
38 | <property name="alignment"> | |
39 | <set>Qt::AlignCenter</set> |
|
39 | <set>Qt::AlignCenter</set> | |
40 | </property> |
|
40 | </property> | |
41 | </widget> |
|
41 | </widget> | |
42 | </item> |
|
42 | </item> | |
43 | <item row="0" column="1"> |
|
43 | <item row="0" column="1"> | |
44 | <widget class="QComboBox" name="comboBox"> |
|
44 | <widget class="QComboBox" name="comboBox"> | |
45 | <item> |
|
45 | <item> | |
46 | <property name="text"> |
|
46 | <property name="text"> | |
47 | <string>none</string> |
|
47 | <string>none</string> | |
48 | </property> |
|
48 | </property> | |
49 | </item> |
|
49 | </item> | |
50 | <item> |
|
50 | <item> | |
51 | <property name="text"> |
|
51 | <property name="text"> | |
52 | <string>system</string> |
|
52 | <string>system</string> | |
53 | </property> |
|
53 | </property> | |
54 | </item> |
|
54 | </item> | |
55 | <item> |
|
55 | <item> | |
56 | <property name="text"> |
|
56 | <property name="text"> | |
57 | <string>manual</string> |
|
57 | <string>manual</string> | |
58 | </property> |
|
58 | </property> | |
59 | </item> |
|
59 | </item> | |
60 | <item> |
|
60 | <item> | |
61 | <property name="text"> |
|
61 | <property name="text"> | |
62 | <string>automatic</string> |
|
62 | <string>automatic</string> | |
63 | </property> |
|
63 | </property> | |
64 | </item> |
|
64 | </item> | |
65 | </widget> |
|
65 | </widget> | |
66 | </item> |
|
66 | </item> | |
67 | </layout> |
|
67 | </layout> | |
68 | </widget> |
|
68 | </widget> | |
69 | </item> |
|
69 | </item> | |
70 | </layout> |
|
70 | </layout> | |
71 | </widget> |
|
71 | </widget> | |
72 | <resources/> |
|
72 | <resources/> | |
73 | <connections/> |
|
73 | <connections/> | |
74 | </ui> |
|
74 | </ui> |
@@ -1,47 +1,85 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "manualproxycfg_gui.h" |
|
22 | #include "manualproxycfg_gui.h" | |
23 | #include "ui_manualproxycfg_gui.h" |
|
23 | #include "ui_manualproxycfg_gui.h" | |
|
24 | #include <qlopsettings.h> | |||
|
25 | #include <filedownloader.h> | |||
24 |
|
26 | |||
25 | ManualProxyCFG_GUI::ManualProxyCFG_GUI(QWidget *parent) : |
|
27 | ManualProxyCFG_GUI::ManualProxyCFG_GUI(QWidget *parent) : | |
26 | QWidget(parent), |
|
28 | QWidget(parent), | |
27 | ui(new Ui::ManualProxyCFG_GUI) |
|
29 | ui(new Ui::ManualProxyCFG_GUI) | |
28 | { |
|
30 | { | |
29 | ui->setupUi(this); |
|
31 | ui->setupUi(this); | |
|
32 | reloadConfig(); | |||
30 | } |
|
33 | } | |
31 |
|
34 | |||
32 | ManualProxyCFG_GUI::~ManualProxyCFG_GUI() |
|
35 | ManualProxyCFG_GUI::~ManualProxyCFG_GUI() | |
33 | { |
|
36 | { | |
34 | delete ui; |
|
37 | delete ui; | |
35 | } |
|
38 | } | |
36 |
|
39 | |||
|
40 | void ManualProxyCFG_GUI::reloadConfig() | |||
|
41 | { | |||
|
42 | this->ui->httpHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY,"").toString()); | |||
|
43 | this->ui->httpPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY,"").toString()); | |||
|
44 | ||||
|
45 | this->ui->httpsHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY,"").toString()); | |||
|
46 | this->ui->httpsPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY,"").toString()); | |||
|
47 | ||||
|
48 | this->ui->ftpHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY,"").toString()); | |||
|
49 | this->ui->ftpPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY,"").toString()); | |||
|
50 | ||||
|
51 | this->ui->socksHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY,"").toString()); | |||
|
52 | this->ui->socksPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY,"").toString()); | |||
|
53 | ||||
|
54 | this->ui->IgnoreHosts->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_IGNORE_HOSTS_ENTRY,"localhost, 127.0.0.0/8, ::1").toString()); | |||
|
55 | } | |||
|
56 | ||||
|
57 | void ManualProxyCFG_GUI::saveConfig() | |||
|
58 | { | |||
|
59 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY,this->ui->httpHost->text()); | |||
|
60 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY,this->ui->httpPort->text()); | |||
|
61 | ||||
|
62 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY,this->ui->httpsHost->text()); | |||
|
63 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY,this->ui->httpsPort->text()); | |||
|
64 | ||||
|
65 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY,this->ui->ftpHost->text()); | |||
|
66 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY,this->ui->ftpPort->text()); | |||
|
67 | ||||
|
68 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY,this->ui->socksHost->text()); | |||
|
69 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY,this->ui->socksPort->text()); | |||
|
70 | ||||
|
71 | QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_IGNORE_HOSTS_ENTRY,this->ui->IgnoreHosts->text()); | |||
|
72 | ||||
|
73 | } | |||
|
74 | ||||
37 | void ManualProxyCFG_GUI::changeEvent(QEvent *e) |
|
75 | void ManualProxyCFG_GUI::changeEvent(QEvent *e) | |
38 | { |
|
76 | { | |
39 | QWidget::changeEvent(e); |
|
77 | QWidget::changeEvent(e); | |
40 | switch (e->type()) { |
|
78 | switch (e->type()) { | |
41 | case QEvent::LanguageChange: |
|
79 | case QEvent::LanguageChange: | |
42 | ui->retranslateUi(this); |
|
80 | ui->retranslateUi(this); | |
43 | break; |
|
81 | break; | |
44 | default: |
|
82 | default: | |
45 | break; |
|
83 | break; | |
46 | } |
|
84 | } | |
47 | } |
|
85 | } |
@@ -1,46 +1,47 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef MANUALPROXYCFG_GUI_H |
|
22 | #ifndef MANUALPROXYCFG_GUI_H | |
23 | #define MANUALPROXYCFG_GUI_H |
|
23 | #define MANUALPROXYCFG_GUI_H | |
24 |
|
24 | |||
25 | #include <QWidget> |
|
25 | #include <QWidget> | |
26 |
|
26 | |||
27 | namespace Ui { |
|
27 | namespace Ui { | |
28 | class ManualProxyCFG_GUI; |
|
28 | class ManualProxyCFG_GUI; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | class ManualProxyCFG_GUI : public QWidget |
|
31 | class ManualProxyCFG_GUI : public QWidget | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | explicit ManualProxyCFG_GUI(QWidget *parent = 0); |
|
36 | explicit ManualProxyCFG_GUI(QWidget *parent = 0); | |
37 | ~ManualProxyCFG_GUI(); |
|
37 | ~ManualProxyCFG_GUI(); | |
38 |
|
38 | void reloadConfig(); | ||
|
39 | void saveConfig(); | |||
39 | protected: |
|
40 | protected: | |
40 | void changeEvent(QEvent *e); |
|
41 | void changeEvent(QEvent *e); | |
41 |
|
42 | |||
42 | private: |
|
43 | private: | |
43 | Ui::ManualProxyCFG_GUI *ui; |
|
44 | Ui::ManualProxyCFG_GUI *ui; | |
44 | }; |
|
45 | }; | |
45 |
|
46 | |||
46 | #endif // MANUALPROXYCFG_GUI_H |
|
47 | #endif // MANUALPROXYCFG_GUI_H |
@@ -1,109 +1,218 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>ManualProxyCFG_GUI</class> |
|
3 | <class>ManualProxyCFG_GUI</class> | |
4 | <widget class="QWidget" name="ManualProxyCFG_GUI"> |
|
4 | <widget class="QWidget" name="ManualProxyCFG_GUI"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>423</width> |
|
9 | <width>423</width> | |
10 | <height>207</height> |
|
10 | <height>207</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QGridLayout" name="gridLayout"> |
|
16 | <layout class="QGridLayout" name="gridLayout"> | |
17 | <item row="0" column="0"> |
|
17 | <item row="0" column="0"> | |
18 | <widget class="QLabel" name="label"> |
|
18 | <widget class="QLabel" name="label"> | |
|
19 | <property name="sizePolicy"> | |||
|
20 | <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> | |||
|
21 | <horstretch>0</horstretch> | |||
|
22 | <verstretch>0</verstretch> | |||
|
23 | </sizepolicy> | |||
|
24 | </property> | |||
19 | <property name="text"> |
|
25 | <property name="text"> | |
20 | <string>HTTP proxy</string> |
|
26 | <string>HTTP proxy</string> | |
21 | </property> |
|
27 | </property> | |
22 | </widget> |
|
28 | </widget> | |
23 | </item> |
|
29 | </item> | |
24 | <item row="0" column="1"> |
|
30 | <item row="0" column="1"> | |
25 |
<widget class="QLineEdit" name="httpHost" |
|
31 | <widget class="QLineEdit" name="httpHost"> | |
|
32 | <property name="sizePolicy"> | |||
|
33 | <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | |||
|
34 | <horstretch>0</horstretch> | |||
|
35 | <verstretch>0</verstretch> | |||
|
36 | </sizepolicy> | |||
|
37 | </property> | |||
|
38 | <property name="placeholderText"> | |||
|
39 | <string>Put host address here</string> | |||
|
40 | </property> | |||
|
41 | </widget> | |||
26 | </item> |
|
42 | </item> | |
27 | <item row="1" column="0"> |
|
43 | <item row="1" column="0"> | |
28 | <widget class="QLabel" name="label_2"> |
|
44 | <widget class="QLabel" name="label_2"> | |
|
45 | <property name="sizePolicy"> | |||
|
46 | <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> | |||
|
47 | <horstretch>0</horstretch> | |||
|
48 | <verstretch>0</verstretch> | |||
|
49 | </sizepolicy> | |||
|
50 | </property> | |||
29 | <property name="text"> |
|
51 | <property name="text"> | |
30 | <string>HTTPS proxy</string> |
|
52 | <string>HTTPS proxy</string> | |
31 | </property> |
|
53 | </property> | |
32 | </widget> |
|
54 | </widget> | |
33 | </item> |
|
55 | </item> | |
34 | <item row="1" column="1"> |
|
56 | <item row="1" column="1"> | |
35 |
<widget class="QLineEdit" name="httpsHost" |
|
57 | <widget class="QLineEdit" name="httpsHost"> | |
|
58 | <property name="sizePolicy"> | |||
|
59 | <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | |||
|
60 | <horstretch>0</horstretch> | |||
|
61 | <verstretch>0</verstretch> | |||
|
62 | </sizepolicy> | |||
|
63 | </property> | |||
|
64 | <property name="placeholderText"> | |||
|
65 | <string>Put host address here</string> | |||
|
66 | </property> | |||
|
67 | </widget> | |||
36 | </item> |
|
68 | </item> | |
37 | <item row="2" column="0"> |
|
69 | <item row="2" column="0"> | |
38 | <widget class="QLabel" name="label_3"> |
|
70 | <widget class="QLabel" name="label_3"> | |
|
71 | <property name="sizePolicy"> | |||
|
72 | <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> | |||
|
73 | <horstretch>0</horstretch> | |||
|
74 | <verstretch>0</verstretch> | |||
|
75 | </sizepolicy> | |||
|
76 | </property> | |||
39 | <property name="text"> |
|
77 | <property name="text"> | |
40 | <string>FTP proxy</string> |
|
78 | <string>FTP proxy</string> | |
41 | </property> |
|
79 | </property> | |
42 | </widget> |
|
80 | </widget> | |
43 | </item> |
|
81 | </item> | |
44 | <item row="2" column="1"> |
|
82 | <item row="2" column="1"> | |
45 |
<widget class="QLineEdit" name="ftpHost" |
|
83 | <widget class="QLineEdit" name="ftpHost"> | |
|
84 | <property name="sizePolicy"> | |||
|
85 | <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | |||
|
86 | <horstretch>0</horstretch> | |||
|
87 | <verstretch>0</verstretch> | |||
|
88 | </sizepolicy> | |||
|
89 | </property> | |||
|
90 | <property name="placeholderText"> | |||
|
91 | <string>Put host address here</string> | |||
|
92 | </property> | |||
|
93 | </widget> | |||
46 | </item> |
|
94 | </item> | |
47 | <item row="3" column="0"> |
|
95 | <item row="3" column="0"> | |
48 | <widget class="QLabel" name="label_4"> |
|
96 | <widget class="QLabel" name="label_4"> | |
|
97 | <property name="sizePolicy"> | |||
|
98 | <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> | |||
|
99 | <horstretch>0</horstretch> | |||
|
100 | <verstretch>0</verstretch> | |||
|
101 | </sizepolicy> | |||
|
102 | </property> | |||
49 | <property name="text"> |
|
103 | <property name="text"> | |
50 | <string>SOCKS proxy</string> |
|
104 | <string>SOCKS proxy</string> | |
51 | </property> |
|
105 | </property> | |
52 | </widget> |
|
106 | </widget> | |
53 | </item> |
|
107 | </item> | |
54 | <item row="3" column="1"> |
|
108 | <item row="3" column="1"> | |
55 |
<widget class="QLineEdit" name="socksHost" |
|
109 | <widget class="QLineEdit" name="socksHost"> | |
|
110 | <property name="sizePolicy"> | |||
|
111 | <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | |||
|
112 | <horstretch>0</horstretch> | |||
|
113 | <verstretch>0</verstretch> | |||
|
114 | </sizepolicy> | |||
|
115 | </property> | |||
|
116 | <property name="placeholderText"> | |||
|
117 | <string>Put host address here</string> | |||
|
118 | </property> | |||
|
119 | </widget> | |||
56 | </item> |
|
120 | </item> | |
57 | <item row="4" column="0"> |
|
121 | <item row="4" column="0"> | |
58 | <widget class="QLabel" name="label_5"> |
|
122 | <widget class="QLabel" name="label_5"> | |
|
123 | <property name="sizePolicy"> | |||
|
124 | <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> | |||
|
125 | <horstretch>0</horstretch> | |||
|
126 | <verstretch>0</verstretch> | |||
|
127 | </sizepolicy> | |||
|
128 | </property> | |||
59 | <property name="text"> |
|
129 | <property name="text"> | |
60 | <string>Ignore hosts</string> |
|
130 | <string>Ignore hosts</string> | |
61 | </property> |
|
131 | </property> | |
62 | </widget> |
|
132 | </widget> | |
63 | </item> |
|
133 | </item> | |
64 | <item row="0" column="2"> |
|
134 | <item row="0" column="2"> | |
65 | <widget class="QLineEdit" name="httpPort"> |
|
135 | <widget class="QLineEdit" name="httpPort"> | |
66 | <property name="sizePolicy"> |
|
136 | <property name="sizePolicy"> | |
67 |
<sizepolicy hsizetype="M |
|
137 | <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> | |
|
138 | <horstretch>0</horstretch> | |||
|
139 | <verstretch>0</verstretch> | |||
|
140 | </sizepolicy> | |||
|
141 | </property> | |||
|
142 | <property name="inputMask"> | |||
|
143 | <string>000000</string> | |||
|
144 | </property> | |||
|
145 | <property name="frame"> | |||
|
146 | <bool>true</bool> | |||
|
147 | </property> | |||
|
148 | <property name="placeholderText"> | |||
|
149 | <string>0 to 65536</string> | |||
|
150 | </property> | |||
|
151 | </widget> | |||
|
152 | </item> | |||
|
153 | <item row="1" column="2"> | |||
|
154 | <widget class="QLineEdit" name="httpsPort"> | |||
|
155 | <property name="sizePolicy"> | |||
|
156 | <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> | |||
68 | <horstretch>0</horstretch> |
|
157 | <horstretch>0</horstretch> | |
69 | <verstretch>0</verstretch> |
|
158 | <verstretch>0</verstretch> | |
70 | </sizepolicy> |
|
159 | </sizepolicy> | |
71 | </property> |
|
160 | </property> | |
72 | <property name="inputMask"> |
|
161 | <property name="inputMask"> | |
73 | <string>000000</string> |
|
162 | <string>000000</string> | |
74 | </property> |
|
163 | </property> | |
75 | </widget> |
|
164 | <property name="placeholderText"> | |
76 | </item> |
|
165 | <string>0 to 65536</string> | |
77 | <item row="1" column="2"> |
|
|||
78 | <widget class="QLineEdit" name="httpsPort"> |
|
|||
79 | <property name="inputMask"> |
|
|||
80 | <string>000000</string> |
|
|||
81 | </property> |
|
166 | </property> | |
82 | </widget> |
|
167 | </widget> | |
83 | </item> |
|
168 | </item> | |
84 | <item row="2" column="2"> |
|
169 | <item row="2" column="2"> | |
85 | <widget class="QLineEdit" name="ftpPort"> |
|
170 | <widget class="QLineEdit" name="ftpPort"> | |
|
171 | <property name="sizePolicy"> | |||
|
172 | <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> | |||
|
173 | <horstretch>0</horstretch> | |||
|
174 | <verstretch>0</verstretch> | |||
|
175 | </sizepolicy> | |||
|
176 | </property> | |||
86 | <property name="inputMask"> |
|
177 | <property name="inputMask"> | |
87 | <string>000000</string> |
|
178 | <string>000000</string> | |
88 | </property> |
|
179 | </property> | |
|
180 | <property name="placeholderText"> | |||
|
181 | <string>0 to 65536</string> | |||
|
182 | </property> | |||
89 | </widget> |
|
183 | </widget> | |
90 | </item> |
|
184 | </item> | |
91 | <item row="3" column="2"> |
|
185 | <item row="3" column="2"> | |
92 | <widget class="QLineEdit" name="socksPort"> |
|
186 | <widget class="QLineEdit" name="socksPort"> | |
|
187 | <property name="sizePolicy"> | |||
|
188 | <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> | |||
|
189 | <horstretch>0</horstretch> | |||
|
190 | <verstretch>0</verstretch> | |||
|
191 | </sizepolicy> | |||
|
192 | </property> | |||
93 | <property name="inputMask"> |
|
193 | <property name="inputMask"> | |
94 | <string>000000</string> |
|
194 | <string>000000</string> | |
95 | </property> |
|
195 | </property> | |
|
196 | <property name="placeholderText"> | |||
|
197 | <string>0 to 65536</string> | |||
|
198 | </property> | |||
96 | </widget> |
|
199 | </widget> | |
97 | </item> |
|
200 | </item> | |
98 | <item row="4" column="1" colspan="2"> |
|
201 | <item row="4" column="1" colspan="2"> | |
99 | <widget class="QLineEdit" name="IgnoreHosts"> |
|
202 | <widget class="QLineEdit" name="IgnoreHosts"> | |
|
203 | <property name="sizePolicy"> | |||
|
204 | <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | |||
|
205 | <horstretch>0</horstretch> | |||
|
206 | <verstretch>0</verstretch> | |||
|
207 | </sizepolicy> | |||
|
208 | </property> | |||
100 | <property name="text"> |
|
209 | <property name="text"> | |
101 | <string>localhost, 127.0.0.0/8, ::1</string> |
|
210 | <string>localhost, 127.0.0.0/8, ::1</string> | |
102 | </property> |
|
211 | </property> | |
103 | </widget> |
|
212 | </widget> | |
104 | </item> |
|
213 | </item> | |
105 | </layout> |
|
214 | </layout> | |
106 | </widget> |
|
215 | </widget> | |
107 | <resources/> |
|
216 | <resources/> | |
108 | <connections/> |
|
217 | <connections/> | |
109 | </ui> |
|
218 | </ui> |
@@ -1,70 +1,71 | |||||
1 | #include "qlopsettingsdialog.h" |
|
1 | #include "qlopsettingsdialog.h" | |
2 | #include "ui_qlopsettingsdialog.h" |
|
2 | #include "ui_qlopsettingsdialog.h" | |
3 |
|
3 | |||
4 | QLopSettingsDialog::QLopSettingsDialog(QWidget *parent) : |
|
4 | QLopSettingsDialog::QLopSettingsDialog(QWidget *parent) : | |
5 | QDialog(parent), |
|
5 | QDialog(parent), | |
6 | ui(new Ui::QLopSettingsDialog) |
|
6 | ui(new Ui::QLopSettingsDialog) | |
7 | { |
|
7 | { | |
8 | ui->setupUi(this); |
|
8 | ui->setupUi(this); | |
9 | connect(ui->contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*))); |
|
9 | connect(ui->contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*))); | |
10 | ui->contentsWidget->setViewMode(QListView::IconMode); |
|
10 | ui->contentsWidget->setViewMode(QListView::IconMode); | |
11 | ui->contentsWidget->setIconSize(QSize(96, 84)); |
|
11 | ui->contentsWidget->setIconSize(QSize(96, 84)); | |
12 | ui->contentsWidget->setMovement(QListView::Static); |
|
12 | ui->contentsWidget->setMovement(QListView::Static); | |
13 | ui->contentsWidget->setSpacing(12); |
|
13 | ui->contentsWidget->setSpacing(12); | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | QLopSettingsDialog::~QLopSettingsDialog() |
|
16 | QLopSettingsDialog::~QLopSettingsDialog() | |
17 | { |
|
17 | { | |
18 | delete ui; |
|
18 | delete ui; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void QLopSettingsDialog::changeEvent(QEvent *e) |
|
21 | void QLopSettingsDialog::changeEvent(QEvent *e) | |
22 | { |
|
22 | { | |
23 | QDialog::changeEvent(e); |
|
23 | QDialog::changeEvent(e); | |
24 | switch (e->type()) { |
|
24 | switch (e->type()) { | |
25 | case QEvent::LanguageChange: |
|
25 | case QEvent::LanguageChange: | |
26 | ui->retranslateUi(this); |
|
26 | ui->retranslateUi(this); | |
27 | break; |
|
27 | break; | |
28 | default: |
|
28 | default: | |
29 | break; |
|
29 | break; | |
30 | } |
|
30 | } | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | void QLopSettingsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) |
|
34 | void QLopSettingsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) | |
35 | { |
|
35 | { | |
36 | if (!current) |
|
36 | if (!current) | |
37 | current = previous; |
|
37 | current = previous; | |
38 |
|
38 | |||
39 | ui->pagesWidget->setCurrentIndex(ui->contentsWidget->row(current)); |
|
39 | ui->pagesWidget->setCurrentIndex(ui->contentsWidget->row(current)); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 |
bool QLopSettingsDialog::registerConfigEntry(Q |
|
42 | bool QLopSettingsDialog::registerConfigEntry(QLopSettingsItem *configEntry, QIcon icon, QString text) | |
43 | { |
|
43 | { | |
44 | if(configEntry!=NULL) |
|
44 | if(configEntry!=NULL) | |
45 | { |
|
45 | { | |
46 | ui->pagesWidget->addWidget(configEntry); |
|
46 | ui->pagesWidget->addWidget(configEntry); | |
47 | QListWidgetItem *configButton = new QListWidgetItem(ui->contentsWidget); |
|
47 | QListWidgetItem *configButton = new QListWidgetItem(ui->contentsWidget); | |
48 | configButton->setIcon(icon); |
|
48 | configButton->setIcon(icon); | |
49 | configButton->setText(text); |
|
49 | configButton->setText(text); | |
50 | configButton->setTextAlignment(Qt::AlignHCenter); |
|
50 | configButton->setTextAlignment(Qt::AlignHCenter); | |
51 | configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
|
51 | configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
|
52 | connect(this,SIGNAL(accepted()),configEntry,SLOT(accept())); | |||
52 | return true; |
|
53 | return true; | |
53 | } |
|
54 | } | |
54 | return false; |
|
55 | return false; | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 |
void QLopSettingsDialog::popConfigDialog(Q |
|
58 | void QLopSettingsDialog::popConfigDialog(QLopSettingsItem *selectedConfigEntry) | |
58 | { |
|
59 | { | |
59 | if(selectedConfigEntry!=NULL) |
|
60 | if(selectedConfigEntry!=NULL) | |
60 | { |
|
61 | { | |
61 | for(int i=0;i<ui->pagesWidget->count();i++) |
|
62 | for(int i=0;i<ui->pagesWidget->count();i++) | |
62 | { |
|
63 | { | |
63 | if(ui->pagesWidget->widget(i)==selectedConfigEntry) |
|
64 | if(ui->pagesWidget->widget(i)==selectedConfigEntry) | |
64 | { |
|
65 | { | |
65 | ui->pagesWidget->setCurrentIndex(i); |
|
66 | ui->pagesWidget->setCurrentIndex(i); | |
66 | } |
|
67 | } | |
67 | } |
|
68 | } | |
68 | } |
|
69 | } | |
69 | this->show(); |
|
70 | this->show(); | |
70 | } |
|
71 | } |
@@ -1,30 +1,40 | |||||
1 | #ifndef QLOPSETTINGSDIALOG_H |
|
1 | #ifndef QLOPSETTINGSDIALOG_H | |
2 | #define QLOPSETTINGSDIALOG_H |
|
2 | #define QLOPSETTINGSDIALOG_H | |
3 |
|
3 | |||
4 | #include <QDialog> |
|
4 | #include <QDialog> | |
5 |
|
5 | |||
6 | namespace Ui { |
|
6 | namespace Ui { | |
7 | class QLopSettingsDialog; |
|
7 | class QLopSettingsDialog; | |
8 | } |
|
8 | } | |
9 | #include <QListWidgetItem> |
|
9 | #include <QListWidgetItem> | |
10 |
|
10 | |||
|
11 | class QLopSettingsItem : public QWidget | |||
|
12 | { | |||
|
13 | Q_OBJECT | |||
|
14 | public: | |||
|
15 | QLopSettingsItem(QWidget *parent = 0):QWidget(parent) {} | |||
|
16 | ~QLopSettingsItem() {} | |||
|
17 | public slots: | |||
|
18 | virtual void accept()=0; | |||
|
19 | }; | |||
|
20 | ||||
11 | class QLopSettingsDialog : public QDialog |
|
21 | class QLopSettingsDialog : public QDialog | |
12 | { |
|
22 | { | |
13 | Q_OBJECT |
|
23 | Q_OBJECT | |
14 |
|
24 | |||
15 | public: |
|
25 | public: | |
16 | explicit QLopSettingsDialog(QWidget *parent = 0); |
|
26 | explicit QLopSettingsDialog(QWidget *parent = 0); | |
17 | ~QLopSettingsDialog(); |
|
27 | ~QLopSettingsDialog(); | |
18 |
|
28 | |||
19 | public slots: |
|
29 | public slots: | |
20 | void changePage(QListWidgetItem *current, QListWidgetItem *previous); |
|
30 | void changePage(QListWidgetItem *current, QListWidgetItem *previous); | |
21 |
bool registerConfigEntry(Q |
|
31 | bool registerConfigEntry(QLopSettingsItem* configEntry, QIcon icon, QString text); | |
22 |
void popConfigDialog(Q |
|
32 | void popConfigDialog(QLopSettingsItem* selectedConfigEntry=0); | |
23 | protected: |
|
33 | protected: | |
24 | void changeEvent(QEvent *e); |
|
34 | void changeEvent(QEvent *e); | |
25 |
|
35 | |||
26 | private: |
|
36 | private: | |
27 | Ui::QLopSettingsDialog *ui; |
|
37 | Ui::QLopSettingsDialog *ui; | |
28 | }; |
|
38 | }; | |
29 |
|
39 | |||
30 | #endif // QLOPSETTINGSDIALOG_H |
|
40 | #endif // QLOPSETTINGSDIALOG_H |
@@ -1,6 +1,6 | |||||
1 | #!/bin/bash |
|
1 | #!/bin/bash | |
2 |
|
2 | |||
3 | #export QTDIR=/usr/include |
|
3 | #export QTDIR=/usr/include | |
4 | #export QTDIR=/usr/include/qt5 |
|
4 | #export QTDIR=/usr/include/qt5 | |
5 |
|
5 | |||
6 | pythonqt_generator --include-paths=../QCustomPlot:../:./Widgets:./:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut pyqlop.h pythonQtgeneratorCfg.txt |
|
6 | pythonqt_generator --include-paths=../QCustomPlot:../:./Widgets:./network:./:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut pyqlop.h pythonQtgeneratorCfg.txt |
@@ -1,98 +1,110 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "qlopsettings.h" |
|
22 | #include "qlopsettings.h" | |
23 | #include <QtWidgets> |
|
23 | #include <QtWidgets> | |
24 | #include <QAction> |
|
24 | #include <QAction> | |
25 | #include <qlopgui.h> |
|
25 | #include <qlopgui.h> | |
26 |
|
26 | |||
27 | QLopSettings* QLopSettings::_self=NULL; |
|
27 | QLopSettings* QLopSettings::_self=NULL; | |
28 | QDockWidget* QLopSettings::m_gui=NULL; |
|
28 | QDockWidget* QLopSettings::m_gui=NULL; | |
29 | QSettings* QLopSettings::m_settings=NULL; |
|
29 | QSettings* QLopSettings::m_settings=NULL; | |
30 | QLopSettingsDialog* QLopSettings::m_configDialog=NULL; |
|
30 | QLopSettingsDialog* QLopSettings::m_configDialog=NULL; | |
31 |
|
31 | |||
32 | #define INIT() \ |
|
32 | #define INIT() \ | |
33 | if(Q_UNLIKELY(_self==NULL))\ |
|
33 | if(Q_UNLIKELY(_self==NULL))\ | |
34 | {\ |
|
34 | {\ | |
35 | init();\ |
|
35 | init();\ | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QLopSettings::QLopSettings(bool noGUI,QObject *parent) : QLopService(parent) |
|
38 | QLopSettings::QLopSettings(bool noGUI,QObject *parent) : QLopService(parent) | |
39 | { |
|
39 | { | |
40 | m_serviceName="QLopSettings"; |
|
40 | m_serviceName="QLopSettings"; | |
41 | m_settings = new QSettings(); |
|
41 | m_settings = new QSettings(); | |
42 | m_noGui=noGUI; |
|
42 | m_noGui=noGUI; | |
43 | m_configDialog = new QLopSettingsDialog(); |
|
43 | m_configDialog = new QLopSettingsDialog(); | |
44 | QAction* trigerGUI = new QAction(tr("Settings"),this); |
|
44 | QAction* trigerGUI = new QAction(tr("Settings"),this); | |
45 | connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog())); |
|
45 | connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog())); | |
46 | QLopGUI::addSettingsAction(trigerGUI); |
|
46 | QLopGUI::addSettingsAction(trigerGUI); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | QLopSettings::~QLopSettings() |
|
49 | QLopSettings::~QLopSettings() | |
50 | { |
|
50 | { | |
51 | delete m_configDialog; |
|
51 | delete m_configDialog; | |
52 | delete m_settings; |
|
52 | delete m_settings; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | QDockWidget *QLopSettings::getGUI() |
|
55 | QDockWidget *QLopSettings::getGUI() | |
56 | { |
|
56 | { | |
57 | if(!m_noGui && (m_gui==NULL)) |
|
57 | if(!m_noGui && (m_gui==NULL)) | |
58 | { |
|
58 | { | |
59 | // m_gui=new QLopDataBaseViewer(); |
|
59 | // m_gui=new QLopDataBaseViewer(); | |
60 | // m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); |
|
60 | // m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |
61 | } |
|
61 | } | |
62 | return m_gui; |
|
62 | return m_gui; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void QLopSettings::init(bool noGUI, QObject *parent) |
|
65 | void QLopSettings::init(bool noGUI, QObject *parent) | |
66 | { |
|
66 | { | |
67 | _self=new QLopSettings(noGUI,parent); |
|
67 | _self=new QLopSettings(noGUI,parent); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | const QString &QLopSettings::serviceName() |
|
70 | const QString &QLopSettings::serviceName() | |
71 | { |
|
71 | { | |
72 | INIT(); |
|
72 | INIT(); | |
73 | return m_serviceName; |
|
73 | return m_serviceName; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | QLopSettings *QLopSettings::self() |
|
76 | QLopSettings *QLopSettings::self() | |
77 | { |
|
77 | { | |
78 | INIT(); |
|
78 | INIT(); | |
79 | return _self; |
|
79 | return _self; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 |
void QLopSettings::popConfigDialog(Q |
|
82 | void QLopSettings::popConfigDialog(QLopSettingsItem *selectedConfigEntry) | |
83 | { |
|
83 | { | |
84 | INIT(); |
|
84 | INIT(); | |
85 | m_configDialog->popConfigDialog(selectedConfigEntry); |
|
85 | m_configDialog->popConfigDialog(selectedConfigEntry); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void QLopSettings::popConfigDialog() |
|
88 | void QLopSettings::popConfigDialog() | |
89 | { |
|
89 | { | |
90 | m_configDialog->popConfigDialog(NULL); |
|
90 | m_configDialog->popConfigDialog(NULL); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 |
bool QLopSettings::registerConfigEntry(Q |
|
93 | bool QLopSettings::registerConfigEntry(QLopSettingsItem *configEntry, QIcon icon, QString text) | |
94 | { |
|
94 | { | |
95 | INIT(); |
|
95 | INIT(); | |
96 | return m_configDialog->registerConfigEntry(configEntry, icon, text); |
|
96 | return m_configDialog->registerConfigEntry(configEntry, icon, text); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
|
99 | void QLopSettings::setValue(QLopService* service, const QString &key, const QVariant &value) | |||
|
100 | { | |||
|
101 | INIT(); | |||
|
102 | m_settings->setValue(service->serviceName()+"/"+key,value); | |||
|
103 | } | |||
|
104 | ||||
|
105 | QVariant QLopSettings::value(QLopService* service, const QString &key, const QVariant &defaultValue) | |||
|
106 | { | |||
|
107 | INIT(); | |||
|
108 | return m_settings->value(service->serviceName()+"/"+key,defaultValue); | |||
|
109 | } | |||
|
110 |
@@ -1,53 +1,55 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef QLOPSETTINGS_H |
|
22 | #ifndef QLOPSETTINGS_H | |
23 | #define QLOPSETTINGS_H |
|
23 | #define QLOPSETTINGS_H | |
24 |
|
24 | |||
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <qlopservice.h> |
|
26 | #include <qlopservice.h> | |
27 | #include <QSettings> |
|
27 | #include <QSettings> | |
28 | #include <QDialog> |
|
28 | #include <QDialog> | |
29 | #include <QIcon> |
|
29 | #include <QIcon> | |
30 | #include <qlopsettingsdialog.h> |
|
30 | #include <qlopsettingsdialog.h> | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | class QLopSettings : public QLopService |
|
33 | class QLopSettings : public QLopService | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | static QDockWidget* m_gui; |
|
36 | static QDockWidget* m_gui; | |
37 | QLopSettings(bool noGUI=false,QObject *parent = 0); |
|
37 | QLopSettings(bool noGUI=false,QObject *parent = 0); | |
38 | ~QLopSettings(); |
|
38 | ~QLopSettings(); | |
39 | static QLopSettings* _self; |
|
39 | static QLopSettings* _self; | |
40 | static QSettings* m_settings; |
|
40 | static QSettings* m_settings; | |
41 | static QLopSettingsDialog* m_configDialog; |
|
41 | static QLopSettingsDialog* m_configDialog; | |
42 | public: |
|
42 | public: | |
43 | QDockWidget* getGUI(); |
|
43 | QDockWidget* getGUI(); | |
44 | static void init(bool noGUI=false,QObject *parent = 0); |
|
44 | static void init(bool noGUI=false,QObject *parent = 0); | |
45 | const QString& serviceName(); |
|
45 | const QString& serviceName(); | |
46 | static QLopSettings* self(); |
|
46 | static QLopSettings* self(); | |
47 |
static void popConfigDialog(Q |
|
47 | static void popConfigDialog(QLopSettingsItem *selectedConfigEntry); | |
48 |
static bool registerConfigEntry(Q |
|
48 | static bool registerConfigEntry(QLopSettingsItem* configEntry,QIcon icon, QString text); | |
|
49 | static void setValue(QLopService* service,const QString & key, const QVariant & value); | |||
|
50 | static QVariant value(QLopService* service, const QString & key, const QVariant & defaultValue = QVariant()); | |||
49 | public slots: |
|
51 | public slots: | |
50 | void popConfigDialog(); |
|
52 | void popConfigDialog(); | |
51 | }; |
|
53 | }; | |
52 |
|
54 | |||
53 | #endif // QLOPSETTINGS_H |
|
55 | #endif // QLOPSETTINGS_H |
@@ -1,715 +1,719 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "SocExplorerPlot.h" |
|
22 | #include "SocExplorerPlot.h" | |
23 | #include <QSvgGenerator> |
|
23 | #include <QSvgGenerator> | |
24 | #include <qcpdocumentobject.h> |
|
24 | #include <qcpdocumentobject.h> | |
25 | #include <QPdfWriter> |
|
25 | #include <QPdfWriter> | |
26 | #include <QPrinter> |
|
26 | #include <QPrinter> | |
27 |
|
27 | |||
28 | SocExplorerPlot::SocExplorerPlot(QWidget *parent) : |
|
28 | SocExplorerPlot::SocExplorerPlot(QWidget *parent) : | |
29 | QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) |
|
29 | QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this)) | |
30 | { |
|
30 | { | |
31 | this->m_plot = new QCustomPlotVect(this); |
|
31 | this->m_plot = new QCustomPlotVect(this); | |
32 | this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | |
|
32 | this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | | |
33 | QCP::iSelectLegend | QCP::iSelectPlottables); |
|
33 | QCP::iSelectLegend | QCP::iSelectPlottables); | |
34 | this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical); |
|
34 | this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical); | |
35 | this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); |
|
35 | this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); | |
36 | this->m_mainlayout = new QGridLayout(this); |
|
36 | this->m_mainlayout = new QGridLayout(this); | |
37 | this->setLayout(this->m_mainlayout); |
|
37 | this->setLayout(this->m_mainlayout); | |
38 | this->m_mainlayout->addWidget(this->m_plot); |
|
38 | this->m_mainlayout->addWidget(this->m_plot); | |
39 | this->setMinimumSize(400,300); |
|
39 | this->setMinimumSize(400,300); | |
40 | this->setFocusPolicy(Qt::WheelFocus); |
|
40 | this->setFocusPolicy(Qt::WheelFocus); | |
41 | this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); |
|
41 | this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents); | |
42 | this->ctrl_hold = false; |
|
42 | this->ctrl_hold = false; | |
43 | this->shift_hold = false; |
|
43 | this->shift_hold = false; | |
44 | this->mouse_hold = false; |
|
44 | this->mouse_hold = false; | |
45 | this->m_plot->setNoAntialiasingOnDrag(true); |
|
45 | this->m_plot->setNoAntialiasingOnDrag(true); | |
46 | this->show(); |
|
46 | this->show(); | |
47 | this->m_plot->legend->setVisible(true); |
|
47 | this->m_plot->legend->setVisible(true); | |
|
48 | this->m_plot->plotLayout()->insertRow(0); | |||
|
49 | this->m_plotTitle = new QCPPlotTitle(m_plot); | |||
48 | } |
|
50 | } | |
49 |
|
51 | |||
50 | SocExplorerPlot::~SocExplorerPlot() |
|
52 | SocExplorerPlot::~SocExplorerPlot() | |
51 | { |
|
53 | { | |
52 | delete mRubberBand; |
|
54 | delete mRubberBand; | |
53 | } |
|
55 | } | |
54 |
|
56 | |||
55 | void SocExplorerPlot::show() |
|
57 | void SocExplorerPlot::show() | |
56 | { |
|
58 | { | |
57 | QWidget::show(); |
|
59 | QWidget::show(); | |
58 | } |
|
60 | } | |
59 |
|
61 | |||
60 | void SocExplorerPlot::replot() |
|
62 | void SocExplorerPlot::replot() | |
61 | { |
|
63 | { | |
62 | this->m_plot->replot(); |
|
64 | this->m_plot->replot(); | |
63 | } |
|
65 | } | |
64 |
|
66 | |||
65 | void SocExplorerPlot::exportToSVG(const QString &fileName) |
|
67 | void SocExplorerPlot::exportToSVG(const QString &fileName) | |
66 | { |
|
68 | { | |
67 | QSvgGenerator printer; |
|
69 | QSvgGenerator printer; | |
68 | printer.setFileName(fileName); |
|
70 | printer.setFileName(fileName); | |
69 | QCPPainter qcpPainter; |
|
71 | QCPPainter qcpPainter; | |
70 | qcpPainter.begin(&printer); |
|
72 | qcpPainter.begin(&printer); | |
71 | m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height()); |
|
73 | m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height()); | |
72 | qcpPainter.end(); |
|
74 | qcpPainter.end(); | |
73 | } |
|
75 | } | |
74 |
|
76 | |||
75 | void SocExplorerPlot::exportToPDF(const QString &fileName) |
|
77 | void SocExplorerPlot::exportToPDF(const QString &fileName) | |
76 | { |
|
78 | { | |
77 | QPrinter printer(QPrinter::HighResolution); |
|
79 | QPrinter printer(QPrinter::HighResolution); | |
78 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
80 | printer.setOutputFormat(QPrinter::PdfFormat); | |
79 | printer.setOrientation(QPrinter::Landscape); |
|
81 | printer.setOrientation(QPrinter::Landscape); | |
80 | printer.setOutputFileName(fileName); |
|
82 | printer.setOutputFileName(fileName); | |
81 | printer.setFullPage(true); |
|
83 | printer.setFullPage(true); | |
82 | QCPPainter qcpPainter; |
|
84 | QCPPainter qcpPainter; | |
83 | qcpPainter.begin(&printer); |
|
85 | qcpPainter.begin(&printer); | |
84 | m_plot->toPainter(&qcpPainter, printer.width(), printer.height()); |
|
86 | m_plot->toPainter(&qcpPainter, printer.width(), printer.height()); | |
85 | qcpPainter.end(); |
|
87 | qcpPainter.end(); | |
86 | } |
|
88 | } | |
87 |
|
89 | |||
88 | void SocExplorerPlot::addAction(SocExplorerPlotActions *action) |
|
90 | void SocExplorerPlot::addAction(SocExplorerPlotActions *action) | |
89 | { |
|
91 | { | |
90 | this->m_actions.append(action); |
|
92 | this->m_actions.append(action); | |
91 | QWidget::addAction((QAction*)action); |
|
93 | QWidget::addAction((QAction*)action); | |
92 | } |
|
94 | } | |
93 |
|
95 | |||
94 | QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex) |
|
96 | QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex) | |
95 | { |
|
97 | { | |
96 | QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData(); |
|
98 | QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData(); | |
97 | return visibleData; |
|
99 | return visibleData; | |
98 | } |
|
100 | } | |
99 |
|
101 | |||
100 | void SocExplorerPlot::setTitle(QString title) |
|
102 | void SocExplorerPlot::setTitle(QString title) | |
101 | { |
|
103 | { | |
102 | Q_UNUSED(title) |
|
104 | Q_UNUSED(title) | |
103 | //this->m_plot->setTitle(title); |
|
105 | //this->m_plot->setTitle(title); | |
104 | /*! |
|
106 | /*! | |
105 | @todo Function borcken fixe this! |
|
107 | @todo Function borcken fixe this! | |
106 | */ |
|
108 | */ | |
|
109 | m_plotTitle->setText(title); | |||
|
110 | m_plot->plotLayout()->addElement(0, 0, m_plotTitle); | |||
107 | this->m_Title = title; |
|
111 | this->m_Title = title; | |
108 | emit titleChanged(title); |
|
112 | emit titleChanged(title); | |
109 | this->repaint(); |
|
113 | this->repaint(); | |
110 | } |
|
114 | } | |
111 |
|
115 | |||
112 | const QString &SocExplorerPlot::title() |
|
116 | const QString &SocExplorerPlot::title() | |
113 | { |
|
117 | { | |
114 | return m_Title; |
|
118 | return m_Title; | |
115 | } |
|
119 | } | |
116 |
|
120 | |||
117 | void SocExplorerPlot::setXaxisLabel(QString label) |
|
121 | void SocExplorerPlot::setXaxisLabel(QString label) | |
118 | { |
|
122 | { | |
119 | this->m_plot->xAxis->setLabel(label); |
|
123 | this->m_plot->xAxis->setLabel(label); | |
120 | this->repaint(); |
|
124 | this->repaint(); | |
121 | } |
|
125 | } | |
122 |
|
126 | |||
123 | void SocExplorerPlot::setXaxisLog() |
|
127 | void SocExplorerPlot::setXaxisLog() | |
124 | { |
|
128 | { | |
125 | this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); |
|
129 | this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); | |
126 | } |
|
130 | } | |
127 |
|
131 | |||
128 | void SocExplorerPlot::setYaxisLabel(QString label) |
|
132 | void SocExplorerPlot::setYaxisLabel(QString label) | |
129 | { |
|
133 | { | |
130 | this->m_plot->yAxis->setLabel(label); |
|
134 | this->m_plot->yAxis->setLabel(label); | |
131 | this->repaint(); |
|
135 | this->repaint(); | |
132 | } |
|
136 | } | |
133 |
|
137 | |||
134 | void SocExplorerPlot::setYaxisLog() |
|
138 | void SocExplorerPlot::setYaxisLog() | |
135 | { |
|
139 | { | |
136 | this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); |
|
140 | this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); | |
137 | } |
|
141 | } | |
138 |
|
142 | |||
139 | void SocExplorerPlot::setXaxisRange(double lower, double upper) |
|
143 | void SocExplorerPlot::setXaxisRange(double lower, double upper) | |
140 | { |
|
144 | { | |
141 | this->m_plot->xAxis->setRange(lower,upper); |
|
145 | this->m_plot->xAxis->setRange(lower,upper); | |
142 | } |
|
146 | } | |
143 |
|
147 | |||
144 | void SocExplorerPlot::setYaxisRange(double lower, double upper) |
|
148 | void SocExplorerPlot::setYaxisRange(double lower, double upper) | |
145 | { |
|
149 | { | |
146 | this->m_plot->yAxis->setRange(lower,upper); |
|
150 | this->m_plot->yAxis->setRange(lower,upper); | |
147 | } |
|
151 | } | |
148 |
|
152 | |||
149 |
|
153 | |||
150 | void SocExplorerPlot::rescaleAxis() |
|
154 | void SocExplorerPlot::rescaleAxis() | |
151 | { |
|
155 | { | |
152 | this->m_plot->rescaleAxes(); |
|
156 | this->m_plot->rescaleAxes(); | |
153 | this->m_plot->replot(); |
|
157 | this->m_plot->replot(); | |
154 | } |
|
158 | } | |
155 |
|
159 | |||
156 | void SocExplorerPlot::setLegendFont(QFont font) |
|
160 | void SocExplorerPlot::setLegendFont(QFont font) | |
157 | { |
|
161 | { | |
158 | this->m_plot->legend->setFont(font); |
|
162 | this->m_plot->legend->setFont(font); | |
159 | this->repaint(); |
|
163 | this->repaint(); | |
160 | } |
|
164 | } | |
161 |
|
165 | |||
162 | void SocExplorerPlot::setLegendSelectedFont(QFont font) |
|
166 | void SocExplorerPlot::setLegendSelectedFont(QFont font) | |
163 | { |
|
167 | { | |
164 | this->m_plot->legend->setSelectedFont(font); |
|
168 | this->m_plot->legend->setSelectedFont(font); | |
165 | this->repaint(); |
|
169 | this->repaint(); | |
166 | } |
|
170 | } | |
167 |
|
171 | |||
168 | void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) |
|
172 | void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable) | |
169 | { |
|
173 | { | |
170 | this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); |
|
174 | this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable); | |
171 | } |
|
175 | } | |
172 |
|
176 | |||
173 | void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable) |
|
177 | void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable) | |
174 | { |
|
178 | { | |
175 | // TODO deprecated |
|
179 | // TODO deprecated | |
176 | // this->m_plot->graph(graphIndex)->setUseFastVectors(enable); |
|
180 | // this->m_plot->graph(graphIndex)->setUseFastVectors(enable); | |
177 | } |
|
181 | } | |
178 |
|
182 | |||
179 | int SocExplorerPlot::addGraph() |
|
183 | int SocExplorerPlot::addGraph() | |
180 | { |
|
184 | { | |
181 | this->m_plot->addGraph(); |
|
185 | this->m_plot->addGraph(); | |
182 | return this->m_plot->graphCount() -1; |
|
186 | return this->m_plot->graphCount() -1; | |
183 | } |
|
187 | } | |
184 |
|
188 | |||
185 | bool SocExplorerPlot::removeGraph(int graphIndex) |
|
189 | bool SocExplorerPlot::removeGraph(int graphIndex) | |
186 | { |
|
190 | { | |
187 | return this->m_plot->removeGraph(graphIndex); |
|
191 | return this->m_plot->removeGraph(graphIndex); | |
188 | } |
|
192 | } | |
189 |
|
193 | |||
190 | int SocExplorerPlot::graphCount() |
|
194 | int SocExplorerPlot::graphCount() | |
191 | { |
|
195 | { | |
192 | return m_plot->graphCount(); |
|
196 | return m_plot->graphCount(); | |
193 | } |
|
197 | } | |
194 |
|
198 | |||
195 | void SocExplorerPlot::removeAllGraphs() |
|
199 | void SocExplorerPlot::removeAllGraphs() | |
196 | { |
|
200 | { | |
197 | int graphCount=this->m_plot->graphCount(); |
|
201 | int graphCount=this->m_plot->graphCount(); | |
198 | for(int i=0;i<graphCount;i++) |
|
202 | for(int i=0;i<graphCount;i++) | |
199 | { |
|
203 | { | |
200 | this->m_plot->removeGraph(0); |
|
204 | this->m_plot->removeGraph(0); | |
201 | } |
|
205 | } | |
202 | } |
|
206 | } | |
203 |
|
207 | |||
204 |
|
208 | |||
205 | void SocExplorerPlot::setGraphName(int graphIndex,QString name) |
|
209 | void SocExplorerPlot::setGraphName(int graphIndex,QString name) | |
206 | { |
|
210 | { | |
207 | if(graphIndex<this->m_plot->graphCount()) |
|
211 | if(graphIndex<this->m_plot->graphCount()) | |
208 | { |
|
212 | { | |
209 | this->m_plot->graph(graphIndex)->setName(name); |
|
213 | this->m_plot->graph(graphIndex)->setName(name); | |
210 | } |
|
214 | } | |
211 | } |
|
215 | } | |
212 |
|
216 | |||
213 | const QString &SocExplorerPlot::graphName(int graphIndex) |
|
217 | const QString &SocExplorerPlot::graphName(int graphIndex) | |
214 | { |
|
218 | { | |
215 | if(graphIndex<this->m_plot->graphCount()) |
|
219 | if(graphIndex<this->m_plot->graphCount()) | |
216 | { |
|
220 | { | |
217 | return this->m_plot->graph(graphIndex)->name(); |
|
221 | return this->m_plot->graph(graphIndex)->name(); | |
218 | } |
|
222 | } | |
219 | return ""; |
|
223 | return ""; | |
220 | } |
|
224 | } | |
221 |
|
225 | |||
222 |
|
226 | |||
223 | void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) |
|
227 | void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) | |
224 | { |
|
228 | { | |
225 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double)) |
|
229 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double)) | |
226 | { |
|
230 | { | |
227 | QVector<double> _x(x.count()), _y(y.count()); |
|
231 | QVector<double> _x(x.count()), _y(y.count()); | |
228 | for(int i=0;i<x.count();i++) |
|
232 | for(int i=0;i<x.count();i++) | |
229 | { |
|
233 | { | |
230 | /*_x[i] = x.at(i).value<double>(); |
|
234 | /*_x[i] = x.at(i).value<double>(); | |
231 | _y[i] = y.at(i).value<double>();*/ |
|
235 | _y[i] = y.at(i).value<double>();*/ | |
232 | _x[i] = x.at(i).toDouble(); |
|
236 | _x[i] = x.at(i).toDouble(); | |
233 | _y[i] = y.at(i).toDouble(); |
|
237 | _y[i] = y.at(i).toDouble(); | |
234 | } |
|
238 | } | |
235 | this->m_plot->graph(graphIndex)->setData(_x,_y); |
|
239 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |
236 | } |
|
240 | } | |
237 | else |
|
241 | else | |
238 | { |
|
242 | { | |
239 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) |
|
243 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime)) | |
240 | { |
|
244 | { | |
241 | QVector<double> _x(x.count()), _y(y.count()); |
|
245 | QVector<double> _x(x.count()), _y(y.count()); | |
242 | for(int i=0;i<x.count();i++) |
|
246 | for(int i=0;i<x.count();i++) | |
243 | { |
|
247 | { | |
244 | /*_x[i] = x.at(i).value<double>(); |
|
248 | /*_x[i] = x.at(i).value<double>(); | |
245 | _y[i] = y.at(i).value<double>();*/ |
|
249 | _y[i] = y.at(i).value<double>();*/ | |
246 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); |
|
250 | _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch(); | |
247 | _y[i] = y.at(i).toDouble(); |
|
251 | _y[i] = y.at(i).toDouble(); | |
248 | } |
|
252 | } | |
249 | this->m_plot->graph(graphIndex)->setData(_x,_y); |
|
253 | this->m_plot->graph(graphIndex)->setData(_x,_y); | |
250 | this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); |
|
254 | this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); | |
251 | this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); |
|
255 | this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz"); | |
252 |
|
256 | |||
253 | } |
|
257 | } | |
254 | } |
|
258 | } | |
255 | this->m_plot->replot(); |
|
259 | this->m_plot->replot(); | |
256 | } |
|
260 | } | |
257 |
|
261 | |||
258 | void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot) |
|
262 | void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot) | |
259 | { |
|
263 | { | |
260 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) |
|
264 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | |
261 | { |
|
265 | { | |
262 | this->m_plot->graph(graphIndex)->setData(data,copy); |
|
266 | this->m_plot->graph(graphIndex)->setData(data,copy); | |
263 | } |
|
267 | } | |
264 | if(replot) |
|
268 | if(replot) | |
265 | this->m_plot->replot(); |
|
269 | this->m_plot->replot(); | |
266 | } |
|
270 | } | |
267 |
|
271 | |||
268 | void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot) |
|
272 | void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot) | |
269 | { |
|
273 | { | |
270 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) |
|
274 | if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double)) | |
271 | { |
|
275 | { | |
272 | ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data); |
|
276 | ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data); | |
273 | } |
|
277 | } | |
274 | if(replot) |
|
278 | if(replot) | |
275 | this->m_plot->replot(); |
|
279 | this->m_plot->replot(); | |
276 | } |
|
280 | } | |
277 |
|
281 | |||
278 | void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) |
|
282 | void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y) | |
279 | { |
|
283 | { | |
280 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) |
|
284 | if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double)) | |
281 | { |
|
285 | { | |
282 | QVector<double> _x(x.count()), _y(y.count()); |
|
286 | QVector<double> _x(x.count()), _y(y.count()); | |
283 | for(int i=0;i<x.count();i++) |
|
287 | for(int i=0;i<x.count();i++) | |
284 | { |
|
288 | { | |
285 | /*_x[i] = x.at(i).value<double>(); |
|
289 | /*_x[i] = x.at(i).value<double>(); | |
286 | _y[i] = y.at(i).value<double>();*/ |
|
290 | _y[i] = y.at(i).value<double>();*/ | |
287 | _x[i] = x.at(i).toDouble(); |
|
291 | _x[i] = x.at(i).toDouble(); | |
288 | _y[i] = y.at(i).toDouble(); |
|
292 | _y[i] = y.at(i).toDouble(); | |
289 | } |
|
293 | } | |
290 | this->m_plot->graph(graphIndex)->addData(_x,_y); |
|
294 | this->m_plot->graph(graphIndex)->addData(_x,_y); | |
291 | } |
|
295 | } | |
292 | this->m_plot->replot(); |
|
296 | this->m_plot->replot(); | |
293 | } |
|
297 | } | |
294 |
|
298 | |||
295 | void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) |
|
299 | void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y) | |
296 | { |
|
300 | { | |
297 | if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) |
|
301 | if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double)) | |
298 | { |
|
302 | { | |
299 | this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); |
|
303 | this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble()); | |
300 | } |
|
304 | } | |
301 | this->m_plot->replot(); |
|
305 | this->m_plot->replot(); | |
302 | } |
|
306 | } | |
303 |
|
307 | |||
304 | void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) |
|
308 | void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen) | |
305 | { |
|
309 | { | |
306 | if(graphIndex<this->m_plot->graphCount()) |
|
310 | if(graphIndex<this->m_plot->graphCount()) | |
307 | { |
|
311 | { | |
308 | this->m_plot->graph(graphIndex)->setPen(pen); |
|
312 | this->m_plot->graph(graphIndex)->setPen(pen); | |
309 | } |
|
313 | } | |
310 | } |
|
314 | } | |
311 |
|
315 | |||
312 | QPen SocExplorerPlot::getGraphPen(int graphIndex) |
|
316 | QPen SocExplorerPlot::getGraphPen(int graphIndex) | |
313 | { |
|
317 | { | |
314 | if(graphIndex<this->m_plot->graphCount()) |
|
318 | if(graphIndex<this->m_plot->graphCount()) | |
315 | { |
|
319 | { | |
316 | return this->m_plot->graph(graphIndex)->pen(); |
|
320 | return this->m_plot->graph(graphIndex)->pen(); | |
317 | } |
|
321 | } | |
318 | return this->m_plot->graph()->pen(); |
|
322 | return this->m_plot->graph()->pen(); | |
319 | } |
|
323 | } | |
320 |
|
324 | |||
321 |
|
325 | |||
322 |
|
326 | |||
323 | void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) |
|
327 | void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle) | |
324 | { |
|
328 | { | |
325 | if(graphIndex<this->m_plot->graphCount()) |
|
329 | if(graphIndex<this->m_plot->graphCount()) | |
326 | { |
|
330 | { | |
327 | if(!lineStyle.compare("none")) |
|
331 | if(!lineStyle.compare("none")) | |
328 | { |
|
332 | { | |
329 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); |
|
333 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone); | |
330 | return; |
|
334 | return; | |
331 | } |
|
335 | } | |
332 | if(!lineStyle.compare("line")) |
|
336 | if(!lineStyle.compare("line")) | |
333 | { |
|
337 | { | |
334 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); |
|
338 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine); | |
335 | return; |
|
339 | return; | |
336 | } |
|
340 | } | |
337 | if(!lineStyle.compare("stepleft")) |
|
341 | if(!lineStyle.compare("stepleft")) | |
338 | { |
|
342 | { | |
339 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); |
|
343 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft); | |
340 | return; |
|
344 | return; | |
341 | } |
|
345 | } | |
342 | if(!lineStyle.compare("stepright")) |
|
346 | if(!lineStyle.compare("stepright")) | |
343 | { |
|
347 | { | |
344 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); |
|
348 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight); | |
345 | return; |
|
349 | return; | |
346 | } |
|
350 | } | |
347 | if(!lineStyle.compare("stepcenter")) |
|
351 | if(!lineStyle.compare("stepcenter")) | |
348 | { |
|
352 | { | |
349 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); |
|
353 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter); | |
350 | return; |
|
354 | return; | |
351 | } |
|
355 | } | |
352 | if(!lineStyle.compare("impulse")) |
|
356 | if(!lineStyle.compare("impulse")) | |
353 | { |
|
357 | { | |
354 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); |
|
358 | this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse); | |
355 | return; |
|
359 | return; | |
356 | } |
|
360 | } | |
357 |
|
361 | |||
358 |
|
362 | |||
359 | } |
|
363 | } | |
360 | } |
|
364 | } | |
361 |
|
365 | |||
362 | void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) |
|
366 | void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle) | |
363 | { |
|
367 | { | |
364 | if(graphIndex<this->m_plot->graphCount()) |
|
368 | if(graphIndex<this->m_plot->graphCount()) | |
365 | { |
|
369 | { | |
366 | if(!scatterStyle.compare("none")) |
|
370 | if(!scatterStyle.compare("none")) | |
367 | { |
|
371 | { | |
368 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); |
|
372 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone); | |
369 | return; |
|
373 | return; | |
370 | } |
|
374 | } | |
371 | if(!scatterStyle.compare("dot")) |
|
375 | if(!scatterStyle.compare("dot")) | |
372 | { |
|
376 | { | |
373 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); |
|
377 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot); | |
374 | return; |
|
378 | return; | |
375 | } |
|
379 | } | |
376 | if(!scatterStyle.compare("cross")) |
|
380 | if(!scatterStyle.compare("cross")) | |
377 | { |
|
381 | { | |
378 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); |
|
382 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross); | |
379 | return; |
|
383 | return; | |
380 | } |
|
384 | } | |
381 | if(!scatterStyle.compare("plus")) |
|
385 | if(!scatterStyle.compare("plus")) | |
382 | { |
|
386 | { | |
383 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); |
|
387 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus); | |
384 | return; |
|
388 | return; | |
385 | } |
|
389 | } | |
386 | if(!scatterStyle.compare("circle")) |
|
390 | if(!scatterStyle.compare("circle")) | |
387 | { |
|
391 | { | |
388 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); |
|
392 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle); | |
389 | return; |
|
393 | return; | |
390 | } |
|
394 | } | |
391 | if(!scatterStyle.compare("disc")) |
|
395 | if(!scatterStyle.compare("disc")) | |
392 | { |
|
396 | { | |
393 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); |
|
397 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc); | |
394 | return; |
|
398 | return; | |
395 | } |
|
399 | } | |
396 | if(!scatterStyle.compare("square")) |
|
400 | if(!scatterStyle.compare("square")) | |
397 | { |
|
401 | { | |
398 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); |
|
402 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare); | |
399 | return; |
|
403 | return; | |
400 | } |
|
404 | } | |
401 | if(!scatterStyle.compare("diamond")) |
|
405 | if(!scatterStyle.compare("diamond")) | |
402 | { |
|
406 | { | |
403 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); |
|
407 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond); | |
404 | return; |
|
408 | return; | |
405 | } |
|
409 | } | |
406 | if(!scatterStyle.compare("star")) |
|
410 | if(!scatterStyle.compare("star")) | |
407 | { |
|
411 | { | |
408 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); |
|
412 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar); | |
409 | return; |
|
413 | return; | |
410 | } |
|
414 | } | |
411 | if(!scatterStyle.compare("triangle")) |
|
415 | if(!scatterStyle.compare("triangle")) | |
412 | { |
|
416 | { | |
413 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); |
|
417 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle); | |
414 | return; |
|
418 | return; | |
415 | } |
|
419 | } | |
416 | if(!scatterStyle.compare("invertedtriangle")) |
|
420 | if(!scatterStyle.compare("invertedtriangle")) | |
417 | { |
|
421 | { | |
418 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); |
|
422 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted); | |
419 | return; |
|
423 | return; | |
420 | } |
|
424 | } | |
421 | if(!scatterStyle.compare("crosssquare")) |
|
425 | if(!scatterStyle.compare("crosssquare")) | |
422 | { |
|
426 | { | |
423 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); |
|
427 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare); | |
424 | return; |
|
428 | return; | |
425 | } |
|
429 | } | |
426 | if(!scatterStyle.compare("plussquare")) |
|
430 | if(!scatterStyle.compare("plussquare")) | |
427 | { |
|
431 | { | |
428 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); |
|
432 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare); | |
429 | return; |
|
433 | return; | |
430 | } |
|
434 | } | |
431 | if(!scatterStyle.compare("crosscircle")) |
|
435 | if(!scatterStyle.compare("crosscircle")) | |
432 | { |
|
436 | { | |
433 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); |
|
437 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle); | |
434 | return; |
|
438 | return; | |
435 | } |
|
439 | } | |
436 | if(!scatterStyle.compare("pluscircle")) |
|
440 | if(!scatterStyle.compare("pluscircle")) | |
437 | { |
|
441 | { | |
438 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); |
|
442 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle); | |
439 | return; |
|
443 | return; | |
440 | } |
|
444 | } | |
441 | if(!scatterStyle.compare("peace")) |
|
445 | if(!scatterStyle.compare("peace")) | |
442 | { |
|
446 | { | |
443 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); |
|
447 | this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace); | |
444 | return; |
|
448 | return; | |
445 | } |
|
449 | } | |
446 |
|
450 | |||
447 | } |
|
451 | } | |
448 | } |
|
452 | } | |
449 |
|
453 | |||
450 | void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type) |
|
454 | void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type) | |
451 | { |
|
455 | { | |
452 | this->m_plot->xAxis->setTickLabelType(type); |
|
456 | this->m_plot->xAxis->setTickLabelType(type); | |
453 | } |
|
457 | } | |
454 |
|
458 | |||
455 | void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format) |
|
459 | void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format) | |
456 | { |
|
460 | { | |
457 | this->m_plot->xAxis->setDateTimeFormat(format); |
|
461 | this->m_plot->xAxis->setDateTimeFormat(format); | |
458 | } |
|
462 | } | |
459 |
|
463 | |||
460 |
|
464 | |||
461 |
|
465 | |||
462 |
|
466 | |||
463 |
|
467 | |||
464 | void SocExplorerPlot::keyPressEvent(QKeyEvent * event) |
|
468 | void SocExplorerPlot::keyPressEvent(QKeyEvent * event) | |
465 | { |
|
469 | { | |
466 | switch(event->key()) |
|
470 | switch(event->key()) | |
467 | { |
|
471 | { | |
468 | case Qt::Key_Control: |
|
472 | case Qt::Key_Control: | |
469 | this->ctrl_hold = true; |
|
473 | this->ctrl_hold = true; | |
470 | setCursor(Qt::CrossCursor); |
|
474 | setCursor(Qt::CrossCursor); | |
471 | break; |
|
475 | break; | |
472 | case Qt::Key_Shift: |
|
476 | case Qt::Key_Shift: | |
473 | this->shift_hold = true; |
|
477 | this->shift_hold = true; | |
474 | break; |
|
478 | break; | |
475 | case Qt::Key_M: |
|
479 | case Qt::Key_M: | |
476 | this->rescaleAxis(); |
|
480 | this->rescaleAxis(); | |
477 | break; |
|
481 | break; | |
478 | case Qt::Key_Left: |
|
482 | case Qt::Key_Left: | |
479 | if(!ctrl_hold) |
|
483 | if(!ctrl_hold) | |
480 | { |
|
484 | { | |
481 | move(-0.1,Qt::Horizontal); |
|
485 | move(-0.1,Qt::Horizontal); | |
482 | } |
|
486 | } | |
483 | else |
|
487 | else | |
484 | { |
|
488 | { | |
485 | zoom(2,this->width()/2,Qt::Horizontal); |
|
489 | zoom(2,this->width()/2,Qt::Horizontal); | |
486 | } |
|
490 | } | |
487 | break; |
|
491 | break; | |
488 | case Qt::Key_Right: |
|
492 | case Qt::Key_Right: | |
489 | if(!ctrl_hold) |
|
493 | if(!ctrl_hold) | |
490 | { |
|
494 | { | |
491 | move(0.1,Qt::Horizontal); |
|
495 | move(0.1,Qt::Horizontal); | |
492 | } |
|
496 | } | |
493 | else |
|
497 | else | |
494 | { |
|
498 | { | |
495 | zoom(0.5,this->width()/2,Qt::Horizontal); |
|
499 | zoom(0.5,this->width()/2,Qt::Horizontal); | |
496 | } |
|
500 | } | |
497 | break; |
|
501 | break; | |
498 | case Qt::Key_Up: |
|
502 | case Qt::Key_Up: | |
499 | if(!ctrl_hold) |
|
503 | if(!ctrl_hold) | |
500 | { |
|
504 | { | |
501 | move(0.1,Qt::Vertical); |
|
505 | move(0.1,Qt::Vertical); | |
502 | } |
|
506 | } | |
503 | else |
|
507 | else | |
504 | { |
|
508 | { | |
505 | zoom(0.5,this->height()/2,Qt::Vertical); |
|
509 | zoom(0.5,this->height()/2,Qt::Vertical); | |
506 | } |
|
510 | } | |
507 | break; |
|
511 | break; | |
508 | case Qt::Key_Down: |
|
512 | case Qt::Key_Down: | |
509 | if(!ctrl_hold) |
|
513 | if(!ctrl_hold) | |
510 | { |
|
514 | { | |
511 | move(-0.1,Qt::Vertical); |
|
515 | move(-0.1,Qt::Vertical); | |
512 | } |
|
516 | } | |
513 | else |
|
517 | else | |
514 | { |
|
518 | { | |
515 | zoom(2,this->height()/2,Qt::Vertical); |
|
519 | zoom(2,this->height()/2,Qt::Vertical); | |
516 | } |
|
520 | } | |
517 | break; |
|
521 | break; | |
518 | default: |
|
522 | default: | |
519 | QWidget::keyPressEvent(event); |
|
523 | QWidget::keyPressEvent(event); | |
520 | break; |
|
524 | break; | |
521 | } |
|
525 | } | |
522 | } |
|
526 | } | |
523 |
|
527 | |||
524 | void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) |
|
528 | void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event) | |
525 | { |
|
529 | { | |
526 | switch(event->key()) |
|
530 | switch(event->key()) | |
527 | { |
|
531 | { | |
528 | case Qt::Key_Control: |
|
532 | case Qt::Key_Control: | |
529 | event->accept(); |
|
533 | event->accept(); | |
530 | this->ctrl_hold = false; |
|
534 | this->ctrl_hold = false; | |
531 | break; |
|
535 | break; | |
532 | case Qt::Key_Shift: |
|
536 | case Qt::Key_Shift: | |
533 | event->accept(); |
|
537 | event->accept(); | |
534 | this->shift_hold = false; |
|
538 | this->shift_hold = false; | |
535 | break; |
|
539 | break; | |
536 | default: |
|
540 | default: | |
537 | QWidget::keyReleaseEvent(event); |
|
541 | QWidget::keyReleaseEvent(event); | |
538 | break; |
|
542 | break; | |
539 | } |
|
543 | } | |
540 | setCursor(Qt::ArrowCursor); |
|
544 | setCursor(Qt::ArrowCursor); | |
541 | } |
|
545 | } | |
542 |
|
546 | |||
543 | void SocExplorerPlot::wheelEvent(QWheelEvent * event) |
|
547 | void SocExplorerPlot::wheelEvent(QWheelEvent * event) | |
544 | { |
|
548 | { | |
545 | double factor; |
|
549 | double factor; | |
546 | double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually |
|
550 | double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually | |
547 | if(ctrl_hold) |
|
551 | if(ctrl_hold) | |
548 | { |
|
552 | { | |
549 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) |
|
553 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | |
550 | { |
|
554 | { | |
551 | setCursor(Qt::SizeVerCursor); |
|
555 | setCursor(Qt::SizeVerCursor); | |
552 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); |
|
556 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps); | |
553 | zoom(factor,event->pos().y(),Qt::Vertical); |
|
557 | zoom(factor,event->pos().y(),Qt::Vertical); | |
554 | } |
|
558 | } | |
555 | QWidget::wheelEvent(event); |
|
559 | QWidget::wheelEvent(event); | |
556 | return; |
|
560 | return; | |
557 | } |
|
561 | } | |
558 | if(shift_hold) |
|
562 | if(shift_hold) | |
559 | { |
|
563 | { | |
560 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) |
|
564 | if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical)) | |
561 | { |
|
565 | { | |
562 | setCursor(Qt::SizeHorCursor); |
|
566 | setCursor(Qt::SizeHorCursor); | |
563 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); |
|
567 | factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps); | |
564 | zoom(factor,event->pos().x(),Qt::Horizontal); |
|
568 | zoom(factor,event->pos().x(),Qt::Horizontal); | |
565 | } |
|
569 | } | |
566 | QWidget::wheelEvent(event); |
|
570 | QWidget::wheelEvent(event); | |
567 | return; |
|
571 | return; | |
568 | } |
|
572 | } | |
569 | move(wheelSteps,Qt::Horizontal); |
|
573 | move(wheelSteps,Qt::Horizontal); | |
570 | QWidget::wheelEvent(event); |
|
574 | QWidget::wheelEvent(event); | |
571 | } |
|
575 | } | |
572 |
|
576 | |||
573 |
|
577 | |||
574 |
|
578 | |||
575 |
|
579 | |||
576 | void SocExplorerPlot::mousePressEvent(QMouseEvent *event) |
|
580 | void SocExplorerPlot::mousePressEvent(QMouseEvent *event) | |
577 | { |
|
581 | { | |
578 | if(event->button()==Qt::LeftButton) |
|
582 | if(event->button()==Qt::LeftButton) | |
579 | { |
|
583 | { | |
580 | if(ctrl_hold) |
|
584 | if(ctrl_hold) | |
581 | { |
|
585 | { | |
582 | setCursor(Qt::CrossCursor); |
|
586 | setCursor(Qt::CrossCursor); | |
583 | mOrigin = event->pos(); |
|
587 | mOrigin = event->pos(); | |
584 | mRubberBand->setGeometry(QRect(mOrigin, QSize())); |
|
588 | mRubberBand->setGeometry(QRect(mOrigin, QSize())); | |
585 | mRubberBand->show(); |
|
589 | mRubberBand->show(); | |
586 | } |
|
590 | } | |
587 | else |
|
591 | else | |
588 | { |
|
592 | { | |
589 | setCursor(Qt::ClosedHandCursor); |
|
593 | setCursor(Qt::ClosedHandCursor); | |
590 | mDragStart = event->pos(); |
|
594 | mDragStart = event->pos(); | |
591 | this->mouse_hold = true; |
|
595 | this->mouse_hold = true; | |
592 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); |
|
596 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); | |
593 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); |
|
597 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); | |
594 | } |
|
598 | } | |
595 | } |
|
599 | } | |
596 | QWidget::mousePressEvent(event); |
|
600 | QWidget::mousePressEvent(event); | |
597 | } |
|
601 | } | |
598 |
|
602 | |||
599 | void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) |
|
603 | void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event) | |
600 | { |
|
604 | { | |
601 | if(event->button()==Qt::LeftButton) |
|
605 | if(event->button()==Qt::LeftButton) | |
602 | { |
|
606 | { | |
603 | this->mouse_hold = false; |
|
607 | this->mouse_hold = false; | |
604 | } |
|
608 | } | |
605 | if (mRubberBand->isVisible()) |
|
609 | if (mRubberBand->isVisible()) | |
606 | { |
|
610 | { | |
607 | const QRect & zoomRect = mRubberBand->geometry(); |
|
611 | const QRect & zoomRect = mRubberBand->geometry(); | |
608 | int xp1, yp1, xp2, yp2; |
|
612 | int xp1, yp1, xp2, yp2; | |
609 | zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); |
|
613 | zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2); | |
610 | double x1 = this->m_plot->xAxis->pixelToCoord(xp1); |
|
614 | double x1 = this->m_plot->xAxis->pixelToCoord(xp1); | |
611 | double x2 = this->m_plot->xAxis->pixelToCoord(xp2); |
|
615 | double x2 = this->m_plot->xAxis->pixelToCoord(xp2); | |
612 | double y1 = this->m_plot->yAxis->pixelToCoord(yp1); |
|
616 | double y1 = this->m_plot->yAxis->pixelToCoord(yp1); | |
613 | double y2 = this->m_plot->yAxis->pixelToCoord(yp2); |
|
617 | double y2 = this->m_plot->yAxis->pixelToCoord(yp2); | |
614 |
|
618 | |||
615 | this->m_plot->xAxis->setRange(x1, x2); |
|
619 | this->m_plot->xAxis->setRange(x1, x2); | |
616 | this->m_plot->yAxis->setRange(y1, y2); |
|
620 | this->m_plot->yAxis->setRange(y1, y2); | |
617 |
|
621 | |||
618 | mRubberBand->hide(); |
|
622 | mRubberBand->hide(); | |
619 | this->m_plot->replot(); |
|
623 | this->m_plot->replot(); | |
620 | } |
|
624 | } | |
621 | setCursor(Qt::ArrowCursor); |
|
625 | setCursor(Qt::ArrowCursor); | |
622 | QWidget::mouseReleaseEvent(event); |
|
626 | QWidget::mouseReleaseEvent(event); | |
623 | } |
|
627 | } | |
624 |
|
628 | |||
625 | void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) |
|
629 | void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation) | |
626 | { |
|
630 | { | |
627 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); |
|
631 | QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation); | |
628 | axis->scaleRange(factor, axis->pixelToCoord(center)); |
|
632 | axis->scaleRange(factor, axis->pixelToCoord(center)); | |
629 | this->m_plot->replot(); |
|
633 | this->m_plot->replot(); | |
630 | } |
|
634 | } | |
631 |
|
635 | |||
632 | void SocExplorerPlot::move(double factor, Qt::Orientation orientation) |
|
636 | void SocExplorerPlot::move(double factor, Qt::Orientation orientation) | |
633 | { |
|
637 | { | |
634 | QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); |
|
638 | QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation); | |
635 | // double rg = (axis->range().upper - axis->range().lower)*(factor); |
|
639 | // double rg = (axis->range().upper - axis->range().lower)*(factor); | |
636 | // axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); |
|
640 | // axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | |
637 | double rg =0.0; |
|
641 | double rg =0.0; | |
638 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); |
|
642 | DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range(); | |
639 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); |
|
643 | DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range(); | |
640 | if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) |
|
644 | if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) | |
641 | { |
|
645 | { | |
642 | rg = (axis->range().upper - axis->range().lower)*(factor/10); |
|
646 | rg = (axis->range().upper - axis->range().lower)*(factor/10); | |
643 | axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); |
|
647 | axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg)); | |
644 | } |
|
648 | } | |
645 | else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) |
|
649 | else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) | |
646 | { |
|
650 | { | |
647 | // rg = (axis->range().upper / axis->range().lower)*(factor/100); |
|
651 | // rg = (axis->range().upper / axis->range().lower)*(factor/100); | |
648 | int start,stop; |
|
652 | int start,stop; | |
649 | double diff; |
|
653 | double diff; | |
650 | if(factor>0.0) |
|
654 | if(factor>0.0) | |
651 | { |
|
655 | { | |
652 | stop =this->width()*factor/10; |
|
656 | stop =this->width()*factor/10; | |
653 | start = 2*this->width()*factor/10; |
|
657 | start = 2*this->width()*factor/10; | |
654 | } |
|
658 | } | |
655 | if(factor<0.0) |
|
659 | if(factor<0.0) | |
656 | { |
|
660 | { | |
657 | factor*=-1.0; |
|
661 | factor*=-1.0; | |
658 | start =this->width()*factor/10; |
|
662 | start =this->width()*factor/10; | |
659 | stop = 2*this->width()*factor/10; |
|
663 | stop = 2*this->width()*factor/10; | |
660 | } |
|
664 | } | |
661 | diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop); |
|
665 | diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop); | |
662 | axis->setRange(this->m_plot->axisRect()->rangeDragAxis(orientation)->range().lower*diff, this->m_plot->axisRect()->rangeDragAxis(orientation)->range().upper*diff); |
|
666 | axis->setRange(this->m_plot->axisRect()->rangeDragAxis(orientation)->range().lower*diff, this->m_plot->axisRect()->rangeDragAxis(orientation)->range().upper*diff); | |
663 | } |
|
667 | } | |
664 | this->m_plot->replot(); |
|
668 | this->m_plot->replot(); | |
665 | } |
|
669 | } | |
666 |
|
670 | |||
667 |
|
671 | |||
668 | void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) |
|
672 | void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event) | |
669 | { |
|
673 | { | |
670 | if(mouse_hold) |
|
674 | if(mouse_hold) | |
671 | { |
|
675 | { | |
672 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); |
|
676 | QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |
673 | QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); |
|
677 | QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical); | |
674 | // double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) / rangeDragHorzAxis->pixelToCoord(event->pos().x()); |
|
678 | // double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) / rangeDragHorzAxis->pixelToCoord(event->pos().x()); | |
675 | // rangeDragHorzAxis->setRange(mDragStartHorzRange.lower*diff, mDragStartHorzRange.upper*diff); |
|
679 | // rangeDragHorzAxis->setRange(mDragStartHorzRange.lower*diff, mDragStartHorzRange.upper*diff); | |
676 | double diff=0; |
|
680 | double diff=0; | |
677 | if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) |
|
681 | if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear) | |
678 | { |
|
682 | { | |
679 | diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x()); |
|
683 | diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x()); | |
680 | Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff); |
|
684 | Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff); | |
681 | } |
|
685 | } | |
682 | else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) |
|
686 | else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic) | |
683 | { |
|
687 | { | |
684 | diff = Haxis->pixelToCoord(mDragStart.x()) / Haxis->pixelToCoord(event->pos().x()); |
|
688 | diff = Haxis->pixelToCoord(mDragStart.x()) / Haxis->pixelToCoord(event->pos().x()); | |
685 | Haxis->setRange(DragStartHorzRange.lower*diff, DragStartHorzRange.upper*diff); |
|
689 | Haxis->setRange(DragStartHorzRange.lower*diff, DragStartHorzRange.upper*diff); | |
686 | } |
|
690 | } | |
687 | if(this->m_plot->yAxis->scaleType() == QCPAxis::stLinear) |
|
691 | if(this->m_plot->yAxis->scaleType() == QCPAxis::stLinear) | |
688 | { |
|
692 | { | |
689 | diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y()); |
|
693 | diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y()); | |
690 | Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); |
|
694 | Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff); | |
691 | } |
|
695 | } | |
692 | else if(this->m_plot->yAxis->scaleType() == QCPAxis::stLogarithmic) |
|
696 | else if(this->m_plot->yAxis->scaleType() == QCPAxis::stLogarithmic) | |
693 | { |
|
697 | { | |
694 | diff = Vaxis->pixelToCoord(mDragStart.y()) / Vaxis->pixelToCoord(event->pos().y()); |
|
698 | diff = Vaxis->pixelToCoord(mDragStart.y()) / Vaxis->pixelToCoord(event->pos().y()); | |
695 | Vaxis->setRange(DragStartVertRange.lower*diff, DragStartVertRange.upper*diff); |
|
699 | Vaxis->setRange(DragStartVertRange.lower*diff, DragStartVertRange.upper*diff); | |
696 | } |
|
700 | } | |
697 | this->m_plot->replot(); |
|
701 | this->m_plot->replot(); | |
698 | } |
|
702 | } | |
699 | if (mRubberBand->isVisible()) |
|
703 | if (mRubberBand->isVisible()) | |
700 | { |
|
704 | { | |
701 | mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); |
|
705 | mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized()); | |
702 | } |
|
706 | } | |
703 | QWidget::mouseMoveEvent(event); |
|
707 | QWidget::mouseMoveEvent(event); | |
704 | } |
|
708 | } | |
705 |
|
709 | |||
706 |
|
710 | |||
707 |
|
711 | |||
708 |
|
712 | |||
709 |
|
713 | |||
710 |
|
714 | |||
711 |
|
715 | |||
712 |
|
716 | |||
713 |
|
717 | |||
714 |
|
718 | |||
715 |
|
719 |
@@ -1,134 +1,135 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #ifndef SOCEXPLORERPLOT_H |
|
22 | #ifndef SOCEXPLORERPLOT_H | |
23 | #define SOCEXPLORERPLOT_H |
|
23 | #define SOCEXPLORERPLOT_H | |
24 |
|
24 | |||
25 | #include <QWidget> |
|
25 | #include <QWidget> | |
26 | #include <QGridLayout> |
|
26 | #include <QGridLayout> | |
27 | #include <qcustomplot.h> |
|
27 | #include <qcustomplot.h> | |
28 | #include <qcustomplotvect.h> |
|
28 | #include <qcustomplotvect.h> | |
29 | #include <QRubberBand> |
|
29 | #include <QRubberBand> | |
30 | #include <QPoint> |
|
30 | #include <QPoint> | |
31 |
|
31 | |||
32 | class SocExplorerPlotActions : public QAction |
|
32 | class SocExplorerPlotActions : public QAction | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | SocExplorerPlotActions(const QString &text,int PID,QObject* parent=0) |
|
36 | SocExplorerPlotActions(const QString &text,int PID,QObject* parent=0) | |
37 | :QAction(text,parent) |
|
37 | :QAction(text,parent) | |
38 | { |
|
38 | { | |
39 | setPID(PID); |
|
39 | setPID(PID); | |
40 | connect(this,SIGNAL(triggered()),this,SLOT(trigger())); |
|
40 | connect(this,SIGNAL(triggered()),this,SLOT(trigger())); | |
41 | } |
|
41 | } | |
42 | SocExplorerPlotActions(const QIcon &icon, const QString &text,int PID, QObject* parent) |
|
42 | SocExplorerPlotActions(const QIcon &icon, const QString &text,int PID, QObject* parent) | |
43 | :QAction(icon,text,parent) |
|
43 | :QAction(icon,text,parent) | |
44 | { |
|
44 | { | |
45 | setPID(PID); |
|
45 | setPID(PID); | |
46 | connect(this,SIGNAL(triggered()),this,SLOT(trigger())); |
|
46 | connect(this,SIGNAL(triggered()),this,SLOT(trigger())); | |
47 | } |
|
47 | } | |
48 | ~SocExplorerPlotActions(){} |
|
48 | ~SocExplorerPlotActions(){} | |
49 | void setPID(int PID){this->m_PID=PID;} |
|
49 | void setPID(int PID){this->m_PID=PID;} | |
50 | int PID(){return m_PID;} |
|
50 | int PID(){return m_PID;} | |
51 | private slots: |
|
51 | private slots: | |
52 | void trigger(){emit triggered(m_PID);} |
|
52 | void trigger(){emit triggered(m_PID);} | |
53 | signals: |
|
53 | signals: | |
54 | void triggered(int PID); |
|
54 | void triggered(int PID); | |
55 | private: |
|
55 | private: | |
56 | int m_PID; |
|
56 | int m_PID; | |
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 | class SocExplorerPlot : public QWidget |
|
59 | class SocExplorerPlot : public QWidget | |
60 | { |
|
60 | { | |
61 | Q_OBJECT |
|
61 | Q_OBJECT | |
62 | public: |
|
62 | public: | |
63 | explicit SocExplorerPlot(QWidget *parent = 0); |
|
63 | explicit SocExplorerPlot(QWidget *parent = 0); | |
64 | ~SocExplorerPlot(); |
|
64 | ~SocExplorerPlot(); | |
65 | void setTitle(QString title); |
|
65 | void setTitle(QString title); | |
66 | const QString& title(); |
|
66 | const QString& title(); | |
67 | void setXaxisLabel(QString label); |
|
67 | void setXaxisLabel(QString label); | |
68 | void setXaxisLog(); |
|
68 | void setXaxisLog(); | |
69 | void setXaxisRange(double lower, double upper); |
|
69 | void setXaxisRange(double lower, double upper); | |
70 | void setYaxisLabel(QString label); |
|
70 | void setYaxisLabel(QString label); | |
71 | void setYaxisLog(); |
|
71 | void setYaxisLog(); | |
72 | void setYaxisRange(double lower, double upper); |
|
72 | void setYaxisRange(double lower, double upper); | |
73 | void rescaleAxis(); |
|
73 | void rescaleAxis(); | |
74 | void setLegendFont(QFont font); |
|
74 | void setLegendFont(QFont font); | |
75 | void setLegendSelectedFont(QFont font); |
|
75 | void setLegendSelectedFont(QFont font); | |
76 | void setAdaptativeSampling(int graphIndex,bool enable); |
|
76 | void setAdaptativeSampling(int graphIndex,bool enable); | |
77 | void setUseFastVector(int graphIndex,bool enable); |
|
77 | void setUseFastVector(int graphIndex,bool enable); | |
78 | int addGraph(); |
|
78 | int addGraph(); | |
79 | bool removeGraph(int graphIndex); |
|
79 | bool removeGraph(int graphIndex); | |
80 | int graphCount(); |
|
80 | int graphCount(); | |
81 | void removeAllGraphs(); |
|
81 | void removeAllGraphs(); | |
82 | void setGraphName(int graphIndex,QString name); |
|
82 | void setGraphName(int graphIndex,QString name); | |
83 | const QString& graphName(int graphIndex); |
|
83 | const QString& graphName(int graphIndex); | |
84 | void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y); |
|
84 | void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y); | |
85 | void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true); |
|
85 | void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true); | |
86 | void setGraphData(int graphIndex, QVector<QCPData> *data, bool replot); |
|
86 | void setGraphData(int graphIndex, QVector<QCPData> *data, bool replot); | |
87 | void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y); |
|
87 | void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y); | |
88 | void addGraphData(int graphIndex, QVariant x, QVariant y); |
|
88 | void addGraphData(int graphIndex, QVariant x, QVariant y); | |
89 | void setGraphPen(int graphIndex,QPen pen); |
|
89 | void setGraphPen(int graphIndex,QPen pen); | |
90 | QPen getGraphPen(int graphIndex); |
|
90 | QPen getGraphPen(int graphIndex); | |
91 | void setGraphLineStyle(int graphIndex,QString lineStyle); |
|
91 | void setGraphLineStyle(int graphIndex,QString lineStyle); | |
92 | void setGraphScatterStyle(int graphIndex,QString scatterStyle); |
|
92 | void setGraphScatterStyle(int graphIndex,QString scatterStyle); | |
93 | void setXaxisTickLabelType(QCPAxis::LabelType type); |
|
93 | void setXaxisTickLabelType(QCPAxis::LabelType type); | |
94 | void setXaxisDateTimeFormat(const QString &format); |
|
94 | void setXaxisDateTimeFormat(const QString &format); | |
95 | void show(); |
|
95 | void show(); | |
96 | void replot(); |
|
96 | void replot(); | |
97 | void exportToSVG(const QString& fileName); |
|
97 | void exportToSVG(const QString& fileName); | |
98 | void exportToPDF(const QString& fileName); |
|
98 | void exportToPDF(const QString& fileName); | |
99 | void addAction(SocExplorerPlotActions* action); |
|
99 | void addAction(SocExplorerPlotActions* action); | |
100 | int PID(){return m_PID;} |
|
100 | int PID(){return m_PID;} | |
101 | void setPID(int PID){m_PID = PID;} |
|
101 | void setPID(int PID){m_PID = PID;} | |
102 | QVector<QCPData>* getVisibleData(int graphIndex); |
|
102 | QVector<QCPData>* getVisibleData(int graphIndex); | |
103 | signals: |
|
103 | signals: | |
104 | void titleChanged(const QString& newTitle); |
|
104 | void titleChanged(const QString& newTitle); | |
105 | public slots: |
|
105 | public slots: | |
106 |
|
106 | |||
107 | protected: |
|
107 | protected: | |
108 | void keyPressEvent(QKeyEvent *); |
|
108 | void keyPressEvent(QKeyEvent *); | |
109 | void keyReleaseEvent(QKeyEvent *); |
|
109 | void keyReleaseEvent(QKeyEvent *); | |
110 | void wheelEvent(QWheelEvent *); |
|
110 | void wheelEvent(QWheelEvent *); | |
111 | void mousePressEvent(QMouseEvent *); |
|
111 | void mousePressEvent(QMouseEvent *); | |
112 | void mouseMoveEvent(QMouseEvent *); |
|
112 | void mouseMoveEvent(QMouseEvent *); | |
113 | void mouseReleaseEvent(QMouseEvent *); |
|
113 | void mouseReleaseEvent(QMouseEvent *); | |
114 |
|
114 | |||
115 | private: |
|
115 | private: | |
116 | void zoom(double factor, int center, Qt::Orientation orientation); |
|
116 | void zoom(double factor, int center, Qt::Orientation orientation); | |
117 | void move(double factor, Qt::Orientation orientation); |
|
117 | void move(double factor, Qt::Orientation orientation); | |
118 | QCustomPlotVect* m_plot; |
|
118 | QCustomPlotVect* m_plot; | |
119 | QGridLayout* m_mainlayout; |
|
119 | QGridLayout* m_mainlayout; | |
120 | bool ctrl_hold; |
|
120 | bool ctrl_hold; | |
121 | bool shift_hold; |
|
121 | bool shift_hold; | |
122 | bool mouse_hold; |
|
122 | bool mouse_hold; | |
123 | QCPRange DragStartHorzRange; |
|
123 | QCPRange DragStartHorzRange; | |
124 | QCPRange DragStartVertRange; |
|
124 | QCPRange DragStartVertRange; | |
125 | QPoint mDragStart; |
|
125 | QPoint mDragStart; | |
126 | bool mZoomMode; |
|
126 | bool mZoomMode; | |
127 | QRubberBand * mRubberBand; |
|
127 | QRubberBand * mRubberBand; | |
128 | QPoint mOrigin; |
|
128 | QPoint mOrigin; | |
129 | QList<SocExplorerPlotActions*> m_actions; |
|
129 | QList<SocExplorerPlotActions*> m_actions; | |
130 | QString m_Title; |
|
130 | QString m_Title; | |
|
131 | QCPPlotTitle* m_plotTitle; | |||
131 | int m_PID; |
|
132 | int m_PID; | |
132 | }; |
|
133 | }; | |
133 |
|
134 | |||
134 | #endif // SOCEXPLORERPLOT_H |
|
135 | #endif // SOCEXPLORERPLOT_H |
@@ -1,123 +1,124 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "mainwindow.h" |
|
22 | #include "mainwindow.h" | |
23 | #include "ui_mainwindow.h" |
|
23 | #include "ui_mainwindow.h" | |
24 | #include <QFileDialog> |
|
24 | #include <QFileDialog> | |
25 | #include <QDir> |
|
25 | #include <QDir> | |
26 | #include "qcustomplot.h" |
|
26 | #include "qcustomplot.h" | |
27 | #include <omp.h> |
|
27 | #include <omp.h> | |
28 | #include <QAction> |
|
28 | #include <QAction> | |
29 | #include <downloadhistory.h> |
|
29 | #include <downloadhistory.h> | |
30 | #include <QDateTime> |
|
30 | #include <QDateTime> | |
31 | #include <QDate> |
|
31 | #include <QDate> | |
32 | #include <filedownloader.h> |
|
32 | #include <filedownloader.h> | |
33 | #include <cassinitools.h> |
|
33 | #include <cassinitools.h> | |
34 | #include <qlopplots.h> |
|
34 | #include <qlopplots.h> | |
35 | #include <qlopdatabase.h> |
|
35 | #include <qlopdatabase.h> | |
36 | #include <qlopsettings.h> |
|
36 | #include <qlopsettings.h> | |
37 | #include <qlopgui.h> |
|
37 | #include <qlopgui.h> | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() |
|
|||
41 | <<QLopDataBase::self() |
|
|||
42 | <<FileDownloader::self() |
|
|||
43 | <<CassiniTools::self() |
|
|||
44 | << QLopPlots::self(); |
|
|||
45 |
|
40 | |||
46 | MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) : |
|
41 | MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) : | |
47 | QMainWindow(parent), |
|
42 | QMainWindow(parent), | |
48 | ui(new Ui::MainWindow) |
|
43 | ui(new Ui::MainWindow) | |
49 | { |
|
44 | { | |
50 | this->OMP_THREADS = OMP_THREADS; |
|
45 | this->OMP_THREADS = OMP_THREADS; | |
51 | ui->setupUi(this); |
|
46 | ui->setupUi(this); | |
52 | QLopGUI::registerMenuBar(menuBar()); |
|
47 | QLopGUI::registerMenuBar(menuBar()); | |
53 | this->setWindowIcon(QIcon(":img/QLop.svg")); |
|
48 | this->setWindowIcon(QIcon(":img/QLop.svg")); | |
54 | this->progressWidget = new QWidget(); |
|
49 | this->progressWidget = new QWidget(); | |
55 | this->progressLayout = new QVBoxLayout(this->progressWidget); |
|
50 | this->progressLayout = new QVBoxLayout(this->progressWidget); | |
56 | this->progressWidget->setLayout(this->progressLayout); |
|
51 | this->progressWidget->setLayout(this->progressLayout); | |
57 | this->progressWidget->setWindowModality(Qt::WindowModal); |
|
52 | this->progressWidget->setWindowModality(Qt::WindowModal); | |
58 | progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); |
|
53 | progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); | |
59 | for(int i=0;i<OMP_THREADS;i++) |
|
54 | for(int i=0;i<OMP_THREADS;i++) | |
60 | { |
|
55 | { | |
61 | this->progress.append(new QProgressBar(this->progressWidget)); |
|
56 | this->progress.append(new QProgressBar(this->progressWidget)); | |
62 | this->progress.last()->setMinimum(0); |
|
57 | this->progress.last()->setMinimum(0); | |
63 | this->progress.last()->setMaximum(100); |
|
58 | this->progress.last()->setMaximum(100); | |
64 | this->progressLayout->addWidget(this->progress.last()); |
|
59 | this->progressLayout->addWidget(this->progress.last()); | |
65 | this->progressWidget->hide(); |
|
60 | this->progressWidget->hide(); | |
66 | this->progressThreadIds[i] = -1; |
|
61 | this->progressThreadIds[i] = -1; | |
67 | } |
|
62 | } | |
68 | this->progressWidget->setWindowTitle("Loading File"); |
|
63 | this->progressWidget->setWindowTitle("Loading File"); | |
|
64 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() | |||
|
65 | <<QLopDataBase::self() | |||
|
66 | <<FileDownloader::self() | |||
|
67 | <<CassiniTools::self() | |||
|
68 | << QLopPlots::self(); | |||
|
69 | ||||
69 | for(int i=0;i<ServicesToLoad.count();i++) |
|
70 | for(int i=0;i<ServicesToLoad.count();i++) | |
70 | { |
|
71 | { | |
71 | qDebug()<<ServicesToLoad.at(i)->serviceName(); |
|
72 | qDebug()<<ServicesToLoad.at(i)->serviceName(); | |
72 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); |
|
73 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); | |
73 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
74 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); | |
74 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); |
|
75 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); | |
75 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); |
|
76 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); | |
76 | } |
|
77 | } | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | MainWindow::~MainWindow() |
|
80 | MainWindow::~MainWindow() | |
80 | { |
|
81 | { | |
81 | delete ui; |
|
82 | delete ui; | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | void MainWindow::updateProgress(int threadId, int percentProgress) |
|
85 | void MainWindow::updateProgress(int threadId, int percentProgress) | |
85 | { |
|
86 | { | |
86 | bool updated=false; |
|
87 | bool updated=false; | |
87 | for(int i=0;i<OMP_THREADS;i++) |
|
88 | for(int i=0;i<OMP_THREADS;i++) | |
88 | { |
|
89 | { | |
89 | if(progressThreadIds[i]==threadId) |
|
90 | if(progressThreadIds[i]==threadId) | |
90 | { |
|
91 | { | |
91 | if(threadId<this->progress.count()) |
|
92 | if(threadId<this->progress.count()) | |
92 | { |
|
93 | { | |
93 | this->progress.at(i)->setValue(percentProgress); |
|
94 | this->progress.at(i)->setValue(percentProgress); | |
94 | updated=true; |
|
95 | updated=true; | |
95 | } |
|
96 | } | |
96 | } |
|
97 | } | |
97 | } |
|
98 | } | |
98 | if(Q_UNLIKELY(updated==false)) |
|
99 | if(Q_UNLIKELY(updated==false)) | |
99 | { |
|
100 | { | |
100 | for(int i=0;i<OMP_THREADS;i++) |
|
101 | for(int i=0;i<OMP_THREADS;i++) | |
101 | { |
|
102 | { | |
102 | if(progressThreadIds[i]==-1) |
|
103 | if(progressThreadIds[i]==-1) | |
103 | { |
|
104 | { | |
104 | progressThreadIds[i] = threadId; |
|
105 | progressThreadIds[i] = threadId; | |
105 | updateProgress(threadId,percentProgress); |
|
106 | updateProgress(threadId,percentProgress); | |
106 | return; |
|
107 | return; | |
107 | } |
|
108 | } | |
108 | } |
|
109 | } | |
109 | } |
|
110 | } | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 |
|
113 | |||
113 | void MainWindow::changeEvent(QEvent *e) |
|
114 | void MainWindow::changeEvent(QEvent *e) | |
114 | { |
|
115 | { | |
115 | QMainWindow::changeEvent(e); |
|
116 | QMainWindow::changeEvent(e); | |
116 | switch (e->type()) { |
|
117 | switch (e->type()) { | |
117 | case QEvent::LanguageChange: |
|
118 | case QEvent::LanguageChange: | |
118 | ui->retranslateUi(this); |
|
119 | ui->retranslateUi(this); | |
119 | break; |
|
120 | break; | |
120 | default: |
|
121 | default: | |
121 | break; |
|
122 | break; | |
122 | } |
|
123 | } | |
123 | } |
|
124 | } |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now