Blame SOURCES/0163-p2v-Factor-out-code-for-parsing-vcpus-memory-from-co.patch

ffd6ed
From d0c304a1e5aab10933ab4a3b625bc37f223d9d17 Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Tue, 5 May 2015 15:09:13 +0100
ffd6ed
Subject: [PATCH] p2v: Factor out code for parsing vcpus & memory from
ffd6ed
 conversion dialog.
ffd6ed
ffd6ed
No functional change, just code refactoring.
ffd6ed
ffd6ed
(cherry picked from commit b1336f26e6a4a643eefd7422e8cd2d4520b1a565)
ffd6ed
---
ffd6ed
 p2v/gui.c | 42 ++++++++++++++++++++++++++++++------------
ffd6ed
 1 file changed, 30 insertions(+), 12 deletions(-)
ffd6ed
ffd6ed
diff --git a/p2v/gui.c b/p2v/gui.c
ffd6ed
index 5065560..8a5cda1 100644
ffd6ed
--- a/p2v/gui.c
ffd6ed
+++ b/p2v/gui.c
ffd6ed
@@ -375,6 +375,8 @@ static void set_interfaces_from_ui (struct config *);
ffd6ed
 static void conversion_back_clicked (GtkWidget *w, gpointer data);
ffd6ed
 static void start_conversion_clicked (GtkWidget *w, gpointer data);
ffd6ed
 static void notify_ui_callback (int type, const char *data);
ffd6ed
+static int get_vcpus_from_conv_dlg (void);
ffd6ed
+static uint64_t get_memory_from_conv_dlg (void);
ffd6ed
 
ffd6ed
 enum {
ffd6ed
   DISKS_COL_CONVERT = 0,
ffd6ed
@@ -1051,6 +1053,32 @@ conversion_back_clicked (GtkWidget *w, gpointer data)
ffd6ed
   gtk_widget_set_sensitive (next_button, FALSE);
ffd6ed
 }
ffd6ed
 
ffd6ed
+static int
ffd6ed
+get_vcpus_from_conv_dlg (void)
ffd6ed
+{
ffd6ed
+  const char *str;
ffd6ed
+  int i;
ffd6ed
+
ffd6ed
+  str = gtk_entry_get_text (GTK_ENTRY (vcpus_entry));
ffd6ed
+  if (sscanf (str, "%d", &i) == 1 && i > 0)
ffd6ed
+    return i;
ffd6ed
+  else
ffd6ed
+    return 1;
ffd6ed
+}
ffd6ed
+
ffd6ed
+static uint64_t
ffd6ed
+get_memory_from_conv_dlg (void)
ffd6ed
+{
ffd6ed
+  const char *str;
ffd6ed
+  uint64_t i;
ffd6ed
+
ffd6ed
+  str = gtk_entry_get_text (GTK_ENTRY (memory_entry));
ffd6ed
+  if (sscanf (str, "%" SCNu64, &i) == 1 && i >= 256)
ffd6ed
+    return i * 1024 * 1024;
ffd6ed
+  else
ffd6ed
+    return UINT64_C (1024) * 1024 * 1024;
ffd6ed
+}
ffd6ed
+
ffd6ed
 /*----------------------------------------------------------------------*/
ffd6ed
 /* Running dialog. */
ffd6ed
 
ffd6ed
@@ -1174,7 +1202,6 @@ static void
ffd6ed
 start_conversion_clicked (GtkWidget *w, gpointer data)
ffd6ed
 {
ffd6ed
   struct config *config = data;
ffd6ed
-  int i;
ffd6ed
   const char *str;
ffd6ed
   char *str2;
ffd6ed
   GtkWidget *dlg;
ffd6ed
@@ -1200,17 +1227,8 @@ start_conversion_clicked (GtkWidget *w, gpointer data)
ffd6ed
     return;
ffd6ed
   }
ffd6ed
 
ffd6ed
-  str = gtk_entry_get_text (GTK_ENTRY (vcpus_entry));
ffd6ed
-  if (sscanf (str, "%d", &i) == 1 && i > 0)
ffd6ed
-    config->vcpus = i;
ffd6ed
-  else
ffd6ed
-    config->vcpus = 1;
ffd6ed
-
ffd6ed
-  str = gtk_entry_get_text (GTK_ENTRY (memory_entry));
ffd6ed
-  if (sscanf (str, "%d", &i) == 1 && i >= 256)
ffd6ed
-    config->memory = (uint64_t) i * 1024 * 1024;
ffd6ed
-  else
ffd6ed
-    config->memory = 1024 * 1024 * 1024;
ffd6ed
+  config->vcpus = get_vcpus_from_conv_dlg ();
ffd6ed
+  config->memory = get_memory_from_conv_dlg ();
ffd6ed
 
ffd6ed
   config->verbose =
ffd6ed
     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (debug_button));
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed