diff options
37 files changed, 5958 insertions, 1733 deletions
@@ -47,9 +47,8 @@ src/status-provider-telepathy-marshal.h src/status-provider-mc5-marshal.c src/status-provider-mc5-marshal.h data/indicator-session.schemas -src/users-service-client.h -src/users-service-marshal.c -src/users-service-marshal.h +src/accounts-service-client.h +src/accounts-service-user-client.h indicator-session-[0-9].[0-9].[0-9].tar.gz indicator-session-[0-9].[0-9].tar.gz indicator-session-[0-9].[0-9].[0-9].tar.gz.asc @@ -58,5 +57,145 @@ src/consolekit-manager-client.h src/gen-session-dbus.xml.c src/gen-session-dbus.xml.h src/upower-client.h -src/gdm-local-display-factory-client.h +src/display-manager-client.h src/consolekit-session-client.h +INSTALL +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +depcomp +indicator-session-0.2.93.tar.gz +indicator-session-0.2.93.tar.gz.asc +indicator-session-0.2.94.tar.gz +install-sh +libtool +ltmain.sh +missing +mkinstalldirs +stamp-h1 +data/Makefile +data/Makefile.in +data/extra-sessions/Makefile +data/extra-sessions/Makefile.in +data/extra-sessions/classic-desktop.desktop +data/icons/Makefile +data/icons/Makefile.in +data/icons/16x16/Makefile +data/icons/16x16/Makefile.in +data/icons/16x16/actions/Makefile +data/icons/16x16/actions/Makefile.in +data/icons/16x16/status/Makefile +data/icons/16x16/status/Makefile.in +data/icons/22x22/Makefile +data/icons/22x22/Makefile.in +data/icons/22x22/actions/Makefile +data/icons/22x22/actions/Makefile.in +data/icons/22x22/status/Makefile +data/icons/22x22/status/Makefile.in +data/icons/24x24/Makefile +data/icons/24x24/Makefile.in +data/icons/24x24/actions/Makefile +data/icons/24x24/actions/Makefile.in +data/icons/24x24/status/Makefile +data/icons/24x24/status/Makefile.in +data/icons/32x32/Makefile +data/icons/32x32/Makefile.in +data/icons/32x32/actions/Makefile +data/icons/32x32/actions/Makefile.in +data/icons/32x32/status/Makefile +data/icons/32x32/status/Makefile.in +data/icons/scalable/Makefile +data/icons/scalable/Makefile.in +data/icons/scalable/actions/Makefile +data/icons/scalable/actions/Makefile.in +data/icons/scalable/status/Makefile +data/icons/scalable/status/Makefile.in +po/.intltool-merge-cache +po/Makefile +po/Makefile.in +po/Makefile.in.in +po/POTFILES +po/am.gmo +po/ar.gmo +po/ast.gmo +po/az.gmo +po/be.gmo +po/bg.gmo +po/bn.gmo +po/br.gmo +po/bs.gmo +po/ca.gmo +po/crh.gmo +po/cs.gmo +po/csb.gmo +po/cv.gmo +po/da.gmo +po/de.gmo +po/el.gmo +po/en_AU.gmo +po/en_CA.gmo +po/en_GB.gmo +po/eo.gmo +po/es.gmo +po/et.gmo +po/eu.gmo +po/fa.gmo +po/fi.gmo +po/fr.gmo +po/gl.gmo +po/gu.gmo +po/he.gmo +po/hi.gmo +po/hr.gmo +po/hu.gmo +po/id.gmo +po/is.gmo +po/it.gmo +po/ja.gmo +po/kk.gmo +po/kn.gmo +po/ko.gmo +po/ku.gmo +po/lb.gmo +po/lt.gmo +po/lv.gmo +po/mr.gmo +po/ms.gmo +po/nb.gmo +po/nl.gmo +po/nn.gmo +po/oc.gmo +po/pa.gmo +po/pl.gmo +po/pt.gmo +po/pt_BR.gmo +po/ro.gmo +po/ru.gmo +po/si.gmo +po/sk.gmo +po/sl.gmo +po/sq.gmo +po/sr.gmo +po/stamp-it +po/sv.gmo +po/te.gmo +po/th.gmo +po/tr.gmo +po/ug.gmo +po/uk.gmo +po/vi.gmo +po/zh_CN.gmo +po/zh_HK.gmo +po/zh_TW.gmo +src/Makefile +modified: +.bzrignore +src/libsession_la-user-widget.lo diff --git a/configure.ac b/configure.ac index afa82f0..19cc4bc 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(src/indicator-session.c) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-session, 0.2.17) +AM_INIT_AUTOMAKE(indicator-session, 0.3.1) AM_MAINTAINER_MODE @@ -31,20 +31,20 @@ INDICATOR_REQUIRED_VERSION=0.3.19 DBUSMENUGTK_REQUIRED_VERSION=0.3.91 POLKIT_REQUIRED_VERSION=0.92 -AC_ARG_WITH([indicator-gtk], - [AS_HELP_STRING([--with-indicator-gtk], +AC_ARG_WITH([gtk], + [AS_HELP_STRING([--with-gtk], [Which version of gtk to use for the indicator @<:@default=3@:>@])], [], - [with_indicator_gtk=3]) + [with_gtk=3]) -AS_IF([test "x$with_indicator_gtk" = x3], +AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(APPLET, gtk+-3.0 >= $GTK3_REQUIRED_VERSION - indicator3 >= $INDICATOR_REQUIRED_VERSION + indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) ], - [test "x$with_indicator_gtk" = x2], + [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION - indicator >= $INDICATOR_REQUIRED_VERSION + indicator-0.4 >= $INDICATOR_REQUIRED_VERSION dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) ], [AC_MSG_FAILURE([Value for --with-indicator-gtk was neither 2 nor 3])] @@ -54,17 +54,36 @@ AC_SUBST(APPLET_LIBS) DBUSMENUGLIB_REQUIRED_VERSION=0.1.1 -PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION - dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION - dbus-glib-1 - gio-unix-2.0 - indicator3 >= $INDICATOR_REQUIRED_VERSION) +AS_IF([test "x$with_gtk" = x3], + [PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION + dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + dbus-glib-1 + gudev-1.0 + gio-unix-2.0 + indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION) + ], + [test "x$with_gtk" = x2], + [PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION + dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + gudev-1.0 + dbus-glib-1 + gio-unix-2.0 + indicator-0.4 >= $INDICATOR_REQUIRED_VERSION) + ] +) AC_SUBST(SESSIONERVICE_CFLAGS) AC_SUBST(SESSIONERVICE_LIBS) -PKG_CHECK_MODULES(GTKLOGOUTHELPER, gtk+-3.0 >= $GTK3_REQUIRED_VERSION - polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) +AS_IF([test "x$with_gtk" = x3], + [PKG_CHECK_MODULES(GTKLOGOUTHELPER, gtk+-3.0 >= $GTK3_REQUIRED_VERSION + polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) + ], + [test "x$with_gtk" = x2], + [PKG_CHECK_MODULES(GTKLOGOUTHELPER, gtk+-2.0 >= $GTK_REQUIRED_VERSION + polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) + ] +) AC_SUBST(GTKLOGOUTHELPER_CFLAGS) @@ -94,12 +113,12 @@ AC_ARG_ENABLE(localinstall, AS_HELP_STRING([--enable-localinstall], [install all if test "x$with_localinstall" = "xyes"; then INDICATORDIR="${libdir}/indicators/2/" INDICATORICONSDIR="${datadir}/indicator-applet/icons/" -elif test "x$with_indicator_gtk" = x2; then - INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator` - INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator` +elif test "x$with_gtk" = x2; then + INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator-0.4` + INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator-0.4` else - INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3` - INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3` + INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3-0.4` + INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3-0.4` fi AC_SUBST(INDICATORDIR) AC_SUBST(INDICATORICONSDIR) @@ -179,5 +198,6 @@ AC_MSG_NOTICE([ SUS Indicator Configuration: Prefix: $prefix - Indicator GTK: $with_indicator_gtk + Indicator Dir: $INDICATORDIR + Indicator GTK: $with_gtk ]) diff --git a/po/POTFILES.in b/po/POTFILES.in index c2256c1..08eff5f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -7,3 +7,6 @@ src/gtk-logout-helper.c src/dialog.c src/indicator-session.c src/session-service.c +src/apt-watcher.c +src/device-menu-mgr.c +src/user-menu-mgr.c diff --git a/src/Makefile.am b/src/Makefile.am index 0317de7..3bfd790 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,10 @@ libsession_la_SOURCES = \ gen-session-dbus.xml.h \ dbus-shared-names.h \ dbusmenu-shared.h \ - users-service-client.h + user-widget.c \ + user-widget.h \ + accounts-service-client.h \ + accounts-service-user-client.h libsession_la_CFLAGS = \ $(APPLET_CFLAGS) \ -Wall -Werror \ @@ -22,33 +25,47 @@ libsession_la_CFLAGS = \ libsession_la_LIBADD = $(APPLET_LIBS) libsession_la_LDFLAGS = -module -avoid-version -consolekit-manager-client.h: $(srcdir)/consolekit-manager.xml +consolekit-manager-client.h: $(srcdir)/org.freedesktop.ConsoleKit.Manager.xml dbus-binding-tool \ --prefix=_consolekit_manager_client \ --mode=glib-client \ --output=consolekit-manager-client.h \ - $(srcdir)/consolekit-manager.xml + $(srcdir)/org.freedesktop.ConsoleKit.Manager.xml -consolekit-session-client.h: $(srcdir)/consolekit-session.xml +consolekit-seat-client.h: $(srcdir)/org.freedesktop.ConsoleKit.Seat.xml + dbus-binding-tool \ + --prefix=_consolekit_seat_client \ + --mode=glib-client \ + --output=consolekit-seat-client.h \ + $(srcdir)/org.freedesktop.ConsoleKit.Seat.xml + +consolekit-session-client.h: $(srcdir)/org.freedesktop.ConsoleKit.Session.xml dbus-binding-tool \ --prefix=_consolekit_session_client \ --mode=glib-client \ --output=consolekit-session-client.h \ - $(srcdir)/consolekit-session.xml + $(srcdir)/org.freedesktop.ConsoleKit.Session.xml -gdm-local-display-factory-client.h: $(srcdir)/gdm-local-display-factory.xml +display-manager-client.h: $(srcdir)/display-manager.xml dbus-binding-tool \ --prefix=_gdm_local_display_factory_client \ --mode=glib-client \ - --output=gdm-local-display-factory-client.h \ - $(srcdir)/gdm-local-display-factory.xml + --output=display-manager-client.h \ + $(srcdir)/display-manager.xml + +accounts-service-client.h: $(srcdir)/accounts-service.xml + dbus-binding-tool \ + --prefix=_accounts_service_client \ + --mode=glib-client \ + --output=accounts-service-client.h \ + $(srcdir)/accounts-service.xml -users-service-client.h: $(srcdir)/users-service.xml +accounts-service-user-client.h: $(srcdir)/accounts-service-user.xml dbus-binding-tool \ - --prefix=_users_service_client \ + --prefix=_accounts_service_user_client \ --mode=glib-client \ - --output=users-service-client.h \ - $(srcdir)/users-service.xml + --output=accounts-service-user-client.h \ + $(srcdir)/accounts-service-user.xml upower-client.h: $(srcdir)/upower.xml dbus-binding-tool \ @@ -57,16 +74,6 @@ upower-client.h: $(srcdir)/upower.xml --output=upower-client.h \ $(srcdir)/upower.xml -users-service-marshal.h: $(srcdir)/users-service.list - glib-genmarshal --header \ - --prefix=_users_service_marshal $(srcdir)/users-service.list \ - > users-service-marshal.h - -users-service-marshal.c: $(srcdir)/users-service.list - glib-genmarshal --body \ - --prefix=_users_service_marshal $(srcdir)/users-service.list \ - > users-service-marshal.c - gen-%.xml.c: %.xml @echo "Building $@ from $<" @echo "const char * _$(subst -,_,$(subst .,_,$(basename $(notdir $<)))) = " > $@ @@ -92,7 +99,17 @@ indicator_session_service_SOURCES = \ gconf-helper.c \ users-service-dbus.h \ users-service-dbus.c \ - users-service-marshal.c + user-menu-mgr.h \ + user-menu-mgr.c \ + device-menu-mgr.h \ + device-menu-mgr.c \ + apt-watcher.h \ + apt-watcher.c \ + apt-transaction.h \ + apt-transaction.c \ + udev-mgr.h \ + udev-mgr.c \ + sane-rules.h indicator_session_service_CFLAGS = \ $(SESSIONSERVICE_CFLAGS) \ $(GCONF_CFLAGS) \ @@ -133,23 +150,24 @@ gtk_logout_helper_LDADD = \ BUILT_SOURCES = \ consolekit-manager-client.h \ + consolekit-seat-client.h \ consolekit-session-client.h \ - gdm-local-display-factory-client.h \ + display-manager-client.h \ gen-session-dbus.xml.c \ gen-session-dbus.xml.h \ upower-client.h \ - users-service-client.h \ - users-service-marshal.h \ - users-service-marshal.c + accounts-service-client.h \ + accounts-service-user-client.h EXTRA_DIST = \ - consolekit-manager.xml \ - consolekit-session.xml \ - gdm-local-display-factory.xml \ + org.freedesktop.ConsoleKit.Manager.xml \ + org.freedesktop.ConsoleKit.Seat.xml \ + org.freedesktop.ConsoleKit.Session.xml \ + display-manager.xml \ session-dbus.xml \ upower.xml \ - users-service.xml \ - users-service.list + accounts-service.xml \ + accounts-service-user.xml CLEANFILES = \ $(BUILT_SOURCES) diff --git a/src/accounts-service-user.xml b/src/accounts-service-user.xml new file mode 100644 index 0000000..bd4cb21 --- /dev/null +++ b/src/accounts-service-user.xml @@ -0,0 +1,689 @@ +<!DOCTYPE node PUBLIC +"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" > +<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> + <interface name="org.freedesktop.Accounts.User"> + + <method name="SetUserName"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="name" direction="in" type="s"> + <doc:doc> + <doc:summary> + The new username. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users username. Note that it is usually not allowed + to have multiple users with the same username. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the username of any user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetRealName"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="name" direction="in" type="s"> + <doc:doc> + <doc:summary> + The new name, typically in the form "Firstname Lastname". + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users real name. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.change-own-user-data</doc:term> + <doc:definition>To change his own name</doc:definition> + </doc:item> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the name of another user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetEmail"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="email" direction="in" type="s"> + <doc:doc> + <doc:summary> + The new email address. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users email address. + </doc:para> + <doc:para> + Note that setting an email address in the AccountsService is + not the same as configuring a mail client. Mail clients might + default to email address that is configured here, though. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.change-own-user-data</doc:term> + <doc:definition>To change his own email address</doc:definition> + </doc:item> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the email address of another user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetLanguage"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="language" direction="in" type="s"> + <doc:doc> + <doc:summary> + The new language, as a locale specification like "de_DE.UTF-8". + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users language. + </doc:para> + <doc:language> + The expectation is that display managers will start the + users session with this locale. + </doc:language> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.change-own-user-data</doc:term> + <doc:definition>To change his own language</doc:definition> + </doc:item> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the language of another user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetLocation"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="location" direction="in" type="s"> + <doc:doc> + <doc:summary> + The new location as a freeform string. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users location. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.change-own-user-data</doc:term> + <doc:definition>To change his own location</doc:definition> + </doc:item> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the location of another user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetHomeDirectory"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="homedir" direction="in" type="s"> + <doc:doc> + <doc:summary> + The new homedir as an absolute path. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users home directory. + </doc:para> + <doc:para> + Note that changing the users home directory moves all the content + from the old location to the new one, and is potentially an + expensive operation. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the home directory of a user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetShell"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="shell" direction="in" type="s"> + <doc:doc> + <doc:summary> + The new user shell. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users shell. + </doc:para> + <doc:para> + Note that setting the shell to a non-allowed program may + prevent the user from logging in. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the shell of a user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetIconFile"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="filename" direction="in" type="s"> + <doc:doc> + <doc:summary> + The absolute filename of a png file to use as the users icon. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets the users icon. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.change-own-user-data</doc:term> + <doc:definition>To change his own icon</doc:definition> + </doc:item> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the icon of another user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetLocked"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="locked" direction="in" type="b"> + <doc:doc> + <doc:summary> + Whether to lock or unlock the users account. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Locks or unlocks a users account. + </doc:para> + <doc:para> + Locking an account prevents the user from logging in. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To lock or unlock user accounts</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetAccountType"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="accountType" direction="in" type="i"> + <doc:doc> + <doc:summary> + The new account type, encoded as an integer: + <doc:list> + <doc:item> + <doc:term>0</doc:term> + <doc:definition>Standard user</doc:definition> + </doc:item> + <doc:item> + <doc:term>1</doc:term> + <doc:definition>Administrator</doc:definition> + </doc:item> + <doc:item> + <doc:term>2</doc:term> + <doc:definition>Supervised user</doc:definition> + </doc:item> + </doc:list> + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Changes the users account type. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change an account type</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetPasswordMode"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="mode" direction="in" type="i"> + <doc:doc> + <doc:summary> + The new password mode, encoded as an integer: + <doc:list> + <doc:item> + <doc:term>0</doc:term> + <doc:definition>Regular password</doc:definition> + </doc:item> + <doc:item> + <doc:term>1</doc:term> + <doc:definition>Password must be set at next login</doc:definition> + </doc:item> + <doc:item> + <doc:term>2</doc:term> + <doc:definition>No password</doc:definition> + </doc:item> + </doc:list> + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Changes the users password mode. + </doc:para> + <doc:para> + Note that changing the password mode has the side-effect of + unlocking the account. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change a users password mode</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetPassword"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="password" direction="in" type="s"> + <doc:doc> + <doc:summary> + The crypted password. + </doc:summary> + </doc:doc> + </arg> + <arg name="hint" direction="in" type="s"> + <doc:doc> + <doc:summary> + The password hint. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Sets a new password for this user. + </doc:para> + <doc:para> + Note that setting a password has the side-effect of + unlocking the account. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.user-administration</doc:term> + <doc:definition>To change the password of a user</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="SetAutomaticLogin"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="enabled" direction="in" type="b"> + <doc:doc> + <doc:summary> + Whether to enable automatic login for this user. + </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Enables or disables automatic login for a user. + </doc:para> + <doc:para> + Note that usually only one user can have automatic login + enabled, so turning it on for a user will disable it for + the previously configured autologin user. + </doc:para> + </doc:description> + <doc:permission> + The caller needs one of the following PolicyKit authorizations: + <doc:list> + <doc:item> + <doc:term>org.freedesktop.accounts.set-login-option</doc:term> + <doc:definition>To change the login screen configuration</doc:definition> + </doc:item> + </doc:list> + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <property name="Uid" type="t" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The uid of the user. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="UserName" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The username of the user. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="RealName" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The users real name. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="AccountType" type="i" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The users account type, encoded as an integer: + <doc:list> + <doc:item> + <doc:term>0</doc:term> + <doc:definition>Standard user</doc:definition> + </doc:item> + <doc:item> + <doc:term>1</doc:term> + <doc:definition>Administrator</doc:definition> + </doc:item> + <doc:item> + <doc:term>2</doc:term> + <doc:definition>Supervised user</doc:definition> + </doc:item> + </doc:list> + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="HomeDirectory" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The users home directory. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="Shell" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The users shell. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="Email" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The email address. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="Language" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The users language, as a locale specification like "de_DE.UTF-8". + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="Location" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The users location. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="LoginFrequency" type="t" access="read"> + <doc:doc> + <doc:description> + <doc:para> + How often the user has logged in. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="IconFile" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The filename of a png file containing the users icon. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="Locked" type="b" access="read"> + <doc:doc> + <doc:description> + <doc:para> + Whether the users account is locked. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="PasswordMode" type="i" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The password mode for the user account, encoded as an integer: + <doc:list> + <doc:item> + <doc:term>0</doc:term> + <doc:definition>Regular password</doc:definition> + </doc:item> + <doc:item> + <doc:term>1</doc:term> + <doc:definition>Password must be set at next login</doc:definition> + </doc:item> + <doc:item> + <doc:term>2</doc:term> + <doc:definition>No password</doc:definition> + </doc:item> + </doc:list> + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="PasswordHint" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The password hint for the user. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <property name="AutomaticLogin" type="b" access="read"> + <doc:doc> + <doc:description> + <doc:para> + Whether automatic login is enabled for the user. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <signal name="Changed"> + <doc:doc> + <doc:description> + <doc:para> + Emitted when the user is changed. + </doc:para> + </doc:description> + </doc:doc> + </signal> + + </interface> +</node> diff --git a/src/accounts-service.xml b/src/accounts-service.xml new file mode 100644 index 0000000..9c19761 --- /dev/null +++ b/src/accounts-service.xml @@ -0,0 +1,194 @@ +<!DOCTYPE node PUBLIC +"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" > +<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> + <interface name="org.freedesktop.Accounts"> + + <!-- ************************************************************ --> + + <method name="ListCachedUsers"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="users" direction="out" type="ao"> + <doc:doc><doc:summary>Object paths of cached users</doc:summary></doc:doc> + </arg> + + <doc:doc> + <doc:description> + <doc:para> + Lists users which have logged into the system locally before. + This is not meant to return an exhaustive list of all users. + It is possible for <doc:ref type="method" to="Accounts.FindUserByName">FindUserByName()</doc:ref> + to return a user that's not on the list. + </doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="FindUserById"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="id" direction="in" type="x"> + <doc:doc><doc:summary>The uid to look up</doc:summary></doc:doc> + </arg> + <arg name="user" direction="out" type="o"> + <doc:doc><doc:summary>Object path of user</doc:summary></doc:doc> + </arg> + + <doc:doc> + <doc:description> + <doc:para> + Finds a user by uid. + </doc:para> + </doc:description> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if no user with the given uid exists</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="FindUserByName"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="name" direction="in" type="s"> + <doc:doc><doc:summary>The username to look up</doc:summary></doc:doc> + </arg> + <arg name="user" direction="out" type="o"> + <doc:doc><doc:summary>Object path of user</doc:summary></doc:doc> + </arg> + + <doc:doc> + <doc:description> + <doc:para> + Finds a user by its username. + </doc:para> + </doc:description> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if no user with the given username exists</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="CreateUser"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="name" direction="in" type="s"> + <doc:doc><doc:summary>The username for the new user</doc:summary></doc:doc> + </arg> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="fullname" direction="in" type="s"> + <doc:doc><doc:summary>The real name for the new user</doc:summary></doc:doc> + </arg> + <arg name="user" direction="out" type="o"> + <doc:doc><doc:summary>Object path of the new user</doc:summary></doc:doc> + </arg> + <arg name="accountType" direction="in" type="i"> + <doc:doc> + <doc:summary>The account type, encoded as an integer</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Creates a new user account. + </doc:para> + <doc:para> + The accountType argument can take the following values: + </doc:para> + <doc:list> + <doc:item> + <doc:term>0</doc:term> + <doc:definition>Standard user</doc:definition> + </doc:item> + <doc:item> + <doc:term>1</doc:term> + <doc:definition>Administrator</doc:definition> + </doc:item> + <doc:item> + <doc:term>2</doc:term> + <doc:definition>Supervised user</doc:definition> + </doc:item> + </doc:list> + </doc:description> + <doc:permission> + The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization. + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <method name="DeleteUser"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="id" direction="in" type="x"> + <doc:doc><doc:summary>The uid to delete</doc:summary></doc:doc> + </arg> + <arg name="removeFiles" direction="in" type="b"> + <doc:doc><doc:summary>Whether to remove the users files</doc:summary></doc:doc> + </arg> + + <doc:doc> + <doc:description> + <doc:para> + Deletes a user account. + </doc:para> + </doc:description> + <doc:permission> + The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization. + </doc:permission> + <doc:errors> + <doc:error name="org.freedesktop.Accounts.Error.PermissionDenied">if the caller lacks the appropriate PolicyKit authorization</doc:error> + <doc:error name="org.freedesktop.Accounts.Error.Failed">if the operation failed</doc:error> + </doc:errors> + </doc:doc> + </method> + + <signal name="UserAdded"> + <arg name="user" type="o"> + <doc:doc><doc:summary>Object path of the user that was added.</doc:summary></doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Emitted when a user is added. + </doc:para> + </doc:description> + </doc:doc> + </signal> + + <signal name="UserDeleted"> + <arg name="user" type="o"> + <doc:doc><doc:summary>Object path of the user that was deleted.</doc:summary></doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Emitted when a user is deleted. + </doc:para> + </doc:description> + </doc:doc> + </signal> + + <signal name="UserChanged"> + <arg name="user" type="o"> + <doc:doc><doc:summary>Object path of the user that was changed.</doc:summary></doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para> + Emitted when a user is changed. + </doc:para> + </doc:description> + </doc:doc> + </signal> + + <property name="DaemonVersion" type="s" access="read"> + <doc:doc> + <doc:description> + <doc:para> + The version of the running daemon. + </doc:para> + </doc:description> + </doc:doc> + </property> + + </interface> +</node> diff --git a/src/apt-transaction.c b/src/apt-transaction.c new file mode 100644 index 0000000..be1c57b --- /dev/null +++ b/src/apt-transaction.c @@ -0,0 +1,265 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#include <gio/gio.h> + +#include "apt-transaction.h" +#include "dbus-shared-names.h" + +static void apt_transaction_investigate (AptTransaction* self); +static void apt_transaction_simulate_transaction_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data); +static void apt_transaction_receive_signal (GDBusProxy * proxy, + gchar * sender_name, + gchar * signal_name, + GVariant * parameters, + gpointer user_data); +static void apt_transaction_finish_proxy_setup (GObject *source_object, + GAsyncResult *res, + gpointer user_data); + +struct _AptTransaction +{ + GObject parent_instance; + GDBusProxy * proxy; + GCancellable * proxy_cancel; + gchar* id; + TransactionType type; +}; + +enum { + UPDATE, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT); + +static void +apt_transaction_init (AptTransaction *self) +{ + self->proxy = NULL; + self->id = NULL; + self->proxy_cancel = g_cancellable_new(); +} + +static void +apt_transaction_finalize (GObject *object) +{ + AptTransaction* self = APT_TRANSACTION(object); + g_signal_handlers_disconnect_by_func (G_OBJECT (self->proxy), + G_CALLBACK (apt_transaction_receive_signal), + self); + if (self->proxy != NULL){ + g_object_unref (self->proxy); + self->proxy = NULL; + } + g_free (self->id); + G_OBJECT_CLASS (apt_transaction_parent_class)->finalize (object); +} + +static void +apt_transaction_class_init (AptTransactionClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + object_class->finalize = apt_transaction_finalize; + + signals[UPDATE] = g_signal_new("state-update", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, G_TYPE_INT); +} + +// TODO: you don't need this additional helper +// Just GObject properties properly +static void +apt_transaction_investigate (AptTransaction* self) +{ + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.debian.apt", + self->id, + "org.debian.apt.transaction", + self->proxy_cancel, + apt_transaction_finish_proxy_setup, + self); +} + +static void +apt_transaction_finish_proxy_setup (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + g_return_if_fail (APT_IS_TRANSACTION (user_data)); + AptTransaction* self = APT_TRANSACTION(user_data); + GError * error = NULL; + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (self->proxy_cancel != NULL) { + g_object_unref(self->proxy_cancel); + self->proxy_cancel = NULL; + } + + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", + "org.debian.apt", error->message); + g_error_free(error); + return; + } + + self->proxy = proxy; + + g_signal_connect (G_OBJECT(self->proxy), + "g-signal", + G_CALLBACK (apt_transaction_receive_signal), + self); + + if (self->type == SIMULATION){ + g_dbus_proxy_call (self->proxy, + "Simulate", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_transaction_simulate_transaction_cb, + self); + } +} + +static void +apt_transaction_receive_signal (GDBusProxy * proxy, + gchar * sender_name, + gchar * signal_name, + GVariant * parameters, + gpointer user_data) +{ + g_return_if_fail (APT_IS_TRANSACTION (user_data)); + AptTransaction* self = APT_TRANSACTION(user_data); + AptState current_state = DONT_KNOW; + + if (g_strcmp0(signal_name, "PropertyChanged") == 0 && self->type == SIMULATION) + { + gchar* prop_name= NULL; + GVariant* value = NULL; + g_variant_get (parameters, "(sv)", &prop_name, &value); + g_debug ("transaction prop update - prop = %s", prop_name); + + if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) == TRUE){ + gchar* key = NULL; + g_variant_get (value, "s", &key); + g_debug ("transaction prop update - value = %s", key); + } + + if (g_strcmp0 (prop_name, "Dependencies") == 0){ + + gchar** install = NULL; + gchar** reinstall = NULL; + gchar** remove = NULL; + gchar** purge = NULL; + gchar** upgrade = NULL; + gchar** downgrade = NULL; + gchar** keep = NULL; + g_variant_get (value, "(asasasasasasas)", &install, + &reinstall, &remove, &purge, &upgrade, &downgrade, + &keep); + /* + g_debug ("upgrade package length %i", g_strv_length(upgrade)); + g_debug ("install package length %i", g_strv_length(install)); + g_debug ("reinstall package length %i", g_strv_length(reinstall)); + g_debug ("remove package length %i", g_strv_length(remove)); + g_debug ("purge package length %i", g_strv_length(purge)); + */ + gboolean upgrade_needed = (g_strv_length(upgrade) > 1) || + (g_strv_length(install) > 1) || + (g_strv_length(reinstall) > 1) || + (g_strv_length(remove) > 1) || + (g_strv_length(purge) > 1); + if (upgrade_needed == TRUE){ + current_state = UPDATES_AVAILABLE; + } + else{ + current_state = UP_TO_DATE; + } + } + } + else if (g_strcmp0(signal_name, "PropertyChanged") == 0 && + self->type == REAL) + { + GVariant* role = g_dbus_proxy_get_cached_property (self->proxy, + "Role"); + if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){ + gchar* current_role = NULL; + g_variant_get (role, "s", ¤t_role); + g_debug ("Current transaction role = %s", current_role); + if (g_strcmp0 (current_role, "role-commit-packages") == 0 || + g_strcmp0 (current_role, "role-upgrade-system") == 0){ + g_debug ("UPGRADE IN PROGRESS"); + current_state = UPGRADE_IN_PROGRESS; + } + } + } + else if (g_strcmp0(signal_name, "Finished") == 0) + { + g_debug ("TRANSACTION Finished"); + current_state = FINISHED; + } + // Finally send out the state update + if (current_state != DONT_KNOW){ + g_signal_emit (self, + signals[UPDATE], + 0, + current_state); + } + g_variant_unref (parameters); +} + +static void +apt_transaction_simulate_transaction_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data) +{ + GError * error = NULL; + if (error != NULL) { + g_warning ("unable to complete the simulate call"); + g_error_free (error); + return; + } +} +TransactionType +apt_transaction_get_transaction_type (AptTransaction* self) +{ + return self->type; +} + +AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t) +{ + AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL); + tr->id = transaction_id; + tr->type = t; + g_debug ("Apt transaction new id = %s", tr->id); + apt_transaction_investigate (tr); + return tr; +} diff --git a/src/apt-transaction.h b/src/apt-transaction.h new file mode 100644 index 0000000..9e4370d --- /dev/null +++ b/src/apt-transaction.h @@ -0,0 +1,49 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _APT_TRANSACTION_H_ +#define _APT_TRANSACTION_H_ + +#include <glib-object.h> +#include "dbus-shared-names.h" + +G_BEGIN_DECLS + +#define APT_TYPE_TRANSACTION (apt_transaction_get_type ()) +#define APT_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APT_TYPE_TRANSACTION, AptTransaction)) +#define APT_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APT_TYPE_TRANSACTION, AptTransactionClass)) +#define APT_IS_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APT_TYPE_TRANSACTION)) +#define APT_IS_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APT_TYPE_TRANSACTION)) +#define APT_TRANSACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APT_TYPE_TRANSACTION, AptTransactionClass)) + +typedef struct _AptTransactionClass AptTransactionClass; +typedef struct _AptTransaction AptTransaction; + +struct _AptTransactionClass +{ + GObjectClass parent_class; +}; + +AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t); +TransactionType apt_transaction_get_transaction_type (AptTransaction* self); +GType apt_transaction_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _APT_TRANSACTION_H_ */ diff --git a/src/apt-watcher.c b/src/apt-watcher.c new file mode 100644 index 0000000..7d706a0 --- /dev/null +++ b/src/apt-watcher.c @@ -0,0 +1,348 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#include <gio/gio.h> +#include <glib/gi18n.h> +#include "apt-watcher.h" +#include "apt-transaction.h" + +static guint watcher_id; + +struct _AptWatcher +{ + GObject parent_instance; + GCancellable * proxy_cancel; + GDBusProxy * proxy; + SessionDbus* session_dbus_interface; + DbusmenuMenuitem* apt_item; + AptState current_state; + AptTransaction* current_transaction; +}; + +static void +apt_watcher_on_name_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data); +static void +apt_watcher_on_name_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data); +static void fetch_proxy_cb (GObject * object, + GAsyncResult * res, + gpointer user_data); + +static void apt_watcher_upgrade_system_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data); + + +static void apt_watcher_show_apt_dialog (DbusmenuMenuitem* mi, + guint timestamp, + gchar * type); + +static void apt_watcher_signal_cb (GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + gpointer user_data); +static void apt_watcher_manage_transactions (AptWatcher* self, + gchar* transaction_id); + + + +G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT); + +static void +apt_watcher_init (AptWatcher *self) +{ + self->current_state = UP_TO_DATE; + self->proxy_cancel = g_cancellable_new(); + self->proxy = NULL; + self->current_transaction = NULL; + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.debian.apt", + "/org/debian/apt", + "org.debian.apt", + self->proxy_cancel, + fetch_proxy_cb, + self); +} + +static void +apt_watcher_finalize (GObject *object) +{ + g_bus_unwatch_name (watcher_id); + AptWatcher* self = APT_WATCHER (object); + + if (self->proxy != NULL) + g_object_unref (self->proxy); + + G_OBJECT_CLASS (apt_watcher_parent_class)->finalize (object); +} + +static void +apt_watcher_class_init (AptWatcherClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + object_class->finalize = apt_watcher_finalize; +} + +static void +fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) +{ + GError * error = NULL; + + AptWatcher* self = APT_WATCHER(user_data); + g_return_if_fail(self != NULL); + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (self->proxy_cancel != NULL) { + g_object_unref(self->proxy_cancel); + self->proxy_cancel = NULL; + } + + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", + "org.debian.apt", error->message); + g_error_free(error); + return; + } + + self->proxy = proxy; + // Set up the watch. + watcher_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, + "org.debian.apt", + G_BUS_NAME_WATCHER_FLAGS_NONE, + apt_watcher_on_name_appeared, + apt_watcher_on_name_vanished, + self, + NULL); + + g_signal_connect (self->proxy, + "g-signal", + G_CALLBACK(apt_watcher_signal_cb), + self); +} + + +static void +apt_watcher_on_name_appeared (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* watcher = APT_WATCHER (user_data); + + g_print ("Name %s on %s is owned by %s\n", + name, + "the system bus", + name_owner); + + g_dbus_proxy_call (watcher->proxy, + "UpgradeSystem", + g_variant_new("(b)", TRUE), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + apt_watcher_upgrade_system_cb, + user_data); +} + +static void +apt_watcher_on_name_vanished (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + g_debug ("Name %s does not exist or has just vanished", + name); + g_return_if_fail (APT_IS_WATCHER (user_data)); +} + +static void +apt_watcher_upgrade_system_cb (GObject * obj, + GAsyncResult * res, + gpointer user_data) +{ + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + GError * error = NULL; + GVariant * result; + + result = g_dbus_proxy_call_finish(self->proxy, res, &error); + + if (error != NULL) { + g_warning ("unable to complete the UpgradeSystem apt call"); + g_error_free (error); + return; + } + + gchar* transaction_id = NULL; + g_variant_get (result, "(s)", &transaction_id); + + if (transaction_id == NULL){ + g_warning ("apt_watcher_upgrade_system_cb - transaction id is null"); + return; + } + + apt_watcher_manage_transactions (self, transaction_id); + +} + +static void +apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("update-manager", &error)) + { + g_warning("Unable to show update-manager: %s", error->message); + g_error_free(error); + } +} + +static void +apt_watcher_transaction_state_update_cb (AptTransaction* trans, + gint update, + gpointer user_data) +{ + g_debug ("apt-watcher -transaction update %i", update); + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + AptState state = (AptState)update; + + if (state == UP_TO_DATE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + // Simulations don't send a finished signal for some reason + // Anyway from a simulation we just need one state update + // (updates available or not) + if (apt_transaction_get_transaction_type (self->current_transaction) + == SIMULATION){ + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } + } + else if (state == UPDATES_AVAILABLE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Updates Available…")); + // Simulations don't send a finished signal for some reason + // Anyway from a simulation we just need one state update + // (updates available or not) + if (apt_transaction_get_transaction_type (self->current_transaction) + == SIMULATION){ + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } + } + else if (state == UPGRADE_IN_PROGRESS){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Updates Installing…")); + } + else if (state == FINISHED){ + GVariant* reboot_result = g_dbus_proxy_get_cached_property (self->proxy, + "RebootRequired"); + gboolean reboot; + g_variant_get (reboot_result, "b", &reboot); + if (reboot == FALSE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + } + else{ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Reboot Required")); + session_dbus_restart_required (self->session_dbus_interface); + } + g_debug ("Finished with a reboot value of %i", reboot); + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } + self->current_state = state; +} + +static void +apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) +{ + if (self->current_transaction == NULL){ + self->current_transaction = apt_transaction_new (transaction_id, SIMULATION); + g_signal_connect (G_OBJECT(self->current_transaction), + "state-update", + G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + } +} + +// TODO - Ask MVO about this. +// Signal is of type s not sas which is on d-feet !!! +static void apt_watcher_signal_cb ( GDBusProxy* proxy, + gchar* sender_name, + gchar* signal_name, + GVariant* parameters, + gpointer user_data) +{ + g_return_if_fail (APT_IS_WATCHER (user_data)); + AptWatcher* self = APT_WATCHER (user_data); + + g_variant_ref (parameters); + GVariant *value = g_variant_get_child_value (parameters, 0); + + if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){ + gchar* input = NULL; + g_variant_get(value, "s", & input); + if (g_str_has_prefix (input, "/org/debian/apt/transaction/") == TRUE){ + g_debug ("Active Transactions signal - input is null = %i", input == NULL); + + if (self->current_transaction != NULL) + { + g_object_unref (G_OBJECT(self->current_transaction)); + self->current_transaction = NULL; + } + + self->current_transaction = apt_transaction_new (input, REAL); + g_signal_connect (G_OBJECT(self->current_transaction), + "state-update", + G_CALLBACK(apt_watcher_transaction_state_update_cb), self); + } + } + g_variant_unref (parameters); +} + +AptWatcher* apt_watcher_new (SessionDbus* session_dbus, + DbusmenuMenuitem* item) +{ + AptWatcher* watcher = g_object_new (APT_TYPE_WATCHER, NULL); + watcher->session_dbus_interface = session_dbus; + watcher->apt_item = item; + g_signal_connect (G_OBJECT(watcher->apt_item), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(apt_watcher_show_apt_dialog), watcher); + return watcher; +} + diff --git a/src/apt-watcher.h b/src/apt-watcher.h new file mode 100644 index 0000000..7b98a44 --- /dev/null +++ b/src/apt-watcher.h @@ -0,0 +1,60 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _APT_WATCHER_H_ +#define _APT_WATCHER_H_ + +#include <glib-object.h> + +#include <libdbusmenu-glib/client.h> + +#include <gtk/gtk.h> +#if GTK_CHECK_VERSION(3, 0, 0) +#include <libdbusmenu-gtk3/menuitem.h> +#else +#include <libdbusmenu-gtk/menuitem.h> +#endif + +#include "session-dbus.h" + +G_BEGIN_DECLS + +#define APT_TYPE_WATCHER (apt_watcher_get_type ()) +#define APT_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APT_TYPE_WATCHER, AptWatcher)) +#define APT_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APT_TYPE_WATCHER, AptWatcherClass)) +#define APT_IS_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APT_TYPE_WATCHER)) +#define APT_IS_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APT_TYPE_WATCHER)) +#define APT_WATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APT_TYPE_WATCHER, AptWatcherClass)) + +typedef struct _AptWatcherClass AptWatcherClass; +typedef struct _AptWatcher AptWatcher; + +struct _AptWatcherClass +{ + GObjectClass parent_class; +}; + +GType apt_watcher_get_type (void) G_GNUC_CONST; + +AptWatcher* apt_watcher_new (SessionDbus* session_dbus, + DbusmenuMenuitem* apt_item); + +G_END_DECLS + +#endif /* _APT_WATCHER_H_ */ diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index f97dddc..d9dfff1 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -20,16 +20,25 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ - #ifndef __DBUS_SHARED_NAMES_H__ -#define __DBUS_SHARED_NAMES_H__ 1 +#define __DBUS_SHARED_NAMES_H__ + +typedef enum { + UP_TO_DATE, + CHECKING_FOR_UPDATES, + UPDATES_AVAILABLE, + UPGRADE_IN_PROGRESS, + FINISHED, + RESTART_NEEDED, + DONT_KNOW +}AptState; -#define INDICATOR_STATUS_DBUS_NAME "com.canonical.indicator.status" -#define INDICATOR_STATUS_DBUS_OBJECT "/com/canonical/indicator/status/menu" -#define INDICATOR_STATUS_SERVICE_DBUS_OBJECT "/com/canonical/indicator/status/service" -#define INDICATOR_STATUS_SERVICE_DBUS_INTERFACE "com.canonical.indicator.status.service" +typedef enum { + SIMULATION, + REAL +}TransactionType; -#define INDICATOR_USERS_DBUS_NAME "com.canonical.indicator.users" +#define INDICATOR_USERS_DBUS_NAME INDICATOR_SESSION_DBUS_NAME #define INDICATOR_USERS_DBUS_OBJECT "/com/canonical/indicator/users/menu" #define INDICATOR_USERS_SERVICE_DBUS_OBJECT "/org/gnome/DisplayManager/UserManager" #define INDICATOR_USERS_SERVICE_DBUS_INTERFACE "org.gnome.DisplayManager.UserManager" @@ -44,8 +53,9 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define USER_ITEM_TYPE "x-canonical-user-item" #define USER_ITEM_PROP_NAME "user-item-name" #define USER_ITEM_PROP_LOGGED_IN "user-item-logged-in" +#define USER_ITEM_PROP_IS_CURRENT_USER "user-item-is-current-user" #define USER_ITEM_PROP_ICON "user-item-icon-path" -#define USER_ITEM_ICON_DEFAULT "default-icon" +#define USER_ITEM_ICON_DEFAULT "user-offline" #define RESTART_ITEM_TYPE "x-canonical-restart-item" #define RESTART_ITEM_LABEL "restart-label" diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c new file mode 100644 index 0000000..cbddaa3 --- /dev/null +++ b/src/device-menu-mgr.c @@ -0,0 +1,874 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#include <libdbusmenu-glib/client.h> +#include <libdbusmenu-gtk3/menuitem.h> + +#include "device-menu-mgr.h" +#include "gconf-helper.h" +#include "dbus-shared-names.h" +#include "dbusmenu-shared.h" +#include "lock-helper.h" +#include "upower-client.h" +#include "apt-watcher.h" +#include "udev-mgr.h" + +#define UP_ADDRESS "org.freedesktop.UPower" +#define UP_OBJECT "/org/freedesktop/UPower" +#define UP_INTERFACE "org.freedesktop.UPower" + +#define EXTRA_LAUNCHER_DIR "/usr/share/indicators/session/applications" + +struct _DeviceMenuMgr +{ + GObject parent_instance; + DbusmenuMenuitem* root_item; + SessionDbus* session_dbus_interface; + AptWatcher* apt_watcher; + UdevMgr* udev_mgr; +}; + +static GConfClient *gconf_client = NULL; +static DbusmenuMenuitem *lock_menuitem = NULL; +static DbusmenuMenuitem *system_settings_menuitem = NULL; +static DbusmenuMenuitem *display_settings_menuitem = NULL; +static DbusmenuMenuitem *bluetooth_settings_menuitem = NULL; +static DbusmenuMenuitem *login_settings_menuitem = NULL; +static DbusmenuMenuitem *software_updates_menuitem = NULL; +static DbusmenuMenuitem *printers_menuitem = NULL; +static DbusmenuMenuitem *scanners_menuitem = NULL; +static DbusmenuMenuitem *webcam_menuitem = NULL; + +static DBusGProxyCall * suspend_call = NULL; +static DBusGProxyCall * hibernate_call = NULL; + +static DbusmenuMenuitem * hibernate_mi = NULL; +static DbusmenuMenuitem * suspend_mi = NULL; +static DbusmenuMenuitem * logout_mi = NULL; +static DbusmenuMenuitem * restart_mi = NULL; +static DbusmenuMenuitem * shutdown_mi = NULL; + +static gboolean can_hibernate = TRUE; +static gboolean can_suspend = TRUE; +static gboolean allow_hibernate = TRUE; +static gboolean allow_suspend = TRUE; + +static DBusGProxy * up_main_proxy = NULL; +static DBusGProxy * up_prop_proxy = NULL; + +static void device_menu_mgr_ensure_gconf_client (DeviceMenuMgr* self); +static void setup_restart_watch (DeviceMenuMgr* self); +static void setup_up (DeviceMenuMgr* self); +static void device_menu_mgr_rebuild_items (DeviceMenuMgr *self); +static void lock_if_possible (DeviceMenuMgr* self); +static void machine_sleep_with_context (DeviceMenuMgr* self, + gchar* type); +static void show_system_settings_with_context (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type); + +static void device_menu_mgr_show_simple_scan (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type); +static void device_menu_mgr_show_cheese (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type); + +static void +machine_sleep_from_hibernate (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata); +static void +machine_sleep_from_suspend (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata); + +G_DEFINE_TYPE (DeviceMenuMgr, device_menu_mgr, G_TYPE_OBJECT); + +static void +device_menu_mgr_init (DeviceMenuMgr *self) +{ + self->apt_watcher = NULL; + self->root_item = dbusmenu_menuitem_new (); + setup_restart_watch(self); + setup_up(self); + g_idle_add(lock_screen_setup, NULL); +} + +static void +device_menu_mgr_finalize (GObject *object) +{ + G_OBJECT_CLASS (device_menu_mgr_parent_class)->finalize (object); +} + +// TODO refactor into one helper method for both menu mgrs. +static void +device_menu_mgr_class_init (DeviceMenuMgrClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + object_class->finalize = device_menu_mgr_finalize; +} + +// TODO +// Is this needed anymore +static void +lockdown_changed (GConfClient *client, + guint cnxd_id, + GConfEntry *entry, + gpointer user_data) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (user_data); + GConfValue *value = gconf_entry_get_value (entry); + const gchar *key = gconf_entry_get_key (entry); + + if (value == NULL || key == NULL) { + return; + } + + if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0 || + g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { + device_menu_mgr_rebuild_items(self); + } + + return; +} + +static void +keybinding_changed (GConfClient *client, + guint cnxd_id, + GConfEntry *entry, + gpointer user_data) +{ + GConfValue *value = gconf_entry_get_value (entry); + const gchar *key = gconf_entry_get_key (entry); + + if (value == NULL || key == NULL) { + return; + } + + if (g_strcmp0 (key, KEY_LOCK_SCREEN) == 0) { + g_debug("Keybinding changed to: %s", gconf_value_get_string(value)); + if (lock_menuitem != NULL) { + dbusmenu_menuitem_property_set_shortcut_string (lock_menuitem, + gconf_value_get_string(value)); + } + } + return; +} + +/* Check to see if the lockdown key is protecting from + locking the screen. If not, lock it. */ +static void +lock_if_possible (DeviceMenuMgr* self) { + device_menu_mgr_ensure_gconf_client (self); + + if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) { + lock_screen (NULL, 0, NULL); + } + return; +} + +/* A return from the command to sleep the system. Make sure + that we unthrottle the screensaver. */ +static void +sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) +{ + screensaver_unthrottle(); + return; +} + +static void +machine_sleep_from_suspend (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + machine_sleep_with_context (self, "Suspend"); +} + +static void +machine_sleep_from_hibernate (DbusmenuMenuitem * mi, + guint timestamp, + gpointer userdata) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + machine_sleep_with_context (self, "Hibernate"); +} + +/* Let's put this machine to sleep, with some info on how + it should sleep. */ +static void +machine_sleep_with_context (DeviceMenuMgr* self, gchar* type) +{ + if (up_main_proxy == NULL) { + g_warning("Can not %s as no upower proxy", type); + } + + screensaver_throttle(type); + lock_if_possible (self); + dbus_g_proxy_begin_call(up_main_proxy, + type, + sleep_response, + NULL, + NULL, + G_TYPE_INVALID); + + return; +} + +/* A response to getting the suspend property */ +static void +suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + suspend_call = NULL; + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + + GValue candoit = {0}; + GError * error = NULL; + dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); + if (error != NULL) { + g_warning("Unable to check suspend: %s", error->message); + g_error_free(error); + return; + } + g_debug("Got Suspend: %s", g_value_get_boolean(&candoit) ? "true" : "false"); + + gboolean local_can_suspend = g_value_get_boolean(&candoit); + if (local_can_suspend != can_suspend) { + can_suspend = local_can_suspend; + // TODO figure out what needs updating on the menu + // And add or remove it but just don't rebuild the whole menu + // a waste + device_menu_mgr_rebuild_items(self); + } + return; +} + +/* Response to getting the hibernate property */ +static void +hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) +{ + hibernate_call = NULL; + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + + GValue candoit = {0}; + GError * error = NULL; + dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); + if (error != NULL) { + g_warning("Unable to check hibernate: %s", error->message); + g_error_free(error); + return; + } + g_debug("Got Hibernate: %s", g_value_get_boolean(&candoit) ? "true" : "false"); + + gboolean local_can_hibernate = g_value_get_boolean(&candoit); + if (local_can_hibernate != can_hibernate) { + can_hibernate = local_can_hibernate; + device_menu_mgr_rebuild_items(self); + } +} + +/* A signal that we need to recheck to ensure we can still + hibernate and/or suspend */ +static void +up_changed_cb (DBusGProxy * proxy, gpointer user_data) +{ + /* Start Async call to see if we can hibernate */ + if (suspend_call == NULL) { + suspend_call = dbus_g_proxy_begin_call(up_prop_proxy, + "Get", + suspend_prop_cb, + user_data, + NULL, + G_TYPE_STRING, + UP_INTERFACE, + G_TYPE_STRING, + "CanSuspend", + G_TYPE_INVALID, + G_TYPE_VALUE, + G_TYPE_INVALID); + } + + /* Start Async call to see if we can suspend */ + if (hibernate_call == NULL) { + hibernate_call = dbus_g_proxy_begin_call(up_prop_proxy, + "Get", + hibernate_prop_cb, + user_data, + NULL, + G_TYPE_STRING, + UP_INTERFACE, + G_TYPE_STRING, + "CanHibernate", + G_TYPE_INVALID, + G_TYPE_VALUE, + G_TYPE_INVALID); + } +} +/* Handle the callback from the allow functions to check and + see if we're changing the value, and if so, rebuilding the + menus based on that info. */ +static void +allowed_suspend_cb (DBusGProxy *proxy, + gboolean OUT_allowed, + GError *error, + gpointer userdata) +{ + if (error != NULL) { + g_warning("Unable to get information on what is allowed from UPower: %s", + error->message); + return; + } + + if (OUT_allowed != allow_suspend) { + allow_suspend = OUT_allowed; + device_menu_mgr_rebuild_items(DEVICE_MENU_MGR (userdata)); + } +} + +/* Handle the callback from the allow functions to check and + see if we're changing the value, and if so, rebuilding the + menus based on that info. */ +static void +allowed_hibernate_cb (DBusGProxy *proxy, + gboolean OUT_allowed, + GError *error, + gpointer userdata) +{ + if (error != NULL) { + g_warning("Unable to get information on what is allowed from UPower: %s", + error->message); + return; + } + + if (OUT_allowed != allow_hibernate) { + allow_hibernate = OUT_allowed; + device_menu_mgr_rebuild_items(DEVICE_MENU_MGR (userdata)); + } +} + +/* This function goes through and sets up what we need for + DKp checking. We're even setting up the calls for the props + we need */ +static void +setup_up (DeviceMenuMgr* self) { + DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); + g_return_if_fail(bus != NULL); + + if (up_main_proxy == NULL) { + up_main_proxy = dbus_g_proxy_new_for_name(bus, + UP_ADDRESS, + UP_OBJECT, + UP_INTERFACE); + } + g_return_if_fail(up_main_proxy != NULL); + + if (up_prop_proxy == NULL) { + up_prop_proxy = dbus_g_proxy_new_for_name(bus, + UP_ADDRESS, + UP_OBJECT, + DBUS_INTERFACE_PROPERTIES); + /* Connect to changed signal */ + dbus_g_proxy_add_signal(up_main_proxy, + "Changed", + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal(up_main_proxy, + "Changed", + G_CALLBACK(up_changed_cb), + self, + NULL); + } + g_return_if_fail(up_prop_proxy != NULL); + + + /* Force an original "changed" event */ + up_changed_cb(up_main_proxy, self); + + /* Check to see if these are getting blocked by PolicyKit */ + org_freedesktop_UPower_suspend_allowed_async(up_main_proxy, + allowed_suspend_cb, + self); + org_freedesktop_UPower_hibernate_allowed_async(up_main_proxy, + allowed_hibernate_cb, + self); + + return; +} + +/* This is the function to show a dialog on actions that + can destroy data. Currently it just calls the GTK version + but it seems that in the future it should figure out + what's going on and something better. */ +static void +show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) +{ + + gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); + gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); + g_free(helper); + + g_debug("Showing dialog '%s'", dialog_line); + + GError * error = NULL; + if (!g_spawn_command_line_async(dialog_line, &error)) { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } + g_free(dialog_line); +} + +static void +show_session_properties (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("gnome-session-properties", &error)) + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } +} + +static void +show_printer_properties (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("system-config-printer", &error)) + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } +} + +static void +show_system_settings_with_context (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + gchar * control_centre_command = g_strdup_printf("%s %s", + "gnome-control-center", + type); + + g_debug("Command centre exec call '%s'", control_centre_command); + + GError * error = NULL; + if (!g_spawn_command_line_async(control_centre_command, &error)) + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } + g_free(control_centre_command); +} + +// TODO: refactor both of these down to the one method. +static void device_menu_mgr_show_simple_scan (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("simple-scan", &error)) + { + g_warning("Unable to launch simple-scan: %s", error->message); + g_error_free(error); + if (!g_spawn_command_line_async("software-center simple-scan", &error)) + { + g_warning ("Unable to launch software-centre simple-scan: %s", + error->message); + g_error_free(error); + } + } +} + +static void device_menu_mgr_show_cheese (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("cheese", &error)) + { + g_warning("Unable to launch cheese: %s", error->message); + g_error_free(error); + if (!g_spawn_command_line_async("software-center cheese", &error)) + { + g_warning ("Unable to launch software-centre cheese: %s", + error->message); + g_error_free(error); + } + } +} + +static void +device_menu_mgr_build_settings_items (DeviceMenuMgr* self) +{ + system_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (system_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("System Settings…")); + g_signal_connect (G_OBJECT(system_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), ""); + dbusmenu_menuitem_child_add_position(self->root_item, + system_settings_menuitem, + 0); + + display_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (display_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Displays…")); + g_signal_connect (G_OBJECT(display_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), "display"); + dbusmenu_menuitem_child_add_position(self->root_item, + display_settings_menuitem, + 1); + bluetooth_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (bluetooth_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Bluetooth…")); + g_signal_connect (G_OBJECT(bluetooth_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), "bluetooth"); + dbusmenu_menuitem_child_add_position(self->root_item, + bluetooth_settings_menuitem, + 2); + + login_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (login_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Startup Applications…")); + g_signal_connect (G_OBJECT(login_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_session_properties), + "login"); + dbusmenu_menuitem_child_add_position(self->root_item, + login_settings_menuitem, + 3); + software_updates_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (software_updates_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + dbusmenu_menuitem_child_add_position(self->root_item, + software_updates_menuitem, + 4); + + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator1, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_add_position (self->root_item, separator1, 5); +} + +static void +device_menu_mgr_build_devices_items (DeviceMenuMgr* self) +{ + DbusmenuMenuitem * device_heading = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (device_heading, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Attached Devices")); + dbusmenu_menuitem_property_set_bool (device_heading, + DBUSMENU_MENUITEM_PROP_ENABLED, + FALSE); + dbusmenu_menuitem_child_add_position (self->root_item, + device_heading, + 6); + + printers_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (printers_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Printers")); + g_signal_connect (G_OBJECT(printers_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_printer_properties), + "printers"); + dbusmenu_menuitem_child_add_position(self->root_item, + printers_menuitem, + 7); + scanners_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (scanners_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Scanners")); + g_signal_connect (G_OBJECT(scanners_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(device_menu_mgr_show_simple_scan), + NULL); + dbusmenu_menuitem_child_add_position (self->root_item, + scanners_menuitem, + 8); + dbusmenu_menuitem_property_set_bool (scanners_menuitem, + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); + + webcam_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (webcam_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Webcam")); + g_signal_connect (G_OBJECT(webcam_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(device_menu_mgr_show_cheese), + NULL); + dbusmenu_menuitem_child_add_position (self->root_item, + webcam_menuitem, + 10); + dbusmenu_menuitem_property_set_bool (webcam_menuitem, + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); + + DbusmenuMenuitem * separator3 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator3, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_add_position (self->root_item, separator3, 11); +} + +static void +device_menu_mgr_build_static_items (DeviceMenuMgr* self, gboolean greeter_mode) +{ + // Static Setting items + if (!greeter_mode) { + device_menu_mgr_build_settings_items (self); + } + + // Devices control + if (!greeter_mode) { + device_menu_mgr_build_devices_items (self); + } + + // Session control + if (!greeter_mode) { + gboolean can_lockscreen; + + /* Make sure we have a valid GConf client, and build one + if needed */ + device_menu_mgr_ensure_gconf_client (self); + can_lockscreen = !gconf_client_get_bool ( gconf_client, + LOCKDOWN_KEY_SCREENSAVER, + NULL); + /* Lock screen item */ + if (can_lockscreen) { + lock_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (lock_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Lock Screen")); + + gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); + if (shortcut != NULL) { + g_debug("Lock screen shortcut: %s", shortcut); + dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); + g_free(shortcut); + } + else { + g_debug("Unable to get lock screen shortcut."); + } + + g_signal_connect (G_OBJECT(lock_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(lock_screen), NULL); + dbusmenu_menuitem_child_append(self->root_item, lock_menuitem); + } + + logout_mi = dbusmenu_menuitem_new(); + + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out")); + } + else { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (logout_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_logout()); + dbusmenu_menuitem_child_append(self->root_item, logout_mi); + g_signal_connect( G_OBJECT(logout_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "logout"); + } + + if (can_suspend && allow_suspend) { + suspend_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (suspend_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Suspend")); + dbusmenu_menuitem_child_append (self->root_item, suspend_mi); + g_signal_connect( G_OBJECT(suspend_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_suspend), + self); + } + + if (can_hibernate && allow_hibernate) { + hibernate_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (hibernate_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Hibernate")); + dbusmenu_menuitem_child_append(self->root_item, hibernate_mi); + g_signal_connect (G_OBJECT(hibernate_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_hibernate), self); + } + + shutdown_mi = dbusmenu_menuitem_new(); + + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down")); + } + else { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (shutdown_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_shutdown()); + dbusmenu_menuitem_child_append (self->root_item, shutdown_mi); + g_signal_connect (G_OBJECT(shutdown_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "shutdown"); + + RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); + restart_shutdown_logout_mi->logout_mi = logout_mi; + restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; + + update_menu_entries(restart_shutdown_logout_mi); + // Time to create the udev mgr and hand it the static relevant items. + self->udev_mgr = udev_mgr_new (scanners_menuitem, webcam_menuitem); +} + + +static void +device_menu_mgr_rebuild_items (DeviceMenuMgr* self) +{ + dbusmenu_menuitem_property_set_bool (hibernate_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + can_hibernate && allow_hibernate); + dbusmenu_menuitem_property_set_bool (suspend_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + can_suspend && allow_suspend); +} + +/* When the directory changes we need to figure out how our menu + item should look. */ +static void +restart_dir_changed (gpointer userdata) +{ + DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); + gboolean restart_required = g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS); + + if (restart_required) { + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_LABEL, + _("Restart to Complete Update")); + } else { + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_LABEL, + _("Restart to Complete Update\342\200\246")); + } + dbusmenu_menuitem_property_set (restart_mi, + RESTART_ITEM_ICON, + "system-restart-panel"); + if (self->session_dbus_interface != NULL) { + session_dbus_set_name (self->session_dbus_interface, ICON_RESTART); + } + } else { + if (supress_confirmations()) { + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); + } else { + dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart\342\200\246")); + } + dbusmenu_menuitem_property_remove(restart_mi, RESTART_ITEM_ICON); + if (self->session_dbus_interface != NULL) { + session_dbus_set_name(self->session_dbus_interface, ICON_DEFAULT); + } + } + return; +} + +/* Buids a file watcher for the directory so that when it + changes we can check to see if our reboot-required is + there. */ +static void +setup_restart_watch (DeviceMenuMgr* self) +{ + GFile * filedir = g_file_new_for_path("/var/run"); + GFileMonitor * filemon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL); + if (filemon != NULL) { + g_signal_connect (G_OBJECT(filemon), + "changed", + G_CALLBACK(restart_dir_changed), + self); + } + restart_dir_changed(self); + return; +} + +/* Ensures that we have a GConf client and if we build one + set up the signal handler. */ +static void +device_menu_mgr_ensure_gconf_client (DeviceMenuMgr* self) +{ + if (!gconf_client) { + gconf_client = gconf_client_get_default (); + gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add (gconf_client, + LOCKDOWN_DIR, + lockdown_changed, + self, + NULL, + NULL); + + gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add (gconf_client, + KEYBINDING_DIR, + keybinding_changed, + self, + NULL, + NULL); + } +} + +DbusmenuMenuitem* +device_mgr_get_root_item (DeviceMenuMgr* self) +{ + return self->root_item; +} + +/* + * Clean Entry Point + */ +DeviceMenuMgr* device_menu_mgr_new (SessionDbus* session_dbus, gboolean greeter_mode) +{ + DeviceMenuMgr* device_mgr = g_object_new (DEVICE_TYPE_MENU_MGR, NULL); + device_mgr->session_dbus_interface = session_dbus; + device_menu_mgr_build_static_items (device_mgr, greeter_mode); + if (software_updates_menuitem != NULL) { + device_mgr->apt_watcher = apt_watcher_new (session_dbus, + software_updates_menuitem); + } + return device_mgr; +} diff --git a/src/device-menu-mgr.h b/src/device-menu-mgr.h new file mode 100644 index 0000000..d3c3a5a --- /dev/null +++ b/src/device-menu-mgr.h @@ -0,0 +1,53 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + + +#ifndef _DEVICE_MENU_MGR_H_ +#define _DEVICE_MENU_MGR_H_ + +#include <glib-object.h> + +#include "session-dbus.h" + +G_BEGIN_DECLS + +#define DEVICE_TYPE_MENU_MGR (device_menu_mgr_get_type ()) +#define DEVICE_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEVICE_TYPE_MENU_MGR, DeviceMenuMgr)) +#define DEVICE_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEVICE_TYPE_MENU_MGR, DeviceMenuMgrClass)) +#define DEVICE_IS_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEVICE_TYPE_MENU_MGR)) +#define DEVICE_IS_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEVICE_TYPE_MENU_MGR)) +#define DEVICE_MENU_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEVICE_TYPE_MENU_MGR, DeviceMenuMgrClass)) + +typedef struct _DeviceMenuMgrClass DeviceMenuMgrClass; +typedef struct _DeviceMenuMgr DeviceMenuMgr; + +struct _DeviceMenuMgrClass +{ + GObjectClass parent_class; +}; + +GType device_menu_mgr_get_type (void) G_GNUC_CONST; + +DeviceMenuMgr* device_menu_mgr_new (SessionDbus* session_dbus, gboolean greeter_mode); + +DbusmenuMenuitem* device_mgr_get_root_item (DeviceMenuMgr* self); + +G_END_DECLS + +#endif /* _DEVICE_MENU_MGR_H_ */ diff --git a/src/dialog.c b/src/dialog.c index 9633224..299f954 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -183,6 +183,8 @@ logout_dialog_new (LogoutDialogType type) "text", _(body_strings[type]), NULL)); + gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); + gboolean allowed = FALSE; if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) { allowed = ck_check_allowed(LOGOUT_DIALOG_TYPE_RESTART); @@ -223,6 +225,12 @@ logout_dialog_new (LogoutDialogType type) button_text, GTK_RESPONSE_OK, NULL); } + + if (type == LOGOUT_DIALOG_TYPE_SHUTDOWN){ + const gchar * restart_text; + restart_text = g_dpgettext2 (NULL, "button", button_strings[LOGOUT_DIALOG_TYPE_RESTART]); + gtk_dialog_add_button (GTK_DIALOG(dialog), restart_text, GTK_RESPONSE_HELP); + } gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); diff --git a/src/display-manager.xml b/src/display-manager.xml new file mode 100644 index 0000000..92f5e05 --- /dev/null +++ b/src/display-manager.xml @@ -0,0 +1,20 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="org.freedesktop.DisplayManager.Seat"> + + <!-- Show greeter to allow new login / switch users --> + <method name="SwitchToGreeter"/> + + <!-- Switch to a user, starting a new display if required --> + <method name="SwitchToUser"> + <arg name="username" direction="in" type="s"/> + <arg name="session" direction="in" type="s"/> + </method> + + <!-- Switch to the guest user --> + <method name="SwitchToGuest"> + <arg name="session" direction="in" type="s"/> + </method> + + </interface> +</node> diff --git a/src/gconf-helper.h b/src/gconf-helper.h index 505c24f..039b309 100644 --- a/src/gconf-helper.h +++ b/src/gconf-helper.h @@ -39,6 +39,12 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define RESTART_KEY GLOBAL_DIR "/suppress_restart_menuitem" #define SHUTDOWN_KEY GLOBAL_DIR "/suppress_shutdown_menuitem" +#define LOCKDOWN_DIR "/desktop/gnome/lockdown" +#define LOCKDOWN_KEY_USER LOCKDOWN_DIR "/disable_user_switching" +#define LOCKDOWN_KEY_SCREENSAVER LOCKDOWN_DIR "/disable_lock_screen" +#define KEYBINDING_DIR "/apps/gnome_settings_daemon/keybindings" +#define KEY_LOCK_SCREEN KEYBINDING_DIR "/screensaver" + typedef struct _RestartShutdownLogoutMenuItems { DbusmenuMenuitem * logout_mi; diff --git a/src/gdm-local-display-factory.xml b/src/gdm-local-display-factory.xml deleted file mode 100644 index 66fb77c..0000000 --- a/src/gdm-local-display-factory.xml +++ /dev/null @@ -1,20 +0,0 @@ -<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> -<node name="/org/gnome/DisplayManager/LocalDisplayFactory"> - <interface name="org.gnome.DisplayManager.LocalDisplayFactory"> - <method name="CreateProductDisplay"> - <arg name="parent_display_id" direction="in" type="o"/> - <arg name="relay_address" direction="in" type="s"/> - <arg name="id" direction="out" type="o"/> - </method> - <method name="CreateTransientDisplay"> - <arg name="id" direction="out" type="o"/> - </method> - <method name="StartGuestSession"> - <arg name="id" direction="out" type="o"/> - </method> - <method name="SwitchToUser"> - <arg name="username" direction="in" type="s"/> - <arg name="id" direction="out" type="o"/> - </method> - </interface> -</node> diff --git a/src/indicator-session.c b/src/indicator-session.c index c9617c4..f6727d9 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -6,7 +6,8 @@ Copyright 2009 Canonical Ltd. Authors: Ted Gould <ted@canonical.com> - + Conor Curran <conor.curran@canonical.com> + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published by the Free Software Foundation. @@ -43,6 +44,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "dbus-shared-names.h" #include "dbusmenu-shared.h" +#include "user-widget.h" #define INDICATOR_SESSION_TYPE (indicator_session_get_type ()) #define INDICATOR_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SESSION_TYPE, IndicatorSession)) @@ -61,8 +63,9 @@ struct _IndicatorSessionClass { struct _IndicatorSession { IndicatorObject parent; IndicatorServiceManager * service; - GtkImage * status_image; - DbusmenuGtkMenu * menu; + IndicatorObjectEntry users; + IndicatorObjectEntry devices; + gboolean show_users_entry; GCancellable * service_proxy_cancel; GDBusProxy * service_proxy; }; @@ -74,26 +77,37 @@ INDICATOR_SET_VERSION INDICATOR_SET_TYPE(INDICATOR_SESSION_TYPE) /* Prototypes */ -static GtkLabel * get_label (IndicatorObject * io); -static GtkImage * get_icon (IndicatorObject * io); -static GtkMenu * get_menu (IndicatorObject * io); -static const gchar * get_accessible_desc (IndicatorObject * io); -static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); -static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); -static void icon_changed (IndicatorSession * session, const gchar * icon_name); +static gboolean build_menu_switch (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data); +static gboolean new_user_item (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data); +static gboolean build_restart_item (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data); +static void indicator_session_update_users_label (IndicatorSession* self, + const gchar* name); static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data); -static gboolean build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); +static void user_real_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data); +static void user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); static void indicator_session_dispose (GObject *object); static void indicator_session_finalize (GObject *object); - +static GList* indicator_session_get_entries (IndicatorObject* obj); +static guint indicator_session_get_location (IndicatorObject * io, + IndicatorObjectEntry * entry); + G_DEFINE_TYPE (IndicatorSession, indicator_session, INDICATOR_OBJECT_TYPE); -static void +static void indicator_session_class_init (IndicatorSessionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -102,82 +116,87 @@ indicator_session_class_init (IndicatorSessionClass *klass) object_class->finalize = indicator_session_finalize; IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); - io_class->get_label = get_label; - io_class->get_image = get_icon; - io_class->get_menu = get_menu; - io_class->get_accessible_desc = get_accessible_desc; - + io_class->get_entries = indicator_session_get_entries; + io_class->get_location = indicator_session_get_location; return; } static void indicator_session_init (IndicatorSession *self) { - /* Set good defaults */ self->service = NULL; self->service_proxy_cancel = NULL; self->service_proxy = NULL; - + self->show_users_entry = FALSE; + /* Now let's fire these guys up. */ - self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION); - g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(service_connection_cb), self); - - self->status_image = indicator_image_helper(ICON_DEFAULT); - self->menu = dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT); - - DbusmenuClient * client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(self->menu)); - dbusmenu_client_add_type_handler(client, MENU_SWITCH_TYPE, build_menu_switch); - dbusmenu_client_add_type_handler(client, USER_ITEM_TYPE, new_user_item); - dbusmenu_client_add_type_handler(client, RESTART_ITEM_TYPE, build_restart_item); - + self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, + INDICATOR_SESSION_DBUS_VERSION); + g_signal_connect(G_OBJECT(self->service), + INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, + G_CALLBACK(service_connection_cb), self); + + GtkWidget* avatar_icon = NULL; + // users + self->users.menu = GTK_MENU (dbusmenu_gtkmenu_new (INDICATOR_USERS_DBUS_NAME, + INDICATOR_USERS_DBUS_OBJECT)); + // Set the image to the default avator image + GdkPixbuf* pixbuf = NULL; + GError* error = NULL; + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + "avatar-default", + 17, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + // I think the avatar image is available always but just in case have a fallback + if (error != NULL) { + g_warning ("Could not load the default avatar image for some reason"); + self->users.image = indicator_image_helper (USER_ITEM_ICON_DEFAULT); + } + else{ + avatar_icon = gtk_image_new (); + gtk_image_set_from_pixbuf (GTK_IMAGE (avatar_icon), pixbuf); + self->users.image = GTK_IMAGE (avatar_icon); + g_object_unref (pixbuf); + g_error_free (error); + } + + self->users.label = GTK_LABEL (gtk_label_new (NULL)); + + // devices + self->devices.menu = GTK_MENU (dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, + INDICATOR_SESSION_DBUS_OBJECT)); + self->devices.image = indicator_image_helper ("system-devices-panel"); + + gtk_widget_show (GTK_WIDGET(self->devices.menu)); + gtk_widget_show (GTK_WIDGET(self->devices.image)); + gtk_widget_show (GTK_WIDGET(self->users.image)); + gtk_widget_show (GTK_WIDGET(self->users.menu)); + + g_object_ref_sink (self->users.menu); + g_object_ref_sink (self->users.image); + g_object_ref_sink (self->devices.menu); + g_object_ref_sink (self->devices.image); + + // Setup the handlers for users + DbusmenuClient * users_client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(DBUSMENU_GTKMENU(self->users.menu))); + dbusmenu_client_add_type_handler (users_client, + USER_ITEM_TYPE, + new_user_item); + dbusmenu_client_add_type_handler_full (users_client, + MENU_SWITCH_TYPE, + build_menu_switch, + self, NULL); + + // Setup the handlers for devices + DbusmenuClient * devices_client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(DBUSMENU_GTKMENU(self->devices.menu))); + dbusmenu_client_add_type_handler (devices_client, + RESTART_ITEM_TYPE, + build_restart_item); + GtkAccelGroup * agroup = gtk_accel_group_new(); - dbusmenu_gtkclient_set_accel_group(DBUSMENU_GTKCLIENT(client), agroup); - - self->service_proxy_cancel = g_cancellable_new(); - - g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - INDICATOR_SESSION_DBUS_NAME, - INDICATOR_SESSION_SERVICE_DBUS_OBJECT, - INDICATOR_SESSION_SERVICE_DBUS_IFACE, - self->service_proxy_cancel, - service_proxy_cb, - self); - - return; -} - -/* Callback from trying to create the proxy for the serivce, this - could include starting the service. Sometime it'll fail and - we'll try to start that dang service again! */ -static void -service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) -{ - GError * error = NULL; - - IndicatorSession * self = INDICATOR_SESSION(user_data); - g_return_if_fail(self != NULL); - - GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); - - if (self->service_proxy_cancel != NULL) { - g_object_unref(self->service_proxy_cancel); - self->service_proxy_cancel = NULL; - } - - if (error != NULL) { - g_warning("Could not grab DBus proxy for %s: %s", INDICATOR_SESSION_DBUS_NAME, error->message); - g_error_free(error); - return; - } - - /* Okay, we're good to grab the proxy at this point, we're - sure that it's ours. */ - self->service_proxy = proxy; - - g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); - + dbusmenu_gtkclient_set_accel_group(DBUSMENU_GTKCLIENT(devices_client), agroup); return; } @@ -201,6 +220,14 @@ indicator_session_dispose (GObject *object) g_object_unref(self->service_proxy_cancel); self->service_proxy_cancel = NULL; } + + if (self->users.menu != NULL) { + g_object_unref (self->users.menu); + } + + if (self->devices.menu != NULL) { + g_object_unref (self->devices.menu); + } G_OBJECT_CLASS (indicator_session_parent_class)->dispose (object); return; @@ -214,256 +241,348 @@ indicator_session_finalize (GObject *object) return; } -static void -icon_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data) +static GList* +indicator_session_get_entries (IndicatorObject* obj) { - IndicatorSession * self = INDICATOR_SESSION(user_data); - GError * error = NULL; - gchar * name; - GVariant * result; - - result = g_dbus_proxy_call_finish(self->service_proxy, res, &error); - - if (error != NULL) { - return; - } - - g_variant_get(result, "(&s)", &name); - - if (name == NULL || name[0] == '\0') { - return; + g_return_val_if_fail(IS_INDICATOR_SESSION(obj), NULL); + IndicatorSession* self = INDICATOR_SESSION (obj); + + g_debug ("get entries"); + GList * retval = NULL; + // Only show the users menu if we have more than one + if (self->show_users_entry == TRUE){ + retval = g_list_prepend (retval, &self->users); + } + retval = g_list_prepend (retval, &self->devices); + + if (retval != NULL) { + retval = g_list_reverse(retval); } + return retval; +} - indicator_image_helper_update(self->status_image, name); - return; +static guint +indicator_session_get_location (IndicatorObject * io, + IndicatorObjectEntry * entry) +{ + IndicatorSession * self = INDICATOR_SESSION (io); + if (entry == &self->users){ + return 1; + } + else if (entry == &self->devices){ + return 0; + } + g_warning ("IOEntry handed to us to position but we don't own it!"); + return 0; } +/* callback for the service manager state of being */ static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) { - IndicatorSession * self = INDICATOR_SESSION(user_data); + IndicatorSession * self = INDICATOR_SESSION (user_data); if (connected) { - g_dbus_proxy_call(self->service_proxy, "GetIcon", NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, - icon_name_get_cb, user_data); - } else { - indicator_image_helper_update(self->status_image, ICON_DEFAULT); - } - + if (self->service_proxy != NULL){ + // Its a reconnect ! + // Fetch synchronisation data and return (proxy is still legit) + g_dbus_proxy_call (self->service_proxy, + "GetUserMenuVisibility", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_menu_visibility_get_cb, + user_data); + g_dbus_proxy_call (self->service_proxy, + "GetUserRealName", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_real_name_get_cb, + user_data); + return; + } + + self->service_proxy_cancel = g_cancellable_new(); + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + INDICATOR_SESSION_DBUS_NAME, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + self->service_proxy_cancel, + service_proxy_cb, + self); + } return; } -static GtkLabel * -get_label (IndicatorObject * io) -{ - return NULL; -} - -static const gchar * -get_accessible_desc (IndicatorObject * io) -{ - return _("Session"); -} static void -icon_changed (IndicatorSession * session, const gchar * icon_name) +service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) { - indicator_image_helper_update(session->status_image, icon_name); - return; -} + GError * error = NULL; -/* Receives all signals from the service, routed to the appropriate functions */ -static void -receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, - GVariant * parameters, gpointer user_data) -{ IndicatorSession * self = INDICATOR_SESSION(user_data); + g_return_if_fail(self != NULL); + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); - if (g_strcmp0(signal_name, "IconUpdated") == 0) { - const gchar *name; - g_variant_get (parameters, "(&s)", &name); - icon_changed(self, name); + if (self->service_proxy_cancel != NULL) { + g_object_unref(self->service_proxy_cancel); + self->service_proxy_cancel = NULL; } - return; -} + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", INDICATOR_SESSION_DBUS_NAME, error->message); + g_error_free(error); + return; + } -static GtkImage * -get_icon (IndicatorObject * io) -{ - gtk_widget_show(GTK_WIDGET(INDICATOR_SESSION(io)->status_image)); - return INDICATOR_SESSION(io)->status_image; -} + /* Okay, we're good to grab the proxy at this point, we're + sure that it's ours. */ + self->service_proxy = proxy; -static void -user_property_change (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer user_data) -{ - if (g_strcmp0(property, USER_ITEM_PROP_LOGGED_IN) == 0) { - if (g_variant_get_boolean(variant)) { - gtk_widget_show(GTK_WIDGET(user_data)); - } else { - gtk_widget_hide(GTK_WIDGET(user_data)); - } - } + g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); + + // Figure out whether we should show the user menu at all. + g_dbus_proxy_call (self->service_proxy, + "GetUserMenuVisibility", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_menu_visibility_get_cb, + user_data); + + // Fetch the user's real name for the user entry label + g_dbus_proxy_call (self->service_proxy, + "GetUserRealName", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + user_real_name_get_cb, + user_data); return; } -/* Builds an item with a hip little logged in icon. */ + static gboolean -new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) +new_user_item (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data) { - GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); - gint padding = 0; - gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL); - GtkWidget * hbox = gtk_hbox_new(FALSE, padding); - - GtkWidget * usericon = NULL; - const gchar * icon_name = dbusmenu_menuitem_property_get(newitem, USER_ITEM_PROP_ICON); - g_debug("Using user icon for '%s' from file: %s", dbusmenu_menuitem_property_get(newitem, USER_ITEM_PROP_NAME), icon_name); - if (icon_name != NULL && icon_name[0] != '\0') { - if (g_strcmp0(icon_name, USER_ITEM_ICON_DEFAULT) != 0 && g_file_test(icon_name, G_FILE_TEST_EXISTS)) { - gint width, height; - gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); - - GError * error = NULL; - GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file_at_size(icon_name, width, height, &error); - - if (error == NULL) { - usericon = gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(pixbuf); - } else { - g_warning("Unable to load user icon '%s': %s", icon_name, error->message); - g_error_free(error); - } - } + - if (usericon == NULL) { - GIcon * gicon = g_themed_icon_new_with_default_fallbacks("stock_person-panel"); - usericon = gtk_image_new_from_gicon(gicon, GTK_ICON_SIZE_MENU); - g_object_unref(gicon); - } - } - if (usericon != NULL) { - gtk_misc_set_alignment(GTK_MISC(usericon), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), usericon, FALSE, FALSE, 0); - gtk_widget_show(usericon); - } + GtkWidget* user_item = NULL; - GtkWidget * label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, USER_ITEM_PROP_NAME)); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); - gtk_widget_show(label); - - GtkWidget * icon = gtk_image_new_from_icon_name("account-logged-in", GTK_ICON_SIZE_MENU); - gtk_misc_set_alignment(GTK_MISC(icon), 1.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0); - if (dbusmenu_menuitem_property_get_bool(newitem, USER_ITEM_PROP_LOGGED_IN)) { - gtk_widget_show(icon); - } else { - gtk_widget_hide(icon); - } + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - gtk_container_add(GTK_CONTAINER(gmi), hbox); - gtk_widget_show(hbox); + user_item = user_widget_new(newitem); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + GtkMenuItem *user_widget = GTK_MENU_ITEM(user_item); - g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(user_property_change), icon); + dbusmenu_gtkclient_newitem_base (DBUSMENU_GTKCLIENT(client), + newitem, + user_widget, + parent); - return TRUE; -} + g_debug ("%s (\"%s\")", __func__, + dbusmenu_menuitem_property_get (newitem, + USER_ITEM_PROP_NAME)); + gtk_widget_show_all (user_item); -/* Indicator based function to get the menu for the whole - applet. This starts up asking for the parts of the menu - from the various services. */ -static GtkMenu * -get_menu (IndicatorObject * io) -{ - return GTK_MENU(INDICATOR_SESSION(io)->menu); + return TRUE; } + static void -switch_property_change (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer user_data) +user_real_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data) { - if (g_strcmp0(property, MENU_SWITCH_USER) != 0) { - return; - } - - GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(DBUSMENU_GTKCLIENT(user_data), item); - gchar * finalstring = NULL; - gboolean set_ellipsize = FALSE; - gboolean no_name_in_lang = FALSE; - - /* TRANSLATORS: Translate the '1' below into anything other than - '1' if "Switch From %s..." doesn't make sense in your language. - Instead, the string "Switch User..." will be used. */ - const gchar * translate = C_("session_menu:switchfrom", "1"); - if (g_strcmp0(translate, "1") != 0) { - no_name_in_lang = TRUE; - } + IndicatorSession * self = INDICATOR_SESSION(user_data); + GError * error = NULL; + GVariant * result; - /* If there's a NULL string of some type, then we want to - go back to our old 'Switch User' which isn't great but - eh, this error condition should never happen. */ - if (variant == NULL || g_variant_get_string(variant, NULL) == NULL || g_variant_get_string(variant, NULL)[0] == '\0' || no_name_in_lang) { - finalstring = _("Switch User..."); - set_ellipsize = FALSE; - } + result = g_dbus_proxy_call_finish(self->service_proxy, res, &error); - if (finalstring == NULL) { - const gchar * username = g_variant_get_string(variant, NULL); - GtkStyle * style = gtk_widget_get_style(GTK_WIDGET(gmi)); + if (error != NULL) { + g_warning ("unable to complete real name dbus query"); + g_error_free (error); + return; + } + + const gchar* username = NULL; + g_variant_get (result, "(s)", &username); + indicator_session_update_users_label (self, username); + return; +} - PangoLayout * layout = pango_layout_new(gtk_widget_get_pango_context(GTK_WIDGET(gmi))); - pango_layout_set_text(layout, username, -1); - pango_layout_set_font_description(layout, style->font_desc); +static void +user_menu_visibility_get_cb (GObject* obj, GAsyncResult* res, gpointer user_data) +{ + IndicatorSession * self = INDICATOR_SESSION(user_data); + GError * error = NULL; + GVariant * result; - gint width; - pango_layout_get_pixel_size(layout, &width, NULL); - g_object_unref(layout); - g_debug("Username width %dpx", width); + result = g_dbus_proxy_call_finish(self->service_proxy, res, &error); - gint point = pango_font_description_get_size(style->font_desc); - g_debug("Font size %f pt", (gfloat)point / PANGO_SCALE); + if (error != NULL) { + g_warning ("unable to complete real name dbus query"); + g_error_free (error); + return; + } + gboolean update; + g_variant_get (result, "(b)", &update); + + // If it is what we had before no need to do anything... + if (self->show_users_entry == update){ + return; + } + //Otherwise + self->show_users_entry = update; + + if (self->show_users_entry == TRUE){ + g_signal_emit_by_name ((gpointer)self, + "entry-added", + &self->users); + } + else{ + g_signal_emit_by_name ((gpointer)self, + "entry-removed", + &self->users); + } +} - gdouble dpi = gdk_screen_get_resolution(gdk_screen_get_default()); - g_debug("Screen DPI %f", dpi); +/* Receives all signals from the service, routed to the appropriate functions */ +static void +receive_signal (GDBusProxy * proxy, + gchar * sender_name, + gchar * signal_name, + GVariant * parameters, + gpointer user_data) +{ + IndicatorSession * self = INDICATOR_SESSION(user_data); - gdouble pixels_per_em = ((point * dpi) / 72.0f) / PANGO_SCALE; - gdouble ems = width / pixels_per_em; - g_debug("Username width %fem", ems); + if (g_strcmp0(signal_name, "UserRealNameUpdated") == 0) { + const gchar* username = NULL; + g_variant_get (parameters, "(s)", &username); + indicator_session_update_users_label (self, username); + } + else if (g_strcmp0(signal_name, "UserMenuIsVisible") == 0) { + gboolean update; + g_variant_get (parameters, "(b)", &update); + + // If it is what we had before no need to do anything... + if (self->show_users_entry == update){ + return; + } + + //Otherwise + self->show_users_entry = update; + + if (self->show_users_entry == TRUE){ + g_signal_emit_by_name ((gpointer)self, + "entry-added", + &self->users); + + } + else{ + g_signal_emit_by_name ((gpointer)self, + "entry-removed", + &self->users); + } + } + else if (g_strcmp0(signal_name, "RebootRequired") == 0) { + // TODO waiting on design to give me a name. + self->devices.image = indicator_image_helper ("system-devices-alert-panel"); + } +} - /* TODO: We need some way to remove the elipsis from appearing - twice in the label. Not sure how to do that yet. */ - finalstring = g_strdup_printf(_("Switch From %s..."), username); - if (ems >= 20.0f) { - set_ellipsize = TRUE; - } else { - set_ellipsize = FALSE; - } - } - gtk_menu_item_set_label(gmi, finalstring); - GtkLabel * label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(gmi))); - if (label != NULL) { - if (set_ellipsize) { - gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_END); - } else { - gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_NONE); - } - } +static void +switch_property_change (DbusmenuMenuitem * item, + const gchar * property, + GVariant * variant, + gpointer user_data) +{ + if (g_strcmp0 (property, MENU_SWITCH_USER) != 0) { + return; + } + + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(DBUSMENU_GTKCLIENT(user_data), item); + gchar * finalstring = NULL; + gboolean set_ellipsize = FALSE; + gboolean no_name_in_lang = FALSE; + + const gchar * translate = C_("session_menu:switchfrom", "1"); + if (g_strcmp0(translate, "1") != 0) { + no_name_in_lang = TRUE; + } + + if (variant == NULL || g_variant_get_string(variant, NULL) == NULL || + g_variant_get_string(variant, NULL)[0] == '\0' || no_name_in_lang) { + finalstring = _("Switch User..."); + set_ellipsize = FALSE; + } + + if (finalstring == NULL) { + const gchar * username = g_variant_get_string(variant, NULL); + GtkStyle * style = gtk_widget_get_style(GTK_WIDGET(gmi)); + + PangoLayout * layout = pango_layout_new(gtk_widget_get_pango_context(GTK_WIDGET(gmi))); + pango_layout_set_text (layout, username, -1); + pango_layout_set_font_description(layout, style->font_desc); + + gint width; + pango_layout_get_pixel_size(layout, &width, NULL); + g_object_unref(layout); + g_debug("Username width %dpx", width); + + gint point = pango_font_description_get_size(style->font_desc); + g_debug("Font size %f pt", (gfloat)point / PANGO_SCALE); + + gdouble dpi = gdk_screen_get_resolution(gdk_screen_get_default()); + g_debug("Screen DPI %f", dpi); + + gdouble pixels_per_em = ((point * dpi) / 72.0f) / PANGO_SCALE; + gdouble ems = width / pixels_per_em; + g_debug("Username width %fem", ems); + + finalstring = g_strdup_printf(_("Switch From %s..."), username); + if (ems >= 20.0f) { + set_ellipsize = TRUE; + } else { + set_ellipsize = FALSE; + } + + } + gtk_menu_item_set_label(gmi, finalstring); + + GtkLabel * label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(gmi))); + if (label != NULL) { + if (set_ellipsize) { + gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_END); + } else { + gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_NONE); + } + } return; } static const gchar * dbusmenu_item_data = "dbusmenu-item"; -/* IF the label or icon changes we need to grab that and update - the menu item */ static void -restart_property_change (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer user_data) +restart_property_change (DbusmenuMenuitem * item, + const gchar * property, + GVariant * variant, + gpointer user_data) { DbusmenuGtkClient * client = DBUSMENU_GTKCLIENT(user_data); GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(client, item); @@ -482,14 +601,14 @@ restart_property_change (DbusmenuMenuitem * item, const gchar * property, GVaria } g_object_unref(G_OBJECT(gicon)); } - return; } -/* Builds the restart item which is a more traditional GTK image - menu item that puts the graphic into the gutter. */ static gboolean -build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) +build_restart_item (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data) { GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_image_menu_item_new()); if (gmi == NULL) { @@ -500,7 +619,6 @@ build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(restart_property_change), client); - /* Grab the inital variants and put them into the item */ GVariant * variant; variant = dbusmenu_menuitem_property_get_variant(newitem, RESTART_ITEM_LABEL); if (variant != NULL) { @@ -515,36 +633,63 @@ build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm return TRUE; } - -/* Callback for when the style changes so we can reevaluate the - size of the user name with the potentially new font. */ static void -switch_style_set (GtkWidget * widget, GtkStyle * prev_style, gpointer user_data) +switch_style_set (GtkWidget * widget, + GtkStyle * prev_style, + gpointer user_data) { DbusmenuGtkClient * client = DBUSMENU_GTKCLIENT(user_data); - DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), dbusmenu_item_data)); + DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), + dbusmenu_item_data)); - switch_property_change(mi, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_variant(mi, MENU_SWITCH_USER), client); + switch_property_change (mi, + MENU_SWITCH_USER, + dbusmenu_menuitem_property_get_variant(mi, MENU_SWITCH_USER), + client); return; } -/* This function checks to see if the user name is short enough - to not need ellipsing itself, or if, it will get ellipsed by - the standard label processor. */ static gboolean -build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) +build_menu_switch (DbusmenuMenuitem * newitem, + DbusmenuMenuitem * parent, + DbusmenuClient * client, + gpointer user_data) { GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); if (gmi == NULL) { return FALSE; } - g_object_set_data(G_OBJECT(gmi), dbusmenu_item_data, newitem); + + g_object_set_data(G_OBJECT(gmi), dbusmenu_item_data, newitem); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); - g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(switch_property_change), client); - g_signal_connect(G_OBJECT(gmi), "style-set", G_CALLBACK(switch_style_set), client); - switch_property_change(newitem, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_variant(newitem, MENU_SWITCH_USER), client); + g_signal_connect (G_OBJECT(newitem), + DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, + G_CALLBACK(switch_property_change), + client); + g_signal_connect (G_OBJECT(gmi), + "style-set", + G_CALLBACK(switch_style_set), + client); + + switch_property_change (newitem, + MENU_SWITCH_USER, + dbusmenu_menuitem_property_get_variant(newitem, MENU_SWITCH_USER), client); + + return TRUE; +} - return TRUE; +static void +indicator_session_update_users_label (IndicatorSession* self, + const gchar* name) +{ + g_debug ("update users label"); + + if (name == NULL){ + gtk_widget_hide(GTK_WIDGET(self->users.label)); + return; + } + gtk_label_set_text (self->users.label, g_strdup(name)); + gtk_widget_show(GTK_WIDGET(self->users.label)); } diff --git a/src/lock-helper.c b/src/lock-helper.c index 9b15070..4c91aa5 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -20,12 +20,12 @@ with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <glib/gi18n.h> -#include <gconf/gconf-client.h> +#include <gio/gio.h> #include <dbus/dbus-glib.h> #include "lock-helper.h" -#define GCONF_DIR "/apps/gnome-screensaver" -#define GCONF_KEY GCONF_DIR "/lock_enabled" +#define SCREENSAVER_SCHEMA "org.gnome.desktop.screensaver" +#define SCREENSAVER_LOCK_ENABLED_KEY "lock-enabled" static DBusGProxy * gss_proxy = NULL; static GMainLoop * gss_mainloop = NULL; @@ -34,7 +34,7 @@ static DBusGProxyCall * cookie_call = NULL; static gboolean is_guest = FALSE; -static GConfClient * gconf_client = NULL; +static GSettings * settings = NULL; void build_gss_proxy (void); @@ -131,11 +131,11 @@ will_lock_screen (void) return FALSE; } - if (gconf_client == NULL) { - gconf_client = gconf_client_get_default(); + if (settings == NULL) { + settings = g_settings_new (SCREENSAVER_SCHEMA); } - return gconf_client_get_bool (gconf_client, GCONF_KEY, NULL); + return g_settings_get_boolean (settings, SCREENSAVER_LOCK_ENABLED_KEY); } /* When the screensave go active, if we've got a mainloop @@ -150,11 +150,22 @@ gss_active_changed (DBusGProxy * proxy, gboolean active, gpointer data) return; } +static gboolean +get_greeter_mode (void) +{ + const gchar *var; + var = g_getenv("INDICATOR_GREETER_MODE"); + return (g_strcmp0(var, "1") == 0); +} + /* Build the gss proxy and set up it's signals */ void build_gss_proxy (void) { if (gss_proxy == NULL) { + if (get_greeter_mode ()) + return; /* Don't start/lock the screensaver from the login screen */ + DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); g_return_if_fail(session_bus != NULL); diff --git a/src/consolekit-manager.xml b/src/org.freedesktop.ConsoleKit.Manager.xml index f903b55..f903b55 100644 --- a/src/consolekit-manager.xml +++ b/src/org.freedesktop.ConsoleKit.Manager.xml diff --git a/src/org.freedesktop.ConsoleKit.Seat.xml b/src/org.freedesktop.ConsoleKit.Seat.xml new file mode 100644 index 0000000..d95990b --- /dev/null +++ b/src/org.freedesktop.ConsoleKit.Seat.xml @@ -0,0 +1,164 @@ +<?xml version="1.0" encoding="UTF-8"?> +<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> + + <interface name="org.freedesktop.ConsoleKit.Seat"> + <doc:doc> + <doc:description> + <doc:para>A seat is a collection of sessions and a set of hardware (usually at +least a keyboard and mouse). Only one session may be active on a +seat at a time.</doc:para> + </doc:description> + </doc:doc> + + <method name="GetId"> + <arg name="sid" direction="out" type="o"> + <doc:doc> + <doc:summary>Seat ID</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Returns the ID for Seat.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="GetSessions"> + <arg name="sessions" direction="out" type="ao"> + <doc:doc> + <doc:summary>an array of Session IDs</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This gets a list of all the <doc:ref type="interface" to="Session">Sessions</doc:ref> + that are currently attached to this seat.</doc:para> + <doc:para>Each Session ID is an D-Bus object path for the object that implements the + <doc:ref type="interface" to="Session">Session</doc:ref> interface.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="GetDevices"> + <arg name="devices" direction="out" type="a(ss)"> + <doc:doc> + <doc:summary>an array of devices</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This gets a list of all the devices + that are currently associated with this seat.</doc:para> + <doc:para>Each device is an D-Bus structure that represents + the device type and the device id. + </doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="GetActiveSession"> + <arg name="ssid" direction="out" type="o"> + <doc:doc> + <doc:summary>Session ID</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Gets the Session ID that is currently active on this Seat.</doc:para> + <doc:para>Returns NULL if there is no active session.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="CanActivateSessions"> + <arg name="can_activate" direction="out" type="b"> + <doc:doc> + <doc:summary>TRUE if seat supports session activation</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description><doc:para>Used to determine whether the seat supports session activation.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="ActivateSession"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="ssid" direction="in" type="o"> + <doc:doc> + <doc:summary>Session ID</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Attempt to activate the specified session. In most + cases, if successful, this will cause the session to + become visible and take control of the hardware that is + associated with this seat.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="method" to="Session.Activate">Activate()</doc:ref></doc:seealso> + </doc:doc> + </method> + + <signal name="ActiveSessionChanged"> + <arg name="ssid" type="o"> + <doc:doc> + <doc:summary>Session ID</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when the active session has changed.</doc:para> + </doc:description> + </doc:doc> + </signal> + <signal name="SessionAdded"> + <arg name="ssid" type="o"> + <doc:doc> + <doc:summary>Session ID</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when a session has been added to the seat.</doc:para> + </doc:description> + </doc:doc> + </signal> + <signal name="SessionRemoved"> + <arg name="ssid" type="o"> + <doc:doc> + <doc:summary>Session ID</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when a session has been removed from the seat.</doc:para> + </doc:description> + </doc:doc> + </signal> + <signal name="DeviceAdded"> + <arg name="device" type="(ss)"> + <doc:doc> + <doc:summary>Device structure</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when a device has been associated with the seat.</doc:para> + </doc:description> + </doc:doc> + </signal> + <signal name="DeviceRemoved"> + <arg name="device" type="(ss)"> + <doc:doc> + <doc:summary>Device structure</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when a device has been dissociated from the seat.</doc:para> + </doc:description> + </doc:doc> + </signal> + </interface> +</node> diff --git a/src/consolekit-session.xml b/src/org.freedesktop.ConsoleKit.Session.xml index b6e1cdb..b6e1cdb 100644 --- a/src/consolekit-session.xml +++ b/src/org.freedesktop.ConsoleKit.Session.xml diff --git a/src/sane-rules.h b/src/sane-rules.h new file mode 100644 index 0000000..0b72e52 --- /dev/null +++ b/src/sane-rules.h @@ -0,0 +1,778 @@ +void populate_scsi_scanners (GHashTable* scanners) +{ + GList* epson = NULL; + epson = g_list_append (epson, g_strdup ("GT-9700")); + epson = g_list_append (epson, g_strdup ("GT-9800")); + epson = g_list_append (epson, g_strdup ("Perfection1200")); + epson = g_list_append (epson, g_strdup ("Perfection636")); + epson = g_list_append (epson, g_strdup ("SCANNER GT-7000")); + g_hash_table_insert (scanners, + g_strdup("EPSON"), + epson); + + + GList* hp = NULL; + hp = g_list_append (hp, g_strdup ("C1130A")); + hp = g_list_append (hp, g_strdup ("C1750A")); + hp = g_list_append (hp, g_strdup ("C1790A")); + hp = g_list_append (hp, g_strdup ("C2500A")); + hp = g_list_append (hp, g_strdup ("C2520A")); + hp = g_list_append (hp, g_strdup ("C5110A")); + hp = g_list_append (hp, g_strdup ("C6270A")); + hp = g_list_append (hp, g_strdup ("C7670A")); + g_hash_table_insert (scanners, + g_strdup("HP"), + hp); +} + + + +void populate_usb_scanners (GHashTable* scanners) +{ + GList* hp = NULL; + + hp = g_list_append (hp, g_strdup ("0101")); + hp = g_list_append (hp, g_strdup ("0105")); + hp = g_list_append (hp, g_strdup ("0201")); + hp = g_list_append (hp, g_strdup ("0205")); + hp = g_list_append (hp, g_strdup ("0305")); + hp = g_list_append (hp, g_strdup ("0401")); + hp = g_list_append (hp, g_strdup ("0405")); + hp = g_list_append (hp, g_strdup ("0505")); + hp = g_list_append (hp, g_strdup ("0601")); + hp = g_list_append (hp, g_strdup ("0605")); + hp = g_list_append (hp, g_strdup ("0701")); + hp = g_list_append (hp, g_strdup ("0705")); + hp = g_list_append (hp, g_strdup ("0801")); + hp = g_list_append (hp, g_strdup ("0805")); + hp = g_list_append (hp, g_strdup ("0901")); + hp = g_list_append (hp, g_strdup ("0a01")); + hp = g_list_append (hp, g_strdup ("0b01")); + hp = g_list_append (hp, g_strdup ("1005")); + hp = g_list_append (hp, g_strdup ("1105")); + hp = g_list_append (hp, g_strdup ("1205")); + hp = g_list_append (hp, g_strdup ("1305")); + hp = g_list_append (hp, g_strdup ("1405")); + hp = g_list_append (hp, g_strdup ("1705")); + hp = g_list_append (hp, g_strdup ("1805")); + hp = g_list_append (hp, g_strdup ("2005")); + hp = g_list_append (hp, g_strdup ("2205")); + hp = g_list_append (hp, g_strdup ("2305")); + hp = g_list_append (hp, g_strdup ("2405")); + hp = g_list_append (hp, g_strdup ("2605")); + hp = g_list_append (hp, g_strdup ("2805")); + hp = g_list_append (hp, g_strdup ("3805")); + hp = g_list_append (hp, g_strdup ("3905")); + hp = g_list_append (hp, g_strdup ("3B17")); + hp = g_list_append (hp, g_strdup ("4105")); + hp = g_list_append (hp, g_strdup ("4205")); + hp = g_list_append (hp, g_strdup ("4305")); + hp = g_list_append (hp, g_strdup ("4505")); + hp = g_list_append (hp, g_strdup ("4605")); + hp = g_list_append (hp, g_strdup ("5617")); + hp = g_list_append (hp, g_strdup ("5717")); + + g_hash_table_insert (scanners, + g_strdup("03f0"), + hp); + + GList* mustek_2 = NULL; + mustek_2 = g_list_append (mustek_2, g_strdup ("1000")); + mustek_2 = g_list_append (mustek_2, g_strdup ("1001")); + g_hash_table_insert (scanners, + g_strdup("0400"), + mustek_2); + + GList* kodak = NULL; + kodak = g_list_append (kodak, g_strdup ("6001")); + kodak = g_list_append (kodak, g_strdup ("6002")); + kodak = g_list_append (kodak, g_strdup ("6003")); + kodak = g_list_append (kodak, g_strdup ("6004")); + kodak = g_list_append (kodak, g_strdup ("6005")); + g_hash_table_insert (scanners, + g_strdup("040a"), + kodak); + + GList* creative = NULL; + + creative = g_list_append (creative, g_strdup ("4007")); + + g_hash_table_insert (scanners, + g_strdup("041e"), + creative); + + GList* lexmark = NULL; + + lexmark = g_list_append (lexmark, g_strdup("002d")); + lexmark = g_list_append (lexmark, g_strdup("0060")); + lexmark = g_list_append (lexmark, g_strdup("007c")); + lexmark = g_list_append (lexmark, g_strdup("007d")); + + g_hash_table_insert (scanners, + g_strdup("043d"), + lexmark); + + + GList* genius = NULL; + genius = g_list_append (genius, g_strdup("2004")); + genius = g_list_append (genius, g_strdup("2007")); + genius = g_list_append (genius, g_strdup("2008")); + genius = g_list_append (genius, g_strdup("2009")); + genius = g_list_append (genius, g_strdup("2011")); + genius = g_list_append (genius, g_strdup("2013")); + genius = g_list_append (genius, g_strdup("2014")); + genius = g_list_append (genius, g_strdup("2015")); + genius = g_list_append (genius, g_strdup("2016")); + genius = g_list_append (genius, g_strdup("2017")); + genius = g_list_append (genius, g_strdup("201a")); + genius = g_list_append (genius, g_strdup("201b")); + genius = g_list_append (genius, g_strdup("201d")); + genius = g_list_append (genius, g_strdup("201e")); + genius = g_list_append (genius, g_strdup("201f")); + genius = g_list_append (genius, g_strdup("20c1")); + g_hash_table_insert (scanners, + g_strdup("0458"), + genius); + + GList* medion = NULL; + medion = g_list_append (medion, g_strdup("0377")); + g_hash_table_insert (scanners, + g_strdup("0461"), + medion); + + GList* trust = NULL; + trust = g_list_append (trust, g_strdup("1000")); + trust = g_list_append (trust, g_strdup("1002")); + g_hash_table_insert (scanners, + g_strdup("047b"), + trust); + + GList* kyocera = NULL; + kyocera = g_list_append (kyocera, g_strdup("0335")); + g_hash_table_insert (scanners, + g_strdup("0482"), + kyocera); + + GList* compaq = NULL; + compaq = g_list_append (compaq, g_strdup("001a")); + g_hash_table_insert (scanners, + g_strdup("049f"), + compaq); + GList* benq = NULL; + benq = g_list_append (benq, g_strdup("1a20")); + benq = g_list_append (benq, g_strdup("1a2a")); + benq = g_list_append (benq, g_strdup("2022")); + benq = g_list_append (benq, g_strdup("2040")); + benq = g_list_append (benq, g_strdup("2060")); + benq = g_list_append (benq, g_strdup("207e")); + benq = g_list_append (benq, g_strdup("20b0")); + benq = g_list_append (benq, g_strdup("20be")); + benq = g_list_append (benq, g_strdup("20c0")); + benq = g_list_append (benq, g_strdup("20de")); + benq = g_list_append (benq, g_strdup("20f8")); + benq = g_list_append (benq, g_strdup("20fc")); + benq = g_list_append (benq, g_strdup("20fe")); + benq = g_list_append (benq, g_strdup("2137")); + benq = g_list_append (benq, g_strdup("2211")); + g_hash_table_insert (scanners, + g_strdup("04a5"), + benq); + + GList* visioneer = NULL; + visioneer = g_list_append (visioneer, g_strdup("0229")); + visioneer = g_list_append (visioneer, g_strdup("0390")); + visioneer = g_list_append (visioneer, g_strdup("0420")); + visioneer = g_list_append (visioneer, g_strdup("0421")); + visioneer = g_list_append (visioneer, g_strdup("0422")); + visioneer = g_list_append (visioneer, g_strdup("0423")); + visioneer = g_list_append (visioneer, g_strdup("0424")); + visioneer = g_list_append (visioneer, g_strdup("0426")); + visioneer = g_list_append (visioneer, g_strdup("0427")); + visioneer = g_list_append (visioneer, g_strdup("0444")); + visioneer = g_list_append (visioneer, g_strdup("0446")); + visioneer = g_list_append (visioneer, g_strdup("0447")); + visioneer = g_list_append (visioneer, g_strdup("0448")); + visioneer = g_list_append (visioneer, g_strdup("0449")); + visioneer = g_list_append (visioneer, g_strdup("044c")); + visioneer = g_list_append (visioneer, g_strdup("0474")); + visioneer = g_list_append (visioneer, g_strdup("0475")); + visioneer = g_list_append (visioneer, g_strdup("0477")); + visioneer = g_list_append (visioneer, g_strdup("0478")); + visioneer = g_list_append (visioneer, g_strdup("0479")); + visioneer = g_list_append (visioneer, g_strdup("047a")); + visioneer = g_list_append (visioneer, g_strdup("047b")); + visioneer = g_list_append (visioneer, g_strdup("047c")); + visioneer = g_list_append (visioneer, g_strdup("048c")); + visioneer = g_list_append (visioneer, g_strdup("048d")); + visioneer = g_list_append (visioneer, g_strdup("048e")); + visioneer = g_list_append (visioneer, g_strdup("048f")); + visioneer = g_list_append (visioneer, g_strdup("0490")); + visioneer = g_list_append (visioneer, g_strdup("0491")); + visioneer = g_list_append (visioneer, g_strdup("0492")); + visioneer = g_list_append (visioneer, g_strdup("0493")); + visioneer = g_list_append (visioneer, g_strdup("0494")); + visioneer = g_list_append (visioneer, g_strdup("0495")); + visioneer = g_list_append (visioneer, g_strdup("0497")); + visioneer = g_list_append (visioneer, g_strdup("0498")); + visioneer = g_list_append (visioneer, g_strdup("0499")); + visioneer = g_list_append (visioneer, g_strdup("049a")); + visioneer = g_list_append (visioneer, g_strdup("049b")); + visioneer = g_list_append (visioneer, g_strdup("049c")); + visioneer = g_list_append (visioneer, g_strdup("049d")); + visioneer = g_list_append (visioneer, g_strdup("04a7")); + visioneer = g_list_append (visioneer, g_strdup("04ac")); + g_hash_table_insert (scanners, + g_strdup("04a7"), + visioneer); + GList* canon = NULL; + canon = g_list_append (canon, g_strdup("1601")); + canon = g_list_append (canon, g_strdup("1602")); + canon = g_list_append (canon, g_strdup("1603")); + canon = g_list_append (canon, g_strdup("1604")); + canon = g_list_append (canon, g_strdup("1606")); + canon = g_list_append (canon, g_strdup("1607")); + canon = g_list_append (canon, g_strdup("1608")); + canon = g_list_append (canon, g_strdup("1609")); + canon = g_list_append (canon, g_strdup("160a")); + canon = g_list_append (canon, g_strdup("160b")); + canon = g_list_append (canon, g_strdup("1706")); + canon = g_list_append (canon, g_strdup("1707")); + canon = g_list_append (canon, g_strdup("1708")); + canon = g_list_append (canon, g_strdup("1709")); + canon = g_list_append (canon, g_strdup("170a")); + canon = g_list_append (canon, g_strdup("170b")); + canon = g_list_append (canon, g_strdup("170c")); + canon = g_list_append (canon, g_strdup("170d")); + canon = g_list_append (canon, g_strdup("170e")); + canon = g_list_append (canon, g_strdup("1712")); + canon = g_list_append (canon, g_strdup("1713")); + canon = g_list_append (canon, g_strdup("1714")); + canon = g_list_append (canon, g_strdup("1715")); + canon = g_list_append (canon, g_strdup("1716")); + canon = g_list_append (canon, g_strdup("1717")); + canon = g_list_append (canon, g_strdup("1718")); + canon = g_list_append (canon, g_strdup("1719")); + canon = g_list_append (canon, g_strdup("171a")); + canon = g_list_append (canon, g_strdup("171b")); + canon = g_list_append (canon, g_strdup("171c")); + canon = g_list_append (canon, g_strdup("1721")); + canon = g_list_append (canon, g_strdup("1722")); + canon = g_list_append (canon, g_strdup("1723")); + canon = g_list_append (canon, g_strdup("1724")); + canon = g_list_append (canon, g_strdup("1725")); + canon = g_list_append (canon, g_strdup("1726")); + canon = g_list_append (canon, g_strdup("1727")); + canon = g_list_append (canon, g_strdup("1728")); + canon = g_list_append (canon, g_strdup("1729")); + canon = g_list_append (canon, g_strdup("172b")); + canon = g_list_append (canon, g_strdup("172c")); + canon = g_list_append (canon, g_strdup("172d")); + canon = g_list_append (canon, g_strdup("172e")); + canon = g_list_append (canon, g_strdup("172f")); + canon = g_list_append (canon, g_strdup("1730")); + canon = g_list_append (canon, g_strdup("1731")); + canon = g_list_append (canon, g_strdup("1732")); + canon = g_list_append (canon, g_strdup("1733")); + canon = g_list_append (canon, g_strdup("1734")); + canon = g_list_append (canon, g_strdup("1735")); + canon = g_list_append (canon, g_strdup("1736")); + canon = g_list_append (canon, g_strdup("173a")); + canon = g_list_append (canon, g_strdup("173b")); + canon = g_list_append (canon, g_strdup("173c")); + canon = g_list_append (canon, g_strdup("173d")); + canon = g_list_append (canon, g_strdup("173e")); + canon = g_list_append (canon, g_strdup("173f")); + canon = g_list_append (canon, g_strdup("1740")); + canon = g_list_append (canon, g_strdup("1741")); + canon = g_list_append (canon, g_strdup("1742")); + canon = g_list_append (canon, g_strdup("1901")); + canon = g_list_append (canon, g_strdup("1904")); + canon = g_list_append (canon, g_strdup("1905")); + canon = g_list_append (canon, g_strdup("1909")); + canon = g_list_append (canon, g_strdup("190a")); + canon = g_list_append (canon, g_strdup("2204")); + canon = g_list_append (canon, g_strdup("2206")); + canon = g_list_append (canon, g_strdup("2207")); + canon = g_list_append (canon, g_strdup("2208")); + canon = g_list_append (canon, g_strdup("220d")); + canon = g_list_append (canon, g_strdup("220e")); + canon = g_list_append (canon, g_strdup("2213")); + canon = g_list_append (canon, g_strdup("221c")); + canon = g_list_append (canon, g_strdup("2220")); + canon = g_list_append (canon, g_strdup("2222")); + canon = g_list_append (canon, g_strdup("262f")); + canon = g_list_append (canon, g_strdup("2630")); + canon = g_list_append (canon, g_strdup("263c")); + canon = g_list_append (canon, g_strdup("263d")); + canon = g_list_append (canon, g_strdup("263e")); + canon = g_list_append (canon, g_strdup("263f")); + canon = g_list_append (canon, g_strdup("264c")); + canon = g_list_append (canon, g_strdup("264d")); + canon = g_list_append (canon, g_strdup("264e")); + canon = g_list_append (canon, g_strdup("264f")); + canon = g_list_append (canon, g_strdup("2659")); + canon = g_list_append (canon, g_strdup("265d")); + canon = g_list_append (canon, g_strdup("265e")); + canon = g_list_append (canon, g_strdup("265f")); + canon = g_list_append (canon, g_strdup("2660")); + canon = g_list_append (canon, g_strdup("2684")); + canon = g_list_append (canon, g_strdup("2686")); + canon = g_list_append (canon, g_strdup("26a3")); + canon = g_list_append (canon, g_strdup("26b0")); + canon = g_list_append (canon, g_strdup("26b4")); + canon = g_list_append (canon, g_strdup("26b5")); + canon = g_list_append (canon, g_strdup("26ec")); + canon = g_list_append (canon, g_strdup("26ed")); + canon = g_list_append (canon, g_strdup("26ee")); + g_hash_table_insert (scanners, + g_strdup("04a9"), + canon); + + GList* nikon = NULL; + nikon = g_list_append (nikon, g_strdup ("4000")); + nikon = g_list_append (nikon, g_strdup ("4001")); + nikon = g_list_append (nikon, g_strdup ("4002")); + g_hash_table_insert (scanners, + g_strdup("04b0"), + nikon); + + GList* epson = NULL; + + // for testing (its a printer not a scanner!) + //epson = g_list_append (epson, g_strdup ("0001")); + + epson = g_list_append (epson, g_strdup("0101")); + epson = g_list_append (epson, g_strdup("0103")); + epson = g_list_append (epson, g_strdup("0104")); + epson = g_list_append (epson, g_strdup("0105")); + epson = g_list_append (epson, g_strdup("0106")); + epson = g_list_append (epson, g_strdup("0107")); + epson = g_list_append (epson, g_strdup("0109")); + epson = g_list_append (epson, g_strdup("010a")); + epson = g_list_append (epson, g_strdup("010b")); + epson = g_list_append (epson, g_strdup("010c")); + epson = g_list_append (epson, g_strdup("010e")); + epson = g_list_append (epson, g_strdup("010f")); + epson = g_list_append (epson, g_strdup("0110")); + epson = g_list_append (epson, g_strdup("0112")); + epson = g_list_append (epson, g_strdup("0114")); + epson = g_list_append (epson, g_strdup("011b")); + epson = g_list_append (epson, g_strdup("011c")); + epson = g_list_append (epson, g_strdup("011d")); + epson = g_list_append (epson, g_strdup("011e")); + epson = g_list_append (epson, g_strdup("011f")); + epson = g_list_append (epson, g_strdup("0120")); + epson = g_list_append (epson, g_strdup("0121")); + epson = g_list_append (epson, g_strdup("0122")); + epson = g_list_append (epson, g_strdup("0126")); + epson = g_list_append (epson, g_strdup("0128")); + epson = g_list_append (epson, g_strdup("0129")); + epson = g_list_append (epson, g_strdup("012a")); + epson = g_list_append (epson, g_strdup("012b")); + epson = g_list_append (epson, g_strdup("012c")); + epson = g_list_append (epson, g_strdup("0135")); + epson = g_list_append (epson, g_strdup("0801")); + epson = g_list_append (epson, g_strdup("0802")); + epson = g_list_append (epson, g_strdup("0805")); + epson = g_list_append (epson, g_strdup("0806")); + epson = g_list_append (epson, g_strdup("0807")); + epson = g_list_append (epson, g_strdup("0808")); + epson = g_list_append (epson, g_strdup("080c")); + epson = g_list_append (epson, g_strdup("080d")); + epson = g_list_append (epson, g_strdup("080e")); + epson = g_list_append (epson, g_strdup("080f")); + epson = g_list_append (epson, g_strdup("0810")); + epson = g_list_append (epson, g_strdup("0811")); + epson = g_list_append (epson, g_strdup("0813")); + epson = g_list_append (epson, g_strdup("0814")); + epson = g_list_append (epson, g_strdup("0815")); + epson = g_list_append (epson, g_strdup("0817")); + epson = g_list_append (epson, g_strdup("0818")); + epson = g_list_append (epson, g_strdup("0819")); + epson = g_list_append (epson, g_strdup("081a")); + epson = g_list_append (epson, g_strdup("081c")); + epson = g_list_append (epson, g_strdup("081d")); + epson = g_list_append (epson, g_strdup("081f")); + epson = g_list_append (epson, g_strdup("0820")); + epson = g_list_append (epson, g_strdup("0827")); + epson = g_list_append (epson, g_strdup("0828")); + epson = g_list_append (epson, g_strdup("0829")); + epson = g_list_append (epson, g_strdup("082a")); + epson = g_list_append (epson, g_strdup("082b")); + epson = g_list_append (epson, g_strdup("082e")); + epson = g_list_append (epson, g_strdup("082f")); + epson = g_list_append (epson, g_strdup("0830")); + epson = g_list_append (epson, g_strdup("0833")); + epson = g_list_append (epson, g_strdup("0834")); + epson = g_list_append (epson, g_strdup("0835")); + epson = g_list_append (epson, g_strdup("0836")); + epson = g_list_append (epson, g_strdup("0837")); + epson = g_list_append (epson, g_strdup("0838")); + epson = g_list_append (epson, g_strdup("0839")); + epson = g_list_append (epson, g_strdup("083a")); + epson = g_list_append (epson, g_strdup("083c")); + epson = g_list_append (epson, g_strdup("0841")); + epson = g_list_append (epson, g_strdup("0843")); + epson = g_list_append (epson, g_strdup("0844")); + epson = g_list_append (epson, g_strdup("0846")); + epson = g_list_append (epson, g_strdup("0847")); + epson = g_list_append (epson, g_strdup("0848")); + epson = g_list_append (epson, g_strdup("0849")); + epson = g_list_append (epson, g_strdup("084a")); + epson = g_list_append (epson, g_strdup("084c")); + epson = g_list_append (epson, g_strdup("084d")); + epson = g_list_append (epson, g_strdup("084f")); + epson = g_list_append (epson, g_strdup("0851")); + epson = g_list_append (epson, g_strdup("0854")); + epson = g_list_append (epson, g_strdup("0856")); + g_hash_table_insert (scanners, + g_strdup("04b8"), + epson); + + GList* fujitsu = NULL; + fujitsu = g_list_append (fujitsu, g_strdup ("1029")); + fujitsu = g_list_append (fujitsu, g_strdup ("1041")); + fujitsu = g_list_append (fujitsu, g_strdup ("1042")); + fujitsu = g_list_append (fujitsu, g_strdup ("1078")); + fujitsu = g_list_append (fujitsu, g_strdup ("1095")); + fujitsu = g_list_append (fujitsu, g_strdup ("1096")); + fujitsu = g_list_append (fujitsu, g_strdup ("1097")); + fujitsu = g_list_append (fujitsu, g_strdup ("10ad")); + fujitsu = g_list_append (fujitsu, g_strdup ("10ae")); + fujitsu = g_list_append (fujitsu, g_strdup ("10af")); + fujitsu = g_list_append (fujitsu, g_strdup ("10c7")); + fujitsu = g_list_append (fujitsu, g_strdup ("10cf")); + fujitsu = g_list_append (fujitsu, g_strdup ("10e0")); + fujitsu = g_list_append (fujitsu, g_strdup ("10e1")); + fujitsu = g_list_append (fujitsu, g_strdup ("10e2")); + fujitsu = g_list_append (fujitsu, g_strdup ("10e6")); + fujitsu = g_list_append (fujitsu, g_strdup ("10e7")); + fujitsu = g_list_append (fujitsu, g_strdup ("10ef")); + fujitsu = g_list_append (fujitsu, g_strdup ("10f2")); + fujitsu = g_list_append (fujitsu, g_strdup ("10fe")); + fujitsu = g_list_append (fujitsu, g_strdup ("1135")); + fujitsu = g_list_append (fujitsu, g_strdup ("114a")); + fujitsu = g_list_append (fujitsu, g_strdup ("114d")); + fujitsu = g_list_append (fujitsu, g_strdup ("114e")); + fujitsu = g_list_append (fujitsu, g_strdup ("114f")); + fujitsu = g_list_append (fujitsu, g_strdup ("1150")); + fujitsu = g_list_append (fujitsu, g_strdup ("1155")); + fujitsu = g_list_append (fujitsu, g_strdup ("1156")); + fujitsu = g_list_append (fujitsu, g_strdup ("116f")); + fujitsu = g_list_append (fujitsu, g_strdup ("1174")); + fujitsu = g_list_append (fujitsu, g_strdup ("1175")); + fujitsu = g_list_append (fujitsu, g_strdup ("1176")); + fujitsu = g_list_append (fujitsu, g_strdup ("1177")); + fujitsu = g_list_append (fujitsu, g_strdup ("1178")); + fujitsu = g_list_append (fujitsu, g_strdup ("117f")); + fujitsu = g_list_append (fujitsu, g_strdup ("119d")); + fujitsu = g_list_append (fujitsu, g_strdup ("119e")); + fujitsu = g_list_append (fujitsu, g_strdup ("119f")); + fujitsu = g_list_append (fujitsu, g_strdup ("11a0")); + fujitsu = g_list_append (fujitsu, g_strdup ("11a2")); + fujitsu = g_list_append (fujitsu, g_strdup ("11ed")); + fujitsu = g_list_append (fujitsu, g_strdup ("11ee")); + fujitsu = g_list_append (fujitsu, g_strdup ("11ef")); + fujitsu = g_list_append (fujitsu, g_strdup ("11f1")); + fujitsu = g_list_append (fujitsu, g_strdup ("11f2")); + fujitsu = g_list_append (fujitsu, g_strdup ("11f3")); + fujitsu = g_list_append (fujitsu, g_strdup ("11f4")); + fujitsu = g_list_append (fujitsu, g_strdup ("11fc")); + g_hash_table_insert (scanners, + g_strdup("04c5"), + fujitsu); + GList* konica = NULL; + konica = g_list_append (konica, g_strdup ("0722")); + g_hash_table_insert (scanners, + g_strdup("04c8"), + konica); + GList* panasonic = NULL; + panasonic = g_list_append (panasonic, g_strdup ("1000")); + panasonic = g_list_append (panasonic, g_strdup ("1001")); + panasonic = g_list_append (panasonic, g_strdup ("1006")); + panasonic = g_list_append (panasonic, g_strdup ("1007")); + panasonic = g_list_append (panasonic, g_strdup ("1009")); + panasonic = g_list_append (panasonic, g_strdup ("100a")); + panasonic = g_list_append (panasonic, g_strdup ("100f")); + panasonic = g_list_append (panasonic, g_strdup ("1010")); + g_hash_table_insert (scanners, + g_strdup("04da"), + panasonic); + + GList* samsung = NULL; + + samsung = g_list_append (samsung, g_strdup ("341b")); + samsung = g_list_append (samsung, g_strdup ("341f")); + samsung = g_list_append (samsung, g_strdup ("3426")); + samsung = g_list_append (samsung, g_strdup ("342a")); + samsung = g_list_append (samsung, g_strdup ("342b")); + samsung = g_list_append (samsung, g_strdup ("342c")); + samsung = g_list_append (samsung, g_strdup ("3433")); + samsung = g_list_append (samsung, g_strdup ("3434")); + samsung = g_list_append (samsung, g_strdup ("343c")); + samsung = g_list_append (samsung, g_strdup ("3434")); + g_hash_table_insert (scanners, + g_strdup("04e8"), + samsung); + + GList* pentax = NULL; + pentax = g_list_append (pentax, g_strdup ("2038")); + g_hash_table_insert (scanners, + g_strdup("04f9"), + pentax); + + GList* apitek = NULL; + apitek = g_list_append (apitek, g_strdup ("0202")); + g_hash_table_insert (scanners, + g_strdup("0553"), + apitek); + + GList* mustek = NULL; + mustek = g_list_append (mustek, g_strdup ("0001")); + mustek = g_list_append (mustek, g_strdup ("0002")); + mustek = g_list_append (mustek, g_strdup ("0006")); + mustek = g_list_append (mustek, g_strdup ("0008")); + mustek = g_list_append (mustek, g_strdup ("0010")); + mustek = g_list_append (mustek, g_strdup ("0210")); + mustek = g_list_append (mustek, g_strdup ("0218")); + mustek = g_list_append (mustek, g_strdup ("0219")); + mustek = g_list_append (mustek, g_strdup ("021a")); + mustek = g_list_append (mustek, g_strdup ("021b")); + mustek = g_list_append (mustek, g_strdup ("021c")); + mustek = g_list_append (mustek, g_strdup ("021d")); + mustek = g_list_append (mustek, g_strdup ("021e")); + mustek = g_list_append (mustek, g_strdup ("021f")); + mustek = g_list_append (mustek, g_strdup ("0409")); + g_hash_table_insert (scanners, + g_strdup("055f"), + mustek); + GList* artec = NULL; + artec = g_list_append (artec, g_strdup ("4002")); + artec = g_list_append (artec, g_strdup ("4003")); + artec = g_list_append (artec, g_strdup ("4004")); + artec = g_list_append (artec, g_strdup ("4005")); + artec = g_list_append (artec, g_strdup ("4006")); + artec = g_list_append (artec, g_strdup ("4007")); + artec = g_list_append (artec, g_strdup ("4009")); + artec = g_list_append (artec, g_strdup ("4010")); + artec = g_list_append (artec, g_strdup ("4011")); + g_hash_table_insert (scanners, + g_strdup("05d8"), + artec); + + GList* microtek = NULL; + microtek = g_list_append (microtek, g_strdup ("0099")); + microtek = g_list_append (microtek, g_strdup ("009a")); + microtek = g_list_append (microtek, g_strdup ("00a3")); + microtek = g_list_append (microtek, g_strdup ("00b6")); + microtek = g_list_append (microtek, g_strdup ("30cf")); + microtek = g_list_append (microtek, g_strdup ("30d4")); + microtek = g_list_append (microtek, g_strdup ("40b3")); + microtek = g_list_append (microtek, g_strdup ("40b8")); + microtek = g_list_append (microtek, g_strdup ("40ca")); + microtek = g_list_append (microtek, g_strdup ("40cb")); + microtek = g_list_append (microtek, g_strdup ("40dd")); + microtek = g_list_append (microtek, g_strdup ("40ff")); + microtek = g_list_append (microtek, g_strdup ("80a3")); + g_hash_table_insert (scanners, + g_strdup("05da"), + microtek); + + GList* avision = NULL; + avision = g_list_append (avision, g_strdup ("0268")); + avision = g_list_append (avision, g_strdup ("026a")); + avision = g_list_append (avision, g_strdup ("0a13")); + avision = g_list_append (avision, g_strdup ("0a15")); + avision = g_list_append (avision, g_strdup ("0a16")); + avision = g_list_append (avision, g_strdup ("0a18")); + avision = g_list_append (avision, g_strdup ("0a19")); + avision = g_list_append (avision, g_strdup ("0a23")); + avision = g_list_append (avision, g_strdup ("0a24")); + avision = g_list_append (avision, g_strdup ("0a25")); + avision = g_list_append (avision, g_strdup ("0a27")); + avision = g_list_append (avision, g_strdup ("0a2a")); + avision = g_list_append (avision, g_strdup ("0a2b")); + avision = g_list_append (avision, g_strdup ("0a2c")); + avision = g_list_append (avision, g_strdup ("0a2d")); + avision = g_list_append (avision, g_strdup ("0a2e")); + avision = g_list_append (avision, g_strdup ("0a2f")); + avision = g_list_append (avision, g_strdup ("0a33")); + avision = g_list_append (avision, g_strdup ("0a3a")); + avision = g_list_append (avision, g_strdup ("0a3c")); + avision = g_list_append (avision, g_strdup ("0a40")); + avision = g_list_append (avision, g_strdup ("0a41")); + avision = g_list_append (avision, g_strdup ("0a45")); + avision = g_list_append (avision, g_strdup ("0a4d")); + avision = g_list_append (avision, g_strdup ("0a4e")); + avision = g_list_append (avision, g_strdup ("0a4f")); + avision = g_list_append (avision, g_strdup ("0a5e")); + avision = g_list_append (avision, g_strdup ("0a61")); + avision = g_list_append (avision, g_strdup ("0a65")); + avision = g_list_append (avision, g_strdup ("0a66")); + avision = g_list_append (avision, g_strdup ("0a68")); + avision = g_list_append (avision, g_strdup ("0a82")); + avision = g_list_append (avision, g_strdup ("0a84")); + avision = g_list_append (avision, g_strdup ("0a93")); + avision = g_list_append (avision, g_strdup ("0a94")); + avision = g_list_append (avision, g_strdup ("0aa1")); + avision = g_list_append (avision, g_strdup ("1a35")); + g_hash_table_insert (scanners, + g_strdup("0638"), + avision); + GList* minolta = NULL; + minolta = g_list_append (minolta, g_strdup ("4004")); + minolta = g_list_append (minolta, g_strdup ("400d")); + minolta = g_list_append (minolta, g_strdup ("400e")); + g_hash_table_insert (scanners, + g_strdup("0686"), + minolta); + + GList* agfa = NULL; + agfa = g_list_append (agfa, g_strdup ("0001")); + agfa = g_list_append (agfa, g_strdup ("0002")); + agfa = g_list_append (agfa, g_strdup ("0100")); + agfa = g_list_append (agfa, g_strdup ("2061")); + agfa = g_list_append (agfa, g_strdup ("208d")); + agfa = g_list_append (agfa, g_strdup ("208f")); + agfa = g_list_append (agfa, g_strdup ("2091")); + agfa = g_list_append (agfa, g_strdup ("2093")); + agfa = g_list_append (agfa, g_strdup ("2095")); + agfa = g_list_append (agfa, g_strdup ("2097")); + agfa = g_list_append (agfa, g_strdup ("20fd")); + agfa = g_list_append (agfa, g_strdup ("20ff")); + g_hash_table_insert (scanners, + g_strdup("06bd"), + minolta); + + GList* umax_2 = NULL; + umax_2 = g_list_append (umax_2, g_strdup ("0020")); + g_hash_table_insert (scanners, + g_strdup("06dc"), + umax_2); + + GList* plustek = NULL; + + plustek = g_list_append (plustek, g_strdup ("0001")); + plustek = g_list_append (plustek, g_strdup ("0010")); + plustek = g_list_append (plustek, g_strdup ("0011")); + plustek = g_list_append (plustek, g_strdup ("0013")); + plustek = g_list_append (plustek, g_strdup ("0015")); + plustek = g_list_append (plustek, g_strdup ("0017")); + plustek = g_list_append (plustek, g_strdup ("0400")); + plustek = g_list_append (plustek, g_strdup ("0401")); + plustek = g_list_append (plustek, g_strdup ("0402")); + plustek = g_list_append (plustek, g_strdup ("0403")); + plustek = g_list_append (plustek, g_strdup ("040b")); + plustek = g_list_append (plustek, g_strdup ("040e")); + plustek = g_list_append (plustek, g_strdup ("0412")); + plustek = g_list_append (plustek, g_strdup ("0413")); + plustek = g_list_append (plustek, g_strdup ("0422")); + plustek = g_list_append (plustek, g_strdup ("0454")); + plustek = g_list_append (plustek, g_strdup ("045f")); + plustek = g_list_append (plustek, g_strdup ("0462")); + plustek = g_list_append (plustek, g_strdup ("0900")); + g_hash_table_insert (scanners, + g_strdup("07b3"), + plustek); + + GList* corex = NULL; + corex = g_list_append (corex, g_strdup ("0002")); + corex = g_list_append (corex, g_strdup ("0005")); + g_hash_table_insert (scanners, + g_strdup("08f0"), + corex); + + GList* xerox = NULL; + xerox = g_list_append (xerox, g_strdup ("3d5d")); + xerox = g_list_append (xerox, g_strdup ("3da4")); + xerox = g_list_append (xerox, g_strdup ("420c")); + xerox = g_list_append (xerox, g_strdup ("4265")); + xerox = g_list_append (xerox, g_strdup ("4293")); + xerox = g_list_append (xerox, g_strdup ("4294")); + g_hash_table_insert (scanners, + g_strdup("0924"), + xerox); + + GList* pentax_2 = NULL; + pentax_2 = g_list_append (pentax_2, g_strdup ("3210")); + g_hash_table_insert (scanners, + g_strdup("0a17"), + pentax_2); + + GList* portable = NULL; + portable = g_list_append (portable, g_strdup ("1000")); + g_hash_table_insert (scanners, + g_strdup("0a53"), + portable); + + GList* syscan = NULL; + syscan = g_list_append (syscan, g_strdup ("4600")); + syscan = g_list_append (syscan, g_strdup ("4802")); + syscan = g_list_append (syscan, g_strdup ("4803")); + syscan = g_list_append (syscan, g_strdup ("480c")); + syscan = g_list_append (syscan, g_strdup ("4810")); + syscan = g_list_append (syscan, g_strdup ("6620")); + g_hash_table_insert (scanners, + g_strdup("0a82"), + syscan); + + GList* canon_2 = NULL; + canon_2 = g_list_append (canon_2, g_strdup ("160c")); + canon_2 = g_list_append (canon_2, g_strdup ("160f")); + canon_2 = g_list_append (canon_2, g_strdup ("1614")); + canon_2 = g_list_append (canon_2, g_strdup ("1617")); + canon_2 = g_list_append (canon_2, g_strdup ("1618")); + canon_2 = g_list_append (canon_2, g_strdup ("161a")); + canon_2 = g_list_append (canon_2, g_strdup ("161b")); + canon_2 = g_list_append (canon_2, g_strdup ("161d")); + canon_2 = g_list_append (canon_2, g_strdup ("1620")); + canon_2 = g_list_append (canon_2, g_strdup ("1622")); + canon_2 = g_list_append (canon_2, g_strdup ("1623")); + canon_2 = g_list_append (canon_2, g_strdup ("1624")); + canon_2 = g_list_append (canon_2, g_strdup ("1626")); + canon_2 = g_list_append (canon_2, g_strdup ("162b")); + canon_2 = g_list_append (canon_2, g_strdup ("1638")); + canon_2 = g_list_append (canon_2, g_strdup ("1639")); + g_hash_table_insert (scanners, + g_strdup("1083"), + canon_2); + + GList* digital = NULL; + digital = g_list_append (digital, g_strdup ("0001")); + g_hash_table_insert (scanners, + g_strdup("1183"), + digital); + + GList* konica_2 = NULL; + konica_2 = g_list_append (konica_2, g_strdup ("2089")); + g_hash_table_insert (scanners, + g_strdup("132b"), + konica_2); + + GList* umax = NULL; + umax = g_list_append (umax, g_strdup ("0010")); + umax = g_list_append (umax, g_strdup ("0030")); + umax = g_list_append (umax, g_strdup ("0050")); + umax = g_list_append (umax, g_strdup ("0060")); + umax = g_list_append (umax, g_strdup ("0070")); + umax = g_list_append (umax, g_strdup ("0130")); + umax = g_list_append (umax, g_strdup ("0160")); + umax = g_list_append (umax, g_strdup ("0230")); + g_hash_table_insert (scanners, + g_strdup("1606"), + umax); + + GList* docketport = NULL; + docketport = g_list_append (docketport, g_strdup ("4810")); + g_hash_table_insert (scanners, + g_strdup("1dcc"), + docketport); + + GList* dell = NULL; + dell = g_list_append (dell, g_strdup ("5105")); + dell = g_list_append (dell, g_strdup ("5124")); + dell = g_list_append (dell, g_strdup ("5250")); + g_hash_table_insert (scanners, + g_strdup("413c"), + dell); +} diff --git a/src/session-dbus.c b/src/session-dbus.c index fa9ea54..1cf73ac 100644 --- a/src/session-dbus.c +++ b/src/session-dbus.c @@ -5,6 +5,7 @@ Copyright 2010 Canonical Ltd. Authors: Ted Gould <ted@canonical.com> + Conor Curran <conor.curran@canonical.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published @@ -28,7 +29,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "session-dbus.h" #include "dbus-shared-names.h" -static GVariant * get_icon (SessionDbus * service); +static GVariant * get_users_real_name (SessionDbus * service); static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data); static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data); @@ -37,6 +38,7 @@ static void bus_method_call (GDBusConnection * connection, const gchar * sender, typedef struct _SessionDbusPrivate SessionDbusPrivate; struct _SessionDbusPrivate { gchar * name; + gboolean user_menu_is_visible; GDBusConnection * bus; GCancellable * bus_cancel; guint dbus_registration; @@ -98,10 +100,11 @@ session_dbus_init (SessionDbus *self) { SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(self); - priv->name = g_strdup(ICON_DEFAULT); + priv->name = NULL; priv->bus = NULL; priv->bus_cancel = NULL; priv->dbus_registration = 0; + priv->user_menu_is_visible = FALSE; priv->bus_cancel = g_cancellable_new(); g_bus_get(G_BUS_TYPE_SESSION, @@ -160,15 +163,20 @@ bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data) { - SessionDbus * service = SESSION_DBUS(user_data); + SessionDbus * service = SESSION_DBUS (user_data); + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE (service); + GVariant * retval = NULL; - if (g_strcmp0(method, "GetIcon") == 0) { - retval = get_icon(service); - } else { - g_warning("Calling method '%s' on the indicator service and it's unknown", method); + if (g_strcmp0(method, "GetUserRealName") == 0) { + retval = get_users_real_name (service); + } + else if (g_strcmp0 (method, "GetUserMenuVisibility") == 0){ + retval = g_variant_new ("(b)", priv->user_menu_is_visible); + } + else { + g_warning("Calling method '%s' on the indicator service and it's unknown", method); } - g_dbus_method_invocation_return_value(invocation, retval); return; } @@ -214,10 +222,10 @@ session_dbus_finalize (GObject *object) } static GVariant * -get_icon (SessionDbus * service) +get_users_real_name (SessionDbus * service) { SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(service); - return g_variant_new("(s)", priv->name); + return g_variant_new ("(s)", priv->name); } SessionDbus * @@ -229,29 +237,81 @@ session_dbus_new (void) void session_dbus_set_name (SessionDbus * session, const gchar * name) { +} + +void +session_dbus_set_users_real_name (SessionDbus * session, const gchar * name) +{ SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session); GError * error = NULL; if (priv->name != NULL) { g_free(priv->name); priv->name = NULL; } + priv->name = g_strdup(name); if (priv->bus != NULL) { g_dbus_connection_emit_signal (priv->bus, - NULL, - INDICATOR_SESSION_SERVICE_DBUS_OBJECT, - INDICATOR_SESSION_SERVICE_DBUS_IFACE, - "IconUpdated", - g_variant_new ("(s)", priv->name, NULL), - &error); + NULL, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + "UserRealNameUpdated", + g_variant_new ("(s)", priv->name, NULL), + &error); if (error != NULL) { - g_warning("Unable to send IconUpdated signal: %s", error->message); + g_warning("Unable to send UserRealNameUpdated signal: %s", error->message); g_error_free(error); return; } } - return; } + +void +session_dbus_set_user_menu_visibility (SessionDbus* session, + gboolean visible) +{ + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session); + GError * error = NULL; + + priv->user_menu_is_visible = visible; + + if (priv->bus != NULL) { + g_dbus_connection_emit_signal (priv->bus, + NULL, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + "UserMenuIsVisible", + g_variant_new ("(b)", priv->user_menu_is_visible), + &error); + + if (error != NULL) { + g_warning("Unable to send UserMenuIsVisible signal: %s", error->message); + g_error_free(error); + } + } +} + +void session_dbus_restart_required (SessionDbus* session) +{ + SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session); + GError * error = NULL; + + if (priv->bus != NULL) { + g_dbus_connection_emit_signal (priv->bus, + NULL, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + "RebootRequired", + NULL, + &error); + + if (error != NULL) { + g_warning("Unable to send reboot-required signal: %s", error->message); + g_error_free(error); + } + } + +} diff --git a/src/session-dbus.h b/src/session-dbus.h index 792917b..4dc340a 100644 --- a/src/session-dbus.h +++ b/src/session-dbus.h @@ -48,8 +48,10 @@ struct _SessionDbus { GType session_dbus_get_type (void); SessionDbus * session_dbus_new (void); -void session_dbus_set_name (SessionDbus * session, const gchar * name); - +void session_dbus_set_name (SessionDbus * session, const gchar * name); +void session_dbus_set_users_real_name (SessionDbus * session, const gchar * name); +void session_dbus_set_user_menu_visibility (SessionDbus* session, gboolean visible); +void session_dbus_restart_required (SessionDbus* session); G_END_DECLS #endif diff --git a/src/session-dbus.xml b/src/session-dbus.xml index ee724f5..fd1859f 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -2,14 +2,22 @@ <node name="/com/canonical/indicator/session/service"> <interface name="com.canonical.indicator.session.service"> - <!-- Icon --> - <method name="GetIcon"> + <method name="GetUserRealName"> <arg name="name" direction="out" type="s"/> </method> - - <signal name="IconUpdated"> + <method name="GetUserMenuVisibility"> + <arg name="update" direction="out" type="b"/> + </method> + <method name="IsUpdateNeeded"> + <arg name="update" direction="out" type="b"/> + </method> + <signal name="UserRealNameUpdated"> <arg name="name" type="s"/> </signal> - + <signal name="UserMenuIsVisible"> + <arg name="update" type="b"/> + </signal> + <signal name="RestartRequired"> + </signal> </interface> </node> diff --git a/src/session-service.c b/src/session-service.c index ddcb7cb..753e304 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -8,6 +8,7 @@ Authors: Ted Gould <ted@canonical.com> Christoph Korn <c_korn@gmx.de> Cody Russell <crussell@canonical.com> + Conor Curran <conor.curran@canonical.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published @@ -36,34 +37,22 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libdbusmenu-glib/server.h> #include <libdbusmenu-glib/menuitem.h> #include <libdbusmenu-glib/client.h> + +#include <gtk/gtk.h> +#if GTK_CHECK_VERSION(3, 0, 0) #include <libdbusmenu-gtk3/menuitem.h> +#else +#include <libdbusmenu-gtk/menuitem.h> +#endif #include <libindicator/indicator-service.h> #include "dbus-shared-names.h" #include "dbusmenu-shared.h" - -#include "gconf-helper.h" - -#include "session-dbus.h" #include "users-service-dbus.h" -#include "lock-helper.h" -#include "upower-client.h" - -#define UP_ADDRESS "org.freedesktop.UPower" -#define UP_OBJECT "/org/freedesktop/UPower" -#define UP_INTERFACE "org.freedesktop.UPower" - -#define EXTRA_LAUNCHER_DIR "/usr/share/indicators/session/applications" - -#define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" - -#define LOCKDOWN_DIR "/desktop/gnome/lockdown" -#define LOCKDOWN_KEY_USER LOCKDOWN_DIR "/disable_user_switching" -#define LOCKDOWN_KEY_SCREENSAVER LOCKDOWN_DIR "/disable_lock_screen" - -#define KEYBINDING_DIR "/apps/gnome_settings_daemon/keybindings" -#define KEY_LOCK_SCREEN KEYBINDING_DIR "/screensaver" +#include "user-menu-mgr.h" +#include "device-menu-mgr.h" +#include "session-dbus.h" typedef struct _ActivateData ActivateData; struct _ActivateData @@ -72,738 +61,10 @@ struct _ActivateData UserData *user; }; -static DBusGConnection *system_bus = NULL; -static DBusGProxy *gdm_proxy = NULL; -static UsersServiceDbus *dbus_interface = NULL; +//static UsersServiceDbus *dbus_interface = NULL; static SessionDbus *session_dbus = NULL; - -static DbusmenuMenuitem *lock_menuitem = NULL; -static DbusmenuMenuitem *switch_menuitem = NULL; - -static DbusmenuMenuitem * root_menuitem = NULL; static GMainLoop * mainloop = NULL; -static DBusGProxy * up_main_proxy = NULL; -static DBusGProxy * up_prop_proxy = NULL; - -static DBusGProxyCall * suspend_call = NULL; -static DBusGProxyCall * hibernate_call = NULL; - -static DbusmenuMenuitem * hibernate_mi = NULL; -static DbusmenuMenuitem * suspend_mi = NULL; -static DbusmenuMenuitem * logout_mi = NULL; -static DbusmenuMenuitem * restart_mi = NULL; -static DbusmenuMenuitem * shutdown_mi = NULL; - -static gboolean can_hibernate = TRUE; -static gboolean can_suspend = TRUE; -static gboolean allow_hibernate = TRUE; -static gboolean allow_suspend = TRUE; - -static GConfClient * gconf_client = NULL; - -static void rebuild_items (DbusmenuMenuitem *root, UsersServiceDbus *service); - -static void -lockdown_changed (GConfClient *client, - guint cnxd_id, - GConfEntry *entry, - gpointer user_data) -{ - GConfValue *value = gconf_entry_get_value (entry); - const gchar *key = gconf_entry_get_key (entry); - - if (value == NULL || key == NULL) { - return; - } - - if (g_strcmp0 (key, LOCKDOWN_KEY_USER) == 0 || g_strcmp0 (key, LOCKDOWN_KEY_SCREENSAVER) == 0) { - rebuild_items(root_menuitem, dbus_interface); - } - - return; -} - -static void -keybinding_changed (GConfClient *client, - guint cnxd_id, - GConfEntry *entry, - gpointer user_data) -{ - GConfValue *value = gconf_entry_get_value (entry); - const gchar *key = gconf_entry_get_key (entry); - - if (value == NULL || key == NULL) { - return; - } - - if (g_strcmp0 (key, KEY_LOCK_SCREEN) == 0) { - g_debug("Keybinding changed to: %s", gconf_value_get_string(value)); - if (lock_menuitem != NULL) { - dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, gconf_value_get_string(value)); - } - } - - return; -} - -/* Ensures that we have a GConf client and if we build one - set up the signal handler. */ -static void -ensure_gconf_client (void) -{ - if (!gconf_client) { - gconf_client = gconf_client_get_default (); - - gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_notify_add(gconf_client, LOCKDOWN_DIR, lockdown_changed, NULL, NULL, NULL); - - gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_notify_add(gconf_client, KEYBINDING_DIR, keybinding_changed, NULL, NULL, NULL); - } - return; -} - -/* Check to see if the lockdown key is protecting from - locking the screen. If not, lock it. */ -static void -lock_if_possible (void) { - ensure_gconf_client (); - - if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) { - lock_screen(NULL, 0, NULL); - } - - return; -} - -/* A return from the command to sleep the system. Make sure - that we unthrottle the screensaver. */ -static void -sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) -{ - screensaver_unthrottle(); - return; -} - -/* Let's put this machine to sleep, with some info on how - it should sleep. */ -static void -machine_sleep (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) -{ - gchar * type = (gchar *)userdata; - - if (up_main_proxy == NULL) { - g_warning("Can not %s as no upower proxy", type); - } - - screensaver_throttle(type); - lock_if_possible(); - - dbus_g_proxy_begin_call(up_main_proxy, - type, - sleep_response, - NULL, - NULL, - G_TYPE_INVALID); - - return; -} - -/* A response to getting the suspend property */ -static void -suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) -{ - suspend_call = NULL; - - GValue candoit = {0}; - GError * error = NULL; - dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); - if (error != NULL) { - g_warning("Unable to check suspend: %s", error->message); - g_error_free(error); - return; - } - g_debug("Got Suspend: %s", g_value_get_boolean(&candoit) ? "true" : "false"); - - gboolean local_can_suspend = g_value_get_boolean(&candoit); - if (local_can_suspend != can_suspend) { - can_suspend = local_can_suspend; - rebuild_items(root_menuitem, dbus_interface); - } - - return; -} - -/* Response to getting the hibernate property */ -static void -hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) -{ - hibernate_call = NULL; - - GValue candoit = {0}; - GError * error = NULL; - dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &candoit, G_TYPE_INVALID); - if (error != NULL) { - g_warning("Unable to check hibernate: %s", error->message); - g_error_free(error); - return; - } - g_debug("Got Hibernate: %s", g_value_get_boolean(&candoit) ? "true" : "false"); - - gboolean local_can_hibernate = g_value_get_boolean(&candoit); - if (local_can_hibernate != can_hibernate) { - can_hibernate = local_can_hibernate; - rebuild_items(root_menuitem, dbus_interface); - } - - return; -} - -/* A signal that we need to recheck to ensure we can still - hibernate and/or suspend */ -static void -up_changed_cb (DBusGProxy * proxy, gpointer user_data) -{ - /* Start Async call to see if we can hibernate */ - if (suspend_call == NULL) { - suspend_call = dbus_g_proxy_begin_call(up_prop_proxy, - "Get", - suspend_prop_cb, - NULL, - NULL, - G_TYPE_STRING, - UP_INTERFACE, - G_TYPE_STRING, - "CanSuspend", - G_TYPE_INVALID, - G_TYPE_VALUE, - G_TYPE_INVALID); - } - - /* Start Async call to see if we can suspend */ - if (hibernate_call == NULL) { - hibernate_call = dbus_g_proxy_begin_call(up_prop_proxy, - "Get", - hibernate_prop_cb, - NULL, - NULL, - G_TYPE_STRING, - UP_INTERFACE, - G_TYPE_STRING, - "CanHibernate", - G_TYPE_INVALID, - G_TYPE_VALUE, - G_TYPE_INVALID); - } - - return; -} - -/* Handle the callback from the allow functions to check and - see if we're changing the value, and if so, rebuilding the - menus based on that info. */ -static void -allowed_cb (DBusGProxy *proxy, gboolean OUT_allowed, GError *error, gpointer userdata) -{ - if (error != NULL) { - g_warning("Unable to get information on what is allowed from UPower: %s", error->message); - return; - } - - gboolean * can_do = (gboolean *)userdata; - - if (OUT_allowed != *can_do) { - *can_do = OUT_allowed; - rebuild_items (root_menuitem, dbus_interface); - } -} - -/* This function goes through and sets up what we need for - DKp checking. We're even setting up the calls for the props - we need */ -static void -setup_up (void) { - DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - g_return_if_fail(bus != NULL); - - if (up_main_proxy == NULL) { - up_main_proxy = dbus_g_proxy_new_for_name(bus, - UP_ADDRESS, - UP_OBJECT, - UP_INTERFACE); - } - g_return_if_fail(up_main_proxy != NULL); - - if (up_prop_proxy == NULL) { - up_prop_proxy = dbus_g_proxy_new_for_name(bus, - UP_ADDRESS, - UP_OBJECT, - DBUS_INTERFACE_PROPERTIES); - /* Connect to changed signal */ - dbus_g_proxy_add_signal(up_main_proxy, - "Changed", - G_TYPE_INVALID); - - dbus_g_proxy_connect_signal(up_main_proxy, - "Changed", - G_CALLBACK(up_changed_cb), - NULL, - NULL); - } - g_return_if_fail(up_prop_proxy != NULL); - - - /* Force an original "changed" event */ - up_changed_cb(up_main_proxy, NULL); - - /* Check to see if these are getting blocked by PolicyKit */ - org_freedesktop_UPower_suspend_allowed_async(up_main_proxy, - allowed_cb, - &allow_suspend); - org_freedesktop_UPower_hibernate_allowed_async(up_main_proxy, - allowed_cb, - &allow_hibernate); - - return; -} - -/* This is the function to show a dialog on actions that - can destroy data. Currently it just calls the GTK version - but it seems that in the future it should figure out - what's going on and something better. */ -static void -show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) -{ - gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); - gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); - g_free(helper); - - g_debug("Showing dialog '%s'", dialog_line); - - GError * error = NULL; - if (!g_spawn_command_line_async(dialog_line, &error)) { - g_warning("Unable to show dialog: %s", error->message); - g_error_free(error); - } - - g_free(dialog_line); - - return; -} - -/* Checks to see if we should show the guest suession item */ -static gboolean -check_guest_session (void) -{ - if (geteuid() < 500) { - /* System users shouldn't have guest account shown. Mosly - this would be the case of the guest user itself. */ - return FALSE; - } - if (!g_file_test(GUEST_SESSION_LAUNCHER, G_FILE_TEST_IS_EXECUTABLE)) { - /* It doesn't appear that the Guest session stuff is - installed. So let's not use it then! */ - return FALSE; - } - - return TRUE; -} - -/* Called when someone clicks on the guest session item. */ -static void -activate_guest_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) -{ - GError * error = NULL; - - lock_if_possible(); - - if (dbusmenu_menuitem_property_get_bool(mi, USER_ITEM_PROP_LOGGED_IN)) { - if (users_service_dbus_activate_guest_session(USERS_SERVICE_DBUS(user_data))) { - return; - } - g_warning("Unable to activate guest session, falling back to command line activation."); - } - if (!g_spawn_command_line_async(GUEST_SESSION_LAUNCHER " --no-lock", &error)) { - g_warning("Unable to start guest session: %s", error->message); - g_error_free(error); - } - - return; -} - -/* Checks to see if we can create sessions and get a proxy - to the display manager (GDM) */ -static gboolean -check_new_session (void) -{ - if (system_bus == NULL) { - system_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - } - - if (system_bus == NULL) { - return FALSE; - } - - if (gdm_proxy == NULL) { - gdm_proxy = dbus_g_proxy_new_for_name(system_bus, - "org.gnome.DisplayManager", - "/org/gnome/DisplayManager/LocalDisplayFactory", - "org.gnome.DisplayManager.LocalDisplayFactory"); - } - - if (gdm_proxy == NULL) { - return FALSE; - } - - return TRUE; -} - -/* Starts a new generic session */ -static void -activate_new_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) -{ - GError * error = NULL; - - lock_if_possible(); - - if (!g_spawn_command_line_async("gdmflexiserver --startnew", &error)) { - g_warning("Unable to start new session: %s", error->message); - g_error_free(error); - } - - return; -} - -/* Activates a session for a particular user. */ -static void -activate_user_session (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data) -{ - UserData *user = (UserData *)user_data; - UsersServiceDbus *service = user->service; - - lock_if_possible(); - - users_service_dbus_activate_user_session (service, user); -} - -/* Comparison function to look into the UserData struct - to compare by using the username value */ -static gint -compare_users_by_username (const gchar *a, - const gchar *b) -{ - UserData *user1 = (UserData *)a; - UserData *user2 = (UserData *)b; - - gint retval = g_strcmp0 (user1->real_name, user2->real_name); - - /* If they're the same, they're both in conflict. */ - if (retval == 0) { - user1->real_name_conflict = TRUE; - user2->real_name_conflict = TRUE; - } - - return retval; -} - -/* Take a desktop file and execute it */ -static void -desktop_activate_cb (DbusmenuMenuitem * mi, guint timestamp, gpointer data) -{ - GAppInfo * appinfo = G_APP_INFO(data); - g_return_if_fail(appinfo != NULL); - g_app_info_launch(appinfo, NULL, NULL, NULL); - return; -} - -/* Look at the GAppInfo structures and sort based on - the application names */ -static gint -sort_app_infos (gconstpointer a, gconstpointer b) -{ - GAppInfo * appa = G_APP_INFO(a); - GAppInfo * appb = G_APP_INFO(b); - - const gchar * namea = NULL; - const gchar * nameb = NULL; - - if (appa != NULL) { - namea = g_app_info_get_name(appa); - } - - if (appb != NULL) { - nameb = g_app_info_get_name(appb); - } - - return g_strcmp0(namea, nameb); -} - -/* Builds up the menu for us */ -static void -rebuild_items (DbusmenuMenuitem *root, - UsersServiceDbus *service) -{ - DbusmenuMenuitem *mi = NULL; - DbusmenuMenuitem * guest_mi = NULL; - GList *u; - UserData *user; - gboolean can_activate; - gboolean can_lockscreen; - GList *children; - - /* Make sure we have a valid GConf client, and build one - if needed */ - ensure_gconf_client (); - - /* Check to see which menu items we're allowed to have */ - can_activate = users_service_dbus_can_activate_session (service) && - !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); - can_lockscreen = !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL); - - /* Remove the old menu items if that makes sense */ - children = dbusmenu_menuitem_take_children (root); - g_list_foreach (children, (GFunc)g_object_unref, NULL); - g_list_free (children); - - /* Lock screen item */ - if (can_lockscreen) { - lock_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); - - gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); - if (shortcut != NULL) { - g_debug("Lock screen shortcut: %s", shortcut); - dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); - g_free(shortcut); - } else { - g_debug("Unable to get lock screen shortcut."); - } - - g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); - dbusmenu_menuitem_child_append(root, lock_menuitem); - } - - /* Set to NULL just incase we don't end up building one */ - users_service_dbus_set_guest_item(service, NULL); - - /* Build all of the user switching items */ - if (can_activate == TRUE) - { - if (can_lockscreen) { - DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator1, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator1); - } - - if (check_guest_session ()) - { - guest_mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (guest_mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); - dbusmenu_menuitem_property_set (guest_mi, USER_ITEM_PROP_NAME, _("Guest Session")); - dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, FALSE); - dbusmenu_menuitem_child_append (root, guest_mi); - g_signal_connect (G_OBJECT (guest_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_guest_session), service); - users_service_dbus_set_guest_item(service, guest_mi); - } - - if (check_new_session ()) - { - - switch_menuitem = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_TYPE, MENU_SWITCH_TYPE); - dbusmenu_menuitem_property_set (switch_menuitem, MENU_SWITCH_USER, g_get_user_name()); - dbusmenu_menuitem_child_append (root, switch_menuitem); - g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); - } - - GList * users = NULL; - users = users_service_dbus_get_user_list (service); - guint user_count = g_list_length(users); - - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - users = g_list_sort (users, (GCompareFunc)compare_users_by_username); - } - - for (u = users; u != NULL; u = g_list_next (u)) { - user = u->data; - user->service = service; - - if (user->uid == getuid()) { - /* Hide me from the list */ - continue; - } - - if (g_strcmp0(user->user_name, "guest") == 0) { - /* Check to see if the guest has sessions and so therefore should - get a check mark. */ - if (user->sessions != NULL) { - dbusmenu_menuitem_property_set_bool (guest_mi, USER_ITEM_PROP_LOGGED_IN, TRUE); - } - /* If we're showing user accounts, keep going through the list */ - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - continue; - } - /* If not, we can stop here */ - break; - } - - if (user_count > MINIMUM_USERS && user_count < MAXIMUM_USERS) { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, USER_ITEM_TYPE); - if (user->real_name_conflict) { - gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); - g_free(conflictedname); - } else { - dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, user->real_name); - } - dbusmenu_menuitem_property_set_bool (mi, USER_ITEM_PROP_LOGGED_IN, user->sessions != NULL); - if (user->icon_url != NULL && user->icon_url[0] != '\0' && g_str_has_prefix(user->icon_url, "file://")) { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_url + strlen("file://")); - } else { - dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); - } - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_user_session), user); - user->menuitem = mi; - } - } - - g_list_free(users); - } - - /* If there were a bunch of items before us, we need a - separator. */ - if (can_lockscreen || can_activate) { - DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator); - } - - /* Start going through the session based items. */ - - logout_mi = dbusmenu_menuitem_new(); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out")); - } else { - dbusmenu_menuitem_property_set(logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out\342\200\246")); - } - dbusmenu_menuitem_property_set_bool(logout_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_logout()); - dbusmenu_menuitem_child_append(root, logout_mi); - g_signal_connect(G_OBJECT(logout_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "logout"); - - if (can_suspend && allow_suspend) { - suspend_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(suspend_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Suspend")); - dbusmenu_menuitem_child_append(root, suspend_mi); - g_signal_connect(G_OBJECT(suspend_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Suspend"); - } - - if (can_hibernate && allow_hibernate) { - hibernate_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(hibernate_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Hibernate")); - dbusmenu_menuitem_child_append(root, hibernate_mi); - g_signal_connect(G_OBJECT(hibernate_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Hibernate"); - } - - restart_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_TYPE, RESTART_ITEM_TYPE); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); - } else { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart\342\200\246")); - } - dbusmenu_menuitem_property_set_bool(restart_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_restart()); - dbusmenu_menuitem_child_append(root, restart_mi); - g_signal_connect(G_OBJECT(restart_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "restart"); - - shutdown_mi = dbusmenu_menuitem_new(); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down")); - } else { - dbusmenu_menuitem_property_set(shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down\342\200\246")); - } - dbusmenu_menuitem_property_set_bool(shutdown_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_shutdown()); - dbusmenu_menuitem_child_append(root, shutdown_mi); - g_signal_connect(G_OBJECT(shutdown_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "shutdown"); - - RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); - restart_shutdown_logout_mi->logout_mi = logout_mi; - restart_shutdown_logout_mi->restart_mi = restart_mi; - restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; - - update_menu_entries(restart_shutdown_logout_mi); - - /* now add extra launchers */ - GDir *extra_launchers_dir; - extra_launchers_dir = g_dir_open (EXTRA_LAUNCHER_DIR, 0, NULL); - if (extra_launchers_dir != NULL) { - GList * launchers = NULL; - - /* Find all the desktop files we want to use */ - for (;;) { - const gchar *extra_launcher_file; - - extra_launcher_file = g_dir_read_name (extra_launchers_dir); - if (extra_launcher_file == NULL) - break; - if (!g_str_has_suffix (extra_launcher_file, ".desktop")) - continue; - - gchar *full_path = g_build_filename (EXTRA_LAUNCHER_DIR, extra_launcher_file, NULL); - GAppInfo * appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename (full_path)); - g_free (full_path); - - launchers = g_list_prepend(launchers, appinfo); - } - g_dir_close(extra_launchers_dir); - - /* Sort the desktop files based on their names */ - launchers = g_list_sort(launchers, sort_app_infos); - - /* Turn each one into a separate menu item */ - GList * launcher = NULL; - gboolean sepadded = FALSE; - for (launcher = launchers; launcher != NULL; launcher = g_list_next(launcher)) { - GAppInfo * appinfo = G_APP_INFO(launcher->data); - - /* Make sure we have a separator */ - if (!sepadded) { - DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator); - g_object_unref(separator); - sepadded = TRUE; - } - - /* Build the item */ - DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(desktop_mi, DBUSMENU_MENUITEM_PROP_LABEL, g_app_info_get_name(appinfo)); - g_signal_connect(G_OBJECT(desktop_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(desktop_activate_cb), appinfo); - g_object_weak_ref(G_OBJECT(desktop_mi), (GWeakNotify)g_object_unref, appinfo); - - /* Put into the menu */ - dbusmenu_menuitem_child_append(root, desktop_mi); - } - - g_list_free(launchers); - } - - return; -} - -/* Signal called when a user is added. It updates the count and - rebuilds the menu */ -static void -user_change (UsersServiceDbus *service, - gint64 user, - gpointer user_data) -{ - DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; - rebuild_items (root, service); - return; -} /* When the service interface starts to shutdown, we should follow it. */ @@ -817,51 +78,12 @@ service_shutdown (IndicatorService * service, gpointer user_data) return; } -/* When the directory changes we need to figure out how our menu - item should look. */ -static void -restart_dir_changed (void) -{ - gboolean restart_required = g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS); - - if (restart_required) { - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart to Complete Update")); - } else { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart to Complete Update\342\200\246")); - } - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_ICON, "system-restart-panel"); - if (session_dbus != NULL) { - session_dbus_set_name(session_dbus, ICON_RESTART); - } - } else { - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); - } else { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart\342\200\246")); - } - dbusmenu_menuitem_property_remove(restart_mi, RESTART_ITEM_ICON); - if (session_dbus != NULL) { - session_dbus_set_name(session_dbus, ICON_DEFAULT); - } - } - - return; -} - -/* Buids a file watcher for the directory so that when it - changes we can check to see if our reboot-required is - there. */ -static void -setup_restart_watch (void) +static gboolean +get_greeter_mode (void) { - GFile * filedir = g_file_new_for_path("/var/run"); - GFileMonitor * filemon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL); - if (filemon != NULL) { - g_signal_connect(G_OBJECT(filemon), "changed", G_CALLBACK(restart_dir_changed), NULL); - } - restart_dir_changed(); - return; + const gchar *var; + var = g_getenv("INDICATOR_GREETER_MODE"); + return (g_strcmp0(var, "1") == 0); } /* Main, is well, main. It brings everything up and throws @@ -869,7 +91,9 @@ setup_restart_watch (void) int main (int argc, char ** argv) { - g_type_init(); + gboolean greeter_mode; + + g_type_init(); /* Setting up i18n and gettext. Apparently, we need all of these. */ @@ -877,42 +101,31 @@ main (int argc, char ** argv) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); - IndicatorService * service = indicator_service_new_version(INDICATOR_SESSION_DBUS_NAME, - INDICATOR_SESSION_DBUS_VERSION); - g_signal_connect(G_OBJECT(service), - INDICATOR_SERVICE_SIGNAL_SHUTDOWN, - G_CALLBACK(service_shutdown), NULL); + IndicatorService * service = indicator_service_new_version (INDICATOR_SESSION_DBUS_NAME, + INDICATOR_SESSION_DBUS_VERSION); + g_signal_connect (G_OBJECT(service), + INDICATOR_SERVICE_SIGNAL_SHUTDOWN, + G_CALLBACK(service_shutdown), NULL); session_dbus = session_dbus_new(); - g_idle_add(lock_screen_setup, NULL); - - root_menuitem = dbusmenu_menuitem_new(); - g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem)); - - dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); - - rebuild_items (root_menuitem, dbus_interface); - - g_signal_connect (G_OBJECT (dbus_interface), - "user-added", - G_CALLBACK (user_change), - root_menuitem); - g_signal_connect (G_OBJECT (dbus_interface), - "user-removed", - G_CALLBACK (user_change), - root_menuitem); - - setup_restart_watch(); - - setup_up(); - - DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT); - dbusmenu_server_set_root(server, root_menuitem); - - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); + greeter_mode = get_greeter_mode(); + + // Devices + DeviceMenuMgr* device_mgr = device_menu_mgr_new (session_dbus, greeter_mode); + DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT); + dbusmenu_server_set_root(server, device_mgr_get_root_item (device_mgr)); + + if (!greeter_mode) { + // Users + UserMenuMgr* user_mgr = user_menu_mgr_new (session_dbus, greeter_mode); + DbusmenuServer* users_server = dbusmenu_server_new (INDICATOR_USERS_DBUS_OBJECT); + dbusmenu_server_set_root (users_server, user_mgr_get_root_item (user_mgr)); + } - return 0; + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return 0; } diff --git a/src/udev-mgr.c b/src/udev-mgr.c new file mode 100644 index 0000000..f66d862 --- /dev/null +++ b/src/udev-mgr.c @@ -0,0 +1,456 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#include <gudev/gudev.h> + +// TEMP +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdarg.h> + +#include "udev-mgr.h" +#include "sane-rules.h" + +static void udevice_mgr_device_list_iterator (gpointer data, + gpointer userdata); +static void udev_mgr_uevent_cb (GUdevClient *client, + gchar *action, + GUdevDevice *device, + gpointer user_data); +static void udev_mgr_update_menuitems (UdevMgr* self); +static void udev_mgr_check_if_usb_device_is_supported (UdevMgr* self, + GUdevDevice *device, + UdevMgrDeviceAction action); +static void udev_mgr_handle_webcam (UdevMgr* self, + GUdevDevice* device, + UdevMgrDeviceAction action); +static void udev_mgr_handle_scsi_device (UdevMgr* self, + GUdevDevice* device, + UdevMgrDeviceAction action); + +static void udev_mgr_cleanup_lists(gpointer data, gpointer self); +static void udev_mgr_cleanup_entries(gpointer data, gpointer self); + + +static void debug_device (UdevMgr* self, + GUdevDevice* device, + UdevMgrDeviceAction action); + + +struct _UdevMgr +{ + GObject parent_instance; + DbusmenuMenuitem* scanner_item; + DbusmenuMenuitem* webcam_item; + GUdevClient* client; + GHashTable* supported_usb_scanners; + GHashTable* supported_scsi_scanners; + GHashTable* scanners_present; + GHashTable* webcams_present; +}; + +const char *subsystems[3] = {"usb", "scsi", "video4linux"}; +const gchar* usb_subsystem = "usb"; +const gchar* scsi_subsystem = "scsi"; +const gchar* video4linux_subsystem = "video4linux"; + + +G_DEFINE_TYPE (UdevMgr, udev_mgr, G_TYPE_OBJECT); + +static void +udev_mgr_init (UdevMgr* self) +{ + self->client = NULL; + self->supported_usb_scanners = NULL; + self->scanners_present = NULL; + self->webcams_present = NULL; + self->client = g_udev_client_new (subsystems); + self->supported_usb_scanners = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + (GDestroyNotify)udev_mgr_cleanup_lists); + self->supported_scsi_scanners = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + (GDestroyNotify)udev_mgr_cleanup_lists); + self->scanners_present = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); + self->webcams_present = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); + + // load into memory all supported scanners ... + populate_usb_scanners (self->supported_usb_scanners); + populate_scsi_scanners (self->supported_scsi_scanners); + g_signal_connect (G_OBJECT (self->client), + "uevent", + G_CALLBACK (udev_mgr_uevent_cb), + self); +} + +static void +udev_mgr_cleanup_lists(gpointer data, gpointer self) +{ + GList* scanners = (GList*)data; + g_list_foreach (scanners, udev_mgr_cleanup_entries, NULL); + g_list_free(scanners); +} + +static void +udev_mgr_cleanup_entries(gpointer data, gpointer self) +{ + gchar* entry = (gchar*)data; + g_free(entry); +} + +static void +udev_mgr_finalize (GObject *object) +{ + UdevMgr* self = UDEV_MGR (object); + g_hash_table_destroy (self->supported_scsi_scanners); + g_hash_table_destroy (self->supported_usb_scanners); + g_hash_table_destroy (self->scanners_present); + g_hash_table_destroy (self->webcams_present); + G_OBJECT_CLASS (udev_mgr_parent_class)->finalize (object); +} + +static void +udev_mgr_class_init (UdevMgrClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + object_class->finalize = udev_mgr_finalize; +} + +static void +udevice_mgr_device_list_iterator (gpointer data, gpointer userdata) +{ + g_return_if_fail (G_UDEV_IS_DEVICE (data)); + g_return_if_fail (UDEV_IS_MGR (userdata)); + + UdevMgr* self = UDEV_MGR (userdata); + + GUdevDevice* device = G_UDEV_DEVICE (data); + + const gchar* subsystem = NULL; + subsystem = g_udev_device_get_subsystem (device); + + if (g_strcmp0 (subsystem, "usb") == 0){ + udev_mgr_check_if_usb_device_is_supported (self, device, ADD); + } + else if (g_strcmp0 (subsystem, "video4linux") == 0){ + udev_mgr_handle_webcam (self, device, ADD); + } + else if (g_strcmp0 (subsystem, "scsi") == 0){ + udev_mgr_handle_scsi_device (self, device, ADD); + } + + g_object_unref (device); +} + + +static void udev_mgr_update_menuitems (UdevMgr* self) +{ + dbusmenu_menuitem_property_set_bool (self->scanner_item, + DBUSMENU_MENUITEM_PROP_VISIBLE, + g_hash_table_size (self->scanners_present) > 0); + + dbusmenu_menuitem_property_set_bool (self->webcam_item, + DBUSMENU_MENUITEM_PROP_VISIBLE, + g_hash_table_size (self->webcams_present) > 0); + +} + +static void udev_mgr_uevent_cb (GUdevClient *client, + gchar *action, + GUdevDevice *device, + gpointer user_data) +{ + g_return_if_fail (UDEV_IS_MGR (user_data)); + UdevMgr* self = UDEV_MGR (user_data); + g_return_if_fail (device != NULL); + + g_debug ("just received a UEVENT with an action : %s", action); + + UdevMgrDeviceAction udev_mgr_action = ADD; + + if (g_strcmp0 (action, "remove") == 0){ + udev_mgr_action = REMOVE; + } + + const gchar* subsystem = NULL; + subsystem = g_udev_device_get_subsystem (device); + + if (g_strcmp0 (subsystem, "usb") == 0){ + udev_mgr_check_if_usb_device_is_supported (self, + device, + udev_mgr_action); + } + else if (g_strcmp0 (subsystem, "video4linux") == 0){ + udev_mgr_handle_webcam (self, device, udev_mgr_action); + } + else if (g_strcmp0 (subsystem, "scsi") == 0){ + udev_mgr_handle_scsi_device (self, device, udev_mgr_action); + } +} + + +static void +udev_mgr_handle_webcam (UdevMgr* self, + GUdevDevice* device, + UdevMgrDeviceAction action) +{ + if (FALSE) + debug_device (self, device, action); + + const gchar* vendor; + const gchar* product; + + vendor = g_udev_device_get_property (device, "ID_VENDOR_ID"); + product = g_udev_device_get_property (device, "ID_MODEL_ID"); + + if (action == REMOVE){ + if (g_hash_table_lookup (self->webcams_present, product) == NULL){ + g_warning ("Got a remove event on a webcam device but we don't have that device in our webcam cache"); + return; + } + g_hash_table_remove (self->webcams_present, + product); + + } + else { + if (g_hash_table_lookup (self->webcams_present, product) != NULL){ + g_warning ("Got an ADD event on a webcam device but we already have that device in our webcam cache"); + return; + } + g_hash_table_insert (self->webcams_present, + g_strdup (product), + g_strdup (vendor)); + } + udev_mgr_update_menuitems (self); +} + +static void +debug_device (UdevMgr* self, + GUdevDevice* device, + UdevMgrDeviceAction action) +{ + /*const gchar* vendor; + const gchar* product; + const gchar* number; + const gchar* name; + + vendor = g_udev_device_get_property (device, "ID_VENDOR_ID"); + product = g_udev_device_get_property (device, "ID_MODEL_ID"); + number = g_udev_device_get_number (device); + name = g_udev_device_get_name (device); + + g_debug ("device vendor id %s , product id of %s , number of %s and name of %s", + g_strdup(vendor), + g_strdup(product), + g_strdup(number), + g_strdup(name)); + + const gchar *const *list; + const gchar *const *iter; + char propstr[500]; + guint32 namelen = 0, i; + + list = g_udev_device_get_property_keys(device); + + for (iter = list; iter && *iter; iter++) { + if (strlen(*iter) > namelen) + namelen = strlen(*iter); + } + namelen++; + + for (iter = list; iter && *iter; iter++) { + strcpy(propstr, *iter); + strcat(propstr, ":"); + for (i = 0; i < namelen - strlen(*iter); i++) + strcat(propstr, " "); + strcat(propstr, g_udev_device_get_property(device, *iter)); + g_debug("%s", propstr); + }*/ +} + +static void udev_mgr_handle_scsi_device (UdevMgr* self, + GUdevDevice* device, + UdevMgrDeviceAction action) +{ + const gchar* type = NULL; + type = g_udev_device_get_property (device, "TYPE"); + // apparently anything thats type 3 and SCSI is a Scanner + if (g_strcmp0 (type, "6") == 0){ + gchar* random_scanner_name = g_strdup_printf("%p--scanner", self); + g_hash_table_insert (self->scanners_present, + random_scanner_name, + g_strdup("Scanner")); + udev_mgr_update_menuitems (self); + return; + } + + // We only care about type 3 for the special cases below + if (g_strcmp0 (type, "3") != 0){ + return; + } + + const gchar* vendor = NULL; + vendor = g_udev_device_get_property (device, "VENDOR"); + + if (vendor == NULL) + return; + + GList* vendor_list = NULL; + vendor_list = g_hash_table_lookup (self->supported_scsi_scanners, + (gpointer)vendor); + if (vendor_list == NULL) + return; + + const gchar* model_id = NULL; + model_id = g_udev_device_get_property (device, "MODEL"); + + if (model_id == NULL) + return; + + GList* model_entry = NULL; + model_entry = g_list_find_custom (vendor_list, + model_id, + (GCompareFunc)g_strcmp0); + + if (model_entry != NULL){ + if (action == REMOVE){ + if (g_hash_table_lookup (self->scanners_present, g_strdup(vendor)) == NULL){ + g_warning ("Got an REMOVE event on a scanner device but we dont have that device in our scanners cache"); + } + else{ + g_hash_table_remove (self->scanners_present, vendor); + } + } + else{ + if (g_hash_table_lookup (self->scanners_present, g_strdup(vendor)) != NULL){ + g_warning ("Got an ADD event on a scanner device but we already have that device in our scanners cache"); + } + else{ + g_hash_table_insert (self->scanners_present, + g_strdup(vendor), + g_strdup(model_id)); + } + } + udev_mgr_update_menuitems (self); + } +} + +static void +udev_mgr_check_if_usb_device_is_supported (UdevMgr* self, + GUdevDevice *device, + UdevMgrDeviceAction action) +{ + const gchar* vendor = NULL; + debug_device (self, device, action); + + vendor = g_udev_device_get_property (device, "ID_VENDOR_ID"); + + if (vendor == NULL) + return; + + //g_debug ("vendor = %s", vendor); + + GList* vendor_list = NULL; + vendor_list = g_hash_table_lookup (self->supported_usb_scanners, + (gpointer)vendor); + if (vendor_list == NULL) + return; + + const gchar* model_id = NULL; + model_id = g_udev_device_get_property (device, "ID_MODEL_ID"); + + if (model_id == NULL) + return; + + GList* model_entry = NULL; + model_entry = g_list_find_custom(vendor_list, model_id, (GCompareFunc)g_strcmp0); + + if (model_entry != NULL){ + if (action == REMOVE){ + if (g_hash_table_lookup (self->scanners_present, g_strdup(vendor)) == NULL){ + g_warning ("Got an REMOVE event on a scanner device but we dont have that device in our scanners cache"); + } + else{ + g_hash_table_remove (self->scanners_present, vendor); + } + } + else{ + if (g_hash_table_lookup (self->scanners_present, g_strdup(vendor)) != NULL){ + g_warning ("Got an ADD event on a scanner device but we already have that device in our scanners cache"); + } + else{ + g_hash_table_insert (self->scanners_present, + g_strdup(vendor), + g_strdup(model_id)); + } + } + udev_mgr_update_menuitems (self); + } +} + +UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner, + DbusmenuMenuitem* webcam) +{ + UdevMgr* mgr = g_object_new (UDEV_TYPE_MGR, NULL); + mgr->scanner_item = scanner; + mgr->webcam_item = webcam; + + // Check for USB devices + GList* usb_devices_available = NULL; + usb_devices_available = g_udev_client_query_by_subsystem (mgr->client, + usb_subsystem); + if (usb_devices_available != NULL){ + g_list_foreach (usb_devices_available, + udevice_mgr_device_list_iterator, + mgr); + + g_list_free (usb_devices_available); + } + // Check for webcams + GList* video_devices_available = NULL; + video_devices_available = g_udev_client_query_by_subsystem (mgr->client, + video4linux_subsystem); + if (video_devices_available != NULL){ + g_list_foreach (video_devices_available, + udevice_mgr_device_list_iterator, + mgr); + + g_list_free (video_devices_available); + } + // Check for SCSI devices + GList* scsi_devices_available = NULL; + scsi_devices_available = g_udev_client_query_by_subsystem (mgr->client, + scsi_subsystem); + if (scsi_devices_available != NULL){ + g_list_foreach (scsi_devices_available, + udevice_mgr_device_list_iterator, + mgr); + g_list_free (scsi_devices_available); + } + return mgr; +} diff --git a/src/udev-mgr.h b/src/udev-mgr.h new file mode 100644 index 0000000..5119803 --- /dev/null +++ b/src/udev-mgr.h @@ -0,0 +1,62 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _UDEV_MGR_H_ +#define _UDEV_MGR_H_ + +#include <glib-object.h> +#include <libdbusmenu-glib/client.h> + +#include <gtk/gtk.h> +#if GTK_CHECK_VERSION(3, 0, 0) +#include <libdbusmenu-gtk3/menuitem.h> +#else +#include <libdbusmenu-gtk/menuitem.h> +#endif + +G_BEGIN_DECLS + +#define UDEV_TYPE_MGR (udev_mgr_get_type ()) +#define UDEV_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UDEV_TYPE_MGR, UdevMgr)) +#define UDEV_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UDEV_TYPE_MGR, UdevMgrClass)) +#define UDEV_IS_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UDEV_TYPE_MGR)) +#define UDEV_IS_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UDEV_TYPE_MGR)) +#define UDEV_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UDEV_TYPE_MGR, UdevMgrClass)) + +typedef struct _UdevMgrClass UdevMgrClass; +typedef struct _UdevMgr UdevMgr; + +struct _UdevMgrClass +{ + GObjectClass parent_class; +}; + + +GType udev_mgr_get_type (void) G_GNUC_CONST; +UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner_item, + DbusmenuMenuitem* webcam_item); + +typedef enum { + ADD, + REMOVE +}UdevMgrDeviceAction; + +G_END_DECLS + +#endif /* _UDEV_MGR_H_ */ diff --git a/src/user-menu-mgr.c b/src/user-menu-mgr.c new file mode 100644 index 0000000..44c1960 --- /dev/null +++ b/src/user-menu-mgr.c @@ -0,0 +1,431 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#include <libdbusmenu-glib/client.h> + +#include "user-menu-mgr.h" +#include "gconf-helper.h" +#include "dbus-shared-names.h" +#include "dbusmenu-shared.h" +#include "lock-helper.h" +#include "users-service-dbus.h" + +static GConfClient * gconf_client = NULL; +static DbusmenuMenuitem *switch_menuitem = NULL; + +struct _UserMenuMgr +{ + GObject parent_instance; + UsersServiceDbus* users_dbus_interface; + DbusmenuMenuitem* root_item; + gint user_count; + SessionDbus* session_dbus_interface; +}; + +static void activate_new_session (DbusmenuMenuitem * mi, + guint timestamp, + gpointer user_data); +static void activate_user_session (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data); +static gint compare_users_by_username (const gchar *a, + const gchar *b); +static void activate_online_accounts (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data); +static void user_menu_mgr_rebuild_items (UserMenuMgr *self, + gboolean greeter_mode); +static gboolean check_new_session (); +static void user_change (UsersServiceDbus *service, + const gchar *user_id, + gpointer user_data); + +static void ensure_gconf_client (); +static gboolean check_guest_session (void); +static void activate_guest_session (DbusmenuMenuitem * mi, + guint timestamp, + gpointer user_data); + + +G_DEFINE_TYPE (UserMenuMgr, user_menu_mgr, G_TYPE_OBJECT); + + +static void +user_menu_mgr_init (UserMenuMgr *self) +{ + self->users_dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); + self->root_item = dbusmenu_menuitem_new (); + g_signal_connect (G_OBJECT (self->users_dbus_interface), + "user-added", + G_CALLBACK (user_change), + self); + g_signal_connect (G_OBJECT (self->users_dbus_interface), + "user-removed", + G_CALLBACK (user_change), + self); +} + +static void +user_menu_mgr_finalize (GObject *object) +{ + /* TODO: Add deinitalization code here */ + G_OBJECT_CLASS (user_menu_mgr_parent_class)->finalize (object); +} + +static void +user_menu_mgr_class_init (UserMenuMgrClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + //GObjectClass* parent_class = G_OBJECT_CLASS (klass); + + object_class->finalize = user_menu_mgr_finalize; +} + +/* Builds up the menu for us */ +static void +user_menu_mgr_rebuild_items (UserMenuMgr *self, gboolean greeter_mode) +{ + DbusmenuMenuitem *mi = NULL; + DbusmenuMenuitem *guest_mi = NULL; + GList *u; + UserData *user; + gboolean can_activate; + GList *children; + + /* Make sure we have a valid GConf client, and build one + if needed */ + ensure_gconf_client (); + + /* Check to see which menu items we're allowed to have */ + can_activate = users_service_dbus_can_activate_session (self->users_dbus_interface) && + !gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_USER, NULL); + + /* Remove the old menu items if that makes sense */ + children = dbusmenu_menuitem_take_children (self->root_item); + g_list_foreach (children, (GFunc)g_object_unref, NULL); + g_list_free (children); + + /* Set to NULL just incase we don't end up building one */ + users_service_dbus_set_guest_item(self->users_dbus_interface, NULL); + + /* Build all of the user switching items */ + if (can_activate == TRUE) + { + + if (check_new_session ()){ + switch_menuitem = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (switch_menuitem, + DBUSMENU_MENUITEM_PROP_TYPE, + MENU_SWITCH_TYPE); + dbusmenu_menuitem_property_set (switch_menuitem, + MENU_SWITCH_USER, + g_get_user_name()); + dbusmenu_menuitem_child_append (self->root_item, switch_menuitem); + g_signal_connect (G_OBJECT (switch_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_new_session), + self->users_dbus_interface); + } + + if (check_guest_session ()) + { + guest_mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (guest_mi, + DBUSMENU_MENUITEM_PROP_TYPE, + USER_ITEM_TYPE); + dbusmenu_menuitem_property_set (guest_mi, + USER_ITEM_PROP_NAME, + _("Guest Session")); + dbusmenu_menuitem_property_set_bool (guest_mi, + USER_ITEM_PROP_LOGGED_IN, + FALSE); + dbusmenu_menuitem_child_append (self->root_item, guest_mi); + g_signal_connect (G_OBJECT (guest_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_guest_session), + self); + users_service_dbus_set_guest_item (self->users_dbus_interface, + guest_mi); + } + + GList * users = NULL; + users = users_service_dbus_get_user_list (self->users_dbus_interface); + self->user_count = g_list_length(users); + + gboolean user_menu_is_visible = FALSE; + + if (!greeter_mode){ + user_menu_is_visible = self->user_count > 1; + } + + session_dbus_set_user_menu_visibility (self->session_dbus_interface, + user_menu_is_visible); + + if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + users = g_list_sort (users, (GCompareFunc)compare_users_by_username); + } + + for (u = users; u != NULL; u = g_list_next (u)) { + user = u->data; + g_debug ("%p: %s", user, user->real_name); + user->service = self->users_dbus_interface; + + if (g_strcmp0(user->user_name, "guest") == 0) { + /* Check to see if the guest has sessions and so therefore should + get a check mark. */ + if (user->sessions != NULL) { + dbusmenu_menuitem_property_set_bool (guest_mi, + USER_ITEM_PROP_LOGGED_IN, + TRUE); + } + /* If we're showing user accounts, keep going through the list */ + if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + continue; + } + /* If not, we can stop here */ + break; + } + + if (self->user_count > MINIMUM_USERS && self->user_count < MAXIMUM_USERS) { + mi = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (mi, + DBUSMENU_MENUITEM_PROP_TYPE, + USER_ITEM_TYPE); + if (user->real_name_conflict) { + gchar * conflictedname = g_strdup_printf("%s (%s)", user->real_name, user->user_name); + dbusmenu_menuitem_property_set (mi, USER_ITEM_PROP_NAME, conflictedname); + g_free(conflictedname); + } else { + //g_debug ("%i %s", (gint)user->uid, user->real_name); + //g_debug ("users uid = %i", (gint)user->uid); + //g_debug ("users real name = %s", user->real_name); + if (user == NULL){ + g_debug ("USER pointer is NULL"); + return; + } + g_debug ("%p: %s", user, user->real_name); + + dbusmenu_menuitem_property_set (mi, + USER_ITEM_PROP_NAME, + user->real_name); + } + dbusmenu_menuitem_property_set_bool (mi, + USER_ITEM_PROP_LOGGED_IN, + user->sessions != NULL); + if (user->icon_file != NULL && user->icon_file[0] != '\0') { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, user->icon_file); + } else { + dbusmenu_menuitem_property_set(mi, USER_ITEM_PROP_ICON, USER_ITEM_ICON_DEFAULT); + } + + gboolean logged_in = g_strcmp0 (user->user_name, g_get_user_name()) == 0; + dbusmenu_menuitem_property_set_bool (mi, + USER_ITEM_PROP_IS_CURRENT_USER, + logged_in); + if (logged_in == TRUE){ + g_debug ("about to set the users real name to %s for user %s", + user->real_name, user->user_name); + session_dbus_set_users_real_name (self->session_dbus_interface, user->real_name); + } + + dbusmenu_menuitem_child_append (self->root_item, mi); + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_user_session), + user); + user->menuitem = mi; + } + } + g_list_free(users); + } + // Add the online accounts and separator + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator1, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append (self->root_item, separator1); + DbusmenuMenuitem * online_accounts_item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (online_accounts_item, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_DEFAULT); + dbusmenu_menuitem_property_set (online_accounts_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Online Accounts…")); + + g_signal_connect (G_OBJECT (online_accounts_item), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (activate_online_accounts), + NULL); + + dbusmenu_menuitem_child_append (self->root_item, online_accounts_item); +} + +/* Checks to see if we can create sessions */ +// TODO what is this ? +static gboolean +check_new_session () +{ + return TRUE; +} + +/* Check to see if the lockdown key is protecting from + locking the screen. If not, lock it. */ +static void +lock_if_possible (void) { + ensure_gconf_client (); + + if (!gconf_client_get_bool (gconf_client, LOCKDOWN_KEY_SCREENSAVER, NULL)) { + lock_screen(NULL, 0, NULL); + } + + return; +} + + +/* Starts a new generic session */ +static void +activate_new_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) +{ + lock_if_possible(); + + users_service_dbus_show_greeter (USERS_SERVICE_DBUS(user_data)); + + return; +} + +/* Activates a session for a particular user. */ +static void +activate_user_session (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data) +{ + UserData *user = (UserData *)user_data; + UsersServiceDbus *service = user->service; + + lock_if_possible(); + + users_service_dbus_activate_user_session (service, user); +} + +/* Comparison function to look into the UserData struct + to compare by using the username value */ +static gint +compare_users_by_username (const gchar *a, + const gchar *b) +{ + UserData *user1 = (UserData *)a; + UserData *user2 = (UserData *)b; + + gint retval = g_strcmp0 (user1->real_name, user2->real_name); + + /* If they're the same, they're both in conflict. */ + if (retval == 0) { + user1->real_name_conflict = TRUE; + user2->real_name_conflict = TRUE; + } + + return retval; +} + +// TODO +// Wait until dialog is complete to find out name to pass +// to the control centre. +static void +activate_online_accounts (DbusmenuMenuitem *mi, + guint timestamp, + gpointer user_data) +{ + GError * error = NULL; + if (!g_spawn_command_line_async("gnome-control-center online-accounts", &error)) + { + g_warning("Unable to show control centre: %s", error->message); + g_error_free(error); + } +} + +/* Signal called when a user is added. It updates the count and + rebuilds the menu */ +static void +user_change (UsersServiceDbus *service, + const gchar *user_id, + gpointer user_data) +{ + //DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data; + // TODO sort this out. + //rebuild_user_items (root, service); + return; +} + +/* Ensures that we have a GConf client and if we build one + set up the signal handler. */ +static void +ensure_gconf_client () +{ + if (!gconf_client) { + gconf_client = gconf_client_get_default (); + gconf_client_add_dir (gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_add_dir (gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + } +} + +DbusmenuMenuitem* +user_mgr_get_root_item (UserMenuMgr* self) +{ + return self->root_item; +} + +/* Checks to see if we should show the guest suession item */ +static gboolean +check_guest_session (void) +{ + if (geteuid() < 500) { + /* System users shouldn't have guest account shown. Mosly + this would be the case of the guest user itself. */ + return FALSE; + } + + return TRUE; +} + +/* Called when someone clicks on the guest session item. */ +static void +activate_guest_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data) +{ + g_return_if_fail (USER_IS_MENU_MGR (user_data)); + UserMenuMgr* user_mgr = USER_MENU_MGR(user_data); + UsersServiceDbus *service = user_mgr->users_dbus_interface; + + lock_if_possible(); + + if (users_service_dbus_activate_guest_session(service)) { + return; + } +} + + +/* + * Clean Entry Point + */ +UserMenuMgr* user_menu_mgr_new (SessionDbus* session_dbus, gboolean greeter_mode) +{ + UserMenuMgr* user_mgr = g_object_new (USER_TYPE_MENU_MGR, NULL); + user_mgr->session_dbus_interface = session_dbus; + user_menu_mgr_rebuild_items (user_mgr, greeter_mode); + return user_mgr; +} + + diff --git a/src/user-menu-mgr.h b/src/user-menu-mgr.h new file mode 100644 index 0000000..01823e7 --- /dev/null +++ b/src/user-menu-mgr.h @@ -0,0 +1,54 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + + +#ifndef _USER_MENU_MGR_H_ +#define _USER_MENU_MGR_H_ + + +#include <glib-object.h> +#include <libdbusmenu-gtk3/menuitem.h> + +#include "session-dbus.h" + +G_BEGIN_DECLS + +#define USER_TYPE_MENU_MGR (user_menu_mgr_get_type ()) +#define USER_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USER_TYPE_MENU_MGR, UserMenuMgr)) +#define USER_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USER_TYPE_MENU_MGR, UserMenuMgrClass)) +#define USER_IS_MENU_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USER_TYPE_MENU_MGR)) +#define USER_IS_MENU_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USER_TYPE_MENU_MGR)) +#define USER_MENU_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USER_TYPE_MENU_MGR, UserMenuMgrClass)) + +typedef struct _UserMenuMgrClass UserMenuMgrClass; +typedef struct _UserMenuMgr UserMenuMgr; + +struct _UserMenuMgrClass +{ + GObjectClass parent_class; +}; + +GType user_menu_mgr_get_type (void) G_GNUC_CONST; +UserMenuMgr* user_menu_mgr_new (SessionDbus* session_dbus, + gboolean greeter_mode); + +DbusmenuMenuitem* user_mgr_get_root_item (UserMenuMgr* self); +G_END_DECLS + +#endif /* _USER_MENU_MGR_H_ */ diff --git a/src/user-widget.c b/src/user-widget.c new file mode 100644 index 0000000..6495e80 --- /dev/null +++ b/src/user-widget.c @@ -0,0 +1,343 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib/gi18n.h> +#include <gtk/gtk.h> +#include <glib.h> +#include <libindicator/indicator-image-helper.h> +#include "user-widget.h" +#include "dbus-shared-names.h" + + +typedef struct _UserWidgetPrivate UserWidgetPrivate; + +struct _UserWidgetPrivate +{ + DbusmenuMenuitem* twin_item; + GtkWidget* user_image; + GtkWidget* user_name; + GtkWidget* container; + GtkWidget* tick_icon; + gboolean logged_in; + gboolean sessions_active; +}; + +#define USER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USER_WIDGET_TYPE, UserWidgetPrivate)) + +/* Prototypes */ +static void user_widget_class_init (UserWidgetClass *klass); +static void user_widget_init (UserWidget *self); +static void user_widget_dispose (GObject *object); +static void user_widget_finalize (GObject *object); + +static void user_widget_set_twin_item (UserWidget* self, + DbusmenuMenuitem* twin_item); +// keyevent consumers +static gboolean user_widget_button_release_event (GtkWidget *menuitem, + GdkEventButton *event); +// Dbusmenuitem properties update callback +static void user_widget_property_update (DbusmenuMenuitem* item, + gchar* property, + GVariant* value, + gpointer userdata); +#if GTK_CHECK_VERSION(3, 0, 0) +static gboolean user_widget_primitive_draw_cb_gtk_3 (GtkWidget *image, + cairo_t* cr, + gpointer user_data); +#else +static gboolean user_widget_primitive_draw_cb (GtkWidget *image, + GdkEventExpose *event, + gpointer user_data); +#endif + +G_DEFINE_TYPE (UserWidget, user_widget, GTK_TYPE_MENU_ITEM); + +static void +user_widget_class_init (UserWidgetClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->button_release_event = user_widget_button_release_event; + + g_type_class_add_private (klass, sizeof (UserWidgetPrivate)); + + gobject_class->dispose = user_widget_dispose; + gobject_class->finalize = user_widget_finalize; +} + +static void +user_widget_init (UserWidget *self) +{ + UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(self); + + gint padding = 0; + gtk_widget_style_get (GTK_WIDGET(self), + "horizontal-padding", + &padding, + NULL); + + priv->user_image = NULL; + priv->user_name = NULL; + priv->logged_in = FALSE; + priv->sessions_active = FALSE; + priv->container = NULL; + priv->tick_icon = NULL; + + // Create the UI elements. + priv->user_image = gtk_image_new (); + + // Just for now set the image to the default avator image + GdkPixbuf* pixbuf = NULL; + GError* error = NULL; + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + "avatar-default", + 32, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (pixbuf == NULL || error != NULL) { + g_warning ("Could not load the default avatar image for some reason"); + } + else{ + gtk_image_set_from_pixbuf (GTK_IMAGE(priv->user_image), pixbuf); + g_object_unref (pixbuf); + } + + priv->user_name = gtk_label_new (""); + priv->container = gtk_hbox_new (FALSE, 0); + priv->tick_icon = gtk_image_new_from_icon_name ("account-logged-in", + GTK_ICON_SIZE_MENU); + gtk_misc_set_alignment(GTK_MISC(priv->tick_icon), 1.0, 0.5); + + // Pack it together + gtk_box_pack_start (GTK_BOX (priv->container), + priv->user_image, + FALSE, + FALSE, + 0); + gtk_box_pack_start (GTK_BOX (priv->container), + priv->user_name, + FALSE, + FALSE, + 3); + gtk_box_pack_start (GTK_BOX(priv->container), + priv->tick_icon, + FALSE, + FALSE, 5); + + gtk_widget_show_all (priv->container); + gtk_container_add (GTK_CONTAINER (self), priv->container); + + gtk_widget_show_all (priv->tick_icon); + gtk_widget_set_no_show_all (priv->tick_icon, TRUE); + gtk_widget_hide (priv->tick_icon); + + // Fetch the drawing context. + #if GTK_CHECK_VERSION(3, 0, 0) + g_signal_connect_after (GTK_WIDGET(self), "draw", + G_CALLBACK(user_widget_primitive_draw_cb_gtk_3), + GTK_WIDGET(self)); + #else + g_signal_connect_after (GTK_WIDGET(self), "expose-event", + G_CALLBACK(user_widget_primitive_draw_cb), + GTK_WIDGET(self)); + #endif +} + +static void +user_widget_dispose (GObject *object) +{ + //UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(USER_WIDGET(object)); + + G_OBJECT_CLASS (user_widget_parent_class)->dispose (object); +} + +// TODO tidy up image and name +static void +user_widget_finalize (GObject *object) +{ + G_OBJECT_CLASS (user_widget_parent_class)->finalize (object); +} + +#if GTK_CHECK_VERSION(3, 0, 0) + +// Draw the radio dot and/or green check mark +// TODO handle drawing of green check mark +static gboolean +user_widget_primitive_draw_cb_gtk_3 (GtkWidget *widget, + cairo_t* cr, + gpointer user_data) +{ + + g_return_val_if_fail(IS_USER_WIDGET(user_data), FALSE); + UserWidget* meta = USER_WIDGET(user_data); + UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(meta); + + // Draw dot only when user is the current user. + if (!dbusmenu_menuitem_property_get_bool (priv->twin_item, + USER_ITEM_PROP_IS_CURRENT_USER)){ + return FALSE; + } + + GtkStyle *style; + gdouble x, y; + gdouble offset = 15.0; + + style = gtk_widget_get_style (widget); + + GtkAllocation allocation; + gtk_widget_get_allocation (widget, &allocation); + x = allocation.x + 13; + y = offset; + + cairo_arc (cr, x, y, 3.0, 0.0, 2 * G_PI);; + + cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0); + cairo_fill (cr); + + return FALSE; +} + +// GTK 2 Expose handler +#else + +// Draw the triangle if the player is running ... +static gboolean +user_widget_primitive_draw_cb (GtkWidget *widget, + GdkEventExpose *event, + gpointer user_data) +{ + /* + g_return_val_if_fail(IS_USER_WIDGET(user_data), FALSE); + UserWidget* meta = USER_WIDGET(user_data); + UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(meta); + + GtkStyle *style; + cairo_t *cr; + int x, y, arrow_width, arrow_height; + + gint offset = 3; + arrow_width = 5; + arrow_height = 9; + + style = gtk_widget_get_style (widget); + + cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget)); + + GtkAllocation allocation; + gtk_widget_get_allocation (widget, &allocation); + x = allocation.x; + y = allocation.y; + + // Draw player icon + if (priv->icon_buf != NULL){ + gdk_cairo_set_source_pixbuf (cr, + priv->icon_buf, + x + arrow_width + 1, + y + offset); + cairo_paint (cr); + } + + // Draw triangle but only if the player is running. + if (dbusmenu_menuitem_property_get_bool (priv->twin_item, + DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING)){ + y += (double)arrow_height/2.0 + offset; + cairo_set_line_width (cr, 1.0); + + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + arrow_height); + cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); + cairo_close_path (cr); + cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0); + cairo_fill (cr); + } + + cairo_destroy (cr);*/ + return FALSE; +} +#endif + + +/* Suppress/consume keyevents */ +static gboolean +user_widget_button_release_event (GtkWidget *menuitem, + GdkEventButton *event) +{ + return FALSE; +} + +static void +user_widget_property_update (DbusmenuMenuitem* item, gchar* property, + GVariant* value, gpointer userdata) +{ + g_return_if_fail (IS_USER_WIDGET (userdata)); + //gtk_widget_queue_redraw (GTK_WIDGET(userdata)); +} + + +static void +user_widget_set_twin_item (UserWidget* self, + DbusmenuMenuitem* twin_item) +{ + UserWidgetPrivate* priv = USER_WIDGET_GET_PRIVATE(self); + priv->twin_item = twin_item; + g_signal_connect( G_OBJECT(priv->twin_item), "property-changed", + G_CALLBACK(user_widget_property_update), self); + + const gchar * icon_name = dbusmenu_menuitem_property_get (twin_item, + USER_ITEM_PROP_ICON); + gtk_label_set_label (GTK_LABEL (priv->user_name), + dbusmenu_menuitem_property_get (twin_item, USER_ITEM_PROP_NAME)); + + if (dbusmenu_menuitem_property_get_bool (twin_item, USER_ITEM_PROP_LOGGED_IN)) { + g_debug ("%s USER HAS ACTIVE SESSIONS", + dbusmenu_menuitem_property_get (twin_item, USER_ITEM_PROP_NAME)); + gtk_widget_show(priv->tick_icon); + } + else { + g_debug ("%s USER DOESN'T HAVE ACTIVE SESSIONS", + dbusmenu_menuitem_property_get (twin_item, USER_ITEM_PROP_NAME)); + gtk_widget_hide(priv->tick_icon); + } + + g_debug("Using user icon for '%s' from file: %s", + dbusmenu_menuitem_property_get(twin_item, USER_ITEM_PROP_NAME), icon_name); + +} + + /** + * transport_new: + * @returns: a new #UserWidget. + **/ +GtkWidget* +user_widget_new(DbusmenuMenuitem *item) +{ + GtkWidget* widget = g_object_new(USER_WIDGET_TYPE, NULL); + user_widget_set_twin_item ( USER_WIDGET(widget), item ); + return widget; +} diff --git a/src/user-widget.h b/src/user-widget.h new file mode 100644 index 0000000..e1f6d1a --- /dev/null +++ b/src/user-widget.h @@ -0,0 +1,54 @@ +/* +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __USER_WIDGET_H__ +#define __USER_WIDGET_H__ + +#include <gtk/gtk.h> +#if GTK_CHECK_VERSION(3, 0, 0) +#include <libdbusmenu-gtk3/menuitem.h> +#else +#include <libdbusmenu-gtk/menuitem.h> +#endif + +G_BEGIN_DECLS + +#define USER_WIDGET_TYPE (user_widget_get_type ()) +#define USER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USER_WIDGET_TYPE, UserWidget)) +#define USER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USER_WIDGET_TYPE, UserWidgetClass)) +#define IS_USER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USER_WIDGET_TYPE)) +#define IS_USER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USER_WIDGET_TYPE)) +#define USER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USER_WIDGET_TYPE, UserWidgetClass)) + +typedef struct _UserWidget UserWidget; +typedef struct _UserWidgetClass UserWidgetClass; + +struct _UserWidgetClass { + GtkMenuItemClass parent_class; +}; + +struct _UserWidget { + GtkMenuItem parent; +}; + +GType user_widget_get_type (void); +GtkWidget* user_widget_new(DbusmenuMenuitem *twin_item); + +G_END_DECLS + +#endif diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 11ee497..e7507a4 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -31,12 +31,12 @@ #include <dbus/dbus-glib-lowlevel.h> #include "dbus-shared-names.h" -#include "gdm-local-display-factory-client.h" +#include "display-manager-client.h" #include "users-service-dbus.h" -#include "users-service-client.h" -#include "users-service-marshal.h" +#include "accounts-service-client.h" #include "consolekit-manager-client.h" #include "consolekit-session-client.h" +#include "consolekit-seat-client.h" #define CK_ADDR "org.freedesktop.ConsoleKit" #define CK_SESSION_IFACE "org.freedesktop.ConsoleKit.Session" @@ -46,21 +46,17 @@ static void users_service_dbus_class_init (UsersServiceDbusClass *kl static void users_service_dbus_init (UsersServiceDbus *self); static void users_service_dbus_dispose (GObject *object); static void users_service_dbus_finalize (GObject *object); -static void create_gdm_proxy (UsersServiceDbus *self); +static void create_display_manager_proxy (UsersServiceDbus *self); +static void create_accounts_service_proxy (UsersServiceDbus *self); static void create_seat_proxy (UsersServiceDbus *self); static void create_ck_proxy (UsersServiceDbus *self); static void create_cksession_proxy (UsersServiceDbus *self); static gchar *get_seat (UsersServiceDbus *service); -static void users_loaded (DBusGProxy *proxy, - gpointer user_data); static void user_added (DBusGProxy *proxy, - gint64 uid, - gpointer user_data); -static void user_removed (DBusGProxy *proxy, - gint64 uid, + const gchar *user_id, gpointer user_data); -static void user_updated (DBusGProxy *proxy, - guint uid, +static void user_deleted (DBusGProxy *proxy, + const gchar *user_id, gpointer user_data); static void seat_proxy_session_added (DBusGProxy *seat_proxy, const gchar *session_id, @@ -68,6 +64,7 @@ static void seat_proxy_session_added (DBusGProxy *seat_ static void seat_proxy_session_removed (DBusGProxy *seat_proxy, const gchar *session_id, UsersServiceDbus *service); +static void sync_users (UsersServiceDbus *self); static gboolean do_add_session (UsersServiceDbus *service, UserData *user, const gchar *ssid); @@ -85,8 +82,8 @@ struct _UsersServiceDbusPrivate DBusGConnection *system_bus; - DBusGProxy *gdm_proxy; - DBusGProxy *gdm_local_proxy; + DBusGProxy *accounts_service_proxy; + DBusGProxy *display_manager_proxy; DBusGProxy *ck_proxy; DBusGProxy *seat_proxy; DBusGProxy *session_proxy; @@ -102,10 +99,8 @@ struct _UsersServiceDbusPrivate /* Signals */ enum { - USERS_LOADED, USER_ADDED, - USER_REMOVED, - USER_UPDATED, + USER_DELETED, LAST_SIGNAL }; @@ -124,37 +119,21 @@ users_service_dbus_class_init (UsersServiceDbusClass *klass) object_class->dispose = users_service_dbus_dispose; object_class->finalize = users_service_dbus_finalize; - signals[USERS_LOADED] = g_signal_new ("users-loaded", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (UsersServiceDbusClass, users_loaded), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - signals[USER_ADDED] = g_signal_new ("user-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (UsersServiceDbusClass, user_added), NULL, NULL, - _users_service_marshal_VOID__INT64, - G_TYPE_NONE, 1, G_TYPE_INT64); + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); - signals[USER_REMOVED] = g_signal_new ("user-removed", + signals[USER_DELETED] = g_signal_new ("user-deleted", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (UsersServiceDbusClass, user_removed), + G_STRUCT_OFFSET (UsersServiceDbusClass, user_deleted), NULL, NULL, - _users_service_marshal_VOID__INT64, - G_TYPE_NONE, 1, G_TYPE_INT64); - - signals[USER_UPDATED] = g_signal_new ("user-updated", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (UsersServiceDbusClass, user_updated), - NULL, NULL, - _users_service_marshal_VOID__INT64, - G_TYPE_NONE, 1, G_TYPE_INT64); + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); } static void @@ -188,17 +167,10 @@ users_service_dbus_init (UsersServiceDbus *self) g_free, NULL); - dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, - G_TYPE_NONE, - G_TYPE_INT64, - G_TYPE_INVALID); - - create_gdm_proxy (self); create_ck_proxy (self); create_seat_proxy (self); - - if (priv->gdm_proxy) - users_loaded (priv->gdm_proxy, self); + create_display_manager_proxy (self); + create_accounts_service_proxy (self); } static void @@ -221,75 +193,110 @@ users_service_dbus_finalize (GObject *object) } static void -create_gdm_proxy (UsersServiceDbus *self) +create_display_manager_proxy (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusGProxy *dm_proxy = NULL; GError *error = NULL; + const gchar *cookie = NULL; + gchar *seat = NULL; + + cookie = g_getenv ("XDG_SESSION_COOKIE"); + if (cookie == NULL || cookie[0] == 0) + { + g_warning ("Failed to get DisplayManager proxy: XDG_SESSION_COOKIE undefined."); + return; + } - priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, - "org.gnome.DisplayManager", - "/org/gnome/DisplayManager/UserManager", - "org.gnome.DisplayManager.UserManager", - &error); + dm_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.DisplayManager", + "/org/freedesktop/DisplayManager", + "org.freedesktop.DisplayManager"); - if (!priv->gdm_proxy) + if (!dm_proxy) { - if (error != NULL) - { - g_warning ("Unable to get DisplayManager proxy on system bus: %s", error->message); - g_error_free (error); - } + g_warning ("Failed to get DisplayManager proxy."); + return; + } + + /* Now request the proper seat */ + if (!dbus_g_proxy_call (dm_proxy, "GetSeatForCookie", &error, + G_TYPE_STRING, cookie, G_TYPE_INVALID, + DBUS_TYPE_G_OBJECT_PATH, &seat, G_TYPE_INVALID)) + { + g_warning ("Failed to get DisplayManager seat proxy: %s", error->message); + g_object_unref (dm_proxy); + g_error_free (error); + return; + } + g_object_unref (dm_proxy); + + priv->display_manager_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.DisplayManager", + seat, + "org.freedesktop.DisplayManager.Seat"); + g_free (seat); + if (!priv->display_manager_proxy) + { + g_warning ("Failed to get DisplayManager seat proxy."); return; } +} - dbus_g_proxy_add_signal (priv->gdm_proxy, - "UsersLoaded", - G_TYPE_INVALID); +static void +create_accounts_service_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GPtrArray *users = g_ptr_array_new (); + GError *error = NULL; - dbus_g_proxy_add_signal (priv->gdm_proxy, + priv->accounts_service_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.Accounts", + "/org/freedesktop/Accounts", + "org.freedesktop.Accounts"); + + dbus_g_proxy_add_signal (priv->accounts_service_proxy, "UserAdded", - G_TYPE_INT64, + DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->gdm_proxy, - "UserRemoved", - G_TYPE_INT64, + dbus_g_proxy_add_signal (priv->accounts_service_proxy, + "UserChanged", + DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->gdm_proxy, - "UserUpdated", - G_TYPE_INT64, + dbus_g_proxy_add_signal (priv->accounts_service_proxy, + "UserDeleted", + DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->gdm_proxy, - "UsersLoaded", - G_CALLBACK (users_loaded), - self, - NULL); - - dbus_g_proxy_connect_signal (priv->gdm_proxy, + dbus_g_proxy_connect_signal (priv->accounts_service_proxy, "UserAdded", G_CALLBACK (user_added), self, NULL); - dbus_g_proxy_connect_signal (priv->gdm_proxy, - "UserRemoved", - G_CALLBACK (user_removed), + dbus_g_proxy_connect_signal (priv->accounts_service_proxy, + "UserDeleted", + G_CALLBACK (user_deleted), self, NULL); - dbus_g_proxy_connect_signal (priv->gdm_proxy, - "UserUpdated", - G_CALLBACK (user_updated), - self, - NULL); + if (!org_freedesktop_Accounts_list_cached_users (priv->accounts_service_proxy, + &users, + &error)) + { + g_warning ("failed to retrieve user count: %s", error->message); + g_error_free (error); - priv->gdm_local_proxy = dbus_g_proxy_new_for_name (priv->system_bus, - "org.gnome.DisplayManager", - "/org/gnome/DisplayManager/LocalDisplayFactory", - "org.gnome.DisplayManager.LocalDisplayFactory"); + return; + } + + priv->count = users->len; + g_ptr_array_free (users, TRUE); + + sync_users (self); } static void @@ -309,6 +316,28 @@ create_ck_proxy (UsersServiceDbus *self) } } +/* Get the initial sessions when starting up */ +static void +get_cksessions_cb (DBusGProxy *proxy, GPtrArray * sessions, GError * error, gpointer userdata) +{ + if (error != NULL) { + g_warning("Unable to get initial sessions: %s", error->message); + return; + } + + /* If there's no error we should at least get an + array of zero entries */ + g_return_if_fail(sessions != NULL); + g_debug("Got %d initial sessions", sessions->len); + + int i; + for (i = 0; i < sessions->len; i++) { + seat_proxy_session_added(proxy, g_ptr_array_index(sessions, i), USERS_SERVICE_DBUS(userdata)); + } + + return; +} + static void create_seat_proxy (UsersServiceDbus *self) { @@ -357,6 +386,10 @@ create_seat_proxy (UsersServiceDbus *self) G_CALLBACK (seat_proxy_session_removed), self, NULL); + + org_freedesktop_ConsoleKit_Seat_get_sessions_async (priv->seat_proxy, get_cksessions_cb, self); + + return; } static void @@ -550,7 +583,11 @@ static void add_sessions_for_user (UsersServiceDbus *self, UserData *user) { - g_return_if_fail(IS_USERS_SERVICE_DBUS(self)); + g_return_if_fail (IS_USERS_SERVICE_DBUS(self)); + + g_debug ("!!!!!!!!!! - add_sessions_for_user %i %s", + (int)user->uid, user->user_name); + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); GError *error; GPtrArray *sessions; @@ -586,7 +623,6 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, g_return_if_fail(IS_USERS_SERVICE_DBUS(service)); UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); uid_t uid; - gboolean res; struct passwd *pwent; UserData *user; @@ -615,13 +651,11 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, return; } - user = g_hash_table_lookup (priv->users, pwent->pw_name); + user = users_service_dbus_get_user_by_username (service, pwent->pw_name); if (!user) - { - return; - } + return; - res = do_add_session (service, user, session_id); + do_add_session (service, user, session_id); } static void @@ -648,7 +682,7 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, return; } - user = g_hash_table_lookup (priv->users, username); + user = users_service_dbus_get_user_by_username (service, username); if (!user) return; @@ -684,16 +718,15 @@ sync_users (UsersServiceDbus *self) if (priv->count > MINIMUM_USERS && priv->count < MAXIMUM_USERS) { - GArray *uids = NULL; - GPtrArray *users_info = NULL; + GPtrArray *users = NULL; GError *error = NULL; gint i; - uids = g_array_new (FALSE, FALSE, sizeof (gint64)); + users = g_ptr_array_new (); - if (!org_gnome_DisplayManager_UserManager_get_user_list (priv->gdm_proxy, - &uids, - &error)) + if (!org_freedesktop_Accounts_list_cached_users (priv->accounts_service_proxy, + &users, + &error)) { g_warning ("failed to retrieve user list: %s", error->message); g_error_free (error); @@ -701,374 +734,101 @@ sync_users (UsersServiceDbus *self) return; } - users_info = g_ptr_array_new (); - - if (!org_gnome_DisplayManager_UserManager_get_users_info (priv->gdm_proxy, - uids, - &users_info, - &error)) + for (i = 0; i < users->len; i++) { - g_warning ("failed to retrieve user info: %s", error->message); - g_error_free (error); + gchar *id; + DBusGProxy *proxy; + UserData *user; + GError *error = NULL; - return; - } + id = g_ptr_array_index (users, i); - for (i = 0; i < users_info->len; i++) - { - GValueArray *values; - UserData *user; + proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.Accounts", + id, + "org.freedesktop.DBus.Properties"); - values = g_ptr_array_index (users_info, i); + GHashTable *properties; + if (!dbus_g_proxy_call (proxy, "GetAll", &error, + G_TYPE_STRING, "org.freedesktop.Accounts.User", G_TYPE_INVALID, + dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &properties, G_TYPE_INVALID)) + { + g_warning ("unable to retrieve user info: %s", error->message); + g_error_free (error); + + continue; + } user = g_new0 (UserData, 1); - user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); - user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); - user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); - user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); - user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); - user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); + user->uid = g_value_get_uint64 (g_hash_table_lookup (properties, "Uid")); + user->user_name = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "UserName"))); + user->real_name = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "RealName"))); + user->icon_file = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "IconFile"))); user->real_name_conflict = FALSE; user->menuitem = NULL; + g_hash_table_unref (properties); + g_hash_table_insert (priv->users, - g_strdup (user->user_name), + g_strdup (id), user); add_sessions_for_user (self, user); } - } -} - -static void -users_loaded (DBusGProxy *proxy, - gpointer user_data) -{ - UsersServiceDbus *service; - UsersServiceDbusPrivate *priv; - GError *error = NULL; - gint count; - - g_return_if_fail (proxy != NULL); - - service = (UsersServiceDbus *)user_data; - priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - - if (!org_gnome_DisplayManager_UserManager_count_users (proxy, - &count, - &error)) - { - g_warning ("failed to retrieve user count: %s", error->message); - g_error_free (error); - - return; - } - - priv->count = count; - - sync_users (service); -} - -static gboolean -session_is_login_window (UsersServiceDbus *self, - const char *ssid) -{ - g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), FALSE); - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - DBusGProxy *proxy = NULL; - GError *error = NULL; - char *type = NULL; - - if (!(proxy = dbus_g_proxy_new_for_name (priv->system_bus, - CK_ADDR, - ssid, - CK_SESSION_IFACE))) - { - g_warning ("Failed to get ConsoleKit proxy"); - - return FALSE; - } - - if (!org_freedesktop_ConsoleKit_Session_get_session_type (proxy, &type, &error)) - { - g_warning ("Can't call GetSessionType: %s", error->message); - g_error_free (error); - - if (proxy) - g_object_unref (proxy); - - return FALSE; - } - - if (proxy) - g_object_unref (proxy); - - return (type && type[0] != '\0' && strcmp (type, "LoginWindow") == 0); -} - -static char * -get_login_session (UsersServiceDbus *self) -{ - g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), NULL); - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - gboolean can_activate; - GError *error = NULL; - GPtrArray *sessions = NULL; - char *ssid = NULL; - int i; - - if (!priv->seat || priv->seat[0] == '\0') - { - return NULL; - } - - if (!dbus_g_proxy_call (priv->seat_proxy, - "CanActivateSessions", - &error, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &can_activate, - G_TYPE_INVALID)) - { - g_warning ("Failed to call CanActivateSessions: %s", error->message); - g_error_free (error); - - return NULL; - } - - if (!can_activate) - { - return NULL; - } - - error = NULL; - if (!dbus_g_proxy_call (priv->seat_proxy, - "GetSessions", - &error, - G_TYPE_INVALID, - dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &sessions, - G_TYPE_INVALID)) - { - g_warning ("Failed to call GetSessions: %s", error->message); - g_error_free (error); - - return NULL; - } - - for (i = 0; i < sessions->len; i++) - { - char *s = g_ptr_array_index (sessions, i); - - if (session_is_login_window (self, s)) - { - ssid = g_strdup (s); - break; - } - } - - g_ptr_array_foreach (sessions, (GFunc)g_free, NULL); - g_ptr_array_free (sessions, TRUE); - - return ssid; -} - -static gboolean -activate_user_session (UsersServiceDbus *self, - const char *seat, - const char *ssid) -{ - g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), FALSE); - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - DBusMessage *message = NULL; - DBusMessage *reply = NULL; - DBusError error; - - if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", - seat, - "org.freedesktop.ConsoleKit.Seat", - "ActivateSession"))) - { - return FALSE; - } - - if (!dbus_message_append_args (message, - DBUS_TYPE_OBJECT_PATH, &ssid, - DBUS_TYPE_INVALID)) - { - return FALSE; - } - - dbus_error_init (&error); - if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), - message, - -1, - &error))) - { - if (dbus_error_is_set (&error)) - { - g_warning ("Can't activate session: %s", error.message); - dbus_error_free (&error); - - return FALSE; - } - } - - if (message) - { - dbus_message_unref (message); - } - if (reply) - { - dbus_message_unref (reply); + g_ptr_array_free (users, TRUE); } - - return TRUE; -} - -gboolean -start_new_user_session (UsersServiceDbus *self, - UserData *user) -{ - g_return_val_if_fail (IS_USERS_SERVICE_DBUS (self), FALSE); - - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - GError *error = NULL; - char *ssid; - - ssid = get_login_session (self); - if (ssid) - { - if (!activate_user_session (self, priv->seat, ssid)) - { - return FALSE; - } - } - - if (!g_spawn_command_line_async ("gdmflexiserver -s", &error)) - { - g_warning ("Failed to start new login session: %s", error->message); - g_error_free (error); - - return FALSE; - } - - return TRUE; } static void -user_added (DBusGProxy *proxy, - gint64 uid, - gpointer user_data) +user_added (DBusGProxy *proxy, + const gchar *user_id, + gpointer user_data) { UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - UserData *user = g_new0 (UserData, 1); - GError *error = NULL; priv->count++; if (priv->count < MAXIMUM_USERS) { - if ((priv->count - g_hash_table_size (priv->users)) > 1) - { - sync_users (service); - } - else - { - if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy, - uid, - &user->user_name, - &user->real_name, - &user->shell, - &user->login_count, - &user->icon_url, - &error)) - { - g_warning ("unable to retrieve user info: %s", error->message); - g_error_free (error); - - g_free (user); - - return; - } - - user->uid = uid; - - g_hash_table_insert (priv->users, - g_strdup (user->user_name), - user); - - g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); - } + sync_users (service); } } -static gboolean -compare_users_by_uid (gpointer key, - gpointer value, - gpointer user_data) -{ - return (GPOINTER_TO_UINT (value) == GPOINTER_TO_UINT (user_data)); -} - static void -user_removed (DBusGProxy *proxy, - gint64 uid, - gpointer user_data) +user_deleted (DBusGProxy *proxy, + const gchar *user_id, + gpointer user_data) { UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - UserData *user; - gint size; - - size = g_hash_table_size (priv->users); priv->count--; - - if (size == 0 || (size - priv->count) > 1) - { - sync_users (service); - } - else - { - user = g_hash_table_find (priv->users, - compare_users_by_uid, - GUINT_TO_POINTER ((gint)uid)); - - if (user != NULL) - { - g_hash_table_remove (priv->users, - user->user_name); - } - } + g_hash_table_remove (priv->users, user_id); } -static void -user_updated (DBusGProxy *proxy, - guint uid, - gpointer user_data) +UserData * +users_service_dbus_get_user_by_username (UsersServiceDbus *self, + const gchar *username) { -#if 0 - // XXX - TODO - UsersServiceDbus *service = (UsersServiceDbus *)user_data; - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - UserData *user; - - user = g_hash_table_find (priv->users, - compare_users_by_uid, - GUINT_TO_POINTER (uid)); -#endif -} + GHashTableIter iter; + gpointer value; -gint -users_service_dbus_get_user_count (UsersServiceDbus *self) -{ - g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), 0); + g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), NULL); UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - return priv->count; + g_hash_table_iter_init (&iter, priv->users); + while (g_hash_table_iter_next (&iter, NULL, &value)) + { + UserData *user = value; + if (strcmp (user->user_name, username) == 0) + return user; + } + + return NULL; } GList * @@ -1081,13 +841,21 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) return g_hash_table_get_values (priv->users); } +gboolean +users_service_dbus_show_greeter (UsersServiceDbus *self) +{ + g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), FALSE); + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + return org_freedesktop_DisplayManager_Seat_switch_to_greeter(priv->display_manager_proxy, NULL); +} + /* Activates the guest account if it can. */ gboolean users_service_dbus_activate_guest_session (UsersServiceDbus *self) { g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), FALSE); UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - return org_gnome_DisplayManager_LocalDisplayFactory_switch_to_user(priv->gdm_local_proxy, "guest", NULL, NULL); + return org_freedesktop_DisplayManager_Seat_switch_to_guest(priv->display_manager_proxy, "", NULL); } /* Activates a specific user */ @@ -1097,7 +865,7 @@ users_service_dbus_activate_user_session (UsersServiceDbus *self, { g_return_val_if_fail(IS_USERS_SERVICE_DBUS(self), FALSE); UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - return org_gnome_DisplayManager_LocalDisplayFactory_switch_to_user(priv->gdm_local_proxy, user->user_name, NULL, NULL); + return org_freedesktop_DisplayManager_Seat_switch_to_user(priv->display_manager_proxy, user->user_name, "", NULL); } gboolean diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h index 4798d64..c3f0171 100644 --- a/src/users-service-dbus.h +++ b/src/users-service-dbus.h @@ -42,9 +42,7 @@ struct _UserData gint64 uid; gchar *user_name; gchar *real_name; - gchar *shell; - gint login_count; - gchar *icon_url; + gchar *icon_file; GList *sessions; @@ -70,17 +68,16 @@ struct _UsersServiceDbusClass { GObjectClass parent_class; /* Signals */ - void (* users_loaded) (UsersServiceDbus *self, gpointer user_data); - - void (* user_added) (UsersServiceDbus *self, gint64 uid, gpointer user_data); - void (* user_removed) (UsersServiceDbus *self, gint64 uid, gpointer user_data); - void (* user_updated) (UsersServiceDbus *self, gint64 uid, gpointer user_data); + void (* user_added) (UsersServiceDbus *self, const gchar *user_id, gpointer user_data); + void (* user_deleted) (UsersServiceDbus *self, const gchar *user_id, gpointer user_data); }; GType users_service_dbus_get_type (void) G_GNUC_CONST; -gint users_service_dbus_get_user_count (UsersServiceDbus *self); +UserData *users_service_dbus_get_user_by_username (UsersServiceDbus *self, + const gchar *username); GList *users_service_dbus_get_user_list (UsersServiceDbus *self); +gboolean users_service_dbus_show_greeter (UsersServiceDbus *self); gboolean users_service_dbus_can_activate_session (UsersServiceDbus *self); gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self, UserData *user); diff --git a/src/users-service.list b/src/users-service.list deleted file mode 100644 index 36f34ba..0000000 --- a/src/users-service.list +++ /dev/null @@ -1 +0,0 @@ -VOID:INT64 diff --git a/src/users-service.xml b/src/users-service.xml deleted file mode 100644 index c90f1e8..0000000 --- a/src/users-service.xml +++ /dev/null @@ -1,56 +0,0 @@ -<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> -<node name="/org/gnome/DisplayManager/UserManager"> - <interface name="org.gnome.DisplayManager.UserManager"> - - <!-- Get the number of known users --> - <method name="CountUsers"> - <arg name="user_count" direction="out" type="i"/> - </method> - - <!-- Get the list of known UIDs --> - <method name="GetUserList"> - <arg name="uids" direction="out" type="ax"/> - </method> - - <!-- Get user info for a user --> - <method name="GetUserInfo"> - <arg name="uid" direction="in" type="x"/> - <arg name="user_name" direction="out" type="s"/> - <arg name="real_name" direction="out" type="s"/> - <arg name="shell" direction="out" type="s"/> - <arg name="login_count" direction="out" type="i"/> - <arg name="icon_url" direction="out" type="s"/> - </method> - - <!-- Get user info for a list of users --> - <method name="GetUsersInfo"> - <arg name="uid" direction="in" type="ax"/> - <!-- (uid, user_name, real_name, shell, icon_url) --> - <arg name="user_info" direction="out" type="a(xsssis)"/> - </method> - - <!-- Query if the initial user list is loaded --> - <method name="GetUsersLoaded"> - <arg name="is_loaded" direction="out" type="b"/> - </method> - - <!-- Triggered when the initial user list is loaded --> - <signal name="UsersLoaded"></signal> - - <!-- Triggered when a users are added to/removed from the system. - Clients should monitor these signals as soon as they connect to - this object --> - <signal name="UserAdded"> - <arg name="uid" type="x"/> - </signal> - <signal name="UserRemoved"> - <arg name="uid" type="x"/> - </signal> - - <!-- Triggered when a user has updated information --> - <signal name="UserUpdated"> - <arg name="uid" type="x"/> - </signal> - - </interface> -</node> |