1# $Id$
2
3# KDE tray icon support.
4# Requires Tk_Theme package
5# (http://tkabber.jabber.ru/files/other/Tk_Theme-23.tgz)
6
7##########################################################################
8
9if {![cequal $::interface tk]} return
10
11if {[catch { package require Tk_Theme }]} return
12
13##########################################################################
14
15namespace eval dockingtray {
16    variable s2p
17    foreach {k v} [list available   available      \
18			away        away \
19			chat        chat \
20			dnd         dnd  \
21			xa          xa   \
22		        unavailable unavailable    \
23		        invisible   invisible      \
24		        blank       blank          \
25			message1    message-server \
26			message2    message        \
27			message3    message-personal] {
28        set s2p($k) docking/$v
29    }
30
31    variable options
32
33    custom::defvar options(enable) 1 \
34	[::msgcat::mc "Enable KDE tray icon."] \
35	-group Systray -type boolean \
36	-command [namespace code enable_disable]
37}
38
39##########################################################################
40
41proc dockingtray::enable_disable {args} {
42    variable options
43
44    set icon .dockingtray
45
46    if {$options(enable) && ![winfo exists $icon]} {
47	ifacetk::systray::create $icon \
48	    -createcommand [namespace code create] \
49	    -configurecommand [namespace code configure] \
50	    -destroycommand [namespace code destroy]
51    } elseif {!$options(enable) && [winfo exists $icon]} {
52	ifacetk::systray::destroy $icon
53    }
54}
55
56hook::add finload_hook [namespace current]::dockingtray::enable_disable
57
58##########################################################################
59
60proc dockingtray::create {icon} {
61    variable s2p
62
63    set mb $icon.mb
64
65    theme:frame $icon -kdesystray -class TkabberIcon
66
67    label $mb -borderwidth 0 -image $s2p(unavailable) \
68	      -highlightthickness 0 -padx 0 -pady 0
69    pack $mb
70
71    set m [ifacetk::systray::popupmenu $icon.menu]
72
73    bind $mb <ButtonRelease-1> ifacetk::systray::restore
74    bind $mb <<PasteSelection>> ifacetk::systray::withdraw
75    bind $mb <<ContextMenu>> [list tk_popup [double% $m] %X %Y]
76    balloon::setup $icon -command [list ifacetk::systray::balloon $icon]
77}
78
79##########################################################################
80
81proc dockingtray::configure {icon status} {
82    variable s2p
83
84    if {![cequal $icon ""] && [winfo exists $icon]} {
85	$icon.mb configure -image $s2p($status)
86    }
87}
88
89##########################################################################
90
91proc dockingtray::destroy {icon} {
92    if {![cequal $icon ""] && [winfo exists $icon]} {
93	::destroy $icon
94    }
95}
96
97##########################################################################
98
99