1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
# -*- 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
}
|