Ver Fonte

improvements to url handling in loader

Malte Veerman há 9 anos atrás
pai
commit
51e6d29781

+ 20 - 3
lib/src/loader.cpp

@@ -245,6 +245,12 @@ bool Loader::load(const QUrl &url)
 
     if (file.open(QFile::ReadOnly | QFile::Text))
     {
+        if (!url.isEmpty())
+        {
+            m_configUrl = url;
+            emit configUrlChanged();
+        }
+        
         stream.setDevice(&file);
         fileContent = stream.readAll();
     }
@@ -264,12 +270,23 @@ bool Loader::load(const QUrl &url)
         }
         else
         {
+            if (!url.isEmpty())
+            {
+                m_configUrl = url;
+                emit configUrlChanged();
+            }
+            
             fileContent = reply->data()["content"].toString();
         }
     }
     else
-    {
-        setError(file.fileName() + " does not exist!");
+    {     
+        if (!url.isEmpty())
+        {
+            emit invalidConfigUrl();
+            setError(file.fileName() + " does not exist!");
+        }
+        
         return false;
     }
 
@@ -404,7 +421,7 @@ bool Loader::save(const QUrl &url)
 
     else
     {
-        setError("Url is not a local file");
+        setError(url.toDisplayString() + " is not a local file!");
         return false;
     }
 

+ 1 - 0
lib/src/loader.h

@@ -116,6 +116,7 @@ signals:
     void sensorsUpdateNeeded();
     void allPwmFansChanged();
     void allTempsChanged();
+    void invalidConfigUrl();
 };
 
 }

+ 1 - 1
package/contents/ui/Application.qml

@@ -133,7 +133,7 @@ ApplicationWindow {
         text: i18n("Save configuration file")
         onTriggered: base.loader.save()
         iconName: "document-save"
-        tooltip: i18n("Save configuration file")
+        tooltip: i18n("Save configuration file") + " (" + base.loader.configUrl.toString() + ")"
         shortcut: StandardKey.Save
     }
     

+ 14 - 0
package/contents/ui/KCM.qml

@@ -21,6 +21,7 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.3
 import QtQuick.Layouts 1.1
+import QtQuick.Dialogs 1.2
 import org.kde.kcm 1.0
 import "../scripts/arrayfunctions.js" as ArrayFunctions
 import "../scripts/units.js" as Units
@@ -230,6 +231,19 @@ Item {
         }
     }
     
+//     FileDialog {
+//         id: openFileDialog
+//         title: i18n("Please choose a configuration file")
+//         folder: "file:///etc"
+//         selectExisting: true
+//         selectMultiple: false
+//         modality: Qt.NonModal
+//         
+//         onAccepted: {
+//             base.loader.load(fileUrl);
+//         }
+//     }
+    
     ErrorDialog {
         id: errorDialog
         visible: !!base.loader.error