Boot2Qt: Simplify QdbUtils

Change-Id: Ief211d00812284828197f34bc2aaf4a72bdffda4
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-06-12 18:12:04 +02:00
parent 65658f411b
commit 91ba57399c
4 changed files with 12 additions and 38 deletions

View File

@@ -143,7 +143,7 @@ QdbDevice::QdbDevice()
}}); }});
addDeviceAction({tr("Restore Default App"), [](const IDevice::Ptr &device, QWidget *) { addDeviceAction({tr("Restore Default App"), [](const IDevice::Ptr &device, QWidget *) {
CommandLine cmd{FilePath::fromString(appControllerFilePath()), {"--remove-default"}}; CommandLine cmd{FilePath::fromString("appcontroller"), {"--remove-default"}};
(void) new DeviceApplicationObserver(device, cmd); (void) new DeviceApplicationObserver(device, cmd);
}}); }});
} }

View File

@@ -78,6 +78,15 @@ static void startFlashingWizard()
showMessage(message.arg(filePath), true); showMessage(message.arg(filePath), true);
} }
static bool isFlashActionDisabled()
{
QSettings * const settings = Core::ICore::settings();
settings->beginGroup(settingsGroupKey());
bool disabled = settings->value("flashActionDisabled", false).toBool();
settings->endGroup();
return disabled;
}
void registerFlashAction(QObject *parentForAction) void registerFlashAction(QObject *parentForAction)
{ {
if (isFlashActionDisabled()) if (isFlashActionDisabled())

View File

@@ -39,8 +39,6 @@ namespace Internal {
static QString executableBaseName(QdbTool tool) static QString executableBaseName(QdbTool tool)
{ {
switch (tool) { switch (tool) {
case QdbTool::Adb:
return QLatin1String("adb");
case QdbTool::FlashingWizard: case QdbTool::FlashingWizard:
return QLatin1String("b2qt-flashing-wizard"); return QLatin1String("b2qt-flashing-wizard");
case QdbTool::Qdb: case QdbTool::Qdb:
@@ -50,24 +48,15 @@ static QString executableBaseName(QdbTool tool)
return QString(); return QString();
} }
QString appControllerFilePath() Utils::FilePath findTool(QdbTool tool)
{
return QLatin1String("appcontroller");
}
Utils::FilePath findTool(QdbTool tool, PathSource *source)
{ {
QString filePath = QString::fromLocal8Bit(qgetenv(overridingEnvironmentVariable(tool))); QString filePath = QString::fromLocal8Bit(qgetenv(overridingEnvironmentVariable(tool)));
if (source)
*source = PathSource::Environment;
if (filePath.isEmpty()) { if (filePath.isEmpty()) {
QSettings * const settings = Core::ICore::settings(); QSettings * const settings = Core::ICore::settings();
settings->beginGroup(settingsGroupKey()); settings->beginGroup(settingsGroupKey());
filePath = settings->value(settingsKey(tool)).toString(); filePath = settings->value(settingsKey(tool)).toString();
settings->endGroup(); settings->endGroup();
if (source)
*source = PathSource::Settings;
} }
if (filePath.isEmpty()) { if (filePath.isEmpty()) {
@@ -79,27 +68,14 @@ Utils::FilePath findTool(QdbTool tool, PathSource *source)
+ QLatin1String("/../../b2qt/") + QLatin1String("/../../b2qt/")
#endif #endif
+ executableBaseName(tool)); + executableBaseName(tool));
if (source)
*source = PathSource::Fallback;
} }
return Utils::FilePath::fromString(QDir::cleanPath(filePath)); return Utils::FilePath::fromString(QDir::cleanPath(filePath));
} }
bool isFlashActionDisabled()
{
QSettings * const settings = Core::ICore::settings();
settings->beginGroup(settingsGroupKey());
bool disabled = settings->value("flashActionDisabled", false).toBool();
settings->endGroup();
return disabled;
}
const char *overridingEnvironmentVariable(QdbTool tool) const char *overridingEnvironmentVariable(QdbTool tool)
{ {
switch (tool) { switch (tool) {
case QdbTool::Adb:
return "BOOT2QT_ADB_FILEPATH";
case QdbTool::FlashingWizard: case QdbTool::FlashingWizard:
return "BOOT2QT_FLASHWIZARD_FILEPATH"; return "BOOT2QT_FLASHWIZARD_FILEPATH";
case QdbTool::Qdb: case QdbTool::Qdb:
@@ -124,8 +100,6 @@ QString settingsGroupKey()
QString settingsKey(QdbTool tool) QString settingsKey(QdbTool tool)
{ {
switch (tool) { switch (tool) {
case QdbTool::Adb:
return QLatin1String("adbFilePath");
case QdbTool::FlashingWizard: case QdbTool::FlashingWizard:
return QLatin1String("flashingWizardFilePath"); return QLatin1String("flashingWizardFilePath");
case QdbTool::Qdb: case QdbTool::Qdb:

View File

@@ -33,20 +33,11 @@ namespace Qdb {
namespace Internal { namespace Internal {
enum class QdbTool { enum class QdbTool {
Adb,
FlashingWizard, FlashingWizard,
Qdb Qdb
}; };
enum class PathSource { Utils::FilePath findTool(QdbTool tool);
Environment,
Settings,
Fallback
};
QString appControllerFilePath();
Utils::FilePath findTool(QdbTool tool, PathSource *source = nullptr);
bool isFlashActionDisabled();
const char *overridingEnvironmentVariable(QdbTool tool); const char *overridingEnvironmentVariable(QdbTool tool);
void showMessage(const QString &message, bool important = false); void showMessage(const QString &message, bool important = false);
QString settingsGroupKey(); QString settingsGroupKey();