summaryrefslogtreecommitdiff
path: root/netspeed/src
diff options
context:
space:
mode:
Diffstat (limited to 'netspeed/src')
-rw-r--r--netspeed/src/Makefile.am2
-rw-r--r--netspeed/src/netspeed-preferences.c259
-rw-r--r--netspeed/src/netspeed-preferences.h31
-rw-r--r--netspeed/src/netspeed.c368
-rw-r--r--netspeed/src/netspeed.h7
5 files changed, 455 insertions, 212 deletions
diff --git a/netspeed/src/Makefile.am b/netspeed/src/Makefile.am
index faf55e0b..8358b3c9 100644
--- a/netspeed/src/Makefile.am
+++ b/netspeed/src/Makefile.am
@@ -22,6 +22,8 @@ mate_netspeed_applet_SOURCES = \
backend.c \
netspeed.c \
netspeed.h \
+ netspeed-preferences.c \
+ netspeed-preferences.h \
$(NULL)
if HAVE_NL
diff --git a/netspeed/src/netspeed-preferences.c b/netspeed/src/netspeed-preferences.c
new file mode 100644
index 00000000..7ed05a3b
--- /dev/null
+++ b/netspeed/src/netspeed-preferences.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright (C) 2020 MATE Development Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include "backend.h"
+#include "netspeed-preferences.h"
+
+struct _NetspeedPreferences
+{
+ GtkDialog parent;
+
+ NetspeedApplet *netspeed;
+
+ GSettings *settings;
+ GtkWidget *network_device_combo;
+ GtkWidget *show_all_addresses_checkbutton;
+ GtkWidget *show_sum_checkbutton;
+ GtkWidget *show_bits_checkbutton;
+ GtkWidget *show_icon_checkbutton;
+ GtkWidget *show_quality_icon_checkbutton;
+ GtkWidget *change_icon_checkbutton;
+};
+
+typedef enum
+{
+ PROP_NETSPEED_APPLET = 1,
+ N_PROPERTIES
+} NetspeedPreferencesProperty;
+
+G_DEFINE_TYPE (NetspeedPreferences, netspeed_preferences, GTK_TYPE_DIALOG)
+
+static void
+netspeed_preferences_init (NetspeedPreferences *preferences)
+{
+ gtk_widget_init_template (GTK_WIDGET (preferences));
+}
+
+static void
+netspeed_preferences_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (netspeed_preferences_parent_class)->finalize (object);
+}
+
+static void
+netspeed_preferences_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ NetspeedPreferences *self = NETSPEED_PREFERENCES (object);
+
+ switch ((NetspeedPreferencesProperty) property_id) {
+ case PROP_NETSPEED_APPLET:
+ self->netspeed = g_value_get_pointer (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+netspeed_preferences_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NetspeedPreferences *self = NETSPEED_PREFERENCES (object);
+
+ switch ((NetspeedPreferencesProperty) property_id) {
+ case PROP_NETSPEED_APPLET:
+ g_value_set_pointer (value, self->netspeed);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+netspeed_preferences_response (GtkDialog *dialog,
+ gint response_id)
+{
+ NetspeedPreferences *preferences;
+
+ preferences = NETSPEED_PREFERENCES (dialog);
+
+ switch (response_id) {
+ case GTK_RESPONSE_HELP:
+ netspeed_applet_display_help (GTK_WIDGET (dialog),
+ "netspeed_applet-settings");
+ break;
+ default:
+ gtk_widget_destroy (GTK_WIDGET (preferences));
+ }
+}
+
+static void
+on_network_device_combo_changed (GtkComboBox *combo,
+ NetspeedPreferences *preferences)
+{
+ GList *devices;
+ int i, active;
+ gboolean old_auto_change_device, auto_change_device;
+
+ devices = g_object_get_data (G_OBJECT (combo), "devices");
+ active = gtk_combo_box_get_active (combo);
+ g_assert (active > -1);
+
+ old_auto_change_device = auto_change_device = g_settings_get_boolean (preferences->settings,
+ "auto-change-device");
+ if (0 == active) {
+ if (auto_change_device)
+ return;
+ auto_change_device = TRUE;
+ } else {
+ const gchar *current_device_name;
+
+ current_device_name = netspeed_applet_get_current_device_name (preferences->netspeed);
+ auto_change_device = FALSE;
+ for (i = 1; i < active; i++) {
+ devices = g_list_next (devices);
+ }
+ if (g_str_equal (devices->data, current_device_name))
+ return;
+ g_settings_set_string (preferences->settings,
+ "device", devices->data);
+ }
+ if (old_auto_change_device != auto_change_device)
+ g_settings_set_boolean (preferences->settings,
+ "auto-change-device", auto_change_device);
+}
+
+static void
+netspeed_preferences_class_init (NetspeedPreferencesClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
+
+ object_class->finalize = netspeed_preferences_finalize;
+ object_class->set_property = netspeed_preferences_set_property;
+ object_class->get_property = netspeed_preferences_get_property;
+
+ dialog_class->response = netspeed_preferences_response;
+
+ g_object_class_install_property (object_class,
+ PROP_NETSPEED_APPLET,
+ g_param_spec_pointer ("netspeed-applet",
+ "Netspeed Applet",
+ "The Netspeed Applet",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ gtk_widget_class_set_template_from_resource (widget_class, NETSPEED_RESOURCE_PATH "netspeed-preferences.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, NetspeedPreferences, network_device_combo);
+ gtk_widget_class_bind_template_child (widget_class, NetspeedPreferences, show_all_addresses_checkbutton);
+ gtk_widget_class_bind_template_child (widget_class, NetspeedPreferences, show_sum_checkbutton);
+ gtk_widget_class_bind_template_child (widget_class, NetspeedPreferences, show_bits_checkbutton);
+ gtk_widget_class_bind_template_child (widget_class, NetspeedPreferences, show_icon_checkbutton);
+ gtk_widget_class_bind_template_child (widget_class, NetspeedPreferences, show_quality_icon_checkbutton);
+ gtk_widget_class_bind_template_child (widget_class, NetspeedPreferences, change_icon_checkbutton);
+
+ gtk_widget_class_bind_template_callback (widget_class, on_network_device_combo_changed);
+}
+
+static void
+free_devices (gpointer data)
+{
+ g_list_free_full (data, g_free);
+}
+
+static void
+fill_device_combo (NetspeedPreferences *preferences, GSettings *settings)
+{
+ GList *ptr, *devices;
+ int i, active = -1;
+ const gchar *current_device_name;
+ gboolean auto_change_device;
+
+ /* Default means device with default route set */
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (preferences->network_device_combo),
+ _("Default"));
+ ptr = devices = get_available_devices ();
+ current_device_name = netspeed_applet_get_current_device_name (preferences->netspeed);
+ auto_change_device = g_settings_get_boolean (settings, "auto-change-device");
+ for (i = 0; ptr; ptr = g_list_next (ptr)) {
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (preferences->network_device_combo),
+ ptr->data);
+ if (g_str_equal (ptr->data, current_device_name))
+ active = (i + 1);
+ ++i;
+ }
+ if (active < 0 || auto_change_device)
+ active = 0;
+ gtk_combo_box_set_active (GTK_COMBO_BOX (preferences->network_device_combo), active);
+ g_object_set_data_full (G_OBJECT (preferences->network_device_combo), "devices",
+ devices, free_devices);
+}
+
+GtkWidget *
+netspeed_preferences_new (NetspeedApplet *netspeed)
+{
+ NetspeedPreferences *preferences;
+ GSettings *settings;
+
+ preferences = g_object_new (NETSPEED_TYPE_PREFERENCES,
+ "netspeed-applet", netspeed,
+ NULL);
+
+ preferences->settings = settings = netspeed_applet_get_settings (preferences->netspeed);
+
+ fill_device_combo (preferences, settings);
+
+ g_settings_bind (settings, "show-all-addresses",
+ preferences->show_all_addresses_checkbutton, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (settings, "show-sum",
+ preferences->show_sum_checkbutton, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (settings, "show-bits",
+ preferences->show_bits_checkbutton, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (settings, "show-icon",
+ preferences->show_icon_checkbutton, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (settings, "show-quality-icon",
+ preferences->show_quality_icon_checkbutton, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (settings, "change-icon",
+ preferences->change_icon_checkbutton, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ return GTK_WIDGET (preferences);
+}
diff --git a/netspeed/src/netspeed-preferences.h b/netspeed/src/netspeed-preferences.h
new file mode 100644
index 00000000..d10470ab
--- /dev/null
+++ b/netspeed/src/netspeed-preferences.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 MATE Development Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSPEED_PREFERENCES_H
+#define NETSPEED_PREFERENCES_H
+
+#include <gtk/gtk.h>
+
+#include "netspeed.h"
+
+#define NETSPEED_TYPE_PREFERENCES netspeed_preferences_get_type ()
+G_DECLARE_FINAL_TYPE (NetspeedPreferences, netspeed_preferences,
+ NETSPEED, PREFERENCES, GtkDialog)
+
+GtkWidget *netspeed_preferences_new (NetspeedApplet *netspeed);
+
+#endif
diff --git a/netspeed/src/netspeed.c b/netspeed/src/netspeed.c
index 2dc2f276..c9cdf936 100644
--- a/netspeed/src/netspeed.c
+++ b/netspeed/src/netspeed.c
@@ -32,6 +32,8 @@
#include <gio/gio.h>
#include "backend.h"
+#include "netspeed-preferences.h"
+
#include "netspeed.h"
#define GET_COLOR_CHOOSER(x) (GTK_COLOR_CHOOSER (gtk_builder_get_object (builder, (x))))
@@ -131,8 +133,7 @@ struct _NetspeedApplet
GtkWidget *netlink_box;
GtkWidget *wireless_box;
/* settings dialog */
- GtkWidget *settings;
- GtkWidget *network_device_combo;
+ GtkWidget *preferences;
guint index_old;
guint64 in_old [OLD_VALUES];
@@ -144,7 +145,7 @@ struct _NetspeedApplet
GtkWidget *connect_dialog;
gboolean show_tooltip;
GtkIconTheme *icon_theme;
- GSettings *gsettings;
+ GSettings *settings;
};
G_DEFINE_TYPE (NetspeedApplet, netspeed_applet, PANEL_TYPE_APPLET)
@@ -152,9 +153,17 @@ G_DEFINE_TYPE (NetspeedApplet, netspeed_applet, PANEL_TYPE_APPLET)
static void
update_tooltip (NetspeedApplet *netspeed);
-static void
-device_change_cb (GtkComboBox *combo,
- NetspeedApplet *netspeed);
+GSettings *
+netspeed_applet_get_settings (NetspeedApplet *netspeed)
+{
+ return netspeed->settings;
+}
+
+const gchar *
+netspeed_applet_get_current_device_name (NetspeedApplet *netspeed)
+{
+ return netspeed->devinfo->name;
+}
/* Adds a Pango markup "foreground" to a bytestring
*/
@@ -982,9 +991,9 @@ timeout_function (NetspeedApplet *netspeed)
/* Display a section of netspeed help
*/
-static void
-display_help (GtkWidget *dialog,
- const gchar *section)
+void
+netspeed_applet_display_help (GtkWidget *dialog,
+ const gchar *section)
{
GError *error = NULL;
gboolean ret;
@@ -1024,7 +1033,7 @@ static void
help_cb (GtkAction *action,
NetspeedApplet *netspeed)
{
- display_help (GTK_WIDGET (netspeed), NULL);
+ netspeed_applet_display_help (GTK_WIDGET (netspeed), NULL);
}
/* Just the about window... If it's already open, just fokus it
@@ -1059,117 +1068,15 @@ about_cb (GtkAction *action,
NULL);
}
-/* this basically just retrieves the new devicestring
- * and then calls applet_device_change () and change_icons ()
- */
static void
-device_change_cb (GtkComboBox *combo,
- NetspeedApplet *netspeed)
+netspeed_applet_destory_preferences (GtkWidget *widget,
+ gpointer user_data)
{
- GList *devices;
- int i, active;
+ NetspeedApplet *netspeed;
+ (void) widget;
- g_assert (combo);
- devices = g_object_get_data (G_OBJECT (combo), "devices");
- active = gtk_combo_box_get_active (combo);
- g_assert (active > -1);
-
- if (0 == active) {
- if (netspeed->auto_change_device)
- return;
- netspeed->auto_change_device = TRUE;
- } else {
- netspeed->auto_change_device = FALSE;
- for (i = 1; i < active; i++) {
- devices = g_list_next (devices);
- }
- if (g_str_equal (devices->data, netspeed->devinfo->name))
- return;
- free_device_info (netspeed->devinfo);
- get_device_info (devices->data, &netspeed->devinfo);
- }
-
- netspeed->device_has_changed = TRUE;
- update_applet (netspeed);
-}
-
-/* Handle preference dialog response event
- */
-static void
-pref_response_cb (GtkDialog *dialog,
- gint id,
- NetspeedApplet *netspeed)
-{
- if (id == GTK_RESPONSE_HELP) {
- display_help (GTK_WIDGET (dialog), "netspeed_applet-settings");
- return;
- }
- g_settings_delay (netspeed->gsettings);
- g_settings_set_string (netspeed->gsettings, "device", netspeed->devinfo->name);
- g_settings_set_boolean (netspeed->gsettings, "auto-change-device", netspeed->auto_change_device);
- g_settings_apply (netspeed->gsettings);
-
- gtk_widget_destroy (netspeed->settings);
- netspeed->settings = NULL;
-}
-
-/* Called when the showalladdresses checkbutton is toggled...
- */
-static void
-showalladdresses_change_cb (GtkToggleButton *button,
- NetspeedApplet *netspeed)
-{
- netspeed->show_all_addresses = gtk_toggle_button_get_active (button);
-}
-
-/* Called when the showsum checkbutton is toggled...
- */
-static void
-showsum_change_cb (GtkToggleButton *button,
- NetspeedApplet *netspeed)
-{
- netspeed->show_sum = gtk_toggle_button_get_active (button);
- applet_change_size_or_orient (MATE_PANEL_APPLET (netspeed), -1, netspeed);
- change_icons (netspeed);
-}
-
-/* Called when the showbits checkbutton is toggled...
- */
-static void
-showbits_change_cb (GtkToggleButton *button,
- NetspeedApplet *netspeed)
-{
- netspeed->show_bits = gtk_toggle_button_get_active (button);
-}
-
-/* Called when the showicon checkbutton is toggled...
- */
-static void
-showicon_change_cb (GtkToggleButton *button,
- NetspeedApplet *netspeed)
-{
- netspeed->show_icon = gtk_toggle_button_get_active (button);
- change_icons (netspeed);
-}
-
-/* Called when the showqualityicon checkbutton is toggled...
- */
-static void
-showqualityicon_change_cb (GtkToggleButton *button,
- NetspeedApplet *netspeed)
-{
- netspeed->show_quality_icon = gtk_toggle_button_get_active (button);
- change_quality_icon (netspeed);
-}
-
-/* Called when the changeicon checkbutton is toggled...
- */
-static void
-changeicon_change_cb (GtkToggleButton *button,
- NetspeedApplet *netspeed)
-{
- netspeed->change_icon = gtk_toggle_button_get_active (button);
- change_icons (netspeed);
+ netspeed = NETSPEED_APPLET (user_data);
+ netspeed->preferences = NULL;
}
/* Creates the settings dialog
@@ -1180,86 +1087,18 @@ static void
settings_cb (GtkAction *action,
NetspeedApplet *netspeed)
{
- GtkBuilder *builder;
- GList *ptr, *devices;
- int i, active = -1;
-
g_assert (netspeed);
- if (netspeed->settings)
+ if (netspeed->preferences)
{
- gtk_window_present (GTK_WINDOW (netspeed->settings));
+ gtk_window_present (GTK_WINDOW (netspeed->preferences));
return;
}
- builder = gtk_builder_new_from_resource (NETSPEED_RESOURCE_PATH "netspeed-preferences.ui");
-
- netspeed->settings = GET_WIDGET ("preferences_dialog");
- netspeed->network_device_combo = GET_WIDGET ("network_device_combo");
-
- gtk_window_set_screen (GTK_WINDOW (netspeed->settings),
- gtk_widget_get_screen (netspeed->settings));
-
- gtk_dialog_set_default_response (GTK_DIALOG (netspeed->settings), GTK_RESPONSE_CLOSE);
-
- g_settings_bind (netspeed->gsettings, "show-all-addresses",
- gtk_builder_get_object (builder, "show_all_addresses_checkbutton"),
- "active", G_SETTINGS_BIND_DEFAULT);
-
- g_settings_bind (netspeed->gsettings, "show-sum",
- gtk_builder_get_object (builder, "show_sum_checkbutton"),
- "active", G_SETTINGS_BIND_DEFAULT);
-
- g_settings_bind (netspeed->gsettings, "show-bits",
- gtk_builder_get_object (builder, "show_bits_checkbutton"),
- "active", G_SETTINGS_BIND_DEFAULT);
-
- g_settings_bind (netspeed->gsettings, "show-icon",
- gtk_builder_get_object (builder, "show_icon_checkbutton"),
- "active", G_SETTINGS_BIND_DEFAULT);
-
- g_settings_bind (netspeed->gsettings, "show-quality-icon",
- gtk_builder_get_object (builder, "show_quality_icon_checkbutton"),
- "active", G_SETTINGS_BIND_DEFAULT);
-
- g_settings_bind (netspeed->gsettings, "change-icon",
- gtk_builder_get_object (builder, "change_icon_checkbutton"),
- "active", G_SETTINGS_BIND_DEFAULT);
-
- /* Default means device with default route set */
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (netspeed->network_device_combo),
- _("Default"));
- ptr = devices = get_available_devices ();
- for (i = 0; ptr; ptr = g_list_next (ptr)) {
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (netspeed->network_device_combo),
- ptr->data);
- if (g_str_equal (ptr->data, netspeed->devinfo->name))
- active = (i + 1);
- ++i;
- }
- if (active < 0 || netspeed->auto_change_device) {
- active = 0;
- }
- gtk_combo_box_set_active (GTK_COMBO_BOX (netspeed->network_device_combo), active);
- g_object_set_data_full (G_OBJECT (netspeed->network_device_combo), "devices",
- devices, (GDestroyNotify)free_devices_list);
-
- /* signals */
- gtk_builder_add_callback_symbols (builder,
- "on_network_device_combo_changed", G_CALLBACK (device_change_cb),
- "on_show_all_addresses_checkbutton_toggled", G_CALLBACK (showalladdresses_change_cb),
- "on_show_sum_checkbutton_toggled", G_CALLBACK (showsum_change_cb),
- "on_show_bits_checkbutton_toggled", G_CALLBACK (showbits_change_cb),
- "on_change_icon_checkbutton_toggled", G_CALLBACK (changeicon_change_cb),
- "on_show_icon_checkbutton_toggled", G_CALLBACK (showicon_change_cb),
- "on_show_quality_icon_checkbutton_toggled", G_CALLBACK (showqualityicon_change_cb),
- "on_preferences_dialog_response", G_CALLBACK (pref_response_cb),
- NULL);
- gtk_builder_connect_signals (builder, netspeed);
-
- g_object_unref (builder);
-
- gtk_widget_show_all (netspeed->settings);
+ netspeed->preferences = netspeed_preferences_new (netspeed);
+ g_signal_connect (netspeed->preferences, "destroy",
+ G_CALLBACK (netspeed_applet_destory_preferences), netspeed);
+ gtk_widget_show_all (netspeed->preferences);
}
static gboolean
@@ -1283,7 +1122,7 @@ incolor_changed_cb (GtkColorChooser *button,
netspeed->in_color = color;
string = gdk_rgba_to_string (&color);
- g_settings_set_string (netspeed->gsettings, "in-color", string);
+ g_settings_set_string (netspeed->settings, "in-color", string);
g_free (string);
}
@@ -1298,7 +1137,7 @@ outcolor_changed_cb (GtkColorChooser *button,
netspeed->out_color = color;
string = gdk_rgba_to_string (&color);
- g_settings_set_string (netspeed->gsettings, "out-color", string);
+ g_settings_set_string (netspeed->settings, "out-color", string);
g_free (string);
}
@@ -1311,7 +1150,7 @@ info_response_cb (GtkDialog *dialog,
{
if (id == GTK_RESPONSE_HELP) {
- display_help (GTK_WIDGET (dialog), "netspeed_applet-details");
+ netspeed_applet_display_help (GTK_WIDGET (dialog), "netspeed_applet-details");
return;
}
@@ -1507,18 +1346,16 @@ netspeed_applet_finalize (GObject *object)
netspeed->timeout_id = 0;
}
- g_clear_object (&netspeed->gsettings);
+ g_clear_object (&netspeed->settings);
g_clear_pointer (&netspeed->details, gtk_widget_destroy);
- g_clear_pointer (&netspeed->settings, gtk_widget_destroy);
+ g_clear_pointer (&netspeed->preferences, gtk_widget_destroy);
g_free (netspeed->up_cmd);
g_free (netspeed->down_cmd);
/* Should never be NULL */
free_device_info (netspeed->devinfo);
-
- G_OBJECT_CLASS (netspeed_applet_parent_class)->finalize (object);
}
static void
@@ -1658,6 +1495,81 @@ netspeed_applet_init (NetspeedApplet *netspeed)
{
}
+static void
+changeicon_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ netspeed->change_icon = g_settings_get_boolean (settings, key);
+ change_icons (netspeed);
+}
+
+static void
+showalladdresses_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ netspeed->show_all_addresses = g_settings_get_boolean (settings, key);
+}
+
+static void
+showsum_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ netspeed->show_sum = g_settings_get_boolean (settings, key);
+ applet_change_size_or_orient (MATE_PANEL_APPLET (netspeed), -1, netspeed);
+ change_icons (netspeed);
+}
+
+static void
+showbits_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ netspeed->show_bits = g_settings_get_boolean (settings, key);
+}
+
+static void
+showicon_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ netspeed->show_icon = g_settings_get_boolean (settings, key);
+ change_icons (netspeed);
+}
+
+static void
+showqualityicon_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ netspeed->show_quality_icon = g_settings_get_boolean (settings, key);
+ change_quality_icon (netspeed);
+}
+
+static void
+auto_change_device_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ netspeed->auto_change_device = g_settings_get_boolean (settings, key);
+ netspeed->device_has_changed = TRUE;
+ update_applet (netspeed);
+}
+
+static void
+device_settings_changed (GSettings *settings,
+ const gchar *key,
+ NetspeedApplet *netspeed)
+{
+ char *davice;
+
+ davice = g_settings_get_string (settings, key);
+ set_applet_devinfo (netspeed, davice);
+ g_free (davice);
+}
+
/* The "main" function of the applet
*/
static gboolean
@@ -1694,44 +1606,44 @@ netspeed_applet_factory (MatePanelApplet *applet,
netspeed->out_graph[i] = -1;
}
- netspeed->gsettings = mate_panel_applet_settings_new (applet, "org.mate.panel.applet.netspeed");
+ netspeed->settings = mate_panel_applet_settings_new (applet, "org.mate.panel.applet.netspeed");
/* Get stored settings from gsettings
*/
- netspeed->show_all_addresses = g_settings_get_boolean (netspeed->gsettings, "show-all-addresses");
- netspeed->show_sum = g_settings_get_boolean (netspeed->gsettings, "show-sum");
- netspeed->show_bits = g_settings_get_boolean (netspeed->gsettings, "show-bits");
- netspeed->show_icon = g_settings_get_boolean (netspeed->gsettings, "show-icon");
- netspeed->show_quality_icon = g_settings_get_boolean (netspeed->gsettings, "show-quality-icon");
- netspeed->change_icon = g_settings_get_boolean (netspeed->gsettings, "change-icon");
- netspeed->auto_change_device = g_settings_get_boolean (netspeed->gsettings, "auto-change-device");
+ netspeed->show_all_addresses = g_settings_get_boolean (netspeed->settings, "show-all-addresses");
+ netspeed->show_sum = g_settings_get_boolean (netspeed->settings, "show-sum");
+ netspeed->show_bits = g_settings_get_boolean (netspeed->settings, "show-bits");
+ netspeed->show_icon = g_settings_get_boolean (netspeed->settings, "show-icon");
+ netspeed->show_quality_icon = g_settings_get_boolean (netspeed->settings, "show-quality-icon");
+ netspeed->change_icon = g_settings_get_boolean (netspeed->settings, "change-icon");
+ netspeed->auto_change_device = g_settings_get_boolean (netspeed->settings, "auto-change-device");
char *tmp = NULL;
- tmp = g_settings_get_string (netspeed->gsettings, "device");
+ tmp = g_settings_get_string (netspeed->settings, "device");
if (tmp && strcmp (tmp, "")) {
get_device_info (tmp, &netspeed->devinfo);
g_free (tmp);
}
- tmp = g_settings_get_string (netspeed->gsettings, "up-command");
+ tmp = g_settings_get_string (netspeed->settings, "up-command");
if (tmp && strcmp (tmp, "")) {
netspeed->up_cmd = g_strdup (tmp);
g_free (tmp);
}
- tmp = g_settings_get_string (netspeed->gsettings, "down-command");
+ tmp = g_settings_get_string (netspeed->settings, "down-command");
if (tmp && strcmp (tmp, "")) {
netspeed->down_cmd = g_strdup (tmp);
g_free (tmp);
}
- tmp = g_settings_get_string (netspeed->gsettings, "in-color");
+ tmp = g_settings_get_string (netspeed->settings, "in-color");
if (tmp) {
gdk_rgba_parse (&netspeed->in_color, tmp);
g_free (tmp);
}
- tmp = g_settings_get_string (netspeed->gsettings, "out-color");
+ tmp = g_settings_get_string (netspeed->settings, "out-color");
if (tmp) {
gdk_rgba_parse (&netspeed->out_color, tmp);
g_free (tmp);
@@ -1810,6 +1722,38 @@ netspeed_applet_factory (MatePanelApplet *applet,
G_CALLBACK (label_size_allocate_cb),
netspeed);
+ g_signal_connect (netspeed->settings, "changed::auto-change-device",
+ G_CALLBACK (auto_change_device_settings_changed),
+ netspeed);
+
+ g_signal_connect (netspeed->settings, "changed::device",
+ G_CALLBACK (device_settings_changed),
+ netspeed);
+
+ g_signal_connect (netspeed->settings, "changed::show-all-addresses",
+ G_CALLBACK (showalladdresses_settings_changed),
+ netspeed);
+
+ g_signal_connect (netspeed->settings, "changed::show-sum",
+ G_CALLBACK (showsum_settings_changed),
+ netspeed);
+
+ g_signal_connect (netspeed->settings, "changed::show-bits",
+ G_CALLBACK (showbits_settings_changed),
+ netspeed);
+
+ g_signal_connect (netspeed->settings, "changed::change-icon",
+ G_CALLBACK (changeicon_settings_changed),
+ netspeed);
+
+ g_signal_connect (netspeed->settings, "changed::show-icon",
+ G_CALLBACK (showicon_settings_changed),
+ netspeed);
+
+ g_signal_connect (netspeed->settings, "changed::show-quality-icon",
+ G_CALLBACK (showqualityicon_settings_changed),
+ netspeed);
+
action_group = gtk_action_group_new ("Netspeed Applet Actions");
gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
gtk_action_group_add_actions (action_group,
diff --git a/netspeed/src/netspeed.h b/netspeed/src/netspeed.h
index 66574c04..2e954e8e 100644
--- a/netspeed/src/netspeed.h
+++ b/netspeed/src/netspeed.h
@@ -21,8 +21,15 @@
#include <mate-panel-applet.h>
+#include "backend.h"
+#include "netspeed-preferences.h"
+
#define NETSPEED_TYPE_APPLET netspeed_applet_get_type ()
G_DECLARE_FINAL_TYPE (NetspeedApplet, netspeed_applet,
NETSPEED, APPLET, MatePanelApplet)
+GSettings * netspeed_applet_get_settings (NetspeedApplet *netspeed);
+const gchar * netspeed_applet_get_current_device_name (NetspeedApplet *netspeed);
+void netspeed_applet_display_help (GtkWidget *dialog, const gchar *section);
+
#endif