258 lines
6.9 KiB
Diff
258 lines
6.9 KiB
Diff
|
--- /dev/null 2006-02-06 19:14:42.000000000 +0100
|
||
|
+++ gnome-session/gsm-motd.h 2006-02-03 12:30:48.000000000 +0100
|
||
|
@@ -0,0 +1,7 @@
|
||
|
+#ifndef GSM_MOTD_H
|
||
|
+#define GSM_MOTD_H
|
||
|
+
|
||
|
+void gsm_motd_start (void);
|
||
|
+void gsm_motd_stop (void);
|
||
|
+
|
||
|
+#endif
|
||
|
--- /dev/null 2006-02-06 19:14:42.000000000 +0100
|
||
|
+++ gnome-session/gsm-motd.c 2006-02-15 14:57:58.000000000 +0100
|
||
|
@@ -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;
|
||
|
+ }
|
||
|
+}
|
||
|
? depcomp
|
||
|
? stamp-h1
|
||
|
? gnome-session/gsm-motd.c
|
||
|
? gnome-session/gsm-motd.h
|
||
|
? po/stamp-it
|
||
|
Index: gnome-session/Makefile.am
|
||
|
===================================================================
|
||
|
RCS file: /cvs/gnome/gnome-session/gnome-session/Makefile.am,v
|
||
|
retrieving revision 1.108
|
||
|
diff -u -p -r1.108 Makefile.am
|
||
|
--- gnome-session/Makefile.am 10 Jan 2005 16:36:40 -0000 1.108
|
||
|
+++ gnome-session/Makefile.am 15 Feb 2006 14:01:55 -0000
|
||
|
@@ -4,6 +4,7 @@ defaultdir = $(datadir)/gnome
|
||
|
|
||
|
INCLUDES = \
|
||
|
$(GNOME_SESSION_CFLAGS) \
|
||
|
+ $(LIBNOTIFY_CFLAGS) \
|
||
|
$(STANDARD_PROPERTIES_CFLAGS) \
|
||
|
$(WARN_CFLAGS) \
|
||
|
$(DISABLE_DEPRECATED_CFLAGS) \
|
||
|
@@ -26,7 +27,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)
|
||
|
@@ -95,6 +96,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
|
||
|
===================================================================
|
||
|
RCS file: /cvs/gnome/gnome-session/gnome-session/main.c,v
|
||
|
retrieving revision 1.70
|
||
|
diff -u -p -r1.70 main.c
|
||
|
--- gnome-session/main.c 30 Oct 2005 11:26:31 -0000 1.70
|
||
|
+++ gnome-session/main.c 15 Feb 2006 14:01:56 -0000
|
||
|
@@ -48,6 +48,7 @@
|
||
|
#include "gsm-xrandr.h"
|
||
|
#include "gsm-at-startup.h"
|
||
|
#include "gsm-remote-desktop.h"
|
||
|
+#include "gsm-motd.h"
|
||
|
|
||
|
/* Flag indicating autosave - user won't be prompted on logout to
|
||
|
* save the session */
|
||
|
@@ -465,7 +466,11 @@ main (int argc, char *argv[])
|
||
|
if (a_t_support) /* the ATs are happier if the session has started */
|
||
|
gsm_assistive_technologies_start ();
|
||
|
|
||
|
+ gsm_motd_start ();
|
||
|
+
|
||
|
gtk_main ();
|
||
|
+
|
||
|
+ gsm_motd_stop ();
|
||
|
|
||
|
gsm_remote_desktop_cleanup ();
|
||
|
|