##// 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
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,237
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22
23 #include "filedownloader.h"
24 #include <QFile>
25 #include <QIcon>
26 #include <qlopsettings.h>
27 #include <QHostInfo>
28
29 FileDownloader* FileDownloader::_self=NULL;
30 QNetworkAccessManager* FileDownloader::m_WebCtrl=NULL;
31 QList<FileDownloaderTask*>* FileDownloader::m_pendingTasks=NULL;
32 QDockWidget* FileDownloader::m_gui=NULL;
33 DownLoadHistory* FileDownloader::m_DownLoadHistory=NULL;
34 FileDowloaderSettingsGUI* FileDownloader::m_SettingsGui=NULL;
35 QLopNetworkProxyFactory* FileDownloader::m_ProxyFactory=NULL;
36
37 #define _INIT if(Q_UNLIKELY(_self==NULL)){ init();}
38
39
40
41 int FileDownloader::downloadFile(QUrl fileUrl, const QString &name)
42 {
43 _INIT
44 if(QFile::exists(name)|| QFile::exists(name+".part"))
45 {
46 return -1;
47 }
48 int ID=_self->getTaskId();
49 if(ID!=-1)
50 {
51 QNetworkRequest request(fileUrl);
52 QNetworkReply* reply = m_WebCtrl->head(request);
53 if(reply && (reply->error()==QNetworkReply::NoError))
54 {
55 FileDownloaderTask*task=new FileDownloaderTask(reply,ID,name,_self);
56 m_pendingTasks->append(task);
57 connect(task, SIGNAL(gotHead(FileDownloaderTask*,QNetworkReply*)), _self, SLOT(gotHead(FileDownloaderTask*,QNetworkReply*)));
58 if(!_self->m_noGui)
59 {
60 m_DownLoadHistory->addElement(new DownloadHistoryElement(task));
61 }
62 }
63 else
64 {
65 return -1;
66 }
67 }
68 return ID;
69 }
70
71 int FileDownloader::downloadFile(QString fileUrl, const QString &name)
72 {
73 return downloadFile(QUrl(fileUrl),name);
74 }
75
76 QDockWidget *FileDownloader::getGUI()
77 {
78 if(!_self->m_noGui && (m_gui==NULL))
79 {
80 m_DownLoadHistory=new DownLoadHistory();
81 m_gui=new QDockWidget("Download History");
82 m_gui->setWidget(m_DownLoadHistory);
83 m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
84 m_SettingsGui = new FileDowloaderSettingsGUI();
85 QLopSettings::registerConfigEntry(this->m_SettingsGui,QIcon(":/img/Gnome-emblem-downloads.svg"),"Qlop Downloader");
86 }
87 return (QDockWidget*) m_gui;
88 }
89
90 const QString &FileDownloader::serviceName()
91 {
92 return m_serviceName;
93 }
94
95 int FileDownloader::download_file(QUrl fileUrl, const QString &name)
96 {
97 return downloadFile(fileUrl,name);
98 }
99
100 int FileDownloader::download_file(QString fileUrl, const QString &name)
101 {
102 return downloadFile(fileUrl,name);
103 }
104
105 void FileDownloader::gotHead(FileDownloaderTask* task,QNetworkReply* headerreply)
106 {
107 QNetworkReply* reply;
108 QByteArray rangeHeaderValue;
109 bool acceptRestart=false;
110 int DownloadTotalFileSize = headerreply->header(QNetworkRequest::ContentLengthHeader).toInt();
111 if (headerreply->hasRawHeader("Accept-Ranges"))
112 {
113 QString qstrAcceptRanges = headerreply->rawHeader("Accept-Ranges");
114 acceptRestart = (qstrAcceptRanges.compare("bytes", Qt::CaseInsensitive) == 0);
115 rangeHeaderValue = "bytes=" + QByteArray::number(task->startPosition()) + "-";
116 if (DownloadTotalFileSize > 0)
117 {
118 rangeHeaderValue += QByteArray::number(DownloadTotalFileSize);
119 }
120 }
121 QNetworkRequest request(headerreply->request());
122 delete headerreply;
123 request.setRawHeader("Connection", "Keep-Alive");
124 if(acceptRestart)
125 request.setRawHeader("Range", rangeHeaderValue);
126 request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
127 reply = m_WebCtrl->get(request);
128 task->restart(reply,acceptRestart);
129 }
130
131 void FileDownloader::configureProxy()
132 {
133 // QString proxyType = QLopSettings::value(FileDownloader::self(),"proxy/type","none").toString();
134 // if(proxyType=="none")
135 // {
136 // QNetworkProxy proxy;
137 // proxy.setType(QNetworkProxy::Socks5Proxy);
138 // proxy.setHostName("proxy.example.com");
139 // proxy.setPort(1080);
140 // proxy.setUser("username");
141 // proxy.setPassword("password");
142 // QNetworkProxy::setApplicationProxy(proxy);
143 // }
144 // QNetworkProxyQuery q(QUrl(QLatin1String("http://www.google.com")));
145 // QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(q);
146 // foreach ( QNetworkProxy loopItem, proxies ) {
147 // qDebug() << "proxyUsed:" << loopItem.hostName();
148 // }
149 // if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy )
150 // QNetworkProxy::setApplicationProxy(proxies[0]);
151 // else
152 // qDebug("No proxy server selected");
153 }
154
155 FileDownloaderTask* FileDownloader::getDownloadTask(int ID)
156 {
157 _INIT
158 for(int i=0;i<m_pendingTasks->count();i++)
159 {
160 if(m_pendingTasks->at(i)->ID()==ID)
161 return m_pendingTasks->at(i);
162 }
163 return NULL;
164 }
165
166 bool FileDownloader::taskIsCompleted(int ID)
167 {
168 return getDownloadTask(ID)->downloadComplete();
169 }
170
171 FileDownloader *FileDownloader::self()
172 {
173 _INIT
174
175 return _self;
176
177 }
178
179 void FileDownloader::reloadConfig()
180 {
181 m_ProxyFactory->reloadConfig();
182 }
183
184 int FileDownloader::getTaskId()
185 {
186 for(unsigned int i=0;i<INT_MAX;i++)
187 {
188 bool idValid=true;
189 for(int j=0;j<m_pendingTasks->count();j++)
190 {
191 if(m_pendingTasks->at(j)->ID()==(int)i)
192 idValid=false;
193 }
194 if(idValid)
195 return (int)i;
196 }
197 return -1;
198 }
199
200 void FileDownloader::init(bool noGUI, QObject *parent)
201 {
202 if(Q_UNLIKELY(_self==NULL))
203 {
204 _self=new FileDownloader(noGUI,parent);
205 _self->reloadConfig();
206 }
207 }
208 /*for gnome:
209 *
210 * gsettings list-recursively org.gnome.system.proxy
211 * gsettings get org.gnome.system.proxy.http host
212 *
213 * To detect desktop $XDG_CURRENT_DESKTOP
214 */
215 FileDownloader::FileDownloader(bool noGUI,QObject *parent) : QLopService(parent)
216 {
217 m_ProxyFactory = new QLopNetworkProxyFactory();
218 // configureProxy();
219 m_WebCtrl = new QNetworkAccessManager(this);
220 m_WebCtrl->setProxyFactory(m_ProxyFactory);
221 m_pendingTasks = new QList<FileDownloaderTask*>();
222 m_noGui=noGUI;
223 m_serviceName="FileDownloader";
224 }
225
226 FileDownloader::~FileDownloader()
227 {
228 if(!m_noGui)
229 delete m_gui;
230 while (m_pendingTasks->count())
231 {
232 FileDownloaderTask* task=m_pendingTasks->last();
233 m_pendingTasks->removeLast();
234 delete task;
235 }
236 delete m_WebCtrl;
237 }
@@ -0,0 +1,78
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22
23 #ifndef FILEDOWNLOADER_H
24 #define FILEDOWNLOADER_H
25
26 #include <QObject>
27 #include <QNetworkAccessManager>
28 #include <QNetworkReply>
29 #include <QNetworkProxy>
30 #include <QList>
31 #include <QHash>
32 #include <filedownloadertask.h>
33 #include <downloadhistory.h>
34 #include <qlopservice.h>
35 #include <QDockWidget>
36 #include <filedowloadersettingsgui.h>
37 #include <qlopsettings.h>
38 #include <QHostAddress>
39 #include <qlopnetworkproxyfactory.h>
40
41 class FileDownloader : public QLopService
42 {
43 Q_OBJECT
44 private:
45 static FileDownloader* _self;
46 static QNetworkAccessManager* m_WebCtrl;
47 static QList<FileDownloaderTask*>* m_pendingTasks;
48 static DownLoadHistory* m_DownLoadHistory;
49 static QDockWidget* m_gui;
50 static QLopNetworkProxyFactory* m_ProxyFactory;
51 static FileDowloaderSettingsGUI* m_SettingsGui;
52 FileDownloader(bool noGUI=false,QObject *parent = 0);
53 ~FileDownloader();
54
55 public:
56 static void init(bool noGUI=false,QObject *parent = 0);
57 static int downloadFile(QUrl fileUrl,const QString& name);
58 static int downloadFile(QString fileUrl,const QString& name);
59 static FileDownloaderTask *getDownloadTask(int ID);
60 static bool taskIsCompleted(int ID);
61 static FileDownloader *self();
62 void reloadConfig();
63 // QLopService methodes
64 QDockWidget* getGUI();
65 const QString& serviceName();
66 signals:
67
68 public slots:
69 int download_file(QUrl fileUrl,const QString& name);
70 int download_file(QString fileUrl,const QString& name);
71 private slots:
72 void gotHead(FileDownloaderTask *task, QNetworkReply *headerreply);
73 private:
74 void configureProxy();
75 int getTaskId();
76 };
77
78 #endif // FILEDOWNLOADER_H
@@ -0,0 +1,97
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22
23 #include "filedownloadertask.h"
24
25 FileDownloaderTask::FileDownloaderTask(QNetworkReply *headerreply, int ID, const QString &fileName, QObject *parent)
26 : QObject(parent),p_acceptRestart(false)
27 {
28 this->m_Reply = headerreply;
29 this->m_downloadComplete = false;
30 this->m_FileName = fileName;
31 this->m_taskId = ID;
32 this->m_file = new QFile(fileName+".part");
33 this->m_file->open(QIODevice::WriteOnly|QIODevice::Append);
34 this->m_startPos = this->m_file->size();
35 this->m_startDateTime = QDateTime::currentDateTime();
36 this->m_URL = m_Reply->url().toString();
37 connect(this->m_Reply,SIGNAL(finished()),this,SLOT(gotHead()));
38 }
39
40 FileDownloaderTask::~FileDownloaderTask()
41 {
42 delete m_file;
43 delete m_Reply;
44 }
45
46 int FileDownloaderTask::ID(){return m_taskId;}
47
48 const QString &FileDownloaderTask::fileName(){return m_FileName;}
49
50 const QString &FileDownloaderTask::url(){return m_URL;}
51
52 const QDateTime &FileDownloaderTask::startDateTime(){return m_startDateTime;}
53
54 bool FileDownloaderTask::downloadComplete(){return m_downloadComplete;}
55
56 void FileDownloaderTask::restart(QNetworkReply *reply, bool acceptRestart)
57 {
58 if(!acceptRestart)
59 this->m_file->seek(0);
60 this->p_acceptRestart = acceptRestart;
61 this->m_Reply = reply;
62 connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64)));
63 connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SIGNAL(updateProgress(qint64,qint64)));
64 connect(this->m_Reply,SIGNAL(readyRead()),this,SLOT(readReady()));
65 connect(this->m_Reply,SIGNAL(finished()),this,SLOT(downloadFinished()));
66 }
67
68 int FileDownloaderTask::startPosition()
69 {
70 return m_startPos;
71 }
72
73 void FileDownloaderTask::gotHead()
74 {
75 emit gotHead(this,m_Reply);
76 }
77
78
79 void FileDownloaderTask::downloadProgress(qint64 bytesSent, qint64 bytesTotal)
80 {
81 if(bytesTotal!=0)
82 emit updateProgress((100*bytesSent)/bytesTotal);
83 }
84
85 void FileDownloaderTask::readReady()
86 {
87 this->m_file->write(this->m_Reply->readAll());
88 }
89
90 void FileDownloaderTask::downloadFinished()
91 {
92 this->m_downloadComplete = true;
93 this->m_file->write(this->m_Reply->readAll());
94 this->m_file->close();
95 this->m_file->rename(this->m_FileName);
96 }
97
@@ -0,0 +1,73
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22
23 #ifndef FILEDOWNLOADERTASK_H
24 #define FILEDOWNLOADERTASK_H
25
26 #include <QObject>
27 #include <QByteArray>
28 #include <QNetworkAccessManager>
29 #include <QNetworkRequest>
30 #include <QNetworkReply>
31 #include <QFile>
32 #include <QDateTime>
33
34 // TODO add download speed and remaining time.
35
36 class FileDownloaderTask : public QObject
37 {
38 Q_OBJECT
39 public:
40 explicit FileDownloaderTask(QNetworkReply* headerreply, int ID, const QString& fileName, QObject *parent = 0);
41 ~FileDownloaderTask();
42 int ID();
43 const QString& fileName();
44 const QString& url();
45 const QDateTime& startDateTime();
46 bool downloadComplete();
47 void restart(QNetworkReply* reply,bool acceptRestart=false);
48 int startPosition();
49 signals:
50 void updateProgress(int percent);
51 void updateProgress(qint64 bytesSent, qint64 bytesTotal);
52 void gotHead(FileDownloaderTask* task,QNetworkReply* headerreply);
53 public slots:
54
55 private slots:
56 void gotHead();
57 void downloadProgress(qint64 bytesSent, qint64 bytesTotal);
58 void readReady();
59 void downloadFinished();
60 private:
61 int m_taskId;
62 QNetworkReply* m_Reply;
63 QByteArray m_DownloadedData;
64 bool m_downloadComplete;
65 QFile* m_file;
66 QString m_FileName;
67 QString m_URL;
68 QDateTime m_startDateTime;
69 int m_startPos;
70 bool p_acceptRestart;
71 };
72
73 #endif // FILEDOWNLOADERTASK_H
This diff has been collapsed as it changes many lines, (693 lines changed) Show them Hide them
@@ -0,0 +1,693
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22 // based on Based on qt-examples: https://gitorious.org/qt-examples/qt-examples/blobs/master/pac-files
23 // and also KDE's KIO kpac source code: https://projects.kde.org/projects/frameworks/kio/repository/revisions/master/show/src/kpac
24 // specially https://projects.kde.org/projects/frameworks/kio/repository/revisions/master/entry/src/kpac/script.cpp
25
26 #include "proxypacparser.h"
27 #include <QHostAddress>
28 #include <QHostInfo>
29 #include <QNetworkInterface>
30 #include <QDateTime>
31
32
33 class Address
34 {
35 public:
36 struct Error {};
37 static Address resolve(const QString &host)
38 {
39 return Address(host);
40 }
41
42 QList<QHostAddress> addresses() const
43 {
44 return m_addressList;
45 }
46
47 QHostAddress address() const
48 {
49 if (m_addressList.isEmpty()) {
50 return QHostAddress();
51 }
52
53 return m_addressList.first();
54 }
55
56 private:
57 Address(const QString &host)
58 {
59 // Always try to see if it's already an IP first, to avoid Qt doing a
60 // needless reverse lookup
61 QHostAddress address(host);
62 if (address.isNull()) {
63 QHostInfo hostInfo;
64 if (hostInfo.hostName().isEmpty() || hostInfo.error() != QHostInfo::NoError) {
65 hostInfo = QHostInfo::fromName(host);
66 }
67 m_addressList = hostInfo.addresses();
68 } else {
69 m_addressList.clear();
70 m_addressList.append(address);
71 }
72 }
73
74 QList<QHostAddress> m_addressList;
75 };
76
77 ProxyPacParser::ProxyPacParser(QObject *parent)
78 {
79 engine = new QScriptEngine(this);
80 QScriptValue globalObject = engine->globalObject();
81
82 globalObject.setProperty(QString("isPlainHostName"), engine->newFunction(isPlainHostName));
83 globalObject.setProperty(QString("dnsDomainIs"), engine->newFunction(dnsDomainIs));
84 globalObject.setProperty(QString("localHostOrDomainIs"), engine->newFunction(localHostOrDomainIs));
85 globalObject.setProperty(QString("isResolvable"), engine->newFunction(isResolvable));
86 globalObject.setProperty(QString("isInNet"), engine->newFunction(isInNet));
87
88 //Related utility functions:
89 globalObject.setProperty(QString("dnsResolve"), engine->newFunction(dnsResolve));
90 globalObject.setProperty(QString("myIpAddress"), engine->newFunction(myIpAddress));
91 globalObject.setProperty(QString("dnsDomainLevels"), engine->newFunction(dnsDomainLevels));
92
93 //URL/hostname based conditions:
94 globalObject.setProperty(QString("shExpMatch"), engine->newFunction(shExpMatch));
95
96 // Time based conditions:
97 globalObject.setProperty(QString("weekdayRange"), engine->newFunction(weekdayRange));
98 globalObject.setProperty(QString("dateRange"), engine->newFunction(dateRange));
99 globalObject.setProperty(QString("timeRange"), engine->newFunction(timeRange));
100
101 //Implementation of Microsoft's IPv6 Extension for PAC
102 globalObject.setProperty(QString("isResolvableEx"), engine->newFunction(isResolvableEx));
103 globalObject.setProperty(QString("isInNetEx"), engine->newFunction(isInNetEx));
104 globalObject.setProperty(QString("dnsResolveEx"), engine->newFunction(dnsResolveEx));
105 globalObject.setProperty(QString("myIpAddressEx"), engine->newFunction(myIpAddressEx));
106 globalObject.setProperty(QString("sortIpAddressList"), engine->newFunction(sortIpAddressList));
107
108
109 }
110
111 ProxyPacParser::~ProxyPacParser()
112 {
113 // delete engine;
114 }
115
116 void ProxyPacParser::setPacFile(const QString &fileContent)
117 {
118 engine->evaluate(fileContent);
119 }
120
121 QString ProxyPacParser::findProxyForUrl(const QString &url, const QString &host)
122 {
123 QScriptValue global = engine->globalObject();
124 QScriptValue fun = global.property("FindProxyForURL");
125 if ( !fun.isFunction() ) {
126 return QString("DIRECT");
127 }
128
129 QScriptValueList args;
130 args << engine->toScriptValue( url ) << engine->toScriptValue( host );
131
132 QScriptValue val = fun.call( global, args );
133
134 return val.toString();
135 }
136
137 template <typename T>
138 static bool checkRange(T value, T min, T max)
139 {
140 return ((min <= max && value >= min && value <= max) ||
141 (min > max && (value <= min || value >= max)));
142 }
143
144
145 static bool isLocalHostAddress(const QHostAddress &address)
146 {
147 if (address == QHostAddress::LocalHost) {
148 return true;
149 }
150
151 if (address == QHostAddress::LocalHostIPv6) {
152 return true;
153 }
154
155 return false;
156 }
157
158 static bool isIPv6Address(const QHostAddress &address)
159 {
160 return address.protocol() == QAbstractSocket::IPv6Protocol;
161 }
162
163 static bool isIPv4Address(const QHostAddress &address)
164 {
165 return (address.protocol() == QAbstractSocket::IPv4Protocol);
166 }
167
168 static bool isSpecialAddress(const QHostAddress &address)
169 {
170 // Catch all the special addresses and return false.
171 if (address == QHostAddress::Null) {
172 return true;
173 }
174
175 if (address == QHostAddress::Any) {
176 return true;
177 }
178
179 if (address == QHostAddress::AnyIPv6) {
180 return true;
181 }
182
183 if (address == QHostAddress::Broadcast) {
184 return true;
185 }
186
187 return false;
188 }
189
190
191 static bool addressLessThanComparison(const QHostAddress &addr1, const QHostAddress &addr2)
192 {
193 if (addr1.protocol() == QAbstractSocket::IPv4Protocol &&
194 addr2.protocol() == QAbstractSocket::IPv4Protocol) {
195 return addr1.toIPv4Address() < addr2.toIPv4Address();
196 }
197
198 if (addr1.protocol() == QAbstractSocket::IPv6Protocol &&
199 addr2.protocol() == QAbstractSocket::IPv6Protocol) {
200 const Q_IPV6ADDR ipv6addr1 = addr1.toIPv6Address();
201 const Q_IPV6ADDR ipv6addr2 = addr2.toIPv6Address();
202 for (int i = 0; i < 16; ++i) {
203 if (ipv6addr1[i] != ipv6addr2[i]) {
204 return ((ipv6addr1[i] & 0xff) - (ipv6addr2[i] & 0xff));
205 }
206 }
207 }
208
209 return false;
210 }
211
212 static QString addressListToString(const QList<QHostAddress> &addressList,
213 const QHash<QString, QString> &actualEntryMap)
214 {
215 QString result;
216 Q_FOREACH (const QHostAddress &address, addressList) {
217 if (!result.isEmpty()) {
218 result += QLatin1Char(';');
219 }
220 result += actualEntryMap.value(address.toString());
221 }
222 return result;
223 }
224
225 const QDateTime ProxyPacParser::getTime(QScriptContext *context)
226 {
227 const QString tz = context->argument(context->argumentCount() - 1).toString();
228 if (tz.compare(QLatin1String("gmt"), Qt::CaseInsensitive) == 0) {
229 return QDateTime::currentDateTimeUtc();
230 }
231 return QDateTime::currentDateTime();
232 }
233
234 int ProxyPacParser::findString(const QString &s, const char *const *values)
235 {
236 int index = 0;
237 const QString lower = s.toLower();
238 for (const char *const *p = values; *p; ++p, ++index) {
239 if (s.compare(QLatin1String(*p), Qt::CaseInsensitive) == 0) {
240 return index;
241 }
242 }
243 return -1;
244 }
245
246 QScriptValue ProxyPacParser::myIpAddress(QScriptContext *context, QScriptEngine *engine)
247 {
248 if ( context->argumentCount() != 0 )
249 return context->throwError("myIpAddress takes no arguments");
250
251 foreach( QHostAddress address, QNetworkInterface::allAddresses() ) {
252 if ( address != QHostAddress::LocalHost
253 && address != QHostAddress::LocalHostIPv6 )
254 return QScriptValue( engine, address.toString() );
255 }
256
257 return engine->undefinedValue();
258 }
259
260 // dnsDomainLevels(host)
261 // @returns the number of dots ('.') in @p host
262 QScriptValue ProxyPacParser::dnsDomainLevels(QScriptContext *context, QScriptEngine *engine)
263 {
264 if (context->argumentCount() != 1) {
265 return engine->undefinedValue();
266 }
267 const QString host = context->argument(0).toString();
268 if (host.isNull()) {
269 return engine->toScriptValue(0);
270 }
271 return engine->toScriptValue(host.count(QLatin1Char('.')));
272 }
273
274 QScriptValue ProxyPacParser::isInNet(QScriptContext *context, QScriptEngine *engine)
275 {
276 if ( context->argumentCount() != 3 )
277 return context->throwError("isInNet takes three arguments");
278
279 QHostAddress addr( context->argument(0).toString() );
280 QHostAddress netaddr( context->argument(1).toString() );
281 QHostAddress netmask( context->argument(2).toString() );
282
283 if ( (netaddr.toIPv4Address() & netmask.toIPv4Address()) == (addr.toIPv4Address() & netmask.toIPv4Address()) )
284 return QScriptValue( engine, true );
285
286 return QScriptValue( engine, false );
287 }
288
289 QScriptValue ProxyPacParser::shExpMatch(QScriptContext *context, QScriptEngine *engine)
290 {
291 if ( context->argumentCount() != 2 )
292 return context->throwError("shExpMatch takes two arguments");
293
294 QRegExp re( context->argument(1).toString(), Qt::CaseSensitive, QRegExp::Wildcard );
295 if ( re.exactMatch( context->argument(0).toString() ) )
296 return QScriptValue( engine, true );
297
298 return QScriptValue( engine, false );
299 }
300
301 // weekdayRange(day [, "GMT" ])
302 // weekdayRange(day1, day2 [, "GMT" ])
303 // @returns true if the current day equals day or between day1 and day2 resp.
304 // If the last argument is "GMT", GMT timezone is used, otherwise local time
305 QScriptValue ProxyPacParser::weekdayRange(QScriptContext *context, QScriptEngine *engine)
306 {
307 if (context->argumentCount() < 1 || context->argumentCount() > 3) {
308 return engine->undefinedValue();
309 }
310
311 static const char *const days[] = { "sun", "mon", "tue", "wed", "thu", "fri", "sat", 0 };
312
313 const int d1 = findString(context->argument(0).toString(), days);
314 if (d1 == -1) {
315 return engine->undefinedValue();
316 }
317
318 int d2 = findString(context->argument(1).toString(), days);
319 if (d2 == -1) {
320 d2 = d1;
321 }
322
323 // Adjust the days of week coming from QDateTime since it starts
324 // counting with Monday as 1 and ends with Sunday as day 7.
325 int dayOfWeek = getTime(context).date().dayOfWeek();
326 if (dayOfWeek == 7) {
327 dayOfWeek = 0;
328 }
329 return engine->toScriptValue(checkRange(dayOfWeek, d1, d2));
330 }
331
332 // dateRange(day [, "GMT" ])
333 // dateRange(day1, day2 [, "GMT" ])
334 // dateRange(month [, "GMT" ])
335 // dateRange(month1, month2 [, "GMT" ])
336 // dateRange(year [, "GMT" ])
337 // dateRange(year1, year2 [, "GMT" ])
338 // dateRange(day1, month1, day2, month2 [, "GMT" ])
339 // dateRange(month1, year1, month2, year2 [, "GMT" ])
340 // dateRange(day1, month1, year1, day2, month2, year2 [, "GMT" ])
341 // @returns true if the current date (GMT or local time according to
342 // presence of "GMT" as last argument) is within the given range
343 QScriptValue ProxyPacParser::dateRange(QScriptContext *context, QScriptEngine *engine)
344 {
345 if (context->argumentCount() < 1 || context->argumentCount() > 7) {
346 return engine->undefinedValue();
347 }
348
349 static const char *const months[] = { "jan", "feb", "mar", "apr", "may", "jun",
350 "jul", "aug", "sep", "oct", "nov", "dec", 0
351 };
352
353 QVector<int> values;
354 for (int i = 0; i < context->argumentCount(); ++i) {
355 int value = -1;
356 if (context->argument(i).isNumber()) {
357 value = context->argument(i).toInt32();
358 } else {
359 // QDate starts counting months from 1, so we add 1 here.
360 value = findString(context->argument(i).toString(), months) + 1;
361 }
362
363 if (value > 0) {
364 values.append(value);
365 } else {
366 break;
367 }
368 }
369
370 const QDate now = getTime(context).date();
371
372 // day1, month1, year1, day2, month2, year2
373 if (values.size() == 6) {
374 const QDate d1(values[2], values[1], values[0]);
375 const QDate d2(values[5], values[4], values[3]);
376 return engine->toScriptValue(checkRange(now, d1, d2));
377 }
378 // day1, month1, day2, month2
379 else if (values.size() == 4 && values[ 1 ] < 13 && values[ 3 ] < 13) {
380 const QDate d1(now.year(), values[1], values[0]);
381 const QDate d2(now.year(), values[3], values[2]);
382 return engine->toScriptValue(checkRange(now, d1, d2));
383 }
384 // month1, year1, month2, year2
385 else if (values.size() == 4) {
386 const QDate d1(values[1], values[0], now.day());
387 const QDate d2(values[3], values[2], now.day());
388 return engine->toScriptValue(checkRange(now, d1, d2));
389 }
390 // year1, year2
391 else if (values.size() == 2 && values[0] >= 1000 && values[1] >= 1000) {
392 return engine->toScriptValue(checkRange(now.year(), values[0], values[1]));
393 }
394 // day1, day2
395 else if (values.size() == 2 && context->argument(0).isNumber() && context->argument(1).isNumber()) {
396 return engine->toScriptValue(checkRange(now.day(), values[0], values[1]));
397 }
398 // month1, month2
399 else if (values.size() == 2) {
400 return engine->toScriptValue(checkRange(now.month(), values[0], values[1]));
401 }
402 // year
403 else if (values.size() == 1 && values[ 0 ] >= 1000) {
404 return engine->toScriptValue(checkRange(now.year(), values[0], values[0]));
405 }
406 // day
407 else if (values.size() == 1 && context->argument(0).isNumber()) {
408 return engine->toScriptValue(checkRange(now.day(), values[0], values[0]));
409 }
410 // month
411 else if (values.size() == 1) {
412 return engine->toScriptValue(checkRange(now.month(), values[0], values[0]));
413 }
414
415 return engine->undefinedValue();
416 }
417
418 // timeRange(hour [, "GMT" ])
419 // timeRange(hour1, hour2 [, "GMT" ])
420 // timeRange(hour1, min1, hour2, min2 [, "GMT" ])
421 // timeRange(hour1, min1, sec1, hour2, min2, sec2 [, "GMT" ])
422 // @returns true if the current time (GMT or local based on presence
423 // of "GMT" argument) is within the given range
424 QScriptValue ProxyPacParser::timeRange(QScriptContext *context, QScriptEngine *engine)
425 {
426 if (context->argumentCount() < 1 || context->argumentCount() > 7) {
427 return engine->undefinedValue();
428 }
429
430 QVector<int> values;
431 for (int i = 0; i < context->argumentCount(); ++i) {
432 if (!context->argument(i).isNumber()) {
433 break;
434 }
435 values.append(context->argument(i).toNumber());
436 }
437
438 const QTime now = getTime(context).time();
439
440 // hour1, min1, sec1, hour2, min2, sec2
441 if (values.size() == 6) {
442 const QTime t1(values[0], values[1], values[2]);
443 const QTime t2(values[3], values[4], values[5]);
444 return engine->toScriptValue(checkRange(now, t1, t2));
445 }
446 // hour1, min1, hour2, min2
447 else if (values.size() == 4) {
448 const QTime t1(values[0], values[1]);
449 const QTime t2(values[2], values[3]);
450 return engine->toScriptValue(checkRange(now, t1, t2));
451 }
452 // hour1, hour2
453 else if (values.size() == 2) {
454 return engine->toScriptValue(checkRange(now.hour(), values[0], values[1]));
455 }
456 // hour
457 else if (values.size() == 1) {
458 return engine->toScriptValue(checkRange(now.hour(), values[0], values[0]));
459 }
460
461 return engine->undefinedValue();
462 }
463
464 QScriptValue ProxyPacParser::dnsResolve(QScriptContext *context, QScriptEngine *engine)
465 {
466 if ( context->argumentCount() != 1 )
467 return context->throwError("dnsResolve takes one arguments");
468
469 QHostInfo info = QHostInfo::fromName( context->argument(0).toString() );
470 QList<QHostAddress> addresses = info.addresses();
471 if ( addresses.isEmpty() )
472 return engine->nullValue(); // TODO: Should this be undefined or an exception? check other implementations
473
474 return QScriptValue( engine, addresses.first().toString() );
475 }
476
477 QScriptValue ProxyPacParser::dnsDomainIs(QScriptContext *context, QScriptEngine *engine)
478 {
479 if ( context->argumentCount() != 2 )
480 return context->throwError("dnsDomainIs takes two arguments");
481
482 QHostInfo info = QHostInfo::fromName( context->argument(0).toString() );
483 QString domain = info.localDomainName();
484 QString argDomain = context->argument(1).toString();
485
486 if ( !domain.compare(argDomain) || !argDomain.compare("."+domain))
487 return QScriptValue( engine, true );
488 return QScriptValue( engine, false);
489 }
490
491 // localHostOrDomainIs(host, fqdn)
492 // @returns true if @p host is unqualified or equals @p fqdn
493 QScriptValue ProxyPacParser::localHostOrDomainIs(QScriptContext *context, QScriptEngine *engine)
494 {
495 if (context->argumentCount() != 2) {
496 return engine->undefinedValue();
497 }
498
499 const QString host = context->argument(0).toString();
500 if (!host.contains(QLatin1Char('.'))) {
501 return engine->toScriptValue(true);
502 }
503 const QString fqdn = context->argument(1).toString();
504 return engine->toScriptValue((host.compare(fqdn, Qt::CaseInsensitive) == 0));
505 }
506
507 // isResolvable(host)
508 // @returns true if host is resolvable to a IPv4 address.
509 QScriptValue ProxyPacParser::isResolvable(QScriptContext *context, QScriptEngine *engine)
510 {
511 if (context->argumentCount() != 1) {
512 return engine->undefinedValue();
513 }
514
515 try {
516 const Address info = Address::resolve(context->argument(0).toString());
517 bool hasResolvableIPv4Address = false;
518
519 Q_FOREACH (const QHostAddress &address, info.addresses()) {
520 if (!isSpecialAddress(address) && isIPv4Address(address)) {
521 hasResolvableIPv4Address = true;
522 break;
523 }
524 }
525
526 return engine->toScriptValue(hasResolvableIPv4Address);
527 } catch (const Address::Error &) {
528 return engine->toScriptValue(false);
529 }
530 }
531
532 // isPlainHostName(host)
533 // @returns true if @p host doesn't contains a domain part
534 QScriptValue ProxyPacParser::isPlainHostName(QScriptContext *context, QScriptEngine *engine)
535 {
536 if (context->argumentCount() != 1) {
537 return engine->undefinedValue();
538 }
539 return engine->toScriptValue(context->argument(0).toString().indexOf(QLatin1Char('.')) == -1);
540 }
541
542
543 // isResolvableEx(host)
544 // @returns true if host is resolvable to an IPv4 or IPv6 address.
545 QScriptValue ProxyPacParser::isResolvableEx(QScriptContext *context, QScriptEngine *engine)
546 {
547 if (context->argumentCount() != 1) {
548 return engine->undefinedValue();
549 }
550
551 try {
552 const Address info = Address::resolve(context->argument(0).toString());
553 bool hasResolvableIPAddress = false;
554 Q_FOREACH (const QHostAddress &address, info.addresses()) {
555 if (isIPv4Address(address) || isIPv6Address(address)) {
556 hasResolvableIPAddress = true;
557 break;
558 }
559 }
560 return engine->toScriptValue(hasResolvableIPAddress);
561 } catch (const Address::Error &) {
562 return engine->toScriptValue(false);
563 }
564 }
565
566 // isInNetEx(ipAddress, ipPrefix )
567 // @returns true if ipAddress is within the specified ipPrefix.
568 QScriptValue ProxyPacParser::isInNetEx(QScriptContext *context, QScriptEngine *engine)
569 {
570 if (context->argumentCount() != 2) {
571 return engine->undefinedValue();
572 }
573
574 try {
575 const Address info = Address::resolve(context->argument(0).toString());
576 bool isInSubNet = false;
577 const QString subnetStr = context->argument(1).toString();
578 const QPair<QHostAddress, int> subnet = QHostAddress::parseSubnet(subnetStr);
579
580 Q_FOREACH (const QHostAddress &address, info.addresses()) {
581 if (isSpecialAddress(address)) {
582 continue;
583 }
584
585 if (address.isInSubnet(subnet)) {
586 isInSubNet = true;
587 break;
588 }
589 }
590 return engine->toScriptValue(isInSubNet);
591 } catch (const Address::Error &) {
592 return engine->toScriptValue(false);
593 }
594 }
595
596
597 // dnsResolveEx(host)
598 // @returns a semi-colon delimited string containing IPv6 and IPv4 addresses
599 // for host or an empty string if host is not resolvable.
600 QScriptValue ProxyPacParser::dnsResolveEx(QScriptContext *context, QScriptEngine *engine)
601 {
602 if (context->argumentCount() != 1) {
603 return engine->undefinedValue();
604 }
605
606 try {
607 const Address info = Address::resolve(context->argument(0).toString());
608
609 QStringList addressList;
610 QString resolvedAddress(QLatin1String(""));
611
612 Q_FOREACH (const QHostAddress &address, info.addresses()) {
613 if (!isSpecialAddress(address)) {
614 addressList << address.toString();
615 }
616 }
617 if (!addressList.isEmpty()) {
618 resolvedAddress = addressList.join(QLatin1String(";"));
619 }
620
621 return engine->toScriptValue(resolvedAddress);
622 } catch (const Address::Error &) {
623 return engine->toScriptValue(QString(QLatin1String("")));
624 }
625 }
626
627 // myIpAddressEx()
628 // @returns a semi-colon delimited string containing all IP addresses for localhost (IPv6 and/or IPv4),
629 // or an empty string if unable to resolve localhost to an IP address.
630 QScriptValue ProxyPacParser::myIpAddressEx(QScriptContext *context, QScriptEngine *engine)
631 {
632 if (context->argumentCount()) {
633 return engine->undefinedValue();
634 }
635
636 QStringList ipAddressList;
637 const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
638 Q_FOREACH (const QHostAddress address, addresses) {
639 if (!isSpecialAddress(address) && !isLocalHostAddress(address)) {
640 ipAddressList << address.toString();
641 }
642 }
643
644 return engine->toScriptValue(ipAddressList.join(QLatin1String(";")));
645 }
646
647 // sortIpAddressList(ipAddressList)
648 // @returns a sorted ipAddressList. If both IPv4 and IPv6 addresses are present in
649 // the list. The sorted IPv6 addresses will precede the sorted IPv4 addresses.
650 QScriptValue ProxyPacParser::sortIpAddressList(QScriptContext *context, QScriptEngine *engine)
651 {
652 if (context->argumentCount() != 1) {
653 return engine->undefinedValue();
654 }
655
656 QHash<QString, QString> actualEntryMap;
657 QList<QHostAddress> ipV4List, ipV6List;
658 const QStringList ipAddressList = context->argument(0).toString().split(QLatin1Char(';'));
659
660 Q_FOREACH (const QString &ipAddress, ipAddressList) {
661 QHostAddress address(ipAddress);
662 switch (address.protocol()) {
663 case QAbstractSocket::IPv4Protocol:
664 ipV4List << address;
665 actualEntryMap.insert(address.toString(), ipAddress);
666 break;
667 case QAbstractSocket::IPv6Protocol:
668 ipV6List << address;
669 actualEntryMap.insert(address.toString(), ipAddress);
670 break;
671 default:
672 break;
673 }
674 }
675
676 QString sortedAddress(QLatin1String(""));
677
678 if (!ipV6List.isEmpty()) {
679 qSort(ipV6List.begin(), ipV6List.end(), addressLessThanComparison);
680 sortedAddress += addressListToString(ipV6List, actualEntryMap);
681 }
682
683 if (!ipV4List.isEmpty()) {
684 qSort(ipV4List.begin(), ipV4List.end(), addressLessThanComparison);
685 if (!sortedAddress.isEmpty()) {
686 sortedAddress += QLatin1Char(';');
687 }
688 sortedAddress += addressListToString(ipV4List, actualEntryMap);
689 }
690
691 return engine->toScriptValue(sortedAddress);
692
693 }
@@ -0,0 +1,89
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22 #ifndef PROXYPACPARSER_H
23 #define PROXYPACPARSER_H
24
25 #include <QObject>
26 #include <QScriptContext>
27 #include <QScriptEngine>
28
29 class ProxyPacParser : public QObject
30 {
31 Q_OBJECT
32 Q_PROPERTY( QString PacFile WRITE setPacFile )
33
34 public:
35 ProxyPacParser(QObject *parent = 0);
36 ~ProxyPacParser();
37 void setPacFile(const QString& fileContent);
38 Q_SCRIPTABLE QString findProxyForUrl( const QString &url, const QString &host );
39
40 signals:
41
42 public slots:
43 private:
44
45 //Hostname based conditions:
46 static QScriptValue isPlainHostName( QScriptContext *context, QScriptEngine *engine );
47 static QScriptValue dnsDomainIs( QScriptContext *context, QScriptEngine *engine );
48 static QScriptValue localHostOrDomainIs( QScriptContext *context, QScriptEngine *engine );
49 static QScriptValue isResolvable( QScriptContext *context, QScriptEngine *engine );
50 static QScriptValue isInNet( QScriptContext *context, QScriptEngine *engine );
51
52 //Related utility functions:
53 static QScriptValue dnsResolve( QScriptContext *context, QScriptEngine *engine );
54 static QScriptValue myIpAddress( QScriptContext *context, QScriptEngine *engine );
55 static QScriptValue dnsDomainLevels( QScriptContext *context, QScriptEngine *engine );
56
57 //URL/hostname based conditions:
58 static QScriptValue shExpMatch( QScriptContext *context, QScriptEngine *engine );
59
60 // Time based conditions:
61 static QScriptValue weekdayRange(QScriptContext *context, QScriptEngine *engine );
62 static QScriptValue dateRange(QScriptContext *context, QScriptEngine *engine );
63 static QScriptValue timeRange(QScriptContext *context, QScriptEngine *engine );
64
65 /*
66 * Implementation of Microsoft's IPv6 Extension for PAC
67 *
68 * Documentation:
69 * http://msdn.microsoft.com/en-us/library/gg308477(v=vs.85).aspx
70 * http://msdn.microsoft.com/en-us/library/gg308478(v=vs.85).aspx
71 * http://msdn.microsoft.com/en-us/library/gg308474(v=vs.85).aspx
72 * http://blogs.msdn.com/b/wndp/archive/2006/07/13/ipv6-pac-extensions-v0-9.aspx
73 *
74 * taken from KDE KIO kpac source code :)
75 */
76 static QScriptValue isResolvableEx(QScriptContext *context, QScriptEngine *engine);
77 static QScriptValue isInNetEx(QScriptContext *context, QScriptEngine *engine);
78 static QScriptValue dnsResolveEx(QScriptContext *context, QScriptEngine *engine);
79 static QScriptValue myIpAddressEx(QScriptContext *context, QScriptEngine *engine);
80 static QScriptValue sortIpAddressList(QScriptContext *context, QScriptEngine *engine);
81
82
83 QScriptEngine* engine;
84
85 static int findString(const QString &s, const char * const *values);
86 static const QDateTime getTime(QScriptContext *context);
87 };
88
89 #endif // PROXYPACPARSER_H
@@ -0,0 +1,171
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22 #include "qlopnetworkproxyfactory.h"
23 #include <QHostInfo>
24 #include <qlopsettings.h>
25 #include <filedownloader.h>
26
27 QLopNetworkProxyFactory::QLopNetworkProxyFactory()
28 :QNetworkProxyFactory()
29 {
30 p_pacParser = new ProxyPacParser();
31 }
32
33 QLopNetworkProxyFactory::~QLopNetworkProxyFactory()
34 {
35
36 }
37
38
39 QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query)
40 {
41 QList<QNetworkProxy> result;
42 switch (proxyCfgType)
43 {
44 case none:
45 result << QNetworkProxy(QNetworkProxy::NoProxy);
46 return result;
47 break;
48 case manual:
49 return queryProxy_manual(query);
50 break;
51 case system:
52 return queryProxy_system(query);
53 break;
54 case automatic:
55 return queryProxy_auto(query);
56 break;
57 default:
58 result << QNetworkProxy(QNetworkProxy::DefaultProxy);
59 return result;
60 break;
61 }
62 }
63
64
65 //should hanlde ignored hosts
66 QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy_manual(const QNetworkProxyQuery &query)
67 {
68 QList<QNetworkProxy> result;
69 QString scheme = query.url().scheme();
70 QHostInfo peerHost = QHostInfo::fromName(query.peerHostName());
71 if(scheme=="http")
72 {
73 result.append(p_http_proxy);
74 }
75 if(scheme=="https")
76 {
77 result.append(p_https_proxy);
78 }
79 if(scheme=="ftp")
80 {
81 result.append(p_ftp_proxy);
82 }
83 result << QNetworkProxy(QNetworkProxy::DefaultProxy);
84 return result;
85 }
86
87 QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy_system(const QNetworkProxyQuery &query)
88 {
89 QList<QNetworkProxy> result;
90 result << QNetworkProxy(QNetworkProxy::DefaultProxy);
91 return result;
92 }
93
94 QList<QNetworkProxy> QLopNetworkProxyFactory::queryProxy_auto(const QNetworkProxyQuery &query)
95 {
96 QList<QNetworkProxy> result;
97 QString config=p_pacParser->findProxyForUrl(query.url().toString(),QHostInfo::localHostName());
98 QStringList proxyList=config.split(";");
99 for(int i=0;i<proxyList.count();i++)
100 {
101 QStringList line = proxyList.at(i).split(" ");
102 if(line.count()>=2)
103 { //TODO check correct syntax for pac returned proxy cfg
104 if(line.at(0).compare("PROXY",Qt::CaseInsensitive))
105 {
106 QStringList proxyArgs=line.at(1).split(":");
107 if(proxyArgs.count()>=2)
108 {
109 result << QNetworkProxy(QNetworkProxy::HttpProxy,proxyArgs.at(0),proxyArgs.at(1).toUInt());
110 }
111 }
112 else if (line.at(0).compare("SOCKS",Qt::CaseInsensitive))
113 {
114 QStringList proxyArgs=line.at(1).split(":");
115 if(proxyArgs.count()>=2)
116 {
117 result << QNetworkProxy(QNetworkProxy::Socks5Proxy,proxyArgs.at(0),proxyArgs.at(1).toUInt());
118 }
119 }
120 else
121 {
122 result << QNetworkProxy(QNetworkProxy::NoProxy);
123 }
124 }
125 else
126 {
127 result << QNetworkProxy(QNetworkProxy::NoProxy);
128 }
129 }
130 return result;
131 }
132
133 void QLopNetworkProxyFactory::reloadConfig()
134 {
135 QString proxyType = QLopSettings::value(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,CFG_PROXY_TYPE_VALUE_NONE).toString();
136 if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_NONE))
137 {
138 this->proxyCfgType = none;
139 }
140 else
141 if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_MANUAL))
142 {
143 this->proxyCfgType = manual;
144 QString host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY).toString();
145 QString port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY).toString();
146 this->p_http_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt());
147
148 host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY).toString();
149 port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY).toString();
150 this->p_https_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt());
151
152 host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY).toString();
153 port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY).toString();
154 this->p_ftp_proxy = QNetworkProxy(QNetworkProxy::HttpProxy,host,port.toUInt());
155
156 host = QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY).toString();
157 port = QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY).toString();
158 this->p_socks_proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy,host,port.toUInt());
159
160 }
161 else
162 if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_SYSTEM))
163 {
164 this->proxyCfgType = system;
165 }
166 else
167 if(!proxyType.compare(CFG_PROXY_TYPE_VALUE_AUTOMATIC))
168 {
169 this->proxyCfgType = automatic;
170 }
171 }
@@ -0,0 +1,78
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
22 #ifndef QLOPNETWORKPROXYFACTORY_H
23 #define QLOPNETWORKPROXYFACTORY_H
24
25 #include <QObject>
26 #include <QNetworkProxyFactory>
27 #include <QHostAddress>
28 #include <proxypacparser.h>
29
30 #define CFG_PROXY_TYPE_ENTRY "proxy/type"
31 #define CFG_PROXY_TYPE_VALUE_NONE "none"
32 #define CFG_PROXY_TYPE_VALUE_MANUAL "manual"
33 #define CFG_PROXY_TYPE_VALUE_SYSTEM "system"
34 #define CFG_PROXY_TYPE_VALUE_AUTOMATIC "automatic"
35 #define CFG_PROXY_HTTP_HOST_ENTRY "proxy/http/host"
36 #define CFG_PROXY_HTTP_PORT_ENTRY "proxy/http/port"
37 #define CFG_PROXY_HTTPS_HOST_ENTRY "proxy/https/host"
38 #define CFG_PROXY_HTTPS_PORT_ENTRY "proxy/https/port"
39 #define CFG_PROXY_FTP_HOST_ENTRY "proxy/ftp/host"
40 #define CFG_PROXY_FTP_PORT_ENTRY "proxy/ftp/port"
41 #define CFG_PROXY_SOCKS_HOST_ENTRY "proxy/socks/host"
42 #define CFG_PROXY_SOCKS_PORT_ENTRY "proxy/socks/port"
43
44 #define CFG_PROXY_IGNORE_HOSTS_ENTRY "proxy/ignore_hosts"
45
46
47
48 class QLopNetworkProxyFactory : public QNetworkProxyFactory
49 {
50 public:
51 QLopNetworkProxyFactory();
52 ~QLopNetworkProxyFactory();
53
54 QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery());
55 QList<QNetworkProxy> queryProxy_manual(const QNetworkProxyQuery &query = QNetworkProxyQuery());
56 QList<QNetworkProxy> queryProxy_system(const QNetworkProxyQuery &query = QNetworkProxyQuery());
57 QList<QNetworkProxy> queryProxy_auto(const QNetworkProxyQuery &query = QNetworkProxyQuery());
58
59 void reloadConfig();
60 private:
61 typedef enum proxyCfgType_t
62 {
63 none=0,
64 manual=1,
65 system=2,
66 automatic=3
67 }proxyCfgType_t;
68 proxyCfgType_t proxyCfgType;
69
70 //=======================================================================
71 // MANUAL PROXY CFG
72 //=======================================================================
73 QNetworkProxy p_http_proxy,p_https_proxy,p_ftp_proxy,p_socks_proxy;
74 QList<QHostAddress> p_ignoreHosts;
75 ProxyPacParser* p_pacParser;
76 };
77
78 #endif // QLOPNETWORKPROXYFACTORY_H
@@ -4,7 +4,7
4 #
4 #
5 #-------------------------------------------------
5 #-------------------------------------------------
6
6
7 QT += core gui network xml svg
7 QT += core gui network xml svg script
8 CONFIG += pythonqt
8 CONFIG += pythonqt
9
9
10 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
10 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
@@ -22,10 +22,12 LIBS+=-lfftw3_threads -lfftw3
22
22
23 INCLUDEPATH += src/QCustomPlot \
23 INCLUDEPATH += src/QCustomPlot \
24 src src/Cassini \
24 src src/Cassini \
25 src/Core/network \
25 src/Core src/Core/Widgets \
26 src/Core src/Core/Widgets \
26 src/Core/Widgets/PyWdgt
27 src/Core/Widgets/PyWdgt
27
28
28 defined(QLOP_DEBUG,var){
29 defined(QLOP_DEBUG,var){
30 message("building without optimisation")
29 QMAKE_CXXFLAGS += -O0 -fopenmp
31 QMAKE_CXXFLAGS += -O0 -fopenmp
30 QMAKE_LFLAGS += -O0 -fopenmp
32 QMAKE_LFLAGS += -O0 -fopenmp
31 }
33 }
@@ -41,8 +43,8 SOURCES += src/main.cpp\
41 src/QCustomPlot/qcustomplot.cpp \
43 src/QCustomPlot/qcustomplot.cpp \
42 src/toolbarcontainer.cpp \
44 src/toolbarcontainer.cpp \
43 src/Core/abstractfileloader.cpp \
45 src/Core/abstractfileloader.cpp \
44 src/Core/filedownloader.cpp \
46 src/Core/network/filedownloader.cpp \
45 src/Core/filedownloadertask.cpp \
47 src/Core/network/filedownloadertask.cpp \
46 src/Core/Widgets/downloadhistory.cpp \
48 src/Core/Widgets/downloadhistory.cpp \
47 src/Core/Widgets/downloadhistoryelement.cpp \
49 src/Core/Widgets/downloadhistoryelement.cpp \
48 src/Core/qlopservice.cpp \
50 src/Core/qlopservice.cpp \
@@ -70,15 +72,17 SOURCES += src/main.cpp\
70 src/Core/qlopgui.cpp \
72 src/Core/qlopgui.cpp \
71 src/Core/Widgets/manualproxycfg_gui.cpp \
73 src/Core/Widgets/manualproxycfg_gui.cpp \
72 src/Core/Widgets/qlopsettingsdialog.cpp \
74 src/Core/Widgets/qlopsettingsdialog.cpp \
73 src/Cassini/cassinitoolssettingsgui.cpp
75 src/Cassini/cassinitoolssettingsgui.cpp \
76 src/Core/network/proxypacparser.cpp \
77 src/Core/network/qlopnetworkproxyfactory.cpp
74
78
75 HEADERS += src/mainwindow.h \
79 HEADERS += src/mainwindow.h \
76 src/SocExplorerPlot.h \
80 src/SocExplorerPlot.h \
77 src/QCustomPlot/qcustomplot.h \
81 src/QCustomPlot/qcustomplot.h \
78 src/toolbarcontainer.h \
82 src/toolbarcontainer.h \
79 src/Core/abstractfileloader.h \
83 src/Core/abstractfileloader.h \
80 src/Core/filedownloader.h \
84 src/Core/network/filedownloader.h \
81 src/Core/filedownloadertask.h \
85 src/Core/network/filedownloadertask.h \
82 src/Core/Widgets/downloadhistory.h \
86 src/Core/Widgets/downloadhistory.h \
83 src/Core/Widgets/downloadhistoryelement.h \
87 src/Core/Widgets/downloadhistoryelement.h \
84 src/Core/qlopservice.h \
88 src/Core/qlopservice.h \
@@ -108,7 +112,9 HEADERS += src/mainwindow.h \
108 src/Core/qlopgui.h \
112 src/Core/qlopgui.h \
109 src/Core/Widgets/manualproxycfg_gui.h \
113 src/Core/Widgets/manualproxycfg_gui.h \
110 src/Core/Widgets/qlopsettingsdialog.h \
114 src/Core/Widgets/qlopsettingsdialog.h \
111 src/Cassini/cassinitoolssettingsgui.h
115 src/Cassini/cassinitoolssettingsgui.h \
116 src/Core/network/proxypacparser.h \
117 src/Core/network/qlopnetworkproxyfactory.h
112
118
113 FORMS += src/mainwindow.ui \
119 FORMS += src/mainwindow.ui \
114 src/Core/Widgets/downloadhistory.ui \
120 src/Core/Widgets/downloadhistory.ui \
@@ -8,6 +8,9
8 <file>QLop.svg</file>
8 <file>QLop.svg</file>
9 <file>Gnome-emblem-downloads.svg</file>
9 <file>Gnome-emblem-downloads.svg</file>
10 <file>cassini.gif</file>
10 <file>cassini.gif</file>
11 <file>restart.png</file>
12 <file>start.png</file>
13 <file>stop.png</file>
11 </qresource>
14 </qresource>
12 <qresource prefix="/">
15 <qresource prefix="/">
13 <file>QLop.png</file>
16 <file>QLop.png</file>
@@ -2,7 +2,7
2 #include "ui_cassinitoolssettingsgui.h"
2 #include "ui_cassinitoolssettingsgui.h"
3
3
4 CassiniToolsSettingsGUI::CassiniToolsSettingsGUI(QWidget *parent) :
4 CassiniToolsSettingsGUI::CassiniToolsSettingsGUI(QWidget *parent) :
5 QWidget(parent),
5 QLopSettingsItem(parent),
6 ui(new Ui::CassiniToolsSettingsGUI)
6 ui(new Ui::CassiniToolsSettingsGUI)
7 {
7 {
8 ui->setupUi(this);
8 ui->setupUi(this);
@@ -2,12 +2,12
2 #define CASSINITOOLSSETTINGSGUI_H
2 #define CASSINITOOLSSETTINGSGUI_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5
5 #include <qlopsettingsdialog.h>
6 namespace Ui {
6 namespace Ui {
7 class CassiniToolsSettingsGUI;
7 class CassiniToolsSettingsGUI;
8 }
8 }
9
9
10 class CassiniToolsSettingsGUI : public QWidget
10 class CassiniToolsSettingsGUI : public QLopSettingsItem
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13
13
@@ -15,6 +15,8 public:
15 explicit CassiniToolsSettingsGUI(QWidget *parent = 0);
15 explicit CassiniToolsSettingsGUI(QWidget *parent = 0);
16 ~CassiniToolsSettingsGUI();
16 ~CassiniToolsSettingsGUI();
17
17
18 public slots:
19 void accept(){}
18 protected:
20 protected:
19 void changeEvent(QEvent *e);
21 void changeEvent(QEvent *e);
20
22
@@ -51,8 +51,21
51 </property>
51 </property>
52 </widget>
52 </widget>
53 </item>
53 </item>
54 <item row="1" column="3">
55 <widget class="QPushButton" name="pauseQpb">
56 <property name="text">
57 <string/>
58 </property>
59 <property name="icon">
60 <iconset resource="../../../resources/qlop.qrc">
61 <normaloff>:/img/stop.png</normaloff>:/img/stop.png</iconset>
62 </property>
63 </widget>
64 </item>
54 </layout>
65 </layout>
55 </widget>
66 </widget>
56 <resources/>
67 <resources>
68 <include location="../../../resources/qlop.qrc"/>
69 </resources>
57 <connections/>
70 <connections/>
58 </ui>
71 </ui>
@@ -21,15 +21,26
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "filedowloadersettingsgui.h"
22 #include "filedowloadersettingsgui.h"
23 #include "ui_filedowloadersettingsgui.h"
23 #include "ui_filedowloadersettingsgui.h"
24 #include <qlopsettings.h>
25 #include <filedownloader.h>
26 #include <QDir>
27 #include <qlopnetworkproxyfactory.h>
24
28
25 FileDowloaderSettingsGUI::FileDowloaderSettingsGUI(QWidget *parent) :
29 FileDowloaderSettingsGUI::FileDowloaderSettingsGUI(QWidget *parent) :
26 QWidget(parent),
30 QLopSettingsItem(parent),
27 ui(new Ui::FileDowloaderSettingsGUI)
31 ui(new Ui::FileDowloaderSettingsGUI)
28 {
32 {
29 ui->setupUi(this);
33 ui->setupUi(this);
30 this->manualProxyCFG_GUI = new ManualProxyCFG_GUI();
34 this->manualProxyCFG_GUI = new ManualProxyCFG_GUI();
31 lastWidget = NULL;
35 lastWidget = NULL;
32 connect(this->ui->comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(proxyMethodChanged(QString)));
36 connect(this->ui->comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(proxyMethodChanged(QString)));
37 QString proxyType = QLopSettings::value(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,CFG_PROXY_TYPE_VALUE_NONE).toString();
38 for(int i=0;i<ui->comboBox->count();i++)
39 {
40 if(!this->ui->comboBox->itemText(i).compare(proxyType))
41 this->ui->comboBox->setCurrentIndex(i);
42 }
43 this->ui->defaultDestPath->setText(QLopSettings::value(FileDownloader::self(),"default_path",QDir::homePath()+"/Downloads").toString());
33 }
44 }
34
45
35 FileDowloaderSettingsGUI::~FileDowloaderSettingsGUI()
46 FileDowloaderSettingsGUI::~FileDowloaderSettingsGUI()
@@ -49,10 +60,17 void FileDowloaderSettingsGUI::changeEve
49 }
60 }
50 }
61 }
51
62
63 void FileDowloaderSettingsGUI::accept()
64 {
65 QLopSettings::setValue(FileDownloader::self(),"default_path",this->ui->defaultDestPath->text());
66 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_TYPE_ENTRY,this->ui->comboBox->currentText());
67 manualProxyCFG_GUI->saveConfig();
68 }
69
52 void FileDowloaderSettingsGUI::proxyMethodChanged(const QString &text)
70 void FileDowloaderSettingsGUI::proxyMethodChanged(const QString &text)
53 {
71 {
54 this->ui->gridLayout->removeWidget(this->lastWidget);
72 this->ui->gridLayout->removeWidget(this->lastWidget);
55 if(text=="manual")
73 if(text==CFG_PROXY_TYPE_VALUE_MANUAL)
56 {
74 {
57 this->ui->gridLayout->addWidget(this->manualProxyCFG_GUI,1,0,1,-1);
75 this->ui->gridLayout->addWidget(this->manualProxyCFG_GUI,1,0,1,-1);
58 this->lastWidget = this->manualProxyCFG_GUI;
76 this->lastWidget = this->manualProxyCFG_GUI;
@@ -24,22 +24,23
24
24
25 #include <QWidget>
25 #include <QWidget>
26 #include "manualproxycfg_gui.h"
26 #include "manualproxycfg_gui.h"
27 #include <qlopsettingsdialog.h>
27
28
28 namespace Ui {
29 namespace Ui {
29 class FileDowloaderSettingsGUI;
30 class FileDowloaderSettingsGUI;
30 }
31 }
31
32
32 class FileDowloaderSettingsGUI : public QWidget
33 class FileDowloaderSettingsGUI : public QLopSettingsItem
33 {
34 {
34 Q_OBJECT
35 Q_OBJECT
35
36
36 public:
37 public:
37 explicit FileDowloaderSettingsGUI(QWidget *parent = 0);
38 explicit FileDowloaderSettingsGUI(QWidget *parent = 0);
38 ~FileDowloaderSettingsGUI();
39 ~FileDowloaderSettingsGUI();
39
40 protected:
40 protected:
41 void changeEvent(QEvent *e);
41 void changeEvent(QEvent *e);
42
42 public slots:
43 void accept();
43 private slots:
44 private slots:
44 void proxyMethodChanged(const QString & text);
45 void proxyMethodChanged(const QString & text);
45 private:
46 private:
@@ -22,7 +22,7
22 </widget>
22 </widget>
23 </item>
23 </item>
24 <item row="0" column="1">
24 <item row="0" column="1">
25 <widget class="QLineEdit" name="lineEdit"/>
25 <widget class="QLineEdit" name="defaultDestPath"/>
26 </item>
26 </item>
27 <item row="1" column="0" colspan="2">
27 <item row="1" column="0" colspan="2">
28 <widget class="QGroupBox" name="groupBox">
28 <widget class="QGroupBox" name="groupBox">
@@ -21,12 +21,15
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "manualproxycfg_gui.h"
22 #include "manualproxycfg_gui.h"
23 #include "ui_manualproxycfg_gui.h"
23 #include "ui_manualproxycfg_gui.h"
24 #include <qlopsettings.h>
25 #include <filedownloader.h>
24
26
25 ManualProxyCFG_GUI::ManualProxyCFG_GUI(QWidget *parent) :
27 ManualProxyCFG_GUI::ManualProxyCFG_GUI(QWidget *parent) :
26 QWidget(parent),
28 QWidget(parent),
27 ui(new Ui::ManualProxyCFG_GUI)
29 ui(new Ui::ManualProxyCFG_GUI)
28 {
30 {
29 ui->setupUi(this);
31 ui->setupUi(this);
32 reloadConfig();
30 }
33 }
31
34
32 ManualProxyCFG_GUI::~ManualProxyCFG_GUI()
35 ManualProxyCFG_GUI::~ManualProxyCFG_GUI()
@@ -34,6 +37,41 ManualProxyCFG_GUI::~ManualProxyCFG_GUI(
34 delete ui;
37 delete ui;
35 }
38 }
36
39
40 void ManualProxyCFG_GUI::reloadConfig()
41 {
42 this->ui->httpHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY,"").toString());
43 this->ui->httpPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY,"").toString());
44
45 this->ui->httpsHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY,"").toString());
46 this->ui->httpsPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY,"").toString());
47
48 this->ui->ftpHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY,"").toString());
49 this->ui->ftpPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY,"").toString());
50
51 this->ui->socksHost->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY,"").toString());
52 this->ui->socksPort->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY,"").toString());
53
54 this->ui->IgnoreHosts->setText(QLopSettings::value(FileDownloader::self(),CFG_PROXY_IGNORE_HOSTS_ENTRY,"localhost, 127.0.0.0/8, ::1").toString());
55 }
56
57 void ManualProxyCFG_GUI::saveConfig()
58 {
59 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTP_HOST_ENTRY,this->ui->httpHost->text());
60 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTP_PORT_ENTRY,this->ui->httpPort->text());
61
62 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTPS_HOST_ENTRY,this->ui->httpsHost->text());
63 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_HTTPS_PORT_ENTRY,this->ui->httpsPort->text());
64
65 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_FTP_HOST_ENTRY,this->ui->ftpHost->text());
66 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_FTP_PORT_ENTRY,this->ui->ftpPort->text());
67
68 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_SOCKS_HOST_ENTRY,this->ui->socksHost->text());
69 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_SOCKS_PORT_ENTRY,this->ui->socksPort->text());
70
71 QLopSettings::setValue(FileDownloader::self(),CFG_PROXY_IGNORE_HOSTS_ENTRY,this->ui->IgnoreHosts->text());
72
73 }
74
37 void ManualProxyCFG_GUI::changeEvent(QEvent *e)
75 void ManualProxyCFG_GUI::changeEvent(QEvent *e)
38 {
76 {
39 QWidget::changeEvent(e);
77 QWidget::changeEvent(e);
@@ -35,7 +35,8 class ManualProxyCFG_GUI : public QWidge
35 public:
35 public:
36 explicit ManualProxyCFG_GUI(QWidget *parent = 0);
36 explicit ManualProxyCFG_GUI(QWidget *parent = 0);
37 ~ManualProxyCFG_GUI();
37 ~ManualProxyCFG_GUI();
38
38 void reloadConfig();
39 void saveConfig();
39 protected:
40 protected:
40 void changeEvent(QEvent *e);
41 void changeEvent(QEvent *e);
41
42
@@ -16,46 +16,116
16 <layout class="QGridLayout" name="gridLayout">
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="0">
17 <item row="0" column="0">
18 <widget class="QLabel" name="label">
18 <widget class="QLabel" name="label">
19 <property name="sizePolicy">
20 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
21 <horstretch>0</horstretch>
22 <verstretch>0</verstretch>
23 </sizepolicy>
24 </property>
19 <property name="text">
25 <property name="text">
20 <string>HTTP proxy</string>
26 <string>HTTP proxy</string>
21 </property>
27 </property>
22 </widget>
28 </widget>
23 </item>
29 </item>
24 <item row="0" column="1">
30 <item row="0" column="1">
25 <widget class="QLineEdit" name="httpHost"/>
31 <widget class="QLineEdit" name="httpHost">
32 <property name="sizePolicy">
33 <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
34 <horstretch>0</horstretch>
35 <verstretch>0</verstretch>
36 </sizepolicy>
37 </property>
38 <property name="placeholderText">
39 <string>Put host address here</string>
40 </property>
41 </widget>
26 </item>
42 </item>
27 <item row="1" column="0">
43 <item row="1" column="0">
28 <widget class="QLabel" name="label_2">
44 <widget class="QLabel" name="label_2">
45 <property name="sizePolicy">
46 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
47 <horstretch>0</horstretch>
48 <verstretch>0</verstretch>
49 </sizepolicy>
50 </property>
29 <property name="text">
51 <property name="text">
30 <string>HTTPS proxy</string>
52 <string>HTTPS proxy</string>
31 </property>
53 </property>
32 </widget>
54 </widget>
33 </item>
55 </item>
34 <item row="1" column="1">
56 <item row="1" column="1">
35 <widget class="QLineEdit" name="httpsHost"/>
57 <widget class="QLineEdit" name="httpsHost">
58 <property name="sizePolicy">
59 <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
60 <horstretch>0</horstretch>
61 <verstretch>0</verstretch>
62 </sizepolicy>
63 </property>
64 <property name="placeholderText">
65 <string>Put host address here</string>
66 </property>
67 </widget>
36 </item>
68 </item>
37 <item row="2" column="0">
69 <item row="2" column="0">
38 <widget class="QLabel" name="label_3">
70 <widget class="QLabel" name="label_3">
71 <property name="sizePolicy">
72 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
73 <horstretch>0</horstretch>
74 <verstretch>0</verstretch>
75 </sizepolicy>
76 </property>
39 <property name="text">
77 <property name="text">
40 <string>FTP proxy</string>
78 <string>FTP proxy</string>
41 </property>
79 </property>
42 </widget>
80 </widget>
43 </item>
81 </item>
44 <item row="2" column="1">
82 <item row="2" column="1">
45 <widget class="QLineEdit" name="ftpHost"/>
83 <widget class="QLineEdit" name="ftpHost">
84 <property name="sizePolicy">
85 <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
86 <horstretch>0</horstretch>
87 <verstretch>0</verstretch>
88 </sizepolicy>
89 </property>
90 <property name="placeholderText">
91 <string>Put host address here</string>
92 </property>
93 </widget>
46 </item>
94 </item>
47 <item row="3" column="0">
95 <item row="3" column="0">
48 <widget class="QLabel" name="label_4">
96 <widget class="QLabel" name="label_4">
97 <property name="sizePolicy">
98 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
99 <horstretch>0</horstretch>
100 <verstretch>0</verstretch>
101 </sizepolicy>
102 </property>
49 <property name="text">
103 <property name="text">
50 <string>SOCKS proxy</string>
104 <string>SOCKS proxy</string>
51 </property>
105 </property>
52 </widget>
106 </widget>
53 </item>
107 </item>
54 <item row="3" column="1">
108 <item row="3" column="1">
55 <widget class="QLineEdit" name="socksHost"/>
109 <widget class="QLineEdit" name="socksHost">
110 <property name="sizePolicy">
111 <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
112 <horstretch>0</horstretch>
113 <verstretch>0</verstretch>
114 </sizepolicy>
115 </property>
116 <property name="placeholderText">
117 <string>Put host address here</string>
118 </property>
119 </widget>
56 </item>
120 </item>
57 <item row="4" column="0">
121 <item row="4" column="0">
58 <widget class="QLabel" name="label_5">
122 <widget class="QLabel" name="label_5">
123 <property name="sizePolicy">
124 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
125 <horstretch>0</horstretch>
126 <verstretch>0</verstretch>
127 </sizepolicy>
128 </property>
59 <property name="text">
129 <property name="text">
60 <string>Ignore hosts</string>
130 <string>Ignore hosts</string>
61 </property>
131 </property>
@@ -64,7 +134,26
64 <item row="0" column="2">
134 <item row="0" column="2">
65 <widget class="QLineEdit" name="httpPort">
135 <widget class="QLineEdit" name="httpPort">
66 <property name="sizePolicy">
136 <property name="sizePolicy">
67 <sizepolicy hsizetype="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 <horstretch>0</horstretch>
157 <horstretch>0</horstretch>
69 <verstretch>0</verstretch>
158 <verstretch>0</verstretch>
70 </sizepolicy>
159 </sizepolicy>
@@ -72,31 +161,51
72 <property name="inputMask">
161 <property name="inputMask">
73 <string>000000</string>
162 <string>000000</string>
74 </property>
163 </property>
75 </widget>
164 <property name="placeholderText">
76 </item>
165 <string>0 to 65536</string>
77 <item row="1" column="2">
78 <widget class="QLineEdit" name="httpsPort">
79 <property name="inputMask">
80 <string>000000</string>
81 </property>
166 </property>
82 </widget>
167 </widget>
83 </item>
168 </item>
84 <item row="2" column="2">
169 <item row="2" column="2">
85 <widget class="QLineEdit" name="ftpPort">
170 <widget class="QLineEdit" name="ftpPort">
171 <property name="sizePolicy">
172 <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
173 <horstretch>0</horstretch>
174 <verstretch>0</verstretch>
175 </sizepolicy>
176 </property>
86 <property name="inputMask">
177 <property name="inputMask">
87 <string>000000</string>
178 <string>000000</string>
88 </property>
179 </property>
180 <property name="placeholderText">
181 <string>0 to 65536</string>
182 </property>
89 </widget>
183 </widget>
90 </item>
184 </item>
91 <item row="3" column="2">
185 <item row="3" column="2">
92 <widget class="QLineEdit" name="socksPort">
186 <widget class="QLineEdit" name="socksPort">
187 <property name="sizePolicy">
188 <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
189 <horstretch>0</horstretch>
190 <verstretch>0</verstretch>
191 </sizepolicy>
192 </property>
93 <property name="inputMask">
193 <property name="inputMask">
94 <string>000000</string>
194 <string>000000</string>
95 </property>
195 </property>
196 <property name="placeholderText">
197 <string>0 to 65536</string>
198 </property>
96 </widget>
199 </widget>
97 </item>
200 </item>
98 <item row="4" column="1" colspan="2">
201 <item row="4" column="1" colspan="2">
99 <widget class="QLineEdit" name="IgnoreHosts">
202 <widget class="QLineEdit" name="IgnoreHosts">
203 <property name="sizePolicy">
204 <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
205 <horstretch>0</horstretch>
206 <verstretch>0</verstretch>
207 </sizepolicy>
208 </property>
100 <property name="text">
209 <property name="text">
101 <string>localhost, 127.0.0.0/8, ::1</string>
210 <string>localhost, 127.0.0.0/8, ::1</string>
102 </property>
211 </property>
@@ -39,7 +39,7 void QLopSettingsDialog::changePage(QLis
39 ui->pagesWidget->setCurrentIndex(ui->contentsWidget->row(current));
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 if(configEntry!=NULL)
44 if(configEntry!=NULL)
45 {
45 {
@@ -49,12 +49,13 bool QLopSettingsDialog::registerConfigE
49 configButton->setText(text);
49 configButton->setText(text);
50 configButton->setTextAlignment(Qt::AlignHCenter);
50 configButton->setTextAlignment(Qt::AlignHCenter);
51 configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
51 configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
52 connect(this,SIGNAL(accepted()),configEntry,SLOT(accept()));
52 return true;
53 return true;
53 }
54 }
54 return false;
55 return false;
55 }
56 }
56
57
57 void QLopSettingsDialog::popConfigDialog(QWidget *selectedConfigEntry)
58 void QLopSettingsDialog::popConfigDialog(QLopSettingsItem *selectedConfigEntry)
58 {
59 {
59 if(selectedConfigEntry!=NULL)
60 if(selectedConfigEntry!=NULL)
60 {
61 {
@@ -8,6 +8,16 class QLopSettingsDialog;
8 }
8 }
9 #include <QListWidgetItem>
9 #include <QListWidgetItem>
10
10
11 class QLopSettingsItem : public QWidget
12 {
13 Q_OBJECT
14 public:
15 QLopSettingsItem(QWidget *parent = 0):QWidget(parent) {}
16 ~QLopSettingsItem() {}
17 public slots:
18 virtual void accept()=0;
19 };
20
11 class QLopSettingsDialog : public QDialog
21 class QLopSettingsDialog : public QDialog
12 {
22 {
13 Q_OBJECT
23 Q_OBJECT
@@ -18,8 +28,8 public:
18
28
19 public slots:
29 public slots:
20 void changePage(QListWidgetItem *current, QListWidgetItem *previous);
30 void changePage(QListWidgetItem *current, QListWidgetItem *previous);
21 bool registerConfigEntry(QWidget* configEntry, QIcon icon, QString text);
31 bool registerConfigEntry(QLopSettingsItem* configEntry, QIcon icon, QString text);
22 void popConfigDialog(QWidget* selectedConfigEntry=0);
32 void popConfigDialog(QLopSettingsItem* selectedConfigEntry=0);
23 protected:
33 protected:
24 void changeEvent(QEvent *e);
34 void changeEvent(QEvent *e);
25
35
@@ -3,4 +3,4
3 #export QTDIR=/usr/include
3 #export QTDIR=/usr/include
4 #export QTDIR=/usr/include/qt5
4 #export QTDIR=/usr/include/qt5
5
5
6 pythonqt_generator --include-paths=../QCustomPlot:../:./Widgets:./:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut pyqlop.h pythonQtgeneratorCfg.txt
6 pythonqt_generator --include-paths=../QCustomPlot:../:./Widgets:./network:./:/usr/include/qt5:/usr/include/qt5/QtCore:/usr/include/qt5/QtWidgets --output-directory=pythonQtOut pyqlop.h pythonQtgeneratorCfg.txt
@@ -79,7 +79,7 QLopSettings *QLopSettings::self()
79 return _self;
79 return _self;
80 }
80 }
81
81
82 void QLopSettings::popConfigDialog(QWidget *selectedConfigEntry)
82 void QLopSettings::popConfigDialog(QLopSettingsItem *selectedConfigEntry)
83 {
83 {
84 INIT();
84 INIT();
85 m_configDialog->popConfigDialog(selectedConfigEntry);
85 m_configDialog->popConfigDialog(selectedConfigEntry);
@@ -90,9 +90,21 void QLopSettings::popConfigDialog()
90 m_configDialog->popConfigDialog(NULL);
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 INIT();
95 INIT();
96 return m_configDialog->registerConfigEntry(configEntry, icon, text);
96 return m_configDialog->registerConfigEntry(configEntry, icon, text);
97 }
97 }
98
98
99 void QLopSettings::setValue(QLopService* service, const QString &key, const QVariant &value)
100 {
101 INIT();
102 m_settings->setValue(service->serviceName()+"/"+key,value);
103 }
104
105 QVariant QLopSettings::value(QLopService* service, const QString &key, const QVariant &defaultValue)
106 {
107 INIT();
108 return m_settings->value(service->serviceName()+"/"+key,defaultValue);
109 }
110
@@ -44,8 +44,10 public:
44 static void init(bool noGUI=false,QObject *parent = 0);
44 static void init(bool noGUI=false,QObject *parent = 0);
45 const QString& serviceName();
45 const QString& serviceName();
46 static QLopSettings* self();
46 static QLopSettings* self();
47 static void popConfigDialog(QWidget* selectedConfigEntry);
47 static void popConfigDialog(QLopSettingsItem *selectedConfigEntry);
48 static bool registerConfigEntry(QWidget* configEntry,QIcon icon, QString text);
48 static bool registerConfigEntry(QLopSettingsItem* configEntry,QIcon icon, QString text);
49 static void setValue(QLopService* service,const QString & key, const QVariant & value);
50 static QVariant value(QLopService* service, const QString & key, const QVariant & defaultValue = QVariant());
49 public slots:
51 public slots:
50 void popConfigDialog();
52 void popConfigDialog();
51 };
53 };
@@ -45,6 +45,8 SocExplorerPlot::SocExplorerPlot(QWidget
45 this->m_plot->setNoAntialiasingOnDrag(true);
45 this->m_plot->setNoAntialiasingOnDrag(true);
46 this->show();
46 this->show();
47 this->m_plot->legend->setVisible(true);
47 this->m_plot->legend->setVisible(true);
48 this->m_plot->plotLayout()->insertRow(0);
49 this->m_plotTitle = new QCPPlotTitle(m_plot);
48 }
50 }
49
51
50 SocExplorerPlot::~SocExplorerPlot()
52 SocExplorerPlot::~SocExplorerPlot()
@@ -104,6 +106,8 void SocExplorerPlot::setTitle(QString t
104 /*!
106 /*!
105 @todo Function borcken fixe this!
107 @todo Function borcken fixe this!
106 */
108 */
109 m_plotTitle->setText(title);
110 m_plot->plotLayout()->addElement(0, 0, m_plotTitle);
107 this->m_Title = title;
111 this->m_Title = title;
108 emit titleChanged(title);
112 emit titleChanged(title);
109 this->repaint();
113 this->repaint();
@@ -128,6 +128,7 private:
128 QPoint mOrigin;
128 QPoint mOrigin;
129 QList<SocExplorerPlotActions*> m_actions;
129 QList<SocExplorerPlotActions*> m_actions;
130 QString m_Title;
130 QString m_Title;
131 QCPPlotTitle* m_plotTitle;
131 int m_PID;
132 int m_PID;
132 };
133 };
133
134
@@ -37,11 +37,6
37 #include <qlopgui.h>
37 #include <qlopgui.h>
38
38
39
39
40 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
41 <<QLopDataBase::self()
42 <<FileDownloader::self()
43 <<CassiniTools::self()
44 << QLopPlots::self();
45
40
46 MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) :
41 MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) :
47 QMainWindow(parent),
42 QMainWindow(parent),
@@ -66,6 +61,12 MainWindow::MainWindow(int OMP_THREADS,
66 this->progressThreadIds[i] = -1;
61 this->progressThreadIds[i] = -1;
67 }
62 }
68 this->progressWidget->setWindowTitle("Loading File");
63 this->progressWidget->setWindowTitle("Loading File");
64 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
65 <<QLopDataBase::self()
66 <<FileDownloader::self()
67 <<CassiniTools::self()
68 << QLopPlots::self();
69
69 for(int i=0;i<ServicesToLoad.count();i++)
70 for(int i=0;i<ServicesToLoad.count();i++)
70 {
71 {
71 qDebug()<<ServicesToLoad.at(i)->serviceName();
72 qDebug()<<ServicesToLoad.at(i)->serviceName();
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now