gnome-session/gnome-session-motd.patch

252 lines
6.5 KiB
Diff

Index: gnome-session/gsm-motd.h
===================================================================
--- /dev/null
+++ gnome-session/gsm-motd.h
@@ -0,0 +1,7 @@
+#ifndef GSM_MOTD_H
+#define GSM_MOTD_H
+
+void gsm_motd_start (void);
+void gsm_motd_stop (void);
+
+#endif
Index: gnome-session/gsm-motd.c
===================================================================
--- /dev/null
+++ gnome-session/gsm-motd.c
@@ -0,0 +1,179 @@
+/* gdm-motd.c - Message of the Day support in gnome-session.
+
+ Copyright (C) 1998, 1999 Tom Tromey
+
+ 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, 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <gconf/gconf-client.h>
+#include <gtk/gtkmessagedialog.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+#endif
+#include "gsm-motd.h"
+
+static gchar *motd_contents = NULL;
+static GnomeVFSMonitorHandle *monitor_handle = NULL;
+
+static void
+display_message_of_the_day_dialog (void)
+{
+ GtkWidget *dialog;
+
+ if (motd_contents)
+ {
+ dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
+ "<big><b>%s</b></big>\n%s",
+ _("Message of the Day"), motd_contents);
+ g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL);
+ gtk_widget_show (dialog);
+ }
+}
+
+#ifdef HAVE_LIBNOTIFY
+static void
+display_message_of_the_day_notification (void)
+{
+ NotifyNotification *n;
+ GdkPixbuf *icon;
+
+ if (!motd_contents)
+ return;
+
+ if (!notify_is_initted () && !notify_init (_("Session Manager")))
+ {
+ g_printerr ("Could not contact the notification daemon");
+ display_message_of_the_day_dialog ();
+ }
+ else
+ {
+ icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "gtk-info",
+ 48,
+ GTK_ICON_LOOKUP_USE_BUILTIN,
+ NULL);
+
+ n = notify_notification_new (_("Message of the Day"), motd_contents, NULL, NULL);
+ notify_notification_set_icon_from_pixbuf (n, icon);
+ gdk_pixbuf_unref (icon);
+
+ if (!notify_notification_show (n, NULL))
+ {
+ display_message_of_the_day_dialog ();
+ }
+
+ //g_object_unref (n);
+ }
+}
+#endif
+
+static void
+motd_changed_cb (GnomeVFSMonitorHandle *handle,
+ const gchar *monitor_uri,
+ const gchar *info_uri,
+ GnomeVFSMonitorEventType event_type,
+ gpointer user_data)
+{
+ gchar *contents;
+ gsize length;
+
+ switch (event_type)
+ {
+ case GNOME_VFS_MONITOR_EVENT_CHANGED :
+ case GNOME_VFS_MONITOR_EVENT_CREATED :
+ if (g_file_get_contents ("/etc/motd", &contents, &length, NULL))
+ {
+ if (length > 0)
+ {
+ g_free (motd_contents);
+ motd_contents = contents;
+
+#ifdef HAVE_LIBNOTIFY
+ display_message_of_the_day_notification ();
+#else
+ display_message_of_the_day_dialog ();
+#endif
+ }
+ }
+ break;
+ case GNOME_VFS_MONITOR_EVENT_DELETED :
+ g_free (motd_contents);
+ motd_contents = NULL;
+ break;
+ }
+}
+
+static gboolean
+on_login_cb (gpointer user_data)
+{
+#ifdef HAVE_LIBNOTIFY
+ display_message_of_the_day_notification ();
+#else
+ display_message_of_the_day_dialog ();
+#endif
+
+ return FALSE;
+}
+
+void
+gsm_motd_start (void)
+{
+ gchar *contents;
+ gsize length;
+ GConfClient *client;
+ gboolean enabled;
+
+ client = gconf_client_get_default ();
+ enabled = gconf_client_get_bool (client, "/apps/gnome-session/options/enable_motd", NULL);
+ g_object_unref (client);
+
+ if (!enabled)
+ return;
+
+ /* load the MOTD file */
+ if (gnome_vfs_monitor_add (&monitor_handle, "file:///etc/motd", GNOME_VFS_MONITOR_FILE,
+ (GnomeVFSMonitorCallback) motd_changed_cb, NULL) != GNOME_VFS_OK)
+ {
+ g_printerr ("Failed to setup monitor for /etc/motd file");
+ }
+
+ if (g_file_get_contents ("/etc/motd", &contents, &length, NULL))
+ {
+ if (length > 0)
+ motd_contents = contents;
+ }
+
+ /* install a timeout to show the message first time */
+ g_timeout_add (8000, (GSourceFunc) on_login_cb, NULL);
+}
+
+void
+gsm_motd_stop (void)
+{
+ if (monitor_handle)
+ {
+ gnome_vfs_monitor_cancel (monitor_handle);
+ monitor_handle = NULL;
+ }
+
+ if (motd_contents)
+ {
+ g_free (motd_contents);
+ motd_contents = NULL;
+ }
+}
Index: gnome-session/Makefile.am
===================================================================
--- gnome-session/Makefile.am.orig
+++ gnome-session/Makefile.am
@@ -4,6 +4,7 @@ defaultdir = $(datadir)/gnome
INCLUDES = \
$(GNOME_SESSION_CFLAGS) \
+ $(LIBNOTIFY_CFLAGS) \
$(STANDARD_PROPERTIES_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
@@ -25,7 +26,7 @@ STANDARD_PROPERTIES_CFLAGS =
-DDATADIR=\""$(datadir)"\" \
$(NULL)
-gnome_session_LDADD = $(X_LIBS) $(GNOME_SESSION_LIBS) $(LIBWRAP_LIBS)
+gnome_session_LDADD = $(X_LIBS) $(GNOME_SESSION_LIBS) $(LIBWRAP_LIBS) $(LIBNOTIFY_LIBS)
gnome_session_save_LDADD = $(GNOME_SESSION_LIBS)
gnome_session_remove_LDADD = $(GNOME_SESSION_LIBS)
gnome_session_properties_LDADD = $(GNOME_SESSION_LIBS)
@@ -83,6 +84,8 @@ gnome_session_SOURCES = \
gsm-keyring.h \
gsm-gsd.c \
gsm-gsd.h \
+ gsm-motd.c \
+ gsm-motd.h \
gsm-protocol.c \
gsm-protocol.h \
gsm-remote-desktop.c \
Index: gnome-session/main.c
===================================================================
--- gnome-session/main.c.orig
+++ gnome-session/main.c
@@ -53,6 +53,7 @@
#include "gsm-keyring.h"
#include "gsm-at-startup.h"
#include "gsm-remote-desktop.h"
+#include "gsm-motd.h"
#include "migrate-trash.h"
/* Flag indicating autosave - user won't be prompted on logout to
@@ -668,8 +669,12 @@ main (int argc, char *argv[])
migrate_trash();
+ gsm_motd_start ();
+
gtk_main ();
+ gsm_motd_stop ();
+
gsm_remote_desktop_cleanup ();
gsm_sound_logout ();