aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohnny Jacob <jjohnny@src.gnome.org>2007-12-15 19:59:39 +0800
committerJohnny Jacob <jjohnny@src.gnome.org>2007-12-15 19:59:39 +0800
commit6cb13b10b6c87bd6fd89454049dd9b58c1f9808c (patch)
tree7c96fa9f180a0295eea711ecef359c635143033c
parent4f7d3decd1bb7f47e9d23c0514e82d002aaac752 (diff)
downloadgsoc2013-evolution-6cb13b10b6c87bd6fd89454049dd9b58c1f9808c.tar
gsoc2013-evolution-6cb13b10b6c87bd6fd89454049dd9b58c1f9808c.tar.gz
gsoc2013-evolution-6cb13b10b6c87bd6fd89454049dd9b58c1f9808c.tar.bz2
gsoc2013-evolution-6cb13b10b6c87bd6fd89454049dd9b58c1f9808c.tar.lz
gsoc2013-evolution-6cb13b10b6c87bd6fd89454049dd9b58c1f9808c.tar.xz
gsoc2013-evolution-6cb13b10b6c87bd6fd89454049dd9b58c1f9808c.tar.zst
gsoc2013-evolution-6cb13b10b6c87bd6fd89454049dd9b58c1f9808c.zip
Part of fix for #492702 from Milan Crha : New mail notify and preferences ui movement.
svn path=/trunk/; revision=34702
-rw-r--r--mail/ChangeLog16
-rw-r--r--mail/em-mailer-prefs.c62
-rw-r--r--mail/em-mailer-prefs.h6
-rw-r--r--mail/em-migrate.c89
-rw-r--r--mail/evolution-mail.schemas.in30
-rw-r--r--mail/mail-config.glade235
-rw-r--r--mail/mail-config.h6
-rw-r--r--mail/mail-folder-cache.c67
-rw-r--r--mail/mail-folder-cache.h3
-rw-r--r--plugins/mail-notification/ChangeLog10
-rw-r--r--plugins/mail-notification/apps-evolution-mail-notification.schemas.in85
-rw-r--r--plugins/mail-notification/mail-notification.c791
-rw-r--r--plugins/mail-notification/org-gnome-mail-notification.eplug.xml13
13 files changed, 899 insertions, 514 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index a5a9961e03..10a923c9e1 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,19 @@
+2007-12-15 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #492702
+
+ * mail-config.h:
+ * mail-config.glade:
+ * evolution-mail.schemas.in:
+ * mail-folder-cache.h:
+ * mail-folder-cache.c:
+ * em-mailer-prefs.h:
+ * em-mailer-prefs.c: Moved bits of sound notification
+ on new messages to mail-notification plugin.
+ * em-migrate.c: (is_in_plugs_list),
+ (em_update_message_notify_settings_2_21), (em_migrate):
+ Migration code to move old options to new plugin options.
+
2007-12-14 Sankar P <psankar@novell.com>
* em-folder-tree-model.c: (emft_model_unread_count_changed),
diff --git a/mail/em-mailer-prefs.c b/mail/em-mailer-prefs.c
index 2a4e81117d..b8c3d7fb59 100644
--- a/mail/em-mailer-prefs.c
+++ b/mail/em-mailer-prefs.c
@@ -702,36 +702,6 @@ http_images_changed (GtkWidget *widget, EMMailerPrefs *prefs)
}
-static void
-notify_type_changed (GtkWidget *widget, EMMailerPrefs *prefs)
-{
- int type;
-
- if (gtk_toggle_button_get_active (prefs->notify_not))
- type = MAIL_CONFIG_NOTIFY_NOT;
- else if (gtk_toggle_button_get_active (prefs->notify_beep))
- type = MAIL_CONFIG_NOTIFY_BEEP;
- else
- type = MAIL_CONFIG_NOTIFY_PLAY_SOUND;
-
- if (type == MAIL_CONFIG_NOTIFY_PLAY_SOUND)
- gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_sound_file, TRUE);
- else
- gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_sound_file, FALSE);
-
- gconf_client_set_int (prefs->gconf, "/apps/evolution/mail/notify/type", type, NULL);
-}
-
-static void
-notify_sound_changed (GtkWidget *widget, EMMailerPrefs *prefs)
-{
- const char *filename;
-
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (prefs->notify_sound_file));
- /* When we startup the file name will be NULL*/
- gconf_client_set_string (prefs->gconf, "/apps/evolution/mail/notify/sound", filename ? filename : "", NULL);
-}
-
static GtkWidget *
emmp_widget_glade(EConfig *ec, EConfigItem *item, struct _GtkWidget *parent, struct _GtkWidget *old, void *data)
{
@@ -973,38 +943,6 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs)
"/apps/evolution/mail/prompts/expunge",
G_CALLBACK (toggle_button_toggled));
- /* New Mail Notification */
- locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/notify/type", NULL);
-
- val = gconf_client_get_int (prefs->gconf, "/apps/evolution/mail/notify/type", NULL);
- prefs->notify_not = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radNotifyNot"));
- gtk_toggle_button_set_active (prefs->notify_not, val == MAIL_CONFIG_NOTIFY_NOT);
- g_signal_connect (prefs->notify_not, "toggled", G_CALLBACK (notify_type_changed), prefs);
- if (locked)
- gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_not, FALSE);
-
- prefs->notify_beep = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radNotifyBeep"));
- prefs->notify_sound_file = GTK_FILE_CHOOSER_BUTTON (glade_xml_get_widget (gui, "fileNotifyPlaySoundButton"));
- gtk_toggle_button_set_active (prefs->notify_beep, val == MAIL_CONFIG_NOTIFY_BEEP);
- g_signal_connect (prefs->notify_beep, "toggled", G_CALLBACK (notify_type_changed), prefs);
- if (locked)
- gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_beep, FALSE);
-
- prefs->notify_play_sound = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "radNotifyPlaySound"));
- gtk_toggle_button_set_active (prefs->notify_play_sound, val == MAIL_CONFIG_NOTIFY_PLAY_SOUND);
- g_signal_connect (prefs->notify_play_sound, "toggled", G_CALLBACK (notify_type_changed), prefs);
- if (locked)
- gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_play_sound, FALSE);
-
- buf = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/notify/sound", NULL);
- if (buf && *buf)
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (prefs->notify_sound_file), buf);
- g_signal_connect (GTK_FILE_CHOOSER_BUTTON (prefs->notify_sound_file), "selection-changed",
- G_CALLBACK (notify_sound_changed), prefs);
- if (val != MAIL_CONFIG_NOTIFY_PLAY_SOUND)
- gtk_widget_set_sensitive ((GtkWidget *) prefs->notify_sound_file, FALSE);
- g_free (buf);
-
/* Mail Fonts */
font = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/display/fonts/monospace", NULL);
prefs->font_fixed = GTK_FONT_BUTTON (glade_xml_get_widget (gui, "FontFixed"));
diff --git a/mail/em-mailer-prefs.h b/mail/em-mailer-prefs.h
index 647da6e571..846ce151bd 100644
--- a/mail/em-mailer-prefs.h
+++ b/mail/em-mailer-prefs.h
@@ -87,12 +87,6 @@ struct _EMMailerPrefs {
struct _GtkOptionMenu *empty_trash_days;
struct _GtkToggleButton *confirm_expunge;
- /* New Mail Notification */
- struct _GtkToggleButton *notify_not;
- struct _GtkToggleButton *notify_beep;
- struct _GtkToggleButton *notify_play_sound;
- struct _GtkFileChooserButton *notify_sound_file;
-
/* HTML Mail tab */
struct _GtkFontButton *font_variable;
struct _GtkFontButton *font_fixed;
diff --git a/mail/em-migrate.c b/mail/em-migrate.c
index 1c64c5e659..f038a8f640 100644
--- a/mail/em-migrate.c
+++ b/mail/em-migrate.c
@@ -66,6 +66,7 @@
#include "e-util/e-signature-list.h"
#include "e-util/e-error.h"
#include "e-util/e-util-private.h"
+#include "e-util/e-plugin.h"
#include "mail-config.h"
#include "em-utils.h"
@@ -2728,6 +2729,90 @@ emm_setup_initial(const char *evolution_dir)
return 0;
}
+static gboolean
+is_in_plugs_list (GSList *list, const gchar *value)
+{
+ GSList *l;
+
+ for (l = list; l; l = l->next) {
+ if (l->data && !strcmp (l->data, value))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*
+ * em_update_message_notify_settings_2_21
+ * DBus plugin and sound email notification was merged to mail-notification plugin,
+ * so move these options to new locations.
+ */
+static void
+em_update_message_notify_settings_2_21 (void)
+{
+ GConfClient *client;
+ GConfValue *is_key;
+ gboolean dbus, status;
+ GSList *list;
+ gchar *str;
+ gint val;
+
+ client = gconf_client_get_default ();
+
+ is_key = gconf_client_get (client, "/apps/evolution/eplugin/mail-notification/dbus-enabled", NULL);
+ if (is_key) {
+ /* already migrated, so do not migrate again */
+ gconf_value_free (is_key);
+ g_object_unref (client);
+
+ return;
+ }
+
+ gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-blink-icon",
+ gconf_client_get_bool (client, "/apps/evolution/mail/notification/blink-status-icon", NULL), NULL);
+ gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-notification",
+ gconf_client_get_bool (client, "/apps/evolution/mail/notification/notification", NULL), NULL);
+
+ list = gconf_client_get_list (client, "/apps/evolution/eplugin/disabled", GCONF_VALUE_STRING, NULL);
+ dbus = !is_in_plugs_list (list, "org.gnome.evolution.new_mail_notify");
+ status = !is_in_plugs_list (list, "org.gnome.evolution.mail_notification");
+
+ gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/dbus-enabled", dbus, NULL);
+ gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-enabled", status, NULL);
+
+ if (!status) {
+ /* enable this plugin, because it holds all those other things */
+ GSList *plugins, *l;
+
+ plugins = e_plugin_list_plugins ();
+
+ for (l = plugins; l; l = l->next) {
+ EPlugin *p = l->data;
+
+ if (p && p->id && !strcmp (p->id, "org.gnome.evolution.mail_notification")) {
+ e_plugin_enable (p, 1);
+ break;
+ }
+ }
+
+ g_slist_foreach (plugins, (GFunc)g_object_unref, NULL);
+ g_slist_free (plugins);
+ }
+
+ g_slist_foreach (list, (GFunc) g_free, NULL);
+ g_slist_free (list);
+
+ val = gconf_client_get_int (client, "/apps/evolution/mail/notify/type", NULL);
+ gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/sound-enabled", val == 1 || val == 2, NULL);
+ gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/sound-beep", val == 0 || val == 1, NULL);
+
+ str = gconf_client_get_string (client, "/apps/evolution/mail/notify/sound", NULL);
+ gconf_client_set_string (client, "/apps/evolution/eplugin/mail-notification/sound-file", str ? str : "", NULL);
+ g_free (str);
+
+ g_object_unref (client);
+}
+
int
em_migrate (const char *evolution_dir, int major, int minor, int revision, CamelException *ex)
{
@@ -2813,6 +2898,10 @@ em_migrate (const char *evolution_dir, int major, int minor, int revision, Camel
if (major < 2 || (major == 2 && minor < 12)) {
em_update_accounts_2_11 ();
}
+
+ if (major < 2 || (major == 2 && minor < 22))
+ em_update_message_notify_settings_2_21 ();
+
#endif /* !G_OS_WIN32 */
return 0;
}
diff --git a/mail/evolution-mail.schemas.in b/mail/evolution-mail.schemas.in
index 8affc57671..ffba439eb9 100644
--- a/mail/evolution-mail.schemas.in
+++ b/mail/evolution-mail.schemas.in
@@ -757,36 +757,6 @@
</locale>
</schema>
- <!-- New Mail Notification settings -->
-
- <schema>
- <key>/schemas/apps/evolution/mail/notify/type</key>
- <applyto>/apps/evolution/mail/notify/type</applyto>
- <owner>evolution-mail</owner>
- <type>int</type>
- <default>0</default>
- <locale name="C">
- <short>New Mail Notify type</short>
- <long>
- Specifies the type of New Mail Notification the user wishes to use.
- </long>
- </locale>
- </schema>
-
- <schema>
- <key>/schemas/apps/evolution/mail/notify/sound</key>
- <applyto>/apps/evolution/mail/notify/sound</applyto>
- <owner>evolution-mail</owner>
- <type>string</type>
- <default></default>
- <locale name="C">
- <short>New Mail Notify sound file</short>
- <long>
- Sound file to play when new mail arrives.
- </long>
- </locale>
- </schema>
-
<!-- Prompt settings -->
<schema>
diff --git a/mail/mail-config.glade b/mail/mail-config.glade
index 4c6cc805c9..316934df1a 100644
--- a/mail/mail-config.glade
+++ b/mail/mail-config.glade
@@ -550,8 +550,8 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
<accessibility>
- <atkrelation target="identity_address_label" type="labelled-by"/>
<atkrelation target="label464" type="labelled-by"/>
+ <atkrelation target="identity_address_label" type="labelled-by"/>
</accessibility>
</widget>
<packing>
@@ -633,8 +633,8 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
<accessibility>
- <atkrelation target="label464" type="labelled-by"/>
<atkrelation target="identity_full_name_label" type="labelled-by"/>
+ <atkrelation target="label464" type="labelled-by"/>
</accessibility>
</widget>
<packing>
@@ -836,8 +836,8 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
<accessibility>
- <atkrelation target="identity_organization_label" type="labelled-by"/>
<atkrelation target="label466" type="labelled-by"/>
+ <atkrelation target="identity_organization_label" type="labelled-by"/>
</accessibility>
</widget>
<packing>
@@ -890,8 +890,8 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
<accessibility>
- <atkrelation target="label466" type="labelled-by"/>
<atkrelation target="reply_to_label" type="labelled-by"/>
+ <atkrelation target="label466" type="labelled-by"/>
</accessibility>
</widget>
<packing>
@@ -1612,7 +1612,6 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;span weight=&quot;bold&quot;&gt;_Authentication Type&lt;/span&gt;</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">source_auth_dropdown</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
@@ -1621,6 +1620,7 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
+ <property name="mnemonic_widget">source_auth_dropdown</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
@@ -2803,7 +2803,7 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<widget class="Custom" id="sent_button">
<property name="visible">True</property>
<property name="creation_function">em_account_editor_folder_selector_button_new</property>
- <property name="string1" translatable="yes">Select Sent Folder</property>
+ <property name="string1">Select Sent Folder</property>
<property name="int1">0</property>
<property name="int2">0</property>
<property name="last_modification_time">Tue, 14 Dec 2004 17:07:09 GMT</property>
@@ -2822,7 +2822,7 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<widget class="Custom" id="drafts_button">
<property name="visible">True</property>
<property name="creation_function">em_account_editor_folder_selector_button_new</property>
- <property name="string1" translatable="yes">Select Drafts Folder</property>
+ <property name="string1">Select Drafts Folder</property>
<property name="int1">0</property>
<property name="int2">0</property>
<property name="last_modification_time">Tue, 14 Dec 2004 17:07:02 GMT</property>
@@ -5466,227 +5466,6 @@ For example: &quot;Work&quot; or &quot;Personal&quot;</property>
<property name="fill">False</property>
</packing>
</child>
-
- <child>
- <widget class="GtkVBox" id="MailNotifyFrame">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">6</property>
-
- <child>
- <widget class="GtkLabel" id="label498">
- <property name="visible">True</property>
- <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot;&gt;New Message Notification&lt;/span&gt;</property>
- <property name="use_underline">False</property>
- <property name="use_markup">True</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkHBox" id="hbox185">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">12</property>
-
- <child>
- <widget class="GtkLabel" id="label543">
- <property name="visible">True</property>
- <property name="label" translatable="yes"></property>
- <property name="use_underline">False</property>
- <property name="use_markup">False</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0.5</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkTable" id="table25">
- <property name="visible">True</property>
- <property name="n_rows">1</property>
- <property name="n_columns">1</property>
- <property name="homogeneous">False</property>
- <property name="row_spacing">2</property>
- <property name="column_spacing">6</property>
-
- <child>
- <widget class="GtkVBox" id="vboxNewMailNotify">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">6</property>
-
- <child>
- <widget class="GtkRadioButton" id="radNotifyNot">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">_Do not notify me when new messages arrive</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">True</property>
- <property name="inconsistent">False</property>
- <property name="draw_indicator">True</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkRadioButton" id="radNotifyBeep">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">_Beep when new messages arrive</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- <property name="draw_indicator">True</property>
- <property name="group">radNotifyNot</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkRadioButton" id="radNotifyPlaySound">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">Play sound file when new messages arri_ve</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- <property name="draw_indicator">True</property>
- <property name="group">radNotifyNot</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkHBox" id="hbox154">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">6</property>
-
- <child>
- <widget class="GtkLabel" id="lblNotifyFilename">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Specify _filename:</property>
- <property name="use_underline">True</property>
- <property name="use_markup">False</property>
- <property name="justify">GTK_JUSTIFY_CENTER</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0.5</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
- <property name="mnemonic_widget">fileNotifyPlaySoundButton</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
- <property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
- <property name="angle">0</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkFileChooserButton" id="fileNotifyPlaySoundButton">
- <property name="visible">True</property>
- <property name="title" translatable="yes">Select sound file</property>
- <property name="action">GTK_FILE_CHOOSER_ACTION_OPEN</property>
- <property name="local_only">False</property>
- <property name="show_hidden">False</property>
- <property name="do_overwrite_confirmation">False</property>
- <property name="width_chars">-1</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="left_attach">0</property>
- <property name="right_attach">1</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
</widget>
<packing>
<property name="tab_expand">False</property>
diff --git a/mail/mail-config.h b/mail/mail-config.h
index 7a2783ce65..698cb74399 100644
--- a/mail/mail-config.h
+++ b/mail/mail-config.h
@@ -81,12 +81,6 @@ typedef enum {
} MailConfigDisplayStyle;
typedef enum {
- MAIL_CONFIG_NOTIFY_NOT,
- MAIL_CONFIG_NOTIFY_BEEP,
- MAIL_CONFIG_NOTIFY_PLAY_SOUND,
-} MailConfigNewMailNotify;
-
-typedef enum {
MAIL_CONFIG_XMAILER_NONE = 0,
MAIL_CONFIG_XMAILER_EVO = 1,
MAIL_CONFIG_XMAILER_OTHER = 2,
diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c
index 5433616a1b..8d9b7a2fc9 100644
--- a/mail/mail-folder-cache.c
+++ b/mail/mail-folder-cache.c
@@ -123,15 +123,6 @@ static void folder_finalised(CamelObject *o, gpointer event_data, gpointer user_
static guint ping_id = 0;
static gboolean ping_cb (gpointer user_data);
-static guint notify_id = 0;
-static int notify_type = -1;
-
-static time_t last_notify = 0;
-static time_t last_newmail = 0;
-static guint notify_idle_id = 0;
-static gboolean notify_idle_cb (gpointer user_data);
-
-
/* Store to storeinfo table, active stores */
static GHashTable *stores = NULL;
@@ -155,43 +146,6 @@ free_update(struct _folder_update *up)
g_free(up);
}
-static gboolean
-notify_idle_cb (gpointer user_data)
-{
- GConfClient *gconf;
- char *filename;
-
- gconf = mail_config_get_gconf_client ();
-
- switch (notify_type) {
- case MAIL_CONFIG_NOTIFY_PLAY_SOUND:
- filename = gconf_client_get_string (gconf, "/apps/evolution/mail/notify/sound", NULL);
- if (filename != NULL) {
- gnome_sound_play (filename);
- g_free (filename);
- }
- break;
- case MAIL_CONFIG_NOTIFY_BEEP:
- gdk_beep ();
- break;
- default:
- break;
- }
-
- time (&last_notify);
-
- notify_idle_id = 0;
-
- return FALSE;
-}
-
-static void
-notify_type_changed (GConfClient *client, guint cnxn_id,
- GConfEntry *entry, gpointer user_data)
-{
- notify_type = gconf_client_get_int (client, "/apps/evolution/mail/notify/type", NULL);
-}
-
static void
real_flush_updates(void *o, void *event_data, void *data)
{
@@ -230,21 +184,6 @@ real_flush_updates(void *o, void *event_data, void *data)
/* update unread counts */
em_folder_tree_model_set_unread_count (model, up->store, up->full_name, up->unread);
- /* new mail notification */
- if (notify_type == -1) {
- /* need to track the user's new-mail-notification settings... */
- GConfClient *gconf;
-
- gconf = mail_config_get_gconf_client ();
- gconf_client_add_dir (gconf, "/apps/evolution/mail/notify",
- GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
- notify_id = gconf_client_notify_add (gconf, "/apps/evolution/mail/notify",
- notify_type_changed, NULL, NULL, NULL);
- notify_type = gconf_client_get_int (gconf, "/apps/evolution/mail/notify/type", NULL);
- }
-
- if (notify_type != 0 && up->new && notify_idle_id == 0 && (last_newmail - last_notify >= NOTIFY_THROTTLE))
- notify_idle_id = g_idle_add_full (G_PRIORITY_LOW, notify_idle_cb, NULL, NULL);
if (up->uri) {
EMEvent *e = em_event_peek();
@@ -474,16 +413,12 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data)
flags = camel_message_info_flags (info);
if (((flags & CAMEL_MESSAGE_SEEN) == 0) &&
((flags & CAMEL_MESSAGE_JUNK) == 0) &&
- ((flags & CAMEL_MESSAGE_DELETED) == 0) &&
- (camel_message_info_date_received (info) > last_newmail))
+ ((flags & CAMEL_MESSAGE_DELETED) == 0))
new++;
}
}
}
- if (new > 0)
- time (&last_newmail);
-
LOCK(info_lock);
if (stores != NULL
&& (si = g_hash_table_lookup(stores, store)) != NULL
diff --git a/mail/mail-folder-cache.h b/mail/mail-folder-cache.h
index f4c1e1b4db..656d97135b 100644
--- a/mail/mail-folder-cache.h
+++ b/mail/mail-folder-cache.h
@@ -25,9 +25,6 @@
#ifndef _MAIL_FOLDER_CACHE_H
#define _MAIL_FOLDER_CACHE_H
-/* min no. seconds between newmail notifications */
-#define NOTIFY_THROTTLE 30
-
#include <camel/camel-store.h>
/* Add a store whose folders should appear in the shell
diff --git a/plugins/mail-notification/ChangeLog b/plugins/mail-notification/ChangeLog
index a3f7fed466..fad75f1101 100644
--- a/plugins/mail-notification/ChangeLog
+++ b/plugins/mail-notification/ChangeLog
@@ -1,3 +1,13 @@
+2007-12-07 Milan Crha <mcrha@redhat.com>
+
+ ** Fix for bug #492702
+
+ * apps-evolution-mail-notification.schemas.in:
+ * mail-notification.c:
+ * org-gnome-mail-notification.eplug.xml:
+ New-mail-notification plugin and sound notification has been merged
+ to this plugin, with couple of options in plugins Configuration tab.
+
2007-10-11 Matthew Barnes <mbarnes@redhat.com>
* mail-notification.c:
diff --git a/plugins/mail-notification/apps-evolution-mail-notification.schemas.in b/plugins/mail-notification/apps-evolution-mail-notification.schemas.in
index 5cc552d0d0..c6cec4803b 100644
--- a/plugins/mail-notification/apps-evolution-mail-notification.schemas.in
+++ b/plugins/mail-notification/apps-evolution-mail-notification.schemas.in
@@ -1,25 +1,94 @@
<gconfschemafile>
<schemalist>
<schema>
- <key>/schemas/apps/evolution/mail/notification/notification</key>
- <applyto>/apps/evolution/mail/notification/notification</applyto>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/notify-only-inbox</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/notify-only-inbox</applyto>
<owner>evolution-mail</owner>
<type>bool</type>
<default>true</default>
<locale name="C">
- <short>Enable libnotify notifications of new mail</short>
- <long>Every time a new mail arrives, pop up a libnotify notification.</long>
+ <short>Notify messages in Inbox only.</short>
+ <long>Whether to notify new messages in Inbox folder only.</long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/dbus-enabled</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/dbus-enabled</applyto>
+ <owner>evolution-mail</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Enable D-Bus messages.</short>
+ <long>Generates a D-Bus message when new mail messages arrive.</long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/status-enabled</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/status-enabled</applyto>
+ <owner>evolution-mail</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Enable icon in notification area.</short>
+ <long>Show new mail icon in notification area when new messages arrive.</long>
</locale>
</schema>
<schema>
- <key>/schemas/apps/evolution/mail/notification/blink-status-icon</key>
- <applyto>/apps/evolution/mail/notification/blink-status-icon</applyto>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/status-blink-icon</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/status-blink-icon</applyto>
<owner>evolution-mail</owner>
<type>bool</type>
<default>true</default>
<locale name="C">
- <short>Make the status icon blink</short>
- <long>When the new-mail status icon is visible, make it blink.</long>
+ <short>Blink icon in notification area.</short>
+ <long>Whether the icon should blink or not.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/status-notification</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/status-notification</applyto>
+ <owner>evolution-mail</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Popup message together with the icon.</short>
+ <long>Whether show message over the icon when new messages arrive.</long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/sound-enabled</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/sound-enabled</applyto>
+ <owner>evolution-mail</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Play sound when new messages arrive.</short>
+ <long>Whether play sound or beep when new messages arrive.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/sound-beep</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/sound-beep</applyto>
+ <owner>evolution-mail</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Beep or play sound file.</short>
+ <long>If true, then Beep, otherwise will play sound file when new messages arrive.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/evolution/eplugin/mail-notification/sound-file</key>
+ <applyto>/apps/evolution/eplugin/mail-notification/sound-file</applyto>
+ <owner>evolution-mail</owner>
+ <type>string</type>
+ <default></default>
+ <locale name="C">
+ <short>Sound file name to be played.</short>
+ <long>Sound file to be played when new messages arrive, if not in beep mode.</long>
</locale>
</schema>
</schemalist>
diff --git a/plugins/mail-notification/mail-notification.c b/plugins/mail-notification/mail-notification.c
index 7025579172..b2f80829ab 100644
--- a/plugins/mail-notification/mail-notification.c
+++ b/plugins/mail-notification/mail-notification.c
@@ -28,165 +28,768 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gconf/gconf-client.h>
-#include <e-util/e-config.h>
-#include <e-util/e-icon-factory.h>
-
-#include <mail/em-utils.h>
-#include <mail/em-event.h>
-#include <mail/em-folder-tree-model.h>
-#include <camel/camel-folder.h>
+#include <libgnome/libgnome.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <time.h>
+
+#include "e-util/e-config.h"
+#include "e-util/e-icon-factory.h"
+#include "mail/em-utils.h"
+#include "mail/em-event.h"
+#include "mail/em-folder-tree-model.h"
+#include "camel/camel-folder.h"
#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
#endif
-#define GCONF_KEY_NOTIFICATION "/apps/evolution/mail/notification/notification"
-#define GCONF_KEY_BLINK "/apps/evolution/mail/notification/blink-status-icon"
-
-int e_plugin_lib_enable (EPluginLib *ep, int enable);
-void org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t);
-void org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t);
+#define GCONF_KEY_ROOT "/apps/evolution/eplugin/mail-notification/"
+#define GCONF_KEY_NOTIFY_ONLY_INBOX GCONF_KEY_ROOT "notify-only-inbox"
+#define GCONF_KEY_ENABLED_DBUS GCONF_KEY_ROOT "dbus-enabled"
+#define GCONF_KEY_ENABLED_STATUS GCONF_KEY_ROOT "status-enabled"
+#define GCONF_KEY_ENABLED_SOUND GCONF_KEY_ROOT "sound-enabled"
static gboolean enabled = FALSE;
-static GtkStatusIcon *status_icon = NULL;
-#ifdef HAVE_LIBNOTIFY
-static gboolean notification_callback (gpointer notify);
-static NotifyNotification *notify = NULL;
-#endif
+/**
+ * each part should "implement" its own "public" functions:
+ * a) void new_notify_... (EMEventTargetFolder *t)
+ * when new_notify message is sent by Evolution
+ *
+ * b) void read_notify_... (EMEventTargetMessage *t)
+ * it is called when read_notify message is sent by Evolution
+ *
+ * c) void enable_... (int enable)
+ * when plugin itself or the part is enabled/disabled
+ *
+ * d) GtkWidget *get_config_widget_...(void)
+ * to obtain config widget for the particular part
+ *
+ * It also should have its own gconf key for enabled state. In each particular
+ * function it should do its work as expected. enable_... will be called always
+ * when disabling plugin, but only when enabling/disabling part itself.
+ **/
-static GStaticMutex mlock = G_STATIC_MUTEX_INIT;
+/* ------------------------------------------------------------------- */
+/* Helper functions */
+/* ------------------------------------------------------------------- */
-void
-org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t)
+static gboolean
+is_part_enabled (const gchar *gconf_key)
{
- g_static_mutex_lock (&mlock);
+ /* the part is enabled by defaul */
+ gboolean res = TRUE;
+ GConfClient *client;
+ GConfValue *is_key;
- if (!status_icon) {
- g_static_mutex_unlock (&mlock);
- return;
+ client = gconf_client_get_default ();
+
+ is_key = gconf_client_get (client, gconf_key, NULL);
+ if (is_key) {
+ res = gconf_client_get_bool (client, gconf_key, NULL);
+ gconf_value_free (is_key);
}
-#ifdef HAVE_LIBNOTIFY
- notify_notification_close (notify, NULL);
-#endif
- gtk_status_icon_set_visible (status_icon, FALSE);
+ g_object_unref (client);
- g_static_mutex_unlock (&mlock);
+ return res;
}
static void
-#ifdef HAVE_LIBNOTIFY
-icon_activated (GtkStatusIcon *icon, NotifyNotification *notify)
+set_part_enabled (const gchar *gconf_key, gboolean enable)
+{
+ GConfClient *client;
+
+ client = gconf_client_get_default ();
+
+ gconf_client_set_bool (client, gconf_key, enable, NULL);
+ g_object_unref (client);
+}
+
+/* ------------------------------------------------------------------- */
+/* DBUS part */
+/* ------------------------------------------------------------------- */
+
+#define DBUS_PATH "/org/gnome/evolution/mail/newmail"
+#define DBUS_INTERFACE "org.gnome.evolution.mail.dbus.Signal"
+
+static DBusConnection *bus = NULL;
+
+static gboolean init_dbus (void);
+
+static void
+send_dbus_message (const char *name, const char *data, guint new)
+{
+ DBusMessage *message;
+
+ /* Create a new message on the DBUS_INTERFACE */
+ if (!(message = dbus_message_new_signal (DBUS_PATH, DBUS_INTERFACE, name)))
+ return;
+
+ /* Appends the data as an argument to the message */
+ dbus_message_append_args (message,
+#if DBUS_VERSION >= 310
+ DBUS_TYPE_STRING, &data,
#else
-icon_activated (GtkStatusIcon *icon, gpointer notify)
+ DBUS_TYPE_STRING, data,
#endif
+ DBUS_TYPE_INVALID);
+
+ if (new) {
+ char * display_name = em_utils_folder_name_from_uri (data);
+ dbus_message_append_args (message,
+#if DBUS_VERSION >= 310
+ DBUS_TYPE_STRING, &display_name, DBUS_TYPE_UINT32, &new,
+#else
+ DBUS_TYPE_STRING, display_name, DBUS_TYPE_UINT32, new,
+#endif
+ DBUS_TYPE_INVALID);
+
+ }
+
+ /* Sends the message */
+ dbus_connection_send (bus, message, NULL);
+
+ /* Frees the message */
+ dbus_message_unref (message);
+}
+
+static gboolean
+reinit_dbus (gpointer user_data)
{
- g_static_mutex_lock (&mlock);
+ if (!enabled || init_dbus ())
+ return FALSE;
+
+ /* keep trying to re-establish dbus connection */
+ return TRUE;
+}
+
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+ if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
+ strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
+ dbus_connection_unref (bus);
+ bus = NULL;
+
+ g_timeout_add (3000, reinit_dbus, NULL);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static gboolean
+init_dbus (void)
+{
+ DBusError error;
+
+ if (bus != NULL)
+ return TRUE;
+
+ dbus_error_init (&error);
+ if (!(bus = dbus_bus_get (DBUS_BUS_SESSION, &error))) {
+ g_warning ("could not get system bus: %s\n", error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ dbus_connection_setup_with_g_main (bus, NULL);
+ dbus_connection_set_exit_on_disconnect (bus, FALSE);
+
+ dbus_connection_add_filter (bus, filter_function, NULL, NULL);
+
+ return TRUE;
+}
+
+static void
+toggled_dbus_cb (GtkWidget *widget, gpointer data)
+{
+ g_return_if_fail (widget != NULL);
+
+ set_part_enabled (GCONF_KEY_ENABLED_DBUS, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
+}
+
+/* ------------------------------------------------------------------- */
+
+static void
+new_notify_dbus (EMEventTargetFolder *t)
+{
+ if (bus != NULL)
+ send_dbus_message ("Newmail", t->uri, t->new);
+}
+
+static void
+read_notify_dbus (EMEventTargetMessage *t)
+{
+ if (bus != NULL)
+ send_dbus_message ("MessageReading", t->folder->name, 0);
+}
+
+static void
+enable_dbus (int enable)
+{
+ if (enable) {
+ /* we ignore errors here */
+ init_dbus ();
+ } else if (bus != NULL) {
+ dbus_connection_unref (bus);
+ bus = NULL;
+ }
+}
+
+static GtkWidget *
+get_config_widget_dbus (void)
+{
+ GtkWidget *w;
+
+ w = gtk_check_button_new_with_mnemonic (_("Generate a _D-Bus message"));
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), is_part_enabled (GCONF_KEY_ENABLED_DBUS));
+ g_signal_connect (G_OBJECT (w), "toggled", G_CALLBACK (toggled_dbus_cb), NULL);
+ gtk_widget_show (w);
+
+ return w;
+}
+
+/* ------------------------------------------------------------------- */
+/* Notification area part */
+/* ------------------------------------------------------------------- */
+
+#define GCONF_KEY_STATUS_BLINK GCONF_KEY_ROOT "status-blink-icon"
+#define GCONF_KEY_STATUS_NOTIFICATION GCONF_KEY_ROOT "status-notification"
+
+static GtkStatusIcon *status_icon = NULL;
+static unsigned int status_count = 0;
+
#ifdef HAVE_LIBNOTIFY
- notify_notification_close (notify, NULL);
+static gboolean notification_callback (gpointer notify);
+static NotifyNotification *notify = NULL;
#endif
+
+static void
+#ifdef HAVE_LIBNOTIFY
+icon_activated (GtkStatusIcon *icon, NotifyNotification *pnotify)
+#else
+icon_activated (GtkStatusIcon *icon, gpointer pnotify)
+#endif
+{
+ #ifdef HAVE_LIBNOTIFY
+ if (notify)
+ notify_notification_close (notify, NULL);
+
+ notify = NULL;
+ #endif
+
gtk_status_icon_set_visible (status_icon, FALSE);
- g_static_mutex_unlock (&mlock);
+ g_object_unref (status_icon);
+ status_icon = NULL;
+ status_count = 0;
}
#ifdef HAVE_LIBNOTIFY
-gboolean
+static gboolean
notification_callback (gpointer notify)
{
- printf("fff\n");
- return (!notify_notification_show(notify, NULL));
-
+ return (!notify_notification_show (notify, NULL));
}
#endif
-void
-org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t)
+struct _StatusConfigureWidgets
{
- char *msg = NULL;
- char *folder;
- GConfClient *client;
- GConfValue *is_key;
+ GtkWidget *enable;
+ GtkWidget *blink;
+ #ifdef HAVE_LIBNOTIFY
+ GtkWidget *message;
+ #endif
+};
- /* FIXME: Should this is_inbox be configurable? */
- if (!t->new || !t->is_inbox)
- return;
+static void
+toggled_status_cb (GtkWidget *widget, gpointer data)
+{
+ struct _StatusConfigureWidgets *scw = (struct _StatusConfigureWidgets *) data;
+ gboolean enabl;
+
+ g_return_if_fail (scw != NULL);
+ g_return_if_fail (scw->enable != NULL);
+ g_return_if_fail (scw->blink != NULL);
+ #ifdef HAVE_LIBNOTIFY
+ g_return_if_fail (scw->message != NULL);
+ #endif
+
+ enabl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->enable));
+ if (widget == scw->enable)
+ set_part_enabled (GCONF_KEY_ENABLED_STATUS, enabl);
+
+ #define work_widget(w, key) \
+ gtk_widget_set_sensitive (w, enabl); \
+ if (widget == w) \
+ set_part_enabled (key, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)));
+
+ work_widget (scw->blink, GCONF_KEY_STATUS_BLINK);
+ #ifdef HAVE_LIBNOTIFY
+ work_widget (scw->message, GCONF_KEY_STATUS_NOTIFICATION);
+ #endif
+
+ #undef work_widget
+}
- g_static_mutex_lock (&mlock);
- client = gconf_client_get_default ();
+/* ------------------------------------------------------------------- */
- is_key = gconf_client_get (client, GCONF_KEY_BLINK, NULL);
- if (!is_key)
- gconf_client_set_bool (client, GCONF_KEY_BLINK, TRUE, NULL);
- else
- gconf_value_free (is_key);
+static void
+new_notify_status (EMEventTargetFolder *t)
+{
+ char *msg;
if (!status_icon) {
- printf("creating\n");
status_icon = gtk_status_icon_new ();
- gtk_status_icon_set_from_pixbuf (status_icon, e_icon_factory_get_icon ("stock_mail", E_ICON_SIZE_LARGE_TOOLBAR));
+ gtk_status_icon_set_from_pixbuf (status_icon, e_icon_factory_get_icon ("mail-unread", E_ICON_SIZE_LARGE_TOOLBAR));
}
- folder = em_utils_folder_name_from_uri (t->uri);
- msg = g_strdup_printf (ngettext("You have received %d new message in %s.", "You have received %d new messages in %s.", t->new), t->new, folder);
+ if (!status_count) {
+ char *folder;
+
+ status_count = t->new;
+ folder = em_utils_folder_name_from_uri (t->uri);
+ msg = g_strdup_printf (_("You have received %d new messages\nin %s."), status_count, folder);
+
+ g_free (folder);
+ } else {
+ status_count += t->new;
+ msg = g_strdup_printf (_("You have received %d new messages."), status_count);
+ }
gtk_status_icon_set_tooltip (status_icon, msg);
gtk_status_icon_set_visible (status_icon, TRUE);
- gtk_status_icon_set_blinking (status_icon,
- gconf_client_get_bool (client, GCONF_KEY_BLINK, NULL));
+ gtk_status_icon_set_blinking (status_icon, is_part_enabled (GCONF_KEY_STATUS_BLINK));
-#ifdef HAVE_LIBNOTIFY
- /* See whether the notification key has already been set */
- is_key = gconf_client_get (client, GCONF_KEY_NOTIFICATION, NULL);
- if (!is_key)
- gconf_client_set_bool (client, GCONF_KEY_NOTIFICATION, TRUE, NULL);
+ #ifdef HAVE_LIBNOTIFY
+ /* Now check whether we're supposed to send notifications */
+ if (is_part_enabled (GCONF_KEY_STATUS_NOTIFICATION)) {
+ if (notify) {
+ notify_notification_update (notify, _("New email"), msg, "mail-unread");
+ } else {
+ if (!notify_init ("evolution-mail-notification"))
+ fprintf (stderr,"notify init error");
+
+ notify = notify_notification_new (_("New email"), msg, "mail-unread", NULL);
+ notify_notification_attach_to_status_icon (notify, status_icon);
+
+ notify_notification_set_urgency (notify, NOTIFY_URGENCY_NORMAL);
+ notify_notification_set_timeout (notify, NOTIFY_EXPIRES_DEFAULT);
+ g_timeout_add (500, notification_callback, notify);
+ }
+ }
+ #endif
+
+ g_free (msg);
+
+ #ifdef HAVE_LIBNOTIFY
+ g_signal_connect (G_OBJECT (status_icon), "activate", G_CALLBACK (icon_activated), notify);
+ #else
+ g_signal_connect (G_OBJECT (status_icon), "activate", G_CALLBACK (icon_activated), NULL);
+ #endif
+}
+
+static void
+read_notify_status (EMEventTargetMessage *t)
+{
+ if (!status_icon)
+ return;
+
+ #ifdef HAVE_LIBNOTIFY
+ icon_activated (status_icon, notify);
+ #else
+ icon_activated (status_icon, NULL);
+ #endif
+}
+
+static void
+enable_status (int enable)
+{
+ /* this does nothing on enable, it's here just to be
+ consistent with other parts of this plugin */
+}
+
+static GtkWidget *
+get_config_widget_status (void)
+{
+ GtkWidget *vbox, *parent, *alignment;
+ struct _StatusConfigureWidgets *scw;
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ scw = g_malloc0 (sizeof (struct _StatusConfigureWidgets));
+
+ #define create_check(c, key, desc) \
+ c = gtk_check_button_new_with_mnemonic (desc); \
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (c), is_part_enabled (key)); \
+ gtk_box_pack_start (GTK_BOX (parent), c, FALSE, FALSE, 0); \
+ g_signal_connect (G_OBJECT (c), "toggled", G_CALLBACK (toggled_status_cb), scw);
+
+ parent = vbox;
+ create_check (scw->enable, GCONF_KEY_ENABLED_STATUS, _("Show icon in _notification area"));
+
+ parent = gtk_vbox_new (FALSE, 0);
+ create_check (scw->blink, GCONF_KEY_STATUS_BLINK, _("B_link icon in notification area"));
+ #ifdef HAVE_LIBNOTIFY
+ create_check (scw->message, GCONF_KEY_STATUS_NOTIFICATION, _("Popup _message together with the icon"));
+ #endif
+
+ alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 20, 0);
+ gtk_container_add (GTK_CONTAINER (alignment), parent);
+ gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
+
+ #undef create_check
+
+ /* to let structure free properly */
+ g_object_set_data_full (G_OBJECT (vbox), "scw-data", scw, g_free);
+
+ toggled_status_cb (NULL, scw);
+ gtk_widget_show_all (vbox);
+
+ return vbox;
+}
+
+/* ------------------------------------------------------------------- */
+/* Sound part */
+/* ------------------------------------------------------------------- */
+
+/* min no. seconds between newmail notifications */
+#define NOTIFY_THROTTLE 30
+
+#define GCONF_KEY_SOUND_BEEP GCONF_KEY_ROOT "sound-beep"
+#define GCONF_KEY_SOUND_FILE GCONF_KEY_ROOT "sound-file"
+
+static void
+do_play_sound (gboolean beep, const gchar *file)
+{
+ if (beep)
+ gdk_beep ();
+ else if (!file || !*file)
+ g_warning ("No file to play!");
else
- gconf_value_free (is_key);
+ gnome_sound_play (file);
+}
- /* Now check whether we're supposed to send notifications */
- if (gconf_client_get_bool (client, GCONF_KEY_NOTIFICATION, NULL)) {
- if (!notify_init ("evolution-mail-notification"))
- fprintf(stderr,"notify init error");
+struct _SoundConfigureWidgets
+{
+ GtkWidget *enable;
+ GtkWidget *beep;
+ GtkWidget *file;
+ GtkWidget *label;
+ GtkWidget *filechooser;
+ GtkWidget *play;
+};
- notify = notify_notification_new (
- _("New email"),
- msg,
- "stock_mail",
- NULL);
- notify_notification_attach_to_status_icon (notify, status_icon);
+static void
+toggled_sound_cb (GtkWidget *widget, gpointer data)
+{
+ struct _SoundConfigureWidgets *scw = (struct _SoundConfigureWidgets *) data;
+ gboolean enabl;
+
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (scw->enable != NULL);
+ g_return_if_fail (scw->beep != NULL);
+ g_return_if_fail (scw->file != NULL);
+ g_return_if_fail (scw->label != NULL);
+ g_return_if_fail (scw->filechooser != NULL);
+ g_return_if_fail (scw->play != NULL);
+
+ enabl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->enable));
+ if (widget == scw->enable)
+ set_part_enabled (GCONF_KEY_ENABLED_SOUND, enabl);
+
+ gtk_widget_set_sensitive (scw->beep, enabl);
+ gtk_widget_set_sensitive (scw->file, enabl);
+ gtk_widget_set_sensitive (scw->label, enabl);
+ gtk_widget_set_sensitive (scw->filechooser, enabl && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->file)));
+ gtk_widget_set_sensitive (scw->play, enabl);
+
+ if (widget == scw->beep || widget == scw->file)
+ set_part_enabled (GCONF_KEY_SOUND_BEEP, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->beep)));
+}
- notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL);
- notify_notification_set_timeout(notify, NOTIFY_EXPIRES_DEFAULT);
- g_timeout_add(500, notification_callback, notify);
+static void
+sound_file_set_cb (GtkWidget *widget, gpointer data)
+{
+ gchar *file;
+ GConfClient *client;
- }
-#endif
+ g_return_if_fail (widget != NULL);
+
+ client = gconf_client_get_default ();
+ file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
+
+ gconf_client_set_string (client, GCONF_KEY_SOUND_FILE, file ? file : "", NULL);
- g_free (folder);
- g_free (msg);
g_object_unref (client);
-#ifdef HAVE_LIBNOTIFY
- g_signal_connect (G_OBJECT (status_icon), "activate",
- G_CALLBACK (icon_activated), notify);
-#else
- g_signal_connect (G_OBJECT (status_icon), "activate",
- G_CALLBACK (icon_activated), NULL);
-#endif
+ g_free (file);
+}
+
+static void
+sound_play_cb (GtkWidget *widget, gpointer data)
+{
+ struct _SoundConfigureWidgets *scw = (struct _SoundConfigureWidgets *) data;
+ gchar *file;
+
+ g_return_if_fail (data != NULL);
+
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->enable)))
+ return;
+
+ file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (scw->filechooser));
+ do_play_sound (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->beep)), file);
+ g_free (file);
+}
+
+struct _SoundNotifyData {
+ time_t last_notify;
+ guint notify_idle_id;
+};
+
+static gboolean
+sound_notify_idle_cb (gpointer user_data)
+{
+ gchar *file;
+ GConfClient *client;
+ struct _SoundNotifyData *data = (struct _SoundNotifyData *) user_data;
+
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ client = gconf_client_get_default ();
+ file = gconf_client_get_string (client, GCONF_KEY_SOUND_FILE, NULL);
+
+ do_play_sound (is_part_enabled (GCONF_KEY_SOUND_BEEP), file);
+
+ g_object_unref (client);
+ g_free (file);
+
+ time (&data->last_notify);
+
+ data->notify_idle_id = 0;
+
+ return FALSE;
+}
+
+/* ------------------------------------------------------------------- */
+
+static void
+new_notify_sound (EMEventTargetFolder *t)
+{
+ time_t last_newmail;
+ struct _SoundNotifyData data = {0, 0};
+
+ time (&last_newmail);
+
+ /* just put it to the idle queue */
+ if (data.notify_idle_id == 0 && (last_newmail - data.last_notify >= NOTIFY_THROTTLE))
+ data.notify_idle_id = g_idle_add_full (G_PRIORITY_LOW, sound_notify_idle_cb, &data, NULL);
+}
+
+static void
+read_notify_sound (EMEventTargetMessage *t)
+{
+ /* we do nothing here */
+}
+
+static void
+enable_sound (int enable)
+{
+ if (enable)
+ gnome_sound_init ("localhost");
+ else
+ gnome_sound_shutdown ();
+}
+
+static GtkWidget *
+get_config_widget_sound (void)
+{
+ GtkWidget *vbox, *alignment, *parent, *hbox;
+ gchar *file;
+ GConfClient *client;
+ struct _SoundConfigureWidgets *scw;
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ scw = g_malloc0 (sizeof (struct _SoundConfigureWidgets));
+
+ scw->enable = gtk_check_button_new_with_mnemonic (_("_Play sound when new messages arrive"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scw->enable), is_part_enabled (GCONF_KEY_ENABLED_SOUND));
+ gtk_box_pack_start (GTK_BOX (vbox), scw->enable, FALSE, FALSE, 0);
+ g_signal_connect (G_OBJECT (scw->enable), "toggled", G_CALLBACK (toggled_sound_cb), scw);
+
+ parent = gtk_vbox_new (FALSE, 0);
+ scw->beep = gtk_radio_button_new_with_mnemonic (NULL, _("_Beep"));
+ scw->file = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (scw->beep), _("Play _sound file"));
+
+ if (is_part_enabled (GCONF_KEY_SOUND_BEEP))
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scw->beep), TRUE);
+ else
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scw->file), TRUE);
+
+ g_signal_connect (G_OBJECT (scw->beep), "toggled", G_CALLBACK (toggled_sound_cb), scw);
+ g_signal_connect (G_OBJECT (scw->file), "toggled", G_CALLBACK (toggled_sound_cb), scw);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ scw->label = gtk_label_new_with_mnemonic (_("Specify _filename:"));
+ scw->filechooser = gtk_file_chooser_button_new (_("Select sound file"), GTK_FILE_CHOOSER_ACTION_OPEN);
+ scw->play = gtk_button_new_with_mnemonic (_("Pl_ay"));
+
+ gtk_label_set_mnemonic_widget (GTK_LABEL (scw->label), scw->filechooser);
+ gtk_button_set_image (GTK_BUTTON (scw->play), gtk_image_new_from_icon_name ("media-playback-start", GTK_ICON_SIZE_BUTTON));
+
+ client = gconf_client_get_default ();
+ file = gconf_client_get_string (client, GCONF_KEY_SOUND_FILE, NULL);
+
+ if (file && *file)
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (scw->filechooser), file);
+
+ g_object_unref (client);
+ g_free (file);
+
+ g_signal_connect (G_OBJECT (scw->filechooser), "file-set", G_CALLBACK (sound_file_set_cb), scw);
+ g_signal_connect (G_OBJECT (scw->play), "clicked", G_CALLBACK (sound_play_cb), scw);
+
+ gtk_box_pack_start (GTK_BOX (hbox), scw->label, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), scw->filechooser, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), scw->play, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (parent), scw->beep, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (parent), scw->file, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (parent), hbox, FALSE, FALSE, 0);
+
+ alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 20, 0);
+ gtk_container_add (GTK_CONTAINER (alignment), parent);
+ gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
+
+ /* to let structure free properly */
+ g_object_set_data_full (G_OBJECT (vbox), "scw-data", scw, g_free);
+
+ toggled_sound_cb (NULL, scw);
+ gtk_widget_show_all (vbox);
+
+ return vbox;
+}
+
+/* ------------------------------------------------------------------- */
+/* Plugin itself part */
+/* ------------------------------------------------------------------- */
+
+static void
+toggled_only_inbox_cb (GtkWidget *widget, gpointer data)
+{
+ g_return_if_fail (widget != NULL);
+
+ set_part_enabled (GCONF_KEY_NOTIFY_ONLY_INBOX, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
+}
+
+void org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t);
+void org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t);
+
+int e_plugin_lib_enable (EPluginLib *ep, int enable);
+GtkWidget *e_plugin_lib_get_configure_widget (EPlugin *epl);
+
+static GStaticMutex mlock = G_STATIC_MUTEX_INIT;
+
+void
+org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t)
+{
+ g_return_if_fail (t != NULL);
+
+ if (!enabled || !t->new || (!t->is_inbox && is_part_enabled (GCONF_KEY_NOTIFY_ONLY_INBOX)))
+ return;
+
+ g_static_mutex_lock (&mlock);
+
+ if (is_part_enabled (GCONF_KEY_ENABLED_DBUS))
+ new_notify_dbus (t);
+
+ if (is_part_enabled (GCONF_KEY_ENABLED_STATUS))
+ new_notify_status (t);
+
+ if (is_part_enabled (GCONF_KEY_ENABLED_SOUND))
+ new_notify_sound (t);
+
g_static_mutex_unlock (&mlock);
}
+void
+org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t)
+{
+ g_return_if_fail (t != NULL);
+
+ if (!enabled)
+ return;
+
+ g_static_mutex_lock (&mlock);
+
+ if (is_part_enabled (GCONF_KEY_ENABLED_DBUS))
+ read_notify_dbus (t);
+ if (is_part_enabled (GCONF_KEY_ENABLED_STATUS))
+ read_notify_status (t);
+ if (is_part_enabled (GCONF_KEY_ENABLED_SOUND))
+ read_notify_sound (t);
+
+ g_static_mutex_unlock (&mlock);
+}
int
e_plugin_lib_enable (EPluginLib *ep, int enable)
{
- if (enable)
+ if (enable) {
+ if (is_part_enabled (GCONF_KEY_ENABLED_DBUS))
+ enable_dbus (enable);
+
+ if (is_part_enabled (GCONF_KEY_ENABLED_STATUS))
+ enable_status (enable);
+
+ if (is_part_enabled (GCONF_KEY_ENABLED_SOUND))
+ enable_sound (enable);
+
enabled = TRUE;
- else
+ } else {
+ enable_dbus (enable);
+ enable_status (enable);
+ enable_sound (enable);
+
enabled = FALSE;
+ }
return 0;
}
+GtkWidget *
+e_plugin_lib_get_configure_widget (EPlugin *epl)
+{
+ GtkWidget *cfg, *vbox, *check;
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ check = gtk_check_button_new_with_mnemonic (_("Notify new messages for _Inbox only"));
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), is_part_enabled (GCONF_KEY_NOTIFY_ONLY_INBOX));
+ g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (toggled_only_inbox_cb), NULL);
+ gtk_widget_show (check);
+ gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
+
+ cfg = get_config_widget_dbus ();
+ if (cfg)
+ gtk_box_pack_start (GTK_BOX (vbox), cfg, FALSE, FALSE, 0);
+
+ cfg = get_config_widget_status ();
+ if (cfg)
+ gtk_box_pack_start (GTK_BOX (vbox), cfg, FALSE, FALSE, 0);
+
+ cfg = get_config_widget_sound ();
+ if (cfg)
+ gtk_box_pack_start (GTK_BOX (vbox), cfg, FALSE, FALSE, 0);
+
+ gtk_widget_show (vbox);
+
+ return vbox;
+}
diff --git a/plugins/mail-notification/org-gnome-mail-notification.eplug.xml b/plugins/mail-notification/org-gnome-mail-notification.eplug.xml
index b6bcc6e350..9cc4530e73 100644
--- a/plugins/mail-notification/org-gnome-mail-notification.eplug.xml
+++ b/plugins/mail-notification/org-gnome-mail-notification.eplug.xml
@@ -5,7 +5,8 @@
_name="Mail Notification"
location="@PLUGINDIR@/liborg-gnome-mail-notification@SOEXT@">
- <_description>Notifies the user with an icon in notification area and a notification message whenever a new message has arrived.</_description>
+ <_description>Generates a D-Bus message or notifies the user with an icon in notification area and a notification message whenever a new message has arrived.</_description>
+ <author name="Miguel Angel López Hernández" email="miguel@gulev.org.mx"/>
<author name="Srinivasa Ragavan" email="sragavan@novell.com"/>
<hook class="org.gnome.evolution.mail.events:1.0">
@@ -20,15 +21,5 @@
handle="org_gnome_mail_read_notify"
target="message"/>
</hook>
- <!--
- <hook class="org.gnome.evolution.mail.config:1.0">
- <group id="org.gnome.evolution.mail.prefs" target="prefs">
- <item type="item"
- path="00.general/30.notify/00.new_mail_notify"
- _label="New mail notify"
- factory="org_gnome_new_mail_config"/>
- </group>
- </hook>
- -->
</e-plugin>
</e-plugin-list>