[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 14/96: Properly deal with no configuration file and defaults in various classes

noreply at xfce.org noreply at xfce.org
Thu Nov 27 22:20:19 CET 2014


This is an automated email from the git hooks/post-receive script.

nick pushed a commit to branch master
in repository panel-plugins/xfce4-hardware-monitor-plugin.

commit 5c598884fcf83d96aed8eaf0b3ab90e0ec6a409c
Author: Omega Weapon <OmegaPhil at gmail.com>
Date:   Sun Oct 27 13:47:35 2013 +0000

    Properly deal with no configuration file and defaults in various classes
---
 src/bar-view.cpp              |   69 ++++++++++++++++++-----------------------
 src/canvas-view.cpp           |   64 +++++++++++++++++---------------------
 src/choose-monitor-window.cpp |    6 +---
 src/column-view.cpp           |   58 +++++++++++++++-------------------
 src/curve-view.cpp            |   62 ++++++++++++++++--------------------
 src/flame-view.cpp            |   58 +++++++++++++++-------------------
 src/text-view.cpp             |   62 ++++++++++++++++--------------------
 7 files changed, 164 insertions(+), 215 deletions(-)

diff --git a/src/bar-view.cpp b/src/bar-view.cpp
index 269cd09..51e1ecc 100644
--- a/src/bar-view.cpp
+++ b/src/bar-view.cpp
@@ -102,9 +102,11 @@ void Bar::draw(Gnome::Canvas::Canvas &canvas,
 	       double time_offset)
 {
   // Get drawing attributes
-  unsigned int fill_color;
+  unsigned int fill_color = applet->get_fg_color();
+  bool color_missing = true;
 
-  // Fetching assigned settings group
+  /* Loading fill_color from settings if it exists
+   * Fetching assigned settings group */
   Glib::ustring dir = monitor->get_settings_dir();
 
   // Search for settings file
@@ -117,55 +119,44 @@ void Bar::draw(Gnome::Canvas::Canvas &canvas,
     g_free(file);
 
     // Loading color
-    bool color_missing = false;
     xfce_rc_set_group(settings, dir.c_str());
     if (xfce_rc_has_entry(settings, "color"))
     {
       fill_color = xfce_rc_read_int_entry(settings, "color",
                                           applet->get_fg_color());
+      color_missing = false;
     }
-    else
-      color_missing = true;
 
     // Close settings file
     xfce_rc_close(settings);
+  }
+
+  /* Saving color if it was not recorded. XFCE4 configuration is done in
+   * read and write stages, so this needs to be separated */
+  if (color_missing)
+  {
+    // Search for a writeable settings file, create one if it doesnt exist
+    file = xfce_panel_plugin_save_location(applet->panel_applet, true);
 
-    /* Color not recorded - setting default then updating config. XFCE4
-     * configuration is done in read and write stages, so this needs to
-     * be separated */
-    if (color_missing)
+    if (file)
     {
-      fill_color = applet->get_fg_color();
-
-      // Search for a writeable settings file, create one if it doesnt exist
-      file = xfce_panel_plugin_save_location(applet->panel_applet, true);
-
-      if (file)
-      {
-        // Opening setting file
-        settings = xfce_rc_simple_open(file, false);
-        g_free(file);
-
-        // Saving color
-        xfce_rc_set_group(settings, dir.c_str());
-        xfce_rc_write_int_entry(settings, "color", int(fill_color));
-
-        // Close settings file
-        xfce_rc_close(settings);
-      }
-      else
-      {
-        // Unable to obtain writeable config file - informing user
-        std::cerr << _("Unable to obtain writeable config file path in "
-          "order to update color in Bar::draw call!\n");
-      }
+      // Opening setting file
+      settings = xfce_rc_simple_open(file, false);
+      g_free(file);
+
+      // Saving color
+      xfce_rc_set_group(settings, dir.c_str());
+      xfce_rc_write_int_entry(settings, "color", int(fill_color));
+
+      // Close settings file
+      xfce_rc_close(settings);
+    }
+    else
+    {
+      // Unable to obtain writeable config file - informing user
+      std::cerr << _("Unable to obtain writeable config file path in "
+        "order to update color in Bar::draw call!\n");
     }
-  }
-  else
-  {
-    // Unable to obtain read only config file - informing user
-    std::cerr << _("Unable to obtain read-only config file path in order"
-      " to load color in Bar::draw call!\n");
   }
   
   unsigned int outline_color = outlineified(fill_color);
diff --git a/src/canvas-view.cpp b/src/canvas-view.cpp
index 91b5b7c..7f4dee3 100644
--- a/src/canvas-view.cpp
+++ b/src/canvas-view.cpp
@@ -54,6 +54,9 @@ void CanvasView::do_display()
 
 void CanvasView::do_update()
 {
+  size = 60;
+  bool size_missing = true;
+
   /* Obtaining size
    * Keeping with the default settings group for viewer settings
    * Search for settings file */
@@ -66,51 +69,42 @@ void CanvasView::do_update()
     g_free(file);
 
     // Loading size
-    bool size_missing = false;
-    int size = 60;
     if (xfce_rc_has_entry(settings, "viewer_size"))
     {
       size = xfce_rc_read_int_entry(settings, "viewer_size", 60);
+      size_missing = false;
     }
-    else
-      size_missing = true;
 
     // Close settings file
     xfce_rc_close(settings);
+  }
 
-    /* Viewer size not recorded - setting default then updating config. XFCE4
-     * configuration is done in read and write stages, so this needs to
-     * be separated */
-    if (size_missing)
+  /* Setting default viewer size then updating config if it hasn't been
+   * saved. XFCE4 configuration is done in read and write stages, so
+   * this needs to be separated */
+  if (size_missing)
+  {
+    // Search for a writeable settings file, create one if it doesnt exist
+    file = xfce_panel_plugin_save_location(applet->panel_applet, true);
+
+    if (file)
     {
-      // Search for a writeable settings file, create one if it doesnt exist
-      file = xfce_panel_plugin_save_location(applet->panel_applet, true);
-	
-      if (file)
-      {
-        // Opening setting file
-        settings = xfce_rc_simple_open(file, false);
-        g_free(file);
-
-        // Saving viewer size
-        xfce_rc_write_int_entry(settings, "viewer_size", size);
-        
-        // Close settings file
-        xfce_rc_close(settings);
-      }
-      else
-      {
-        // Unable to obtain writeable config file - informing user
-        std::cerr << _("Unable to obtain writeable config file path in "
-          "order to update viewer size in CanvasView::do_update call!\n");
-      }
+      // Opening setting file
+      settings = xfce_rc_simple_open(file, false);
+      g_free(file);
+
+      // Saving viewer size
+      xfce_rc_write_int_entry(settings, "viewer_size", size);
+
+      // Close settings file
+      xfce_rc_close(settings);
+    }
+    else
+    {
+      // Unable to obtain writeable config file - informing user
+      std::cerr << _("Unable to obtain writeable config file path in "
+        "order to update viewer size in CanvasView::do_update call!\n");
     }
-  }
-  else
-  {
-    // Unable to obtain read only config file - informing user
-    std::cerr << _("Unable to obtain read-only config file path in order"
-      " to load viewer size in CanvasView::do_update call!\n");
   }
 
   // Ensure the canvas is shown
diff --git a/src/choose-monitor-window.cpp b/src/choose-monitor-window.cpp
index 21798f2..89bdf33 100644
--- a/src/choose-monitor-window.cpp
+++ b/src/choose-monitor-window.cpp
@@ -290,11 +290,7 @@ Monitor *ChooseMonitorWindow::run(XfcePanelPlugin* panel_applet,
     }
     else
     {
-      // Unable to obtain read-only config path
-      std::cerr << _("Unable to obtain read-only config file path in "
-	"order to configure monitor in ChooseMonitorWindow::run call!\n");
-
-      // Default setting?
+      // No configuration file present - default setting?
       device_notebook->set_current_page(0);
       // FIXME: use schema?
       cpu_usage_radiobutton->set_active();
diff --git a/src/column-view.cpp b/src/column-view.cpp
index 7ee25d6..5ffa0ea 100644
--- a/src/column-view.cpp
+++ b/src/column-view.cpp
@@ -85,6 +85,7 @@ void ColumnGraph::draw(Gnome::Canvas::Canvas &canvas,
 
   // Get default colour
   unsigned int color = applet->get_fg_color();
+  bool color_missing = true;
 
   // Fetching assigned settings group
   Glib::ustring dir = monitor->get_settings_dir();
@@ -99,53 +100,44 @@ void ColumnGraph::draw(Gnome::Canvas::Canvas &canvas,
     g_free(file);
 
     // Loading color
-    bool color_missing = false;
     xfce_rc_set_group(settings, dir.c_str());
     if (xfce_rc_has_entry(settings, "color"))
     {
       color = xfce_rc_read_int_entry(settings, "color",
         applet->get_fg_color());
+      color_missing = false;
     }
-    else
-      color_missing = true;
 
     // Close settings file
     xfce_rc_close(settings);
+  }
+
+  /* Saving color if it was not recorded. XFCE4 configuration is done in
+   * read and write stages, so this needs to be separated */
+  if (color_missing)
+  {
+    // Search for a writeable settings file, create one if it doesnt exist
+    file = xfce_panel_plugin_save_location(applet->panel_applet, true);
 
-    /* Color not recorded - setting default then updating config. XFCE4
-     * configuration is done in read and write stages, so this needs to
-     * be separated */
-    if (color_missing)
+    if (file)
     {
-      // Search for a writeable settings file, create one if it doesnt exist
-      file = xfce_panel_plugin_save_location(applet->panel_applet, true);
-	
-      if (file)
-      {
-        // Opening setting file
-        settings = xfce_rc_simple_open(file, false);
-        g_free(file);
+      // Opening setting file
+      settings = xfce_rc_simple_open(file, false);
+      g_free(file);
 
-        // Saving color
-        xfce_rc_set_group(settings, dir.c_str());
-        xfce_rc_write_int_entry(settings, "color", int(color));
+      // Saving color
+      xfce_rc_set_group(settings, dir.c_str());
+      xfce_rc_write_int_entry(settings, "color", int(color));
 
-        // Close settings file
-        xfce_rc_close(settings);
-      }
-      else
-      {
-        // Unable to obtain writeable config file - informing user
-        std::cerr << _("Unable to obtain writeable config file path in "
-          "order to update color in ColumnGraph::draw call!\n");
-      }
+      // Close settings file
+      xfce_rc_close(settings);
+    }
+    else
+    {
+      // Unable to obtain writeable config file - informing user
+      std::cerr << _("Unable to obtain writeable config file path in "
+        "order to update color in ColumnGraph::draw call!\n");
     }
-  }
-  else
-  {
-    // Unable to obtain read only config file - informing user
-    std::cerr << _("Unable to obtain read-only config file path in order"
-      " to load color in ColumnGraph::draw call!\n");
   }
 
   // make sure we got a pixbuf and that it has the right size
diff --git a/src/curve-view.cpp b/src/curve-view.cpp
index ac911f7..b864877 100644
--- a/src/curve-view.cpp
+++ b/src/curve-view.cpp
@@ -90,6 +90,7 @@ void Curve::draw(Gnome::Canvas::Canvas &canvas,
 
   // Get drawing attributes with defaults
   unsigned int color = applet->get_fg_color();
+  bool color_missing = true;
   double const line_width = 1.5;
 
   // Obtaining color
@@ -106,53 +107,44 @@ void Curve::draw(Gnome::Canvas::Canvas &canvas,
     g_free(file);
 
     // Loading color
-    bool color_missing = false;
     xfce_rc_set_group(settings, dir.c_str());
     if (xfce_rc_has_entry(settings, "color"))
     {
       color = xfce_rc_read_int_entry(settings, "color",
         applet->get_fg_color());
+      color_missing = false;
     }
-    else
-      color_missing = true;
 
     // Close settings file
     xfce_rc_close(settings);
+  }
+
+  /* Saving color if it was not recorded. XFCE4 configuration is done in
+   * read and write stages, so this needs to be separated */
+  if (color_missing)
+  {
+    // Search for a writeable settings file, create one if it doesnt exist
+    file = xfce_panel_plugin_save_location(applet->panel_applet, true);
 
-    /* Color not recorded - setting default then updating config. XFCE4
-     * configuration is done in read and write stages, so this needs to
-     * be separated */
-    if (color_missing)
+    if (file)
     {
-      // Search for a writeable settings file, create one if it doesnt exist
-      file = xfce_panel_plugin_save_location(applet->panel_applet, true);
-	
-      if (file)
-      {
-        // Opening setting file
-        settings = xfce_rc_simple_open(file, false);
-        g_free(file);
-
-        // Saving color
-        xfce_rc_set_group(settings, dir.c_str());
-        xfce_rc_write_int_entry(settings, "color", int(color));
-
-        // Close settings file
-        xfce_rc_close(settings);
-      }
-      else
-      {
-        // Unable to obtain writeable config file - informing user
-        std::cerr << _("Unable to obtain writeable config file path in "
-          "order to update color in Curve::draw call!\n");
-      }
+      // Opening setting file
+      settings = xfce_rc_simple_open(file, false);
+      g_free(file);
+
+      // Saving color
+      xfce_rc_set_group(settings, dir.c_str());
+      xfce_rc_write_int_entry(settings, "color", int(color));
+
+      // Close settings file
+      xfce_rc_close(settings);
+    }
+    else
+    {
+      // Unable to obtain writeable config file - informing user
+      std::cerr << _("Unable to obtain writeable config file path in "
+        "order to update color in Curve::draw call!\n");
     }
-  }
-  else
-  {
-    // Unable to obtain read only config file - informing user
-    std::cerr << _("Unable to obtain read-only config file path in order"
-      " to load color in Curve::draw call!\n");
   }
 
   line->property_fill_color_rgba() = color;
diff --git a/src/flame-view.cpp b/src/flame-view.cpp
index 2fab872..05bbf43 100644
--- a/src/flame-view.cpp
+++ b/src/flame-view.cpp
@@ -68,6 +68,7 @@ void Flame::update(Gnome::Canvas::Canvas &canvas,
 {
   // Get color with default
   unsigned int color = applet->get_fg_color();
+  bool color_missing = true;
 
   // Fetching assigned settings group
   Glib::ustring dir = monitor->get_settings_dir();
@@ -82,53 +83,44 @@ void Flame::update(Gnome::Canvas::Canvas &canvas,
     g_free(file);
 
     // Loading color
-    bool color_missing = false;
     xfce_rc_set_group(settings, dir.c_str());
     if (xfce_rc_has_entry(settings, "color"))
     {
       color = xfce_rc_read_int_entry(settings, "color",
         applet->get_fg_color());
+      color_missing = false;
     }
-    else
-      color_missing = true;
 
     // Close settings file
     xfce_rc_close(settings);
+  }
+
+  /* Saving if color was not recorded. XFCE4 configuration is done in
+   * read and write stages, so this needs to be separated */
+  if (color_missing)
+  {
+    // Search for a writeable settings file, create one if it doesnt exist
+    file = xfce_panel_plugin_save_location(applet->panel_applet, true);
 
-    /* Color not recorded - setting default then updating config. XFCE4
-     * configuration is done in read and write stages, so this needs to
-     * be separated */
-    if (color_missing)
+    if (file)
     {
-      // Search for a writeable settings file, create one if it doesnt exist
-      file = xfce_panel_plugin_save_location(applet->panel_applet, true);
-	
-      if (file)
-      {
-        // Opening setting file
-        settings = xfce_rc_simple_open(file, false);
-        g_free(file);
+      // Opening setting file
+      settings = xfce_rc_simple_open(file, false);
+      g_free(file);
 
-        // Saving color
-        xfce_rc_set_group(settings, dir.c_str());
-        xfce_rc_write_int_entry(settings, "color", int(color));
+      // Saving color
+      xfce_rc_set_group(settings, dir.c_str());
+      xfce_rc_write_int_entry(settings, "color", int(color));
 
-        // Close settings file
-        xfce_rc_close(settings);
-      }
-      else
-      {
-        // Unable to obtain writeable config file - informing user
-        std::cerr << _("Unable to obtain writeable config file path in "
-          "order to update color in Flame::update call!\n");
-      }
+      // Close settings file
+      xfce_rc_close(settings);
+    }
+    else
+    {
+      // Unable to obtain writeable config file - informing user
+      std::cerr << _("Unable to obtain writeable config file path in "
+        "order to update color in Flame::update call!\n");
     }
-  }
-  else
-  {
-    // Unable to obtain read only config file - informing user
-    std::cerr << _("Unable to obtain read-only config file path in order"
-      " to load color in Flame::update call!\n");
   }
 
   // Then make sure layer is correctly setup
diff --git a/src/text-view.cpp b/src/text-view.cpp
index 8a9ff06..b5bea33 100644
--- a/src/text-view.cpp
+++ b/src/text-view.cpp
@@ -99,6 +99,8 @@ void TextView::do_display()
 
 void TextView::do_update()
 {
+  bool font_name_missing = true;
+
   /* First update viewer font
    * Keeping with the default settings group for viewer settings
    * Search for settings file */
@@ -111,52 +113,42 @@ void TextView::do_update()
     g_free(file);
 
     // Loading font_name
-    bool font_name_missing = false;
-    Glib::ustring font_name = "";
     if (xfce_rc_has_entry(settings, "viewer_font"))
     {
       font_name = xfce_rc_read_entry(settings, "viewer_font", "");
+      font_name_missing = false;
     }
-    else
-      font_name_missing = true;
 
     // Close settings file
     xfce_rc_close(settings);
+  }
+
+  /* Saving if font name was not recorded. XFCE4 configuration is done in
+   * read and write stages, so this needs to be separated */
+  if (font_name_missing)
+  {
+    // Search for a writeable settings file, create one if it doesnt exist
+    file = xfce_panel_plugin_save_location(applet->panel_applet, true);
+
+    if (file)
+    {
+      // Opening setting file
+      settings = xfce_rc_simple_open(file, false);
+      g_free(file);
+
+      // Saving viewer size
+      xfce_rc_write_entry(settings, "viewer_font", font_name.c_str());
 
-    /* Viewer size not recorded - setting default then updating config. XFCE4
-     * configuration is done in read and write stages, so this needs to
-     * be separated */
-    if (font_name_missing)
+      // Close settings file
+      xfce_rc_close(settings);
+    }
+    else
     {
-      // Search for a writeable settings file, create one if it doesnt exist
-      file = xfce_panel_plugin_save_location(applet->panel_applet, true);
-	
-      if (file)
-      {
-        // Opening setting file
-        settings = xfce_rc_simple_open(file, false);
-        g_free(file);
-
-        // Saving viewer size
-        xfce_rc_write_entry(settings, "viewer_font", font_name.c_str());
-        
-        // Close settings file
-        xfce_rc_close(settings);
-      }
-      else
-      {
-        // Unable to obtain writeable config file - informing user
-        std::cerr << _("Unable to obtain writeable config file path in "
-          "order to update font name in TextView::do_update call!\n");
-      }
+      // Unable to obtain writeable config file - informing user
+      std::cerr << _("Unable to obtain writeable config file path in "
+        "order to update font name in TextView::do_update call!\n");
     }
   }
-  else
-  {
-    // Unable to obtain read only config file - informing user
-    std::cerr << _("Unable to obtain read-only config file path in order"
-      " to load font name in TextView::do_update call!\n");
-  }
 
   // then update
   for (text_iterator i = texts.begin(), end = texts.end(); i != end; ++i)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list