Skip to content

Commit

Permalink
migrate to GSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
stefano-k committed Aug 3, 2012
1 parent 597a906 commit 2d7e344
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 173 deletions.
16 changes: 8 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dnl Process this file with autoconf to create configure.
dnl ################################################################
dnl # Initialize autoconf
dnl ################################################################
AC_INIT([mate-notification-daemon], [1.4.0], [http://www.mate-desktop.org])
AC_INIT([mate-notification-daemon], [1.5.0], [http://www.mate-desktop.org])
AC_PREREQ(2.63)

AC_CONFIG_HEADERS([config.h])
Expand Down Expand Up @@ -111,17 +111,18 @@ dnl ---------------------------------------------------------------------------
dnl Requirements for the daemon
dnl ---------------------------------------------------------------------------
REQ_GLIB_VERSION=2.18.0
REQ_GIO_VERSION=2.25.0
REQ_DBUS_VERSION=0.78
REQ_LIBCANBERRA_GTK_VERSION=0.4
PKG_CHECK_MODULES(GMODULE,gmodule-2.0,[GMODULE_ADD="gmodule-2.0"],[GMODULE_ADD=""])
pkg_modules="
gtk+-$GTK_API_VERSION >= $GTK_REQUIRED, \
glib-2.0 >= $REQ_GLIB_VERSION, \
gio-2.0 >= $REQ_GIO_VERSION, \
$GMODULE_ADD \
dbus-1 >= $REQ_DBUS_VERSION, \
dbus-glib-1 >= $REQ_DBUS_VERSION, \
libcanberra-gtk >= $REQ_LIBCANBERRA_GTK_VERSION, \
mateconf-2.0, \
libmatewnck \
x11 \
"
Expand All @@ -132,7 +133,7 @@ AC_SUBST(NOTIFICATION_DAEMON_LIBS)
dnl ---------------------------------------------------------------------------
dnl Requirements for the setup tool
dnl ---------------------------------------------------------------------------
PKG_CHECK_MODULES(NOTIFICATION_CAPPLET, glib-2.0 >= $REQ_GLIB_VERSION gtk+-$GTK_API_VERSION >= $GTK_REQUIRED mateconf-2.0 libmatenotify dbus-1 dbus-glib-1)
PKG_CHECK_MODULES(NOTIFICATION_CAPPLET, glib-2.0 >= $REQ_GLIB_VERSION gio-2.0 >= $REQ_GIO_VERSION gtk+-$GTK_API_VERSION >= $GTK_REQUIRED libmatenotify dbus-1 dbus-glib-1)
AC_SUBST(NOTIFICATION_CAPPLET_CFLAGS)
AC_SUBST(NOTIFICATION_CAPPLET_LIBS)

Expand All @@ -151,12 +152,11 @@ AM_CONDITIONAL(HAVE_GDK, test "x$have_gdk" = "xyes")
AC_SUBST(GDK_CFLAGS)
AC_SUBST(GDK_LIBS)

AM_MATECONF_SOURCE_2
AC_PATH_PROG(MATECONFTOOL, mateconftool-2, no)
dnl
dnl Enable gsettigns schema macros
dnl

if test "x$MATECONFTOOL" = "xno"; then
AC_MSG_ERROR([mateconftool-2 executable not found in your path - should be installed with Gconf])
fi
GLIB_GSETTINGS

dnl
dnl Check the D-BUS version.
Expand Down
19 changes: 3 additions & 16 deletions data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,11 @@ iconscalable_DATA = icons/scalable/mate-notification-properties.svg
servicedir = $(DBUS_SERVICES_DIR)
service_DATA = org.freedesktop.mate.Notifications.service

schemasdir = $(MATECONF_SCHEMA_FILE_DIR)
schemas_in_files = mate-notification-daemon.schemas.in
schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)

@INTLTOOL_SCHEMAS_RULE@

if MATECONF_SCHEMAS_INSTALL
install-data-local:
MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-install-rule $(schemas_DATA)
else
install-data-local:
endif
gsettings_SCHEMAS = org.mate.NotificationDaemon.gschema.xml
@GSETTINGS_RULES@

EXTRA_DIST = \
$(schemas_in_files) \
$(gsettings_SCHEMAS) \
$(service_DATA) \
$(icon16_DATA) \
$(icon22_DATA) \
Expand All @@ -39,9 +29,6 @@ EXTRA_DIST = \
$(icon48_DATA) \
$(iconscalable_DATA)

CLEANFILES = $(schemas_DATA)


gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor

install-data-hook: update-icon-cache
Expand Down
53 changes: 0 additions & 53 deletions data/mate-notification-daemon.schemas.in

This file was deleted.

24 changes: 24 additions & 0 deletions data/org.mate.NotificationDaemon.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<schemalist>
<schema id="org.mate.NotificationDaemon" path="/org/mate/notification-daemon/">
<key name="popup-location" type="s">
<default>'bottom_right'</default>
<summary>Popup location</summary>
<description>Default popup location on the workspace for stack notifications. Allowed values: "top_left","top_right","bottom_left" and "bottom_right"</description>
</key>
<key name="theme" type="s">
<default>'default'</default>
<summary>Current theme</summary>
<description>The theme used when displaying notifications.</description>
</key>
<key name="sound-enabled" type="b">
<default>true</default>
<summary>Sound Enabled</summary>
<description>Turns on and off sound support for notifications.</description>
</key>
<key name="default-sound" type="s">
<default>''</default>
<summary>Default Sound</summary>
<description>The default sound file used unless a notification supplies the 'sound-file' or 'suppress-sound' hint. Leave empty for no default sound.</description>
</key>
</schema>
</schemalist>
75 changes: 16 additions & 59 deletions src/capplet/mate-notification-properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,27 @@
#include <glib/gi18n.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <mateconf/mateconf-client.h>
#include <gio/gio.h>
#include <string.h>
#include <libmatenotify/notify.h>

#include "stack.h"

#define MATECONF_KEY_DAEMON "/apps/mate-notification-daemon"
#define MATECONF_KEY_THEME MATECONF_KEY_DAEMON "/theme"
#define MATECONF_KEY_POPUP_LOCATION MATECONF_KEY_DAEMON "/popup_location"

#define N_LISTENERS 2
#define GSETTINGS_SCHEMA "org.mate.NotificationDaemon"
#define GSETTINGS_KEY_THEME "theme"
#define GSETTINGS_KEY_POPUP_LOCATION "popup-location"

#define NOTIFICATION_UI_FILE "mate-notification-properties.ui"

typedef struct {
MateConfClient* client;
GSettings* gsettings;

GtkWidget* dialog;
GtkWidget* position_combo;
GtkWidget* theme_combo;
GtkWidget* preview_button;

NotifyNotification* preview;

guint listeners[N_LISTENERS];
int n_listeners;
int expected_listeners;
} NotificationAppletDialog;

enum {
Expand All @@ -66,19 +60,14 @@ enum {
N_COLUMNS_THEME
};

static void notification_properties_location_notify(MateConfClient* client, guint cnx_id, MateConfEntry* entry, NotificationAppletDialog* dialog)
static void notification_properties_location_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog)
{
GtkTreeModel* model;
GtkTreeIter iter;
const char* location;
gboolean valid;

if (!entry->value || entry->value->type != MATECONF_VALUE_STRING)
{
return;
}

location = mateconf_value_get_string(entry->value);
location = g_settings_get_string(dialog->gsettings, key);

model = gtk_combo_box_get_model(GTK_COMBO_BOX(dialog->position_combo));
valid = gtk_tree_model_get_iter_first(model, &iter);
Expand Down Expand Up @@ -114,7 +103,7 @@ static void notification_properties_location_changed(GtkComboBox* widget, Notifi

gtk_tree_model_get(model, &iter, NOTIFY_POSITION_NAME, &location, -1);

mateconf_client_set_string(dialog->client, MATECONF_KEY_POPUP_LOCATION, location, NULL);
g_settings_set_string (dialog->gsettings, GSETTINGS_KEY_POPUP_LOCATION, location);
g_free(location);
}

Expand All @@ -128,7 +117,7 @@ static void notification_properties_dialog_setup_positions(NotificationAppletDia
model = gtk_combo_box_get_model(GTK_COMBO_BOX(dialog->position_combo));
g_signal_connect(dialog->position_combo, "changed", G_CALLBACK(notification_properties_location_changed), dialog);

location = mateconf_client_get_string(dialog->client, MATECONF_KEY_POPUP_LOCATION, NULL);
location = g_settings_get_string(dialog->gsettings, GSETTINGS_KEY_POPUP_LOCATION);

for (valid = gtk_tree_model_get_iter_first(model, &iter); valid; valid = gtk_tree_model_iter_next(model, &iter))
{
Expand All @@ -146,19 +135,13 @@ static void notification_properties_dialog_setup_positions(NotificationAppletDia
g_free(key);
}

dialog->listeners[dialog->n_listeners] = mateconf_client_notify_add(dialog->client, MATECONF_KEY_POPUP_LOCATION, (MateConfClientNotifyFunc) notification_properties_location_notify, dialog, NULL, NULL);
dialog->n_listeners++;
g_signal_connect (dialog->gsettings, "changed::" GSETTINGS_KEY_POPUP_LOCATION, G_CALLBACK (notification_properties_location_notify), dialog);
g_free(location);
}

static void notification_properties_theme_notify(MateConfClient* client, guint cnx_id, MateConfEntry* entry, NotificationAppletDialog* dialog)
static void notification_properties_theme_notify(GSettings *settings, gchar *key, NotificationAppletDialog* dialog)
{
if (!entry->value || entry->value->type != MATECONF_VALUE_STRING)
{
return;
}

const char* theme = mateconf_value_get_string(entry->value);
const char* theme = g_settings_get_string(dialog->gsettings, key);

GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(dialog->theme_combo));

Expand Down Expand Up @@ -195,7 +178,7 @@ static void notification_properties_theme_changed(GtkComboBox* widget, Notificat
}

gtk_tree_model_get(model, &iter, NOTIFY_THEME_NAME, &theme, -1);
mateconf_client_set_string(dialog->client, MATECONF_KEY_THEME, theme, NULL);
g_settings_set_string(dialog->gsettings, GSETTINGS_KEY_THEME, theme);
g_free(theme);
}

Expand Down Expand Up @@ -267,8 +250,7 @@ static void notification_properties_dialog_setup_themes(NotificationAppletDialog
g_warning("Error opening themes dir");
}


theme = mateconf_client_get_string(dialog->client, MATECONF_KEY_THEME, NULL);
theme = g_settings_get_string(dialog->gsettings, GSETTINGS_KEY_THEME);

for (valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); valid; valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter))
{
Expand All @@ -286,8 +268,7 @@ static void notification_properties_dialog_setup_themes(NotificationAppletDialog
g_free(key);
}

dialog->listeners[dialog->n_listeners] = mateconf_client_notify_add(dialog->client, MATECONF_KEY_THEME, (MateConfClientNotifyFunc) notification_properties_theme_notify, dialog, NULL, NULL);
dialog->n_listeners++;
g_signal_connect (dialog->gsettings, "changed::" GSETTINGS_KEY_THEME, G_CALLBACK (notification_properties_theme_notify), dialog);
g_free(theme);
}

Expand Down Expand Up @@ -408,16 +389,11 @@ static gboolean notification_properties_dialog_init(NotificationAppletDialog* di
g_signal_connect(dialog->dialog, "response", G_CALLBACK(notification_properties_dialog_response), dialog);
g_signal_connect(dialog->dialog, "destroy", G_CALLBACK(notification_properties_dialog_destroyed), dialog);

dialog->client = mateconf_client_get_default();
mateconf_client_add_dir(dialog->client, MATECONF_KEY_DAEMON, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL);

dialog->expected_listeners = N_LISTENERS;
dialog->n_listeners = 0;
dialog->gsettings = g_settings_new (GSETTINGS_SCHEMA);

notification_properties_dialog_setup_themes(dialog);
notification_properties_dialog_setup_positions(dialog);

g_assert(dialog->n_listeners == dialog->expected_listeners);
gtk_widget_show(dialog->dialog);

dialog->preview = NULL;
Expand All @@ -433,25 +409,6 @@ static void notification_properties_dialog_finalize(NotificationAppletDialog* di
dialog->dialog = NULL;
}

if (dialog->client != NULL)
{
int i;

for (i = 0; i < dialog->n_listeners; i++)
{
if (dialog->listeners[i])
{
mateconf_client_notify_remove(dialog->client, dialog->listeners[i]);
dialog->listeners[i] = 0;
}
}

dialog->n_listeners = 0;
mateconf_client_remove_dir(dialog->client, MATECONF_KEY_DAEMON, NULL);
g_object_unref(dialog->client);
dialog->client = NULL;
}

if (dialog->preview)
{
notify_notification_close(dialog->preview, NULL);
Expand Down
Loading

0 comments on commit 2d7e344

Please sign in to comment.