Add some accelerator keys to the Actions menu.
[Rockbox.git] / rbutil / rbutilqt / utils.cpp
blob529298530eaead8f5aca34bffe54aaea9efb9203
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 #endif
61 #if defined(Q_OS_WIN32)
62 HKEY hk;
63 wchar_t proxyval[80];
64 DWORD buflen = 80;
65 long ret;
66 DWORD enable;
67 DWORD enalen = sizeof(DWORD);
69 ret = RegOpenKeyEx(HKEY_CURRENT_USER,
70 _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
71 0, KEY_QUERY_VALUE, &hk);
72 if(ret != ERROR_SUCCESS) return QUrl("");
74 ret = RegQueryValueEx(hk, _TEXT("ProxyServer"), NULL, NULL, (LPBYTE)proxyval, &buflen);
75 if(ret != ERROR_SUCCESS) return QUrl("");
77 ret = RegQueryValueEx(hk, _TEXT("ProxyEnable"), NULL, NULL, (LPBYTE)&enable, &enalen);
78 if(ret != ERROR_SUCCESS) return QUrl("");
80 RegCloseKey(hk);
82 //qDebug() << QString::fromWCharArray(proxyval) << QString("%1").arg(enable);
83 if(enable != 0)
84 return QUrl("http://" + QString::fromWCharArray(proxyval));
85 else
86 return QUrl("");
87 #endif