Hello together,

I wrote a wrapper script for kdesktop_lock to enable gajim to change
it's status to away upon locking the screen manually. I was inspired by
kopete's behaviour switching it's status to away upon locking the
screen. This script might be useful for all kde-users. You may put it
into the wiki just like the gajim2gaim.py script.

Greetings, Nico.

Nico Gulden
GnuPG fingerprint: BBC1 D649 BBA7 C1E4 97BC  30F3 FF4C E2F1 B94B 8FCB
Überall ist das Unheil der Alkohol.
                -- Leo Nikolajewitsch Tolstoi (Tagebücher 1889)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2007, Nico Gulden
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

This script is a wrapper for kdedesktop_lock to enable auto-status for gajim.
It switches the status to away on session locking and restores the previous status
for each account.

__author__ = "Nico Gulden <[EMAIL PROTECTED]>"

import sys
import commands

def whereis(command):
	"""Return the correct path to command using the whereis command."""
	return commands.getoutput('whereis %s' % command).split(' ')[1]

# Please set the path to kdesktop_lock
GAJIM_REMOTE_BIN = whereis('gajim-remote')

def get_status():
	"""Find out all accounts in gajim and save the current status. 
	Output: dictionary with account:status mapping."""
	status = {}
	accounts = commands.getoutput("%s list_accounts" % GAJIM_REMOTE_BIN).split()
	for a in accounts:
		status[a] = commands.getoutput("%s get_status %s" % (GAJIM_REMOTE_BIN, a))
	return status

def change_status(status, status_from, status_to):
	"""Change the status for all accounts matching the status given with status_from 
	and change them to the status give in status_to."""

	print "Change status: %s --> %s" % (status_from, status_to)

	for a in status.keys():
		if (status[a] == status_from):
			(exitstatus, outtext) = commands.getstatusoutput("%s change_status %s 'Abwesend' %s" % 
				(GAJIM_REMOTE_BIN, status_to, a))

if __name__ == '__main__':
		print """You need to configure this script. Find the binary kdedesktop_lock and 
move it to kdesktop_lock.kde. Copy %s to /usr/local/bin and make a symlink 
from the kdesktop_lock path to /usr/local/bin/%s and name it kdesktop_lock.
		""" % (sys.argv[0],sys.argv[0])

	options = " ".join(sys.argv[1:])
	status = get_status()
	change_status(status, status_from='online', status_to='away')
	commands.getoutput("%s %s" % (KDEDESKTOP_LOCK_BIN, options))
	change_status(status, status_from='away', status_to='online')

Attachment: signature.asc
Description: Digital signature

Gajim-devel mailing list

Reply via email to