##// END OF EJS Templates
Working on restart option for data downloader.
jeandet -
r16:8958118aec1a tip default
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 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 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 8 CONFIG += pythonqt
9 9
10 10 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
11 11
12 12 MOC_DIR = moc
13 13 UI_DIR = ui
14 14 OBJECTS_DIR = obj
15 15
16 16 DESTDIR =./bin
17 17
18 18 TARGET = QLop
19 19 TEMPLATE = app
20 20
21 21 LIBS+=-lfftw3_threads -lfftw3
22 22
23 23 INCLUDEPATH += src/QCustomPlot \
24 24 src src/Cassini \
25 src/Core/network \
25 26 src/Core src/Core/Widgets \
26 27 src/Core/Widgets/PyWdgt
27 28
28 29 defined(QLOP_DEBUG,var){
30 message("building without optimisation")
29 31 QMAKE_CXXFLAGS += -O0 -fopenmp
30 32 QMAKE_LFLAGS += -O0 -fopenmp
31 33 }
32 34 !defined(QLOP_DEBUG,var){
33 35 QMAKE_CXXFLAGS += -O5 -fopenmp
34 36 QMAKE_LFLAGS += -O5 -fopenmp
35 37 }
36 38
37 39
38 40 SOURCES += src/main.cpp\
39 41 src/mainwindow.cpp \
40 42 src/SocExplorerPlot.cpp \
41 43 src/QCustomPlot/qcustomplot.cpp \
42 44 src/toolbarcontainer.cpp \
43 45 src/Core/abstractfileloader.cpp \
44 src/Core/filedownloader.cpp \
45 src/Core/filedownloadertask.cpp \
46 src/Core/network/filedownloader.cpp \
47 src/Core/network/filedownloadertask.cpp \
46 48 src/Core/Widgets/downloadhistory.cpp \
47 49 src/Core/Widgets/downloadhistoryelement.cpp \
48 50 src/Core/qlopservice.cpp \
49 51 src/Cassini/expxmldownloader.cpp \
50 52 src/Cassini/cassinidatadownloader.cpp \
51 53 src/Cassini/cassinidatafile.cpp \
52 54 src/Cassini/cassiniindexfile.cpp \
53 55 src/Cassini/cassiniindexfileviewer.cpp \
54 56 src/Cassini/cassinitools.cpp \
55 57 src/Cassini/cassinitoolsgui.cpp \
56 58 src/Core/Widgets/qlopplots.cpp \
57 59 src/Core/qlopdata.cpp \
58 60 src/Core/Widgets/PyWdgt/pythonconsole.cpp \
59 61 src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.cpp \
60 62 src/QCustomPlot/qcpdocumentobject.cpp \
61 63 src/Core/Widgets/filebrowser.cpp \
62 64 src/Core/Widgets/filesystemmodel.cpp \
63 65 src/Core/Widgets/qcustomplotvect.cpp \
64 66 src/Core/qlopdatabase.cpp \
65 67 src/Core/Widgets/qlopdatabaseviewer.cpp \
66 68 src/Core/Widgets/qlopdatabaseviewermodel.cpp \
67 69 src/Cassini/exptimetabledownloader.cpp \
68 70 src/Core/qlopsettings.cpp \
69 71 src/Core/Widgets/filedowloadersettingsgui.cpp \
70 72 src/Core/qlopgui.cpp \
71 73 src/Core/Widgets/manualproxycfg_gui.cpp \
72 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 79 HEADERS += src/mainwindow.h \
76 80 src/SocExplorerPlot.h \
77 81 src/QCustomPlot/qcustomplot.h \
78 82 src/toolbarcontainer.h \
79 83 src/Core/abstractfileloader.h \
80 src/Core/filedownloader.h \
81 src/Core/filedownloadertask.h \
84 src/Core/network/filedownloader.h \
85 src/Core/network/filedownloadertask.h \
82 86 src/Core/Widgets/downloadhistory.h \
83 87 src/Core/Widgets/downloadhistoryelement.h \
84 88 src/Core/qlopservice.h \
85 89 src/Cassini/expxmldownloader.h \
86 90 src/Cassini/cassinidatadownloader.h \
87 91 src/Cassini/cassinidatafile.h \
88 92 src/Cassini/cassiniindexfile.h \
89 93 src/Cassini/cassiniindexfileviewer.h \
90 94 src/Cassini/cassinitools.h \
91 95 src/Cassini/cassinitoolsgui.h \
92 96 src/Core/Widgets/qlopplots.h \
93 97 src/Core/qlopdata.h \
94 98 src/Core/Widgets/PyWdgt/pythonconsole.h \
95 99 src/Core/Widgets/PyWdgt/pythonqtscriptingconsoledandd.h \
96 100 src/Core/qlop.h \
97 101 src/Core/pyqlop.h \
98 102 src/QCustomPlot/qcpdocumentobject.h \
99 103 src/Core/Widgets/filebrowser.h \
100 104 src/Core/Widgets/filesystemmodel.h \
101 105 src/Core/Widgets/qcustomplotvect.h \
102 106 src/Core/qlopdatabase.h \
103 107 src/Core/Widgets/qlopdatabaseviewer.h \
104 108 src/Core/Widgets/qlopdatabaseviewermodel.h \
105 109 src/Cassini/exptimetabledownloader.h \
106 110 src/Core/qlopsettings.h \
107 111 src/Core/Widgets/filedowloadersettingsgui.h \
108 112 src/Core/qlopgui.h \
109 113 src/Core/Widgets/manualproxycfg_gui.h \
110 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 119 FORMS += src/mainwindow.ui \
114 120 src/Core/Widgets/downloadhistory.ui \
115 121 src/Core/Widgets/downloadhistoryelement.ui \
116 122 src/Cassini/cassinidatadownloader.ui \
117 123 src/Cassini/cassiniindexfileviewer.ui \
118 124 src/Cassini/cassinitoolsgui.ui \
119 125 src/Core/Widgets/filebrowser.ui \
120 126 src/Core/Widgets/qlopdatabaseviewer.ui \
121 127 src/Core/Widgets/filedowloadersettingsgui.ui \
122 128 src/Core/Widgets/manualproxycfg_gui.ui \
123 129 src/Core/Widgets/qlopsettingsdialog.ui \
124 130 src/Cassini/cassinitoolssettingsgui.ui
125 131
126 132 RESOURCES += \
127 133 resources/qlop.qrc
128 134
129 135 include(src/Core/Widgets/NicePyConsole/NicePyConsole.pri)
130 136 include(src/Core/pythonQtOut/generated_cpp/PyQLop/PyQLop.pri)
131 137
132 138 win32 {
133 139 DEFINES += WIN32
134 140 }
135 141
136 142 unix {
137 143 DEFINES += UNIX
138 144 }
139 145
140 146 unix{
141 147 target.path = /usr/bin
142 148 INSTALLS += target
143 149 }
144 150
145 151
146 152 unix{
147 153 QLopLauncher.path = /usr/share/applications/
148 154 QLopLauncher.files = linux/QLop.desktop
149 155 QLopAppData.path = /usr/share/appdata/
150 156 QLopAppData.files = linux/QLop.appdata.xml
151 157 share.path = /usr/share/QLop
152 158 share.files = resources/QLop.svg \
153 159 resources/QLop.png
154 160
155 161 INSTALLS+= QLopLauncher share QLopAppData
156 162 }
157 163
158 164 DISTFILES += \
159 165 src/Core/pythongenerator.sh \
160 166 src/Core/pythonQtgeneratorCfg.txt \
161 167 linux/QLop.spec \
162 168 linux/QLop.desktop \
163 169 linux/QLop.appdata.xml
164 170
@@ -1,15 +1,18
1 1 <RCC>
2 2 <qresource prefix="/img">
3 3 <file>Gnome-view-refresh.svg</file>
4 4 <file>Gnome-list-add.svg</file>
5 5 <file>ListView.svg</file>
6 6 <file>TreeView.svg</file>
7 7 <file>Gnome-go-up.svg</file>
8 8 <file>QLop.svg</file>
9 9 <file>Gnome-emblem-downloads.svg</file>
10 10 <file>cassini.gif</file>
11 <file>restart.png</file>
12 <file>start.png</file>
13 <file>stop.png</file>
11 14 </qresource>
12 15 <qresource prefix="/">
13 16 <file>QLop.png</file>
14 17 </qresource>
15 18 </RCC>
@@ -1,26 +1,26
1 1 #include "cassinitoolssettingsgui.h"
2 2 #include "ui_cassinitoolssettingsgui.h"
3 3
4 4 CassiniToolsSettingsGUI::CassiniToolsSettingsGUI(QWidget *parent) :
5 QWidget(parent),
5 QLopSettingsItem(parent),
6 6 ui(new Ui::CassiniToolsSettingsGUI)
7 7 {
8 8 ui->setupUi(this);
9 9 }
10 10
11 11 CassiniToolsSettingsGUI::~CassiniToolsSettingsGUI()
12 12 {
13 13 delete ui;
14 14 }
15 15
16 16 void CassiniToolsSettingsGUI::changeEvent(QEvent *e)
17 17 {
18 18 QWidget::changeEvent(e);
19 19 switch (e->type()) {
20 20 case QEvent::LanguageChange:
21 21 ui->retranslateUi(this);
22 22 break;
23 23 default:
24 24 break;
25 25 }
26 26 }
@@ -1,25 +1,27
1 1 #ifndef CASSINITOOLSSETTINGSGUI_H
2 2 #define CASSINITOOLSSETTINGSGUI_H
3 3
4 4 #include <QWidget>
5
5 #include <qlopsettingsdialog.h>
6 6 namespace Ui {
7 7 class CassiniToolsSettingsGUI;
8 8 }
9 9
10 class CassiniToolsSettingsGUI : public QWidget
10 class CassiniToolsSettingsGUI : public QLopSettingsItem
11 11 {
12 12 Q_OBJECT
13 13
14 14 public:
15 15 explicit CassiniToolsSettingsGUI(QWidget *parent = 0);
16 16 ~CassiniToolsSettingsGUI();
17 17
18 public slots:
19 void accept(){}
18 20 protected:
19 21 void changeEvent(QEvent *e);
20 22
21 23 private:
22 24 Ui::CassiniToolsSettingsGUI *ui;
23 25 };
24 26
25 27 #endif // CASSINITOOLSSETTINGSGUI_H
@@ -1,58 +1,71
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>DownloadHistoryElement</class>
4 4 <widget class="QWidget" name="DownloadHistoryElement">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>724</width>
10 10 <height>74</height>
11 11 </rect>
12 12 </property>
13 13 <property name="sizePolicy">
14 14 <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
15 15 <horstretch>0</horstretch>
16 16 <verstretch>0</verstretch>
17 17 </sizepolicy>
18 18 </property>
19 19 <property name="windowTitle">
20 20 <string>Form</string>
21 21 </property>
22 22 <property name="styleSheet">
23 23 <string notr="true"/>
24 24 </property>
25 25 <layout class="QGridLayout" name="gridLayout">
26 26 <item row="0" column="0" rowspan="2">
27 27 <widget class="QLabel" name="DownloadDate">
28 28 <property name="text">
29 29 <string>TextLabel</string>
30 30 </property>
31 31 </widget>
32 32 </item>
33 33 <item row="1" column="2">
34 34 <widget class="QProgressBar" name="progressBar">
35 35 <property name="value">
36 36 <number>0</number>
37 37 </property>
38 38 </widget>
39 39 </item>
40 40 <item row="1" column="1">
41 41 <widget class="QLabel" name="linkLbl">
42 42 <property name="text">
43 43 <string>TextLabel</string>
44 44 </property>
45 45 </widget>
46 46 </item>
47 47 <item row="0" column="1" colspan="2">
48 48 <widget class="QLabel" name="FileNameLbl">
49 49 <property name="text">
50 50 <string>TextLabel</string>
51 51 </property>
52 52 </widget>
53 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 65 </layout>
55 66 </widget>
56 <resources/>
67 <resources>
68 <include location="../../../resources/qlop.qrc"/>
69 </resources>
57 70 <connections/>
58 71 </ui>
@@ -1,61 +1,79
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "filedowloadersettingsgui.h"
23 23 #include "ui_filedowloadersettingsgui.h"
24 #include <qlopsettings.h>
25 #include <filedownloader.h>
26 #include <QDir>
27 #include <qlopnetworkproxyfactory.h>
24 28
25 29 FileDowloaderSettingsGUI::FileDowloaderSettingsGUI(QWidget *parent) :
26 QWidget(parent),
30 QLopSettingsItem(parent),
27 31 ui(new Ui::FileDowloaderSettingsGUI)
28 32 {
29 33 ui->setupUi(this);
30 34 this->manualProxyCFG_GUI = new ManualProxyCFG_GUI();
31 35 lastWidget = NULL;
32 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 46 FileDowloaderSettingsGUI::~FileDowloaderSettingsGUI()
36 47 {
37 48 delete ui;
38 49 }
39 50
40 51 void FileDowloaderSettingsGUI::changeEvent(QEvent *e)
41 52 {
42 53 QWidget::changeEvent(e);
43 54 switch (e->type()) {
44 55 case QEvent::LanguageChange:
45 56 ui->retranslateUi(this);
46 57 break;
47 58 default:
48 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 70 void FileDowloaderSettingsGUI::proxyMethodChanged(const QString &text)
53 71 {
54 72 this->ui->gridLayout->removeWidget(this->lastWidget);
55 if(text=="manual")
73 if(text==CFG_PROXY_TYPE_VALUE_MANUAL)
56 74 {
57 75 this->ui->gridLayout->addWidget(this->manualProxyCFG_GUI,1,0,1,-1);
58 76 this->lastWidget = this->manualProxyCFG_GUI;
59 77 return;
60 78 }
61 79 }
@@ -1,51 +1,52
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef FILEDOWLOADERSETTINGSGUI_H
23 23 #define FILEDOWLOADERSETTINGSGUI_H
24 24
25 25 #include <QWidget>
26 26 #include "manualproxycfg_gui.h"
27 #include <qlopsettingsdialog.h>
27 28
28 29 namespace Ui {
29 30 class FileDowloaderSettingsGUI;
30 31 }
31 32
32 class FileDowloaderSettingsGUI : public QWidget
33 class FileDowloaderSettingsGUI : public QLopSettingsItem
33 34 {
34 35 Q_OBJECT
35 36
36 37 public:
37 38 explicit FileDowloaderSettingsGUI(QWidget *parent = 0);
38 39 ~FileDowloaderSettingsGUI();
39
40 40 protected:
41 41 void changeEvent(QEvent *e);
42
42 public slots:
43 void accept();
43 44 private slots:
44 45 void proxyMethodChanged(const QString & text);
45 46 private:
46 47 ManualProxyCFG_GUI* manualProxyCFG_GUI;
47 48 Ui::FileDowloaderSettingsGUI *ui;
48 49 QWidget* lastWidget;
49 50 };
50 51
51 52 #endif // FILEDOWLOADERSETTINGSGUI_H
@@ -1,74 +1,74
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>FileDowloaderSettingsGUI</class>
4 4 <widget class="QWidget" name="FileDowloaderSettingsGUI">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>318</width>
10 10 <height>128</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QFormLayout" name="formLayout">
17 17 <item row="0" column="0">
18 18 <widget class="QLabel" name="label">
19 19 <property name="text">
20 20 <string>Default destination path</string>
21 21 </property>
22 22 </widget>
23 23 </item>
24 24 <item row="0" column="1">
25 <widget class="QLineEdit" name="lineEdit"/>
25 <widget class="QLineEdit" name="defaultDestPath"/>
26 26 </item>
27 27 <item row="1" column="0" colspan="2">
28 28 <widget class="QGroupBox" name="groupBox">
29 29 <property name="title">
30 30 <string>Proxy server</string>
31 31 </property>
32 32 <layout class="QGridLayout" name="gridLayout">
33 33 <item row="0" column="0">
34 34 <widget class="QLabel" name="label_2">
35 35 <property name="text">
36 36 <string>Method</string>
37 37 </property>
38 38 <property name="alignment">
39 39 <set>Qt::AlignCenter</set>
40 40 </property>
41 41 </widget>
42 42 </item>
43 43 <item row="0" column="1">
44 44 <widget class="QComboBox" name="comboBox">
45 45 <item>
46 46 <property name="text">
47 47 <string>none</string>
48 48 </property>
49 49 </item>
50 50 <item>
51 51 <property name="text">
52 52 <string>system</string>
53 53 </property>
54 54 </item>
55 55 <item>
56 56 <property name="text">
57 57 <string>manual</string>
58 58 </property>
59 59 </item>
60 60 <item>
61 61 <property name="text">
62 62 <string>automatic</string>
63 63 </property>
64 64 </item>
65 65 </widget>
66 66 </item>
67 67 </layout>
68 68 </widget>
69 69 </item>
70 70 </layout>
71 71 </widget>
72 72 <resources/>
73 73 <connections/>
74 74 </ui>
@@ -1,47 +1,85
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "manualproxycfg_gui.h"
23 23 #include "ui_manualproxycfg_gui.h"
24 #include <qlopsettings.h>
25 #include <filedownloader.h>
24 26
25 27 ManualProxyCFG_GUI::ManualProxyCFG_GUI(QWidget *parent) :
26 28 QWidget(parent),
27 29 ui(new Ui::ManualProxyCFG_GUI)
28 30 {
29 31 ui->setupUi(this);
32 reloadConfig();
30 33 }
31 34
32 35 ManualProxyCFG_GUI::~ManualProxyCFG_GUI()
33 36 {
34 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 75 void ManualProxyCFG_GUI::changeEvent(QEvent *e)
38 76 {
39 77 QWidget::changeEvent(e);
40 78 switch (e->type()) {
41 79 case QEvent::LanguageChange:
42 80 ui->retranslateUi(this);
43 81 break;
44 82 default:
45 83 break;
46 84 }
47 85 }
@@ -1,46 +1,47
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef MANUALPROXYCFG_GUI_H
23 23 #define MANUALPROXYCFG_GUI_H
24 24
25 25 #include <QWidget>
26 26
27 27 namespace Ui {
28 28 class ManualProxyCFG_GUI;
29 29 }
30 30
31 31 class ManualProxyCFG_GUI : public QWidget
32 32 {
33 33 Q_OBJECT
34 34
35 35 public:
36 36 explicit ManualProxyCFG_GUI(QWidget *parent = 0);
37 37 ~ManualProxyCFG_GUI();
38
38 void reloadConfig();
39 void saveConfig();
39 40 protected:
40 41 void changeEvent(QEvent *e);
41 42
42 43 private:
43 44 Ui::ManualProxyCFG_GUI *ui;
44 45 };
45 46
46 47 #endif // MANUALPROXYCFG_GUI_H
@@ -1,109 +1,218
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>ManualProxyCFG_GUI</class>
4 4 <widget class="QWidget" name="ManualProxyCFG_GUI">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>423</width>
10 10 <height>207</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QGridLayout" name="gridLayout">
17 17 <item row="0" column="0">
18 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 25 <property name="text">
20 26 <string>HTTP proxy</string>
21 27 </property>
22 28 </widget>
23 29 </item>
24 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 42 </item>
27 43 <item row="1" column="0">
28 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 51 <property name="text">
30 52 <string>HTTPS proxy</string>
31 53 </property>
32 54 </widget>
33 55 </item>
34 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 68 </item>
37 69 <item row="2" column="0">
38 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 77 <property name="text">
40 78 <string>FTP proxy</string>
41 79 </property>
42 80 </widget>
43 81 </item>
44 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 94 </item>
47 95 <item row="3" column="0">
48 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 103 <property name="text">
50 104 <string>SOCKS proxy</string>
51 105 </property>
52 106 </widget>
53 107 </item>
54 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 120 </item>
57 121 <item row="4" column="0">
58 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 129 <property name="text">
60 130 <string>Ignore hosts</string>
61 131 </property>
62 132 </widget>
63 133 </item>
64 134 <item row="0" column="2">
65 135 <widget class="QLineEdit" name="httpPort">
66 136 <property name="sizePolicy">
67 <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
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 157 <horstretch>0</horstretch>
69 158 <verstretch>0</verstretch>
70 159 </sizepolicy>
71 160 </property>
72 161 <property name="inputMask">
73 162 <string>000000</string>
74 163 </property>
75 </widget>
76 </item>
77 <item row="1" column="2">
78 <widget class="QLineEdit" name="httpsPort">
79 <property name="inputMask">
80 <string>000000</string>
164 <property name="placeholderText">
165 <string>0 to 65536</string>
81 166 </property>
82 167 </widget>
83 168 </item>
84 169 <item row="2" column="2">
85 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 177 <property name="inputMask">
87 178 <string>000000</string>
88 179 </property>
180 <property name="placeholderText">
181 <string>0 to 65536</string>
182 </property>
89 183 </widget>
90 184 </item>
91 185 <item row="3" column="2">
92 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 193 <property name="inputMask">
94 194 <string>000000</string>
95 195 </property>
196 <property name="placeholderText">
197 <string>0 to 65536</string>
198 </property>
96 199 </widget>
97 200 </item>
98 201 <item row="4" column="1" colspan="2">
99 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 209 <property name="text">
101 210 <string>localhost, 127.0.0.0/8, ::1</string>
102 211 </property>
103 212 </widget>
104 213 </item>
105 214 </layout>
106 215 </widget>
107 216 <resources/>
108 217 <connections/>
109 218 </ui>
@@ -1,70 +1,71
1 1 #include "qlopsettingsdialog.h"
2 2 #include "ui_qlopsettingsdialog.h"
3 3
4 4 QLopSettingsDialog::QLopSettingsDialog(QWidget *parent) :
5 5 QDialog(parent),
6 6 ui(new Ui::QLopSettingsDialog)
7 7 {
8 8 ui->setupUi(this);
9 9 connect(ui->contentsWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*)));
10 10 ui->contentsWidget->setViewMode(QListView::IconMode);
11 11 ui->contentsWidget->setIconSize(QSize(96, 84));
12 12 ui->contentsWidget->setMovement(QListView::Static);
13 13 ui->contentsWidget->setSpacing(12);
14 14 }
15 15
16 16 QLopSettingsDialog::~QLopSettingsDialog()
17 17 {
18 18 delete ui;
19 19 }
20 20
21 21 void QLopSettingsDialog::changeEvent(QEvent *e)
22 22 {
23 23 QDialog::changeEvent(e);
24 24 switch (e->type()) {
25 25 case QEvent::LanguageChange:
26 26 ui->retranslateUi(this);
27 27 break;
28 28 default:
29 29 break;
30 30 }
31 31 }
32 32
33 33
34 34 void QLopSettingsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
35 35 {
36 36 if (!current)
37 37 current = previous;
38 38
39 39 ui->pagesWidget->setCurrentIndex(ui->contentsWidget->row(current));
40 40 }
41 41
42 bool QLopSettingsDialog::registerConfigEntry(QWidget *configEntry, QIcon icon, QString text)
42 bool QLopSettingsDialog::registerConfigEntry(QLopSettingsItem *configEntry, QIcon icon, QString text)
43 43 {
44 44 if(configEntry!=NULL)
45 45 {
46 46 ui->pagesWidget->addWidget(configEntry);
47 47 QListWidgetItem *configButton = new QListWidgetItem(ui->contentsWidget);
48 48 configButton->setIcon(icon);
49 49 configButton->setText(text);
50 50 configButton->setTextAlignment(Qt::AlignHCenter);
51 51 configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
52 connect(this,SIGNAL(accepted()),configEntry,SLOT(accept()));
52 53 return true;
53 54 }
54 55 return false;
55 56 }
56 57
57 void QLopSettingsDialog::popConfigDialog(QWidget *selectedConfigEntry)
58 void QLopSettingsDialog::popConfigDialog(QLopSettingsItem *selectedConfigEntry)
58 59 {
59 60 if(selectedConfigEntry!=NULL)
60 61 {
61 62 for(int i=0;i<ui->pagesWidget->count();i++)
62 63 {
63 64 if(ui->pagesWidget->widget(i)==selectedConfigEntry)
64 65 {
65 66 ui->pagesWidget->setCurrentIndex(i);
66 67 }
67 68 }
68 69 }
69 70 this->show();
70 71 }
@@ -1,30 +1,40
1 1 #ifndef QLOPSETTINGSDIALOG_H
2 2 #define QLOPSETTINGSDIALOG_H
3 3
4 4 #include <QDialog>
5 5
6 6 namespace Ui {
7 7 class QLopSettingsDialog;
8 8 }
9 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 21 class QLopSettingsDialog : public QDialog
12 22 {
13 23 Q_OBJECT
14 24
15 25 public:
16 26 explicit QLopSettingsDialog(QWidget *parent = 0);
17 27 ~QLopSettingsDialog();
18 28
19 29 public slots:
20 30 void changePage(QListWidgetItem *current, QListWidgetItem *previous);
21 bool registerConfigEntry(QWidget* configEntry, QIcon icon, QString text);
22 void popConfigDialog(QWidget* selectedConfigEntry=0);
31 bool registerConfigEntry(QLopSettingsItem* configEntry, QIcon icon, QString text);
32 void popConfigDialog(QLopSettingsItem* selectedConfigEntry=0);
23 33 protected:
24 34 void changeEvent(QEvent *e);
25 35
26 36 private:
27 37 Ui::QLopSettingsDialog *ui;
28 38 };
29 39
30 40 #endif // QLOPSETTINGSDIALOG_H
@@ -1,6 +1,6
1 1 #!/bin/bash
2 2
3 3 #export QTDIR=/usr/include
4 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 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "qlopsettings.h"
23 23 #include <QtWidgets>
24 24 #include <QAction>
25 25 #include <qlopgui.h>
26 26
27 27 QLopSettings* QLopSettings::_self=NULL;
28 28 QDockWidget* QLopSettings::m_gui=NULL;
29 29 QSettings* QLopSettings::m_settings=NULL;
30 30 QLopSettingsDialog* QLopSettings::m_configDialog=NULL;
31 31
32 32 #define INIT() \
33 33 if(Q_UNLIKELY(_self==NULL))\
34 34 {\
35 35 init();\
36 36 }
37 37
38 38 QLopSettings::QLopSettings(bool noGUI,QObject *parent) : QLopService(parent)
39 39 {
40 40 m_serviceName="QLopSettings";
41 41 m_settings = new QSettings();
42 42 m_noGui=noGUI;
43 43 m_configDialog = new QLopSettingsDialog();
44 44 QAction* trigerGUI = new QAction(tr("Settings"),this);
45 45 connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog()));
46 46 QLopGUI::addSettingsAction(trigerGUI);
47 47 }
48 48
49 49 QLopSettings::~QLopSettings()
50 50 {
51 51 delete m_configDialog;
52 52 delete m_settings;
53 53 }
54 54
55 55 QDockWidget *QLopSettings::getGUI()
56 56 {
57 57 if(!m_noGui && (m_gui==NULL))
58 58 {
59 59 // m_gui=new QLopDataBaseViewer();
60 60 // m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
61 61 }
62 62 return m_gui;
63 63 }
64 64
65 65 void QLopSettings::init(bool noGUI, QObject *parent)
66 66 {
67 67 _self=new QLopSettings(noGUI,parent);
68 68 }
69 69
70 70 const QString &QLopSettings::serviceName()
71 71 {
72 72 INIT();
73 73 return m_serviceName;
74 74 }
75 75
76 76 QLopSettings *QLopSettings::self()
77 77 {
78 78 INIT();
79 79 return _self;
80 80 }
81 81
82 void QLopSettings::popConfigDialog(QWidget *selectedConfigEntry)
82 void QLopSettings::popConfigDialog(QLopSettingsItem *selectedConfigEntry)
83 83 {
84 84 INIT();
85 85 m_configDialog->popConfigDialog(selectedConfigEntry);
86 86 }
87 87
88 88 void QLopSettings::popConfigDialog()
89 89 {
90 90 m_configDialog->popConfigDialog(NULL);
91 91 }
92 92
93 bool QLopSettings::registerConfigEntry(QWidget *configEntry, QIcon icon, QString text)
93 bool QLopSettings::registerConfigEntry(QLopSettingsItem *configEntry, QIcon icon, QString text)
94 94 {
95 95 INIT();
96 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 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef QLOPSETTINGS_H
23 23 #define QLOPSETTINGS_H
24 24
25 25 #include <QObject>
26 26 #include <qlopservice.h>
27 27 #include <QSettings>
28 28 #include <QDialog>
29 29 #include <QIcon>
30 30 #include <qlopsettingsdialog.h>
31 31
32 32
33 33 class QLopSettings : public QLopService
34 34 {
35 35 Q_OBJECT
36 36 static QDockWidget* m_gui;
37 37 QLopSettings(bool noGUI=false,QObject *parent = 0);
38 38 ~QLopSettings();
39 39 static QLopSettings* _self;
40 40 static QSettings* m_settings;
41 41 static QLopSettingsDialog* m_configDialog;
42 42 public:
43 43 QDockWidget* getGUI();
44 44 static void init(bool noGUI=false,QObject *parent = 0);
45 45 const QString& serviceName();
46 46 static QLopSettings* self();
47 static void popConfigDialog(QWidget* selectedConfigEntry);
48 static bool registerConfigEntry(QWidget* configEntry,QIcon icon, QString text);
47 static void popConfigDialog(QLopSettingsItem *selectedConfigEntry);
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 51 public slots:
50 52 void popConfigDialog();
51 53 };
52 54
53 55 #endif // QLOPSETTINGS_H
@@ -1,715 +1,719
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "SocExplorerPlot.h"
23 23 #include <QSvgGenerator>
24 24 #include <qcpdocumentobject.h>
25 25 #include <QPdfWriter>
26 26 #include <QPrinter>
27 27
28 28 SocExplorerPlot::SocExplorerPlot(QWidget *parent) :
29 29 QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this))
30 30 {
31 31 this->m_plot = new QCustomPlotVect(this);
32 32 this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
33 33 QCP::iSelectLegend | QCP::iSelectPlottables);
34 34 this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
35 35 this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
36 36 this->m_mainlayout = new QGridLayout(this);
37 37 this->setLayout(this->m_mainlayout);
38 38 this->m_mainlayout->addWidget(this->m_plot);
39 39 this->setMinimumSize(400,300);
40 40 this->setFocusPolicy(Qt::WheelFocus);
41 41 this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
42 42 this->ctrl_hold = false;
43 43 this->shift_hold = false;
44 44 this->mouse_hold = false;
45 45 this->m_plot->setNoAntialiasingOnDrag(true);
46 46 this->show();
47 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 52 SocExplorerPlot::~SocExplorerPlot()
51 53 {
52 54 delete mRubberBand;
53 55 }
54 56
55 57 void SocExplorerPlot::show()
56 58 {
57 59 QWidget::show();
58 60 }
59 61
60 62 void SocExplorerPlot::replot()
61 63 {
62 64 this->m_plot->replot();
63 65 }
64 66
65 67 void SocExplorerPlot::exportToSVG(const QString &fileName)
66 68 {
67 69 QSvgGenerator printer;
68 70 printer.setFileName(fileName);
69 71 QCPPainter qcpPainter;
70 72 qcpPainter.begin(&printer);
71 73 m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height());
72 74 qcpPainter.end();
73 75 }
74 76
75 77 void SocExplorerPlot::exportToPDF(const QString &fileName)
76 78 {
77 79 QPrinter printer(QPrinter::HighResolution);
78 80 printer.setOutputFormat(QPrinter::PdfFormat);
79 81 printer.setOrientation(QPrinter::Landscape);
80 82 printer.setOutputFileName(fileName);
81 83 printer.setFullPage(true);
82 84 QCPPainter qcpPainter;
83 85 qcpPainter.begin(&printer);
84 86 m_plot->toPainter(&qcpPainter, printer.width(), printer.height());
85 87 qcpPainter.end();
86 88 }
87 89
88 90 void SocExplorerPlot::addAction(SocExplorerPlotActions *action)
89 91 {
90 92 this->m_actions.append(action);
91 93 QWidget::addAction((QAction*)action);
92 94 }
93 95
94 96 QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex)
95 97 {
96 98 QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData();
97 99 return visibleData;
98 100 }
99 101
100 102 void SocExplorerPlot::setTitle(QString title)
101 103 {
102 104 Q_UNUSED(title)
103 105 //this->m_plot->setTitle(title);
104 106 /*!
105 107 @todo Function borcken fixe this!
106 108 */
109 m_plotTitle->setText(title);
110 m_plot->plotLayout()->addElement(0, 0, m_plotTitle);
107 111 this->m_Title = title;
108 112 emit titleChanged(title);
109 113 this->repaint();
110 114 }
111 115
112 116 const QString &SocExplorerPlot::title()
113 117 {
114 118 return m_Title;
115 119 }
116 120
117 121 void SocExplorerPlot::setXaxisLabel(QString label)
118 122 {
119 123 this->m_plot->xAxis->setLabel(label);
120 124 this->repaint();
121 125 }
122 126
123 127 void SocExplorerPlot::setXaxisLog()
124 128 {
125 129 this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic);
126 130 }
127 131
128 132 void SocExplorerPlot::setYaxisLabel(QString label)
129 133 {
130 134 this->m_plot->yAxis->setLabel(label);
131 135 this->repaint();
132 136 }
133 137
134 138 void SocExplorerPlot::setYaxisLog()
135 139 {
136 140 this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic);
137 141 }
138 142
139 143 void SocExplorerPlot::setXaxisRange(double lower, double upper)
140 144 {
141 145 this->m_plot->xAxis->setRange(lower,upper);
142 146 }
143 147
144 148 void SocExplorerPlot::setYaxisRange(double lower, double upper)
145 149 {
146 150 this->m_plot->yAxis->setRange(lower,upper);
147 151 }
148 152
149 153
150 154 void SocExplorerPlot::rescaleAxis()
151 155 {
152 156 this->m_plot->rescaleAxes();
153 157 this->m_plot->replot();
154 158 }
155 159
156 160 void SocExplorerPlot::setLegendFont(QFont font)
157 161 {
158 162 this->m_plot->legend->setFont(font);
159 163 this->repaint();
160 164 }
161 165
162 166 void SocExplorerPlot::setLegendSelectedFont(QFont font)
163 167 {
164 168 this->m_plot->legend->setSelectedFont(font);
165 169 this->repaint();
166 170 }
167 171
168 172 void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable)
169 173 {
170 174 this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable);
171 175 }
172 176
173 177 void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable)
174 178 {
175 179 // TODO deprecated
176 180 // this->m_plot->graph(graphIndex)->setUseFastVectors(enable);
177 181 }
178 182
179 183 int SocExplorerPlot::addGraph()
180 184 {
181 185 this->m_plot->addGraph();
182 186 return this->m_plot->graphCount() -1;
183 187 }
184 188
185 189 bool SocExplorerPlot::removeGraph(int graphIndex)
186 190 {
187 191 return this->m_plot->removeGraph(graphIndex);
188 192 }
189 193
190 194 int SocExplorerPlot::graphCount()
191 195 {
192 196 return m_plot->graphCount();
193 197 }
194 198
195 199 void SocExplorerPlot::removeAllGraphs()
196 200 {
197 201 int graphCount=this->m_plot->graphCount();
198 202 for(int i=0;i<graphCount;i++)
199 203 {
200 204 this->m_plot->removeGraph(0);
201 205 }
202 206 }
203 207
204 208
205 209 void SocExplorerPlot::setGraphName(int graphIndex,QString name)
206 210 {
207 211 if(graphIndex<this->m_plot->graphCount())
208 212 {
209 213 this->m_plot->graph(graphIndex)->setName(name);
210 214 }
211 215 }
212 216
213 217 const QString &SocExplorerPlot::graphName(int graphIndex)
214 218 {
215 219 if(graphIndex<this->m_plot->graphCount())
216 220 {
217 221 return this->m_plot->graph(graphIndex)->name();
218 222 }
219 223 return "";
220 224 }
221 225
222 226
223 227 void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
224 228 {
225 229 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double))
226 230 {
227 231 QVector<double> _x(x.count()), _y(y.count());
228 232 for(int i=0;i<x.count();i++)
229 233 {
230 234 /*_x[i] = x.at(i).value<double>();
231 235 _y[i] = y.at(i).value<double>();*/
232 236 _x[i] = x.at(i).toDouble();
233 237 _y[i] = y.at(i).toDouble();
234 238 }
235 239 this->m_plot->graph(graphIndex)->setData(_x,_y);
236 240 }
237 241 else
238 242 {
239 243 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime))
240 244 {
241 245 QVector<double> _x(x.count()), _y(y.count());
242 246 for(int i=0;i<x.count();i++)
243 247 {
244 248 /*_x[i] = x.at(i).value<double>();
245 249 _y[i] = y.at(i).value<double>();*/
246 250 _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch();
247 251 _y[i] = y.at(i).toDouble();
248 252 }
249 253 this->m_plot->graph(graphIndex)->setData(_x,_y);
250 254 this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
251 255 this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz");
252 256
253 257 }
254 258 }
255 259 this->m_plot->replot();
256 260 }
257 261
258 262 void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot)
259 263 {
260 264 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
261 265 {
262 266 this->m_plot->graph(graphIndex)->setData(data,copy);
263 267 }
264 268 if(replot)
265 269 this->m_plot->replot();
266 270 }
267 271
268 272 void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot)
269 273 {
270 274 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
271 275 {
272 276 ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data);
273 277 }
274 278 if(replot)
275 279 this->m_plot->replot();
276 280 }
277 281
278 282 void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
279 283 {
280 284 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
281 285 {
282 286 QVector<double> _x(x.count()), _y(y.count());
283 287 for(int i=0;i<x.count();i++)
284 288 {
285 289 /*_x[i] = x.at(i).value<double>();
286 290 _y[i] = y.at(i).value<double>();*/
287 291 _x[i] = x.at(i).toDouble();
288 292 _y[i] = y.at(i).toDouble();
289 293 }
290 294 this->m_plot->graph(graphIndex)->addData(_x,_y);
291 295 }
292 296 this->m_plot->replot();
293 297 }
294 298
295 299 void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y)
296 300 {
297 301 if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double))
298 302 {
299 303 this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble());
300 304 }
301 305 this->m_plot->replot();
302 306 }
303 307
304 308 void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen)
305 309 {
306 310 if(graphIndex<this->m_plot->graphCount())
307 311 {
308 312 this->m_plot->graph(graphIndex)->setPen(pen);
309 313 }
310 314 }
311 315
312 316 QPen SocExplorerPlot::getGraphPen(int graphIndex)
313 317 {
314 318 if(graphIndex<this->m_plot->graphCount())
315 319 {
316 320 return this->m_plot->graph(graphIndex)->pen();
317 321 }
318 322 return this->m_plot->graph()->pen();
319 323 }
320 324
321 325
322 326
323 327 void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle)
324 328 {
325 329 if(graphIndex<this->m_plot->graphCount())
326 330 {
327 331 if(!lineStyle.compare("none"))
328 332 {
329 333 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone);
330 334 return;
331 335 }
332 336 if(!lineStyle.compare("line"))
333 337 {
334 338 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine);
335 339 return;
336 340 }
337 341 if(!lineStyle.compare("stepleft"))
338 342 {
339 343 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft);
340 344 return;
341 345 }
342 346 if(!lineStyle.compare("stepright"))
343 347 {
344 348 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight);
345 349 return;
346 350 }
347 351 if(!lineStyle.compare("stepcenter"))
348 352 {
349 353 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter);
350 354 return;
351 355 }
352 356 if(!lineStyle.compare("impulse"))
353 357 {
354 358 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse);
355 359 return;
356 360 }
357 361
358 362
359 363 }
360 364 }
361 365
362 366 void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle)
363 367 {
364 368 if(graphIndex<this->m_plot->graphCount())
365 369 {
366 370 if(!scatterStyle.compare("none"))
367 371 {
368 372 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone);
369 373 return;
370 374 }
371 375 if(!scatterStyle.compare("dot"))
372 376 {
373 377 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot);
374 378 return;
375 379 }
376 380 if(!scatterStyle.compare("cross"))
377 381 {
378 382 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross);
379 383 return;
380 384 }
381 385 if(!scatterStyle.compare("plus"))
382 386 {
383 387 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus);
384 388 return;
385 389 }
386 390 if(!scatterStyle.compare("circle"))
387 391 {
388 392 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle);
389 393 return;
390 394 }
391 395 if(!scatterStyle.compare("disc"))
392 396 {
393 397 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc);
394 398 return;
395 399 }
396 400 if(!scatterStyle.compare("square"))
397 401 {
398 402 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare);
399 403 return;
400 404 }
401 405 if(!scatterStyle.compare("diamond"))
402 406 {
403 407 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond);
404 408 return;
405 409 }
406 410 if(!scatterStyle.compare("star"))
407 411 {
408 412 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar);
409 413 return;
410 414 }
411 415 if(!scatterStyle.compare("triangle"))
412 416 {
413 417 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle);
414 418 return;
415 419 }
416 420 if(!scatterStyle.compare("invertedtriangle"))
417 421 {
418 422 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted);
419 423 return;
420 424 }
421 425 if(!scatterStyle.compare("crosssquare"))
422 426 {
423 427 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare);
424 428 return;
425 429 }
426 430 if(!scatterStyle.compare("plussquare"))
427 431 {
428 432 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare);
429 433 return;
430 434 }
431 435 if(!scatterStyle.compare("crosscircle"))
432 436 {
433 437 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle);
434 438 return;
435 439 }
436 440 if(!scatterStyle.compare("pluscircle"))
437 441 {
438 442 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle);
439 443 return;
440 444 }
441 445 if(!scatterStyle.compare("peace"))
442 446 {
443 447 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace);
444 448 return;
445 449 }
446 450
447 451 }
448 452 }
449 453
450 454 void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type)
451 455 {
452 456 this->m_plot->xAxis->setTickLabelType(type);
453 457 }
454 458
455 459 void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format)
456 460 {
457 461 this->m_plot->xAxis->setDateTimeFormat(format);
458 462 }
459 463
460 464
461 465
462 466
463 467
464 468 void SocExplorerPlot::keyPressEvent(QKeyEvent * event)
465 469 {
466 470 switch(event->key())
467 471 {
468 472 case Qt::Key_Control:
469 473 this->ctrl_hold = true;
470 474 setCursor(Qt::CrossCursor);
471 475 break;
472 476 case Qt::Key_Shift:
473 477 this->shift_hold = true;
474 478 break;
475 479 case Qt::Key_M:
476 480 this->rescaleAxis();
477 481 break;
478 482 case Qt::Key_Left:
479 483 if(!ctrl_hold)
480 484 {
481 485 move(-0.1,Qt::Horizontal);
482 486 }
483 487 else
484 488 {
485 489 zoom(2,this->width()/2,Qt::Horizontal);
486 490 }
487 491 break;
488 492 case Qt::Key_Right:
489 493 if(!ctrl_hold)
490 494 {
491 495 move(0.1,Qt::Horizontal);
492 496 }
493 497 else
494 498 {
495 499 zoom(0.5,this->width()/2,Qt::Horizontal);
496 500 }
497 501 break;
498 502 case Qt::Key_Up:
499 503 if(!ctrl_hold)
500 504 {
501 505 move(0.1,Qt::Vertical);
502 506 }
503 507 else
504 508 {
505 509 zoom(0.5,this->height()/2,Qt::Vertical);
506 510 }
507 511 break;
508 512 case Qt::Key_Down:
509 513 if(!ctrl_hold)
510 514 {
511 515 move(-0.1,Qt::Vertical);
512 516 }
513 517 else
514 518 {
515 519 zoom(2,this->height()/2,Qt::Vertical);
516 520 }
517 521 break;
518 522 default:
519 523 QWidget::keyPressEvent(event);
520 524 break;
521 525 }
522 526 }
523 527
524 528 void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event)
525 529 {
526 530 switch(event->key())
527 531 {
528 532 case Qt::Key_Control:
529 533 event->accept();
530 534 this->ctrl_hold = false;
531 535 break;
532 536 case Qt::Key_Shift:
533 537 event->accept();
534 538 this->shift_hold = false;
535 539 break;
536 540 default:
537 541 QWidget::keyReleaseEvent(event);
538 542 break;
539 543 }
540 544 setCursor(Qt::ArrowCursor);
541 545 }
542 546
543 547 void SocExplorerPlot::wheelEvent(QWheelEvent * event)
544 548 {
545 549 double factor;
546 550 double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
547 551 if(ctrl_hold)
548 552 {
549 553 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
550 554 {
551 555 setCursor(Qt::SizeVerCursor);
552 556 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
553 557 zoom(factor,event->pos().y(),Qt::Vertical);
554 558 }
555 559 QWidget::wheelEvent(event);
556 560 return;
557 561 }
558 562 if(shift_hold)
559 563 {
560 564 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
561 565 {
562 566 setCursor(Qt::SizeHorCursor);
563 567 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
564 568 zoom(factor,event->pos().x(),Qt::Horizontal);
565 569 }
566 570 QWidget::wheelEvent(event);
567 571 return;
568 572 }
569 573 move(wheelSteps,Qt::Horizontal);
570 574 QWidget::wheelEvent(event);
571 575 }
572 576
573 577
574 578
575 579
576 580 void SocExplorerPlot::mousePressEvent(QMouseEvent *event)
577 581 {
578 582 if(event->button()==Qt::LeftButton)
579 583 {
580 584 if(ctrl_hold)
581 585 {
582 586 setCursor(Qt::CrossCursor);
583 587 mOrigin = event->pos();
584 588 mRubberBand->setGeometry(QRect(mOrigin, QSize()));
585 589 mRubberBand->show();
586 590 }
587 591 else
588 592 {
589 593 setCursor(Qt::ClosedHandCursor);
590 594 mDragStart = event->pos();
591 595 this->mouse_hold = true;
592 596 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
593 597 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
594 598 }
595 599 }
596 600 QWidget::mousePressEvent(event);
597 601 }
598 602
599 603 void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event)
600 604 {
601 605 if(event->button()==Qt::LeftButton)
602 606 {
603 607 this->mouse_hold = false;
604 608 }
605 609 if (mRubberBand->isVisible())
606 610 {
607 611 const QRect & zoomRect = mRubberBand->geometry();
608 612 int xp1, yp1, xp2, yp2;
609 613 zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
610 614 double x1 = this->m_plot->xAxis->pixelToCoord(xp1);
611 615 double x2 = this->m_plot->xAxis->pixelToCoord(xp2);
612 616 double y1 = this->m_plot->yAxis->pixelToCoord(yp1);
613 617 double y2 = this->m_plot->yAxis->pixelToCoord(yp2);
614 618
615 619 this->m_plot->xAxis->setRange(x1, x2);
616 620 this->m_plot->yAxis->setRange(y1, y2);
617 621
618 622 mRubberBand->hide();
619 623 this->m_plot->replot();
620 624 }
621 625 setCursor(Qt::ArrowCursor);
622 626 QWidget::mouseReleaseEvent(event);
623 627 }
624 628
625 629 void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation)
626 630 {
627 631 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation);
628 632 axis->scaleRange(factor, axis->pixelToCoord(center));
629 633 this->m_plot->replot();
630 634 }
631 635
632 636 void SocExplorerPlot::move(double factor, Qt::Orientation orientation)
633 637 {
634 638 QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation);
635 639 // double rg = (axis->range().upper - axis->range().lower)*(factor);
636 640 // axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
637 641 double rg =0.0;
638 642 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
639 643 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
640 644 if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear)
641 645 {
642 646 rg = (axis->range().upper - axis->range().lower)*(factor/10);
643 647 axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
644 648 }
645 649 else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic)
646 650 {
647 651 // rg = (axis->range().upper / axis->range().lower)*(factor/100);
648 652 int start,stop;
649 653 double diff;
650 654 if(factor>0.0)
651 655 {
652 656 stop =this->width()*factor/10;
653 657 start = 2*this->width()*factor/10;
654 658 }
655 659 if(factor<0.0)
656 660 {
657 661 factor*=-1.0;
658 662 start =this->width()*factor/10;
659 663 stop = 2*this->width()*factor/10;
660 664 }
661 665 diff = axis->pixelToCoord(start) / axis->pixelToCoord(stop);
662 666 axis->setRange(this->m_plot->axisRect()->rangeDragAxis(orientation)->range().lower*diff, this->m_plot->axisRect()->rangeDragAxis(orientation)->range().upper*diff);
663 667 }
664 668 this->m_plot->replot();
665 669 }
666 670
667 671
668 672 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
669 673 {
670 674 if(mouse_hold)
671 675 {
672 676 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
673 677 QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
674 678 // double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) / rangeDragHorzAxis->pixelToCoord(event->pos().x());
675 679 // rangeDragHorzAxis->setRange(mDragStartHorzRange.lower*diff, mDragStartHorzRange.upper*diff);
676 680 double diff=0;
677 681 if(this->m_plot->xAxis->scaleType() == QCPAxis::stLinear)
678 682 {
679 683 diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x());
680 684 Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff);
681 685 }
682 686 else if(this->m_plot->xAxis->scaleType() == QCPAxis::stLogarithmic)
683 687 {
684 688 diff = Haxis->pixelToCoord(mDragStart.x()) / Haxis->pixelToCoord(event->pos().x());
685 689 Haxis->setRange(DragStartHorzRange.lower*diff, DragStartHorzRange.upper*diff);
686 690 }
687 691 if(this->m_plot->yAxis->scaleType() == QCPAxis::stLinear)
688 692 {
689 693 diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y());
690 694 Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff);
691 695 }
692 696 else if(this->m_plot->yAxis->scaleType() == QCPAxis::stLogarithmic)
693 697 {
694 698 diff = Vaxis->pixelToCoord(mDragStart.y()) / Vaxis->pixelToCoord(event->pos().y());
695 699 Vaxis->setRange(DragStartVertRange.lower*diff, DragStartVertRange.upper*diff);
696 700 }
697 701 this->m_plot->replot();
698 702 }
699 703 if (mRubberBand->isVisible())
700 704 {
701 705 mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized());
702 706 }
703 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 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef SOCEXPLORERPLOT_H
23 23 #define SOCEXPLORERPLOT_H
24 24
25 25 #include <QWidget>
26 26 #include <QGridLayout>
27 27 #include <qcustomplot.h>
28 28 #include <qcustomplotvect.h>
29 29 #include <QRubberBand>
30 30 #include <QPoint>
31 31
32 32 class SocExplorerPlotActions : public QAction
33 33 {
34 34 Q_OBJECT
35 35 public:
36 36 SocExplorerPlotActions(const QString &text,int PID,QObject* parent=0)
37 37 :QAction(text,parent)
38 38 {
39 39 setPID(PID);
40 40 connect(this,SIGNAL(triggered()),this,SLOT(trigger()));
41 41 }
42 42 SocExplorerPlotActions(const QIcon &icon, const QString &text,int PID, QObject* parent)
43 43 :QAction(icon,text,parent)
44 44 {
45 45 setPID(PID);
46 46 connect(this,SIGNAL(triggered()),this,SLOT(trigger()));
47 47 }
48 48 ~SocExplorerPlotActions(){}
49 49 void setPID(int PID){this->m_PID=PID;}
50 50 int PID(){return m_PID;}
51 51 private slots:
52 52 void trigger(){emit triggered(m_PID);}
53 53 signals:
54 54 void triggered(int PID);
55 55 private:
56 56 int m_PID;
57 57 };
58 58
59 59 class SocExplorerPlot : public QWidget
60 60 {
61 61 Q_OBJECT
62 62 public:
63 63 explicit SocExplorerPlot(QWidget *parent = 0);
64 64 ~SocExplorerPlot();
65 65 void setTitle(QString title);
66 66 const QString& title();
67 67 void setXaxisLabel(QString label);
68 68 void setXaxisLog();
69 69 void setXaxisRange(double lower, double upper);
70 70 void setYaxisLabel(QString label);
71 71 void setYaxisLog();
72 72 void setYaxisRange(double lower, double upper);
73 73 void rescaleAxis();
74 74 void setLegendFont(QFont font);
75 75 void setLegendSelectedFont(QFont font);
76 76 void setAdaptativeSampling(int graphIndex,bool enable);
77 77 void setUseFastVector(int graphIndex,bool enable);
78 78 int addGraph();
79 79 bool removeGraph(int graphIndex);
80 80 int graphCount();
81 81 void removeAllGraphs();
82 82 void setGraphName(int graphIndex,QString name);
83 83 const QString& graphName(int graphIndex);
84 84 void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
85 85 void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true);
86 86 void setGraphData(int graphIndex, QVector<QCPData> *data, bool replot);
87 87 void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
88 88 void addGraphData(int graphIndex, QVariant x, QVariant y);
89 89 void setGraphPen(int graphIndex,QPen pen);
90 90 QPen getGraphPen(int graphIndex);
91 91 void setGraphLineStyle(int graphIndex,QString lineStyle);
92 92 void setGraphScatterStyle(int graphIndex,QString scatterStyle);
93 93 void setXaxisTickLabelType(QCPAxis::LabelType type);
94 94 void setXaxisDateTimeFormat(const QString &format);
95 95 void show();
96 96 void replot();
97 97 void exportToSVG(const QString& fileName);
98 98 void exportToPDF(const QString& fileName);
99 99 void addAction(SocExplorerPlotActions* action);
100 100 int PID(){return m_PID;}
101 101 void setPID(int PID){m_PID = PID;}
102 102 QVector<QCPData>* getVisibleData(int graphIndex);
103 103 signals:
104 104 void titleChanged(const QString& newTitle);
105 105 public slots:
106 106
107 107 protected:
108 108 void keyPressEvent(QKeyEvent *);
109 109 void keyReleaseEvent(QKeyEvent *);
110 110 void wheelEvent(QWheelEvent *);
111 111 void mousePressEvent(QMouseEvent *);
112 112 void mouseMoveEvent(QMouseEvent *);
113 113 void mouseReleaseEvent(QMouseEvent *);
114 114
115 115 private:
116 116 void zoom(double factor, int center, Qt::Orientation orientation);
117 117 void move(double factor, Qt::Orientation orientation);
118 118 QCustomPlotVect* m_plot;
119 119 QGridLayout* m_mainlayout;
120 120 bool ctrl_hold;
121 121 bool shift_hold;
122 122 bool mouse_hold;
123 123 QCPRange DragStartHorzRange;
124 124 QCPRange DragStartVertRange;
125 125 QPoint mDragStart;
126 126 bool mZoomMode;
127 127 QRubberBand * mRubberBand;
128 128 QPoint mOrigin;
129 129 QList<SocExplorerPlotActions*> m_actions;
130 130 QString m_Title;
131 QCPPlotTitle* m_plotTitle;
131 132 int m_PID;
132 133 };
133 134
134 135 #endif // SOCEXPLORERPLOT_H
@@ -1,123 +1,124
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "mainwindow.h"
23 23 #include "ui_mainwindow.h"
24 24 #include <QFileDialog>
25 25 #include <QDir>
26 26 #include "qcustomplot.h"
27 27 #include <omp.h>
28 28 #include <QAction>
29 29 #include <downloadhistory.h>
30 30 #include <QDateTime>
31 31 #include <QDate>
32 32 #include <filedownloader.h>
33 33 #include <cassinitools.h>
34 34 #include <qlopplots.h>
35 35 #include <qlopdatabase.h>
36 36 #include <qlopsettings.h>
37 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 41 MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) :
47 42 QMainWindow(parent),
48 43 ui(new Ui::MainWindow)
49 44 {
50 45 this->OMP_THREADS = OMP_THREADS;
51 46 ui->setupUi(this);
52 47 QLopGUI::registerMenuBar(menuBar());
53 48 this->setWindowIcon(QIcon(":img/QLop.svg"));
54 49 this->progressWidget = new QWidget();
55 50 this->progressLayout = new QVBoxLayout(this->progressWidget);
56 51 this->progressWidget->setLayout(this->progressLayout);
57 52 this->progressWidget->setWindowModality(Qt::WindowModal);
58 53 progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
59 54 for(int i=0;i<OMP_THREADS;i++)
60 55 {
61 56 this->progress.append(new QProgressBar(this->progressWidget));
62 57 this->progress.last()->setMinimum(0);
63 58 this->progress.last()->setMaximum(100);
64 59 this->progressLayout->addWidget(this->progress.last());
65 60 this->progressWidget->hide();
66 61 this->progressThreadIds[i] = -1;
67 62 }
68 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 70 for(int i=0;i<ServicesToLoad.count();i++)
70 71 {
71 72 qDebug()<<ServicesToLoad.at(i)->serviceName();
72 73 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
73 74 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
74 75 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
75 76 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
76 77 }
77 78 }
78 79
79 80 MainWindow::~MainWindow()
80 81 {
81 82 delete ui;
82 83 }
83 84
84 85 void MainWindow::updateProgress(int threadId, int percentProgress)
85 86 {
86 87 bool updated=false;
87 88 for(int i=0;i<OMP_THREADS;i++)
88 89 {
89 90 if(progressThreadIds[i]==threadId)
90 91 {
91 92 if(threadId<this->progress.count())
92 93 {
93 94 this->progress.at(i)->setValue(percentProgress);
94 95 updated=true;
95 96 }
96 97 }
97 98 }
98 99 if(Q_UNLIKELY(updated==false))
99 100 {
100 101 for(int i=0;i<OMP_THREADS;i++)
101 102 {
102 103 if(progressThreadIds[i]==-1)
103 104 {
104 105 progressThreadIds[i] = threadId;
105 106 updateProgress(threadId,percentProgress);
106 107 return;
107 108 }
108 109 }
109 110 }
110 111 }
111 112
112 113
113 114 void MainWindow::changeEvent(QEvent *e)
114 115 {
115 116 QMainWindow::changeEvent(e);
116 117 switch (e->type()) {
117 118 case QEvent::LanguageChange:
118 119 ui->retranslateUi(this);
119 120 break;
120 121 default:
121 122 break;
122 123 }
123 124 }
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now