[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 40/96: For *View specialised classes, move color determination to do_attach methods
noreply at xfce.org
noreply at xfce.org
Thu Nov 27 22:20:45 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 117c9e8b45dfb525770f83f0408d1b88013726c8
Author: Omega Weapon <OmegaPhil at gmail.com>
Date: Wed Nov 6 19:45:54 2013 +0000
For *View specialised classes, move color determination to do_attach methods
This stops constant settings file opening and writing spam
---
src/bar-view.cpp | 132 ++++++++++++++++++++++++++-------------------------
src/column-view.cpp | 127 +++++++++++++++++++++++++------------------------
src/curve-view.cpp | 2 +-
src/flame-view.cpp | 127 +++++++++++++++++++++++++------------------------
4 files changed, 201 insertions(+), 187 deletions(-)
diff --git a/src/bar-view.cpp b/src/bar-view.cpp
index 6e324d7..819406c 100644
--- a/src/bar-view.cpp
+++ b/src/bar-view.cpp
@@ -37,7 +37,7 @@
class Bar
{
public:
- Bar(Monitor *monitor, bool horizontal = false);
+ Bar(Monitor *monitor, unsigned int fill_color, bool horizontal = false);
~Bar();
void update();
@@ -53,10 +53,11 @@ private:
double old_value, new_value;
bool horizontal;
+ unsigned int fill_color;
};
-Bar::Bar(Monitor *m, bool horizontal)
- : monitor(m), old_value(0), new_value(0)
+Bar::Bar(Monitor *m, unsigned int c, bool horizontal)
+ : monitor(m), old_value(0), new_value(0), fill_color(c)
{
this->horizontal = horizontal;
}
@@ -100,67 +101,9 @@ unsigned int outlineified(unsigned int color)
void Bar::draw(Gnome::Canvas::Canvas &canvas,
Applet *applet, int width, int height, int no, int total,
double time_offset)
-{
- // Get drawing attributes
- unsigned int fill_color = applet->get_fg_color();
- bool color_missing = true;
-
- /* Loading fill_color from settings if it exists
- * Fetching assigned settings group */
- Glib::ustring dir = monitor->get_settings_dir();
-
- // Search for settings file
- gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
-
- if (file)
- {
- // One exists - loading readonly settings
- XfceRc* settings = xfce_rc_simple_open(file, true);
- g_free(file);
-
- // Loading color
- 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;
- }
-
- // 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);
-
- if (file)
- {
- // Opening setting file
- XfceRc* 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");
- }
- }
-
+{
unsigned int outline_color = outlineified(fill_color);
-
+
// calculate parameters
int box_size;
// use min_spacing at least, except for last box which doesn't need spacing
@@ -274,7 +217,68 @@ void BarView::do_update()
void BarView::do_attach(Monitor *monitor)
{
- bars.push_back(new Bar(monitor, this->horizontal));
+ unsigned int fill_color = 0;
+ bool color_missing = true;
+
+ // Obtaining color
+ // Fetching assigned settings group
+ Glib::ustring dir = monitor->get_settings_dir();
+
+ // Search for settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ XfceRc* settings = xfce_rc_simple_open(file, true);
+ g_free(file);
+
+ // Loading color
+ xfce_rc_set_group(settings, dir.c_str());
+ if (xfce_rc_has_entry(settings, "fill_color"))
+ {
+ fill_color = xfce_rc_read_int_entry(settings, "fill_color",
+ applet->get_fg_color());
+ color_missing = false;
+ }
+
+ // 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)
+ {
+ // Setting color
+ 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
+ XfceRc* 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, "fill_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 set color in BarView::do_attach call!\n");
+ }
+ }
+
+ // Instantiating bar with determined color
+ bars.push_back(new Bar(monitor, fill_color, this->horizontal));
}
void BarView::do_detach(Monitor *monitor)
diff --git a/src/column-view.cpp b/src/column-view.cpp
index 01c69a9..1a1037b 100644
--- a/src/column-view.cpp
+++ b/src/column-view.cpp
@@ -38,7 +38,7 @@
class ColumnGraph
{
public:
- ColumnGraph(Monitor *monitor);
+ ColumnGraph(Monitor *monitor, unsigned int color);
void update(unsigned int max_samples); // gather info from monitor
void draw(Gnome::Canvas::Canvas &canvas, // redraw columns on canvas
@@ -52,10 +52,11 @@ private:
ValueHistory value_history;
int remaining_draws;
+ unsigned int color;
};
-ColumnGraph::ColumnGraph(Monitor *m)
- : monitor(m), value_history(m), remaining_draws(0)
+ColumnGraph::ColumnGraph(Monitor *m, unsigned int c)
+ : monitor(m), value_history(m), remaining_draws(0), color(c)
{
}
@@ -84,63 +85,6 @@ void ColumnGraph::draw(Gnome::Canvas::Canvas &canvas,
if (vi == vend) // there must be at least one point
return;
- // 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();
-
- // Search for settings file
- gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
-
- if (file)
- {
- // One exists - loading readonly settings
- XfceRc* settings = xfce_rc_simple_open(file, true);
- g_free(file);
-
- // Loading color
- 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;
- }
-
- // 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);
-
- if (file)
- {
- // Opening setting file
- XfceRc* 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 ColumnGraph::draw call!\n");
- }
- }
-
// make sure we got a pixbuf and that it has the right size
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
@@ -233,7 +177,68 @@ void ColumnView::do_update()
void ColumnView::do_attach(Monitor *monitor)
{
- columns.push_back(new ColumnGraph(monitor));
+ unsigned int color = 0;
+ bool color_missing = true;
+
+ // Obtaining color
+ // Fetching assigned settings group
+ Glib::ustring dir = monitor->get_settings_dir();
+
+ // Search for settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ XfceRc* settings = xfce_rc_simple_open(file, true);
+ g_free(file);
+
+ // Loading color
+ 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;
+ }
+
+ // 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)
+ {
+ // Setting color
+ 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
+ XfceRc* 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 set color in ColumnView::do_attach call!\n");
+ }
+ }
+
+ // Instantiating column graph with determined color
+ columns.push_back(new ColumnGraph(monitor, color));
}
void ColumnView::do_detach(Monitor *monitor)
diff --git a/src/curve-view.cpp b/src/curve-view.cpp
index 8d83626..2b8c2bc 100644
--- a/src/curve-view.cpp
+++ b/src/curve-view.cpp
@@ -206,7 +206,7 @@ void CurveView::do_attach(Monitor *monitor)
{
// Unable to obtain writeable config file - informing user
std::cerr << _("Unable to obtain writeable config file path in "
- "order to set color in Curve::do_attach call!\n");
+ "order to set color in CurveView::do_attach call!\n");
}
}
diff --git a/src/flame-view.cpp b/src/flame-view.cpp
index 78ae971..c62f30a 100644
--- a/src/flame-view.cpp
+++ b/src/flame-view.cpp
@@ -39,7 +39,7 @@
class Flame
{
public:
- Flame(Monitor *monitor);
+ Flame(Monitor *monitor, unsigned int color);
void update(Gnome::Canvas::Canvas &canvas,
Applet *applet, int width, int height, int no, int total);
@@ -58,72 +58,16 @@ private:
int cooling; // cooling factor
void recompute_fuel();
+ unsigned int color;
};
-Flame::Flame(Monitor *m)
- : monitor(m), value(0), next_refuel(0)
+Flame::Flame(Monitor *m, unsigned int c)
+ : monitor(m), value(0), next_refuel(0), color(c)
{}
void Flame::update(Gnome::Canvas::Canvas &canvas,
Applet *applet, int width, int height, int no, int total)
{
- // 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();
-
- // Search for settings file
- gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
-
- if (file)
- {
- // One exists - loading readonly settings
- XfceRc* settings = xfce_rc_simple_open(file, true);
- g_free(file);
-
- // Loading color
- 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;
- }
-
- // 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);
-
- if (file)
- {
- // Opening setting file
- XfceRc* 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 Flame::update call!\n");
- }
- }
-
// Then make sure layer is correctly setup
if (flame.get() == 0)
{
@@ -319,7 +263,68 @@ void FlameView::do_update()
void FlameView::do_attach(Monitor *monitor)
{
- flames.push_back(new Flame(monitor));
+ unsigned int color = 0;
+ bool color_missing = true;
+
+ // Obtaining color
+ // Fetching assigned settings group
+ Glib::ustring dir = monitor->get_settings_dir();
+
+ // Search for settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ XfceRc* settings = xfce_rc_simple_open(file, true);
+ g_free(file);
+
+ // Loading color
+ 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;
+ }
+
+ // 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)
+ {
+ // Setting color
+ 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
+ XfceRc* 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 set color in FlameView::do_attach call!\n");
+ }
+ }
+
+ // Instantiating flame with determined color
+ flames.push_back(new Flame(monitor, color));
}
void FlameView::do_detach(Monitor *monitor)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list