diff options
Diffstat (limited to 'applets/inhibit')
-rw-r--r-- | applets/inhibit/MATE_InhibitApplet.server.in.in | 36 | ||||
-rw-r--r-- | applets/inhibit/MATE_InhibitApplet.xml | 8 | ||||
-rw-r--r-- | applets/inhibit/Makefile.am | 55 | ||||
-rw-r--r-- | applets/inhibit/Makefile.in | 717 | ||||
-rw-r--r-- | applets/inhibit/egg-dbus-monitor.c | 251 | ||||
-rw-r--r-- | applets/inhibit/egg-dbus-monitor.h | 65 | ||||
-rw-r--r-- | applets/inhibit/egg-debug.c | 308 | ||||
-rw-r--r-- | applets/inhibit/egg-debug.h | 83 | ||||
-rw-r--r-- | applets/inhibit/gpm-common.c | 210 | ||||
-rw-r--r-- | applets/inhibit/gpm-common.h | 183 | ||||
-rw-r--r-- | applets/inhibit/inhibit-applet.c | 688 |
11 files changed, 2604 insertions, 0 deletions
diff --git a/applets/inhibit/MATE_InhibitApplet.server.in.in b/applets/inhibit/MATE_InhibitApplet.server.in.in new file mode 100644 index 0000000..d65c077 --- /dev/null +++ b/applets/inhibit/MATE_InhibitApplet.server.in.in @@ -0,0 +1,36 @@ +<?xml version="1.0"?> + +<oaf_info> + <oaf_server iid="OAFIID:MATE_InhibitApplet_Factory" type="exe" location="@LIBEXECDIR@/mate-inhibit-applet"> + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:MateComponent/GenericFactory:1.0"/> + <item value="IDL:MateComponent/Unknown:1.0"/> + </oaf_attribute> + <oaf_attribute name="name" type="string" _value="Inhibit Applet Factory"/> + <oaf_attribute name="description" type="string" _value="Factory for Inhibit Applet"/> + <oaf_attribute name="bugzilla:bugzilla" type="string" value="MATE"/> + <oaf_attribute name="bugzilla:product" type="string" value="mate-power-manager"/> + <oaf_attribute name="bugzilla:component" type="string" value="applets"/> + <oaf_attribute name="bugzilla:version" type="string" value="@VERSION@"/> + <oaf_attribute name="bugzilla:other_binaries" type="string" value="mate-inhibit-applet"/> + <oaf_attribute name="matecomponent:environment" type="stringv"> + <item value="DBUS_SESSION_BUS_ADDRESS"/> + </oaf_attribute> + </oaf_server> + <oaf_server iid="OAFIID:MATE_InhibitApplet" type="factory" location="OAFIID:MATE_InhibitApplet_Factory"> + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:MATE/Vertigo/MatePanelAppletShell:1.0"/> + <item value="IDL:MateComponent/Control:1.0"/> + <item value="IDL:MateComponent/Unknown:1.0"/> + </oaf_attribute> + <oaf_attribute name="panel:category" type="string" value="System & Hardware"/> + <oaf_attribute name="panel:icon" type="string" value="mate-inhibit-applet"/> + <oaf_attribute name="name" type="string" _value="Inhibit Applet"/> + <oaf_attribute name="description" type="string" _value="Allows user to inhibit automatic power saving"/> + <oaf_attribute name="bugzilla:bugzilla" type="string" value="MATE"/> + <oaf_attribute name="bugzilla:product" type="string" value="mate-power-manager"/> + <oaf_attribute name="bugzilla:component" type="string" value="applets"/> + <oaf_attribute name="bugzilla:version" type="string" value="@VERSION@"/> + <oaf_attribute name="bugzilla:other_binaries" type="string" value="mate-inhibit-applet"/> + </oaf_server> +</oaf_info> diff --git a/applets/inhibit/MATE_InhibitApplet.xml b/applets/inhibit/MATE_InhibitApplet.xml new file mode 100644 index 0000000..83b176f --- /dev/null +++ b/applets/inhibit/MATE_InhibitApplet.xml @@ -0,0 +1,8 @@ +<Root> + <popups> + <popup name="button3"> + <menuitem name="Help" verb="Help" _label="_Help" pixtype="stock" pixname="gtk-help"/> + <menuitem name="About" verb="About" _label="_About" pixtype="stock" pixname="gtk-about" /> + </popup> + </popups> +</Root> diff --git a/applets/inhibit/Makefile.am b/applets/inhibit/Makefile.am new file mode 100644 index 0000000..fb42774 --- /dev/null +++ b/applets/inhibit/Makefile.am @@ -0,0 +1,55 @@ +INCLUDES = \ + -I. -I$(srcdir) \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(MATE_CFLAGS) \ + $(PANEL_CFLAGS) \ + $(LIBMATENOTIFY_CFLAGS) \ + $(GTKUNIQUE_CFLAGS) \ + -DBINDIR=\"$(bindir)\" \ + -DMATELOCALEDIR=\""$(datadir)/locale"\" \ + -DDATADIR=\"$(datadir)\" \ + -DPREFIX=\""$(prefix)"\" \ + -DSYSCONFDIR=\""$(sysconfdir)"\" \ + -DLIBDIR=\""$(libdir)"\" \ + -DVERSION="\"$(VERSION)\"" \ + -DGPM_DATA=\"$(pkgdatadir)\" \ + -DEGG_LOG_FILE=\""~/mate-power-manager.log"\" \ + -DEGG_VERBOSE="\"GPM_VERBOSE\"" \ + -DEGG_LOGGING="\"GPM_LOGGING\"" \ + -DEGG_CONSOLE="\"GPM_CONSOLE\"" \ + -I$(top_srcdir)/libdbus-glib \ + $(NULL) + +libexec_PROGRAMS=mate-inhibit-applet + +mate_inhibit_applet_SOURCES = \ + inhibit-applet.c \ + egg-dbus-monitor.c \ + egg-dbus-monitor.h \ + egg-debug.c \ + egg-debug.h \ + gpm-common.c \ + gpm-common.h + +mate_inhibit_applet_LDADD = \ + $(DBUS_LIBS) \ + $(MATE_LIBS) \ + $(PANEL_LIBS) + +serverdir = $(libdir)/matecomponent/servers +server_in_files = MATE_InhibitApplet.server.in +server_DATA = $(server_in_files:.server.in=.server) + +$(server_in_files): $(server_in_files:.server.in=.server.in.in) + sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" -e "s|\@VERSION\@|$(VERSION)|" $< > $@ + +@INTLTOOL_SERVER_RULE@ + +uidir = $(datadir)/mate-2.0/ui +ui_DATA = MATE_InhibitApplet.xml + +EXTRA_DIST = MATE_InhibitApplet.server.in.in $(ui_DATA) + +DISTCLEANFILES = \ + $(server_DATA) $(server_DATA).in diff --git a/applets/inhibit/Makefile.in b/applets/inhibit/Makefile.in new file mode 100644 index 0000000..ecddf07 --- /dev/null +++ b/applets/inhibit/Makefile.in @@ -0,0 +1,717 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +libexec_PROGRAMS = mate-inhibit-applet$(EXEEXT) +subdir = applets/inhibit +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/mate-doc-utils.m4 \ + $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(libexecdir)" "$(DESTDIR)$(serverdir)" \ + "$(DESTDIR)$(uidir)" +PROGRAMS = $(libexec_PROGRAMS) +am_mate_inhibit_applet_OBJECTS = inhibit-applet.$(OBJEXT) \ + egg-dbus-monitor.$(OBJEXT) egg-debug.$(OBJEXT) \ + gpm-common.$(OBJEXT) +mate_inhibit_applet_OBJECTS = $(am_mate_inhibit_applet_OBJECTS) +am__DEPENDENCIES_1 = +mate_inhibit_applet_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(mate_inhibit_applet_SOURCES) +DIST_SOURCES = $(mate_inhibit_applet_SOURCES) +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +DATA = $(server_DATA) $(ui_DATA) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BINDIR = @BINDIR@ +CANBERRA_CFLAGS = @CANBERRA_CFLAGS@ +CANBERRA_LIBS = @CANBERRA_LIBS@ +CATALOGS = @CATALOGS@ +CATOBJEXT = @CATOBJEXT@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIR = @DATADIR@ +DATADIRNAME = @DATADIRNAME@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_LIBS = @DBUS_LIBS@ +DBUS_SERVICES_DIR = @DBUS_SERVICES_DIR@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISTCHECK_CONFIGURE_FLAGS = @DISTCHECK_CONFIGURE_FLAGS@ +DOCBOOK2MAN = @DOCBOOK2MAN@ +DOCDIR = @DOCDIR@ +DOC_USER_FORMATS = @DOC_USER_FORMATS@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GMOFILES = @GMOFILES@ +GMSGFMT = @GMSGFMT@ +GPM_EXTRA_LIBS = @GPM_EXTRA_LIBS@ +GREP = @GREP@ +HELP_DIR = @HELP_DIR@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INSTOBJEXT = @INSTOBJEXT@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBMATENOTIFY_CFLAGS = @LIBMATENOTIFY_CFLAGS@ +LIBMATENOTIFY_LIBS = @LIBMATENOTIFY_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MATECONFTOOL = @MATECONFTOOL@ +MATECONF_SCHEMA_CONFIG_SOURCE = @MATECONF_SCHEMA_CONFIG_SOURCE@ +MATECONF_SCHEMA_FILE_DIR = @MATECONF_SCHEMA_FILE_DIR@ +MATE_CFLAGS = @MATE_CFLAGS@ +MATE_LIBS = @MATE_LIBS@ +MKDIR_P = @MKDIR_P@ +MKINSTALLDIRS = @MKINSTALLDIRS@ +MSGFMT = @MSGFMT@ +MSGFMT_OPTS = @MSGFMT_OPTS@ +MSGMERGE = @MSGMERGE@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OMF_DIR = @OMF_DIR@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANEL_CFLAGS = @PANEL_CFLAGS@ +PANEL_LIBS = @PANEL_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POFILES = @POFILES@ +POSUB = @POSUB@ +PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ +PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ +RANLIB = @RANLIB@ +SBINDIR = @SBINDIR@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SYSCONFDIR = @SYSCONFDIR@ +UNIQUE_CFLAGS = @UNIQUE_CFLAGS@ +UNIQUE_LIBS = @UNIQUE_LIBS@ +UPOWER_CFLAGS = @UPOWER_CFLAGS@ +UPOWER_LIBS = @UPOWER_LIBS@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +WARNINGFLAGS = @WARNINGFLAGS@ +WARN_CFLAGS = @WARN_CFLAGS@ +X11_CFLAGS = @X11_CFLAGS@ +X11_LIBS = @X11_LIBS@ +XGETTEXT = @XGETTEXT@ +XMLTO = @XMLTO@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +INCLUDES = \ + -I. -I$(srcdir) \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(MATE_CFLAGS) \ + $(PANEL_CFLAGS) \ + $(LIBMATENOTIFY_CFLAGS) \ + $(GTKUNIQUE_CFLAGS) \ + -DBINDIR=\"$(bindir)\" \ + -DMATELOCALEDIR=\""$(datadir)/locale"\" \ + -DDATADIR=\"$(datadir)\" \ + -DPREFIX=\""$(prefix)"\" \ + -DSYSCONFDIR=\""$(sysconfdir)"\" \ + -DLIBDIR=\""$(libdir)"\" \ + -DVERSION="\"$(VERSION)\"" \ + -DGPM_DATA=\"$(pkgdatadir)\" \ + -DEGG_LOG_FILE=\""~/mate-power-manager.log"\" \ + -DEGG_VERBOSE="\"GPM_VERBOSE\"" \ + -DEGG_LOGGING="\"GPM_LOGGING\"" \ + -DEGG_CONSOLE="\"GPM_CONSOLE\"" \ + -I$(top_srcdir)/libdbus-glib \ + $(NULL) + +mate_inhibit_applet_SOURCES = \ + inhibit-applet.c \ + egg-dbus-monitor.c \ + egg-dbus-monitor.h \ + egg-debug.c \ + egg-debug.h \ + gpm-common.c \ + gpm-common.h + +mate_inhibit_applet_LDADD = \ + $(DBUS_LIBS) \ + $(MATE_LIBS) \ + $(PANEL_LIBS) + +serverdir = $(libdir)/matecomponent/servers +server_in_files = MATE_InhibitApplet.server.in +server_DATA = $(server_in_files:.server.in=.server) +uidir = $(datadir)/mate-2.0/ui +ui_DATA = MATE_InhibitApplet.xml +EXTRA_DIST = MATE_InhibitApplet.server.in.in $(ui_DATA) +DISTCLEANFILES = \ + $(server_DATA) $(server_DATA).in + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign applets/inhibit/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign applets/inhibit/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-libexecPROGRAMS: $(libexec_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(libexecdir)" || $(MKDIR_P) "$(DESTDIR)$(libexecdir)" + @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(libexecdir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(libexecdir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-libexecPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(libexecdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(libexecdir)" && rm -f $$files + +clean-libexecPROGRAMS: + @list='$(libexec_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +mate-inhibit-applet$(EXEEXT): $(mate_inhibit_applet_OBJECTS) $(mate_inhibit_applet_DEPENDENCIES) + @rm -f mate-inhibit-applet$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(mate_inhibit_applet_OBJECTS) $(mate_inhibit_applet_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/egg-dbus-monitor.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/egg-debug.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gpm-common.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inhibit-applet.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-serverDATA: $(server_DATA) + @$(NORMAL_INSTALL) + test -z "$(serverdir)" || $(MKDIR_P) "$(DESTDIR)$(serverdir)" + @list='$(server_DATA)'; test -n "$(serverdir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(serverdir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(serverdir)" || exit $$?; \ + done + +uninstall-serverDATA: + @$(NORMAL_UNINSTALL) + @list='$(server_DATA)'; test -n "$(serverdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(serverdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(serverdir)" && rm -f $$files +install-uiDATA: $(ui_DATA) + @$(NORMAL_INSTALL) + test -z "$(uidir)" || $(MKDIR_P) "$(DESTDIR)$(uidir)" + @list='$(ui_DATA)'; test -n "$(uidir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(uidir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(uidir)" || exit $$?; \ + done + +uninstall-uiDATA: + @$(NORMAL_UNINSTALL) + @list='$(ui_DATA)'; test -n "$(uidir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(uidir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(uidir)" && rm -f $$files + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) $(DATA) +installdirs: + for dir in "$(DESTDIR)$(libexecdir)" "$(DESTDIR)$(serverdir)" "$(DESTDIR)$(uidir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libexecPROGRAMS clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-serverDATA install-uiDATA + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-libexecPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-libexecPROGRAMS uninstall-serverDATA \ + uninstall-uiDATA + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libexecPROGRAMS clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am \ + install-libexecPROGRAMS install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-serverDATA install-strip \ + install-uiDATA installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-libexecPROGRAMS uninstall-serverDATA \ + uninstall-uiDATA + + +$(server_in_files): $(server_in_files:.server.in=.server.in.in) + sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" -e "s|\@VERSION\@|$(VERSION)|" $< > $@ + +@INTLTOOL_SERVER_RULE@ + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/applets/inhibit/egg-dbus-monitor.c b/applets/inhibit/egg-dbus-monitor.c new file mode 100644 index 0000000..b8238d1 --- /dev/null +++ b/applets/inhibit/egg-dbus-monitor.c @@ -0,0 +1,251 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2006-2008 Richard Hughes <[email protected]> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <glib.h> +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-lowlevel.h> +#include <dbus/dbus.h> + +#include "egg-debug.h" +#include "egg-dbus-monitor.h" + +static void egg_dbus_monitor_finalize (GObject *object); + +#define EGG_DBUS_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorPrivate)) + +struct EggDbusMonitorPrivate +{ + gchar *service; + DBusGProxy *proxy; + DBusGConnection *connection; + const gchar *unique_name; +}; + +enum { + EGG_DBUS_MONITOR_CONNECTION_CHANGED, + EGG_DBUS_MONITOR_CONNECTION_REPLACED, + EGG_DBUS_MONITOR_LAST_SIGNAL +}; + +static guint signals [EGG_DBUS_MONITOR_LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE (EggDbusMonitor, egg_dbus_monitor, G_TYPE_OBJECT) + +/** + * egg_dbus_monitor_name_owner_changed_cb: + **/ +static void +egg_dbus_monitor_name_owner_changed_cb (DBusGProxy *proxy, const gchar *name, + const gchar *prev, const gchar *new, + EggDbusMonitor *monitor) +{ + guint new_len; + guint prev_len; + + g_return_if_fail (EGG_IS_DBUS_MONITOR (monitor)); + if (monitor->priv->proxy == NULL) + return; + + /* not us */ + if (strcmp (name, monitor->priv->service) != 0) + return; + + /* ITS4: ignore, not used for allocation */ + new_len = strlen (new); + /* ITS4: ignore, not used for allocation */ + prev_len = strlen (prev); + + /* something --> nothing */ + if (prev_len != 0 && new_len == 0) { + g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, FALSE); + return; + } + + /* nothing --> something */ + if (prev_len == 0 && new_len != 0) { + g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE); + return; + } + + /* something --> something (we've replaced the old process) */ + if (prev_len != 0 && new_len != 0) { + /* only send this to the prev client */ + if (strcmp (monitor->priv->unique_name, prev) == 0) + g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED], 0); + return; + } +} + +/** + * egg_dbus_monitor_assign: + * @monitor: This class instance + * @connection: The bus connection + * @service: The EGG_DBUS_MONITOR service name + * Return value: success + * + * Emits connection-changed(TRUE) if connection is alive - this means you + * have to connect up the callback before this function is called. + **/ +gboolean +egg_dbus_monitor_assign (EggDbusMonitor *monitor, DBusGConnection *connection, const gchar *service) +{ + GError *error = NULL; + gboolean connected; + DBusConnection *conn; + + g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE); + g_return_val_if_fail (service != NULL, FALSE); + g_return_val_if_fail (connection != NULL, FALSE); + + if (monitor->priv->proxy != NULL) { + egg_warning ("already assigned!"); + return FALSE; + } + + monitor->priv->service = g_strdup (service); + monitor->priv->connection = connection; + monitor->priv->proxy = dbus_g_proxy_new_for_name_owner (monitor->priv->connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + egg_warning ("Cannot connect to DBUS: %s", error->message); + g_error_free (error); + return FALSE; + } + dbus_g_proxy_add_signal (monitor->priv->proxy, "NameOwnerChanged", + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal (monitor->priv->proxy, "NameOwnerChanged", + G_CALLBACK (egg_dbus_monitor_name_owner_changed_cb), + monitor, NULL); + + /* coldplug */ + connected = egg_dbus_monitor_is_connected (monitor); + if (connected) + g_signal_emit (monitor, signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED], 0, TRUE); + + /* save this for the replaced check */ + conn = dbus_g_connection_get_connection (monitor->priv->connection); + monitor->priv->unique_name = dbus_bus_get_unique_name (conn); + return TRUE; +} + +/** + * egg_dbus_monitor_is_connected: + * @monitor: This class instance + * Return value: if we are connected to a valid watch + **/ +gboolean +egg_dbus_monitor_is_connected (EggDbusMonitor *monitor) +{ + DBusError error; + DBusConnection *conn; + gboolean ret; + g_return_val_if_fail (EGG_IS_DBUS_MONITOR (monitor), FALSE); + + /* get raw connection */ + conn = dbus_g_connection_get_connection (monitor->priv->connection); + dbus_error_init (&error); + ret = dbus_bus_name_has_owner (conn, monitor->priv->service, &error); + if (dbus_error_is_set (&error)) { + egg_debug ("error: %s", error.message); + dbus_error_free (&error); + } + + return ret; +} + +/** + * egg_dbus_monitor_class_init: + * @klass: The EggDbusMonitorClass + **/ +static void +egg_dbus_monitor_class_init (EggDbusMonitorClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = egg_dbus_monitor_finalize; + g_type_class_add_private (klass, sizeof (EggDbusMonitorPrivate)); + signals [EGG_DBUS_MONITOR_CONNECTION_CHANGED] = + g_signal_new ("connection-changed", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EggDbusMonitorClass, connection_changed), + NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + signals [EGG_DBUS_MONITOR_CONNECTION_REPLACED] = + g_signal_new ("connection-replaced", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EggDbusMonitorClass, connection_replaced), + NULL, NULL, g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +/** + * egg_dbus_monitor_init: + * @monitor: This class instance + **/ +static void +egg_dbus_monitor_init (EggDbusMonitor *monitor) +{ + monitor->priv = EGG_DBUS_MONITOR_GET_PRIVATE (monitor); + monitor->priv->service = NULL; + monitor->priv->connection = NULL; + monitor->priv->proxy = NULL; +} + +/** + * egg_dbus_monitor_finalize: + * @object: The object to finalize + **/ +static void +egg_dbus_monitor_finalize (GObject *object) +{ + EggDbusMonitor *monitor; + + g_return_if_fail (EGG_IS_DBUS_MONITOR (object)); + + monitor = EGG_DBUS_MONITOR (object); + + g_return_if_fail (monitor->priv != NULL); + if (monitor->priv->proxy != NULL) + g_object_unref (monitor->priv->proxy); + + G_OBJECT_CLASS (egg_dbus_monitor_parent_class)->finalize (object); +} + +/** + * egg_dbus_monitor_new: + * + * Return value: a new EggDbusMonitor object. + **/ +EggDbusMonitor * +egg_dbus_monitor_new (void) +{ + EggDbusMonitor *monitor; + monitor = g_object_new (EGG_TYPE_DBUS_MONITOR, NULL); + return EGG_DBUS_MONITOR (monitor); +} + diff --git a/applets/inhibit/egg-dbus-monitor.h b/applets/inhibit/egg-dbus-monitor.h new file mode 100644 index 0000000..9efa8b9 --- /dev/null +++ b/applets/inhibit/egg-dbus-monitor.h @@ -0,0 +1,65 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Richard Hughes <[email protected]> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __EGG_DBUS_MONITOR_H +#define __EGG_DBUS_MONITOR_H + +#include <glib-object.h> +#include <dbus/dbus-glib.h> + +G_BEGIN_DECLS + +#define EGG_TYPE_DBUS_MONITOR (egg_dbus_monitor_get_type ()) +#define EGG_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitor)) +#define EGG_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass)) +#define EGG_IS_DBUS_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_TYPE_DBUS_MONITOR)) +#define EGG_IS_DBUS_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EGG_TYPE_DBUS_MONITOR)) +#define EGG_DBUS_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EGG_TYPE_DBUS_MONITOR, EggDbusMonitorClass)) +#define EGG_DBUS_MONITOR_ERROR (egg_dbus_monitor_error_quark ()) +#define EGG_DBUS_MONITOR_TYPE_ERROR (egg_dbus_monitor_error_get_type ()) + +typedef struct EggDbusMonitorPrivate EggDbusMonitorPrivate; + +typedef struct +{ + GObject parent; + EggDbusMonitorPrivate *priv; +} EggDbusMonitor; + +typedef struct +{ + GObjectClass parent_class; + void (* connection_changed) (EggDbusMonitor *watch, + gboolean connected); + void (* connection_replaced) (EggDbusMonitor *watch); +} EggDbusMonitorClass; + +GType egg_dbus_monitor_get_type (void); +EggDbusMonitor *egg_dbus_monitor_new (void); +gboolean egg_dbus_monitor_assign (EggDbusMonitor *monitor, + DBusGConnection *connection, + const gchar *service); +gboolean egg_dbus_monitor_is_connected (EggDbusMonitor *monitor); + +G_END_DECLS + +#endif /* __EGG_DBUS_MONITOR_H */ + diff --git a/applets/inhibit/egg-debug.c b/applets/inhibit/egg-debug.c new file mode 100644 index 0000000..2f140f2 --- /dev/null +++ b/applets/inhibit/egg-debug.c @@ -0,0 +1,308 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2007-2008 Richard Hughes <[email protected]> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * SECTION:egg-debug + * @short_description: Debugging functions + * + * This file contains functions that can be used for debugging. + */ + +#include <glib.h> +#include <glib/gi18n.h> +#include <glib/gprintf.h> +#include <stdio.h> +#include <string.h> +#include <stdarg.h> +#include <stdlib.h> +#include <signal.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <time.h> +#include <execinfo.h> + +#include "egg-debug.h" + +#define CONSOLE_RESET 0 +#define CONSOLE_BLACK 30 +#define CONSOLE_RED 31 +#define CONSOLE_GREEN 32 +#define CONSOLE_YELLOW 33 +#define CONSOLE_BLUE 34 +#define CONSOLE_MAGENTA 35 +#define CONSOLE_CYAN 36 +#define CONSOLE_WHITE 37 + +static gint fd = -1; + +/** + * pk_set_console_mode: + **/ +static void +pk_set_console_mode (guint console_code) +{ + gchar command[13]; + + /* don't put extra commands into logs */ + if (!egg_debug_is_console ()) + return; + + /* Command is the control command to the terminal */ + g_snprintf (command, 13, "%c[%dm", 0x1B, console_code); + printf ("%s", command); +} + +/** + * egg_debug_backtrace: + **/ +void +egg_debug_backtrace (void) +{ + void *call_stack[512]; + int call_stack_size; + char **symbols; + int i = 1; + + call_stack_size = backtrace (call_stack, G_N_ELEMENTS (call_stack)); + symbols = backtrace_symbols (call_stack, call_stack_size); + if (symbols != NULL) { + pk_set_console_mode (CONSOLE_RED); + g_print ("Traceback:\n"); + while (i < call_stack_size) { + g_print ("\t%s\n", symbols[i]); + i++; + } + pk_set_console_mode (CONSOLE_RESET); + free (symbols); + } +} + +/** + * pk_log_line: + **/ +static void +pk_log_line (const gchar *buffer) +{ + ssize_t count; + /* open a file */ + if (fd == -1) { + /* ITS4: ignore, /var/log/foo is owned by root, and this is just debug text */ + fd = open (EGG_LOG_FILE, O_WRONLY|O_APPEND|O_CREAT, 0777); + if (fd == -1) + g_error ("could not open log: '%s'", EGG_LOG_FILE); + } + + /* ITS4: ignore, debug text always NULL terminated */ + count = write (fd, buffer, strlen (buffer)); + if (count == -1) + g_warning ("could not write %s", buffer); + /* newline */ + count = write (fd, "\n", 1); + if (count == -1) + g_warning ("could not write newline"); +} + +/** + * pk_print_line: + **/ +static void +pk_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color) +{ + gchar *str_time; + gchar *header; + time_t the_time; + GThread *thread; + + time (&the_time); + str_time = g_new0 (gchar, 255); + strftime (str_time, 254, "%H:%M:%S", localtime (&the_time)); + thread = g_thread_self (); + + /* generate header text */ + header = g_strdup_printf ("TI:%s\tTH:%p\tFI:%s\tFN:%s,%d", str_time, thread, file, func, line); + g_free (str_time); + + /* always in light green */ + pk_set_console_mode (CONSOLE_GREEN); + printf ("%s\n", header); + + /* different colors according to the severity */ + pk_set_console_mode (color); + printf (" - %s\n", buffer); + pk_set_console_mode (CONSOLE_RESET); + + /* log to a file */ + if (egg_debug_is_logging ()) { + pk_log_line (header); + pk_log_line (buffer); + } + + /* flush this output, as we need to debug */ + fflush (stdout); + + g_free (header); +} + +/** + * egg_debug_real: + **/ +void +egg_debug_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...) +{ + va_list args; + gchar *buffer = NULL; + + if (!egg_debug_enabled ()) + return; + + va_start (args, format); + g_vasprintf (&buffer, format, args); + va_end (args); + + pk_print_line (func, file, line, buffer, CONSOLE_BLUE); + + g_free(buffer); +} + +/** + * egg_warning_real: + **/ +void +egg_warning_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...) +{ + va_list args; + gchar *buffer = NULL; + + if (!egg_debug_enabled ()) + return; + + va_start (args, format); + g_vasprintf (&buffer, format, args); + va_end (args); + + /* do extra stuff for a warning */ + if (!egg_debug_is_console ()) + printf ("*** WARNING ***\n"); + pk_print_line (func, file, line, buffer, CONSOLE_RED); + + g_free(buffer); +} + +/** + * egg_error_real: + **/ +void +egg_error_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...) +{ + va_list args; + gchar *buffer = NULL; + + va_start (args, format); + g_vasprintf (&buffer, format, args); + va_end (args); + + /* do extra stuff for a warning */ + if (!egg_debug_is_console ()) + printf ("*** ERROR ***\n"); + pk_print_line (func, file, line, buffer, CONSOLE_RED); + g_free(buffer); + + /* we want to fix this! */ + egg_debug_backtrace (); + + exit (1); +} + +/** + * egg_debug_enabled: + * + * Returns: TRUE if we have debugging enabled + **/ +gboolean +egg_debug_enabled (void) +{ + const gchar *env; + env = g_getenv (EGG_VERBOSE); + return (g_strcmp0 (env, "1") == 0); +} + +/** + * egg_debug_is_logging: + * + * Returns: TRUE if we have logging enabled + **/ +gboolean +egg_debug_is_logging (void) +{ + const gchar *env; + env = g_getenv (EGG_LOGGING); + return (g_strcmp0 (env, "1") == 0); +} + +/** + * egg_debug_is_console: + * + * Returns: TRUE if we have debugging enabled + **/ +gboolean +egg_debug_is_console (void) +{ + const gchar *env; + env = g_getenv (EGG_CONSOLE); + return (g_strcmp0 (env, "1") == 0); +} + +/** + * egg_debug_set_logging: + **/ +void +egg_debug_set_logging (gboolean enabled) +{ + if (enabled) + g_setenv (EGG_LOGGING, "1", TRUE); + else + g_setenv (EGG_LOGGING, "0", TRUE); + + if (egg_debug_is_logging ()) + egg_debug ("logging to %s", EGG_LOG_FILE); +} + +/** + * egg_debug_init: + * @debug: If we should print out verbose logging + **/ +void +egg_debug_init (gboolean debug) +{ + /* check if we are on console */ + if (isatty (fileno (stdout)) == 1) + g_setenv (EGG_CONSOLE, "1", FALSE); + else + g_setenv (EGG_CONSOLE, "0", FALSE); + if (debug) + g_setenv (EGG_VERBOSE, "1", FALSE); + else + g_setenv (EGG_VERBOSE, "0", FALSE); + egg_debug ("Verbose debugging %i (on console %i)%s", egg_debug_enabled (), egg_debug_is_console (), EGG_VERBOSE); +} + diff --git a/applets/inhibit/egg-debug.h b/applets/inhibit/egg-debug.h new file mode 100644 index 0000000..fdfb02b --- /dev/null +++ b/applets/inhibit/egg-debug.h @@ -0,0 +1,83 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2007-2008 Richard Hughes <[email protected]> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __EGG_DEBUG_H +#define __EGG_DEBUG_H + +#include <stdarg.h> +#include <glib.h> + +G_BEGIN_DECLS + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +/** + * egg_debug: + * + * Non critical debugging + */ +#define egg_debug(...) egg_debug_real (__func__, __FILE__, __LINE__, __VA_ARGS__) + +/** + * egg_warning: + * + * Important debugging + */ +#define egg_warning(...) egg_warning_real (__func__, __FILE__, __LINE__, __VA_ARGS__) + +/** + * egg_error: + * + * Critical debugging, with exit + */ +#define egg_error(...) egg_error_real (__func__, __FILE__, __LINE__, __VA_ARGS__) + +#elif defined(__GNUC__) && __GNUC__ >= 3 +#define egg_debug(...) egg_debug_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) +#define egg_warning(...) egg_warning_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) +#define egg_error(...) egg_error_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) +#else +#define egg_debug(...) +#define egg_warning(...) +#define egg_error(...) +#endif + +void egg_debug_init (gboolean debug); +void egg_debug_set_logging (gboolean enabled); +gboolean egg_debug_enabled (void); +gboolean egg_debug_is_logging (void); +gboolean egg_debug_is_console (void); +void egg_debug_backtrace (void); +void egg_debug_real (const gchar *func, + const gchar *file, + int line, + const gchar *format, ...) __attribute__((format (printf,4,5))); +void egg_warning_real (const gchar *func, + const gchar *file, + int line, + const gchar *format, ...) __attribute__((format (printf,4,5))); +void egg_error_real (const gchar *func, + const gchar *file, + int line, + const gchar *format, ...) G_GNUC_NORETURN __attribute__((format (printf,4,5))); + +G_END_DECLS + +#endif /* __EGG_DEBUG_H */ diff --git a/applets/inhibit/gpm-common.c b/applets/inhibit/gpm-common.c new file mode 100644 index 0000000..0d0e536 --- /dev/null +++ b/applets/inhibit/gpm-common.c @@ -0,0 +1,210 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2005-2007 Richard Hughes <[email protected]> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <glib.h> +#include <string.h> +#include <glib/gi18n.h> +#include <gdk/gdk.h> +#include <gtk/gtk.h> + +#include "egg-debug.h" +#include "gpm-common.h" + +/** + * gpm_get_timestring: + * @time_secs: The time value to convert in seconds + * @cookie: The cookie we are looking for + * + * Returns a localised timestring + * + * Return value: The time string, e.g. "2 hours 3 minutes" + **/ +gchar * +gpm_get_timestring (guint time_secs) +{ + char* timestring = NULL; + gint hours; + gint minutes; + + /* Add 0.5 to do rounding */ + minutes = (int) ( ( time_secs / 60.0 ) + 0.5 ); + + if (minutes == 0) { + timestring = g_strdup (_("Unknown time")); + return timestring; + } + + if (minutes < 60) { + timestring = g_strdup_printf (ngettext ("%i minute", + "%i minutes", + minutes), minutes); + return timestring; + } + + hours = minutes / 60; + minutes = minutes % 60; + + if (minutes == 0) + timestring = g_strdup_printf (ngettext ( + "%i hour", + "%i hours", + hours), hours); + else + /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes" + * Swap order with "%2$s %2$i %1$s %1$i if needed */ + timestring = g_strdup_printf (_("%i %s %i %s"), + hours, ngettext ("hour", "hours", hours), + minutes, ngettext ("minute", "minutes", minutes)); + return timestring; +} + +/** + * gpm_icon_policy_from_string: + **/ +GpmIconPolicy +gpm_icon_policy_from_string (const gchar *policy) +{ + if (policy == NULL) + return GPM_ICON_POLICY_NEVER; + if (g_strcmp0 (policy, "always") == 0) + return GPM_ICON_POLICY_ALWAYS; + if (g_strcmp0 (policy, "present") == 0) + return GPM_ICON_POLICY_PRESENT; + if (g_strcmp0 (policy, "charge") == 0) + return GPM_ICON_POLICY_CHARGE; + if (g_strcmp0 (policy, "low") == 0) + return GPM_ICON_POLICY_LOW; + if (g_strcmp0 (policy, "critical") == 0) + return GPM_ICON_POLICY_CRITICAL; + if (g_strcmp0 (policy, "never") == 0) + return GPM_ICON_POLICY_NEVER; + return GPM_ICON_POLICY_NEVER; +} + +/** + * gpm_icon_policy_to_string: + **/ +const gchar * +gpm_icon_policy_to_string (GpmIconPolicy policy) +{ + if (policy == GPM_ICON_POLICY_ALWAYS) + return "always"; + if (policy == GPM_ICON_POLICY_PRESENT) + return "present"; + if (policy == GPM_ICON_POLICY_CHARGE) + return "charge"; + if (policy == GPM_ICON_POLICY_LOW) + return "low"; + if (policy == GPM_ICON_POLICY_CRITICAL) + return "critical"; + if (policy == GPM_ICON_POLICY_NEVER) + return "never"; + return "never"; +} + +/** + * gpm_action_policy_from_string: + **/ +GpmActionPolicy +gpm_action_policy_from_string (const gchar *policy) +{ + if (policy == NULL) + return GPM_ACTION_POLICY_NOTHING; + if (g_strcmp0 (policy, "blank") == 0) + return GPM_ACTION_POLICY_BLANK; + if (g_strcmp0 (policy, "shutdown") == 0) + return GPM_ACTION_POLICY_SHUTDOWN; + if (g_strcmp0 (policy, "suspend") == 0) + return GPM_ACTION_POLICY_SUSPEND; + if (g_strcmp0 (policy, "hibernate") == 0) + return GPM_ACTION_POLICY_HIBERNATE; + if (g_strcmp0 (policy, "interactive") == 0) + return GPM_ACTION_POLICY_INTERACTIVE; + return GPM_ACTION_POLICY_NOTHING; +} + +/** + * gpm_action_policy_to_string: + **/ +const gchar * +gpm_action_policy_to_string (GpmActionPolicy policy) +{ + if (policy == GPM_ACTION_POLICY_BLANK) + return "blank"; + if (policy == GPM_ACTION_POLICY_SHUTDOWN) + return "shutdown"; + if (policy == GPM_ACTION_POLICY_SUSPEND) + return "suspend"; + if (policy == GPM_ACTION_POLICY_HIBERNATE) + return "hibernate"; + if (policy == GPM_ACTION_POLICY_INTERACTIVE) + return "interactive"; + return "nothing"; +} + +/** + * gpm_help_display: + * @link_id: Subsection of mate-power-manager help section + **/ +void +gpm_help_display (const gchar *link_id) +{ + GError *error = NULL; + gchar *uri; + + if (link_id != NULL) + uri = g_strconcat ("ghelp:mate-power-manager?", link_id, NULL); + else + uri = g_strdup ("ghelp:mate-power-manager"); + + gtk_show_uri (NULL, uri, GDK_CURRENT_TIME, &error); + + if (error != NULL) { + GtkWidget *d; + d = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error->message); + gtk_dialog_run (GTK_DIALOG(d)); + gtk_widget_destroy (d); + g_error_free (error); + } + g_free (uri); +} + +/*************************************************************************** + *** MAKE CHECK TESTS *** + ***************************************************************************/ +#ifdef EGG_TEST +#include "egg-test.h" + +void +gpm_common_test (gpointer data) +{ + EggTest *test = (EggTest *) data; + if (egg_test_start (test, "GpmCommon") == FALSE) + return; + + egg_test_end (test); +} + +#endif + diff --git a/applets/inhibit/gpm-common.h b/applets/inhibit/gpm-common.h new file mode 100644 index 0000000..e2733a8 --- /dev/null +++ b/applets/inhibit/gpm-common.h @@ -0,0 +1,183 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2005-2007 Richard Hughes <[email protected]> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __GPMCOMMON_H +#define __GPMCOMMON_H + +#include <glib.h> + +G_BEGIN_DECLS + +#define GPM_DBUS_SERVICE "org.mate.PowerManager" +#define GPM_DBUS_INTERFACE "org.mate.PowerManager" +#define GPM_DBUS_INTERFACE_BACKLIGHT "org.mate.PowerManager.Backlight" +#define GPM_DBUS_PATH "/org/mate/PowerManager" +#define GPM_DBUS_PATH_BACKLIGHT "/org/mate/PowerManager/Backlight" + +/* common descriptions of this program */ +#define GPM_NAME _("Power Manager") +#define GPM_DESCRIPTION _("Power Manager for the MATE desktop") + +/* help location */ +#define GPM_HOMEPAGE_URL "http://www.mate.org/projects/mate-power-manager/" +#define GPM_BUGZILLA_URL "http://bugzilla.mate.org/buglist.cgi?product=mate-power-manager" +#define GPM_FAQ_URL "http://live.mate.org/MatePowerManager/Faq" + +/* change general/installed_schema whenever adding or moving keys */ +#define GPM_CONF_SCHEMA_ID 3 + +#define GPM_CONF_DIR "/apps/mate-power-manager" + +/* actions */ +#define GPM_CONF_ACTIONS_CRITICAL_UPS GPM_CONF_DIR "/actions/critical_ups" +#define GPM_CONF_ACTIONS_CRITICAL_BATT GPM_CONF_DIR "/actions/critical_battery" +#define GPM_CONF_ACTIONS_LOW_UPS GPM_CONF_DIR "/actions/low_ups" +#define GPM_CONF_ACTIONS_SLEEP_TYPE_AC GPM_CONF_DIR "/actions/sleep_type_ac" +#define GPM_CONF_ACTIONS_SLEEP_TYPE_BATT GPM_CONF_DIR "/actions/sleep_type_battery" +#define GPM_CONF_ACTIONS_SLEEP_WHEN_CLOSED GPM_CONF_DIR "/actions/event_when_closed_battery" + +/* backlight stuff */ +#define GPM_CONF_BACKLIGHT_ENABLE GPM_CONF_DIR "/backlight/enable" +#define GPM_CONF_BACKLIGHT_BATTERY_REDUCE GPM_CONF_DIR "/backlight/battery_reduce" +#define GPM_CONF_BACKLIGHT_DPMS_METHOD_AC GPM_CONF_DIR "/backlight/dpms_method_ac" +#define GPM_CONF_BACKLIGHT_DPMS_METHOD_BATT GPM_CONF_DIR "/backlight/dpms_method_battery" +#define GPM_CONF_BACKLIGHT_IDLE_BRIGHTNESS GPM_CONF_DIR "/backlight/idle_brightness" +#define GPM_CONF_BACKLIGHT_IDLE_DIM_AC GPM_CONF_DIR "/backlight/idle_dim_ac" +#define GPM_CONF_BACKLIGHT_IDLE_DIM_BATT GPM_CONF_DIR "/backlight/idle_dim_battery" +#define GPM_CONF_BACKLIGHT_IDLE_DIM_TIME GPM_CONF_DIR "/backlight/idle_dim_time" +#define GPM_CONF_BACKLIGHT_BRIGHTNESS_AC GPM_CONF_DIR "/backlight/brightness_ac" +#define GPM_CONF_BACKLIGHT_BRIGHTNESS_DIM_BATT GPM_CONF_DIR "/backlight/brightness_dim_battery" + +/* buttons */ +#define GPM_CONF_BUTTON_LID_AC GPM_CONF_DIR "/buttons/lid_ac" +#define GPM_CONF_BUTTON_LID_BATT GPM_CONF_DIR "/buttons/lid_battery" +#define GPM_CONF_BUTTON_SUSPEND GPM_CONF_DIR "/buttons/suspend" +#define GPM_CONF_BUTTON_HIBERNATE GPM_CONF_DIR "/buttons/hibernate" +#define GPM_CONF_BUTTON_POWER GPM_CONF_DIR "/buttons/power" + +/* general */ +#define GPM_CONF_SCHEMA_VERSION GPM_CONF_DIR "/general/installed_schema" +#define GPM_CONF_USE_TIME_POLICY GPM_CONF_DIR "/general/use_time_for_policy" +#define GPM_CONF_USE_PROFILE_TIME GPM_CONF_DIR "/general/use_profile_time" +#define GPM_CONF_NETWORKMANAGER_SLEEP GPM_CONF_DIR "/general/network_sleep" +#define GPM_CONF_IDLE_CHECK_CPU GPM_CONF_DIR "/general/check_type_cpu" +#define GPM_CONF_LAPTOP_USES_EXT_MON GPM_CONF_DIR "/general/using_external_monitor" + +/* lock */ +#define GPM_CONF_LOCK_USE_SCREENSAVER GPM_CONF_DIR "/lock/use_screensaver_settings" +#define GPM_CONF_LOCK_ON_BLANK_SCREEN GPM_CONF_DIR "/lock/blank_screen" +#define GPM_CONF_LOCK_ON_SUSPEND GPM_CONF_DIR "/lock/suspend" +#define GPM_CONF_LOCK_ON_HIBERNATE GPM_CONF_DIR "/lock/hibernate" +#define GPM_CONF_LOCK_MATE_KEYRING_SUSPEND GPM_CONF_DIR "/lock/mate_keyring_suspend" +#define GPM_CONF_LOCK_MATE_KEYRING_HIBERNATE GPM_CONF_DIR "/lock/mate_keyring_hibernate" + +/* disks */ +#define GPM_CONF_DISKS_SPINDOWN_ENABLE_AC GPM_CONF_DIR "/disks/spindown_enable_ac" +#define GPM_CONF_DISKS_SPINDOWN_ENABLE_BATT GPM_CONF_DIR "/disks/spindown_enable_battery" +#define GPM_CONF_DISKS_SPINDOWN_TIMEOUT_AC GPM_CONF_DIR "/disks/spindown_timeout_ac" +#define GPM_CONF_DISKS_SPINDOWN_TIMEOUT_BATT GPM_CONF_DIR "/disks/spindown_timeout_battery" + +/* notify */ +#define GPM_CONF_NOTIFY_PERHAPS_RECALL GPM_CONF_DIR "/notify/perhaps_recall" +#define GPM_CONF_NOTIFY_LOW_CAPACITY GPM_CONF_DIR "/notify/low_capacity" +#define GPM_CONF_NOTIFY_DISCHARGING GPM_CONF_DIR "/notify/discharging" +#define GPM_CONF_NOTIFY_FULLY_CHARGED GPM_CONF_DIR "/notify/fully_charged" +#define GPM_CONF_NOTIFY_SLEEP_FAILED GPM_CONF_DIR "/notify/sleep_failed" +#define GPM_CONF_NOTIFY_SLEEP_FAILED_URI GPM_CONF_DIR "/notify/sleep_failed_uri" +#define GPM_CONF_NOTIFY_LOW_POWER GPM_CONF_DIR "/notify/low_power" + +/* statistics */ +#define GPM_CONF_STATS_SHOW_AXIS_LABELS GPM_CONF_DIR "/statistics/show_axis_labels" +#define GPM_CONF_STATS_SHOW_EVENTS GPM_CONF_DIR "/statistics/show_events" +#define GPM_CONF_STATS_SMOOTH_DATA GPM_CONF_DIR "/statistics/smooth_data" +#define GPM_CONF_STATS_GRAPH_TYPE GPM_CONF_DIR "/statistics/graph_type" +#define GPM_CONF_STATS_MAX_TIME GPM_CONF_DIR "/statistics/data_max_time" + +/* thresholds */ +#define GPM_CONF_THRESH_PERCENTAGE_LOW GPM_CONF_DIR "/thresholds/percentage_low" +#define GPM_CONF_THRESH_PERCENTAGE_CRITICAL GPM_CONF_DIR "/thresholds/percentage_critical" +#define GPM_CONF_THRESH_PERCENTAGE_ACTION GPM_CONF_DIR "/thresholds/percentage_action" +#define GPM_CONF_THRESH_TIME_LOW GPM_CONF_DIR "/thresholds/time_low" +#define GPM_CONF_THRESH_TIME_CRITICAL GPM_CONF_DIR "/thresholds/time_critical" +#define GPM_CONF_THRESH_TIME_ACTION GPM_CONF_DIR "/thresholds/time_action" + +/* timeout */ +#define GPM_CONF_TIMEOUT_SLEEP_COMPUTER_AC GPM_CONF_DIR "/timeout/sleep_computer_ac" +#define GPM_CONF_TIMEOUT_SLEEP_COMPUTER_BATT GPM_CONF_DIR "/timeout/sleep_computer_battery" +#define GPM_CONF_TIMEOUT_SLEEP_COMPUTER_UPS GPM_CONF_DIR "/timeout/sleep_computer_ups" +#define GPM_CONF_TIMEOUT_SLEEP_DISPLAY_AC GPM_CONF_DIR "/timeout/sleep_display_ac" +#define GPM_CONF_TIMEOUT_SLEEP_DISPLAY_BATT GPM_CONF_DIR "/timeout/sleep_display_battery" +#define GPM_CONF_TIMEOUT_SLEEP_DISPLAY_UPS GPM_CONF_DIR "/timeout/sleep_display_ups" + +/* ui */ +#define GPM_CONF_UI_ICON_POLICY GPM_CONF_DIR "/ui/icon_policy" +#define GPM_CONF_UI_ENABLE_SOUND GPM_CONF_DIR "/ui/enable_sound" +#define GPM_CONF_UI_SHOW_ACTIONS GPM_CONF_DIR "/ui/show_actions" + +/* new info binary */ +#define GPM_CONF_INFO_HISTORY_TIME "/apps/mate-power-manager/info/history_time" +#define GPM_CONF_INFO_HISTORY_TYPE "/apps/mate-power-manager/info/history_type" +#define GPM_CONF_INFO_HISTORY_GRAPH_SMOOTH "/apps/mate-power-manager/info/history_graph_smooth" +#define GPM_CONF_INFO_HISTORY_GRAPH_POINTS "/apps/mate-power-manager/info/history_graph_points" +#define GPM_CONF_INFO_STATS_TYPE "/apps/mate-power-manager/info/stats_type" +#define GPM_CONF_INFO_STATS_GRAPH_SMOOTH "/apps/mate-power-manager/info/stats_graph_smooth" +#define GPM_CONF_INFO_STATS_GRAPH_POINTS "/apps/mate-power-manager/info/stats_graph_points" +#define GPM_CONF_INFO_PAGE_NUMBER "/apps/mate-power-manager/info/page_number" +#define GPM_CONF_INFO_LAST_DEVICE "/apps/mate-power-manager/info/last_device" + +/* mate-screensaver */ +#define GS_CONF_DIR "/apps/mate-screensaver" +#define GS_PREF_LOCK_ENABLED GS_CONF_DIR "/lock_enabled" + +/* mate-session */ +#define GPM_CONF_IDLE_DELAY "/desktop/mate/session/idle_delay" + +typedef enum { + GPM_ICON_POLICY_ALWAYS, + GPM_ICON_POLICY_PRESENT, + GPM_ICON_POLICY_CHARGE, + GPM_ICON_POLICY_LOW, + GPM_ICON_POLICY_CRITICAL, + GPM_ICON_POLICY_NEVER +} GpmIconPolicy; + +typedef enum { + GPM_ACTION_POLICY_BLANK, + GPM_ACTION_POLICY_SUSPEND, + GPM_ACTION_POLICY_SHUTDOWN, + GPM_ACTION_POLICY_HIBERNATE, + GPM_ACTION_POLICY_INTERACTIVE, + GPM_ACTION_POLICY_NOTHING +} GpmActionPolicy; + +gchar *gpm_get_timestring (guint time); +GpmIconPolicy gpm_icon_policy_from_string (const gchar *policy); +const gchar *gpm_icon_policy_to_string (GpmIconPolicy policy); +GpmActionPolicy gpm_action_policy_from_string (const gchar *policy); +const gchar *gpm_action_policy_to_string (GpmActionPolicy policy); +void gpm_help_display (const gchar *link_id); +#ifdef EGG_TEST +void gpm_common_test (gpointer data); +#endif + +G_END_DECLS + +#endif /* __GPMCOMMON_H */ diff --git a/applets/inhibit/inhibit-applet.c b/applets/inhibit/inhibit-applet.c new file mode 100644 index 0000000..e976c60 --- /dev/null +++ b/applets/inhibit/inhibit-applet.c @@ -0,0 +1,688 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * MATE Power Manager Inhibit Applet + * Copyright (C) 2006 Benjamin Canou <[email protected]> + * Copyright (C) 2006-2009 Richard Hughes <[email protected]> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/* FIXME: gdk_gc_* needs porting to cairo */ +#undef GDK_DISABLE_DEPRECATED + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <mate-panel-applet.h> +#include <gtk/gtk.h> +#include <glib-object.h> +#include <dbus/dbus-glib.h> + +#include "egg-debug.h" +#include "egg-dbus-monitor.h" +#include "gpm-common.h" + +#define GPM_TYPE_INHIBIT_APPLET (gpm_inhibit_applet_get_type ()) +#define GPM_INHIBIT_APPLET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_INHIBIT_APPLET, GpmInhibitApplet)) +#define GPM_INHIBIT_APPLET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_INHIBIT_APPLET, GpmInhibitAppletClass)) +#define GPM_IS_INHIBIT_APPLET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_INHIBIT_APPLET)) +#define GPM_IS_INHIBIT_APPLET_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_INHIBIT_APPLET)) +#define GPM_INHIBIT_APPLET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_INHIBIT_APPLET, GpmInhibitAppletClass)) + +typedef struct{ + MatePanelApplet parent; + /* applet state */ + guint cookie; + /* the icon and a cache for size*/ + GdkPixbuf *icon; + gint icon_width, icon_height; + /* connection to g-p-m */ + DBusGProxy *proxy; + DBusGConnection *connection; + EggDbusMonitor *monitor; + guint level; + /* a cache for panel size */ + gint size; +} GpmInhibitApplet; + +typedef struct{ + MatePanelAppletClass parent_class; +} GpmInhibitAppletClass; + +GType gpm_inhibit_applet_get_type (void); + +#define GS_DBUS_SERVICE "org.mate.SessionManager" +#define GS_DBUS_PATH "/org/mate/SessionManager" +#define GS_DBUS_INTERFACE "org.mate.SessionManager" + +static void gpm_inhibit_applet_class_init (GpmInhibitAppletClass *klass); +static void gpm_inhibit_applet_init (GpmInhibitApplet *applet); + +G_DEFINE_TYPE (GpmInhibitApplet, gpm_inhibit_applet, PANEL_TYPE_APPLET) + +static void gpm_applet_get_icon (GpmInhibitApplet *applet); +static void gpm_applet_check_size (GpmInhibitApplet *applet); +static gboolean gpm_applet_draw_cb (GpmInhibitApplet *applet); +static void gpm_applet_update_tooltip (GpmInhibitApplet *applet); +static gboolean gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event); +static void gpm_applet_dialog_about_cb (MateComponentUIComponent *uic, gpointer data, const gchar *verbname); +static gboolean gpm_applet_matecomponent_cb (MatePanelApplet *_applet, const gchar *iid, gpointer data); +static void gpm_applet_destroy_cb (GtkObject *object); + +#define GPM_INHIBIT_APPLET_OAFID "OAFIID:MATE_InhibitApplet" +#define GPM_INHIBIT_APPLET_FACTORY_OAFID "OAFIID:MATE_InhibitApplet_Factory" +#define GPM_INHIBIT_APPLET_ICON_INHIBIT "gpm-inhibit" +#define GPM_INHIBIT_APPLET_ICON_INVALID "gpm-inhibit-invalid" +#define GPM_INHIBIT_APPLET_ICON_UNINHIBIT "gpm-hibernate" +#define GPM_INHIBIT_APPLET_NAME _("Power Manager Inhibit Applet") +#define GPM_INHIBIT_APPLET_DESC _("Allows user to inhibit automatic power saving.") +#define MATE_PANEL_APPLET_VERTICAL(p) \ + (((p) == MATE_PANEL_APPLET_ORIENT_LEFT) || ((p) == MATE_PANEL_APPLET_ORIENT_RIGHT)) + + +/** cookie is returned as an unsigned integer */ +static gboolean +gpm_applet_inhibit (GpmInhibitApplet *applet, + const gchar *appname, + const gchar *reason, + guint *cookie) +{ + GError *error = NULL; + gboolean ret; + + g_return_val_if_fail (cookie != NULL, FALSE); + + if (applet->proxy == NULL) { + egg_warning ("not connected\n"); + return FALSE; + } + + ret = dbus_g_proxy_call (applet->proxy, "Inhibit", &error, + G_TYPE_STRING, appname, + G_TYPE_UINT, 0, /* xid */ + G_TYPE_STRING, reason, + G_TYPE_UINT, 1+2+4+8, /* logoff, switch, suspend, and idle */ + G_TYPE_INVALID, + G_TYPE_UINT, cookie, + G_TYPE_INVALID); + if (error) { + g_debug ("ERROR: %s", error->message); + g_error_free (error); + *cookie = 0; + } + if (!ret) { + /* abort as the DBUS method failed */ + g_warning ("Inhibit failed!"); + } + + return ret; +} + +static gboolean +gpm_applet_uninhibit (GpmInhibitApplet *applet, + guint cookie) +{ + GError *error = NULL; + gboolean ret; + + if (applet->proxy == NULL) { + egg_warning ("not connected"); + return FALSE; + } + + ret = dbus_g_proxy_call (applet->proxy, "Uninhibit", &error, + G_TYPE_UINT, cookie, + G_TYPE_INVALID, + G_TYPE_INVALID); + if (error) { + g_debug ("ERROR: %s", error->message); + g_error_free (error); + } + if (!ret) { + /* abort as the DBUS method failed */ + g_warning ("Uninhibit failed!"); + } + + return ret; +} +#if 0 +static gboolean +gpm_applet_has_inhibit (GpmInhibitApplet *applet, + gboolean *has_inhibit) +{ + GError *error = NULL; + gboolean ret; + DBusGProxy *proxy; + + proxy = egg_dbus_proxy_get_proxy (applet->gproxy); + if (proxy == NULL) { + g_warning ("not connected"); + return FALSE; + } + + ret = dbus_g_proxy_call (proxy, "HasInhibit", &error, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, has_inhibit, + G_TYPE_INVALID); + if (error) { + g_debug ("ERROR: %s", error->message); + g_error_free (error); + } + if (!ret) { + /* abort as the DBUS method failed */ + g_warning ("HasInhibit failed!"); + } + + return ret; +} +#endif + +/** + * gpm_applet_get_icon: + * @applet: Inhibit applet instance + * + * retrieve an icon from stock with a size adapted to panel + **/ +static void +gpm_applet_get_icon (GpmInhibitApplet *applet) +{ + const gchar *icon; + + /* free */ + if (applet->icon != NULL) { + g_object_unref (applet->icon); + applet->icon = NULL; + } + + if (applet->size <= 2) { + return; + } + + /* get icon */ + if (applet->proxy == NULL) { + icon = GPM_INHIBIT_APPLET_ICON_INVALID; + } else if (applet->cookie > 0) { + icon = GPM_INHIBIT_APPLET_ICON_INHIBIT; + } else { + icon = GPM_INHIBIT_APPLET_ICON_UNINHIBIT; + } + applet->icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + icon, + applet->size - 2, + 0, + NULL); + + /* update size cache */ + applet->icon_height = gdk_pixbuf_get_height (applet->icon); + applet->icon_width = gdk_pixbuf_get_width (applet->icon); +} + +/** + * gpm_applet_check_size: + * @applet: Inhibit applet instance + * + * check if panel size has changed and applet adapt size + **/ +static void +gpm_applet_check_size (GpmInhibitApplet *applet) +{ + GtkAllocation allocation; + + /* we don't use the size function here, but the yet allocated size because the + size value is false (kind of rounded) */ + gtk_widget_get_allocation (GTK_WIDGET (applet), &allocation); + if (MATE_PANEL_APPLET_VERTICAL(mate_panel_applet_get_orient (MATE_PANEL_APPLET (applet)))) { + if (applet->size != allocation.width) { + applet->size = allocation.width; + gpm_applet_get_icon (applet); + gtk_widget_set_size_request (GTK_WIDGET(applet), applet->size, applet->icon_height + 2); + } + /* Adjusting incase the icon size has changed */ + if (allocation.height < applet->icon_height + 2) { + gtk_widget_set_size_request (GTK_WIDGET(applet), applet->size, applet->icon_height + 2); + } + } else { + if (applet->size != allocation.height) { + applet->size = allocation.height; + gpm_applet_get_icon (applet); + gtk_widget_set_size_request (GTK_WIDGET(applet), applet->icon_width + 2, applet->size); + } + /* Adjusting incase the icon size has changed */ + if (allocation.width < applet->icon_width + 2) { + gtk_widget_set_size_request (GTK_WIDGET(applet), applet->icon_width + 2, applet->size); + } + } +} + +/** + * gpm_applet_draw_cb: + * @applet: Inhibit applet instance + * + * draws applet content (background + icon) + **/ +static gboolean +gpm_applet_draw_cb (GpmInhibitApplet *applet) +{ + gint w, h, bg_type; + GdkColor color; + GdkGC *gc; + GdkPixmap *background; + GtkAllocation allocation; + + if (gtk_widget_get_window (GTK_WIDGET(applet)) == NULL) { + return FALSE; + } + + /* Clear the window so we can draw on it later */ + gdk_window_clear(gtk_widget_get_window (GTK_WIDGET (applet))); + + /* retrieve applet size */ + gpm_applet_get_icon (applet); + gpm_applet_check_size (applet); + if (applet->size <= 2) { + return FALSE; + } + + /* if no icon, then don't try to display */ + if (applet->icon == NULL) { + return FALSE; + } + + gtk_widget_get_allocation (GTK_WIDGET (applet), &allocation); + w = allocation.width; + h = allocation.height; + + gc = gdk_gc_new (gtk_widget_get_window (GTK_WIDGET(applet))); + + /* draw pixmap background */ + bg_type = mate_panel_applet_get_background (MATE_PANEL_APPLET (applet), &color, &background); + if (bg_type == PANEL_PIXMAP_BACKGROUND) { + /* fill with given background pixmap */ + gdk_draw_drawable (gtk_widget_get_window (GTK_WIDGET(applet)), gc, background, 0, 0, 0, 0, w, h); + } + + /* draw color background */ + if (bg_type == PANEL_COLOR_BACKGROUND) { + gdk_gc_set_rgb_fg_color (gc,&color); + gdk_gc_set_fill (gc,GDK_SOLID); + gdk_draw_rectangle (gtk_widget_get_window (GTK_WIDGET(applet)), gc, TRUE, 0, 0, w, h); + } + + /* draw icon at center */ + gdk_draw_pixbuf (gtk_widget_get_window (GTK_WIDGET(applet)), gc, applet->icon, + 0, 0, (w - applet->icon_width)/2, (h - applet->icon_height)/2, + applet->icon_width, applet->icon_height, + GDK_RGB_DITHER_NONE, 0, 0); + + return TRUE; +} + +/** + * gpm_applet_change_background_cb: + * + * Enqueues an expose event (don't know why it's not the default behaviour) + **/ +static void +gpm_applet_change_background_cb (GpmInhibitApplet *applet, + MatePanelAppletBackgroundType arg1, + GdkColor *arg2, GdkPixmap *arg3, gpointer data) +{ + gtk_widget_queue_draw (GTK_WIDGET (applet)); +} + +/** + * gpm_applet_update_tooltip: + * @applet: Inhibit applet instance + * + * sets tooltip's content (percentage or disabled) + **/ +static void +gpm_applet_update_tooltip (GpmInhibitApplet *applet) +{ + const gchar *buf; + if (applet->proxy == NULL) { + buf = _("Cannot connect to mate-power-manager"); + } else { + if (applet->cookie > 0) { + buf = _("Automatic sleep inhibited"); + } else { + buf = _("Automatic sleep enabled"); + } + } + gtk_widget_set_tooltip_text (GTK_WIDGET(applet), buf); +} + +/** + * gpm_applet_click_cb: + * @applet: Inhibit applet instance + * + * pops and unpops + **/ +static gboolean +gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event) +{ + /* react only to left mouse button */ + if (event->button != 1) { + return FALSE; + } + + if (applet->cookie > 0) { + g_debug ("uninhibiting %u", applet->cookie); + gpm_applet_uninhibit (applet, applet->cookie); + applet->cookie = 0; + } else { + g_debug ("inhibiting"); + gpm_applet_inhibit (applet, + GPM_INHIBIT_APPLET_NAME, + _("Manual inhibit"), + &(applet->cookie)); + } + /* update icon */ + gpm_applet_get_icon (applet); + gpm_applet_check_size (applet); + gpm_applet_update_tooltip (applet); + gpm_applet_draw_cb (applet); + + return TRUE; +} + +/** + * gpm_applet_dialog_about_cb: + * + * displays about dialog + **/ +static void +gpm_applet_dialog_about_cb (MateComponentUIComponent *uic, gpointer data, const gchar *verbname) +{ + GtkAboutDialog *about; + + GdkPixbuf *logo = + gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + GPM_INHIBIT_APPLET_ICON_INHIBIT, + 128, 0, NULL); + + static const gchar *authors[] = { + "Benjamin Canou <[email protected]>", + "Richard Hughes <[email protected]>", + NULL + }; + const char *documenters [] = { + NULL + }; + const char *license[] = { + N_("Licensed under the GNU General Public License Version 2"), + N_("Power Manager is free software; you can redistribute it and/or\n" + "modify it under the terms of the GNU General Public License\n" + "as published by the Free Software Foundation; either version 2\n" + "of the License, or (at your option) any later version."), + N_("Power Manager is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details."), + N_("You should have received a copy of the GNU General Public License\n" + "along with this program; if not, write to the Free Software\n" + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n" + "02110-1301, USA.") + }; + const char *translator_credits = NULL; + char *license_trans; + + license_trans = g_strconcat (_(license[0]), "\n\n", _(license[1]), "\n\n", + _(license[2]), "\n\n", _(license[3]), "\n", NULL); + + about = (GtkAboutDialog*) gtk_about_dialog_new (); + gtk_about_dialog_set_program_name (about, GPM_INHIBIT_APPLET_NAME); + gtk_about_dialog_set_version (about, VERSION); + gtk_about_dialog_set_copyright (about, _("Copyright \xc2\xa9 2006-2007 Richard Hughes")); + gtk_about_dialog_set_comments (about, GPM_INHIBIT_APPLET_DESC); + gtk_about_dialog_set_authors (about, authors); + gtk_about_dialog_set_documenters (about, documenters); + gtk_about_dialog_set_translator_credits (about, translator_credits); + gtk_about_dialog_set_logo (about, logo); + gtk_about_dialog_set_license (about, license_trans); + gtk_about_dialog_set_website (about, GPM_HOMEPAGE_URL); + + g_signal_connect (G_OBJECT(about), "response", + G_CALLBACK(gtk_widget_destroy), NULL); + + gtk_widget_show (GTK_WIDGET(about)); + + g_free (license_trans); + g_object_unref (logo); +} + +/** + * gpm_applet_help_cb: + * + * open gpm help + **/ +static void +gpm_applet_help_cb (MateComponentUIComponent *uic, gpointer data, const gchar *verbname) +{ + gpm_help_display ("applets-inhibit"); +} + +/** + * gpm_applet_destroy_cb: + * @object: Class instance to destroy + **/ +static void +gpm_applet_destroy_cb (GtkObject *object) +{ + GpmInhibitApplet *applet = GPM_INHIBIT_APPLET(object); + + if (applet->monitor != NULL) { + g_object_unref (applet->monitor); + } + if (applet->icon != NULL) { + g_object_unref (applet->icon); + } +} + +/** + * gpm_inhibit_applet_class_init: + * @klass: Class instance + **/ +static void +gpm_inhibit_applet_class_init (GpmInhibitAppletClass *class) +{ + /* nothing to do here */ +} + + +/** + * gpm_inhibit_applet_dbus_connect: + **/ +gboolean +gpm_inhibit_applet_dbus_connect (GpmInhibitApplet *applet) +{ + GError *error = NULL; + + if (applet->connection == NULL) { + egg_debug ("get connection\n"); + g_clear_error (&error); + applet->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (error != NULL) { + egg_warning ("Could not connect to DBUS daemon: %s", error->message); + g_error_free (error); + applet->connection = NULL; + return FALSE; + } + } + if (applet->proxy == NULL) { + egg_debug ("get proxy\n"); + g_clear_error (&error); + applet->proxy = dbus_g_proxy_new_for_name_owner (applet->connection, + GS_DBUS_SERVICE, + GS_DBUS_PATH, + GS_DBUS_INTERFACE, + &error); + if (error != NULL) { + egg_warning ("Cannot connect, maybe the daemon is not running: %s\n", error->message); + g_error_free (error); + applet->proxy = NULL; + return FALSE; + } + } + return TRUE; +} + +/** + * gpm_inhibit_applet_dbus_disconnect: + **/ +gboolean +gpm_inhibit_applet_dbus_disconnect (GpmInhibitApplet *applet) +{ + if (applet->proxy != NULL) { + egg_debug ("removing proxy\n"); + g_object_unref (applet->proxy); + applet->proxy = NULL; + /* we have no inhibit, these are not persistant across reboots */ + applet->cookie = 0; + } + return TRUE; +} + +/** + * monitor_connection_cb: + * @proxy: The dbus raw proxy + * @status: The status of the service, where TRUE is connected + * @screensaver: This class instance + **/ +static void +monitor_connection_cb (EggDbusMonitor *monitor, + gboolean status, + GpmInhibitApplet *applet) +{ + if (status) { + gpm_inhibit_applet_dbus_connect (applet); + gpm_applet_update_tooltip (applet); + gpm_applet_get_icon (applet); + gpm_applet_draw_cb (applet); + } else { + gpm_inhibit_applet_dbus_disconnect (applet); + gpm_applet_update_tooltip (applet); + gpm_applet_get_icon (applet); + gpm_applet_draw_cb (applet); + } +} + +/** + * gpm_inhibit_applet_init: + * @applet: Inhibit applet instance + **/ +static void +gpm_inhibit_applet_init (GpmInhibitApplet *applet) +{ + DBusGConnection *connection; + + /* initialize fields */ + applet->size = 0; + applet->icon = NULL; + applet->cookie = 0; + applet->connection = NULL; + applet->proxy = NULL; + + /* Add application specific icons to search path */ + gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), + GPM_DATA G_DIR_SEPARATOR_S "icons"); + + applet->monitor = egg_dbus_monitor_new (); + g_signal_connect (applet->monitor, "connection-changed", + G_CALLBACK (monitor_connection_cb), applet); + connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); + egg_dbus_monitor_assign (applet->monitor, connection, GS_DBUS_SERVICE); + gpm_inhibit_applet_dbus_connect (applet); + + /* prepare */ + mate_panel_applet_set_flags (MATE_PANEL_APPLET (applet), MATE_PANEL_APPLET_EXPAND_MINOR); + + /* show */ + gtk_widget_show_all (GTK_WIDGET(applet)); + + /* set appropriate size and load icon accordingly */ + gpm_applet_draw_cb (applet); + + /* connect */ + g_signal_connect (G_OBJECT(applet), "button-press-event", + G_CALLBACK(gpm_applet_click_cb), NULL); + + g_signal_connect (G_OBJECT(applet), "expose-event", + G_CALLBACK(gpm_applet_draw_cb), NULL); + + /* We use g_signal_connect_after because letting the panel draw + * the background is the only way to have the correct + * background when a theme defines a background picture. */ + g_signal_connect_after (G_OBJECT(applet), "expose-event", + G_CALLBACK(gpm_applet_draw_cb), NULL); + + g_signal_connect (G_OBJECT(applet), "change-background", + G_CALLBACK(gpm_applet_change_background_cb), NULL); + + g_signal_connect (G_OBJECT(applet), "change-orient", + G_CALLBACK(gpm_applet_draw_cb), NULL); + + g_signal_connect (G_OBJECT(applet), "destroy", + G_CALLBACK(gpm_applet_destroy_cb), NULL); +} + +/** + * gpm_applet_matecomponent_cb: + * @_applet: GpmInhibitApplet instance created by the matecomponent factory + * @iid: MateComponent id + * + * the function called by matecomponent factory after creation + **/ +static gboolean +gpm_applet_matecomponent_cb (MatePanelApplet *_applet, const gchar *iid, gpointer data) +{ + GpmInhibitApplet *applet = GPM_INHIBIT_APPLET(_applet); + + static MateComponentUIVerb verbs [] = { + MATECOMPONENT_UI_VERB ("About", gpm_applet_dialog_about_cb), + MATECOMPONENT_UI_VERB ("Help", gpm_applet_help_cb), + MATECOMPONENT_UI_VERB_END + }; + + if (strcmp (iid, GPM_INHIBIT_APPLET_OAFID) != 0) { + return FALSE; + } + + mate_panel_applet_setup_menu_from_file (MATE_PANEL_APPLET (applet), + DATADIR, + "MATE_InhibitApplet.xml", + NULL, verbs, applet); + gpm_applet_draw_cb (applet); + return TRUE; +} + +/** + * this generates a main with a matecomponent factory + **/ +MATE_PANEL_APPLET_MATECOMPONENT_FACTORY + (/* the factory iid */ + GPM_INHIBIT_APPLET_FACTORY_OAFID, + /* generates brighness applets instead of regular mate applets */ + GPM_TYPE_INHIBIT_APPLET, + /* the applet name and version */ + "InhibitApplet", VERSION, + /* our callback (with no user data) */ + gpm_applet_matecomponent_cb, NULL); |