Tkabber

Check-in [848d6d39da]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: * roster_nested.tcl: Support for nested roster groups (JEP-0083) (currently only "::" separator supported) * roster.tcl: Likewise
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 848d6d39dad13c7ed0d16d4bd4822be60e3c31b6
User & Date: aleksey 2003-05-18 20:09:21.000
Context
2003-05-20
13:37
* xmppmime.tcl: Support for JEP-0081 (XMPP/Jabber MIME Type) (not well tested yet) * tkabber.tcl: Support for "-mime file" option for loading of mime file check-in: 004b79a1d5 user: aleksey tags: trunk
2003-05-18
20:09
* roster_nested.tcl: Support for nested roster groups (JEP-0083) (currently only "::" separator supported) * roster.tcl: Likewise check-in: 848d6d39da user: aleksey tags: trunk
16:41
* roster_nested.tcl: Support for nested roster groups (JEP-0083) (currently only "::" separator supported) * roster.tcl: Likewise check-in: 2087ea07a8 user: aleksey tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Added roster_nested.tcl.








































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# $Id$

# JEP-83 (Nested Roster Groups) support


namespace eval roster {
    custom::defvar options(nested) 0 \
	[::msgcat::mc "Enable nested roster groups."] \
	-type boolean -group Roster
}

proc roster::redraw_nested {} {
    variable roster
    variable config
    variable show_only_online
    variable aliases
    variable use_aliases
    variable show_transport_user_icons
    global rostericon

    clear .roster 0
    
    set groups {}

    set undef_group_name [::msgcat::mc Undefined]

    if {$use_aliases} {
	foreach jid [array names aliases] {
	    foreach alias $aliases($jid) {
		set ignore_jid($alias) ""
	    }
	}
    }

    foreach jid $roster(jids) {
	if {[info exists ignore_jid($jid)]} continue
	if {![lempty $roster(group,$jid)]} {
	    foreach group $roster(group,$jid) {
		set sgroup [::textutil::splitx $group "::"]
		lappend groups $sgroup
	        lappend jidsingroup($sgroup) $jid
		set deep [expr {[llength $sgroup] - 1}]
		for {set i 0} {$i < $deep} {incr i} {
		    set sgr [lrange $sgroup 0 $i]
		    lappend groups $sgr
		    lappend jidsundergroup($sgr) $jid
		    if {![info exists jidsingroup($sgr)]} {
			set jidsingroup($sgr) {}
		    }
		}
		if {![info exists jidsundergroup($sgroup)]} {
		    set jidsundergroup($sgroup) {}
		}
	    }
	} else {
	    set sgroup [list $undef_group_name]
	    lappend jidsingroup($sgroup) $jid
	    lappend groups $sgroup
	    if {![info exists jidsundergroup($sgroup)]} {
		set jidsundergroup($sgroup) {}
	    }
	}
    }
    set groups [lsort -unique -dictionary $groups]
    foreach group $groups {
	set jidsingroup($group) [lrmdups $jidsingroup($group)]
	if {![info exists roster(collapsed,$group)]} {
	    set roster(collapsed,$group) 0
	}
	set indent [expr {[llength $group] - 1}]
	set collapsed 0
	for {set i 0} {$i < $indent} {incr i} {
	    set sgr [lrange $group 0 $i]
	    if {$roster(collapsed,$sgr)} {
		set collapsed 1
		break
	    }
	}
	if {$collapsed} continue
	set group_name "[lindex $group end]"
	set online 0
	set users 0
	set not_users 0
	set sub_jids 0
	foreach jid [concat $jidsingroup($group) $jidsundergroup($group)] {
	    if {$roster(isuser,$jid)} {
		incr users
		set status [get_user_aliases_status $jid]
		set jstat($jid) $status
		if {$status != "unavailable"} {
		    incr online
		    set useronline($jid) 1
		} else {
		    set useronline($jid) 0
		}
	    } else {
		incr not_users
	    }
	}
	if {!$show_only_online || $online + $not_users + $sub_jids > 0} {
	    if {$users} {
		addline_nested .roster group \
		    "$group_name ($online/$users)" $group $indent
	    } else {
		addline_nested .roster group \
		    $group_name $group $indent
	    }
	}
	if {!$roster(collapsed,$group)} {
	    set jid_names {}
	    foreach jid $jidsingroup($group) {
		lappend jid_names [list $jid [get_label $jid]]
	    }
	    set jid_names [lsort -index 1 -dictionary $jid_names]
	    foreach jid_name $jid_names {
		lassign $jid_name jid name
		if {!$show_only_online || \
			![info exists useronline($jid)] || $useronline($jid)} {
		    lassign [get_category_and_subtype $jid] category type
		    set jids [get_jids_of_user $jid]
		    set numjids [llength $jids]
		    if {($numjids > 1) && ($config(subitemtype) > 0) && \
			    $category == "user"} {
		    	if {$config(subitemtype) & 1} {
			    if {$category == "conference"} {
			    	set numjids [expr {$numjids - 1}]
			    }
			    addline_nested .roster jid "$name ($numjids)" \
				$jid $indent $jids
			} else {
			    addline_nested .roster jid "$name" \
				$jid $indent $jids
			}
			changeicon .roster $jid [get_jid_icon $jid]
			changeforeground .roster $jid [get_jid_foreground $jid]

			if {[info exists roster(collapsed,$jid)] && \
				!$roster(collapsed,$jid)} {
			    foreach subjid $jids {
				set subjid_resource [resource_from_jid $subjid]
				if {$subjid_resource != ""} {
				    addline_nested .roster jid2 \
					$subjid_resource $subjid \
					$indent \
					[list $subjid]
				    changeicon .roster \
					$subjid [get_jid_icon $subjid]
				    changeforeground .roster \
					$subjid [get_jid_foreground $subjid]
				}
			    }
			}
		    } else {
			if {$numjids <= 1 && $category == "user" && \
				!$show_transport_user_icons} {
			    #set user [node_and_server_from_jid $jid]
			    set status $jstat($jid)

			    if {([cequal $roster(subsc,$jid) from] || \
				     [cequal $roster(subsc,$jid) none]) && \
				    $status == "unavailable"} {
				set status stalker
			    }
			    addline_nested .roster jid $name $jid $indent \
				$jids \
				$rostericon(user,$status) \
				$config(${status}foreground)
			} else {
			    addline_nested .roster jid $name $jid $indent $jids
			    changeicon .roster $jid [get_jid_icon $jid]
			    changeforeground .roster $jid [get_jid_foreground $jid]
			}
		    }
		}
	    }
	}
    }
    #debugmsg roster [array get roster collapsed*]
    update_scrollregion .roster
}



proc roster::addline_nested {w type text jid indent {jids {}} {icon ""} {foreground ""}} {
    global font
    global rostericon
    variable roster
    variable config
    variable aliases
    variable use_aliases

    set c $w.canvas

    set tag [jid_to_tag $jid]

    set ypad 1
    set linespace [font metric $font -linespace]
    set lineheight [expr {$linespace + $ypad}]

    set uy $roster($w,ypos)
    set ly [expr {$uy + $lineheight + $config(textuppad) + \
		      $config(textdownpad)}]

    set levindent [expr $config(groupindent)*$indent]

    if {$type == "group" && [info exists roster(collapsed,$jid)] && \
	    $roster(collapsed,$jid)} {
	set rfill $config(groupcfill)
    } else {
	set rfill $config(${type}fill)
    }

    $c create rectangle [expr {1 + $levindent}] $uy 10000 $ly -fill $rfill \
	-outline $config(${type}border) \
	-tags [list jid$tag $type rect]


    if {[cequal $type jid]} {
	set isuser \
	    [expr {![info exists roster(isuser,$jid)] || $roster(isuser,$jid)}]

	set y [expr {($uy + $ly)/2}]
	set x [expr {$config(iconindent) + $levindent}]

	if {$icon == ""} {
	    $c create image $x $y -image $rostericon(user,unavailable) \
		-anchor w \
		-tags [list jid$tag $type icon]
	} else {
	    $c create image $x $y -image $icon \
		-anchor w \
		-tags [list jid$tag $type icon]
	}
	#set jids [get_jids_of_user $jid]
	if {[llength $jids] > 1} {
	    if {[info exists roster(collapsed,$jid)] && !$roster(collapsed,$jid)} {
		set jid_state opened
	    } else {
		set roster(collapsed,$jid) 1
		set jid_state closed
	    }
	    if {$config(subitemtype) > 0} {
		if {($config(subitemtype) & 2) && $isuser} {
		    set y [expr {($uy + $ly)/2}]
		    set x [expr {$config(subgroupiconindent) + $levindent}]
		    $c create image $x $y -image $rostericon(group,$jid_state) -anchor w \
			-tags [list jid$tag $type group]
		}
	    }
	} else {
	    set roster(collapsed,$jid) 1
	}
    } elseif {[cequal $type jid2]} {
	#set jids [get_jids_of_user $jid]
	set y [expr {($uy + $ly)/2}]
	set x [expr {$config(subiconindent) + $levindent}]

	$c create image $x $y -image $rostericon(user,unavailable) -anchor w \
	    -tags [list jid$tag $type icon]
    } elseif {[cequal $type group]} {
	set y [expr {($uy + $ly)/2}]
	set x [expr {$config(groupiconindent) + $levindent}]
	if {[info exists roster(collapsed,$jid)] && $roster(collapsed,$jid)} {
	    set group_state closed
	} else {
	    set group_state opened
	}
	$c create image $x $y -image $rostericon(group,$group_state) -anchor w \
	    -tags [list jid$tag $type icon]
    }

    if {([cequal $type jid]) && ($config(subitemtype) > 0) && ($config(subitemtype) & 2)} {
	#set jids [get_jids_of_user $jid]
	if {$isuser && ([llength $jids] > 1)} {
	    set x [expr {$config(jidmultindent) + $levindent}]
	} else {
	    set x [expr {$config(jidindent) + $levindent}]
	}
    } else {
	set x [expr {$config(${type}indent) + $levindent}]
    }
    incr uy $config(textuppad)

    if {$foreground == ""} {
	if {[cequal $type jid] || [cequal $type jid2]} {
	    set foreground $config(unavailableforeground)
	} else {
	    set foreground $config(foreground)
	}
    }
    $c create text $x $uy -text $text -anchor nw -font $font \
	-fill $foreground -tags [list jid$tag $type text]

    set roster($w,width) [max $roster($w,width) \
			      [expr {$x + [font measure $font $text]}]]


    $c bind jid$tag <Any-Enter> \
	[list $c itemconfig jid$tag&&rect -fill $config(${type}hlfill)]
    $c bind jid$tag <Any-Leave> \
	[list $c itemconfig jid$tag&&rect -fill $rfill]

    set doubledjid  [double% $jid]


    $c bind jid$tag&&jid <Double-Button-1> \
	[list roster::jid_doubleclick $doubledjid]
    $c bind jid$tag&&jid2 <Double-Button-1> \
	[list roster::jid_doubleclick $doubledjid]

    set roster($w,ypos) [expr {$ly + $config(linepad)}]

    if {[cequal $type jid] || [cequal $type jid2]} {
	if {[llength $jids] > 0} {
	    set doubledjids [double% $jids]
	    $c bind jid$tag <Any-Enter> \
		+[list eval balloon::set_text \
		    \[roster::jids_popup_info [list $doubledjids]\]]

	    $c bind jid$tag <Any-Motion> \
		[list eval balloon::on_mouse_move \
		    \[roster::jids_popup_info [list $doubledjids]\] %X %Y]
	} else {
	    set jids [list $jid]
	    if {$use_aliases && [info exists aliases($jid)]} {
		set jids [concat $jids $aliases($jid)]
	    }
	    set doubledjids [double% $jids]
	    $c bind jid$tag <Any-Enter> \
		+[list eval balloon::set_text \
		    \[roster::jids_popup_info [list $doubledjids]\]]

	    $c bind jid$tag <Any-Motion> \
		[list eval balloon::on_mouse_move \
		     \[roster::jids_popup_info [list $doubledjids]\] %X %Y]
	}
	
	$c bind jid$tag <Any-Leave> {+
	    balloon::destroy
	}
	
	if {![cequal $roster($w,popup) {}]} {
	    $c bind jid$tag <3> [list $roster($w,popup) $doubledjid]
	}
    } else {
	if {$w == ".roster"} {
	    $c bind jid$tag&&group <Button-1> \
		[list roster::group_doubleclick $doubledjid]
	}

	if {![cequal $roster($w,grouppopup) {}]} {
	    $c bind jid$tag&&group <3> \
		[list $roster($w,grouppopup) $doubledjid]
	}
    }

    if {[cequal $type jid]} {
	if {$isuser \
		&& ([llength $jids] > 1)} {
	    if {$w == ".roster"} {
		$c bind jid$tag <Button-1> \
		    [list roster::user_singleclick $jid]
	    }
	}
    }
    #$c configure -scrollregion [list 0 0 $roster($w,width) $roster($w,ypos)]
}