[Tkabber-dev] r134 - in trunk/plugins: . filter_add

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Sep 28 20:19:21 MSD 2008


Author: archimed
Date: 2008-09-28 20:19:21 +0400 (Sun, 28 Sep 2008)
New Revision: 134

Added:
   trunk/plugins/filter_add/
   trunk/plugins/filter_add/AUTHORS
   trunk/plugins/filter_add/filter_add.tcl
   trunk/plugins/filter_add/iroster.tcl.diff
   trunk/plugins/filter_add/license.terms
   trunk/plugins/filter_add/readme.txt
   trunk/plugins/filter_add/version
Log:
Filter_add plugin adds option to show offline contacts in filter mode even if option "show_only_online" is set to 1. You can toggle showing offline contacts in filter mode by pressing "Toggle showing offline users" on toolbar when your filter string is not empty.

Added: trunk/plugins/filter_add/AUTHORS
===================================================================
--- trunk/plugins/filter_add/AUTHORS	                        (rev 0)
+++ trunk/plugins/filter_add/AUTHORS	2008-09-28 16:19:21 UTC (rev 134)
@@ -0,0 +1 @@
+Rakhmanin Ruslan <rakhmaninr at mail.ru>
\ No newline at end of file

Added: trunk/plugins/filter_add/filter_add.tcl
===================================================================
--- trunk/plugins/filter_add/filter_add.tcl	                        (rev 0)
+++ trunk/plugins/filter_add/filter_add.tcl	2008-09-28 16:19:21 UTC (rev 134)
@@ -0,0 +1,374 @@
+#  This plugin adds option to show offline contacts in filter mode
+#even if option "show_only_online" is set to 1.
+#  You can toggle showing offline contacts in filter mode by pressing
+#"Toggle showing offline users" on toolbar when your filter string is not empty.
+#  It is a dirty patch for iroster.tcl so use it for testing only.
+# Rakhmanin Ruslan <rakhmaninr at mail.ru>
+
+
+namespace eval ::ifacetk::roster {
+    custom::defvar show_only_online_in_filter_mode 0 \
+	[::msgcat::mc "Show only online users in roster when filter is present."] \
+	-type boolean -group Roster \
+	-command [namespace current]::redraw_after_idle
+}
+
+proc ::ifacetk::roster::switch_only_online {args} {
+    variable show_only_online
+    variable use_filter
+    variable options
+    variable show_only_online_in_filter_mode
+    
+    if { ( $options(use_filter) && $options(filter) != "" ) } {
+	set show_only_online_in_filter_mode [expr {!$show_only_online_in_filter_mode}]
+    } else {
+	set show_only_online [expr {!$show_only_online}]
+    }
+}
+
+proc ::ifacetk::roster::redraw {} {
+    upvar #0 roster::aliases aliases
+    variable roster
+    variable options
+    variable config
+    variable show_only_online
+    variable use_aliases
+    variable show_transport_user_icons
+    variable undef_group_name
+    variable chats_group_name
+    variable own_resources_group_name
+    variable collapsed
+    variable show_offline
+    variable show_only_online_in_filter_mode
+
+    clear .roster 0
+    
+    set connections [jlib::connections]
+    switch -- [llength $connections] {
+	0 {
+	    update_scrollregion .roster
+	    return
+	}
+	1 {
+	    set draw_connection 0
+	    set gindent 0
+	}
+	default {
+	    set draw_connection 1
+	    set gindent 0
+	}
+    }
+
+    foreach connid $connections {
+        # Suppress display of aliases, but not if "main" JID is unavailable.
+        # If main JID is unavailable, perform reordering of aliases.
+        # Suppression means that aliases wont get a line in the roster for
+	# themselves, but will be places as children under "main" JID element
+	if {$use_aliases} {
+	    foreach jid [array names aliases] {
+		set status [get_user_status $connid $jid]
+		if {$status == "unavailable"} {
+		    # Need to look an alternative for main JID,
+		    # which is offline.
+		    set jidstatus [get_user_aliases_status_and_jid $connid $jid]
+                    switch -- [lindex $jidstatus 1] {
+                        unavailable {
+                            # Main JID and all aliases are unavailable.
+			    # Will skip them all
+                        }
+                        default {
+                            # Make "most available" JID the main JID,
+			    # put main JID into list of aliases
+                            set new_jid [lindex $jidstatus 0]
+                            set idx [lsearch -exact $aliases($jid) $new_jid]
+                            set new_aliases [lreplace $aliases($jid) $idx $idx]
+                            # If this already have some aliases defined,
+			    # merge them in
+                            if {[info exists aliases($new_jid)]} {
+                                set new_aliases \
+				    [lsort -unique -dictionary -index 0 \
+					 [lappend new_aliases \
+					      $aliases($new_jid)]]
+                            }
+                            set aliases($new_jid) $new_aliases
+                            # Remove aliases of old "main" JID
+                            set aliases($jid) {}
+                        }
+                    }
+                }
+                # Main JID is online, suppress alternatives
+                foreach alias $aliases($jid) {
+                    set ignore_jid($alias) ""
+                }
+            }
+        }
+        
+	if {$draw_connection} {
+	    if {![info exists roster(collapsed,[list connid $connid])]} {
+		set roster(collapsed,[list connid $connid]) 0
+	    }
+	    addline .roster connection \
+		[jlib::connection_jid $connid] \
+		[list connid $connid] [list connid $connid] 0
+	    
+	    if {$roster(collapsed,[list connid $connid])} {
+		continue
+	    }
+	}
+
+	if {[lempty [::roster::get_jids $connid]]} {
+	    continue
+	}
+	set bare_jid [jlib::connection_bare_jid $connid]
+	set groups {}
+	array unset jidsingroup
+	array unset jidsundergroup
+	array unset groupsundergroup
+	foreach jid [::roster::get_jids $connid] {
+	    if {$options(use_filter) && $options(filter) != ""} {
+		if {[string first [string tolower $options(filter)] \
+				  [string tolower [::roster::get_label $connid $jid]]] < 0} {
+		    if {!$options(match_jids) || \
+			    [string first [string tolower $options(filter)] \
+					  [string tolower $jid]] < 0} {
+			continue
+		    }
+		}
+	    }
+	    if {[info exists ignore_jid($jid)]} continue
+	    set jid_groups [::roster::itemconfig $connid $jid -group]
+	    if {![lempty $jid_groups]} {
+		foreach group $jid_groups {
+		    if {$options(nested)} {
+			set sgroup [msplit $group $options(nested_delimiter)]
+		    } else {
+			set sgroup [list $group]
+		    }
+		    lappend groups [list [join $sgroup "\u0000"] $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 [list [join $sgr "\u0000"] $sgr]
+			lappend jidsundergroup($sgr) $jid
+			lappend groupsundergroup($sgr) $sgroup
+			if {![info exists jidsingroup($sgr)]} {
+			    set jidsingroup($sgr) {}
+			}
+		    }
+		    if {![info exists jidsundergroup($sgroup)]} {
+			set jidsundergroup($sgroup) {}
+		    }
+		    if {![info exists groupsundergroup($sgroup)]} {
+			set groupsundergroup($sgroup) {}
+		    }
+		}
+	    } else {
+		set sgroup [list $undef_group_name]
+		lappend jidsingroup($sgroup) $jid
+		set groupsundergroup($sgroup) {}
+		if {![info exists jidsundergroup($sgroup)]} {
+		    set jidsundergroup($sgroup) {}
+		}
+	    }
+	}
+	set groups [lsort -unique -dictionary -index 0 $groups]
+	set ugroup [list $undef_group_name]
+	if {[info exists jidsingroup($ugroup)]} {
+	    lappend groups [list [join $ugroup "\u0000"] $ugroup]
+	}
+	if {$options(chats_group)} {
+	    set cgroup [list $chats_group_name]
+	    foreach chatid [chat::opened $connid] {
+		set jid [chat::get_jid $chatid]
+		lappend jidsingroup($cgroup) $jid
+		if {[cequal [roster::itemconfig $connid $jid -isuser] ""]} {
+		    roster::itemconfig $connid $jid \
+			-name [chat::get_nick $connid $jid chat]
+		    roster::itemconfig $connid $jid -subsc none
+		}
+	    }
+	    if {[info exists jidsingroup($cgroup)]} {
+		set groups [linsert $groups 0 [list [join $cgroup "\u0000"] $cgroup]]
+	    }
+	    set groupsundergroup($cgroup) {}
+	    set jidsundergroup($cgroup) {}
+	}
+	if {$options(show_own_resources)} {
+	    set cgroup [list $own_resources_group_name]
+	    set jid [tolower_node_and_domain [::jlib::connection_bare_jid $connid]]
+	    set jidsingroup($cgroup) [list $jid]
+	    set groups [linsert $groups 0 [list [join $cgroup "\u0000"] $cgroup]]
+	    roster::itemconfig $connid $jid -subsc both
+	    set groupsundergroup($cgroup) {}
+	    set jidsundergroup($cgroup) {}
+	}
+	foreach group $groups {
+	    set group [lindex $group 1]
+	    set gid [list $connid $group]
+	    if {![info exists roster(show_offline,$gid)]} {
+		if {$options(nested)} {
+		    set gname [join $group $options(nested_delimiter)]
+		} else {
+		    set gname $group
+		}
+		if {[info exists show_offline($bare_jid,$gname)]} {
+		    set roster(show_offline,$gid) $show_offline($bare_jid,$gname)
+		} else {
+		    set roster(show_offline,$gid) 0
+		}
+	    }
+	}
+	foreach group $groups {
+	    set group [lindex $group 1]
+	    set jidsingroup($group) [lrmdups $jidsingroup($group)]
+	    set groupsundergroup($group) [lrmdups $groupsundergroup($group)]
+	    set gid [list $connid $group]
+	    if {![info exists roster(collapsed,$gid)]} {
+		if {$options(nested)} {
+		    set gname [join $group $options(nested_delimiter)]
+		} else {
+		    set gname $group
+		}
+		if {[info exists collapsed($bare_jid,$gname)]} {
+		    set roster(collapsed,$gid) $collapsed($bare_jid,$gname)
+		} else {
+		    set roster(collapsed,$gid) 0
+		}
+	    }
+	    set indent [expr {[llength $group] - 1}]
+	    set collapse 0
+	    set show_offline_users 0
+	    set show_offline_group 0
+	    foreach undergroup $groupsundergroup($group) {
+		if {$roster(show_offline,[list $connid $undergroup])} {
+		    set show_offline_group 1
+		    break
+		}
+	    }
+	    for {set i 0} {$i < $indent} {incr i} {
+		set sgr [list $connid [lrange $group 0 $i]]
+		if {$roster(collapsed,$sgr)} {
+		    set collapse 1
+		    break
+		}
+		if {$roster(show_offline,$sgr)} {
+		    set show_offline_users 1
+		    set show_offline_group 1
+		}
+	    }
+	    incr indent $gindent
+	    if {$collapse} 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::itemconfig $connid $jid -isuser]} {
+		    incr users
+		    set status [get_user_aliases_status $connid $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 || $show_offline_group || \
+		    $roster(show_offline,$gid) || \
+		    ( $show_only_online_in_filter_mode && $options(use_filter) && $options(filter) != "" ) || \
+		    $online + $not_users + $sub_jids > 0} {
+		if {$users} {
+		    addline .roster group "$group_name ($online/$users)" \
+			$gid $gid $indent
+		} else {
+		    addline .roster group $group_name \
+			$gid $gid $indent
+		}
+	    }
+	    if {!$roster(collapsed,$gid)} {
+		set jid_names {}
+		foreach jid $jidsingroup($group) {
+		    lappend jid_names [list $jid [::roster::get_label $connid $jid]]
+		}
+		set jid_names [lsort -index 1 -dictionary $jid_names]
+		foreach jid_name $jid_names {
+		    lassign $jid_name jid name
+		    if {$options(chats_group)} {
+			set chatid [chat::chatid $connid $jid]
+			if {[info exists chat::chats(messages,$chatid)] && \
+				$chat::chats(messages,$chatid) > 0} {
+			    append name " \[$chat::chats(messages,$chatid)\]"
+			}
+		    }
+		    set cjid [list $connid $jid]
+		    if {!$show_only_online || $show_offline_users || $roster(show_offline,$gid) || \
+			( $show_only_online_in_filter_mode && $options(use_filter) && $options(filter) != "" ) || \
+			    ![info exists useronline($jid)] || $useronline($jid)} {
+			lassign [::roster::get_category_and_subtype $connid $jid] category type
+			set jids [get_jids_of_user $connid $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}]
+				}
+				set label "$name ($numjids)"
+			    } else {
+				set label "$name"
+			    }
+			    addline .roster jid $label $cjid $gid $indent $jids
+			    changeicon .roster $cjid [get_jid_icon $connid $jid]
+			    changeforeground .roster $cjid [get_jid_foreground $connid $jid]
+			    
+			    if {!$roster(collapsed,$cjid)} {
+				foreach subjid $jids {
+				    set subjid_resource [resource_from_jid $subjid]
+				    if {$subjid_resource != ""} {
+					addline .roster jid2 \
+					    $subjid_resource [list $connid $subjid] \
+					    $gid $indent \
+					    [list $subjid]
+					changeicon .roster \
+					    [list $connid $subjid] [get_jid_icon $connid $subjid]
+					changeforeground .roster \
+					    [list $connid $subjid] [get_jid_foreground $connid $subjid]
+				    }
+				}
+			    }
+			} else {
+			    if {$numjids <= 1 && $category == "user" && \
+				    !$show_transport_user_icons} {
+				if {[info exists jstat($jid)]} {
+				    set status $jstat($jid)
+				} else {
+				    set status [get_user_aliases_status $connid $jid]
+				}
+				set subsc [::roster::itemconfig $connid $jid -subsc]
+				if {([cequal $subsc from] || [cequal $subsc none]) && \
+					$status == "unavailable"} {
+				    set status unsubscribed
+				}
+				addline .roster jid $name $cjid $gid $indent \
+				    $jids \
+				    roster/user/$status \
+				    $config(${status}foreground)
+			    } else {
+				addline .roster jid $name $cjid $gid $indent $jids
+				changeicon .roster $cjid [get_jid_icon $connid $jid]
+				changeforeground .roster $cjid [get_jid_foreground $connid $jid]
+			    }
+			}
+		    }
+		}
+	    }
+	}
+    }
+    update_scrollregion .roster
+}

Added: trunk/plugins/filter_add/iroster.tcl.diff
===================================================================
--- trunk/plugins/filter_add/iroster.tcl.diff	                        (rev 0)
+++ trunk/plugins/filter_add/iroster.tcl.diff	2008-09-28 16:19:21 UTC (rev 134)
@@ -0,0 +1,26 @@
+56d55
+< puts [namespace current]
+65a65,68
+>     custom::defvar show_only_online_in_filter_mode 0 \
+> 	[::msgcat::mc "Show only online users in roster when filter is present."] \
+> 	-type boolean -group Roster \
+> 	-command [namespace current]::redraw_after_idle
+291a295
+>     variable show_only_online_in_filter_mode
+532a537
+> 		    ( $show_only_online_in_filter_mode && $options(use_filter) && $options(filter) != "" ) || \
+558a564
+> 			( $show_only_online_in_filter_mode && $options(use_filter) && $options(filter) != "" ) || \
+1294,1295c1300,1308
+< 
+<     set show_only_online [expr {!$show_only_online}]
+---
+>     variable use_filter
+>     variable options
+>     variable show_only_online_in_filter_mode
+>     
+>     if { ( $options(use_filter) && $options(filter) != "" ) } {
+> 	set show_only_online_in_filter_mode [expr {!$show_only_online_in_filter_mode}]
+>     } else {
+> 	set show_only_online [expr {!$show_only_online}]
+>     }

Added: trunk/plugins/filter_add/license.terms
===================================================================
--- trunk/plugins/filter_add/license.terms	                        (rev 0)
+++ trunk/plugins/filter_add/license.terms	2008-09-28 16:19:21 UTC (rev 134)
@@ -0,0 +1,19 @@
+Copyright (c) 2008 Rakhmanin Ruslan <rakhmaninr at mail.ru>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.

Added: trunk/plugins/filter_add/readme.txt
===================================================================
--- trunk/plugins/filter_add/readme.txt	                        (rev 0)
+++ trunk/plugins/filter_add/readme.txt	2008-09-28 16:19:21 UTC (rev 134)
@@ -0,0 +1,2 @@
+This plugin adds option to show offline contacts in filter mode even if option "show_only_online" is set to 1. You can toggle showing offline contacts in filter mode by pressing "Toggle showing offline users" on toolbar when your filter string is not empty.
+It is a dirty patch for iroster.tcl so use it for testing only.

Added: trunk/plugins/filter_add/version
===================================================================
--- trunk/plugins/filter_add/version	                        (rev 0)
+++ trunk/plugins/filter_add/version	2008-09-28 16:19:21 UTC (rev 134)
@@ -0,0 +1,2 @@
+2008-sep-28
+ver 0.1
\ No newline at end of file



More information about the Tkabber-dev mailing list