MOTD implementation in gnome-session



Hi

I have had this patch around for some time, and seems to work pretty
well, so sending for comments and/or approval.

It just makes gnome-session display the /etc/motd file on startup, using
libnotify if available, or an ugly dialog if not. The 2 new files are to
be placed in gnome-session/gnome-session
-- 
Rodrigo Moya <rodrigo gnome-db org>
? depcomp
? stamp-h1
? gnome-session/gsm-motd.c
? gnome-session/gsm-motd.h
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-session/ChangeLog,v
retrieving revision 1.601
diff -u -p -r1.601 ChangeLog
--- ChangeLog	24 Sep 2005 14:06:25 -0000	1.601
+++ ChangeLog	4 Oct 2005 15:35:46 -0000
@@ -1,3 +1,11 @@
+2005-10-04  Rodrigo Moya <rodrigo novell com>
+
+	* configure.in: look for libnotify.
+
+	* gnome-session/Makefile.am:
+	* gnome-session/main.c (main):
+	* gnome-session/gsm-motd.[ch]: added MOTD implementation.
+
 2005-09-24  Erdal Ronahi  <erdal ronahi gmail com>
 
 	* configure.in: Added "ku" (Kurdish) to ALL_LINGUAS
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-session/configure.in,v
retrieving revision 1.518
diff -u -p -r1.518 configure.in
--- configure.in	24 Sep 2005 14:06:25 -0000	1.518
+++ configure.in	4 Oct 2005 15:35:46 -0000
@@ -59,6 +59,24 @@ PKG_CHECK_MODULES(SOUND_TEST, $ESOUND_MO
 
 PKG_CHECK_MODULES(GNOME_SESSION, gtk+-2.0 >= $GTK_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED $ESOUND_MODULE)
 
+dnl Check if libnotify is present
+
+LIBNOTIFY_REQUIRED=0.2.1
+LIBNOTIFY_CFLAGS=
+LIBNOTIFY_LIBS=
+PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED,
+	          HAVE_LIBNOTIFY="yes", HAVE_LIBNOTIFY="no")
+
+if test "x$HAVE_LIBNOTIFY" = "xyes"; then
+        AC_DEFINE(HAVE_LIBNOTIFY, 1, [libnotify available])
+        AC_MSG_RESULT(available)
+else
+        AC_MSG_RESULT(no)
+fi
+
+AC_SUBST(LIBNOTIFY_CFLAGS)
+AC_SUBST(LIBNOTIFY_LIBS)
+
 dnl gconf checks
 AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
 
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	4 Oct 2005 15:35:47 -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.67
diff -u -p -r1.67 main.c
--- gnome-session/main.c	25 Jul 2005 07:13:53 -0000	1.67
+++ gnome-session/main.c	4 Oct 2005 15:35:48 -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 */
@@ -461,7 +462,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 ();
 
/* 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 <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)
{
  static NotifyIcon *icon = NULL;

  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
    {
      if (!icon)
	      icon = notify_icon_new_from_uri ("gtk-info");

      if (!notify_send_notification (NULL,
				     "device",
				     NOTIFY_URGENCY_NORMAL,
				     _("Message of the Day"),
				     motd_contents,
				     icon,
				     FALSE, 0,
				     NULL,
				     NULL,
				     0))
        {
  	  display_message_of_the_day_dialog ();
	}
    }
}
#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;

  /* 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;
    }
}
#ifndef GSM_MOTD_H
#define GSM_MOTD_H

void gsm_motd_start (void);
void gsm_motd_stop (void);

#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]