Here it goes. Based on the Gaim scriptlet, changes:
* Detects if the PidginLoginMessage/PidginLogoutMessage config options
are set to an empty string (it will clear the message in such case,
but a missing option still means that do not touch the status message).
* Introduced 'PidginWorkaroundAutoAway' config option to work around the
problem arised by the auto-away feature of Pidgin/Gaim.
* Fixed a bug: now it uses "$*" to be able to use a message that contains
whitespace.
* Renamed gaim to pidgin.
* Changed program name from 'Pidgin' to 'Pidgin/Gaim'.
* Renamed all identifiers and config options from Gaim to Pidgin
(with backcompat options for Gaim).
* Added support for Pidgin.
* Better error reporting when reading an envvar fails.
norbi
diff -Naur hibernate-1.99/common.conf hibernate-1.99-fixed/common.conf
--- hibernate-1.99/common.conf 2008-05-01 13:59:58.000000000 +0200
+++ hibernate-1.99-fixed/common.conf 2009-04-08 03:38:16.000000000 +0200
@@ -145,9 +145,9 @@
### xbacklight
# BackLight yes
-### gaim
-## You need to have dbus, gaim_remote available.
-# LogoutGaim yes
-# GaimRestoreStatus yes
-# GaimLogoutMessage Hibernating
-# GaimLoginMessage Back from hibernation
+### pidgin
+## You need to have dbus, purple-remote/gaim-remote available.
+# LogoutPidgin yes
+# PidginRestoreStatus yes
+# PidginLogoutMessage Hibernating
+# PidginLoginMessage Back from hibernation
diff -Naur hibernate-1.99/hibernate.vim hibernate-1.99-fixed/hibernate.vim
--- hibernate-1.99/hibernate.vim 2008-05-01 13:59:58.000000000 +0200
+++ hibernate-1.99-fixed/hibernate.vim 2009-04-08 03:39:33.000000000 +0200
@@ -256,11 +256,12 @@
" xbacklight
syntax keyword hibernate_conf backlight contained nextgroup=hibernate_boolean skipwhite
-" gaim
-syntax keyword hibernate_conf logoutgaim contained nextgroup=hibernate_boolean skipwhite
-syntax keyword hibernate_conf gaimrestorestatus contained nextgroup=hibernate_boolean skipwhite
-syntax keyword hibernate_conf gaimlogoutmessage contained nextgroup=hibernate_text skipwhite
-syntax keyword hibernate_conf gaimloginmessage contained nextgroup=hibernate_text skipwhite
+" pidgin
+syntax keyword hibernate_conf logoutpidgin contained nextgroup=hibernate_boolean skipwhite
+syntax keyword hibernate_conf pidginrestorestatus contained nextgroup=hibernate_boolean skipwhite
+syntax keyword hibernate_conf pidginworkaroundautoaway contained nextgroup=hibernate_boolean skipwhite
+syntax keyword hibernate_conf pidginlogoutmessage contained nextgroup=hibernate_text skipwhite
+syntax keyword hibernate_conf pidginloginmessage contained nextgroup=hibernate_text skipwhite
" Full-line comments:
syntax match hibernate_comment /^#.*/
diff -Naur hibernate-1.99/scriptlets.d/gaim hibernate-1.99-fixed/scriptlets.d/gaim
--- hibernate-1.99/scriptlets.d/gaim 2008-05-01 13:59:58.000000000 +0200
+++ hibernate-1.99-fixed/scriptlets.d/gaim 1970-01-01 01:00:00.000000000 +0100
@@ -1,120 +0,0 @@
-# -*- sh -*-
-# vim:ft=sh:ts=8:sw=4:noet
-
-# $Id: gaim 338 2007-06-10 16:19:56Z mendel $
-
-gaim_remote=$(command -v gaim-remote)
-
-AddConfigHandler GaimOptions
-AddConfigHelp "LogoutGaim <boolean>" "Changes all locally running Gaim's status to offline before suspending, and (optionally) change it back to the original status after resuming."
-AddConfigHelp "GaimRestoreStatus <boolean>" "Changes back Gaim's status to the original status after resuming."
-AddConfigHelp "GaimLogoutMessage <string>" "Status message to set when logging out Gaim."
-AddConfigHelp "GaimLoginMessage <string>" "Status message to set when logging in Gaim."
-
-LogoutGaim()
-{
- [ x"$LOGOUT_GAIM" != "x1" ] && return 0
-
- if [ -z "$gaim_remote" ] || [ ! -x "$gaim_remote" ]; then
- vecho 0 'Cannot log out Gaim: `gaim-remote` not found.'
- return 0
- fi
-
- local pid i=0
- for pid in `pidof gaim`; do
- local user dbus_session_bus_address gaim_status saved_status_id status_type gaim_remote_cmd
-
- user=$(get_env_var_of_process $pid USER)
- dbus_session_bus_address=$(get_env_var_of_process $pid DBUS_SESSION_BUS_ADDRESS)
-
- vecho 2 "Saving status of $user's Gaim using D-Bus session bus address $dbus_session_bus_address"
- # gaim-remote (as of 2.0.0beta5) does not support the 'getstatus' command, so we do it manually
- saved_status_id=$(DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" su "$user" -c "$gaim_remote 'GaimSavedstatusGetCurrent'")
- status_type=$(DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" su "$user" -c "$gaim_remote 'GaimSavedstatusGetType?saved_status=$saved_status_id'")
- gaim_status=$(DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" su "$user" -c "$gaim_remote 'GaimPrimitiveGetIdFromType?type=$status_type'")
-
- # using this eval-crap to be POSIX-compliant (arrays are nonstandard)
- eval "GAIM_LOGGED_OUT_SESSIONS_USER_$i='$user'"
- eval "GAIM_LOGGED_OUT_SESSIONS_DBUS_$i='$dbus_session_bus_address'"
- eval "GAIM_LOGGED_OUT_SESSIONS_STATUS_$i='$gaim_status'"
- i=`expr $i + 1`
-
- gaim_remote_cmd="setstatus?status=offline"
- if [ -n "$GAIM_LOGOUT_MESSAGE" ]; then
- gaim_remote_cmd="$gaim_remote_cmd&message=$GAIM_LOGOUT_MESSAGE"
- fi
-
- vecho 2 "Logging out $user's Gaim using D-Bus session bus address $dbus_session_bus_address"
- DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" su "$user" -c "$gaim_remote '$gaim_remote_cmd'"
- done
-
- return 0
-}
-
-LoginGaim()
-{
- [ x"$LOGOUT_GAIM" != "x1" ] && return 0
-
- [ x"$GAIM_RESTORE_STATUS" != "x1" ] && return 0
-
- if [ -z "$gaim_remote" ] || [ ! -x "$gaim_remote" ]; then
- vecho 0 'Cannot log on Gaim: `gaim-remote` not found.'
- return 0
- fi
-
- local i=0
- while :; do
- local user dbus_session_bus_address gaim_status gaim_remote_cmd
-
- user=`eval "echo \\\$GAIM_LOGGED_OUT_SESSIONS_USER_$i"`
- dbus_session_bus_address=`eval "echo \\\$GAIM_LOGGED_OUT_SESSIONS_DBUS_$i"`
- gaim_status=`eval "echo \\\$GAIM_LOGGED_OUT_SESSIONS_STATUS_$i"`
- i=`expr $i + 1`
-
- [ -z "$user" ] && break
-
- gaim_remote_cmd="setstatus?status=$gaim_status"
- if [ -n "$GAIM_LOGIN_MESSAGE" ]; then
- gaim_remote_cmd="$gaim_remote_cmd&message=$GAIM_LOGIN_MESSAGE"
- fi
-
- vecho 2 "Logging back (to status $gaim_status) $user's Gaim using D-Bus session bus address $dbus_session_bus_address"
- DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" su "$user" -c "$gaim_remote '$gaim_remote_cmd'"
- done
-
- return 0
-}
-
-GaimOptions()
-{
- case "$1" in
- logoutgaim)
- if BoolIsOn "$1" "$2"; then
- LOGOUT_GAIM=1
- if [ -z "$GAIMLOGOUT_HOOKED" ]; then
- AddSuspendHook 19 LogoutGaim
- AddResumeHook 19 LoginGaim
- GAIMLOGOUT_HOOKED=1
- fi
- else
- LOGOUT_GAIM=0
- fi
- ;;
- gaimrestorestatus)
- if BoolIsOn "$1" "$2"; then
- GAIM_RESTORE_STATUS=1
- else
- GAIM_RESTORE_STATUS=0
- fi
- ;;
- gaimlogoutmessage)
- GAIM_LOGOUT_MESSAGE="$2"
- ;;
- gaimloginmessage)
- GAIM_LOGIN_MESSAGE="$2"
- ;;
- *)
- return 1
- ;;
- esac
-}
diff -Naur hibernate-1.99/scriptlets.d/pidgin hibernate-1.99-fixed/scriptlets.d/pidgin
--- hibernate-1.99/scriptlets.d/pidgin 1970-01-01 01:00:00.000000000 +0100
+++ hibernate-1.99-fixed/scriptlets.d/pidgin 2009-04-08 03:38:16.000000000 +0200
@@ -0,0 +1,184 @@
+# -*- sh -*-
+# vim:ft=sh:ts=8:sw=4:noet
+
+# $Id: pidgin 749 2009-04-08 01:27:17Z mendel $
+
+pidgin=$(command -v pidgin || command -v gaim)
+purple_remote=$(command -v purple-remote || command -v gaim-remote)
+
+AddConfigHandler PidginOptions
+AddConfigHelp "LogoutPidgin <boolean>" "Changes all locally running Pidgin's status to offline before suspending, and (optionally) change it back to the original status after resuming."
+AddConfigHelp "LogoutGaim <boolean>" "The same as LogoutPidgin."
+AddConfigHelp "PidginRestoreStatus <boolean>" "Changes back Pidgin's status to the original status after resuming."
+AddConfigHelp "GaimRestoreStatus <boolean>" "The same as PidginRestoreStatus."
+AddConfigHelp "PidginWorkaroundAutoAway <boolean>" "If PidginRestoreStatus is enabled and the status is 'away' at hibernation, whether to restore to 'available' status instead."
+AddConfigHelp "GaimWorkaroundAutoAway <boolean>" "The same as PidginWorkaroundAutoAway."
+AddConfigHelp "PidginLogoutMessage <string>" "Status message to set when logging out Pidgin."
+AddConfigHelp "GaimLogoutMessage <string>" "The same as PidginLogoutMessage."
+AddConfigHelp "PidginLoginMessage <string>" "Status message to set when logging in Pidgin."
+AddConfigHelp "GaimLoginMessage <string>" "The same as PidginLoginMessage."
+
+
+PidginExecuteRemoteCmd()
+{
+ local dbus_session_bus_address="$1" user="$2" command="$3"
+
+ DBUS_SESSION_BUS_ADDRESS="$dbus_session_bus_address" su "$user" -c "$purple_remote '$command'"
+}
+
+PidginGetStatus()
+{
+ local dbus_session_bus_address="$1" user="$2"
+
+ case "$purple_remote" in
+ *purple*)
+ pidgin_status=$(PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "getstatus" 2>/dev/null)
+ if [ $? != 0 ]; then
+ # purple-remote (as of 2.0.1) does not support the 'getstatus' command, so we do it manually
+ saved_status_id=$(PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "PurpleSavedstatusGetCurrent")
+ status_type=$(PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "PurpleSavedstatusGetType?saved_status=$saved_status_id")
+ pidgin_status=$(PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "PurplePrimitiveGetIdFromType?type=$status_type")
+ fi
+ ;;
+ *gaim*)
+ # gaim-remote (as of 2.0.0beta5) does not support the 'getstatus' command, so we do it manually
+ saved_status_id=$(PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "GaimSavedstatusGetCurrent")
+ status_type=$(PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "GaimSavedstatusGetType?saved_status=$saved_status_id")
+ pidgin_status=$(PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "GaimPrimitiveGetIdFromType?type=$status_type")
+ ;;
+ esac
+
+ echo "$pidgin_status"
+}
+
+LogoutPidgin()
+{
+ [ x"$LOGOUT_PIDGIN" != "x1" ] && return 0
+
+ if [ -z "$purple_remote" ] || [ ! -x "$purple_remote" ]; then
+ vecho 0 'Cannot log out Pidgin/Gaim: neither `purple-remote` nor `gaim-remote` executable found.'
+ return 0
+ fi
+
+ local pid i=0
+ for pid in `pidof $pidgin`; do
+ local user dbus_session_bus_address pidgin_status saved_status_id status_type purple_remote_cmd
+
+ user=$(get_env_var_of_process $pid USER)
+ dbus_session_bus_address=$(get_env_var_of_process $pid DBUS_SESSION_BUS_ADDRESS)
+
+ if [ -z "$user" ]; then
+ vecho 0 "Cannot log out $user's Pidgin/Gaim: cannot read USER envvar"
+ continue
+ elif [ -z "$dbus_session_bus_address" ]; then
+ vecho 0 "Cannot log out $user's Pidgin/Gaim: cannot read DBUS_SESSION_BUS_ADDRESS envvar"
+ continue
+ fi
+
+ vecho 2 "Saving status of $user's Pidgin/Gaim using D-Bus session bus address $dbus_session_bus_address"
+
+ pidgin_status=$(PidginGetStatus "$dbus_session_bus_address" "$user")
+
+ # if the status is away, probably it is caused by auto-away, so on login we choose available instead
+ if [ x"$PIDGIN_WORKAROUND_AUTOAWAY" = "x1" ]; then
+ case "$pidgin_status" in
+ [Aa]way)
+ pidgin_status=available
+ ;;
+ esac
+ fi
+
+ # using this eval-crap to be POSIX-compliant (arrays are nonstandard)
+ eval "PIDGIN_LOGGED_OUT_SESSIONS_USER_$i='$user'"
+ eval "PIDGIN_LOGGED_OUT_SESSIONS_DBUS_$i='$dbus_session_bus_address'"
+ eval "PIDGIN_LOGGED_OUT_SESSIONS_STATUS_$i='$pidgin_status'"
+ i=`expr $i + 1`
+
+ purple_remote_cmd="setstatus?status=offline"
+ if [ -n "${PIDGIN_LOGOUT_MESSAGE+empty_but_set}" ]; then
+ purple_remote_cmd="$purple_remote_cmd&message=$PIDGIN_LOGOUT_MESSAGE"
+ fi
+
+ vecho 2 "Logging out $user's Pidgin/Gaim using D-Bus session bus address $dbus_session_bus_address"
+ PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "$purple_remote_cmd"
+ done
+
+ return 0
+}
+
+LoginPidgin()
+{
+ [ x"$LOGOUT_PIDGIN" != "x1" ] && return 0
+
+ [ x"$PIDGIN_RESTORE_STATUS" != "x1" ] && return 0
+
+ if [ -z "$purple_remote" ] || [ ! -x "$purple_remote" ]; then
+ vecho 0 'Cannot log on Pidgin/Gaim: neither `purple-remote` nor `gaim-remote` found.'
+ return 0
+ fi
+
+ local i=0
+ while :; do
+ local user dbus_session_bus_address pidgin_status purple_remote_cmd
+
+ user=`eval "echo \\\$PIDGIN_LOGGED_OUT_SESSIONS_USER_$i"`
+ dbus_session_bus_address=`eval "echo \\\$PIDGIN_LOGGED_OUT_SESSIONS_DBUS_$i"`
+ pidgin_status=`eval "echo \\\$PIDGIN_LOGGED_OUT_SESSIONS_STATUS_$i"`
+ i=`expr $i + 1`
+
+ [ -z "$user" ] && break
+
+ purple_remote_cmd="setstatus?status=$pidgin_status"
+ if [ -n "${PIDGIN_LOGIN_MESSAGE+empty_but_set}" ]; then
+ purple_remote_cmd="$purple_remote_cmd&message=$PIDGIN_LOGIN_MESSAGE"
+ fi
+
+ vecho 2 "Logging back (to status $pidgin_status) $user's Pidgin/Gaim using D-Bus session bus address $dbus_session_bus_address"
+ PidginExecuteRemoteCmd "$dbus_session_bus_address" "$user" "$purple_remote_cmd"
+ done
+
+ return 0
+}
+
+PidginOptions()
+{
+ case "$1" in
+ logoutpidgin|logoutgaim)
+ if BoolIsOn "$1" "$2"; then
+ LOGOUT_PIDGIN=1
+ if [ -z "$PIDGINLOGOUT_HOOKED" ]; then
+ AddSuspendHook 19 LogoutPidgin
+ AddResumeHook 19 LoginPidgin
+ PIDGINLOGOUT_HOOKED=1
+ fi
+ else
+ LOGOUT_PIDGIN=0
+ fi
+ ;;
+ pidginrestorestatus|gaimrestorestatus)
+ if BoolIsOn "$1" "$2"; then
+ PIDGIN_RESTORE_STATUS=1
+ else
+ PIDGIN_RESTORE_STATUS=0
+ fi
+ ;;
+ pidginworkaroundautoaway|gaimworkaroundautoaway)
+ if BoolIsOn "$1" "$2"; then
+ PIDGIN_WORKAROUND_AUTOAWAY=1
+ else
+ PIDGIN_WORKAROUND_AUTOAWAY=0
+ fi
+ ;;
+ pidginlogoutmessage|gaimlogoutmessage)
+ shift
+ PIDGIN_LOGOUT_MESSAGE="$*"
+ ;;
+ pidginloginmessage|gaimloginmessage)
+ shift
+ PIDGIN_LOGIN_MESSAGE="$*"
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+}