aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/new-mail-notify/new-mail-notify.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/new-mail-notify/new-mail-notify.c')
-rw-r--r--plugins/new-mail-notify/new-mail-notify.c125
1 files changed, 46 insertions, 79 deletions
diff --git a/plugins/new-mail-notify/new-mail-notify.c b/plugins/new-mail-notify/new-mail-notify.c
index 230a7fb8b1..872fa80c62 100644
--- a/plugins/new-mail-notify/new-mail-notify.c
+++ b/plugins/new-mail-notify/new-mail-notify.c
@@ -35,7 +35,6 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <camel/camel-folder.h>
-#define GCONF_KEY "/apps/evolution/mail/notify/gen_dbus_msg"
#define DBUS_PATH "/org/gnome/evolution/mail/newmail"
#define DBUS_INTERFACE "org.gnome.evolution.mail.dbus.Signal"
@@ -43,95 +42,37 @@ GtkWidget *org_gnome_new_mail_config (EPlugin *ep, EConfigHookItemFactoryData *h
void org_gnome_new_mail_notify (EPlugin *ep, EMEventTargetFolder *t);
void org_gnome_message_reading_notify (EPlugin *ep, EMEventTargetMessage *t);
-static void
-toggled_cb (GtkWidget *widget, EConfig *config)
-{
- EMConfigTargetPrefs *target = (EMConfigTargetPrefs *) config->target;
-
- /* Save the new setting to gconf */
- gconf_client_set_bool (target->gconf,
- GCONF_KEY,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)),
- NULL);
-}
-
-GtkWidget *
-org_gnome_new_mail_config (EPlugin *ep, EConfigHookItemFactoryData *hook_data)
-{
- GtkWidget *notify;
-
- EMConfigTargetPrefs *target = (EMConfigTargetPrefs *) hook_data->config->target;
-
- /* Create the checkbox we will display, complete with mnemonic that is unique in the dialog */
- notify = gtk_check_button_new_with_mnemonic (_("_Generates a D-BUS message when new mail arrives"));
-
- /* Set the toggle button to the current gconf setting */
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify),
- gconf_client_get_bool (target->gconf,
- GCONF_KEY, NULL));
-
- /* Listen for the item being toggled on and off */
- g_signal_connect (GTK_TOGGLE_BUTTON (notify),
- "toggled",
- G_CALLBACK (toggled_cb),
- hook_data->config);
-
- /* Pack the checkbox in the parent widget and show it */
- gtk_box_pack_start (GTK_BOX (hook_data->parent), notify, FALSE, FALSE, 0);
- gtk_widget_show (notify);
-
- return notify;
-}
+static DBusConnection *bus;
static void
send_dbus_message (const char *message_name, const char *data)
{
- GConfClient *client = gconf_client_get_default ();
+ DBusMessage *message;
- if (gconf_client_get_bool(client, GCONF_KEY, NULL)) {
- DBusConnection *bus;
- DBusError error;
- DBusMessage *message;
+ if (bus == NULL)
+ return;
- /* Get a connection to the session bus */
- dbus_error_init (&error);
- bus = dbus_bus_get (DBUS_BUS_SESSION,
- &error);
+ /* Create a new message on the DBUS_INTERFACE */
+ message = dbus_message_new_signal (DBUS_PATH,
+ DBUS_INTERFACE,
+ message_name);
- if (!bus) {
- printf ("Failed to connect to the D-BUS daemon: %s\n", error.message);
- dbus_error_free (&error);
- }
-
- /* Set up this connection to work in a GLib event loop */
- dbus_connection_setup_with_g_main (bus, NULL);
-
- /* Create a new message on the DBUS_INTERFACE */
- message = dbus_message_new_signal (DBUS_PATH,
- DBUS_INTERFACE,
- message_name);
-
- /* Appends the data as an argument to the message */
- dbus_message_append_args (message,
+ /* Appends the data as an argument to the message */
+ dbus_message_append_args (message,
#if DBUS_VERSION >= 310
- DBUS_TYPE_STRING, &data,
+ DBUS_TYPE_STRING, &data,
#else
- DBUS_TYPE_STRING, data,
-#endif
- DBUS_TYPE_INVALID);
-
- /* Sends the message */
- dbus_connection_send (bus,
- message,
- NULL);
+ DBUS_TYPE_STRING, data,
+#endif
+ DBUS_TYPE_INVALID);
- /* Frees the message */
- dbus_message_unref (message);
+ /* Sends the message */
+ dbus_connection_send (bus,
+ message,
+ NULL);
- /* printf("New message [%s] with arg [%s]!\n", message_name, data); */
- }
-
- g_object_unref (client);
+ /* Frees the message */
+ dbus_message_unref (message);
}
void
@@ -145,3 +86,29 @@ org_gnome_new_mail_notify (EPlugin *ep, EMEventTargetFolder *t)
{
send_dbus_message ("Newmail", t->uri);
}
+
+int
+e_plugin_lib_enable (EPluginLib *ep, int enable)
+{
+ if (enable) {
+ DBusError error;
+
+ dbus_error_init (&error);
+ bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ if (!bus) {
+ g_warning("Failed to connect to the D-BUS daemon: %s\n", error.message);
+
+ /* Could not determine address of the D-BUS session bus */
+ /* Plugin will be disabled */
+ dbus_error_free (&error);
+ return 1;
+ }
+
+ /* Set up this connection to work in a GLib event loop */
+ dbus_connection_setup_with_g_main (bus, NULL);
+ }
+ /* else unref the bus if set? */
+
+ return 0;
+}
+