remove usb_benchmark. Its usefulness is extremely limited, and the usb stack around...
[kugel-rb.git] / rbutil / rbutilqt / utils.cpp
blobee7337b209f4224486e4b52225f464308965287f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id$
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "utils.h"
22 #include <QDir>
24 #if defined(Q_OS_WIN32)
25 #if defined(UNICODE)
26 #define _UNICODE
27 #endif
28 #include <windows.h>
29 #include <tchar.h>
30 #endif
32 // recursive function to delete a dir with files
33 bool recRmdir( const QString &dirName )
35 QString dirN = dirName;
36 QDir dir(dirN);
37 // make list of entries in directory
38 QStringList list = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
39 QFileInfo fileInfo;
40 QString curItem, lstAt;
41 for(int i = 0; i < list.size(); i++){ // loop through all items of list
42 QString name = list.at(i);
43 curItem = dirN + "/" + name;
44 fileInfo.setFile(curItem);
45 if(fileInfo.isDir()) // is directory
46 recRmdir(curItem); // call recRmdir() recursively for deleting subdirectory
47 else // is file
48 QFile::remove(curItem); // ok, delete file
50 dir.cdUp();
51 return dir.rmdir(dirN); // delete empty dir and return if (now empty) dir-removing was successfull
55 //Function to get the system proxy
56 QUrl systemProxy(void)
58 #if defined(Q_OS_LINUX)
59 return QUrl(getenv("http_proxy"));
60 #elif defined(Q_OS_WIN32)
61 HKEY hk;
62 wchar_t proxyval[80];
63 DWORD buflen = 80;
64 long ret;
65 DWORD enable;
66 DWORD enalen = sizeof(DWORD);
68 ret = RegOpenKeyEx(HKEY_CURRENT_USER,
69 _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
70 0, KEY_QUERY_VALUE, &hk);
71 if(ret != ERROR_SUCCESS) return QUrl("");
73 ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
74 if(ret != ERROR_SUCCESS) return QUrl("");
76 ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
77 if(ret != ERROR_SUCCESS) return QUrl("");
79 RegCloseKey(hk);
81 //qDebug() << QString::fromWCharArray(proxyval) << QString("%1").arg(enable);
82 if(enable != 0)
83 return QUrl("http://" + QString::fromWCharArray(proxyval));
84 else
85 return QUrl("");
86 #else
87 return QUrl("");
88 #endif