Просмотр исходного кода

added support for installing in /opt, improved error handling and the helper binary is now always installed in /usr

Malte Veerman 9 лет назад
Родитель
Сommit
ca7bb5a6cc

+ 12 - 10
fancontrol-gui/src/main.cpp

@@ -65,21 +65,23 @@ int main(int argc, char *argv[])
     context->setContextProperty(QStringLiteral("windowConfig"), windowConfig);
 
     KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML"));
-    package.setDefaultPackageRoot(QStringLiteral("/usr/local/share/kpackage/kcms"));
-    package.setPath(QStringLiteral("kcm_fancontrol"));
-    package.addFileDefinition("appqmlroot", QStringLiteral("ui/Application.qml"), i18n("The Application's root QML file"));
-    package.setRequired("appqmlroot", true);
-    
-    if (!package.isValid())
+    QStringList possiblePackageLocations = QStringList() << QStringLiteral("/usr/local/share/kpackage/kcms") 
+                                                         << QStringLiteral("kpackage/kcms")
+                                                         << QStringLiteral("/opt/share/kpackage/kcms");
+
+    for (int i=0; i<possiblePackageLocations.size(); i++)
     {
-        package.setDefaultPackageRoot(QStringLiteral("/usr/share/kpackage/kcms"));
+        package.setDefaultPackageRoot(possiblePackageLocations.at(i));
         package.setPath(QStringLiteral("kcm_fancontrol"));
         package.addFileDefinition("appqmlroot", QStringLiteral("ui/Application.qml"), i18n("The Application's root QML file"));
         package.setRequired("appqmlroot", true);
+        
+        if (package.isValid())
+        {
+            engine->load(QUrl::fromLocalFile(package.filePath("appqmlroot")));
+            break;
+        }
     }
-    
-    if (package.isValid())
-        engine->load(QUrl::fromLocalFile(package.filePath("appqmlroot")));
 
     return app.exec();
 }

+ 3 - 5
helper/CMakeLists.txt

@@ -12,13 +12,11 @@ find_package(KF5Auth REQUIRED)
 
 add_executable(fancontrol-gui-helper src/helper.cpp)
 target_link_libraries(fancontrol-gui-helper ${LIBRARIES})
-install(TARGETS fancontrol-gui-helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
+install(TARGETS fancontrol-gui-helper DESTINATION ${KAUTH_HELPER_INSTALL_ABSOLUTE_DIR})
 
 kauth_install_helper_files(fancontrol-gui-helper fancontrol.gui.helper root)
 kauth_install_actions(fancontrol.gui.helper fancontrol_gui.actions)
 
-message(STATUS "${CMAKE_INSTALL_PREFIX}")
-
-if(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr") 
-    install(SCRIPT MoveSystemFiles.cmake)
+if(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr")
+    install(SCRIPT CreateSystemSymlinks.cmake)
 endif(NOT ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr")

+ 23 - 0
helper/CreateSystemSymlinks.cmake

@@ -0,0 +1,23 @@
+
+set(helper_conf_file "etc/dbus-1/system.d/fancontrol.gui.helper.conf")
+set(helper_service_file "share/dbus-1/system-services/fancontrol.gui.helper.service")
+set(helper_conf_file_destination "/${helper_conf_file}")
+set(helper_service_file_destination "/usr/${helper_service_file}")
+
+
+execute_process(COMMAND ln -sf ${CMAKE_INSTALL_PREFIX}/${helper_conf_file} ${helper_conf_file_destination} RESULT_VARIABLE result OUTPUT_VARIABLE output)
+message(STATUS "Creating symlink: ${helper_conf_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_conf_file}")
+
+if(${result})
+    message(WARNING "Creation of symlink ${helper_conf_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_conf_file} failed:")
+    message(WARNING "${output}")
+endif(${result})
+
+
+execute_process(COMMAND ln -sf ${CMAKE_INSTALL_PREFIX}/${helper_service_file} ${helper_service_file_destination} RESULT_VARIABLE result OUTPUT_VARIABLE output)
+message(STATUS "Creating symlink: ${helper_service_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_service_file}")
+
+if(${result})
+    message(WARNING "Creation of symlink ${helper_service_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_service_file} failed:")
+    message(WARNING "${output}")
+endif(${result})

+ 0 - 35
helper/MoveSystemFiles.cmake

@@ -1,35 +0,0 @@
-# file(RENAME "${CMAKE_INSTALL_PREFIX} "/etc/dbus-1/system.d/fancontrol.gui.helper.conf")
-# file(RENAME "${CMAKE_INSTALL_PREFIX}/lib/kauth/fancontrol-gui-helper" "/usr/lib/kauth/fancontrol-gui-helper")
-# file(RENAME "${CMAKE_INSTALL_PREFIX}/share/dbus-1/system-services/fancontrol.gui.helper.service" "/usr/share/dbus-1/system-services/fancontrol.gui.helper.service")
-
-set(helper_conf_file "etc/dbus-1/system.d/fancontrol.gui.helper.conf")
-set(helper_bin_file "lib/kauth/fancontrol-gui-helper")
-set(helper_service_file "share/dbus-1/system-services/fancontrol.gui.helper.service")
-set(helper_conf_file_destination "/${helper_conf_file}")
-set(helper_bin_file_destination "/usr/${helper_bin_file}")
-set(helper_service_file_destination "/usr/${helper_service_file}")
-set(install_manifest_path "${CMAKE_SOURCE_DIR}/install_manifest.txt")
-
-execute_process(COMMAND ln -sf ${CMAKE_INSTALL_PREFIX}/${helper_conf_file} ${helper_conf_file_destination} RESULT_VARIABLE result OUTPUT_VARIABLE output)
-message(STATUS "Creating symlink: ${helper_conf_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_conf_file}")
-
-if(${result})
-    message(WARNING "Creation of symlink ${helper_conf_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_conf_file} ${result} ${output} failed:")
-    message(WARNING "${output}")
-endif(${result})
-
-execute_process(COMMAND ln -sf ${CMAKE_INSTALL_PREFIX}/${helper_bin_file} ${helper_bin_file_destination} RESULT_VARIABLE result OUTPUT_VARIABLE output)
-message(STATUS "Creating symlink: ${helper_bin_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_bin_file}")
-
-if(${result})
-    message(WARNING "Creation of symlink ${helper_bin_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_bin_file} ${result} ${output} failed:")
-    message(WARNING "${output}")
-endif(${result})
-
-execute_process(COMMAND ln -sf ${CMAKE_INSTALL_PREFIX}/${helper_service_file} ${helper_service_file_destination} RESULT_VARIABLE result OUTPUT_VARIABLE output)
-message(STATUS "Creating symlink: ${helper_service_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_service_file}")
-
-if(${result})
-    message(WARNING "Creation of symlink ${helper_service_file_destination} -> ${CMAKE_INSTALL_PREFIX}/${helper_service_file} ${result} ${output} failed:")
-    message(WARNING "${output}")
-endif(${result})

+ 15 - 3
lib/src/loader.cpp

@@ -272,7 +272,13 @@ bool Loader::load(const QUrl &url)
         KAuth::ExecuteJob *reply = action.execute();
         if (!reply->exec())
         {
-            qDebug() << reply->error();
+            if (reply->error() == 4)
+            {
+                qDebug() << "Aborted by user";
+                return false;
+            }
+            
+            qDebug() << "Error while loading:" << reply->error();
             setError(reply->errorString() + reply->errorText(), true);
             return false;
         }
@@ -495,7 +501,13 @@ bool Loader::save(const QUrl &url)
 
         if (!reply->exec())
         {
-            qDebug() << reply->error();
+            if (reply->error() == 4)
+            {
+                qDebug() << "Aborted by user";
+                return false;
+            }
+            
+            qDebug() << "Error while saving:" << reply->error();
             setError(reply->errorString() + reply->errorText(), true);
             return false;
         }
@@ -678,7 +690,7 @@ void Loader::handleDetectSensorsResult(KJob *job)
 {
     if (job->error())
     {
-        qDebug() << job->error();
+        qDebug() << "Error while detecting sensors:" << job->error();
         setError(job->errorString() + job->errorText(), true);
     }
     else