[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 04/96: Initial porting to XFCE4 and away from GConf - extremely buggy pre-compile state
noreply at xfce.org
noreply at xfce.org
Thu Nov 27 22:20:09 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 b76c7b8af8f401b87ca992696d02f668d3e5cb3d
Author: Omega Weapon <OmegaPhil at gmail.com>
Date: Thu Sep 12 17:55:11 2013 +0100
Initial porting to XFCE4 and away from GConf - extremely buggy pre-compile state
---
configure.ac | 4 +-
src/applet.cpp | 648 ++++++++++++++++++++++++++---------------
src/applet.hpp | 31 +-
src/bar-view.cpp | 75 ++++-
src/canvas-view.cpp | 70 ++++-
src/choose-monitor-window.cpp | 219 ++++++++------
src/choose-monitor-window.hpp | 4 +-
src/column-view.cpp | 114 ++++++--
src/curve-view.cpp | 77 ++++-
src/flame-view.cpp | 178 +++++++----
src/main.cpp | 3 +-
src/monitor-impls.cpp | 422 ++++++++++++++++-----------
src/monitor-impls.hpp | 24 +-
src/monitor.hpp | 15 +-
src/preferences-window.cpp | 483 ++++++++++++++++++++++--------
src/preferences-window.hpp | 20 +-
src/text-view.cpp | 67 ++++-
17 files changed, 1619 insertions(+), 835 deletions(-)
diff --git a/configure.ac b/configure.ac
index fa76fc7..ea53308 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,12 +16,10 @@ AC_PROG_CC
dnl checks for libraries
-PKG_CHECK_MODULES(DEPS, gconfmm-2.6 >= 2.6.0 \
- gtkmm-2.4 >= 2.6.0 \
+PKG_CHECK_MODULES(DEPS, gtkmm-2.4 >= 2.6.0 \
libgnomecanvasmm-2.6 >= 2.6.0 \
libgnomeui-2.0 >= 2.0.0 \
libglademm-2.4 >= 2.4.0 \
- libpanelapplet-2.0 >= 2.0.0 \
libgtop-2.0 >= 2.6.0)
AC_SUBST(DEPS_CFLAGS)
AC_SUBST(DEPS_LIBS)
diff --git a/src/applet.cpp b/src/applet.cpp
index b3555ec..9414a9a 100644
--- a/src/applet.cpp
+++ b/src/applet.cpp
@@ -1,6 +1,7 @@
/* Implementation of the Applet class.
*
* Copyright (c) 2003, 04, 05 Ole Laursen.
+ * Copyright (c) 2013 OmegaPhil (OmegaPhil+hardware.monitor at gmail.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -18,7 +19,7 @@
* USA.
*/
-
+// autoconf-generated, above source directory
#include <config.h>
#include <algorithm>
@@ -26,10 +27,18 @@
#include <gtkmm/main.h>
#include <cassert>
+#include <unistd.h> // for nice
+
+extern "C"
+{
+#include <libxfce4panel/xfce-panel-plugin.h> // Registration macro
+}
#include "ucompose.hpp"
+#include "helpers.hpp"
#include "applet.hpp"
+
#include "column-view.hpp"
#include "curve-view.hpp"
#include "bar-view.hpp"
@@ -39,114 +48,168 @@
#include "preferences-window.hpp"
#include "i18n.hpp"
-// helpers for popping up the various things
-void display_preferences(BonoboUIComponent *, void *applet, const gchar *)
+
+// XFCE4 functions to create and destroy applet
+extern "C" void applet_construct(XfcePanelPlugin* plugin)
+{
+ nice(5); // Don't eat up too much CPU
+
+ // WIP: Try to compile!
+
+ // Initialising GTK and GNOME canvas
+ Gtk::Main main(argc, argv);
+ Gnome::Canvas::init();
+
+ try {
+
+ // i18n
+ xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
+
+ // Actually creating the applet/plugin
+ Applet *applet = manage(new Applet(plugin));
+ applet->show();
+ }
+ catch(const Glib::Error &ex)
+ {
+ // From helpers
+ fatal_error(ex.what());
+ }
+}
+
+// Does not need C linkage as its called via a function pointer?
+// Not needed as GLib manages the lifetime of the applet
+/*void applet_free(XfcePanelPlugin*, Applet* applet)
+{
+ // Called by 'free-data' signal
+ delete applet;
+ applet = NULL;
+}*/
+
+// Helpers for popping up the various things
+void display_preferences(gpointer* applet)
{
static_cast<Applet *>(applet)->on_preferences_activated();
}
-void display_help(BonoboUIComponent *, void *applet, const gchar *)
+void display_help(gpointer* applet)
{
static_cast<Applet *>(applet)->on_help_activated();
}
-void display_about(BonoboUIComponent *, void *applet, const gchar *)
+void display_about(gpointer* applet)
{
static_cast<Applet *>(applet)->on_about_activated();
}
-namespace
-{
- template <typename T>
- Gnome::Conf::Entry get_entry_with_default(
- Glib::RefPtr<Gnome::Conf::Client> &gconf_client,
- const Glib::ustring &key,
- const T &value )
- {
- Gnome::Conf::Entry entry = gconf_client->get_entry(key);
- if (!entry.gobj())
- {
- gconf_client->set( key, value );
- entry = gconf_client->get_entry(key);
- }
- return entry;
- }
-}
-
+Applet::Applet(XfcePanelPlugin *plugin)
+ : panel_applet(plugin),
-Applet::Applet(PanelApplet *a)
- : panel_applet(a)
+ // Setting defaults
+ icon_path("/usr/share/pixmaps/hardware-monitor-applet.png"),
+ viewer_type("curve"),
+ viewer_size(96), // Arbitrary default
+ viewer_font(""),
+ background_color(0x00000000), // black as the night
+ use_background_color(false),
+ next_color(0)
{
- // load icon
- std::string icon_name = GNOMEICONDIR "/hardware-monitor-applet.png";
- try {
+ // Search for settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ XfceRc* settings = xfce_rc_simple_open(file, true);
+ g_free(file);
+
+ icon_path = xfce_rc_read_entry(settings, "icon-path", icon_path.c_str());
+ viewer_type = xfce_rc_read_entry(settings, "viewer_type",
+ viewer_type.c_str());
+ viewer_size = xfce_rc_read_int_entry(settings, "viewer_size",
+ viewer_size);
+ viewer_font = xfce_rc_read_entry(settings, "viewer_font", viewer_font);
+ background_color = xfce_rc_read_int_entry(settings, "background_color",
+ background_color);
+ use_background_color = xfce_rc_read_bool_entry(settings,
+ "use_background_color", use_background_color);
+ next_color = xfce_rc_read_int_entry(settings, "next_color",
+ next_color);
+
+ // All settings loaded
+ xfce_rc_close(settings);
+ }
+
+ // Loading icon
+ try
+ {
icon = Gdk::Pixbuf::create_from_file(icon_name);
}
- catch(...) {
+ catch (...)
+ {
std::cerr <<
String::ucompose(_("Hardware Monitor: cannot load the icon '%1'.\n"),
- icon_name);
- // it's a minor problem if we can't find the icon
+ icon_path);
+
+ // It's a minor problem if we can't find the icon
icon = Glib::RefPtr<Gdk::Pixbuf>();
}
+
+ // Configuring viewer type
+ if (viewer_type == "curve")
+ {
+ // Setting view to CurveView if it isnt already
+ if (!dynamic_cast<CurveView *>(view.get()))
+ set_view(new CurveView);
+ }
+ else if (viewer_type == "bar")
+ {
+ // Setting view to horizontal BarView if it isnt already
+ // It gets tricky here because them BarView can render 2 viewers.
+ // Thus, we much also check the oriententation
+ BarView *bar_view = dynamic_cast<BarView *>(view.get());
+ if (!(bar_view && bar_view->is_horizontal()) )
+ set_view(new BarView);
+ }
+ else if (viewer_type == "vbar")
+ {
+ // Setting view to vertical BarView if it isnt already
+ // Same situation as with "bar"
+ BarView *bar_view = dynamic_cast<BarView *>(view.get());
+ if (!(bar_view && !bar_view->is_horizontal()) )
+ set_view(new BarView(false));
+ }
+ else if (viewer_type == "text") {
+
+ // Setting view to TextView if it isnt already
+ if (!dynamic_cast<TextView *>(view.get()))
+ set_view(new TextView);
+ }
+ else if (viewer_type == "flame") {
+
+ // Setting view to FlameView if it isnt already
+ if (!dynamic_cast<FlameView *>(view.get()))
+ set_view(new FlameView);
+ }
+ else if (viewer_type == "column") {
+
+ // Setting view to ColumnView if it isnt already
+ if (!dynamic_cast<ColumnView *>(view.get()))
+ set_view(new ColumnView);
+ }
+
+ // Setting the view background colour if desired
+ if (use_background_color)
+ view->set_background(background_color);
- // setup GConf
- gconf_dir = panel_applet_get_preferences_key(panel_applet);
- gconf_client = Gnome::Conf::Client::get_default_client();
- gconf_client->add_dir(gconf_dir);
-
- // circumvent GConf bug (FIXME: report it)
- gconf_client->set(gconf_dir + "/dummy", 0);
- gconf_client->set(gconf_dir + "/monitors/dummy", 0);
-
- // connect GConf
- gconf_client->notify_add(gconf_dir + "/viewer_type",
- sigc::mem_fun(*this, &Applet::viewer_type_listener));
- gconf_client->notify_add(gconf_dir + "/background_color",
- sigc::mem_fun(*this, &Applet::
- background_color_listener));
- gconf_client->notify_add(gconf_dir + "/use_background_color",
- sigc::mem_fun(*this, &Applet::
- use_background_color_listener));
-
- monitor_seq mon = load_monitors(gconf_client, gconf_dir);
+ // Loading up monitors
+ monitor_seq mon = load_monitors(settings);
for (monitor_iter i = mon.begin(), end = mon.end(); i != end; ++i)
add_monitor(*i);
-
- // we need this #if 0 so the strings will be in the message catalog for
- // translation below in menu_xml
-#if 0
- // pop-up menu strings
- _("_Preferences...") _("_Help") _("_About...")
-#endif
-
- // setup menu
- static const char menu_xml[] =
- "<popup name=\"button3\">\n"
- " <menuitem name=\"Properties Item\"\n"
- " verb=\"HardwareMonitorPreferences\" _label=\"_Preferences...\"\n"
- " pixtype=\"stock\" pixname=\"gtk-properties\"/>\n"
- " <menuitem name=\"Help Item\"\n"
- " verb=\"HardwareMonitorHelp\" _label=\"_Help\"\n"
- " pixtype=\"stock\" pixname=\"gtk-help\"/>\n"
- " <menuitem name=\"About Item\"\n"
- " verb=\"HardwareMonitorAbout\" _label=\"_About...\"\n"
- " pixtype=\"stock\" pixname=\"gnome-stock-about\"/>\n"
- "</popup>\n";
-
- static const BonoboUIVerb menu_verbs[] = {
- BONOBO_UI_VERB("HardwareMonitorPreferences", &display_preferences),
- BONOBO_UI_VERB("HardwareMonitorHelp", &display_help),
- BONOBO_UI_VERB("HardwareMonitorAbout", &display_about),
-
- BONOBO_UI_VERB_END
- };
-
- panel_applet_setup_menu(panel_applet, menu_xml, menu_verbs, this);
-
- // start displaying something
+
+ /* TODO: This should be completely irrelevant as the view and background colour is already set above
+ // Start displaying something
// Ensure config values aren't null
get_entry_with_default( gconf_client, gconf_dir + "/viewer_type",
Glib::ustring("curve") );
@@ -159,10 +222,51 @@ Applet::Applet(PanelApplet *a)
+ "/background_color"));
use_background_color_listener(0, gconf_client->get_entry(gconf_dir
+ "/use_background_color"));
+ */
+
+ /* Connect plugin signals to functions - since I'm not really interested
+ * in the plugin but the applet pointer, swapped results in the signal
+ * handler getting the applet reference first - the plugin pointer is
+ * passed next, but since the handler only takes one parameter this is
+ * discarded */
+ // Providing About option
+ g_signal_connect_swapped(panel_applet, "about", G_CALLBACK(display_about),
+ this);
+
+ // Hooking into Properties option
+ g_signal_connect_swapped(panel_applet, "configure-plugin",
+ G_CALLBACK(display_preferences), this);
+
+ // Hooking into plugin destruction signal
+ // Not needed as Glib manages the lifetime of the applet
+ /*g_signal_connect_swapped(panel_applet, "free-data", G_CALLBACK(applet_free),
+ this);*/
+
+ /* TODO: Not sure if I really need to support this
+#if (LIBXFCE4PANEL_CHECK_VERSION(4,10,0))
+ g_signal_connect(plugin, "mode-changed", G_CALLBACK(PanelPlugin::mode_changed_slot), this);
+#else
+ g_signal_connect(plugin, "orientation-changed", G_CALLBACK(PanelPlugin::orientation_changed_slot), this);
+#endif
+ */
+
+ // Hooking into save signal
+ g_signal_connect_swapped(panel_applet, "save", G_CALLBACK(save_monitors),
+ this);
+
+ // TODO: No current code is responsible for resizing, so leaving this alone for now
+ //g_signal_connect(panel_applet, "size-changed", G_CALLBACK(PanelPlugin::size_changed_slot), this);
+ // Adding configure and about to the applet's right-click menu
+ xfce_panel_plugin_menu_show_configure(panel_applet);
+ xfce_panel_plugin_menu_show_about(panel_applet);
+
+ // Initialising timer to run every second (by default) to trigger main_loop
timer =
Glib::signal_timeout().connect(sigc::mem_fun(*this, &Applet::main_loop),
- update_interval);
+ update_interval);
+
+ // Initial main_loop run
main_loop();
}
@@ -170,15 +274,18 @@ Applet::~Applet()
{
timer.disconnect();
- // make sure noone is trying to read the monitors before we kill them
+ // Make sure noone is trying to read the monitors before we kill them
if (view.get())
for (monitor_iter i = monitors.begin(), end = monitors.end(); i != end; ++i)
view->detach(*i);
view.reset();
-
+
+ // Save monitors configuration
+ save_monitors();
+
+ // Delete monitors
for (monitor_iter i = monitors.begin(), end = monitors.end(); i != end; ++i) {
- (*i)->save(gconf_client); // save max. values
delete *i;
}
}
@@ -198,23 +305,23 @@ void Applet::set_view(View *v)
bool Applet::main_loop()
{
- // update view
+ // Update view
if (view.get())
view->update();
- // update tooltip
+ // Update tooltip
Glib::ustring tip;
for (monitor_iter i = monitors.begin(), end = monitors.end(); i != end; ++i) {
Monitor &mon = **i;
- // note to translators: %1 is the name of a monitor, e.g. "CPU 1", and %2 is
+ // Note to translators: %1 is the name of a monitor, e.g. "CPU 1", and %2 is
// the current measurement, e.g. "78%"
Glib::ustring next = String::ucompose(_("%1: %2"), mon.get_short_name(),
mon.format_value(mon.value()));
if (tip.empty())
tip = next;
else
- // note to translators: this is used for composing a list of monitors; %1
+ // Note to translators: this is used for composing a list of monitors; %1
// is the previous part of the list and %2 is the part to append
tip = String::ucompose(_("%1\n%2"), tip, next);
}
@@ -234,18 +341,37 @@ unsigned int Applet::get_fg_color()
0x83A67FB0, 0xC1665AB0, 0x7590AEB0, 0xE0C39ED0, 0x887FA3B0
};
- Gnome::Conf::Value v = gconf_client->get(gconf_dir + "/next_color");
- int c;
-
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- c = v.get_int();
+ // Saving 'current' next color
+ int color = next_color;
+
+ // Updating next_color
+ next_color = int((next_color + 1) %
+ (sizeof(colors) / sizeof(unsigned int))));
+
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* file = xfce_panel_plugin_save_location(panel_applet, true);
+
+ if (file)
+ {
+ // Opening setting file
+ XfceRc* settings = xfce_rc_simple_open(file, false);
+ g_free(file);
+
+ // Saving next_color
+ xfce_rc_write_int_entry(settings, "next_color", next_color);
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
else
- c = 0;
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save next_color!\n");
+ }
- gconf_client->set(gconf_dir + "/next_color",
- int((c + 1) % (sizeof(colors) / sizeof(unsigned int))));
-
- return colors[c];
+ // Returning actual next color
+ return colors[color];
}
int Applet::get_size() const
@@ -257,18 +383,8 @@ int Applet::get_size() const
bool Applet::horizontal() const
{
- PanelAppletOrient orient = panel_applet_get_orient(panel_applet);
- return orient == PANEL_APPLET_ORIENT_UP || orient == PANEL_APPLET_ORIENT_DOWN;
-}
-
-Glib::RefPtr<Gnome::Conf::Client> &Applet::get_gconf_client()
-{
- return gconf_client;
-}
-
-Glib::ustring Applet::get_gconf_dir() const
-{
- return gconf_dir;
+ GtkOrientation orient = xfce_panel_plugin_get_orientation(panel_applet);
+ return orient == GTK_ORIENTATION_HORIZONTAL;
}
Glib::RefPtr<Gdk::Pixbuf> Applet::get_icon()
@@ -281,31 +397,94 @@ void Applet::add_monitor(Monitor *monitor)
add_sync_for(monitor);
monitors.push_back(monitor);
- if (monitor->get_gconf_dir().empty()) {
- monitor->set_gconf_dir(find_empty_monitor_dir());
- monitor->save(gconf_client);
+ /* Read and write config locations and the open call are be different
+ * in XFCE4 - hence the duplication here */
+
+ if (monitor->get_settings_dir().empty()) {
+ monitor->set_settings_dir(find_empty_monitor_dir());
+
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* file = xfce_panel_plugin_save_location(panel_applet, true);
+
+ if (file)
+ {
+ // Opening setting file
+ XfceRc* settings = xfce_rc_simple_open(file, false);
+ g_free(file);
+
+ // Saving monitor
+ monitor->save(settings);
+
+ // 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 save monitor in add_monitor call!\n");
+ }
}
else
- monitor->load(gconf_client);
-
+ {
+ // Search for settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ settings = xfce_rc_simple_open(file, true);
+ g_free(file);
+
+ // Load settings for monitor
+ monitor->load(settings);
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain read only config file - informing user
+ std::cerr << _("Unable to obtain read-only config file path in "
+ "order to load monitor settings in add_monitor call!\n");
+ }
+ }
+
+ // Attaching monitor to view
if (view.get())
view->attach(monitor);
}
void Applet::remove_monitor(Monitor *monitor)
{
+ // Detatching monitor
if (view.get())
view->detach(monitor);
- // delete the GConf keys
- Glib::SListHandle<Gnome::Conf::Entry> list
- = gconf_client->all_entries(monitor->get_gconf_dir());
-
- for (Glib::SListHandle<Gnome::Conf::Entry>::const_iterator i = list.begin(),
- end = list.end(); i != end; ++i)
- gconf_client->unset((*i).get_key());
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* file = xfce_panel_plugin_save_location(panel_applet, true);
+
+ if (file)
+ {
+ // Opening setting file
+ XfceRc* settings = xfce_rc_simple_open(file, false);
+ g_free(file);
+
+ // Removing settings group associated with the monitor if it exists
+ if (xfce_rc_has_group(settings, monitor->get_settings_dir().c_str()))
+ xfce_rc_delete_group(settings, monitor->get_settings_dir().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 remove a monitor!\n");
+ }
- // everyone has been notified, it's now safe to remove and delete
+ // Everyone has been notified, it's now safe to remove and delete
// the monitor
monitors.remove(monitor);
remove_sync_for(monitor);
@@ -315,21 +494,68 @@ void Applet::remove_monitor(Monitor *monitor)
void Applet::replace_monitor(Monitor *prev_mon, Monitor *new_mon)
{
+ // Locating monitor of interest
monitor_iter i = std::find(monitors.begin(), monitors.end(), prev_mon);
assert(i != monitors.end());
-
+
+ // Basic configuration
add_sync_for(new_mon);
*i = new_mon;
+ new_mon->set_settings_dir(prev_mon->get_settings_dir());
- new_mon->set_gconf_dir(prev_mon->get_gconf_dir());
- new_mon->load(gconf_client);
- new_mon->save(gconf_client);
-
+ /* Loading monitor with previous monitor's settings - XFCE4 needs
+ * different code to read a config file as compared to writing to it
+ * Search for settings file */
+ gchar* file = xfce_panel_plugin_lookup_rc_file(panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ settings = xfce_rc_simple_open(file, true);
+ g_free(file);
+
+ // Load settings
+ new_mon->load(settings);
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain read-only config file - informing user
+ std::cerr << _("Unable to obtain read-only config file path in "
+ "order to load monitor settings in replace_monitor call!\n");
+ }
+
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* file = xfce_panel_plugin_save_location(panel_applet, true);
+
+ if (file)
+ {
+ // Opening setting file
+ XfceRc* settings = xfce_rc_simple_open(file, false);
+ g_free(file);
+
+ // Saving settings
+ new_mon->save(settings);
+
+ // 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 save monitor settings in replace_monitor call!\n");
+ }
+
+ // Reattach monitor if its attached to the current view
if (view.get()) {
view->detach(prev_mon);
view->attach(new_mon);
}
+ // Deleting previous monitor
remove_sync_for(prev_mon);
delete prev_mon;
}
@@ -346,125 +572,61 @@ void Applet::remove_sync_for(Monitor *monitor)
(*i)->remove_sync_with(monitor);
}
-void Applet::viewer_type_listener(unsigned int, Gnome::Conf::Entry entry)
+void Applet::save_monitors()
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_STRING) {
- // FIXME: use schema for this?
- Gnome::Conf::Value v(Gnome::Conf::VALUE_STRING);
- v.set(Glib::ustring("curve"));
- entry.set_value(v);
-
- gconf_client->set(entry.get_key(), Glib::ustring("curve"));
- }
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* file = xfce_panel_plugin_save_location(panel_applet, true);
+
+ if (file)
+ {
+ // Opening setting file
+ XfceRc* settings = xfce_rc_simple_open(file, false);
+ g_free(file);
- Glib::ustring s = entry.get_value().get_string();
+ // Looping for all monitors and calling save on each
+ for (monitor_iter i = monitors.begin(), end = monitors.end(); i != end; ++i)
+ (*i)->save(settings);
- // FIXME: move this
- if (s == "curve") {
- if (!dynamic_cast<CurveView *>(view.get()))
- set_view(new CurveView);
- }
- else if (s == "bar") {
- // It get's tricky here because them BarView can render 2 viewers.
- // Thus, we much also check the oriententation
- BarView *bar_view = dynamic_cast<BarView *>(view.get());
- if (!(bar_view && bar_view->is_horizontal()) )
- set_view(new BarView);
+ // Close settings file
+ xfce_rc_close(settings);
}
- else if (s == "vbar") {
- // Same situation as with "bar"
- BarView *bar_view = dynamic_cast<BarView *>(view.get());
- if (!(bar_view && !bar_view->is_horizontal()) )
- set_view(new BarView(false));
- }
- else if (s == "text") {
- if (!dynamic_cast<TextView *>(view.get()))
- set_view(new TextView);
- }
- else if (s == "flame") {
- if (!dynamic_cast<FlameView *>(view.get()))
- set_view(new FlameView);
- }
- else if (s == "column") {
- if (!dynamic_cast<ColumnView *>(view.get()))
- set_view(new ColumnView);
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save monitors!\n");
}
-
- // make sure the view sets the background
- background_color_listener(0, gconf_client->get_entry(gconf_dir
- + "/background_color"));
}
-void Applet::background_color_listener(unsigned int, Gnome::Conf::Entry entry)
+Glib::ustring Applet::find_empty_monitor_dir()
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_INT) {
- // FIXME: use schema for this?
- Gnome::Conf::Value v(Gnome::Conf::VALUE_INT);
- v.set(0x00000000); // black as the night
- entry.set_value(v);
- }
-
- unsigned int color = entry.get_value().get_int();
-
- Gnome::Conf::Value v
- = gconf_client->get(gconf_dir + "/use_background_color");
-
- bool use;
+ Glib::ustring mon_dir;
- if (v.get_type() != Gnome::Conf::VALUE_BOOL)
- use = false;
- else
- use = v.get_bool();
+ // Search for read-only settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(panel_applet);
- if (view.get())
- if (use)
- view->set_background(color);
-}
+ if (file)
+ {
+ // One exists - loading readonly settings
+ settings = xfce_rc_simple_open(file, true);
+ g_free(file);
-void Applet::use_background_color_listener(unsigned int, Gnome::Conf::Entry entry)
-{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_BOOL) {
- // FIXME: use schema for this?
- Gnome::Conf::Value v(Gnome::Conf::VALUE_BOOL);
- v.set(false);
- entry.set_value(v);
+ int c = 1;
+ do {
+ mon_dir = String::ucompose("%1", c++);
+ } while (xfce_rc_has_group(settings, mon_dir.c_str()));
+
+ // Close settings file
+ xfce_rc_close(settings);
}
-
- bool use = entry.get_value().get_bool();
-
- Gnome::Conf::Value v
- = gconf_client->get(gconf_dir + "/background_color");
-
- unsigned int color;
-
- if (v.get_type() != Gnome::Conf::VALUE_INT)
- color = 0x00000000;
else
- color = v.get_int();
-
- if (view.get()) {
- if (use)
- view->set_background(color);
- else
- view->unset_background();
- }
-}
-
-Glib::ustring Applet::find_empty_monitor_dir()
-{
- Glib::SListHandle<Glib::ustring> list
- = gconf_client->all_dirs(gconf_dir + "/monitors");
-
- Glib::SListHandle<Glib::ustring>::const_iterator
- begin = list.begin(),
- end = list.end();
-
- int c = 1;
- Glib::ustring mon_dir;
- do {
- mon_dir = String::ucompose(gconf_dir + "/monitors/%1", c++);
- } while (std::find(begin, end, mon_dir) != end);
+ {
+ // Unable to obtain read-only config file - informing user
+ std::cerr << _("Unable to obtain read-only config file path in "
+ "find_empty_monitor_dir call!\n");
+ }
+ // Returning next free monitor directory (number)
return mon_dir;
}
@@ -483,6 +645,7 @@ void Applet::on_about_activated()
{
std::vector<Glib::ustring> authors;
authors.push_back("Ole Laursen <olau at hardworking.dk>");
+ authors.push_back("OmegaPhil <OmegaPhil+hardware.monitor at gmail.com>");
std::vector<Glib::ustring> documenters;
// add documenters here
@@ -497,8 +660,8 @@ void Applet::on_about_activated()
about->set_name(_("Hardware Monitor"));
about->set_version(VERSION);
// %1 is the copyright symbol
- about->set_copyright(String::ucompose(_("Copyright %1 2003 Ole Laursen"),
- "\xc2\xa9"));
+ about->set_copyright(String::ucompose(_("Copyright %1 2003 Ole "
+ "Laursen\nCopyright %1 2013 OmegaPhil"), "\xc2\xa9"));
about->set_authors(authors);
if (!documenters.empty())
about->set_documenters(documenters);
@@ -516,3 +679,10 @@ void Applet::on_about_activated()
about->raise();
}
}
+
+/* 'Registering' the applet - in reality this substitutes into a load
+ * of functions including a main */
+extern "C"
+{
+ XFCE_PANEL_PLUGIN_REGISTER(applet_construct)
+}
diff --git a/src/applet.hpp b/src/applet.hpp
index a75905f..67947d3 100644
--- a/src/applet.hpp
+++ b/src/applet.hpp
@@ -1,6 +1,7 @@
/* The applet class which coordinates everything.
*
* Copyright (c) 2003, 04, 05 Ole Laursen.
+ * Copyright (c) 2013 OmegaPhil (OmegaPhil+hardware.monitor at gmail.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -33,11 +34,11 @@
#include <glibmm/ustring.h>
-#include <gconfmm/client.h>
-#include <gconfmm/entry.h>
-
-
-#include <panel-applet.h>
+extern "C"
+{
+#include <gtk/gtk.h> // TODO: Confirm this is needed
+#include <libxfce4panel/libxfce4panel.h>
+}
#include "monitor.hpp"
@@ -59,9 +60,6 @@ public:
bool horizontal() const; // whether we're in horizontal mode
void set_view(View *view); // use this view to monitor
- Glib::RefPtr<Gnome::Conf::Client> &get_gconf_client();
- Glib::ustring get_gconf_dir() const;
-
Glib::RefPtr<Gdk::Pixbuf> get_icon(); // get the application icon
void add_monitor(Monitor *monitor); // take over ownership of monitor
@@ -85,18 +83,17 @@ private:
bool main_loop();
sigc::connection timer;
- // GConf
- Glib::RefPtr<Gnome::Conf::Client> gconf_client;
- Glib::ustring gconf_dir;
-
- void viewer_type_listener(unsigned int, Gnome::Conf::Entry entry);
- void background_color_listener(unsigned int, Gnome::Conf::Entry entry);
- void use_background_color_listener(unsigned int, Gnome::Conf::Entry entry);
-
Glib::ustring find_empty_monitor_dir();
// data
- PanelApplet *panel_applet;
+ XfcePanelPlugin *panel_applet;
+ Glib::ustring icon_path;
+ Glib::ustring viewer_type;
+ Glib::ustring viewer_font;
+ int viewer_size; // Pixel size used with the viewer scale - nothing to do with the visible area
+ int background_color;
+ gboolean use_background_color;
+ int next_color;
Glib::RefPtr<Gdk::Pixbuf> icon;
std::auto_ptr<Gtk::AboutDialog> about;
std::auto_ptr<View> view;
diff --git a/src/bar-view.cpp b/src/bar-view.cpp
index 2310d0e..6bd8de9 100644
--- a/src/bar-view.cpp
+++ b/src/bar-view.cpp
@@ -23,7 +23,6 @@
#include <algorithm> // for max/min
#include <libgnomecanvasmm/rect.h>
-#include <gconfmm/client.h>
#include "bar-view.hpp"
#include "applet.hpp"
@@ -101,21 +100,73 @@ void Bar::draw(Gnome::Canvas::Canvas &canvas,
Applet *applet, int width, int height, int no, int total,
double time_offset)
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet->get_gconf_client();
-
// get drawing attributes
unsigned int fill_color;
- Gnome::Conf::Value v;
-
- v = client->get(monitor->get_gconf_dir() + "/color");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- fill_color = v.get_int();
- else {
- fill_color = applet->get_fg_color();
- client->set(monitor->get_gconf_dir() + "/color", int(fill_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
+ settings = xfce_rc_simple_open(file, true);
+ 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());
+ }
+ else
+ color_missing = true;
+
+ // Close settings file
+ xfce_rc_close(settings);
+
+ /* 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)
+ {
+ 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_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);
// calculate parameters
diff --git a/src/canvas-view.cpp b/src/canvas-view.cpp
index d17c895..ead4c78 100644
--- a/src/canvas-view.cpp
+++ b/src/canvas-view.cpp
@@ -21,7 +21,6 @@
#include <config.h>
#include <libgnomecanvasmm/pixbuf.h>
-#include <gconfmm/client.h>
#include "canvas-view.hpp"
#include "applet.hpp"
@@ -55,19 +54,66 @@ void CanvasView::do_display()
void CanvasView::do_update()
{
- // first update the configured attributes
- Glib::RefPtr<Gnome::Conf::Client> &client = applet->get_gconf_client();
- Glib::ustring dir = applet->get_gconf_dir();
-
- // FIXME: use schemas?
- if (client->get(dir + "/viewer/size").get_type() == Gnome::Conf::VALUE_INT)
- size = client->get_int(dir + "/viewer/size");
- else {
- size = 60;
- client->set(dir + "/viewer/size", size);
+ /* Obtaining size
+ * Keeping with the default settings group for viewer settings
+ * Search for settings file */
+ gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ settings = xfce_rc_simple_open(file, true);
+ 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);
+ }
+ 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)
+ {
+ // 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_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
+ // Ensure the canvas is shown
resize_canvas();
}
diff --git a/src/choose-monitor-window.cpp b/src/choose-monitor-window.cpp
index 1e5e70a..f3ab657 100644
--- a/src/choose-monitor-window.cpp
+++ b/src/choose-monitor-window.cpp
@@ -20,8 +20,6 @@
#include <config.h>
-#include <gconfmm/client.h>
-
#include "choose-monitor-window.hpp"
#include "gui-helpers.hpp"
#include "monitor-impls.hpp"
@@ -165,111 +163,139 @@ ChooseMonitorWindow::~ChooseMonitorWindow()
}
-Monitor *ChooseMonitorWindow::run(const Glib::RefPtr<Gnome::Conf::Client> &client,
- const Glib::ustring &mon_dir)
+Monitor *ChooseMonitorWindow::run(const XfcePanelPlugin* panel_applet,
+ const Glib::ustring &mon_dir)
{
// setup dialog
- if (!mon_dir.empty()) {
- Glib::ustring type = client->get_string(mon_dir + "/type");
-
- if (type == "memory_usage") {
- device_notebook->set_current_page(1);
- memory_usage_radiobutton->set_active();
- }
- else if (type == "load_average") {
- device_notebook->set_current_page(0);
- load_average_radiobutton->set_active();
- }
- else if (type == "disk_usage") {
- device_notebook->set_current_page(1);
- disk_usage_radiobutton->set_active();
- }
- else if (type == "swap_usage") {
- device_notebook->set_current_page(1);
- swap_usage_radiobutton->set_active();
- }
- else if (type == "network_load") {
- device_notebook->set_current_page(2);
- network_load_radiobutton->set_active();
- }
- else if (type == "temperature") {
- device_notebook->set_current_page(3);
- temperature_radiobutton->set_active();
- }
- else {
- device_notebook->set_current_page(0);
- // FIXME: use schema?
- cpu_usage_radiobutton->set_active();
- }
-
- Gnome::Conf::Value v;
+ if (!mon_dir.empty())
+ {
+ // Search for settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(panel_applet);
- // fill in cpu info
- v = client->get(mon_dir + "/cpu_no");
- if (v.get_type() == Gnome::Conf::VALUE_INT) {
- int no = v.get_int();
- if (no >= 0 && no < CpuUsageMonitor::max_no_cpus) {
- one_cpu_radiobutton->set_active();
- cpu_no_spinbutton->set_value(no + 1);
+ if (file)
+ {
+ // Loading settings
+ xfce_rc_set_group(settings, mon_dir.c_str());
+ Glib::ustring type = xfce_rc_read_entry(settings, "type", "");
+
+ if (type == "memory_usage")
+ {
+ device_notebook->set_current_page(1);
+ memory_usage_radiobutton->set_active();
}
- else {
- all_cpus_radiobutton->set_active();
+ else if (type == "load_average")
+ {
+ device_notebook->set_current_page(0);
+ load_average_radiobutton->set_active();
+ }
+ else if (type == "disk_usage")
+ {
+ device_notebook->set_current_page(1);
+ disk_usage_radiobutton->set_active();
+ }
+ else if (type == "swap_usage")
+ {
+ device_notebook->set_current_page(1);
+ swap_usage_radiobutton->set_active();
+ }
+ else if (type == "network_load")
+ {
+ device_notebook->set_current_page(2);
+ network_load_radiobutton->set_active();
+ }
+ else if (type == "temperature")
+ {
+ device_notebook->set_current_page(3);
+ temperature_radiobutton->set_active();
+ }
+ else
+ {
+ device_notebook->set_current_page(0);
+ // FIXME: use schema?
+ cpu_usage_radiobutton->set_active();
+ }
+
+ // Fill in cpu info
+ if (xfce_rc_has_entry(settings, "cpu_no")
+ {
+ int no = xfce_rc_read_int_entry(settings, "cpu_no", -1)
+ if (no >= 0 && no < CpuUsageMonitor::max_no_cpus) {
+ one_cpu_radiobutton->set_active();
+ cpu_no_spinbutton->set_value(no + 1);
+ }
+ else {
+ all_cpus_radiobutton->set_active();
+ }
}
- }
- // fill in disk usage info
- v = client->get(mon_dir + "/mount_dir");
- if (v.get_type() == Gnome::Conf::VALUE_STRING)
- mount_dir_entry->set_text(v.get_string());
+ // Fill in disk usage info
+ if (xfce_rc_has_entry(settings, "mount_dir")
+ {
+ GLib::ustring mount_dir = xfce_rc_read_entry(settings,
+ "mount_dir", "");
+ mount_dir_entry->set_text(mount_dir);
+ }
+ if (xfce_rc_has_entry(settings, "show_free")
+ {
+ bool show_free = xfce_rc_read_bool_entry(settings,
+ "show_free", false);
+ show_free_checkbutton->set_active(show_free);
+ }
- v = client->get(mon_dir + "/show_free");
- if (v.get_type() == Gnome::Conf::VALUE_BOOL)
- show_free_checkbutton->set_active(v.get_bool());
+ // Fill in network load info
+ if (xfce_rc_has_entry(settings, "interface")
+ {
+ Glib::ustring interface = xfce_rc_read_entry(settings,
+ "interface", "eth");
- // fill in network load info
- v = client->get(mon_dir + "/interface");
- if (v.get_type() == Gnome::Conf::VALUE_STRING) {
- Glib::ustring interface = v.get_string();
+ int interface_no = xfce_rc_read_int_entry(settings,
+ "interface_no", 0);
+
+ if (interface == "eth" && interface_no == 0)
+ network_type_optionmenu->set_history(0);
+ else if (interface == "eth" && interface_no == 1)
+ network_type_optionmenu->set_history(1);
+ else if (interface == "eth" && interface_no == 2)
+ network_type_optionmenu->set_history(2);
+ else if (interface == "ppp")
+ network_type_optionmenu->set_history(3);
+ else if (interface == "slip")
+ network_type_optionmenu->set_history(4);
+ else if (interface == "wlan")
+ network_type_optionmenu->set_history(5);
+ else
+ network_type_optionmenu->set_history(0);
+ }
- int interface_no = 0;
- v = client->get(mon_dir + "/interface_no");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- interface_no = v.get_int();
-
- if (interface == "eth" && interface_no == 0)
- network_type_optionmenu->set_history(0);
- else if (interface == "eth" && interface_no == 1)
- network_type_optionmenu->set_history(1);
- else if (interface == "eth" && interface_no == 2)
- network_type_optionmenu->set_history(2);
- else if (interface == "ppp")
- network_type_optionmenu->set_history(3);
- else if (interface == "slip")
- network_type_optionmenu->set_history(4);
- else if (interface == "wlan")
- network_type_optionmenu->set_history(5);
- else
- network_type_optionmenu->set_history(0);
- }
-
- v = client->get(mon_dir + "/interface_direction");
- if (v.get_type() == Gnome::Conf::VALUE_INT) {
- int direction = v.get_int();
-
- if (direction == NetworkLoadMonitor::incoming_data)
- network_direction_optionmenu->set_history(1);
- else if (direction == NetworkLoadMonitor::outgoing_data)
- network_direction_optionmenu->set_history(2);
- else if (direction == NetworkLoadMonitor::all_data)
- network_direction_optionmenu->set_history(0);
+ if (xfce_rc_has_entry(settings, "interface_direction")
+ {
+ int direction = xfce_rc_read_int_entry(settings,
+ "interface_direction", NetworkLoadMonitor::all_data);
+
+ if (direction == NetworkLoadMonitor::incoming_data)
+ network_direction_optionmenu->set_history(1);
+ else if (direction == NetworkLoadMonitor::outgoing_data)
+ network_direction_optionmenu->set_history(2);
+ else if (direction == NetworkLoadMonitor::all_data)
+ network_direction_optionmenu->set_history(0);
+ }
+
+ int temperature_no = xfce_rc_read_int_entry(settings,
+ "temperature_no", 0);
+
+ temperature_optionmenu->set_history(temperature_no);
}
+ 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");
- int temperature_no = 0;
- v = client->get(mon_dir + "/temperature_no");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- temperature_no = v.get_int();
-
- temperature_optionmenu->set_history(temperature_no);
+ // Default setting?
+ device_notebook->set_current_page(0);
+ // FIXME: use schema?
+ cpu_usage_radiobutton->set_active();
+ }
}
if (cpu_usage_radiobutton->get_active())
@@ -411,4 +437,3 @@ bool ChooseMonitorWindow::on_closed(GdkEventAny *)
window->hide();
return false;
}
-
diff --git a/src/choose-monitor-window.hpp b/src/choose-monitor-window.hpp
index 069937f..a0d2678 100644
--- a/src/choose-monitor-window.hpp
+++ b/src/choose-monitor-window.hpp
@@ -45,8 +45,8 @@ public:
~ChooseMonitorWindow();
// given a monitor directory (may be ""), return a new monitor or 0
- Monitor *run(const Glib::RefPtr<Gnome::Conf::Client> &client,
- const Glib::ustring &mon_dir);
+ Monitor *run(const XfcePanelPlugin* panel_applet,
+ const Glib::ustring &mon_dir);
private:
Glib::RefPtr<Gnome::Glade::Xml> ui;
diff --git a/src/column-view.cpp b/src/column-view.cpp
index d40212f..6f025d9 100644
--- a/src/column-view.cpp
+++ b/src/column-view.cpp
@@ -21,7 +21,6 @@
#include <cmath>
#include <libgnomecanvasmm/pixbuf.h>
-#include <gconfmm/client.h>
#include "column-view.hpp"
#include "applet.hpp"
@@ -79,7 +78,7 @@ void ColumnGraph::draw(Gnome::Canvas::Canvas &canvas,
double time_offset = double(remaining_draws) / CanvasView::draw_iterations;
- Glib::RefPtr<Gnome::Conf::Client> &client = applet->get_gconf_client();
+ Glib::RefPtr<Gnome::Conf::Client> &client = applet->panel_applet;
ValueHistory::iterator vi = value_history.values.begin(),
vend = value_history.values.end();
@@ -87,18 +86,71 @@ void ColumnGraph::draw(Gnome::Canvas::Canvas &canvas,
if (vi == vend) // there must be at least one point
return;
-
// get colour
unsigned int color;
- Gnome::Conf::Value v;
-
- v = client->get(monitor->get_gconf_dir() + "/color");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- color = v.get_int();
- else {
- color = applet->get_fg_color();
- client->set(monitor->get_gconf_dir() + "/color", int(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
+ settings = xfce_rc_simple_open(file, true);
+ 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());
+ }
+ else
+ color_missing = true;
+
+ // Close settings file
+ xfce_rc_close(settings);
+
+ /* 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)
+ {
+ 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_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");
+ }
+ }
+ }
+ 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
@@ -116,7 +168,6 @@ void ColumnGraph::draw(Gnome::Canvas::Canvas &canvas,
pixbuf->fill(color & 0xFFFFFF00);
-
double max = monitor->max();
if (max <= 0)
max = 0.0000001;
@@ -126,30 +177,31 @@ void ColumnGraph::draw(Gnome::Canvas::Canvas &canvas,
+ ColumnView::pixels_per_sample * time_offset;
do {
- if (*vi >= 0) {
+ if (*vi >= 0)
+ {
// FIXME: the uppermost pixel should be scaled down too to avoid aliasing
double r = l + ColumnView::pixels_per_sample;
- int
- t = int((1 - (*vi / max)) * (height - 1)),
- b = height - 1;
+ int t = int((1 - (*vi / max)) * (height - 1)),
+ b = height - 1;
if (t < 0)
- t = 0;
+ t = 0;
- for (int x = std::max(int(l), 0); x < std::min(r, double(width)); ++x) {
- PixelPosition pos = get_position(pixbuf, x, t);
-
- // anti-aliasing effect; if we are partly on a pixel, scale alpha down
- double scale = 1.0;
- if (x < l)
- scale -= l - std::floor(l);
- if (x + 1 > r)
- scale -= std::ceil(r) - r;
-
- int alpha = int((color & 0xFF) * scale);
-
- for (int y = t; y <= b; ++y, pos.down())
- pos.pixel().alpha() = std::min(pos.pixel().alpha() + alpha, 255);
+ for (int x = std::max(int(l), 0); x < std::min(r, double(width)); ++x)
+ {
+ PixelPosition pos = get_position(pixbuf, x, t);
+
+ // anti-aliasing effect; if we are partly on a pixel, scale alpha down
+ double scale = 1.0;
+ if (x < l)
+ scale -= l - std::floor(l);
+ if (x + 1 > r)
+ scale -= std::ceil(r) - r;
+
+ int alpha = int((color & 0xFF) * scale);
+
+ for (int y = t; y <= b; ++y, pos.down())
+ pos.pixel().alpha() = std::min(pos.pixel().alpha() + alpha, 255);
}
}
diff --git a/src/curve-view.cpp b/src/curve-view.cpp
index ca11182..8d414d2 100644
--- a/src/curve-view.cpp
+++ b/src/curve-view.cpp
@@ -22,7 +22,6 @@
#include <libgnomecanvasmm/line.h>
#include <libgnomecanvasmm/point.h>
-#include <gconfmm/client.h>
#include "curve-view.hpp"
#include "applet.hpp"
@@ -75,9 +74,6 @@ void Curve::draw(Gnome::Canvas::Canvas &canvas,
double time_offset = double(remaining_draws) / CanvasView::draw_iterations;
-
- Glib::RefPtr<Gnome::Conf::Client> &client = applet->get_gconf_client();
-
ValueHistory::iterator vi = value_history.values.begin(),
vend = value_history.values.end();
@@ -96,21 +92,74 @@ void Curve::draw(Gnome::Canvas::Canvas &canvas,
unsigned int color;
double const line_width = 1.5;
- Gnome::Conf::Value v;
-
- v = client->get(monitor->get_gconf_dir() + "/color");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- color = v.get_int();
- else {
- color = applet->get_fg_color();
- client->set(monitor->get_gconf_dir() + "/color", int(color));
+ // 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
+ settings = xfce_rc_simple_open(file, true);
+ 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());
+ }
+ else
+ color_missing = true;
+
+ // Close settings file
+ xfce_rc_close(settings);
+
+ /* 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)
+ {
+ 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_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;
line->property_width_units() = line_width;
-
double max = monitor->max();
if (max <= 0)
max = 0.0000001;
diff --git a/src/flame-view.cpp b/src/flame-view.cpp
index 0365e07..cb8c012 100644
--- a/src/flame-view.cpp
+++ b/src/flame-view.cpp
@@ -23,7 +23,6 @@
#include <vector>
#include <libgnomecanvasmm/pixbuf.h>
-#include <gconfmm/client.h>
#include "pixbuf-drawing.hpp"
@@ -67,67 +66,119 @@ Flame::Flame(Monitor *m)
void Flame::update(Gnome::Canvas::Canvas &canvas,
Applet *applet, int width, int height, int no, int total)
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet->get_gconf_client();
-
- // get color
-
+ // Get color
unsigned int color;
- Gnome::Conf::Value v;
-
- v = client->get(monitor->get_gconf_dir() + "/color");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- color = v.get_int();
- else {
- color = applet->get_fg_color();
- client->set(monitor->get_gconf_dir() + "/color", int(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
+ settings = xfce_rc_simple_open(file, true);
+ 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());
+ }
+ else
+ color_missing = true;
+
+ // Close settings file
+ xfce_rc_close(settings);
+
+ /* 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)
+ {
+ 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_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");
+ }
+ }
+ }
+ 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
-
- if (flame.get() == 0) {
+ // Then make sure layer is correctly setup
+ if (flame.get() == 0)
+ {
Glib::RefPtr<Gdk::Pixbuf> p =
Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, width, height);
p->fill(color & 0xFFFFFF00);
flame.reset(new Gnome::Canvas::Pixbuf(*canvas.root(), 0, 0, p));
}
- else {
+ else
+ {
Glib::RefPtr<Gdk::Pixbuf> pixbuf = flame->property_pixbuf();
// perhaps the dimensions have changed
- if (pixbuf->get_width() != width || pixbuf->get_height() != height) {
+ if (pixbuf->get_width() != width || pixbuf->get_height() != height)
+ {
Glib::RefPtr<Gdk::Pixbuf> new_pixbuf =
Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, width, height);
new_pixbuf->fill(color & 0xFFFFFF00);
flame->property_pixbuf() = new_pixbuf;
}
- else {
+ else
+ {
// perhaps the color has changed
PixelIterator i = begin(pixbuf);
- unsigned char
- red = color >> 24,
- green = color >> 16,
- blue = color >> 8;
+ unsigned char red = color >> 24,
+ green = color >> 16,
+ blue = color >> 8;
- if (i->red() != red || i->green() != green || i->blue() != blue) {
- for (PixelIterator e = end(pixbuf); i != e; ++i) {
- Pixel pixel = *i;
- pixel.red() = red;
- pixel.green() = green;
- pixel.blue() = blue;
- }
+ if (i->red() != red || i->green() != green || i->blue() != blue)
+ {
+ for (PixelIterator e = end(pixbuf); i != e; ++i)
+ {
+ Pixel pixel = *i;
+ pixel.red() = red;
+ pixel.green() = green;
+ pixel.blue() = blue;
+ }
- flame->property_pixbuf() = pixbuf;
+ flame->property_pixbuf() = pixbuf;
}
}
}
-
-
- // finally just extract values, we don't draw here
+ // Finally just extract values, we don't draw here
monitor->measure();
value = monitor->value();
@@ -157,24 +208,25 @@ void Flame::recompute_fuel()
if (next_refuel <= 0) {
next_refuel = random_between(5, 20);
- // the fuel values are calculated from parabels with the branches
+ // The fuel values are calculated from parabels with the branches
// turning downwards, concatenated at the roots; span is the
// distance between the roots and max is the value at the summit
- int span = 0, max = 0;
-
- int i = 0;
+ int span = 0, max = 0, i = 0;
for (std::vector<unsigned char>::iterator x = fuel.begin(),
- end = fuel.end(); x != end; ++x) {
- if (i <= 0) {
- // new graph, new parameters
- i = span = random_between(6, 16);
- max = random_between(255 + ratio * 3, 255 * 2 + ratio * 6) / 8;
+ end = fuel.end(); x != end; ++x)
+ {
+ if (i <= 0)
+ {
+ // new graph, new parameters
+ i = span = random_between(6, 16);
+ max = random_between(255 + ratio * 3, 255 * 2 + ratio * 6) / 8;
}
- else {
- // y = -(x - |r1-r2|/2)^2 + y_max
- *x = - (i - span / 2) * (i - span / 2) + max;
- --i;
+ else
+ {
+ // y = -(x - |r1-r2|/2)^2 + y_max
+ *x = - (i - span / 2) * (i - span / 2) + max;
+ --i;
}
}
}
@@ -194,19 +246,20 @@ void Flame::burn()
recompute_fuel();
- // process the lowest row
+ // Process the lowest row
PixelPosition lowest = get_position(pixbuf, 0, height - 1);
- for (int x = 0; x < width; ++x) {
+ for (int x = 0; x < width; ++x)
+ {
lowest.pixel().alpha() = (lowest.pixel().alpha() * 3 + fuel[x]) / 4;
lowest.right();
}
- // then process the rest of the pixbuf
- for (int y = height - 2; y >= 0; --y) {
- // setup positions
- PixelPosition
- pos = get_position(pixbuf, 0, y),
+ // Then process the rest of the pixbuf
+ for (int y = height - 2; y >= 0; --y)
+ {
+ // Setup positions
+ PixelPosition pos = get_position(pixbuf, 0, y),
right = get_position(pixbuf, 2, y),
below = get_position(pixbuf, 1, y + 1);
@@ -214,18 +267,19 @@ void Flame::burn()
pos.right();
// process row
- for (int x = 1; x < width - 1; ++x) {
+ for (int x = 1; x < width - 1; ++x)
+ {
// this is int to ensure enough precision in sum below
- unsigned int
- pos_alpha = pos.pixel().alpha(),
- right_alpha = right.pixel().alpha(),
- below_alpha = below.pixel().alpha();
+ unsigned int pos_alpha = pos.pixel().alpha(),
+ right_alpha = right.pixel().alpha(),
+ below_alpha = below.pixel().alpha();
int tmp =
- (left_alpha + 6 * pos_alpha + right_alpha + 8 * below_alpha) / 16;
+ (left_alpha + 6 * pos_alpha + right_alpha + 8 * below_alpha) / 16;
pos.pixel().alpha()
= std::max(((256 + cooling) * tmp - cooling * 256) / 256, 0);
+
#if 0
if (std::rand() / 4 == 0)
pos.pixel().alpha()
@@ -239,7 +293,6 @@ void Flame::burn()
below.right();
}
}
-
flame->property_pixbuf() = pixbuf;
}
@@ -295,4 +348,3 @@ void FlameView::do_draw_loop()
for (flame_iterator i = flames.begin(), end = flames.end(); i != end; ++i)
(*i)->burn();
}
-
diff --git a/src/main.cpp b/src/main.cpp
index f7f8a00..45606ac 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -24,7 +24,6 @@
#include <libintl.h>
#include <libgnomecanvasmm/init.h>
-#include <gconfmm/init.h>
#include <gtkmm/main.h>
#include <libgnomeui/gnome-ui-init.h>
@@ -35,6 +34,7 @@
#include "helpers.hpp"
#include "i18n.hpp"
+// TODO: How does this compare to applet.cpp?
gboolean hardware_monitor_factory(PanelApplet *panel_applet, const gchar *iid,
void *)
{
@@ -53,7 +53,6 @@ int main(int argc, char *argv[])
nice(5); // don't eat up too much CPU
Gtk::Main main(argc, argv);
- Gnome::Conf::init();
Gnome::Canvas::init();
// this is necessary for panel applets
diff --git a/src/monitor-impls.cpp b/src/monitor-impls.cpp
index c658491..d35231b 100644
--- a/src/monitor-impls.cpp
+++ b/src/monitor-impls.cpp
@@ -52,124 +52,110 @@ double const max_decay = 0.999;
//
std::list<Monitor *>
-load_monitors(const Glib::RefPtr<Gnome::Conf::Client> &client,
- const Glib::ustring &dir)
+load_monitors(const XfceRc* const settings)
{
std::list<Monitor *> monitors;
-
- Glib::SListHandle<Glib::ustring> gconf_list
- = client->all_dirs(dir + "/monitors");
-
- for (Glib::SListHandle<Glib::ustring>::const_iterator i = gconf_list.begin(),
- end = gconf_list.end(); i != end; ++i) {
- const Glib::ustring &mon_dir = *i;
-
- Glib::ustring type = client->get_string(mon_dir + "/type");
-
- if (type == "cpu_usage") {
- Gnome::Conf::Value v = client->get(mon_dir + "/cpu_no");
- int cpu_no;
-
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- cpu_no = v.get_int();
- else
- cpu_no = -1;
-
- if (cpu_no == -1)
- monitors.push_back(new CpuUsageMonitor);
- else
- monitors.push_back(new CpuUsageMonitor(cpu_no));
- }
- else if (type == "memory_usage")
- monitors.push_back(new MemoryUsageMonitor);
- else if (type == "swap_usage")
- monitors.push_back(new SwapUsageMonitor);
- else if (type == "load_average")
- monitors.push_back(new LoadAverageMonitor);
- else if (type == "disk_usage") {
- Gnome::Conf::Value v = client->get(mon_dir + "/mount_dir");
- Glib::ustring mount_dir;
-
- if (v.get_type() == Gnome::Conf::VALUE_STRING)
- mount_dir = v.get_string();
- else
- mount_dir = "/"; // FIXME: use schema?
-
- v = client->get(mon_dir + "/show_free");
- bool show_free;
-
- if (v.get_type() == Gnome::Conf::VALUE_BOOL)
- show_free = v.get_bool();
- else
- show_free = false; // FIXME: use schema?
-
- monitors.push_back(new DiskUsageMonitor(mount_dir, show_free));
- }
- else if (type == "network_load") {
- Glib::ustring inter;
- int inter_no, inter_direction;
-
- Gnome::Conf::Value v = client->get(mon_dir + "/interface");
-
- if (v.get_type() == Gnome::Conf::VALUE_STRING)
- inter = v.get_string();
- else
- inter = "eth"; // FIXME: use schema?
+ // Checking if settings currently exist
+ if (settings)
+ {
+ // They do - fetching list of monitors
+ gchar** settings_monitors = xfce_rc_get_groups(settings);
+
+ // They do - looping for all monitors
+ for (gchar** settings_monitor = settings_monitors; *settings_monitor;
+ ++settings_monitors)
+ {
+ // Setting the correct group prior to loading settings
+ xfce_rc_set_group(settings, settings_monitor);
- v = client->get(mon_dir + "/interface_no");
+ // Obtaining monitor type
+ Glib::ustring type = xfce_rc_read_entry(settings, "type", "");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- inter_no = v.get_int();
- else
- inter_no = 0; // FIXME: use schema?
+ if (type == "cpu_usage")
+ {
+ // Obtaining cpu_no
+ int cpu_no = xfce_rc_read_int_entry(settings, cpu_no, -1);
+
+ // Creating CPU usage monitor with provided number if valid
+ if (cpu_no == -1)
+ monitors.push_back(new CpuUsageMonitor);
+ else
+ monitors.push_back(new CpuUsageMonitor(cpu_no));
+ }
+ else if (type == "memory_usage")
+ monitors.push_back(new MemoryUsageMonitor);
+ else if (type == "swap_usage")
+ monitors.push_back(new SwapUsageMonitor);
+ else if (type == "load_average")
+ monitors.push_back(new LoadAverageMonitor);
+ else if (type == "disk_usage")
+ {
+ // Obtaining volume mount directory
+ Glib::ustring mount_dir = xfce_rc_read_entry(settings,
+ "mount_dir", "/");
+
+ // Obtaining whether to show free space or not
+ bool show_free = xfce_rc_read_bool_entry(settings, "show_free",
+ false);
+
+ // Creating disk usage monitor
+ monitors.push_back(new DiskUsageMonitor(mount_dir, show_free));
+ }
+ else if (type == "network_load")
+ {
+ // Fetching interface type
+ Glib::ustring inter = xfce_rc_read_entry(settings, "interface",
+ "eth");
+
+ // Fetching interface number
+ int inter_no = xfce_rc_read_int_entry(settings, "interface_no",
+ 0);
+
+ // Fetching interface 'direction' setting
+ int inter_direction = xfce_rc_read_int_entry(settings,
+ "interface_direction", NetworkLoadMonitor::all_data);
-
- v = client->get(mon_dir + "/interface_direction");
-
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- inter_direction = v.get_int();
- else
- inter_direction = NetworkLoadMonitor::all_data; // FIXME: use schema?
+ // Converting direction setting into dedicated type
+ NetworkLoadMonitor::Direction dir;
+
+ if (inter_direction == NetworkLoadMonitor::incoming_data)
+ dir = NetworkLoadMonitor::incoming_data;
+ else if (inter_direction == NetworkLoadMonitor::outgoing_data)
+ dir = NetworkLoadMonitor::outgoing_data;
+ else
+ dir = NetworkLoadMonitor::all_data;
+
+ // Creating network load monitor
+ monitors.push_back(new NetworkLoadMonitor(inter, inter_no, dir));
+ }
+ else if (type == "temperature")
+ {
+ // Fetching temperature number
+ int temperature_no = xfce_rc_read_int_entry(settings,
+ "temperature_no", 0);
+
+ // Creating temperature monitor
+ monitors.push_back(new TemperatureMonitor(temperature_no));
+ }
+ else if (type == "fan_speed")
+ {
+ // Fetching fan number
+ int fan_no = xfce_rc_read_int_entry(settings, "fan_no", 0);
+
+ // Creating fan monitor
+ monitors.push_back(new FanSpeedMonitor(fan_no));
+ }
- NetworkLoadMonitor::Direction dir;
-
- if (inter_direction == NetworkLoadMonitor::incoming_data)
- dir = NetworkLoadMonitor::incoming_data;
- else if (inter_direction == NetworkLoadMonitor::outgoing_data)
- dir = NetworkLoadMonitor::outgoing_data;
- else
- dir = NetworkLoadMonitor::all_data;
-
- monitors.push_back(new NetworkLoadMonitor(inter, inter_no, dir));
- }
- else if (type == "temperature") {
- Gnome::Conf::Value v = client->get(mon_dir + "/temperature_no");
- int temperature_no;
-
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- temperature_no = v.get_int();
- else
- temperature_no = 0; // FIXME: use schema?
-
- monitors.push_back(new TemperatureMonitor(temperature_no));
- }
- else if (type == "fan_speed") {
- Gnome::Conf::Value v = client->get(mon_dir + "/fan_no");
- int fan_no;
-
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- fan_no = v.get_int();
- else
- fan_no = 0; // FIXME: use schema?
-
- monitors.push_back(new FanSpeedMonitor(fan_no));
+ // Saving the monitor's settings root
+ monitors.back()->set_settings_dir(settings_monitor);
}
- monitors.back()->set_gconf_dir(mon_dir);
+ // Clearing up
+ g_strfreev(settings_monitors);
}
- // always start with a CpuUsageMonitor - FIXME: use schema?
+ // Always start with a CpuUsageMonitor - FIXME: use schema?
if (monitors.empty())
monitors.push_back(new CpuUsageMonitor);
@@ -319,11 +305,15 @@ int CpuUsageMonitor::update_interval()
return 1000;
}
-void CpuUsageMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void CpuUsageMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("cpu_usage"));
- client->set(dir + "/cpu_no", cpu_no);
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "cpu_usage");
+ xfce_rc_write_int_entry(settings, "cpu_no", cpu_no);
}
@@ -378,10 +368,14 @@ int SwapUsageMonitor::update_interval()
return 10 * 1000;
}
-void SwapUsageMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void SwapUsageMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("swap_usage"));
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "swap_usage");
}
@@ -443,20 +437,40 @@ int LoadAverageMonitor::update_interval()
return 30 * 1000;
}
-void LoadAverageMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void LoadAverageMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("load_average"));
- client->set(dir + "/max", max_value);
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "load_average");
+
+ // No support for floats - stringifying
+ Glib::ustring setting = String::ucompose("%1", max_value);
+ xfce_rc_write_entry(settings, "max", setting.c_str());
}
-void LoadAverageMonitor::load(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void LoadAverageMonitor::load(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- if (client->get_string(dir + "/type") == "load_average") {
- Gnome::Conf::Value v = client->get(dir + "/max");
- if (v.get_type() == Gnome::Conf::VALUE_FLOAT)
- max_value = v.get_float();
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Loading settings
+ xfce_rc_set_group(settings, dir.c_str());
+ if (xfce_rc_read_entry(settings, "type", "") == "load_average")
+ {
+ /* No support for floats - unstringifying, making sure the data is
+ * not corrupt */
+ Glib::ustring setting = xfce_rc_read_entry(settings, "max", "5");
+ if (dynamic_cast<float>(setting))
+ max_value = static_cast<float>(setting)
+ else
+ {
+ std::cerr << String::ucompose(_("Unable to configure max load "
+ "average for monitor %1 - cant cast '%2' to float!\n"),
+ dir, setting);
+ }
}
}
@@ -512,10 +526,14 @@ int MemoryUsageMonitor::update_interval()
return 10 * 1000;
}
-void MemoryUsageMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void MemoryUsageMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("memory_usage"));
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "memory_usage");
}
@@ -589,12 +607,16 @@ int DiskUsageMonitor::update_interval()
return 60 * 1000;
}
-void DiskUsageMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void DiskUsageMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("disk_usage"));
- client->set(dir + "/mount_dir", mount_dir);
- client->set(dir + "/show_free", show_free);
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "disk_usage");
+ xfce_rc_write_entry(settings, "mount_dir", mount_dir.c_str());
+ xfce_rc_write_bool_entry(settings, "show_free", show_free);
}
@@ -707,7 +729,7 @@ Glib::ustring NetworkLoadMonitor::get_name()
else if (interface == "wlan" && interface_no == 0)
str = _("Wireless");
else
- // unknown, someone must have been fiddling with GConf
+ // unknown, someone must have been fiddling with the config file
str = String::ucompose("%1%2", interface, interface_no);
if (direction == incoming_data)
@@ -739,7 +761,7 @@ Glib::ustring NetworkLoadMonitor::get_short_name()
// short for wireless
str = _("W.less.");
else
- // unknown, someone must have been fiddling with GConf
+ // unknown, someone must have been fiddling with the config file
str = String::ucompose("%1%2", interface, interface_no);
if (direction == incoming_data)
@@ -755,26 +777,36 @@ int NetworkLoadMonitor::update_interval()
return 1000;
}
-void NetworkLoadMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void NetworkLoadMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("network_load"));
- client->set(dir + "/interface", interface);
- client->set(dir + "/interface_no", interface_no);
- client->set(dir + "/interface_direction", int(direction));
- client->set(dir + "/max", int(max_value)); // hopefully 32 bits is enough
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "network_load");
+ xfce_rc_write_entry(settings, "interface", interface);
+ xfce_rc_write_int_entry(settings, "interface_no", interface_no);
+ xfce_rc_write_int_entry(settings, "interface_direction",
+ int(direction));
+ xfce_rc_write_int_entry(settings, "max", int(max_value));
}
-void NetworkLoadMonitor::load(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void NetworkLoadMonitor::load(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- if (client->get_string(dir + "/type") == "network_load"
- && client->get_string(dir + "/interface") == interface
- && client->get_int(dir + "/interface_no") == interface_no
- && client->get_int(dir + "/interface_direction") == int(direction)) {
- Gnome::Conf::Value v = client->get(dir + "/max");
- if (v.get_type() == Gnome::Conf::VALUE_INT)
- max_value = v.get_int();
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ /* Loading settings - ensuring the settings are for the particular
+ * network monitor?? */
+ xfce_rc_set_group(settings, dir.c_str());
+ if (xfce_rc_read_entry(settings, "type", "") == "network_load"
+ && xfce_rc_read_entry(settings, "interface", "") == interface
+ && xfce_rc_read_int_entry(settings, "interface_no", 0) == interface
+ && xfce_rc_read_int_entry(settings, "interface_direction",
+ incoming_data) s== interface)
+ {
+ max_value = xfce_rc_read_int_entry(settings, "max", 0);
}
}
@@ -973,22 +1005,43 @@ int TemperatureMonitor::update_interval()
return 20 * 1000;
}
-void TemperatureMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void TemperatureMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("temperature"));
- client->set(dir + "/temperature_no", sensors_no);
- client->set(dir + "/max", max_value);
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "temperature");
+ xfce_rc_write_int_entry(settings, "temperature_no", sensors_no);
+
+ // No support for floats - stringifying
+ Glib::ustring setting = String::ucompose("%1", max_value);
+ xfce_rc_write_entry(settings, "max", setting.c_str());
}
-void TemperatureMonitor::load(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void TemperatureMonitor::load(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- if (client->get_string(dir + "/type") == "temperature"
- && client->get_int(dir + "/temperature_no") == sensors_no) {
- Gnome::Conf::Value v = client->get(dir + "/max");
- if (v.get_type() == Gnome::Conf::VALUE_FLOAT)
- max_value = v.get_float();
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Loading settings, making sure the right sensor is loaded
+ xfce_rc_set_group(settings, dir.c_str());
+ if (xfce_rc_read_entry(settings, "type", "") == "temperature"
+ && xfce_rc_read_int_entry(settings, "temperature_no", 0) ==
+ sensors_no)
+ {
+ /* No support for floats - unstringifying, making sure the data is
+ * not corrupt */
+ Glib::ustring setting = xfce_rc_read_entry(settings, "max", "40");
+ if (dynamic_cast<float>(setting))
+ max_value = static_cast<float>(setting)
+ else
+ {
+ std::cerr << String::ucompose(_("Unable to configure max "
+ "temperature for monitor %1 - cant cast '%2' to float!\n"),
+ dir, setting);
+ }
}
}
@@ -1054,21 +1107,42 @@ int FanSpeedMonitor::update_interval()
return 20 * 1000;
}
-void FanSpeedMonitor::save(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void FanSpeedMonitor::save(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- client->set(dir + "/type", Glib::ustring("fan_speed"));
- client->set(dir + "/fan_no", sensors_no);
- client->set(dir + "/max", max_value);
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Saving settings
+ xfce_rc_set_group(settings, dir.c_str());
+ xfce_rc_write_entry(settings, "type", "fan_speed");
+ xfce_rc_write_int_entry(settings, "fan_no", sensors_no);
+
+ // No support for floats - stringifying
+ Glib::ustring setting = String::ucompose("%1", max_value);
+ xfce_rc_write_entry(settings, "max", setting.c_str());
}
-void FanSpeedMonitor::load(const Glib::RefPtr<Gnome::Conf::Client> &client)
+void FanSpeedMonitor::load(XfceRc *settings)
{
- Glib::ustring dir = get_gconf_dir();
- if (client->get_string(dir + "/type") == "fan_speed"
- && client->get_int(dir + "/fan_no") == sensors_no) {
- Gnome::Conf::Value v = client->get(dir + "/max");
- if (v.get_type() == Gnome::Conf::VALUE_FLOAT)
- max_value = v.get_float();
+ // Fetching assigned settings group
+ Glib::ustring dir = get_settings_dir();
+
+ // Loading settings, making sure the right fan is loaded
+ xfce_rc_set_group(settings, dir.c_str());
+ if (xfce_rc_read_entry(settings, "type", "") == "fan_speed"
+ && xfce_rc_read_int_entry(settings, "fan_no", 0) ==
+ sensors_no)
+ {
+ /* No support for floats - unstringifying, making sure the data is
+ * not corrupt */
+ Glib::ustring setting = xfce_rc_read_entry(settings, "max", "1");
+ if (dynamic_cast<float>(setting))
+ max_value = static_cast<float>(setting)
+ else
+ {
+ std::cerr << String::ucompose(_("Unable to configure max fan RPM "
+ "for monitor %1 - cant cast '%2' to float!\n"),
+ dir, setting);
+ }
}
}
diff --git a/src/monitor-impls.hpp b/src/monitor-impls.hpp
index 09cd7e0..9b992cb 100644
--- a/src/monitor-impls.hpp
+++ b/src/monitor-impls.hpp
@@ -47,7 +47,7 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
static int const max_no_cpus;
@@ -73,7 +73,7 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
private:
virtual double do_measure();
@@ -92,8 +92,8 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
- virtual void load(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
+ virtual void load(XfceRc *settings);
private:
virtual double do_measure();
@@ -112,7 +112,7 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
private:
virtual double do_measure();
@@ -131,7 +131,7 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
private:
virtual double do_measure();
@@ -157,8 +157,8 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
- virtual void load(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
+ virtual void load(XfceRc *settings);
virtual void possibly_add_sync_with(Monitor *other);
virtual void remove_sync_with(Monitor *other);
@@ -190,8 +190,8 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
- virtual void load(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
+ virtual void load(XfceRc *settings);
private:
virtual double do_measure();
@@ -212,8 +212,8 @@ public:
virtual Glib::ustring get_name();
virtual Glib::ustring get_short_name();
virtual int update_interval();
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client);
- virtual void load(const Glib::RefPtr<Gnome::Conf::Client> &client);
+ virtual void save(XfceRc *settings);
+ virtual void load(XfceRc *settings);
private:
virtual double do_measure();
diff --git a/src/monitor.hpp b/src/monitor.hpp
index 7f514fc..812ab42 100644
--- a/src/monitor.hpp
+++ b/src/monitor.hpp
@@ -24,7 +24,6 @@
#include <string>
#include <list>
#include <glibmm/ustring.h>
-#include <gconfmm/client.h>
#include "helpers.hpp"
@@ -53,14 +52,14 @@ public:
return measured_value;
}
- void set_gconf_dir(const Glib::ustring &new_dir)
+ void set_settings_dir(const Glib::ustring &new_dir)
{
- gconf_dir = new_dir;
+ settings_dir = new_dir;
}
- Glib::ustring get_gconf_dir()
+ Glib::ustring get_settings_dir()
{
- return gconf_dir;
+ return settings_dir;
}
// the max value that the monitor may attain
@@ -80,10 +79,10 @@ public:
virtual int update_interval() = 0;
// save information about the monitor
- virtual void save(const Glib::RefPtr<Gnome::Conf::Client> &client) = 0;
+ virtual void save(XfceRc *settings) = 0;
// load any internal monitor state
- virtual void load(const Glib::RefPtr<Gnome::Conf::Client> &client)
+ virtual void load(XfceRc *settings)
{
}
@@ -105,7 +104,7 @@ private:
// perform actual measurement, for derived classes
virtual double do_measure() = 0;
- Glib::ustring gconf_dir;
+ Glib::ustring settings_dir;
};
diff --git a/src/preferences-window.cpp b/src/preferences-window.cpp
index f49a4d2..384163b 100644
--- a/src/preferences-window.cpp
+++ b/src/preferences-window.cpp
@@ -23,7 +23,6 @@
#include <sigc++/bind.h>
#include <gtkmm/button.h>
-#include <gconfmm/client.h>
#include <cassert>
@@ -35,6 +34,9 @@
#include "i18n.hpp"
+// Private prototypes
+void save_font_name(Glib::ustring &font_name)
+
void PreferencesWindow::connect_monitor_colorbutton(Gtk::ColorButton
*colorbutton)
{
@@ -162,8 +164,9 @@ PreferencesWindow::PreferencesWindow(Applet &applet_, monitor_seq monitors)
// connect GConf
+ // TODO: Do these even need to be set up? When a chnge is made, then the relevant function is to be called
+ /*
Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
client->notify_add(dir + "/viewer_type",
sigc::mem_fun(*this, &PreferencesWindow::
@@ -178,27 +181,27 @@ PreferencesWindow::PreferencesWindow(Applet &applet_, monitor_seq monitors)
client->notify_add(dir + "/viewer/font",
sigc::mem_fun(*this, &PreferencesWindow::font_listener));
+ */
- // fill in values
- viewer_type_listener(0, client->get_entry(dir + "/viewer_type"));
- background_color_listener(0, client->get_entry(dir + "/background_color"));
- use_background_color_listener(0, client
- ->get_entry(dir + "/use_background_color"));
- size_listener(0, client->get_entry(dir + "/viewer/size"));
- font_listener(0, client->get_entry(dir + "/viewer/font"));
+ // Fill in values
+ viewer_type_listener(0, &applet->viewer_type);
+ background_color_listener(0, applet->background_color);
+ use_background_color_listener(0, applet->use_background_color);
+ size_listener(0, applet->viewer_size);
+ font_listener(0, &applet->viewer_font);
for (monitor_iter i = monitors.begin(), end = monitors.end(); i != end; ++i)
add_to_monitors_list(*i);
- // deselect all to allow the user to discover the relationship
+ // Deselect all to allow the user to discover the relationship
// between the greyed-out buttons and the treeview
monitor_treeview->get_selection()->unselect_all();
- // make sure background colorbutton is grayed out
+ // Make sure background colorbutton is grayed out
background_color_radiobutton->toggled();
- // connect close operations
+ // Connect close operations
Gtk::Button *close_button;
ui->get_widget("close_button", close_button);
@@ -250,46 +253,46 @@ namespace
}
-// GConf callbacks
-
+// Originally gconf callbacks
void PreferencesWindow::viewer_type_listener(unsigned int,
- Gnome::Conf::Entry entry)
+ Glib::ustring &viewer_type;)
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_STRING)
- return;
-
- Glib::ustring s = entry.get_value().get_string();
-
- if (s == "curve") {
+ if (viewer_type == "curve")
+ {
if (!curve_radiobutton->get_active())
curve_radiobutton->property_active() = true;
size_outer_vbox->property_visible() = true;
monitor_curve_options->property_visible() = true;
}
- else if (s == "bar") {
+ else if (viewer_type == "bar")
+ {
if (!bar_radiobutton->get_active())
bar_radiobutton->property_active() = true;
size_outer_vbox->property_visible() = true;
monitor_bar_options->property_visible() = true;
}
- else if (s == "vbar") {
+ else if (viewer_type == "vbar")
+ {
if (!vbar_radiobutton->get_active())
vbar_radiobutton->property_active() = true;
size_outer_vbox->property_visible() = true;
monitor_vbar_options->property_visible() = true;
}
- else if (s == "column") {
+ else if (viewer_type == "column")
+ {
if (!column_radiobutton->get_active())
column_radiobutton->property_active() = true;
size_outer_vbox->property_visible() = true;
monitor_column_options->property_visible() = true;
}
- else if (s == "text") {
+ else if (viewer_type == "text")
+ {
if (!text_radiobutton->get_active())
text_radiobutton->property_active() = true;
font_outer_vbox->property_visible() = true;
}
- else if (s == "flame") {
+ else if (viewer_type == "flame")
+ {
if (!flame_radiobutton->get_active())
flame_radiobutton->property_active() = true;
size_outer_vbox->property_visible() = true;
@@ -298,69 +301,51 @@ void PreferencesWindow::viewer_type_listener(unsigned int,
}
void PreferencesWindow::background_color_listener(unsigned int,
- Gnome::Conf::Entry entry)
+ unsigned int background_color)
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_INT)
- return;
-
- unsigned int i = entry.get_value().get_int();
-
- unsigned char r = i >> 24, g = i >> 16, b = i >> 8, a = i;
+ unsigned char r = background_color >> 24,
+ g = background_color >> 16,
+ b = background_color >> 8,
+ a = background_color;
update_colorbutton_if_different(background_colorbutton, r, g, b, a);
}
void PreferencesWindow::use_background_color_listener(unsigned int,
- Gnome::Conf::Entry entry)
+ bool use_background_color)
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_BOOL)
- return;
-
- bool b = entry.get_value().get_bool();
-
- if (b)
+ if (use_background_color)
background_color_radiobutton->set_active();
else
panel_background_radiobutton->set_active();
}
void PreferencesWindow::size_listener(unsigned int,
- Gnome::Conf::Entry entry)
+ int viewer_size)
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_INT)
- return;
-
- int i = entry.get_value().get_int();
-
- if (size_scale_to_pixels(int(size_scale->get_value())) != i)
- size_scale->set_value(pixels_to_size_scale(i));
+ if (size_scale_to_pixels(int(size_scale->get_value())) != viewer_size)
+ size_scale->set_value(pixels_to_size_scale(viewer_size));
}
-void PreferencesWindow::font_listener(unsigned int, Gnome::Conf::Entry entry)
+void PreferencesWindow::font_listener(unsigned int,
+ Glib::ustring &viewer_font)
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_STRING)
- return;
-
- Glib::ustring font = entry.get_value().get_string();
-
- if (font.empty())
+ if (viewer_font.empty())
font_checkbutton->set_active(false);
else {
font_checkbutton->set_active(true);
- if (fontbutton->get_font_name() != font)
- fontbutton->set_font_name(font);
+ if (fontbutton->get_font_name() != viewer_font)
+ fontbutton->set_font_name(viewer_font);
}
}
void PreferencesWindow::monitor_color_listener(unsigned int,
- Gnome::Conf::Entry entry)
+ unsigned int color)
{
- if (entry.get_value().get_type() != Gnome::Conf::VALUE_INT)
- return;
-
- unsigned int i = entry.get_value().get_int();
-
- unsigned char r = i >> 24, g = i >> 16, b = i >> 8, a = i;
+ unsigned char r = color >> 24,
+ g = color >> 16,
+ b = color >> 8,
+ a = color;
update_colorbutton_if_different(line_colorbutton, r, g, b, a);
update_colorbutton_if_different(bar_colorbutton, r, g, b, a);
@@ -383,8 +368,8 @@ namespace
}
-void PreferencesWindow::sync_conf_with_colorbutton(std::string path,
- Gtk::ColorButton *button)
+void PreferencesWindow::sync_conf_with_colorbutton(std::string settings_dir,
+ std::string setting_name, Gtk::ColorButton *button)
{
// extract info from button
unsigned char a, r, g, b;
@@ -395,148 +380,344 @@ void PreferencesWindow::sync_conf_with_colorbutton(std::string path,
r = c.get_red() >> 8;
g = c.get_green() >> 8;
b = c.get_blue() >> 8;
-
- // update configuration
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- client->set(path, int(pack_int(r, g, b, a)));
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+
+ // Focussing settings group if requested
+ if (!settings_dir.empty())
+ xfce_rc_set_group(settings, settings_dir.c_str());
+
+ // Updating configuration
+ xfce_rc_write_int_entry(settings, setting_name.c_str(),
+ int(pack_int(r, g, b, a)));
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save configuration change in "
+ "PreferencesWindow::sync_conf_with_colorbutton!\n");
+ }
}
void PreferencesWindow::on_background_colorbutton_set()
{
- sync_conf_with_colorbutton(applet.get_gconf_dir() + "/background_color",
+ sync_conf_with_colorbutton("", "background_color",
background_colorbutton);
}
void PreferencesWindow::on_background_color_radiobutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool on = background_color_radiobutton->get_active();
background_colorbutton->set_sensitive(on);
-
- client->set(dir + "/use_background_color", on);
+ use_background_color_listener(0, on)
+
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+
+ // Updating configuration
+ xfce_rc_write_bool_entry(settings, "use_background_color", on);
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save use_background_color in "
+ "PreferencesWindow::on_background_color_radiobutton_toggled!\n");
+ }
}
void PreferencesWindow::on_curve_radiobutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool active = curve_radiobutton->get_active();
if (active)
- client->set(dir + "/viewer_type", Glib::ustring("curve"));
+ {
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+
+ // Updating configuration
+ xfce_rc_write_entry(settings, "viewer_type", "curve");
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer type in "
+ "PreferencesWindow::on_curve_radiobutton_toggled!\n");
+ }
+ }
size_outer_vbox->property_visible() = active;
monitor_curve_options->property_visible() = active;
+ viewer_type_listener(0, "curve");
}
void PreferencesWindow::on_bar_radiobutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool active = bar_radiobutton->get_active();
if (active)
- client->set(dir + "/viewer_type", Glib::ustring("bar"));
+ {
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+
+ // Updating configuration
+ xfce_rc_write_entry(settings, "viewer_type", "bar");
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer type in "
+ "PreferencesWindow::on_bar_radiobutton_toggled!\n");
+ }
+ }
size_outer_vbox->property_visible() = active;
monitor_bar_options->property_visible() = active;
+ viewer_type_listener(0, "bar");
}
void PreferencesWindow::on_vbar_radiobutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool active = vbar_radiobutton->get_active();
if (active)
- client->set(dir + "/viewer_type", Glib::ustring("vbar"));
+ {
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+
+ // Updating configuration
+ xfce_rc_write_entry(settings, "viewer_type", "vbar");
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer type in "
+ "PreferencesWindow::on_vbar_radiobutton_toggled!\n");
+ }
+ }
size_outer_vbox->property_visible() = active;
monitor_vbar_options->property_visible() = active;
+ viewer_type_listener(0, "vbar");
}
void PreferencesWindow::on_column_radiobutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool active = column_radiobutton->get_active();
if (active)
- client->set(dir + "/viewer_type", Glib::ustring("column"));
+ {
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+ // Updating configuration
+ xfce_rc_write_entry(settings, "viewer_type", "column");
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer type in "
+ "PreferencesWindow::on_column_radiobutton_toggled!\n");
+ }
+ }
+
size_outer_vbox->property_visible() = active;
monitor_column_options->property_visible() = active;
+ viewer_type_listener(0, "column");
}
void PreferencesWindow::on_text_radiobutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool active = text_radiobutton->get_active();
if (active)
- client->set(dir + "/viewer_type", Glib::ustring("text"));
+ {
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+
+ // Updating configuration
+ xfce_rc_write_entry(settings, "viewer_type", "text");
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer type in "
+ "PreferencesWindow::on_text_radiobutton_toggled!\n");
+ }
+ }
+
font_outer_vbox->property_visible() = active;
+ viewer_type_listener(0, "text");
}
void PreferencesWindow::on_flame_radiobutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool active = flame_radiobutton->get_active();
if (active)
- client->set(dir + "/viewer_type", Glib::ustring("flame"));
+ {
+ // Search for a writeable settings file, create one if it doesnt exist
+ gchar* 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);
+
+ // Updating configuration
+ xfce_rc_write_entry(settings, "viewer_type", "flame");
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer type in "
+ "PreferencesWindow::on_flame_radiobutton_toggled!\n");
+ }
+ }
size_outer_vbox->property_visible() = active;
monitor_flame_options->property_visible() = active;
+ viewer_type_listener(0, "flame");
}
void PreferencesWindow::on_size_scale_changed()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
+ // Preventing further callbacks firing
size_scale_cb.block();
+
+ // Adding 0.5 to current scale value??
int i = int(size_scale->get_value() + 0.5);
size_scale->set_value(i);
- client->set(dir + "/viewer/size", size_scale_to_pixels(i));
+
+ /* Saving pixel value of scale
+ * Search for a writeable settings file, create one if it doesnt exist */
+ gchar* 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);
+
+ // Updating configuration
+ xfce_rc_write_int_entry(settings, "viewer_size",
+ size_scale_to_pixels(i));
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+ else
+ {
+ // Unable to obtain writeable config file - informing user and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save scale pixel value in "
+ "PreferencesWindow::on_size_scale_changed!\n");
+ }
+
+ // Allowing further callbacks to fire
size_scale_cb.unblock();
+ size_listener(0, size_scale_to_pixels(i));
}
void PreferencesWindow::on_font_checkbutton_toggled()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
bool active = font_checkbutton->get_active();
fontbutton->set_sensitive(active);
+ // Obtaining font_name to set
+ Glib::ustring font_name;
if (active)
- client->set(dir + "/viewer/font", fontbutton->get_font_name());
+ font_name = fontbutton->get_font_name();
else
- client->set(dir + "/viewer/font", Glib::ustring(""));
+ font_name = "";
+
+ // Saving
+ save_font_name(font_name);
+ font_listener(0, font_name);
}
void PreferencesWindow::on_fontbutton_set()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
- Glib::ustring dir = applet.get_gconf_dir();
-
- client->set(dir + "/viewer/font", fontbutton->get_font_name());
+ // Saving
+ save_font_name(fontbutton->get_font_name());
}
void PreferencesWindow::on_add_button_clicked()
@@ -571,7 +752,7 @@ void PreferencesWindow::on_change_button_clicked()
if (i) {
Monitor *prev_monitor = (*i)[mc.monitor];
Monitor *new_monitor
- = run_choose_monitor_window(prev_monitor->get_gconf_dir());
+ = run_choose_monitor_window(prev_monitor->get_settings_dir());
if (new_monitor) {
applet.replace_monitor(prev_monitor, new_monitor);
@@ -595,26 +776,43 @@ void PreferencesWindow::stop_monitor_listeners()
void PreferencesWindow::on_selection_changed()
{
- Glib::RefPtr<Gnome::Conf::Client> &client = applet.get_gconf_client();
-
static MonitorColumns mc;
store_iter i = monitor_treeview->get_selection()->get_selected();
bool sel = i;
- stop_monitor_listeners();
+ //stop_monitor_listeners();
+
+ // Making sure the selection is available
+ if (sel)
+ {
+ unsigned int con, color;
- if (sel) {
- Glib::ustring key, mon_dir = (*(*i)[mc.monitor]).get_gconf_dir();
- unsigned int con;
+ // Loading up new monitor colour
+ // Fetching assigned settings group
+ Glib::ustring key, mon_dir = (*(*i)[mc.monitor]).get_settings_dir();
- key = mon_dir + "/color";
- con = client->notify_add(key, sigc::mem_fun(*this, &PreferencesWindow::
- monitor_color_listener));
+ // Search for settings file
+ gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
- monitor_color_listener(0, client->get_entry(key));
+ if (file)
+ {
+ // One exists - loading readonly settings
+ settings = xfce_rc_simple_open(file, true);
+ g_free(file);
- monitor_listeners.push_back(con);
+ // Loading color
+ xfce_rc_set_group(settings, mon_dir.c_str());
+ color = xfce_rc_read_int_entry(settings, "color", 0); // TODO: Is this an acceptable default? Can't seem to see how the normal default happens
+
+ // Close settings file
+ xfce_rc_close(settings);
+ }
+
+ // Applying colour
+ monitor_color_listener(0, color);
+
+ //monitor_listeners.push_back(con);
}
remove_button->set_sensitive(sel);
@@ -629,9 +827,9 @@ void PreferencesWindow::on_monitor_colorbutton_set(Gtk::ColorButton *colorbutton
store_iter i = monitor_treeview->get_selection()->get_selected();
if (i) {
- Glib::ustring mon_dir = (*(*i)[mc.monitor]).get_gconf_dir();
+ Glib::ustring mon_dir = (*(*i)[mc.monitor]).get_settings_dir();
- sync_conf_with_colorbutton(mon_dir + "/color", colorbutton);
+ sync_conf_with_colorbutton(mon_dir, "color", colorbutton);
}
}
@@ -649,8 +847,8 @@ bool PreferencesWindow::on_closed(GdkEventAny *)
Monitor *PreferencesWindow::run_choose_monitor_window(const Glib::ustring &str)
{
ChooseMonitorWindow chooser(applet.get_icon(), *window);
-
- return chooser.run(applet.get_gconf_client(), str);
+
+ return chooser.run(applet->panel_applet, str);
}
void PreferencesWindow::add_to_monitors_list(Monitor *mon)
@@ -692,3 +890,30 @@ int PreferencesWindow::pixels_to_size_scale(int pixels)
return min_i;
}
+
+void save_font_name(Glib::ustring &font_name)
+{
+ applet->font = font_name;
+
+ // Search for a writeable settings file, create one if it doesnt exist */
+ gchar* 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);
+
+ // Updating configuration
+ 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 and exiting
+ std::cerr << _("Unable to obtain writeable config file path in order to"
+ " save viewer font in save_font_name!\n");
+ }
+}
diff --git a/src/preferences-window.hpp b/src/preferences-window.hpp
index 7396712..008282a 100644
--- a/src/preferences-window.hpp
+++ b/src/preferences-window.hpp
@@ -27,7 +27,6 @@
#include <libglademm/xml.h>
#include <sigc++/trackable.h>
#include <sigc++/connection.h>
-#include <gconfmm/entry.h>
#include <gtkmm/button.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/colorbutton.h>
@@ -104,13 +103,14 @@ private:
Glib::RefPtr<Gtk::ListStore> monitor_store;
typedef Gtk::ListStore::iterator store_iter;
- // GConf
- void viewer_type_listener(unsigned int, Gnome::Conf::Entry entry);
- void background_color_listener(unsigned int, Gnome::Conf::Entry entry);
- void use_background_color_listener(unsigned int, Gnome::Conf::Entry entry);
- void size_listener(unsigned int, Gnome::Conf::Entry entry);
- void font_listener(unsigned int, Gnome::Conf::Entry entry);
- void monitor_color_listener(unsigned int, Gnome::Conf::Entry entry);
+ // Originally gconf callbacks
+ void viewer_type_listener(unsigned int, Glib::ustring &viewer_type);
+ void background_color_listener(unsigned int,
+ unsigned int background_color);
+ void use_background_color_listener(unsigned int, bool use_background_color);
+ void size_listener(unsigned int, int viewer_size);
+ void font_listener(unsigned int, Glib::ustring &viewer_font);
+ void monitor_color_listener(unsigned int, unsigned int color);
void stop_monitor_listeners();
@@ -147,8 +147,8 @@ private:
// for converting between size_scale units and pixels
int size_scale_to_pixels(int size);
int pixels_to_size_scale(int pixels);
- void sync_conf_with_colorbutton(std::string gconf_path,
- Gtk::ColorButton *button);
+ void sync_conf_with_colorbutton(std::string settings_dir,
+ std::string setting_name, Gtk::ColorButton *button);
void connect_monitor_colorbutton(Gtk::ColorButton *colorbutton);
Applet &applet;
diff --git a/src/text-view.cpp b/src/text-view.cpp
index 9f457b4..8b35e65 100644
--- a/src/text-view.cpp
+++ b/src/text-view.cpp
@@ -98,16 +98,63 @@ void TextView::do_display()
void TextView::do_update()
{
- // first update font
- Glib::RefPtr<Gnome::Conf::Client> &client = applet->get_gconf_client();
- Glib::ustring dir = applet->get_gconf_dir();
-
- // FIXME: use schemas?
- if (client->get(dir + "/viewer/font").get_type() == Gnome::Conf::VALUE_STRING)
- font = client->get_string(dir + "/viewer/font");
- else {
- font = "";
- client->set(dir + "/viewer/font", font);
+ /* First update viewer font
+ * Keeping with the default settings group for viewer settings
+ * Search for settings file */
+ gchar* file = xfce_panel_plugin_lookup_rc_file(applet->panel_applet);
+
+ if (file)
+ {
+ // One exists - loading readonly settings
+ settings = xfce_rc_simple_open(file, true);
+ 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", "");
+ }
+ else
+ font_name_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 (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_write_entry(settings, "viewer_font", font_name);
+
+ // 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");
+ }
+ }
+ }
+ 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
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list