From b4d02bda277f83fd646652942abe7548c97cd561 Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Mon, 29 Aug 2011 10:51:42 +0000 Subject: [PATCH] show an error message box if no accessible devices are found on program launch svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1250081 --- src/main.cpp | 3 +++ src/util/helpers.cpp | 16 ++++++++++++++-- src/util/helpers.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8534c8c..87d069a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,6 +51,9 @@ int main(int argc, char* argv[]) if (!loadBackend()) return 0; + if (!checkAccessibleDevices()) + return 0; + MainWindow* mainWindow = new MainWindow(); mainWindow->show(); diff --git a/src/util/helpers.cpp b/src/util/helpers.cpp index aa3f2c0..cb61cdb 100644 --- a/src/util/helpers.cpp +++ b/src/util/helpers.cpp @@ -203,6 +203,20 @@ bool loadBackend() return true; } +bool checkAccessibleDevices() +{ + if (getSolidDeviceList().empty()) + { + KMessageBox::error(NULL, + i18nc("@info", "No usable devices could be found.Make sure you have sufficient " + "privileges to access block devices on your system."), + i18nc("@title:window", "Error: No Usable Devices Found")); + return false; + } + + return true; +} + QList getSolidDeviceList() { QString predicate = "StorageDrive.driveType == 'HardDisk'"; @@ -229,7 +243,5 @@ QList getSolidDeviceList() predicate += ']'; } - kDebug() << predicate; - return Solid::Device::listFromQuery(predicate); } diff --git a/src/util/helpers.h b/src/util/helpers.h index 03a0d8f..f5698ed 100644 --- a/src/util/helpers.h +++ b/src/util/helpers.h @@ -52,4 +52,6 @@ LIBPARTITIONMANAGERPRIVATE_EXPORT bool loadBackend(); LIBPARTITIONMANAGERPRIVATE_EXPORT QList getSolidDeviceList(); +LIBPARTITIONMANAGERPRIVATE_EXPORT bool checkAccessibleDevices(); + #endif