diff --git a/pandora_applet/AUTHORS b/pandora_applet/AUTHORS new file mode 100644 index 0000000000..d6b1c721bb --- /dev/null +++ b/pandora_applet/AUTHORS @@ -0,0 +1 @@ +Esteban Sanchez diff --git a/pandora_applet/COPYING b/pandora_applet/COPYING new file mode 120000 index 0000000000..e1cdc17cb3 --- /dev/null +++ b/pandora_applet/COPYING @@ -0,0 +1 @@ +/usr/share/automake-1.4/COPYING \ No newline at end of file diff --git a/pandora_applet/ChangeLog b/pandora_applet/ChangeLog new file mode 100644 index 0000000000..54a57c7789 --- /dev/null +++ b/pandora_applet/ChangeLog @@ -0,0 +1,3 @@ +2006-08-31 Esteban Sanchez + + * Initial import. diff --git a/pandora_applet/INSTALL b/pandora_applet/INSTALL new file mode 120000 index 0000000000..56c9903c02 --- /dev/null +++ b/pandora_applet/INSTALL @@ -0,0 +1 @@ +/usr/share/automake-1.4/INSTALL \ No newline at end of file diff --git a/pandora_applet/Makefile.am b/pandora_applet/Makefile.am new file mode 100644 index 0000000000..8723614eb7 --- /dev/null +++ b/pandora_applet/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS=src data + diff --git a/pandora_applet/NEWS b/pandora_applet/NEWS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pandora_applet/README b/pandora_applet/README new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pandora_applet/acinclude.m4 b/pandora_applet/acinclude.m4 new file mode 100644 index 0000000000..3f0e7044a3 --- /dev/null +++ b/pandora_applet/acinclude.m4 @@ -0,0 +1,94 @@ +dnl @synopsis CHECK_MYSQL_DB +dnl +dnl This macro tries to find the headers and librariess for the +dnl MySQL database to build client applications. +dnl +dnl If includes are found, the variable MYSQL_INC will be set. If +dnl libraries are found, the variable MYSQL_LIB will be set. if no check +dnl was successful, the script exits with a error message. +dnl +dnl @category InstalledPackages +dnl @author Harald Welte +dnl @version 2006-01-07 +dnl @license AllPermissive + +AC_DEFUN([CHECK_MYSQL_DB], [ + +AC_ARG_WITH(mysql, + [ --with-mysql=PREFIX Prefix of your MySQL installation], + [my_prefix=$withval], [my_prefix=]) +AC_ARG_WITH(mysql-inc, + [ --with-mysql-inc=PATH Path to the include directory of MySQL], + [my_inc=$withval], [my_inc=]) +AC_ARG_WITH(mysql-lib, + [ --with-mysql-lib=PATH Path to the libraries of MySQL], + [my_lib=$withval], [my_lib=]) + + +AC_SUBST(MYSQL_INC) +AC_SUBST(MYSQL_LIB) + +if test "$my_prefix" != "no"; then + +AC_MSG_CHECKING([for MySQL mysql_config program]) +for d in $my_prefix/bin /usr/bin /usr/local/bin /usr/local/mysql/bin /opt/mysql/bin /opt/packages/mysql/bin +do + if test -x $d/mysql_config + then + AC_MSG_RESULT(found mysql_config in $d) + MYSQL_INC=$($d/mysql_config --include) + MYSQL_LIB=$($d/mysql_config --libs) + break + fi +done + +if test "$MYSQL_INC" = ""; then +AC_MSG_RESULT(mysql_config not found) +if test "$my_prefix" != ""; then + AC_MSG_CHECKING([for MySQL includes in $my_prefix/include]) + if test -f "$my_prefix/include/mysql.h" ; then + MYSQL_INC="-I$my_prefix/include" + AC_MSG_RESULT([yes]) + else + AC_MSG_ERROR(mysql.h not found) + fi + AC_MSG_CHECKING([for MySQL libraries in $my_prefix/lib]) + if test -f "$my_prefix/lib/libmysql.so" ; then + MYSQL_LIB="-L$my_prefix/lib -lmysqlclient" + AC_MSG_RESULT([yes]) + else + AC_MSG_ERROR(libmysqlclient.so not found) + fi +else + if test "$my_inc" != ""; then + AC_MSG_CHECKING([for MySQL includes in $my_inc]) + if test -f "$my_inc/mysql.h" ; then + MYSQL_INC="-I$my_inc" + AC_MSG_RESULT([yes]) + else + AC_MSG_ERROR(mysql.h not found) + fi + fi + if test "$my_lib" != ""; then + AC_MSG_CHECKING([for MySQL libraries in $my_lib]) + if test -f "$my_lib/libmysqlclient.so" ; then + MYSQL_LIB="-L$my_lib -lmysqlclient" + AC_MSG_RESULT([yes]) + else + AC_MSG_ERROR(libmysqlclient.so not found) + fi + fi +fi + +fi + +if test "$MYSQL_INC" = "" ; then + AC_CHECK_HEADER([mysql.h], [], AC_MSG_ERROR(mysql.h not found)) +fi +if test "$MYSQL_LIB" = "" ; then + AC_CHECK_LIB(mysqlclient, mysql_close, [], AC_MSG_ERROR(libmysqlclient.so not found)) +fi + +fi + +]) diff --git a/pandora_applet/autogen.sh b/pandora_applet/autogen.sh new file mode 100755 index 0000000000..5b2a78a59a --- /dev/null +++ b/pandora_applet/autogen.sh @@ -0,0 +1,45 @@ +#! /bin/sh + +# $Id: autogen.sh,v 1.4 2002/12/02 01:39:49 murrayc Exp $ +# +# Copyright (c) 2002 Daniel Elstner +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License VERSION 2 as +# published by the Free Software Foundation. You are not allowed to +# use any other version of the license; unless you got the explicit +# permission from the author to do so. +# +# 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 + +dir=`echo "$0" | sed 's,[^/]*$,,'` +test "x${dir}" = "x" && dir='.' + +if test "x`cd "${dir}" 2>/dev/null && pwd`" != "x`pwd`" +then + echo "This script must be executed directly from the source directory." + exit 1 +fi + +rm -f config.cache acconfig.h + +echo "- Running aclocal." && \ +aclocal && \ +echo "- Running autoconf." && \ +autoconf && \ +echo "- Running autoheader." && \ +autoheader && \ +echo "- Running automake." && \ +automake --add-missing --gnu && \ +echo && \ +./configure "$@" && exit 0 + +exit 1 + diff --git a/pandora_applet/configure.in b/pandora_applet/configure.in new file mode 100644 index 0000000000..0baddea4ed --- /dev/null +++ b/pandora_applet/configure.in @@ -0,0 +1,58 @@ +AC_PREREQ(2.59) + +m4_define([pandoraapplet_major_version], [1]) +m4_define([pandoraapplet_minor_version], [0]) +m4_define([pandoraapplet_micro_version], [0]) +m4_define([pandoraapplet_build_version], []) +m4_define([pandoraapplet_version], m4_format('%s.%s.%s%s', pandoraapplet_major_version, pandoraapplet_minor_version, pandoraapplet_micro_version, pandoraapplet_build_version)) + +AC_INIT([pandora-applet], [pandoraapplet_version], [http://sourceforge.net/], [pandora_applet]) +AC_CONFIG_SRCDIR([src/main.c]) +AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) + +AC_SUBST(ACLOCAL_AMFLAGS, "$ACLOCAL_FLAGS") + +AM_CONFIG_HEADER(config.h) +AM_MAINTAINER_MODE + +AC_ISC_POSIX +AC_PROG_CC +AM_PROG_CC_STDC +AC_STDC_HEADERS + +GLIB_REQUIRED=2.6.0 +GTK_REQUIRED=2.8.0 + +PKG_CHECK_MODULES(PANDORA, + glib-2.0 >= $GLIB_REQUIRED + gtk+-2.0 >= $GTK_REQUIRED + gthread-2.0 + libxml-2.0) + +CHECK_MYSQL_DB + +GETTEXT_PACKAGE=pandora-applet +AC_SUBST(GETTEXT_PACKAGE) +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The gettext package]) +ALL_LINGUAS="" +AM_GLIB_GNU_GETTEXT + +if test "x${prefix}" = "xNONE"; then + AC_DEFINE_UNQUOTED(PIXMAPS_DIR, "${ac_default_prefix}/$DATADIRNAME/${PACKAGE}/pixmaps", [Pixmaps directory]) + pixmaps_dir="${ac_default_prefix}/$DATADIRNAME/${PACKAGE}/pixmaps" +else + AC_DEFINE_UNQUOTED(PIXMAPS_DIR, "${prefix}/$DATADIRNAME/${PACKAGE}/pixmaps", [Pixmaps directory]) + pixmaps_dir="${prefix}/$DATADIRNAME/${PACKAGE}/pixmaps" +fi + +AC_SUBST(pixmaps_dir) + +AC_SUBST(PANDORA_CFLAGS) +AC_SUBST(PANDORA_LIBS) + +AC_CONFIG_FILES([ +Makefile +src/Makefile +data/Makefile]) + +AC_OUTPUT diff --git a/pandora_applet/data/Makefile.am b/pandora_applet/data/Makefile.am new file mode 100644 index 0000000000..75d35ca9b1 --- /dev/null +++ b/pandora_applet/data/Makefile.am @@ -0,0 +1,20 @@ +pixmapsdir = $(pixmaps_dir) + +pixmaps_DATA = \ + pandora-applet-bad.png \ + pandora-applet-good.png \ + pandora-applet-unknown.png \ + pandora-alerts-bad.png \ + pandora-alerts-ok.png \ + pandora-alerts-unknown.png \ + pandora-servers-bad.png \ + pandora-servers-ok.png \ + pandora-servers-unknown.png \ + pandora-agents-bad.png \ + pandora-agents-ok.png \ + pandora-agents-unknown.png \ + pandora.png + +EXTRA_DIST = \ + $(pixmaps_DATA) + diff --git a/pandora_applet/data/bubble-source.svg b/pandora_applet/data/bubble-source.svg new file mode 100644 index 0000000000..a7846212b6 --- /dev/null +++ b/pandora_applet/data/bubble-source.svg @@ -0,0 +1,116 @@ + + + + + + + + + image/svg+xml + + + Emblem Important + + + Jakub Steiner + + + + + emblem + photos + pictures + raw + jpeg + + + + + + + + + + + + + + + + + + + diff --git a/pandora_applet/data/help-browser.svg b/pandora_applet/data/help-browser.svg new file mode 100644 index 0000000000..669dda345f --- /dev/null +++ b/pandora_applet/data/help-browser.svg @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Help Browser + 2005-11-06 + + + Tuomas Kuosmanen + + + + + help + browser + documentation + docs + man + info + + + + + + Jakub Steiner, Andreas Nilsson + + + http://tigert.com + + + + + + + + + + + + + + + + + + diff --git a/pandora_applet/data/lamp-source.svg b/pandora_applet/data/lamp-source.svg new file mode 100644 index 0000000000..74a9aa7885 --- /dev/null +++ b/pandora_applet/data/lamp-source.svg @@ -0,0 +1,1131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Info + + + Jakub Steiner + + + + + dialog + info + + + http://jimmac.musichall.cz + + + + Garrett LeSage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pandora_applet/data/pandora-agents-bad.png b/pandora_applet/data/pandora-agents-bad.png new file mode 100644 index 0000000000..a3e892007d Binary files /dev/null and b/pandora_applet/data/pandora-agents-bad.png differ diff --git a/pandora_applet/data/pandora-agents-ok.png b/pandora_applet/data/pandora-agents-ok.png new file mode 100644 index 0000000000..71b5333396 Binary files /dev/null and b/pandora_applet/data/pandora-agents-ok.png differ diff --git a/pandora_applet/data/pandora-agents-unknown.png b/pandora_applet/data/pandora-agents-unknown.png new file mode 100644 index 0000000000..dc2ede74a1 Binary files /dev/null and b/pandora_applet/data/pandora-agents-unknown.png differ diff --git a/pandora_applet/data/pandora-alerts-bad.png b/pandora_applet/data/pandora-alerts-bad.png new file mode 100644 index 0000000000..fac9cbd781 Binary files /dev/null and b/pandora_applet/data/pandora-alerts-bad.png differ diff --git a/pandora_applet/data/pandora-alerts-ok.png b/pandora_applet/data/pandora-alerts-ok.png new file mode 100644 index 0000000000..0be5bbe73e Binary files /dev/null and b/pandora_applet/data/pandora-alerts-ok.png differ diff --git a/pandora_applet/data/pandora-alerts-unknown.png b/pandora_applet/data/pandora-alerts-unknown.png new file mode 100644 index 0000000000..91c1c5e48a Binary files /dev/null and b/pandora_applet/data/pandora-alerts-unknown.png differ diff --git a/pandora_applet/data/pandora-applet-bad.png b/pandora_applet/data/pandora-applet-bad.png new file mode 100644 index 0000000000..2464dfc845 Binary files /dev/null and b/pandora_applet/data/pandora-applet-bad.png differ diff --git a/pandora_applet/data/pandora-applet-good.png b/pandora_applet/data/pandora-applet-good.png new file mode 100644 index 0000000000..b49df6c298 Binary files /dev/null and b/pandora_applet/data/pandora-applet-good.png differ diff --git a/pandora_applet/data/pandora-applet-unknown.png b/pandora_applet/data/pandora-applet-unknown.png new file mode 100644 index 0000000000..50ce56618d Binary files /dev/null and b/pandora_applet/data/pandora-applet-unknown.png differ diff --git a/pandora_applet/data/pandora-servers-bad.png b/pandora_applet/data/pandora-servers-bad.png new file mode 100644 index 0000000000..7969ce0e0c Binary files /dev/null and b/pandora_applet/data/pandora-servers-bad.png differ diff --git a/pandora_applet/data/pandora-servers-ok.png b/pandora_applet/data/pandora-servers-ok.png new file mode 100644 index 0000000000..bef1cebd40 Binary files /dev/null and b/pandora_applet/data/pandora-servers-ok.png differ diff --git a/pandora_applet/data/pandora-servers-unknown.png b/pandora_applet/data/pandora-servers-unknown.png new file mode 100644 index 0000000000..6a3c37840c Binary files /dev/null and b/pandora_applet/data/pandora-servers-unknown.png differ diff --git a/pandora_applet/data/pandora.png b/pandora_applet/data/pandora.png new file mode 100644 index 0000000000..504858b15e Binary files /dev/null and b/pandora_applet/data/pandora.png differ diff --git a/pandora_applet/data/server-source.svg b/pandora_applet/data/server-source.svg new file mode 100644 index 0000000000..d8e64902c7 --- /dev/null +++ b/pandora_applet/data/server-source.svg @@ -0,0 +1,3095 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Server + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + server + daemon + comupetr + lan + service + provider + + + + + Garrett LeSage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pandora_applet/po/POTFILES.in b/pandora_applet/po/POTFILES.in new file mode 100644 index 0000000000..72ce77c84a --- /dev/null +++ b/pandora_applet/po/POTFILES.in @@ -0,0 +1,8 @@ +[encoding: UTF-8] +# List of source files containing translatable strings. +# Please keep this file sorted alphabetically. + +src/main.c +src/pandora-applet.c +src/pandora-info-window.c +src/pandora-setup-dialog.c diff --git a/pandora_applet/src/Makefile.am b/pandora_applet/src/Makefile.am new file mode 100644 index 0000000000..fdbad846ca --- /dev/null +++ b/pandora_applet/src/Makefile.am @@ -0,0 +1,20 @@ + +INCLUDES = $(PANDORA_CFLAGS) \ + $(MYSQL_INC) \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -DGLADEDIR=\""$(gladedir)"\" + +bin_PROGRAMS = pandora-applet + +pandora_applet_SOURCES = main.c \ + pandora-applet.c pandora-applet.h \ + pandora-setup.c pandora-setup.h \ + pandora-status.c pandora-status.h \ + pandora-status-checker.c pandora-status-checker.h \ + pandora-info-window.c pandora-info-window.h \ + pandora-setup-dialog.c pandora-setup-dialog.h \ + eggtrayicon.c eggtrayicon.h + +pandora_applet_LDADD = $(PANDORA_LIBS) \ + $(MYSQL_LIB) + diff --git a/pandora_applet/src/eggtrayicon.c b/pandora_applet/src/eggtrayicon.c new file mode 100644 index 0000000000..ebf8a4814d --- /dev/null +++ b/pandora_applet/src/eggtrayicon.c @@ -0,0 +1,559 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* eggtrayicon.c + * Copyright (C) 2002 Anders Carlsson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include + +#include "eggtrayicon.h" + +#include +#if defined (GDK_WINDOWING_X11) +#include +#include +#elif defined (GDK_WINDOWING_WIN32) +#include +#endif + +#ifndef EGG_COMPILATION +#ifndef _ +#define _(x) dgettext (GETTEXT_PACKAGE, x) +#define N_(x) x +#endif +#else +#define _(x) x +#define N_(x) x +#endif + +#define SYSTEM_TRAY_REQUEST_DOCK 0 +#define SYSTEM_TRAY_BEGIN_MESSAGE 1 +#define SYSTEM_TRAY_CANCEL_MESSAGE 2 + +#define SYSTEM_TRAY_ORIENTATION_HORZ 0 +#define SYSTEM_TRAY_ORIENTATION_VERT 1 + +enum { + PROP_0, + PROP_ORIENTATION +}; + +static GtkPlugClass *parent_class = NULL; + +static void egg_tray_icon_init (EggTrayIcon *icon); +static void egg_tray_icon_class_init (EggTrayIconClass *klass); + +static void egg_tray_icon_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +static void egg_tray_icon_realize (GtkWidget *widget); +static void egg_tray_icon_unrealize (GtkWidget *widget); + +static void egg_tray_icon_add (GtkContainer *container, + GtkWidget *widget); + +#ifdef GDK_WINDOWING_X11 +static void egg_tray_icon_update_manager_window (EggTrayIcon *icon, + gboolean dock_if_realized); +static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon); +#endif + +GType +egg_tray_icon_get_type (void) +{ + static GType our_type = 0; + + if (our_type == 0) + { + static const GTypeInfo our_info = + { + sizeof (EggTrayIconClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) egg_tray_icon_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (EggTrayIcon), + 0, /* n_preallocs */ + (GInstanceInitFunc) egg_tray_icon_init + }; + + our_type = g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, 0); + } + + return our_type; +} + +static void +egg_tray_icon_init (EggTrayIcon *icon) +{ + icon->stamp = 1; + icon->orientation = GTK_ORIENTATION_HORIZONTAL; + + gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK); +} + +static void +egg_tray_icon_class_init (EggTrayIconClass *klass) +{ + GObjectClass *gobject_class = (GObjectClass *)klass; + GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; + GtkContainerClass *container_class = (GtkContainerClass *)klass; + + parent_class = g_type_class_peek_parent (klass); + + gobject_class->get_property = egg_tray_icon_get_property; + + widget_class->realize = egg_tray_icon_realize; + widget_class->unrealize = egg_tray_icon_unrealize; + + container_class->add = egg_tray_icon_add; + + g_object_class_install_property (gobject_class, + PROP_ORIENTATION, + g_param_spec_enum ("orientation", + _("Orientation"), + _("The orientation of the tray."), + GTK_TYPE_ORIENTATION, + GTK_ORIENTATION_HORIZONTAL, + G_PARAM_READABLE)); + +#if defined (GDK_WINDOWING_X11) + /* Nothing */ +#elif defined (GDK_WINDOWING_WIN32) + g_warning ("Port eggtrayicon to Win32"); +#else + g_warning ("Port eggtrayicon to this GTK+ backend"); +#endif +} + +static void +egg_tray_icon_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EggTrayIcon *icon = EGG_TRAY_ICON (object); + + switch (prop_id) + { + case PROP_ORIENTATION: + g_value_set_enum (value, icon->orientation); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +#ifdef GDK_WINDOWING_X11 + +static void +egg_tray_icon_get_orientation_property (EggTrayIcon *icon) +{ + Display *xdisplay; + Atom type; + int format; + union { + gulong *prop; + guchar *prop_ch; + } prop = { NULL }; + gulong nitems; + gulong bytes_after; + int error, result; + + g_assert (icon->manager_window != None); + + xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); + + gdk_error_trap_push (); + type = None; + result = XGetWindowProperty (xdisplay, + icon->manager_window, + icon->orientation_atom, + 0, G_MAXLONG, FALSE, + XA_CARDINAL, + &type, &format, &nitems, + &bytes_after, &(prop.prop_ch)); + error = gdk_error_trap_pop (); + + if (error || result != Success) + return; + + if (type == XA_CARDINAL) + { + GtkOrientation orientation; + + orientation = (prop.prop [0] == SYSTEM_TRAY_ORIENTATION_HORZ) ? + GTK_ORIENTATION_HORIZONTAL : + GTK_ORIENTATION_VERTICAL; + + if (icon->orientation != orientation) + { + icon->orientation = orientation; + + g_object_notify (G_OBJECT (icon), "orientation"); + } + } + + if (prop.prop) + XFree (prop.prop); +} + +static GdkFilterReturn +egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) +{ + EggTrayIcon *icon = user_data; + XEvent *xev = (XEvent *)xevent; + + if (xev->xany.type == ClientMessage && + xev->xclient.message_type == icon->manager_atom && + xev->xclient.data.l[1] == icon->selection_atom) + { + egg_tray_icon_update_manager_window (icon, TRUE); + } + else if (xev->xany.window == icon->manager_window) + { + if (xev->xany.type == PropertyNotify && + xev->xproperty.atom == icon->orientation_atom) + { + egg_tray_icon_get_orientation_property (icon); + } + if (xev->xany.type == DestroyNotify) + { + egg_tray_icon_manager_window_destroyed (icon); + } + } + return GDK_FILTER_CONTINUE; +} + +#endif + +static void +egg_tray_icon_unrealize (GtkWidget *widget) +{ +#ifdef GDK_WINDOWING_X11 + EggTrayIcon *icon = EGG_TRAY_ICON (widget); + GdkWindow *root_window; + + if (icon->manager_window != None) + { + GdkWindow *gdkwin; + + gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (widget), + icon->manager_window); + + gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); + } + + root_window = gdk_screen_get_root_window (gtk_widget_get_screen (widget)); + + gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon); + + if (GTK_WIDGET_CLASS (parent_class)->unrealize) + (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); +#endif +} + +#ifdef GDK_WINDOWING_X11 + +static void +egg_tray_icon_send_manager_message (EggTrayIcon *icon, + long message, + Window window, + long data1, + long data2, + long data3) +{ + XClientMessageEvent ev; + Display *display; + + ev.type = ClientMessage; + ev.window = window; + ev.message_type = icon->system_tray_opcode_atom; + ev.format = 32; + ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window); + ev.data.l[1] = message; + ev.data.l[2] = data1; + ev.data.l[3] = data2; + ev.data.l[4] = data3; + + display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); + + gdk_error_trap_push (); + XSendEvent (display, + icon->manager_window, False, NoEventMask, (XEvent *)&ev); + XSync (display, False); + gdk_error_trap_pop (); +} + +static void +egg_tray_icon_send_dock_request (EggTrayIcon *icon) +{ + egg_tray_icon_send_manager_message (icon, + SYSTEM_TRAY_REQUEST_DOCK, + icon->manager_window, + gtk_plug_get_id (GTK_PLUG (icon)), + 0, 0); +} + +static void +egg_tray_icon_update_manager_window (EggTrayIcon *icon, + gboolean dock_if_realized) +{ + Display *xdisplay; + + if (icon->manager_window != None) + return; + + xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); + + XGrabServer (xdisplay); + + icon->manager_window = XGetSelectionOwner (xdisplay, + icon->selection_atom); + + if (icon->manager_window != None) + XSelectInput (xdisplay, + icon->manager_window, StructureNotifyMask|PropertyChangeMask); + + XUngrabServer (xdisplay); + XFlush (xdisplay); + + if (icon->manager_window != None) + { + GdkWindow *gdkwin; + + gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)), + icon->manager_window); + + gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon); + + if (dock_if_realized && GTK_WIDGET_REALIZED (icon)) + egg_tray_icon_send_dock_request (icon); + + egg_tray_icon_get_orientation_property (icon); + } +} + +static void +egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon) +{ + GdkWindow *gdkwin; + + g_return_if_fail (icon->manager_window != None); + + gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)), + icon->manager_window); + + gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); + + icon->manager_window = None; + + egg_tray_icon_update_manager_window (icon, TRUE); +} + +#endif + +static gboolean +transparent_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) +{ + gdk_window_clear_area (widget->window, event->area.x, event->area.y, + event->area.width, event->area.height); + return FALSE; +} + +static void +make_transparent_again (GtkWidget *widget, GtkStyle *previous_style, + gpointer user_data) +{ + gdk_window_set_back_pixmap (widget->window, NULL, TRUE); +} + +static void +make_transparent (GtkWidget *widget, gpointer user_data) +{ + if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget)) + return; + + gtk_widget_set_app_paintable (widget, TRUE); + gtk_widget_set_double_buffered (widget, FALSE); + gdk_window_set_back_pixmap (widget->window, NULL, TRUE); + g_signal_connect (widget, "expose_event", + G_CALLBACK (transparent_expose_event), NULL); + g_signal_connect_after (widget, "style_set", + G_CALLBACK (make_transparent_again), NULL); +} + +static void +egg_tray_icon_realize (GtkWidget *widget) +{ +#ifdef GDK_WINDOWING_X11 + EggTrayIcon *icon = EGG_TRAY_ICON (widget); + GdkScreen *screen; + GdkDisplay *display; + Display *xdisplay; + char buffer[256]; + GdkWindow *root_window; + + if (GTK_WIDGET_CLASS (parent_class)->realize) + GTK_WIDGET_CLASS (parent_class)->realize (widget); + + make_transparent (widget, NULL); + + screen = gtk_widget_get_screen (widget); + display = gdk_screen_get_display (screen); + xdisplay = gdk_x11_display_get_xdisplay (display); + + /* Now see if there's a manager window around */ + g_snprintf (buffer, sizeof (buffer), + "_NET_SYSTEM_TRAY_S%d", + gdk_screen_get_number (screen)); + + icon->selection_atom = XInternAtom (xdisplay, buffer, False); + + icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False); + + icon->system_tray_opcode_atom = XInternAtom (xdisplay, + "_NET_SYSTEM_TRAY_OPCODE", + False); + + icon->orientation_atom = XInternAtom (xdisplay, + "_NET_SYSTEM_TRAY_ORIENTATION", + False); + + egg_tray_icon_update_manager_window (icon, FALSE); + egg_tray_icon_send_dock_request (icon); + + root_window = gdk_screen_get_root_window (screen); + + /* Add a root window filter so that we get changes on MANAGER */ + gdk_window_add_filter (root_window, + egg_tray_icon_manager_filter, icon); +#endif +} + +static void +egg_tray_icon_add (GtkContainer *container, GtkWidget *widget) +{ + g_signal_connect (widget, "realize", + G_CALLBACK (make_transparent), NULL); + GTK_CONTAINER_CLASS (parent_class)->add (container, widget); +} + +EggTrayIcon * +egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name) +{ + g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + + return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, NULL); +} + +EggTrayIcon* +egg_tray_icon_new (const gchar *name) +{ + return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL); +} + +guint +egg_tray_icon_send_message (EggTrayIcon *icon, + gint timeout, + const gchar *message, + gint len) +{ + guint stamp; + + g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0); + g_return_val_if_fail (timeout >= 0, 0); + g_return_val_if_fail (message != NULL, 0); + +#ifdef GDK_WINDOWING_X11 + if (icon->manager_window == None) + return 0; +#endif + + if (len < 0) + len = strlen (message); + + stamp = icon->stamp++; + +#ifdef GDK_WINDOWING_X11 + /* Get ready to send the message */ + egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE, + icon->manager_window, + timeout, len, stamp); + + /* Now to send the actual message */ + gdk_error_trap_push (); + while (len > 0) + { + XClientMessageEvent ev; + Display *xdisplay; + + xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); + + ev.type = ClientMessage; + ev.window = icon->manager_window; + ev.format = 8; + ev.message_type = XInternAtom (xdisplay, + "_NET_SYSTEM_TRAY_MESSAGE_DATA", False); + if (len > 20) + { + memcpy (&ev.data, message, 20); + len -= 20; + message += 20; + } + else + { + memcpy (&ev.data, message, len); + len = 0; + } + + XSendEvent (xdisplay, + icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev); + XSync (xdisplay, False); + } + gdk_error_trap_pop (); +#endif + + return stamp; +} + +void +egg_tray_icon_cancel_message (EggTrayIcon *icon, + guint id) +{ + g_return_if_fail (EGG_IS_TRAY_ICON (icon)); + g_return_if_fail (id > 0); +#ifdef GDK_WINDOWING_X11 + egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE, + (Window)gtk_plug_get_id (GTK_PLUG (icon)), + id, 0, 0); +#endif +} + +GtkOrientation +egg_tray_icon_get_orientation (EggTrayIcon *icon) +{ + g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL); + + return icon->orientation; +} diff --git a/pandora_applet/src/eggtrayicon.h b/pandora_applet/src/eggtrayicon.h new file mode 100644 index 0000000000..e6664fcb08 --- /dev/null +++ b/pandora_applet/src/eggtrayicon.h @@ -0,0 +1,80 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* eggtrayicon.h + * Copyright (C) 2002 Anders Carlsson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __EGG_TRAY_ICON_H__ +#define __EGG_TRAY_ICON_H__ + +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +G_BEGIN_DECLS + +#define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ()) +#define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon)) +#define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) +#define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON)) +#define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON)) +#define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) + +typedef struct _EggTrayIcon EggTrayIcon; +typedef struct _EggTrayIconClass EggTrayIconClass; + +struct _EggTrayIcon +{ + GtkPlug parent_instance; + + guint stamp; + +#ifdef GDK_WINDOWING_X11 + Atom selection_atom; + Atom manager_atom; + Atom system_tray_opcode_atom; + Atom orientation_atom; + Window manager_window; +#endif + GtkOrientation orientation; +}; + +struct _EggTrayIconClass +{ + GtkPlugClass parent_class; +}; + +GType egg_tray_icon_get_type (void); + +EggTrayIcon *egg_tray_icon_new_for_screen (GdkScreen *screen, + const gchar *name); + +EggTrayIcon *egg_tray_icon_new (const gchar *name); + +guint egg_tray_icon_send_message (EggTrayIcon *icon, + gint timeout, + const char *message, + gint len); +void egg_tray_icon_cancel_message (EggTrayIcon *icon, + guint id); + +GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon *icon); + +G_END_DECLS + +#endif /* __EGG_TRAY_ICON_H__ */ diff --git a/pandora_applet/src/main.c b/pandora_applet/src/main.c new file mode 100644 index 0000000000..aaf21cf613 --- /dev/null +++ b/pandora_applet/src/main.c @@ -0,0 +1,64 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "pandora-applet.h" + +#include +#include + +void +exit_app () +{ + gtk_main_quit (); +} + +int +main (int argc, char *argv[]) +{ + PandoraApplet *applet; + + gtk_init (&argc, &argv); + + g_set_application_name (_("Pandora applet")); + + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + /* Init threads */ + if (!g_thread_supported ()) { + g_thread_init (NULL); + } + + applet = pandora_applet_new (); + + if (!applet) { + return 1; + } + + gtk_main (); + + return 0; +} diff --git a/pandora_applet/src/pandora-applet.c b/pandora_applet/src/pandora-applet.c new file mode 100644 index 0000000000..6c71bafe70 --- /dev/null +++ b/pandora_applet/src/pandora-applet.c @@ -0,0 +1,513 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + Based on NetworkManager Wireless Applet + GNOME Wireless Applet Authors: + * Eskil Heyn Olsen + * Bastien Nocera (Gnome2 port) + + 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. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "pandora-applet.h" +#include "pandora-info-window.h" +#include "pandora-status-checker.h" +#include "pandora-status.h" +#include "pandora-setup-dialog.h" +#include "pandora-setup.h" + +struct _PandoraAppletPrivate { + GtkImage *image; + GdkPixbuf *icon_good; + GdkPixbuf *icon_bad; + GdkPixbuf *icon_unknown; + GtkWidget *event_box; + GtkWidget *context_menu; + + gchar *userdir; + gchar *userfile; + + PandoraInfoWindow *info_window; + PandoraSetupDialog *setup_dialog; + PandoraSetup *setup; + PandoraStatusChecker *checker; + PandoraStatus *status; +}; + +#define PANDORA_APPLET_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_TYPE_APPLET, PandoraAppletPrivate)) + +static gboolean pandora_applet_create_setup_file (PandoraApplet *applet); +static void pandora_applet_create_user_dir (PandoraApplet *applet); +static void pandora_applet_set_image_from_pixbuf (PandoraApplet *applet, + GdkPixbuf *icon); +static void pandora_applet_set_image_from_stock (PandoraApplet *applet, + gchar *stock_id); +static gboolean pandora_applet_toplevel_menu_button_press_cb (GtkWidget *widget, + GdkEventButton *event, + gpointer data); +static void pandora_applet_changed_status_cb (GObject *object, + gpointer *data); +static GtkWidget *pandora_applet_context_menu_create (PandoraApplet *applet); + +static GObject *pandora_applet_constructor (GType type, guint n_props, + GObjectConstructParam *props); +static GtkWidget *pandora_applet_get_instance (PandoraApplet *applet); +static void pandora_applet_destroy (PandoraApplet *applet); +static GType pandora_applet_get_type (void); /* for G_DEFINE_TYPE */ + +G_DEFINE_TYPE (PandoraApplet, pandora_applet, EGG_TYPE_TRAY_ICON) + +static void +pandora_applet_init (PandoraApplet *applet) +{ + applet->priv = PANDORA_APPLET_GET_PRIVATE (applet); + + applet->priv->icon_good = load_icon_from_disk ("pandora-applet-good.png"); + applet->priv->icon_bad = load_icon_from_disk ("pandora-applet-bad.png"); + applet->priv->icon_unknown = load_icon_from_disk ("pandora-applet-unknown.png"); + + applet->priv->userdir = g_build_filename (g_get_home_dir (), ".pandora", NULL); + applet->priv->userfile = g_build_filename (applet->priv->userdir, "config.xml", + NULL); + pandora_applet_create_user_dir (applet); + + g_signal_connect (applet, "destroy", G_CALLBACK (pandora_applet_destroy), NULL); + + /* Event box is the main applet widget */ + applet->priv->event_box = gtk_event_box_new (); + gtk_container_set_border_width (GTK_CONTAINER (applet->priv->event_box), + 0); + + applet->priv->image = GTK_IMAGE (gtk_image_new ()); + gtk_container_add (GTK_CONTAINER (applet->priv->event_box), + GTK_WIDGET (applet->priv->image)); + gtk_container_add (GTK_CONTAINER (applet), applet->priv->event_box); + + g_signal_connect (applet->priv->event_box, "button_press_event", + G_CALLBACK (pandora_applet_toplevel_menu_button_press_cb), + applet); + + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_unknown); + + applet->priv->context_menu = pandora_applet_context_menu_create (applet); + + /* Init setup */ + applet->priv->setup = pandora_setup_new (applet->priv->userfile); + + /* Init windows and dialogs */ + applet->priv->info_window = PANDORA_INFO_WINDOW (pandora_info_window_new ()); + + applet->priv->setup_dialog = PANDORA_SETUP_DIALOG (pandora_setup_dialog_new ()); + pandora_setup_dialog_set_setup (applet->priv->setup_dialog, + applet->priv->setup); + + /* Init status and checker */ + applet->priv->status = PANDORA_STATUS (pandora_status_new ()); + + pandora_info_window_set_status (applet->priv->info_window, + applet->priv->status); + + applet->priv->checker = pandora_status_checker_new (applet->priv->setup, + applet->priv->status); + + gtk_widget_show_all (GTK_WIDGET (applet)); + + g_signal_connect (G_OBJECT (applet->priv->status), "changed", + G_CALLBACK (pandora_applet_changed_status_cb), + (gpointer) applet); + + pandora_status_checker_run (applet->priv->checker); +} + +static void +pandora_applet_class_init (PandoraAppletClass *klass) +{ + GObjectClass *object_class; + + g_type_class_add_private (klass, sizeof (PandoraAppletPrivate)); + + object_class = G_OBJECT_CLASS (klass); + object_class->constructor = pandora_applet_constructor; +} + +static GObject * +pandora_applet_constructor (GType type, guint n_props, + GObjectConstructParam *props) +{ + GObject *obj; + PandoraApplet *applet; + PandoraAppletClass *klass; + + klass = PANDORA_APPLET_CLASS (g_type_class_peek (type)); + obj = G_OBJECT_CLASS (pandora_applet_parent_class)->constructor (type, + n_props, + props); + applet = PANDORA_APPLET (obj); + + return obj; +} + +static GtkWidget * +pandora_applet_get_instance (PandoraApplet *applet) +{ + gtk_widget_hide (GTK_WIDGET (applet)); + + + return GTK_WIDGET (applet); +} + +static void +pandora_applet_destroy (PandoraApplet *applet) +{ + pandora_status_checker_stop (applet->priv->checker); + + gtk_widget_destroy (GTK_WIDGET (applet->priv->info_window)); + gtk_widget_destroy (GTK_WIDGET (applet->priv->setup_dialog)); + + exit_app (); +} + +PandoraApplet * +pandora_applet_new () +{ + return g_object_new (PANDORA_TYPE_APPLET, "title", "Pandora", NULL); +} + +static void +pandora_applet_quit_cb (GtkMenuItem *mi, PandoraApplet *applet) +{ + gtk_widget_destroy (GTK_WIDGET (applet)); +} + +static void +pandora_applet_about_cb (GtkMenuItem *mi, PandoraApplet *applet) +{ + GdkPixbuf *pixbuf; + gchar *pixbuf_path; + static const gchar *authors[] = + { + "Artica Soluciones Tecnológicas:\n", + "Esteban Sánchez ", + NULL + }; + static const gchar *artists[] = + { + "Esteban Sánchez " + "Icons from Tango Desktop Project ", + NULL + }; + + + + pixbuf_path = g_build_filename (PIXMAPS_DIR, "pandora.png", NULL); + pixbuf = gdk_pixbuf_new_from_file (pixbuf_path, NULL); + g_free (pixbuf_path); + + gtk_show_about_dialog (NULL, + "name", _("Pandora Enterprise monitor applet"), + "version", VERSION, + "copyright", _("Copyright \xc2\xa9 2006 Artica ST.\n"), + "comments", _("Notification area applet for monitoring your Pandora system."), + "website", "http://pandora.sourceforge.net/", + "authors", authors, + "artists", artists, + "translator-credits", _("translator-credits"), + "logo", pixbuf, + NULL); + + if (pixbuf) { + g_object_unref (pixbuf); + } + +} + +static void +pandora_applet_show_info_cb (GtkMenuItem *mi, PandoraApplet *applet) +{ + gtk_window_present (GTK_WINDOW (applet->priv->info_window)); +} + +static void +pandora_applet_show_setup_cb (GtkMenuItem *mi, PandoraApplet *applet) +{ + gint result; + + gtk_widget_show_all (GTK_WIDGET (applet->priv->setup_dialog)); + + result = gtk_dialog_run (GTK_DIALOG (applet->priv->setup_dialog)); + + switch (result) { + case GTK_RESPONSE_ACCEPT: + pandora_setup_dialog_apply_changes (applet->priv->setup_dialog); + pandora_setup_save_to_disk (applet->priv->setup); + break; + default: + break; + } + + gtk_widget_hide (GTK_WIDGET (applet->priv->setup_dialog)); +} + +static void +pandora_applet_changed_status_cb (GObject *object, + gpointer *data) +{ + PandoraApplet *applet = PANDORA_APPLET (data); + + switch (pandora_status_get_alerts (PANDORA_STATUS (object))) { + case STATE_BAD: + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_bad); + return; + break; + case STATE_OK: + break; + default: + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_unknown); + return; + } + + switch (pandora_status_get_servers (PANDORA_STATUS (object))) { + case STATE_BAD: + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_bad); + return; + break; + case STATE_OK: + break; + default: + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_unknown); + return; + } + + switch (pandora_status_get_agents (PANDORA_STATUS (object))) { + case STATE_BAD: + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_bad); + return; + break; + case STATE_OK: + break; + default: + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_unknown); + return; + } + + pandora_applet_set_image_from_pixbuf (applet, applet->priv->icon_good); +} + +static GtkWidget * +pandora_applet_context_menu_create (PandoraApplet *applet) +{ + GtkWidget *menu; + GtkWidget *menu_item; + GtkWidget *image; + + g_return_val_if_fail (applet != NULL, NULL); + + menu = gtk_menu_new (); + + /* Show status item */ + menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Show main window")); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (pandora_applet_show_info_cb), applet); + image = gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), + image); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + + /* Preferences item */ + menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Preferences")); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (pandora_applet_show_setup_cb), applet); + image = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), + image); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + + /* Separator */ + menu_item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + gtk_widget_show (menu_item); + + /* About item */ + menu_item = gtk_image_menu_item_new_with_mnemonic (_("_About")); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (pandora_applet_about_cb), applet); + image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + + /* Quit item */ + menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Quit")); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (pandora_applet_quit_cb), applet); + image = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + + gtk_widget_show_all (menu); + + return menu; +} + +static void +pandora_applet_menu_position_func (GtkMenu *menu G_GNUC_UNUSED, + int *x, int *y, gboolean *push_in, + gpointer user_data) +{ + int screen_w, screen_h, button_x, button_y, panel_w, panel_h; + GtkRequisition requisition; + GdkScreen *screen; + PandoraApplet *applet = (PandoraApplet *)user_data; + + screen = gtk_widget_get_screen (applet->priv->event_box); + screen_w = gdk_screen_get_width (screen); + screen_h = gdk_screen_get_height (screen); + + gdk_window_get_origin (applet->priv->event_box->window, &button_x, &button_y); + gtk_window_get_size (GTK_WINDOW (gtk_widget_get_toplevel (applet->priv->event_box)), + &panel_w, &panel_h); + + *x = button_x; + + /* Check to see if we would be placing the menu off of the end of the screen. */ + gtk_widget_size_request (GTK_WIDGET (menu), &requisition); + if (button_y + panel_h + requisition.height >= screen_h) + *y = button_y - requisition.height; + else + *y = button_y + panel_h; + + *push_in = TRUE; +} + +static gboolean +pandora_applet_toplevel_menu_button_press_cb (GtkWidget *widget, + GdkEventButton *event, + gpointer data) +{ + + PandoraApplet *applet; + + applet = PANDORA_APPLET (data); + + g_return_val_if_fail (applet != NULL, FALSE); + g_return_val_if_fail (PANDORA_IS_APPLET (applet), FALSE); + + switch (event->button) { + case 3: + gtk_menu_popup (GTK_MENU (applet->priv->context_menu), + NULL, NULL, + pandora_applet_menu_position_func, + applet, event->button, event->time); + return TRUE; + default: + g_signal_stop_emission_by_name (widget, "button_press_event"); + return FALSE; + } + + return FALSE; +} + +static void +pandora_applet_setup_widgets (PandoraApplet *applet) +{ +} + +static void +pandora_applet_set_image_from_stock (PandoraApplet *applet, + gchar *stock_id) +{ + gtk_image_set_from_stock (GTK_IMAGE (applet->priv->image), + stock_id, GTK_ICON_SIZE_MENU); +} + +static void +pandora_applet_set_image_from_pixbuf (PandoraApplet *applet, GdkPixbuf *icon) +{ + g_return_if_fail (PANDORA_IS_APPLET (applet)); + g_return_if_fail (icon != NULL); + + gtk_image_set_from_pixbuf (GTK_IMAGE (applet->priv->image), icon); +} + +GdkPixbuf * +load_icon_from_disk (gchar *icon_name) +{ + GError *err = NULL; + gchar *icon_path; + GdkPixbuf *pixbuf; + + icon_path = g_build_filename (PIXMAPS_DIR, icon_name, NULL); + pixbuf = gdk_pixbuf_new_from_file (icon_path, &err); + g_free (icon_path); + + if (pixbuf == NULL) { + g_warning ("Icon %s missing: %s", icon_name, err->message); + g_error_free (err); + return NULL; + } + + return pixbuf; +} + +static gboolean +pandora_applet_create_setup_file (PandoraApplet *applet) +{ + const gchar *contents = "\n\n\n"; + +#if GTK_CHECK_VERSION(2,8,0) + return g_file_set_contents (applet->priv->userfile, contents, -1, NULL); +#else + gint fd; + + if ((fd = open (applet->priv->userfile, O_CREAT | O_WRONLY, 0644)) < 0) { + return FALSE; + } + + if (write (fd, contents, strlen (contents)) < 0) { + close (fd); + return FALSE; + } + + if (close (fd) < 0) { + return FALSE; + } + + return TRUE; +#endif +} + +static void +pandora_applet_create_user_dir (PandoraApplet *applet) +{ + if (!g_file_test (applet->priv->userdir, G_FILE_TEST_IS_DIR)) { + if (g_mkdir (applet->priv->userdir, 0755) != 0) { + g_error ("Cannot create user's directory"); + } + } + + if (!g_file_test (applet->priv->userfile, G_FILE_TEST_IS_REGULAR)) { + if (!pandora_applet_create_setup_file (applet)) { + g_error ("Cannot create user's configuration file"); + } + } +} diff --git a/pandora_applet/src/pandora-applet.h b/pandora_applet/src/pandora-applet.h new file mode 100644 index 0000000000..0732373951 --- /dev/null +++ b/pandora_applet/src/pandora-applet.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifndef APPLET_H +#define APPLET_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include "eggtrayicon.h" + +#define PANDORA_TYPE_APPLET (pandora_applet_get_type()) +#define PANDORA_APPLET(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PANDORA_TYPE_APPLET, PandoraApplet)) +#define PANDORA_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_TYPE_APPLET, PandoraAppletClass)) +#define PANDORA_IS_APPLET(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), PANDORA_TYPE_APPLET)) +#define PANDORA_IS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PANDORA_TYPE_APPLET)) +#define PANDORA_APPLET_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANDORA_TYPE_APPLET, PandoraAppletClass)) + +typedef struct _PandoraAppletPrivate PandoraAppletPrivate; + +typedef struct { + EggTrayIconClass parent_class; +} PandoraAppletClass; + +/* + * Applet instance data + * + */ +typedef struct { + EggTrayIcon parent; + PandoraAppletPrivate *priv; +} PandoraApplet; + +PandoraApplet *pandora_applet_new (void); + +GdkPixbuf *load_icon_from_disk (gchar *icon_name); + +#endif diff --git a/pandora_applet/src/pandora-info-window.c b/pandora_applet/src/pandora-info-window.c new file mode 100644 index 0000000000..d5165d7e30 --- /dev/null +++ b/pandora_applet/src/pandora-info-window.c @@ -0,0 +1,414 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "pandora-applet.h" +#include "pandora-info-window.h" + +struct _PandoraInfoWindowPrivate { + GtkWidget *label_alerts; + GtkWidget *label_servers; + GtkWidget *label_agents; + + GtkImage *image_alerts; + GtkImage *image_servers; + GtkImage *image_agents; + + GdkPixbuf *pixbuf_alerts_ok; + GdkPixbuf *pixbuf_alerts_bad; + GdkPixbuf *pixbuf_alerts_unknown; + + GdkPixbuf *pixbuf_servers_ok; + GdkPixbuf *pixbuf_servers_bad; + GdkPixbuf *pixbuf_servers_unknown; + + GdkPixbuf *pixbuf_agents_ok; + GdkPixbuf *pixbuf_agents_bad; + GdkPixbuf *pixbuf_agents_unknown; + + PandoraState state_alerts; + PandoraState state_servers; + PandoraState state_agents; + + PandoraStatus *status; +}; + +#define PANDORA_INFO_WINDOW_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_INFO_WINDOW_TYPE, \ + PandoraInfoWindowPrivate)) + +static void pandora_info_window_init (PandoraInfoWindow *window); +static void pandora_info_window_class_init (PandoraInfoWindowClass *klass); +static void pandora_info_window_finalize (GObject *object); + +static gboolean pandora_info_window_delete_cb (GtkWidget *dialog, + GdkEvent *event, + gpointer data); + +static gboolean pandora_info_window_close_cb (GtkWidget *widget, + gpointer data); + +static void pandora_info_window_status_changed_cb (GObject *object, + gpointer data); + +static void pandora_info_window_status_update (PandoraInfoWindow *window); + +static void pandora_info_window_status_update_alerts (PandoraInfoWindow *window, + PandoraState state); +static void pandora_info_window_status_update_agents (PandoraInfoWindow *window, + PandoraState state); +static void pandora_info_window_status_update_servers (PandoraInfoWindow *window, + PandoraState state); + +GType +pandora_info_window_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (PandoraInfoWindowClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pandora_info_window_class_init, + NULL, + NULL, + sizeof (PandoraInfoWindow), + 0, + (GInstanceInitFunc) pandora_info_window_init + }; + + type = g_type_register_static (GTK_TYPE_WINDOW, "PandoraInfoWindow", + &info, 0); + } + + return type; +} + +static void +pandora_info_window_init (PandoraInfoWindow *window) +{ + GtkWidget *table; + GtkWidget *image; + GtkWidget *hbutton_box; + GtkWidget *button_close; + + window->priv = PANDORA_INFO_WINDOW_GET_PRIVATE (window); + + window->priv->status = NULL; + window->priv->state_alerts = STATE_INVALID; + window->priv->state_servers = STATE_INVALID; + window->priv->state_agents = STATE_INVALID; + + window->priv->pixbuf_alerts_ok = load_icon_from_disk ("pandora-alerts-ok.png"); + window->priv->pixbuf_alerts_bad = load_icon_from_disk ("pandora-alerts-bad.png"); + window->priv->pixbuf_alerts_unknown = load_icon_from_disk ("pandora-alerts-unknown.png"); + window->priv->image_alerts = GTK_IMAGE (gtk_image_new ()); + + window->priv->pixbuf_servers_ok = load_icon_from_disk ("pandora-servers-ok.png"); + window->priv->pixbuf_servers_bad = load_icon_from_disk ("pandora-servers-bad.png"); + window->priv->pixbuf_servers_unknown = load_icon_from_disk ("pandora-servers-unknown.png"); + window->priv->image_servers = GTK_IMAGE (gtk_image_new ()); + + window->priv->pixbuf_agents_ok = load_icon_from_disk ("pandora-agents-ok.png"); + window->priv->pixbuf_agents_bad = load_icon_from_disk ("pandora-agents-bad.png"); + window->priv->pixbuf_agents_unknown = load_icon_from_disk ("pandora-agents-unknown.png"); + window->priv->image_agents = GTK_IMAGE (gtk_image_new ()); + + gtk_window_set_title (GTK_WINDOW (window), _("Pandora status")); + gtk_container_set_border_width (GTK_CONTAINER (window), 5); + gtk_window_set_icon_name (GTK_WINDOW (window), + GTK_STOCK_INFO); + + table = gtk_table_new (4, 2, FALSE); + gtk_table_set_row_spacings (GTK_TABLE (table), 5); + gtk_table_set_col_spacings (GTK_TABLE (table), 5); + + /* First row */ + window->priv->label_alerts = gtk_label_new (_("Alerts status.")); + gtk_misc_set_alignment (GTK_MISC (window->priv->label_alerts), 0, 0.5); + + gtk_image_set_from_pixbuf (window->priv->image_alerts, + window->priv->pixbuf_alerts_unknown); + + gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (window->priv->image_alerts), + 0, 1, 0, 1, GTK_FILL , GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), window->priv->label_alerts, + 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + + /* Third row */ + window->priv->label_agents = gtk_label_new (_("Agents status.")); + gtk_misc_set_alignment (GTK_MISC (window->priv->label_agents), 0, 0.5); + + gtk_image_set_from_pixbuf (window->priv->image_agents, + window->priv->pixbuf_agents_unknown); + + gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (window->priv->image_agents), + 0, 1, 1, 2, GTK_FILL , GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), window->priv->label_agents, + 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + + /* Second row */ + window->priv->label_servers = gtk_label_new (_("Servers status.")); + gtk_misc_set_alignment (GTK_MISC (window->priv->label_servers), 0, 0.5); + + gtk_image_set_from_pixbuf (window->priv->image_servers, + window->priv->pixbuf_servers_unknown); + + gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (window->priv->image_servers), + 0, 1, 2, 3, GTK_FILL , GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), window->priv->label_servers, + 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + + /* Buttons at the bottom */ + hbutton_box = gtk_hbutton_box_new (); + gtk_button_box_set_layout (GTK_BUTTON_BOX (hbutton_box), + GTK_BUTTONBOX_END); + + button_close = gtk_button_new_from_stock (GTK_STOCK_CLOSE); + g_signal_connect (G_OBJECT (button_close), "clicked", + G_CALLBACK (pandora_info_window_close_cb), + (gpointer) window); + + gtk_box_pack_start (GTK_BOX (hbutton_box), button_close, + FALSE, TRUE, 5); + + gtk_table_attach (GTK_TABLE (table), hbutton_box, + 0, 2, 3, 4, GTK_FILL, 0, 0, 0); + + gtk_widget_show_all (table); + + gtk_container_add (GTK_CONTAINER (window), table); + + g_signal_connect (G_OBJECT (window), "delete-event", + G_CALLBACK (pandora_info_window_delete_cb), NULL); +} + + +static void +pandora_info_window_class_init (PandoraInfoWindowClass *klass) +{ + GObjectClass *object_class; + + g_type_class_add_private (klass, sizeof (PandoraInfoWindowPrivate)); + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = pandora_info_window_finalize; +} + +static void +pandora_info_window_finalize (GObject *object) +{ + PandoraInfoWindow *window = PANDORA_INFO_WINDOW (object); + + if (window->priv->status) { + g_object_unref (window->priv->status); + window->priv->status = NULL; + } + + if (window->priv->pixbuf_alerts_ok) { + g_object_unref (window->priv->pixbuf_alerts_ok); + window->priv->pixbuf_alerts_ok = NULL; + } + + if (window->priv->pixbuf_servers_ok) { + g_object_unref (window->priv->pixbuf_servers_ok); + window->priv->pixbuf_servers_ok = NULL; + } + + if (window->priv->pixbuf_agents_ok) { + g_object_unref (window->priv->pixbuf_agents_ok); + window->priv->pixbuf_agents_ok = NULL; + } +} + +GtkWidget * +pandora_info_window_new (void) +{ + GtkWidget *window; + + window = GTK_WIDGET (g_object_new (PANDORA_INFO_WINDOW_TYPE, + "type", GTK_WINDOW_TOPLEVEL, + "default-width", 300, + "resizable", FALSE, + NULL)); + + gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER); + + return window; +} + +static gboolean +pandora_info_window_close_cb (GtkWidget *widget, gpointer data) +{ + GtkWidget *window; + + if (data != NULL) { + window = GTK_WIDGET (data); + gtk_widget_hide (window); + } + + return TRUE; +} + +static gboolean +pandora_info_window_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer data) +{ + gtk_widget_hide (widget); + + return TRUE; +} + +void +pandora_info_window_set_status (PandoraInfoWindow *window, + PandoraStatus *status) +{ + if (window->priv->status) { + g_object_unref (window->priv->status); + } + + window->priv->status = status; + + g_signal_connect (status, "changed", + G_CALLBACK (pandora_info_window_status_changed_cb), + (gpointer) window); + + pandora_info_window_status_update (window); +} + +static void +pandora_info_window_status_update_alerts (PandoraInfoWindow *window, + PandoraState state) +{ + switch (state) { + case STATE_BAD: + gtk_image_set_from_pixbuf (window->priv->image_alerts, + window->priv->pixbuf_alerts_bad); + gtk_label_set_text (GTK_LABEL (window->priv->label_alerts), + _("There are agents with alerts.")); + + break; + case STATE_OK: + gtk_image_set_from_pixbuf (window->priv->image_alerts, + window->priv->pixbuf_alerts_ok); + gtk_label_set_text (GTK_LABEL (window->priv->label_alerts), + _("There are no alerts.")); + break; + default: + gtk_image_set_from_pixbuf (window->priv->image_alerts, + window->priv->pixbuf_alerts_unknown); + gtk_label_set_text (GTK_LABEL (window->priv->label_alerts), + _("Alerts status unknown.")); + return; + } +} + +static void +pandora_info_window_status_update_agents (PandoraInfoWindow *window, + PandoraState state) +{ + switch (state) { + case STATE_BAD: + gtk_image_set_from_pixbuf (window->priv->image_agents, + window->priv->pixbuf_agents_bad); + gtk_label_set_text (GTK_LABEL (window->priv->label_agents), + _("There are agents down.")); + + break; + case STATE_OK: + gtk_image_set_from_pixbuf (window->priv->image_agents, + window->priv->pixbuf_agents_ok); + gtk_label_set_text (GTK_LABEL (window->priv->label_agents), + _("All the agents are running.")); + break; + default: + gtk_image_set_from_pixbuf (window->priv->image_agents, + window->priv->pixbuf_agents_unknown); + gtk_label_set_text (GTK_LABEL (window->priv->label_agents), + _("Agents status unknown.")); + return; + } +} + +static void +pandora_info_window_status_update_servers (PandoraInfoWindow *window, + PandoraState state) +{ + switch (state) { + case STATE_BAD: + gtk_image_set_from_pixbuf (window->priv->image_servers, + window->priv->pixbuf_servers_bad); + gtk_label_set_text (GTK_LABEL (window->priv->label_servers), + _("There are servers down.")); + + break; + case STATE_OK: + gtk_image_set_from_pixbuf (window->priv->image_servers, + window->priv->pixbuf_servers_ok); + gtk_label_set_text (GTK_LABEL (window->priv->label_servers), + _("All the servers are running.")); + break; + default: + gtk_image_set_from_pixbuf (window->priv->image_servers, + window->priv->pixbuf_servers_unknown); + gtk_label_set_text (GTK_LABEL (window->priv->label_servers), + _("Servers status unknown.")); + return; + } +} + +static void +pandora_info_window_status_update (PandoraInfoWindow *window) +{ + PandoraStatus *status; + PandoraState state; + + status = window->priv->status; + + if (status == NULL) { + pandora_info_window_status_update_alerts (window, TRUE); + pandora_info_window_status_update_agents (window, TRUE); + pandora_info_window_status_update_servers (window, TRUE); + } else { + state = pandora_status_get_alerts (status); + pandora_info_window_status_update_alerts (window, state); + + state = pandora_status_get_agents (status); + pandora_info_window_status_update_agents (window, state); + + state = pandora_status_get_servers (status); + pandora_info_window_status_update_servers (window, state); + } +} + +static void +pandora_info_window_status_changed_cb (GObject *object, + gpointer data) +{ + PandoraInfoWindow *window = PANDORA_INFO_WINDOW (data); + + pandora_info_window_status_update (window); +} diff --git a/pandora_applet/src/pandora-info-window.h b/pandora_applet/src/pandora-info-window.h new file mode 100644 index 0000000000..a47d0ccf2a --- /dev/null +++ b/pandora_applet/src/pandora-info-window.h @@ -0,0 +1,53 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifndef INFO_WINDOW_H +#define INFO_WINDOW_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "pandora-status.h" + +#include + +#define PANDORA_INFO_WINDOW_TYPE (pandora_info_window_get_type()) +#define PANDORA_INFO_WINDOW(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PANDORA_INFO_WINDOW_TYPE, PandoraInfoWindow)) +#define PANDORA_INFO_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_INFO_WINDOW_TYPE, PandoraInfoWindowClass)) +#define PANDORA_IS_INFO_WINDOW(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), PANDORA_INFO_WINDOW_TYPE)) +#define PANDORA_IS_INFO_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PANDORA_INFO_WINDOW_TYPE)) +#define PANDORA_INFO_WINDOW_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANDORA_INFO_WINDOW_TYPE, PandoraInfoWindowClass)) + +typedef struct _PandoraInfoWindowPrivate PandoraInfoWindowPrivate; + +typedef struct { + GtkWindowClass parent_class; +} PandoraInfoWindowClass; + +typedef struct { + GtkWindow parent; + PandoraInfoWindowPrivate *priv; +} PandoraInfoWindow; + +GtkWidget *pandora_info_window_new (void); +void pandora_info_window_set_status (PandoraInfoWindow *window, + PandoraStatus *status); + +#endif diff --git a/pandora_applet/src/pandora-setup-dialog.c b/pandora_applet/src/pandora-setup-dialog.c new file mode 100644 index 0000000000..3582b78cca --- /dev/null +++ b/pandora_applet/src/pandora-setup-dialog.c @@ -0,0 +1,291 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "pandora-setup-dialog.h" + +struct _PandoraSetupDialogPrivate { + GtkWidget *entry_host; + GtkWidget *entry_username; + GtkWidget *entry_password; + gchar *real_password; + GtkWidget *entry_dbname; + + PandoraSetup *setup; +}; + +#define PANDORA_SETUP_DIALOG_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_SETUP_DIALOG_TYPE, \ + PandoraSetupDialogPrivate)) + +static void pandora_setup_dialog_init (PandoraSetupDialog *dialog); +static void pandora_setup_dialog_class_init (PandoraSetupDialogClass *klass); +static void pandora_setup_dialog_finalize (GObject *object); + +static gboolean pandora_setup_close_cb (GtkWidget *dialog, gpointer data); + +GType +pandora_setup_dialog_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (PandoraSetupDialogClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pandora_setup_dialog_class_init, + NULL, + NULL, + sizeof (PandoraSetupDialog), + 0, + (GInstanceInitFunc) pandora_setup_dialog_init + }; + + type = g_type_register_static (GTK_TYPE_DIALOG, "PandoraSetupDialog", + &info, 0); + } + + return type; +} + +static void +pandora_setup_dialog_init (PandoraSetupDialog *dialog) +{ + GtkWidget *table; + GtkWidget *hbutton_box; + GtkWidget *button_close; + GtkWidget *frame; + GtkWidget *label_title; + GtkWidget *label; + GtkWidget *alignment; + gchar *str; + + dialog->priv = PANDORA_SETUP_DIALOG_GET_PRIVATE (dialog); + dialog->priv->setup = NULL; + + + gtk_window_set_title (GTK_WINDOW (dialog), _("Preferences")); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 12); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), + GTK_RESPONSE_CANCEL); + + gtk_window_set_icon_name (GTK_WINDOW (dialog), + GTK_STOCK_PREFERENCES); + /* Frame */ + str = g_strdup_printf ("%s:", _("Database connection")); + label_title = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label_title), str); + gtk_misc_set_alignment (GTK_MISC (label_title), 0, 0.5); + + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label_title); + gtk_container_set_border_width (GTK_CONTAINER (frame), 5); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + + /* Table inside frame */ + table = gtk_table_new (4, 2, FALSE); + gtk_table_set_row_spacings (GTK_TABLE (table), 5); + gtk_table_set_col_spacings (GTK_TABLE (table), 5); + + /* First row */ + label = gtk_label_new (_("Host")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + + dialog->priv->entry_host = gtk_entry_new (); + + gtk_table_attach (GTK_TABLE (table), label, + 0, 1, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), dialog->priv->entry_host, + 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + + /* Second row */ + label = gtk_label_new (_("Username")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + + dialog->priv->entry_username = gtk_entry_new (); + + gtk_table_attach (GTK_TABLE (table), label, + 0, 1, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), dialog->priv->entry_username, + 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + + /* Third row */ + label = gtk_label_new (_("Password")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + + dialog->priv->entry_password = gtk_entry_new (); + gtk_entry_set_invisible_char (GTK_ENTRY (dialog->priv->entry_password), + '*'); + gtk_entry_set_visibility (GTK_ENTRY (dialog->priv->entry_password), + FALSE); + + gtk_table_attach (GTK_TABLE (table), label, + 0, 1, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), dialog->priv->entry_password, + 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + + /* Fourth row */ + label = gtk_label_new (_("Database name")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + + dialog->priv->entry_dbname = gtk_entry_new (); + + gtk_table_attach (GTK_TABLE (table), label, + 0, 1, 3, 4, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + gtk_table_attach (GTK_TABLE (table), dialog->priv->entry_dbname, + 1, 2, 3, 4, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + + alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (alignment), table); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + gtk_widget_show_all (frame); + + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame, FALSE, FALSE, 0); +} + + +static void +pandora_setup_dialog_class_init (PandoraSetupDialogClass *klass) +{ + GObjectClass *object_class; + + g_type_class_add_private (klass, sizeof (PandoraSetupDialogPrivate)); + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = pandora_setup_dialog_finalize; +} + +static void +pandora_setup_dialog_finalize (GObject *object) +{ + PandoraSetupDialog *dialog; + + dialog = PANDORA_SETUP_DIALOG (object); + + if (dialog->priv->setup) { + g_object_unref (dialog->priv->setup); + } +} + +GtkWidget * +pandora_setup_dialog_new (void) +{ + GtkWidget *dialog; + + dialog = GTK_WIDGET (g_object_new (PANDORA_SETUP_DIALOG_TYPE, + NULL)); + return dialog; +} + +void +pandora_setup_dialog_set_setup (PandoraSetupDialog *dialog, + PandoraSetup *setup) +{ + gchar *value; + + if (dialog->priv->setup) { + g_object_unref (dialog->priv->setup); + } + + dialog->priv->setup = setup; + g_object_ref (G_OBJECT (setup)); + + value = pandora_setup_get_host (setup); + if (value) { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_host), + value); + g_free (value); + value = NULL; + } else { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_host), + ""); + } + + value = pandora_setup_get_username (setup); + if (value) { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_username), + value); + g_free (value); + } else { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_username), + ""); + } + + value = pandora_setup_get_password (setup); + if (value) { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_password), + NOT_SHOWN_PASSWORD); + g_free (value); + } else { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_password), + ""); + } + + value = pandora_setup_get_dbname (setup); + if (value) { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_dbname), + value); + g_free (value); + } else { + gtk_entry_set_text (GTK_ENTRY (dialog->priv->entry_dbname), + ""); + } +} + +void +pandora_setup_dialog_apply_changes (PandoraSetupDialog *dialog) +{ + const gchar *host; + const gchar *username; + const gchar *password; + const gchar *dbname; + + host = gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry_host)); + username = gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry_username)); + password = gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry_password)); + dbname = gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry_dbname)); + + g_object_set (G_OBJECT (dialog->priv->setup), + "host", host, + "username", username, + "dbname", dbname, + NULL); + + if (g_ascii_strcasecmp (password, NOT_SHOWN_PASSWORD) != 0) { + pandora_setup_set_password (dialog->priv->setup, password); + } +} diff --git a/pandora_applet/src/pandora-setup-dialog.h b/pandora_applet/src/pandora-setup-dialog.h new file mode 100644 index 0000000000..88bb8da841 --- /dev/null +++ b/pandora_applet/src/pandora-setup-dialog.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifndef SETUP_DIALOG_H +#define SETUP_DIALOG_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "pandora-setup.h" + +#define NOT_SHOWN_PASSWORD "nonenonenone" + +#define PANDORA_SETUP_DIALOG_TYPE (pandora_setup_dialog_get_type()) +#define PANDORA_SETUP_DIALOG(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PANDORA_SETUP_DIALOG_TYPE, PandoraSetupDialog)) +#define PANDORA_SETUP_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_SETUP_DIALOG_TYPE, PandoraSetupDialogClass)) +#define PANDORA_IS_SETUP_DIALOG(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), PANDORA_SETUP_DIALOG_TYPE)) +#define PANDORA_IS_SETUP_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PANDORA_SETUP_DIALOG_TYPE)) +#define PANDORA_SETUP_DIALOG_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANDORA_SETUP_DIALOG_TYPE, PandoraSetupDialogClass)) + +typedef struct _PandoraSetupDialogPrivate PandoraSetupDialogPrivate; + +typedef struct { + GtkDialogClass parent_class; +} PandoraSetupDialogClass; + +typedef struct { + GtkDialog parent; + PandoraSetupDialogPrivate *priv; +} PandoraSetupDialog; + +GtkWidget *pandora_setup_dialog_new (void); + +void pandora_setup_dialog_set_setup (PandoraSetupDialog *dialog, + PandoraSetup *setup); +void pandora_setup_dialog_apply_changes (PandoraSetupDialog *dialog); + +#endif diff --git a/pandora_applet/src/pandora-setup.c b/pandora_applet/src/pandora-setup.c new file mode 100644 index 0000000000..f1509c2235 --- /dev/null +++ b/pandora_applet/src/pandora-setup.c @@ -0,0 +1,417 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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 "pandora-setup.h" + +#include +#include +#include + +enum { + PROP_0, + PROP_HOST, + PROP_USERNAME, + PROP_PASSWORD, + PROP_DBNAME +}; + +struct _PandoraSetupPrivate { + gchar *config_file; + + gchar *host; + gchar *username; + gchar *password; + gchar *dbname; +}; + +#define PANDORA_SETUP_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_TYPE_SETUP, \ + PandoraSetupPrivate)) + +static GObjectClass *parent_class = NULL; + +static void pandora_setup_read_config_file (PandoraSetup *setup, gchar *file); +static void pandora_setup_init (PandoraSetup *pandora_setup); +static void pandora_setup_class_init (PandoraSetupClass *klass); +static void pandora_setup_finalize (GObject *object); +static void pandora_setup_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void pandora_setup_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); + +GType +pandora_setup_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (PandoraSetupClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pandora_setup_class_init, + NULL, + NULL, + sizeof (PandoraSetup), + 0, + (GInstanceInitFunc) pandora_setup_init + }; + + type = g_type_register_static (G_TYPE_OBJECT, "PandoraSetup", + &info, 0); + } + + return type; +} + +static void +pandora_setup_init (PandoraSetup *setup) +{ + setup->priv = PANDORA_SETUP_GET_PRIVATE (setup); + + setup->priv->host = NULL; + setup->priv->username = NULL; + setup->priv->password = NULL; + setup->priv->dbname = NULL; +} + +static void +pandora_setup_class_init (PandoraSetupClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + g_type_class_add_private (klass, sizeof (PandoraSetupPrivate)); + + object_class->set_property = pandora_setup_set_property; + object_class->get_property = pandora_setup_get_property; + + g_object_class_install_property (object_class, + PROP_HOST, + g_param_spec_string ("host", + "Host", + "Host to connect to", + NULL, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_USERNAME, + g_param_spec_string ("username", + "Username", + "Username to use in the connection", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_PASSWORD, + g_param_spec_string ("password", + "Password", + "Password to use in the connection", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_DBNAME, + g_param_spec_string ("dbname", + "Database name", + "Database name to connect to", + NULL, + G_PARAM_READWRITE)); + + object_class->finalize = pandora_setup_finalize; +} + +static void +pandora_setup_finalize (GObject *object) +{ + PandoraSetup *setup = PANDORA_SETUP (object); + + /* Make persistent */ + pandora_setup_save_to_disk (setup); + + if (setup->priv->config_file) { + g_free (setup->priv->config_file); + setup->priv->config_file = NULL; + } + + if (setup->priv->host) { + g_free (setup->priv->host); + setup->priv->host = NULL; + } + + if (setup->priv->username) { + g_free (setup->priv->username); + setup->priv->username = NULL; + } + + if (setup->priv->password) { + g_free (setup->priv->password); + setup->priv->password = NULL; + } + + if (setup->priv->dbname) { + g_free (setup->priv->dbname); + setup->priv->dbname = NULL; + } + + if (G_OBJECT_CLASS (parent_class)->finalize) + (* G_OBJECT_CLASS (parent_class)->finalize) (object); +} + +static void +pandora_setup_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PandoraSetup *setup = PANDORA_SETUP (object); + GDate *date; + + switch (prop_id) { + case PROP_HOST: + g_free (setup->priv->host); + setup->priv->host = g_value_dup_string (value); + + break; + case PROP_USERNAME: + g_free (setup->priv->username); + setup->priv->username = g_value_dup_string (value); + + break; + case PROP_PASSWORD: + g_free (setup->priv->password); + setup->priv->password = g_value_dup_string (value); + + break; + case PROP_DBNAME: + g_free (setup->priv->dbname); + setup->priv->dbname = g_value_dup_string (value); + + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +pandora_setup_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PandoraSetup *setup = PANDORA_SETUP (object); + + switch (prop_id) { + case PROP_HOST: + g_value_set_string (value, setup->priv->host); + + break; + case PROP_USERNAME: + g_value_set_string (value, setup->priv->username); + + break; + case PROP_PASSWORD: + g_value_set_string (value, setup->priv->password); + + break; + case PROP_DBNAME: + g_value_set_string (value, setup->priv->dbname); + + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +gchar * +pandora_setup_get_host (PandoraSetup *setup) +{ + gchar *host = NULL; + + g_return_val_if_fail (PANDORA_IS_SETUP (setup), NULL); + + g_object_get (G_OBJECT (setup), "host", &host, NULL); + + return host; +} + +gchar * +pandora_setup_get_username (PandoraSetup *setup) +{ + gchar *username = NULL; + + g_return_val_if_fail (PANDORA_IS_SETUP (setup), NULL); + + g_object_get (G_OBJECT (setup), "username", &username, NULL); + + return username; +} + +gchar * +pandora_setup_get_password (PandoraSetup *setup) +{ + gchar *password = NULL; + + g_return_val_if_fail (PANDORA_IS_SETUP (setup), NULL); + + g_object_get (G_OBJECT (setup), "password", &password, NULL); + + return password; +} + +gchar * +pandora_setup_get_dbname (PandoraSetup *setup) +{ + gchar *dbname = NULL; + + g_return_val_if_fail (PANDORA_IS_SETUP (setup), NULL); + + g_object_get (G_OBJECT (setup), "dbname", &dbname, NULL); + + return dbname; +} + +void +pandora_setup_set_host (PandoraSetup *setup, const gchar *host) +{ + g_return_if_fail (PANDORA_IS_SETUP (setup)); + g_return_if_fail (host != NULL); + + g_object_set (G_OBJECT (setup), "host", host, NULL); +} + +void +pandora_setup_set_username (PandoraSetup *setup, const gchar *username) +{ + g_return_if_fail (PANDORA_IS_SETUP (setup)); + g_return_if_fail (username != NULL); + + g_object_set (G_OBJECT (setup), "username", username, NULL); + +} + +void +pandora_setup_set_password (PandoraSetup *setup, const gchar *password) +{ + g_return_if_fail (PANDORA_IS_SETUP (setup)); + g_return_if_fail (password != NULL); + + g_object_set (G_OBJECT (setup), "password", password, NULL); + +} + +void +pandora_setup_set_dbname (PandoraSetup *setup, const gchar *dbname) +{ + g_return_if_fail (PANDORA_IS_SETUP (setup)); + g_return_if_fail (dbname != NULL); + + g_object_set (G_OBJECT (setup), "dbname", dbname, NULL); + +} + +static void +pandora_setup_read_config_file (PandoraSetup *setup, gchar *file) +{ + xmlDocPtr doc; + xmlNodePtr root; + gchar *host; + gchar *username; + gchar *password; + gchar *dbname; + + doc = xmlParseFile (file); + + if (!doc) { + return; + } + + root = xmlDocGetRootElement (doc); + + if (!root) { + return; + } + + if (g_ascii_strcasecmp ((const gchar*) root->name, "config") == 0) { + host = (gchar *) xmlGetProp (root, (xmlChar *) "host"); + username = (gchar *) xmlGetProp (root, (xmlChar *) "username"); + password = (gchar *) xmlGetProp (root, (xmlChar *) "password"); + dbname = (gchar *) xmlGetProp (root, (xmlChar *) "dbname"); + + g_object_set (setup, + "host", host, + "username", username, + "password", password, + "dbname", dbname, + NULL); + + g_free (host); + g_free (username); + g_free (password); + g_free (dbname); + } +} + +void +pandora_setup_save_to_disk (PandoraSetup *setup) +{ + xmlTextWriterPtr writer; + + writer = xmlNewTextWriterFilename (setup->priv->config_file, 0); + + xmlTextWriterStartDocument (writer, NULL, NULL, NULL); + xmlTextWriterStartElement (writer, BAD_CAST "config"); + + xmlTextWriterWriteAttribute (writer, + BAD_CAST "host", + BAD_CAST setup->priv->host); + xmlTextWriterWriteAttribute (writer, + BAD_CAST "username", + BAD_CAST setup->priv->username); + xmlTextWriterWriteAttribute (writer, + BAD_CAST "password", + BAD_CAST setup->priv->password); + xmlTextWriterWriteAttribute (writer, + BAD_CAST "dbname", + BAD_CAST setup->priv->dbname); + + xmlTextWriterEndElement (writer); + xmlTextWriterEndDocument (writer); + xmlFreeTextWriter (writer); +} + + +PandoraSetup * +pandora_setup_new (gchar *config_file) +{ + PandoraSetup *setup; + + setup = PANDORA_SETUP (g_object_new (PANDORA_TYPE_SETUP, NULL)); + + setup->priv->config_file = g_strdup (config_file); + + pandora_setup_read_config_file (setup, config_file); + + return setup; +} + diff --git a/pandora_applet/src/pandora-setup.h b/pandora_applet/src/pandora-setup.h new file mode 100644 index 0000000000..94d27adee9 --- /dev/null +++ b/pandora_applet/src/pandora-setup.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifndef SETUP_H +#define SETUP_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#define PANDORA_TYPE_SETUP (pandora_setup_get_type()) +#define PANDORA_SETUP(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PANDORA_TYPE_SETUP, PandoraSetup)) +#define PANDORA_SETUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_TYPE_SETUP, PandoraSetupClass)) +#define PANDORA_IS_SETUP(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), PANDORA_TYPE_SETUP)) +#define PANDORA_IS_SETUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PANDORA_TYPE_SETUP)) +#define PANDORA_SETUP_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANDORA_TYPE_SETUP, PandoraSetupClass)) + +typedef struct _PandoraSetupPrivate PandoraSetupPrivate; + +typedef struct { + GObjectClass parent_class; +} PandoraSetupClass; + +/* + * Setup instance data + * + */ +typedef struct { + GObject parent; + PandoraSetupPrivate *priv; +} PandoraSetup; + +PandoraSetup *pandora_setup_new (gchar *config_file); + +gchar *pandora_setup_get_host (PandoraSetup *setup); +gchar *pandora_setup_get_username (PandoraSetup *setup); +gchar *pandora_setup_get_password (PandoraSetup *setup); +gchar *pandora_setup_get_dbname (PandoraSetup *setup); + +void pandora_setup_set_host (PandoraSetup *setup, const gchar *host); +void pandora_setup_set_username (PandoraSetup *setup, const gchar *username); +void pandora_setup_set_password (PandoraSetup *setup, const gchar *password); +void pandora_setup_set_dbname (PandoraSetup *setup, const gchar *dbname); + +void pandora_setup_save_to_disk (PandoraSetup *setup); + +#endif diff --git a/pandora_applet/src/pandora-status-checker.c b/pandora_applet/src/pandora-status-checker.c new file mode 100644 index 0000000000..ebd610aa46 --- /dev/null +++ b/pandora_applet/src/pandora-status-checker.c @@ -0,0 +1,402 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "pandora-status-checker.h" + +struct _PandoraStatusCheckerPrivate { + GThread *thread; + GMutex *state_mutex; + + gint state; + + PandoraStatus *status; + PandoraSetup *setup; + + MYSQL *connection; +}; + +#define PANDORA_STATUS_CHECKER_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_STATUS_CHECKER_TYPE, \ + PandoraStatusCheckerPrivate)) + +static gboolean pandora_status_checker_connect (PandoraStatusChecker *checker); +static gboolean pandora_status_checker_disconnect (PandoraStatusChecker *checker); + +static PandoraState pandora_status_checker_check_alerts (PandoraStatusChecker *checker); +static PandoraState pandora_status_checker_check_servers (PandoraStatusChecker *checker); +static PandoraState pandora_status_checker_check_agents (PandoraStatusChecker *checker); + +static void pandora_status_checker_init (PandoraStatusChecker *checker); +static void pandora_status_checker_class_init (PandoraStatusCheckerClass *klass); +static void pandora_status_checker_finalize (GObject *object); + +static gpointer pandora_status_checker_run_thread (gpointer data); + +GType +pandora_status_checker_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (PandoraStatusCheckerClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pandora_status_checker_class_init, + NULL, + NULL, + sizeof (PandoraStatusChecker), + 0, + (GInstanceInitFunc) pandora_status_checker_init + }; + + type = g_type_register_static (G_TYPE_OBJECT, "PandoraStatusChecker", + &info, 0); + } + + return type; +} + +static void +pandora_status_checker_init (PandoraStatusChecker *checker) +{ + checker->priv = PANDORA_STATUS_CHECKER_GET_PRIVATE (checker); + + checker->priv->connection = NULL; + + checker->priv->state_mutex = g_mutex_new (); + + checker->priv->state = CHECKER_STATE_READY; +} + + +static void +pandora_status_checker_class_init (PandoraStatusCheckerClass *klass) +{ + GObjectClass *object_class; + + g_type_class_add_private (klass, sizeof (PandoraStatusCheckerPrivate)); + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = pandora_status_checker_finalize; +} + +static void +pandora_status_checker_finalize (GObject *object) +{ + PandoraStatusChecker *checker; + + checker = PANDORA_STATUS_CHECKER (object); + + switch (checker->priv->state) { + case CHECKER_STATE_RUNNING: + pandora_status_checker_stop (checker); + /* Do not break! */ + case CHECKER_STATE_STOPPING: + g_thread_join (checker->priv->thread); + break; + default: + break; + } + + if (checker->priv->status) { + g_object_unref (checker->priv->status); + checker->priv->status = NULL; + } + + + if (checker->priv->state_mutex) { + g_mutex_free (checker->priv->state_mutex); + checker->priv->state_mutex = NULL; + } + + if (checker->priv->setup) { + g_object_unref (checker->priv->setup); + checker->priv->setup = NULL; + } + + if (checker->priv->connection) { + mysql_close (checker->priv->connection); + checker->priv->connection = NULL; + } +} + +PandoraStatusChecker * +pandora_status_checker_new (PandoraSetup *setup, PandoraStatus *status) +{ + PandoraStatusChecker *checker; + + checker = PANDORA_STATUS_CHECKER (g_object_new (PANDORA_STATUS_CHECKER_TYPE, + NULL)); + checker->priv->setup = setup; + g_object_ref (setup); + + checker->priv->status = status; + g_object_ref (status); + + return checker; +} + +static gboolean +pandora_status_checker_connect (PandoraStatusChecker *checker) +{ + MYSQL *connection; + PandoraSetup *setup; + gchar *host, *username, *password, *dbname; + gboolean retval = TRUE; + + connection = checker->priv->connection; + setup = checker->priv->setup; + + if (connection) { + mysql_close (connection); + } + + connection = mysql_init (NULL); + + if (connection == NULL) { + return FALSE; + } + + g_object_get (G_OBJECT (setup), "host", &host, "username", &username, + "password", &password, "dbname", &dbname, NULL); + + if (mysql_real_connect (connection, host, username, + password, dbname, 3306, NULL, 0) == NULL) + { + + g_print ("mysql_real_connect() failed. %s\n", + mysql_error (connection)); + mysql_close (connection); + + retval = FALSE; + } + + checker->priv->connection = connection; + return retval; +} + +static gboolean +pandora_status_checker_disconnect (PandoraStatusChecker *checker) +{ + if (checker->priv->connection) { + mysql_close (checker->priv->connection); + } + + checker->priv->connection = NULL; +} + +static PandoraState +pandora_status_checker_check_agents (PandoraStatusChecker *checker) +{ + MYSQL *connection = NULL; + MYSQL_RES *result; + MYSQL_ROW row; + const gchar const *query_time = "SELECT * FROM tagente " + "WHERE UNIX_TIMESTAMP(ultimo_contacto_remoto)" + "- intervalo > UNIX_TIMESTAMP(NOW())" ; + const gchar const *query_status = "SELECT * FROM tagente_estado " + "LEFT JOIN tagente " + "ON tagente_estado.id_agente = tagente.id_agente " + "WHERE estado != 100 and datos = 0.0"; + connection = checker->priv->connection; + g_return_val_if_fail (connection != NULL, FALSE); + + if (mysql_query (connection, query_time) != 0) { + return STATE_UNKNOWN; + } + + result = mysql_store_result (connection); + + if (mysql_num_rows (result) > 0) { + return STATE_BAD; + } + + mysql_free_result (result); + + if (mysql_query (connection, query_status) != 0) { + return STATE_UNKNOWN; + } + + result = mysql_store_result (connection); + + if (mysql_num_rows (result) > 0) { + return STATE_BAD; + } + + mysql_free_result (result); + return STATE_OK; +} + +static PandoraState +pandora_status_checker_check_servers (PandoraStatusChecker *checker) +{ + MYSQL *connection = NULL; + MYSQL_RES *result; + MYSQL_ROW row; + const gchar const *query = "SELECT * FROM tserver " + "WHERE status = 0"; + + connection = checker->priv->connection; + g_return_val_if_fail (connection != NULL, FALSE); + + if (mysql_query (connection, query) != 0) { + return STATE_UNKNOWN; + } + + result = mysql_store_result (connection); + + if (mysql_num_rows (result) > 0) + return STATE_BAD; + + mysql_free_result (result); + return STATE_OK; +} + +static PandoraState +pandora_status_checker_check_alerts (PandoraStatusChecker *checker) +{ + MYSQL *connection = NULL; + MYSQL_RES *result1 = NULL, *result2 = NULL, *result3 = NULL; + MYSQL_ROW row; + const gchar const *query_all_agents = "SELECT * FROM tagente " + "WHERE disabled = 0"; + const gchar const *query_agent_state = "SELECT * FROM tagente_estado " + "WHERE id_agente = %s"; + const gchar const *query_agent_alert = "SELECT * FROM talerta_agente_modulo " + "WHERE id_agente_modulo = %s " + "AND times_fired > 0"; + gchar *query; + + connection = checker->priv->connection; + g_return_val_if_fail (connection != NULL, FALSE); + + if (mysql_query (connection, query_all_agents) != 0) { + return STATE_UNKNOWN; + } + + result1 = mysql_store_result (connection); + if (result1 == NULL) + return STATE_UNKNOWN; + + if (mysql_num_rows (result1) == 0) + return STATE_UNKNOWN; + + while (row = mysql_fetch_row (result1)) { + query = g_strdup_printf (query_agent_state, row[0]); + + if (mysql_query (connection, query) == 0) { + result2 = mysql_store_result (connection); + + if (mysql_num_rows (result2) > 0) { + + while (row = mysql_fetch_row (result2)) { + + g_free (query); + query = g_strdup_printf (query_agent_alert, + row[1]); + + if (mysql_query (connection, query) == 0) { + result3 = mysql_store_result (connection); + + if (mysql_num_rows (result3) > 0) { + mysql_free_result (result1); + mysql_free_result (result2); + mysql_free_result (result3); + + g_free (query); + + return STATE_BAD; + } + + mysql_free_result (result3); + } + } + + mysql_free_result (result2); + } + } + + g_free (query); + } + + if (mysql_num_rows (result1) > 0) + mysql_free_result (result1); + + return STATE_OK; +} + +static gpointer +pandora_status_checker_run_thread (gpointer data) +{ + PandoraStatusChecker *checker = PANDORA_STATUS_CHECKER (data); + PandoraState alerts, servers, agents; + + g_mutex_lock (checker->priv->state_mutex); + checker->priv->state = CHECKER_STATE_RUNNING; + + while (checker->priv->state == CHECKER_STATE_RUNNING) { + g_mutex_unlock (checker->priv->state_mutex); + + if (!pandora_status_checker_connect (checker)) { + pandora_status_checker_stop (checker); + return NULL; + } + + alerts = pandora_status_checker_check_alerts (checker); + servers = pandora_status_checker_check_servers (checker); + agents = pandora_status_checker_check_agents (checker); + + pandora_status_set_alerts (checker->priv->status, alerts); + pandora_status_set_servers (checker->priv->status, servers); + pandora_status_set_agents (checker->priv->status, agents); + + pandora_status_checker_disconnect (checker); + + g_usleep (G_USEC_PER_SEC * 10); + + g_mutex_lock (checker->priv->state_mutex); + } + + g_mutex_unlock (checker->priv->state_mutex); + + return NULL; +} + +void +pandora_status_checker_run (PandoraStatusChecker *checker) +{ + checker->priv->thread = g_thread_create (pandora_status_checker_run_thread, + (gpointer) checker, TRUE, NULL); +} + +void +pandora_status_checker_stop (PandoraStatusChecker *checker) +{ + g_mutex_lock (checker->priv->state_mutex); + checker->priv->state = CHECKER_STATE_RUNNING; + g_mutex_unlock (checker->priv->state_mutex); +} diff --git a/pandora_applet/src/pandora-status-checker.h b/pandora_applet/src/pandora-status-checker.h new file mode 100644 index 0000000000..d715524f74 --- /dev/null +++ b/pandora_applet/src/pandora-status-checker.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifndef STATUS_CHECKER_H +#define STATUS_CHECKER_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "pandora-setup.h" +#include "pandora-status.h" + +enum { + CHECKER_STATE_READY, + CHECKER_STATE_RUNNING, + CHECKER_STATE_FINISHED, + CHECKER_STATE_STOPPING, + CHECKER_STATE_FAILED +}; + +#define PANDORA_STATUS_CHECKER_TYPE (pandora_status_checker_get_type()) +#define PANDORA_STATUS_CHECKER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PANDORA_STATUS_CHECKER_TYPE, PandoraStatusChecker)) +#define PANDORA_STATUS_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_STATUS_CHECKER_TYPE, PandoraStatusCheckerClass)) +#define PANDORA_IS_STATUS_CHECKER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), PANDORA_STATUS_CHECKER_TYPE)) +#define PANDORA_IS_STATUS_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PANDORA_STATUS_CHECKER_TYPE)) +#define PANDORA_STATUS_CHECKER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANDORA_STATUS_CHECKER_TYPE, PandoraStatusCheckerClass)) + +typedef struct _PandoraStatusCheckerPrivate PandoraStatusCheckerPrivate; + +typedef struct { + GObjectClass parent_class; +} PandoraStatusCheckerClass; + +typedef struct { + GObject parent; + + PandoraStatusCheckerPrivate *priv; +} PandoraStatusChecker; + +PandoraStatusChecker *pandora_status_checker_new (PandoraSetup *setup, + PandoraStatus *status); + +void pandora_status_checker_run (PandoraStatusChecker *checker); +void pandora_status_checker_stop (PandoraStatusChecker *checker); + +#endif diff --git a/pandora_applet/src/pandora-status.c b/pandora_applet/src/pandora-status.c new file mode 100644 index 0000000000..d34b92327b --- /dev/null +++ b/pandora_applet/src/pandora-status.c @@ -0,0 +1,218 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "pandora-status.h" + +enum { + CHANGED, + N_SIGNALS +}; + +struct _PandoraStatusPrivate { + PandoraState alerts; + PandoraState agents; + PandoraState servers; + + GMutex *mutex; +}; + +static guint pandora_status_signals[N_SIGNALS]; + +#define PANDORA_STATUS_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), PANDORA_STATUS_TYPE, \ + PandoraStatusPrivate)) + +static void pandora_status_init (PandoraStatus *status); +static void pandora_status_class_init (PandoraStatusClass *klass); +static void pandora_status_finalize (GObject *object); + +GType +pandora_status_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof (PandoraStatusClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) pandora_status_class_init, + NULL, + NULL, + sizeof (PandoraStatus), + 0, + (GInstanceInitFunc) pandora_status_init + }; + + type = g_type_register_static (G_TYPE_OBJECT, "PandoraStatus", + &info, 0); + } + + return type; +} + +static void +pandora_status_init (PandoraStatus *status) +{ + status->priv = PANDORA_STATUS_GET_PRIVATE (status); + status->priv->alerts = FALSE; + status->priv->agents = FALSE; + status->priv->servers = FALSE; + + status->priv->mutex = g_mutex_new (); +} + + +static void +pandora_status_class_init (PandoraStatusClass *klass) +{ + GObjectClass *object_class; + + g_type_class_add_private (klass, sizeof (PandoraStatusPrivate)); + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = pandora_status_finalize; + + pandora_status_signals[CHANGED] = + g_signal_new ("changed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (PandoraStatusClass, changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +static void +pandora_status_finalize (GObject *object) +{ + PandoraStatus *status; + + status = PANDORA_STATUS (object); + + if (status->priv->mutex) { + g_mutex_free (status->priv->mutex); + status->priv->mutex = NULL; + } +} + +PandoraStatus * +pandora_status_new (void) +{ + PandoraStatus *status; + + status = PANDORA_STATUS (g_object_new (PANDORA_STATUS_TYPE, + NULL)); + + return status; +} + +void +pandora_status_set_alerts (PandoraStatus *status, PandoraState value) +{ + g_return_if_fail (PANDORA_IS_STATUS (status)); + + g_mutex_lock (status->priv->mutex); + + if (status->priv->alerts != value) { + status->priv->alerts = value; + g_mutex_unlock (status->priv->mutex); + + g_signal_emit (status, pandora_status_signals[CHANGED], 0); + } else { + g_mutex_unlock (status->priv->mutex); + } +} + +void +pandora_status_set_agents (PandoraStatus *status, PandoraState value) +{ + g_return_if_fail (PANDORA_IS_STATUS (status)); + + g_mutex_lock (status->priv->mutex); + + if (status->priv->agents != value) { + status->priv->agents = value; + g_mutex_unlock (status->priv->mutex); + + g_signal_emit (status, pandora_status_signals[CHANGED], 0); + } else { + g_mutex_unlock (status->priv->mutex); + } +} + +void +pandora_status_set_servers (PandoraStatus *status, PandoraState value) +{ + g_return_if_fail (PANDORA_IS_STATUS (status)); + + g_mutex_lock (status->priv->mutex); + + if (status->priv->servers != value) { + status->priv->servers = value; + g_mutex_unlock (status->priv->mutex); + + g_signal_emit (status, pandora_status_signals[CHANGED], 0); + } else { + g_mutex_unlock (status->priv->mutex); + } +} + +PandoraState +pandora_status_get_alerts (PandoraStatus *status) +{ + PandoraState value; + + g_mutex_lock (status->priv->mutex); + value = status->priv->alerts; + g_mutex_unlock (status->priv->mutex); + + return value; +} + +PandoraState +pandora_status_get_agents (PandoraStatus *status) +{ + PandoraState value; + + g_mutex_lock (status->priv->mutex); + value = status->priv->agents; + g_mutex_unlock (status->priv->mutex); + + return value; +} + +PandoraState +pandora_status_get_servers (PandoraStatus *status) +{ + PandoraState value; + + g_mutex_lock (status->priv->mutex); + value = status->priv->servers; + g_mutex_unlock (status->priv->mutex); + + return value; +} diff --git a/pandora_applet/src/pandora-status.h b/pandora_applet/src/pandora-status.h new file mode 100644 index 0000000000..540f1ae447 --- /dev/null +++ b/pandora_applet/src/pandora-status.h @@ -0,0 +1,67 @@ +/* + Copyright (C) 2006 Artica ST. + Written by Esteban Sanchez. + + 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. +*/ + +#ifndef STATUS_H +#define STATUS_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +typedef enum { + STATE_INVALID, + STATE_UNKNOWN, + STATE_OK, + STATE_BAD +} PandoraState; + +#define PANDORA_STATUS_TYPE (pandora_status_get_type()) +#define PANDORA_STATUS(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PANDORA_STATUS_TYPE, PandoraStatus)) +#define PANDORA_STATUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PANDORA_STATUS_TYPE, PandoraStatusClass)) +#define PANDORA_IS_STATUS(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), PANDORA_STATUS_TYPE)) +#define PANDORA_IS_STATUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PANDORA_STATUS_TYPE)) +#define PANDORA_STATUS_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PANDORA_STATUS_TYPE, PandoraStatusClass)) + +typedef struct _PandoraStatusPrivate PandoraStatusPrivate; + +typedef struct { + GObject parent; + + PandoraStatusPrivate *priv; +} PandoraStatus; + +typedef struct { + GObjectClass parent_class; + + void (* changed) (PandoraStatus *view); +} PandoraStatusClass; + +PandoraStatus *pandora_status_new (void); +void pandora_status_set_alerts (PandoraStatus *status, PandoraState value); +void pandora_status_set_agents (PandoraStatus *status, PandoraState value); +void pandora_status_set_servers (PandoraStatus *status, PandoraState value); + +PandoraState pandora_status_get_alerts (PandoraStatus *status); +PandoraState pandora_status_get_agents (PandoraStatus *status); +PandoraState pandora_status_get_servers (PandoraStatus *status); + + +#endif