mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-19 10:02:45 -05:00
rbutil: introduce a util function to get the systemproxy, for better reuse.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16150 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9759c035f4
commit
df6c5f414f
4 changed files with 52 additions and 60 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
#include "browsedirtree.h"
|
#include "browsedirtree.h"
|
||||||
#include "encoders.h"
|
#include "encoders.h"
|
||||||
#include "tts.h"
|
#include "tts.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
|
|
@ -384,40 +385,10 @@ void Config::setSystemProxy(bool checked)
|
||||||
proxy.setHost(ui.proxyHost->text());
|
proxy.setHost(ui.proxyHost->text());
|
||||||
proxy.setPort(ui.proxyPort->text().toInt());
|
proxy.setPort(ui.proxyPort->text().toInt());
|
||||||
// show system values in input box
|
// show system values in input box
|
||||||
QUrl envproxy;
|
QUrl envproxy = systemProxy();
|
||||||
#if defined(Q_OS_LINUX)
|
|
||||||
envproxy = QUrl(getenv("http_proxy"));
|
|
||||||
|
|
||||||
ui.proxyHost->setText(envproxy.host());
|
ui.proxyHost->setText(envproxy.host());
|
||||||
#endif
|
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
HKEY hk;
|
|
||||||
wchar_t proxyval[80];
|
|
||||||
DWORD buflen = 80;
|
|
||||||
long ret;
|
|
||||||
DWORD enable;
|
|
||||||
DWORD enalen = sizeof(DWORD);
|
|
||||||
|
|
||||||
ret = RegOpenKeyEx(HKEY_CURRENT_USER, _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
|
|
||||||
0, KEY_QUERY_VALUE, &hk);
|
|
||||||
if(ret != ERROR_SUCCESS) return;
|
|
||||||
|
|
||||||
ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
|
|
||||||
if(ret != ERROR_SUCCESS) return;
|
|
||||||
|
|
||||||
ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
|
|
||||||
if(ret != ERROR_SUCCESS) return;
|
|
||||||
|
|
||||||
RegCloseKey(hk);
|
|
||||||
envproxy = QUrl("http://" + QString::fromWCharArray(proxyval));
|
|
||||||
qDebug() << envproxy;
|
|
||||||
if(enable != 0) {
|
|
||||||
ui.proxyHost->setText(envproxy.host());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ui.proxyHost->setText(envproxy.host() + " " + tr("(system proxy is disabled)"));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
ui.proxyPort->setText(QString("%1").arg(envproxy.port()));
|
ui.proxyPort->setText(QString("%1").arg(envproxy.port()));
|
||||||
ui.proxyUser->setText(envproxy.userName());
|
ui.proxyUser->setText(envproxy.userName());
|
||||||
ui.proxyPass->setText(envproxy.password());
|
ui.proxyPass->setText(envproxy.password());
|
||||||
|
|
|
||||||
|
|
@ -969,36 +969,10 @@ QUrl RbUtilQt::proxy()
|
||||||
{
|
{
|
||||||
if(userSettings->value("proxytype", "system").toString() == "manual")
|
if(userSettings->value("proxytype", "system").toString() == "manual")
|
||||||
return QUrl(userSettings->value("proxy").toString());
|
return QUrl(userSettings->value("proxy").toString());
|
||||||
#if defined(Q_OS_LINUX)
|
|
||||||
else if(userSettings->value("proxytype", "system").toString() == "system")
|
else if(userSettings->value("proxytype", "system").toString() == "system")
|
||||||
return QUrl(getenv("http_proxy"));
|
{
|
||||||
#endif
|
systemProxy();
|
||||||
#if defined(Q_OS_WIN32)
|
}
|
||||||
HKEY hk;
|
|
||||||
wchar_t proxyval[80];
|
|
||||||
DWORD buflen = 80;
|
|
||||||
long ret;
|
|
||||||
DWORD enable;
|
|
||||||
DWORD enalen = sizeof(DWORD);
|
|
||||||
|
|
||||||
ret = RegOpenKeyEx(HKEY_CURRENT_USER,
|
|
||||||
_TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
|
|
||||||
0, KEY_QUERY_VALUE, &hk);
|
|
||||||
if(ret != ERROR_SUCCESS) return QUrl("");
|
|
||||||
|
|
||||||
ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
|
|
||||||
if(ret != ERROR_SUCCESS) return QUrl("");
|
|
||||||
|
|
||||||
ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
|
|
||||||
if(ret != ERROR_SUCCESS) return QUrl("");
|
|
||||||
|
|
||||||
RegCloseKey(hk);
|
|
||||||
|
|
||||||
qDebug() << QString::fromWCharArray(proxyval) << QString("%1").arg(enable);
|
|
||||||
if(enable != 0)
|
|
||||||
return QUrl("http://" + QString::fromWCharArray(proxyval));
|
|
||||||
|
|
||||||
#endif
|
|
||||||
return QUrl("");
|
return QUrl("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,14 @@
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
#if defined(Q_OS_WIN32)
|
||||||
|
#if defined(UNICODE)
|
||||||
|
#define _UNICODE
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// recursive function to delete a dir with files
|
// recursive function to delete a dir with files
|
||||||
bool recRmdir( const QString &dirName )
|
bool recRmdir( const QString &dirName )
|
||||||
{
|
{
|
||||||
|
|
@ -42,3 +50,39 @@ bool recRmdir( const QString &dirName )
|
||||||
dir.cdUp();
|
dir.cdUp();
|
||||||
return dir.rmdir(dirN); // delete empty dir and return if (now empty) dir-removing was successfull
|
return dir.rmdir(dirN); // delete empty dir and return if (now empty) dir-removing was successfull
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Function to get the system proxy
|
||||||
|
QUrl systemProxy(void)
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
return QUrl(getenv("http_proxy"));
|
||||||
|
#endif
|
||||||
|
#if defined(Q_OS_WIN32)
|
||||||
|
HKEY hk;
|
||||||
|
wchar_t proxyval[80];
|
||||||
|
DWORD buflen = 80;
|
||||||
|
long ret;
|
||||||
|
DWORD enable;
|
||||||
|
DWORD enalen = sizeof(DWORD);
|
||||||
|
|
||||||
|
ret = RegOpenKeyEx(HKEY_CURRENT_USER,
|
||||||
|
_TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
|
||||||
|
0, KEY_QUERY_VALUE, &hk);
|
||||||
|
if(ret != ERROR_SUCCESS) return QUrl("");
|
||||||
|
|
||||||
|
ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
|
||||||
|
if(ret != ERROR_SUCCESS) return QUrl("");
|
||||||
|
|
||||||
|
ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
|
||||||
|
if(ret != ERROR_SUCCESS) return QUrl("");
|
||||||
|
|
||||||
|
RegCloseKey(hk);
|
||||||
|
|
||||||
|
//qDebug() << QString::fromWCharArray(proxyval) << QString("%1").arg(enable);
|
||||||
|
if(enable != 0)
|
||||||
|
return QUrl("http://" + QString::fromWCharArray(proxyval));
|
||||||
|
else
|
||||||
|
return QUrl("");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,11 @@
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
bool recRmdir( const QString &dirName );
|
bool recRmdir( const QString &dirName );
|
||||||
|
|
||||||
|
QUrl systemProxy(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue