[virt-tools-list] [RFC virt-viewer 02/12] vv-file: Refactor virt_viewer_file_check_min_version

Christophe Fergeau cfergeau at redhat.com
Tue Jun 2 14:29:19 UTC 2015


Reorganize the code a bit so that it's easier to extend it.
---
 src/virt-viewer-file.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
index 8b732a3..23eae31 100644
--- a/src/virt-viewer-file.c
+++ b/src/virt-viewer-file.c
@@ -710,22 +710,25 @@ spice_hotkey_set_accel(const gchar *accel_path, const gchar *key)
 static gboolean
 virt_viewer_file_check_min_version(VirtViewerFile *self, GError **error)
 {
+    gchar *min_version = NULL;
+    gint version_cmp;
+
     if (virt_viewer_file_is_set(self, "version")) {
-        gchar *val = virt_viewer_file_get_version(self);
-
-        if (virt_viewer_compare_version(val, PACKAGE_VERSION) > 0) {
-            g_set_error(error,
-                VIRT_VIEWER_ERROR,
-                VIRT_VIEWER_ERROR_FAILED,
-                _("At least %s version %s is required to setup this connection"),
-                g_get_application_name(), val);
+        min_version = virt_viewer_file_get_version(self);
+    }
 
-            g_free(val);
-            return FALSE;
-        }
+    version_cmp = virt_viewer_compare_version(min_version, PACKAGE_VERSION);
 
-        g_free(val);
+    if (version_cmp > 0) {
+        g_set_error(error,
+                    VIRT_VIEWER_ERROR,
+                    VIRT_VIEWER_ERROR_FAILED,
+                    _("At least %s version %s is required to setup this connection"),
+                    g_get_application_name(), min_version);
+        g_free(min_version);
+        return FALSE;
     }
+    g_free(min_version);
 
     return TRUE;
 }
-- 
2.4.2




More information about the virt-tools-list mailing list