summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-24 22:31:07 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-24 22:31:07 +0000
commitb208000c3649526d0eeb73a328e4052759bc773c (patch)
tree675e8453392a664b859c129154d60b710b577966 /rbutil/rbutilqt
parent637146017289dd394a6f68327c56867fa8747dc5 (diff)
downloadrockbox-b208000c3649526d0eeb73a328e4052759bc773c.tar.gz
rockbox-b208000c3649526d0eeb73a328e4052759bc773c.tar.bz2
rockbox-b208000c3649526d0eeb73a328e4052759bc773c.zip
Make Detect::check() return an error string instead of a boolean result and move the handling of an occurred error to the application to make detection Gui-clean. Move detect class to base folder.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18873 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/base/detect.cpp (renamed from rbutil/rbutilqt/detect.cpp)65
-rw-r--r--rbutil/rbutilqt/base/detect.h (renamed from rbutil/rbutilqt/detect.h)8
-rw-r--r--rbutil/rbutilqt/install.cpp26
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp21
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro4
5 files changed, 63 insertions, 61 deletions
diff --git a/rbutil/rbutilqt/detect.cpp b/rbutil/rbutilqt/base/detect.cpp
index 7c3d949012..d2a65ee72f 100644
--- a/rbutil/rbutilqt/detect.cpp
+++ b/rbutil/rbutilqt/base/detect.cpp
@@ -22,10 +22,9 @@
#include <QtCore>
#include <QDebug>
+
#include <cstdlib>
#include <stdio.h>
-#include <QMessageBox>
-
// Windows Includes
#if defined(Q_OS_WIN32)
@@ -72,11 +71,11 @@ enum Detect::userlevel Detect::userPermissions(void)
DWORD usersize = UNLEN;
BOOL status;
enum userlevel result;
-
+
status = GetUserNameW(userbuf, &usersize);
if(!status)
return ERR;
-
+
napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf);
switch(buf->usri1_priv) {
@@ -122,7 +121,7 @@ QString Detect::userPermissionsString(void)
return result;
}
#endif
-
+
/** @brief detects current Username.
* @return string with Username.
@@ -133,7 +132,7 @@ QString Detect::userName(void)
wchar_t userbuf[UNLEN];
DWORD usersize = UNLEN;
BOOL status;
-
+
status = GetUserNameW(userbuf, &usersize);
return QString::fromWCharArray(userbuf);
@@ -331,7 +330,7 @@ QUrl Detect::systemProxy(void)
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("");
@@ -341,9 +340,9 @@ QUrl Detect::systemProxy(void)
if(enable != 0)
return QUrl("http://" + QString::fromWCharArray(proxyval));
else
- return QUrl("");
+ return QUrl("");
#else
- return QUrl("");
+ return QUrl("");
#endif
}
@@ -359,14 +358,14 @@ QString Detect::installedVersion(QString mountpoint)
{
return "";
}
-
+
while (!info.atEnd()) {
QString line = info.readLine();
-
+
if(line.contains("Version:"))
{
return line.remove("Version:").trimmed();
- }
+ }
}
info.close();
return "";
@@ -384,15 +383,15 @@ int Detect::installedTargetId(QString mountpoint)
{
return -1;
}
-
- while (!info.atEnd())
+
+ while (!info.atEnd())
{
QString line = info.readLine();
if(line.contains("Target id:"))
{
qDebug() << line;
return line.remove("Target id:").trimmed().toInt();
- }
+ }
}
info.close();
return -1;
@@ -403,9 +402,9 @@ int Detect::installedTargetId(QString mountpoint)
* @param settings A pointer to rbutils settings class
* @param permission if it should check for permission
* @param targetId the targetID to check for. if it is -1 no check is done.
- * @return true if everything is ok, or user wants to continue
+ * @return string with error messages if problems occurred, empty strings if none.
*/
-bool Detect::check(RbSettings* settings,bool permission,int targetId)
+QString Detect::check(RbSettings* settings, bool permission, int targetId)
{
QString text = "";
@@ -415,36 +414,28 @@ bool Detect::check(RbSettings* settings,bool permission,int targetId)
#if defined(Q_OS_WIN32)
if(Detect::userPermissions() != Detect::ADMIN)
{
- text += QObject::tr("Permissions are not sufficient! \n Run with admin rights. \n\n");
- }
+ text += QObject::tr("<li>Permissions insufficient for bootloader "
+ "installation.\nAdministrator priviledges are necessary.</li>");
+ }
#endif
}
// Check TargetId
if(targetId > 0)
- {
+ {
int installedID = Detect::installedTargetId(settings->mountpoint());
if( installedID != -1 && installedID != targetId)
{
- text += QObject::tr("Target mismatch detected. \n\n"
- "Installed target: %1.\n"
- "New Target: %2.\n\n").arg(settings->nameOfTargetId(installedID),settings->curName());
-
- }
- }
-
- // show message Box
- if(text != "")
- {
- text += QObject::tr("\n Do you want to continue ?");
- if(QMessageBox::warning(NULL, QObject::tr("Problems detected"),text,
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
- {
- return false;
- }
+ text += QObject::tr("<li>Target mismatch detected.\n"
+ "Installed target: %1, selected target: %2.</li>")
+ .arg(settings->nameOfTargetId(installedID),settings->curName());
+ }
}
- return true;
+ if(!text.isEmpty())
+ return QObject::tr("Problem detected:") + "<ul>" + text + "</ul>";
+ else
+ return text;
}
diff --git a/rbutil/rbutilqt/detect.h b/rbutil/rbutilqt/base/detect.h
index f72a8a6530..00a8daaef7 100644
--- a/rbutil/rbutilqt/detect.h
+++ b/rbutil/rbutilqt/base/detect.h
@@ -27,17 +27,17 @@
#include <QUrl>
#include "rbsettings.h"
-class Detect
+class Detect
{
public:
Detect() {}
-
+
#if defined(Q_OS_WIN32)
enum userlevel { ERR, GUEST, USER, ADMIN };
static enum userlevel userPermissions(void);
static QString userPermissionsString(void);
#endif
-
+
static QString userName(void);
static QString osVersionString(void);
static QList<uint32_t> listUsbIds(void);
@@ -47,7 +47,7 @@ public:
static QString installedVersion(QString mountpoint);
static int installedTargetId(QString mountpoint);
- static bool check(RbSettings* settings,bool permission,int targetId);
+ static QString check(RbSettings* settings, bool permission, int targetId);
};
#endif
diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp
index d9c750ea4d..ee0d2114da 100644
--- a/rbutil/rbutilqt/install.cpp
+++ b/rbutil/rbutilqt/install.cpp
@@ -120,19 +120,25 @@ void Install::accept()
return;
}
settings->sync();
-
- if(Detect::check(settings,false,settings->curTargetId()) == false)
+
+ QString warning = Detect::check(settings, false, settings->curTargetId());
+ if(!warning.isEmpty())
{
- logger->addItem(tr("Aborted!"),LOGERROR);
- logger->abort();
- return;
- }
-
+ if(QMessageBox::warning(this, tr("Really continue?"), warning,
+ QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
+ == QMessageBox::Abort)
+ {
+ logger->addItem(tr("Aborted!"),LOGERROR);
+ logger->abort();
+ return;
+ }
+ }
+
//! check if we should backup
if(ui.backup->isChecked())
{
logger->addItem(tr("Beginning Backup..."),LOGINFO);
-
+
//! create dir, if it doesnt exist
QFileInfo backupFile(m_backupName);
if(!QDir(backupFile.path()).exists())
@@ -140,7 +146,7 @@ void Install::accept()
QDir a;
a.mkpath(backupFile.path());
}
-
+
//! create backup
RbZip backup;
connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
@@ -155,7 +161,7 @@ void Install::accept()
return;
}
}
-
+
//! install build
installer = new ZipInstaller(this);
installer->setUrl(file);
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp
index e9f6f7fcf2..8c0691c52b 100644
--- a/rbutil/rbutilqt/rbutilqt.cpp
+++ b/rbutil/rbutilqt/rbutilqt.cpp
@@ -496,17 +496,22 @@ bool RbUtilQt::installAuto()
}
QString myversion = "r" + versmap.value("bleed_rev");
-
+
// check installed Version and Target
- QString rbVersion = Detect::installedVersion(settings->mountpoint());
+ QString rbVersion = Detect::installedVersion(settings->mountpoint());
+ QString warning = Detect::check(settings, false, settings->curTargetId());
- if(Detect::check(settings,false,settings->curTargetId()) == false)
+ if(!warning.isEmpty())
{
- logger->addItem(tr("Aborted!"),LOGERROR);
- logger->abort();
- return false;
+ if(QMessageBox::warning(this, tr("Really continue?"), warning,
+ QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort) == QMessageBox::Abort)
+ {
+ logger->addItem(tr("Aborted!"), LOGERROR);
+ logger->abort();
+ return false;
+ }
}
-
+
// check version
if(rbVersion != "")
{
@@ -516,7 +521,7 @@ bool RbUtilQt::installAuto()
{
logger->addItem(tr("Starting backup..."),LOGINFO);
QString backupName = settings->mountpoint() + "/.backup/rockbox-backup-"+rbVersion+".zip";
-
+
//! create dir, if it doesnt exist
QFileInfo backupFile(backupName);
if(!QDir(backupFile.path()).exists())
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index 9fc74da25a..bf6e7459d1 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -74,7 +74,7 @@ SOURCES += rbutilqt.cpp \
rbsettings.cpp \
base/rbunzip.cpp \
base/rbzip.cpp \
- detect.cpp \
+ base/detect.cpp \
sysinfo.cpp \
base/bootloaderinstallbase.cpp \
base/bootloaderinstallmi4.cpp \
@@ -127,7 +127,7 @@ HEADERS += rbutilqt.h \
base/rbunzip.h \
base/rbzip.h \
sysinfo.h \
- detect.h \
+ base/detect.h \
base/bootloaderinstallbase.h \
base/bootloaderinstallmi4.h \
base/bootloaderinstallhex.h \