[Tkabber-dev] r1675 - in trunk/tkabber: . ifacetk plugins/roster

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Feb 20 14:11:09 MSK 2009


Author: sergei
Date: 2009-02-20 14:11:09 +0300 (Fri, 20 Feb 2009)
New Revision: 1675

Added:
   trunk/tkabber/plugins/roster/bkup_metacontacts.tcl
Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/ifacetk/iface.tcl
   trunk/tkabber/ifacetk/iroster.tcl
   trunk/tkabber/plugins.tcl
   trunk/tkabber/plugins/roster/backup.tcl
   trunk/tkabber/plugins/roster/bkup_annotations.tcl
   trunk/tkabber/plugins/roster/bkup_conferences.tcl
   trunk/tkabber/presence.tcl
Log:
	* presence.tcl: Fixed sending custom presence to a conference.

	* ifacetk/iroster.tcl: Fixed metacontact label positioning when group
	  close/open mark should be displayed.

	* plugins.tcl: Remove recognizing preload.tcl as a plugin preload file
	  and added a procedure which checks if the requested plugin is already
	  registered.

	* ifacetk/iface.tcl, plugins/roster/backup.tcl,
	  plugins/roster/bkup_annotations.tcl,
	  plugins/roster/bkup_conferences.tcl: Adapted roster import/export
	  procedures to changes in corresponding modules (moving part of the
	  functionality to TclXMPP).

	* plugins/roster/bkup_metacontacts.tcl: Added plugin for exporting
	  metacontacts.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/ChangeLog	2009-02-20 11:11:09 UTC (rev 1675)
@@ -1,3 +1,23 @@
+2009-02-20  Sergei Golovan  <sgolovan at nes.ru>
+
+	* presence.tcl: Fixed sending custom presence to a conference.
+
+	* ifacetk/iroster.tcl: Fixed metacontact label positioning when group
+	  close/open mark should be displayed.
+
+	* plugins.tcl: Remove recognizing preload.tcl as a plugin preload file
+	  and added a procedure which checks if the requested plugin is already
+	  registered.
+
+	* ifacetk/iface.tcl, plugins/roster/backup.tcl,
+	  plugins/roster/bkup_annotations.tcl,
+	  plugins/roster/bkup_conferences.tcl: Adapted roster import/export
+	  procedures to changes in corresponding modules (moving part of the
+	  functionality to TclXMPP).
+
+	* plugins/roster/bkup_metacontacts.tcl: Added plugin for exporting
+	  metacontacts.
+
 2009-02-19  Sergei Golovan  <sgolovan at nes.ru>
 
 	* presence.tcl: Greyed out sending custom presence submenu in chat

Modified: trunk/tkabber/ifacetk/iface.tcl
===================================================================
--- trunk/tkabber/ifacetk/iface.tcl	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/ifacetk/iface.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -354,10 +354,6 @@
 			 -variable [namespace current]::roster::options(use_filter)] \
 		    [list checkbutton [::msgcat::mc "Enable metacontacts"] {} {} {} \
 			 -variable [namespace current]::roster::options(enable_metacontacts)] \
-		    [list cascad [::msgcat::mc "Export roster..."] \
-			 export_roster export_roster 0 {}] \
-		    [list cascad [::msgcat::mc "Import roster..."] \
-			 import_roster import_roster 0 {}] \
 		    [list command [::msgcat::mc "Add group by regexp on JIDs..."] {} {} {} \
 			 -command [namespace current]::roster::add_group_by_jid_regexp_dialog] \
 		  ]] \

Modified: trunk/tkabber/ifacetk/iroster.tcl
===================================================================
--- trunk/tkabber/ifacetk/iroster.tcl	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/ifacetk/iroster.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -1087,6 +1087,7 @@
 }
 
 proc roster::addline {w type text jid group metajids indent {jids {}} {icon ""} {foreground ""}} {
+    variable options
     variable roster
     variable iroster
     variable config
@@ -1224,7 +1225,15 @@
     }
 
     switch -- $type {
-	metajid -
+	metajid {
+	    if {($config(subitemtype) > 0) && ($config(subitemtype) & 2) && \
+		    (($options(enable_metacontact_labels) && [llength $jids] > 0) || \
+		    [llength $jids] > 1)} {
+		set x [expr {$config(jidmultindent) + $levindent}]
+	    } else {
+		set x [expr {$config(jidindent) + $levindent}]
+	    }
+	}
 	jid {
 	    if {($config(subitemtype) > 0) && ($config(subitemtype) & 2) && \
 		    $isuser && ([llength $jids] > 1)} {

Modified: trunk/tkabber/plugins/roster/backup.tcl
===================================================================
--- trunk/tkabber/plugins/roster/backup.tcl	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/plugins/roster/backup.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -26,34 +26,59 @@
 ###############################################################################
 
 proc rosterbackup::setup_import_export_menus {args} {
-    set emenu [.mainframe getmenu export_roster]
-    set imenu [.mainframe getmenu import_roster]
+    set rmenu [.mainframe getmenu roster]
+    set elabel2 [::msgcat::mc "Export roster"]
+    set ilabel2 [::msgcat::mc "Import roster"]
+    set elabel1 $elabel2...
+    set ilabel1 $ilabel2...
 
+    catch {$rmenu delete $elabel1}
+    catch {$rmenu delete $ilabel1}
+    catch {$rmenu delete $elabel2}
+    catch {$rmenu delete $ilabel2}
+
+    set index [$rmenu index [::msgcat::mc "Add group by regexp on JIDs..."]]
+
+    set emenu .export_roster
+    set imenu .import_roster
+
     if {[winfo exists $emenu]} {
 	destroy $emenu
     }
-    menu $emenu -tearoff 0
 
     if {[winfo exists $imenu]} {
 	destroy $imenu
     }
-    menu $imenu -tearoff 0
 
-    if {[connections] == {}} {
-	.mainframe setmenustate export_roster disabled
-	.mainframe setmenustate import_roster disabled
-    } else {
-	.mainframe setmenustate export_roster normal
-	.mainframe setmenustate import_roster normal
-    }
+    switch -- [llength [connections]] {
+	0 {
+	    $rmenu insert $index command -label $ilabel1 -state disabled
+	    $rmenu insert $index command -label $elabel1 -state disabled
+	}
+	1 {
+	    set xlib [lindex [connections] 0]
+	    $rmenu insert $index command -label $ilabel1 -state normal \
+		    -command [namespace code [list import_from_file $xlib]]
+	    $rmenu insert $index command -label $elabel1 -state normal \
+		    -command [namespace code [list export_to_file $xlib]]
+	}
+	default {
+	    menu $emenu -tearoff $::ifacetk::options(show_tearoffs)
+	    menu $imenu -tearoff $::ifacetk::options(show_tearoffs)
 
-    foreach c [connections] {
-	set jid [connection_jid $c]
-	set label [::msgcat::mc "Roster of %s" $jid]
-	set ecommand [list [namespace current]::export_to_file $c]
-	set icommand [list [namespace current]::import_from_file $c]
-	$emenu add command -label $label -command $ecommand
-	$imenu add command -label $label -command $icommand
+	    $rmenu insert $index cascade -label $ilabel2 -state normal \
+		    -menu $imenu
+	    $rmenu insert $index cascade -label $elabel2 -state normal \
+		    -menu $emenu
+
+	    foreach xlib [connections] {
+		set jid [connection_jid $xlib]
+		$emenu add command -label [::msgcat::mc "Export Roster for %s..." $jid] \
+			-command [namespace code [list export_to_file $xlib]]
+		$imenu add command -label [::msgcat::mc "Import Roster for %s..." $jid] \
+			-command [namespace code [list import_from_file $xlib]]
+	    }
+	}
     }
 }
 
@@ -197,9 +222,9 @@
 	::xmpp::xml::split $item tag xmlns attrs cdata subels
 
 	if {![string equal $tag roster]} continue
-	if {![string equal $xmlns $NS(roster)]} {
+	if {![string equal $xmlns jabber:iq:roster]} {
 	    return -code error "Bad roster element namespace \"$xmlns\":\
-				must be \"$NS(roster)\""
+				must be \"jabber:iq:roster\""
 	}
 
 	foreach subel $subels {
@@ -234,7 +259,7 @@
 
     ::xmpp::sendIQ $xlib set \
 	-query [::xmpp::xml::create query \
-			    -xmlns $NS(roster) \
+			    -xmlns jabber:iq:roster \
 			    -subelements $contacts] \
 	-command [namespace code [list process_send_result $continuation]]
 }
@@ -252,7 +277,7 @@
 		-aspect 50000 \
 		-icon error \
 		-title [::msgcat::mc "Error"] \
-		-message [::msgcat::mc "Error restoring roster contacts: %s" \
+		-message [::msgcat::mc "Error importing roster contacts: %s" \
 		    [error_to_string $xmldata]]
 	}
     }
@@ -265,7 +290,8 @@
 	-aspect 50000 \
 	-icon info \
 	-title [::msgcat::mc "Information"] \
-	-message [::msgcat::mc "Roster restoration completed"]
+	-message [::msgcat::mc "Roster import for %s is completed" \
+			       [connection_bare_jid $xlib]]
     eval $continuation
 }
 

Modified: trunk/tkabber/plugins/roster/bkup_annotations.tcl
===================================================================
--- trunk/tkabber/plugins/roster/bkup_annotations.tcl	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/plugins/roster/bkup_annotations.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -17,7 +17,8 @@
     upvar $level $varName subtags
     global NS
 
-    set xmldata [::plugins::annotations::serialize_notes $xlib]
+    set xmldata [::xmpp::roster::annotations::serialize \
+			[::plugins::annotations::serialize_notes $xlib]]
 
     lappend subtags [::xmpp::xml::create privstorage \
 				-xmlns jabber:iq:private \
@@ -34,18 +35,13 @@
     foreach item $data {
 	::xmpp::xml::split $item tag xmlns attrs cdata subels
 	if {![string equal $tag privstorage]} continue
-	if {![string equal $xmlns $NS(private)]} {
+	if {![string equal $xmlns jabber:iq:private]} {
 	    return -code error "Bad roster element namespace \"$xmlns\":\
-				must be \"$NS(private)\""
+				must be \"jabber:iq:private\""
 	}
 
-	foreach storage $subels {
-	    ::xmpp::xml::split $storage stag sxmlns sattrs scdata ssubels
-	    if {![string equal $stag storage]} continue
-	    if {![string equal $sxmlns $NS(rosternotes)]} continue
-	    
-	    set notes [concat $notes $ssubels]
-	}
+	set notes [concat $notes \
+			  [::xmpp::roster::annotations::deserialize $subels]]
     }
 
     if {[llength $notes] > 0} {

Modified: trunk/tkabber/plugins/roster/bkup_conferences.tcl
===================================================================
--- trunk/tkabber/plugins/roster/bkup_conferences.tcl	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/plugins/roster/bkup_conferences.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -16,11 +16,13 @@
     upvar $level $varName subtags
     global NS
 
-    foreach xmldata [::plugins::conferences::serialize_bookmarks $xlib] {
-	lappend subtags [::xmpp::xml::create privstorage \
-				    -xmlns $NS(private) \
-				    -subelement $xmldata]
-    }
+    lassign [::plugins::conferences::serialize_bookmarks $xlib] \
+	    bookmarks groupstag
+
+    lappend subtags [::xmpp::roster::bookmarks::serialize $bookmarks]
+    lappend subtags [::xmpp::xml::create privstorage \
+					 -xmlns jabber:iq:private \
+					 -subelement $groupstag]
 }
 
 ###############################################################################
@@ -39,20 +41,18 @@
 				must be \"$NS(private)\""
 	}
 
+	set bookmarks [concat $bookmarks \
+			      [::xmpp::roster::bookmarks::deserialize $subels]]
+
 	foreach storage $subels {
 	    ::xmpp::xml::split $storage stag sxmlns sattrs scdata ssubels
-	    if {![string equal $ctag storage]} continue
-	    switch -- $sxmlns \
-		$NS(bookmarks) {
-		    set bookmarks [concat $bookmarks $ssubels]
-		} \
-		$NS(tkabber:groups) {
-		    set bmgroups [concat $bmgroups $ssubels]
-		}
+	    if {![string equal $stag storage] || \
+		    ![string equal $sxmlns tkabber:bookmarks:groups]} continue
+		set bmgroups [concat $bmgroups $ssubels]
 	}
     }
 
-    if {[llength $bookmarks] > 0 && [llength $bmgroups] > 0} {
+    if {[llength $bookmarks] > 0 || [llength $bmgroups] > 0} {
 	lappend handlers [list 70 [namespace code [list \
 	    merge_muc_bookmarks $xlib $bookmarks $bmgroups]]]
     }

Added: trunk/tkabber/plugins/roster/bkup_metacontacts.tcl
===================================================================
--- trunk/tkabber/plugins/roster/bkup_metacontacts.tcl	                        (rev 0)
+++ trunk/tkabber/plugins/roster/bkup_metacontacts.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -0,0 +1,90 @@
+# $Id$
+# Support for backup/restore of metacontacts (XEP-0209)
+# for roster items.
+
+namespace eval metabackup {
+    # Should probably go after the roster contacts, so we set prio to 60:
+    hook::add serialize_roster_hook \
+	      [namespace current]::serialize_metacontacts 60
+    hook::add deserialize_roster_hook \
+	      [namespace current]::deserialize_metacontacts 60
+}
+
+###############################################################################
+
+proc metabackup::serialize_metacontacts {xlib level varName} {
+    upvar $level $varName subtags
+    global NS
+
+    set xmldata [::xmpp::roster::metacontacts::serialize \
+			[::plugins::metacontacts::serialize_contacts $xlib]]
+
+    lappend subtags [::xmpp::xml::create privstorage \
+				-xmlns jabber:iq:private \
+				-subelement $xmldata]
+}
+
+###############################################################################
+
+proc metabackup::deserialize_metacontacts {xlib data level varName} {
+    global NS
+    upvar $level $varName handlers
+
+    set contacts [list]
+    foreach item $data {
+	::xmpp::xml::split $item tag xmlns attrs cdata subels
+	if {![string equal $tag privstorage]} continue
+	if {![string equal $xmlns jabber:iq:private]} {
+	    return -code error "Bad roster element namespace \"$xmlns\":\
+				must be \"jabber:iq:private\""
+	}
+
+	set contacts [concat $contacts \
+			  [::xmpp::roster::metacontacts::deserialize $subels]]
+    }
+
+    if {[llength $contacts] > 0} {
+	lappend handlers [list 60 [namespace code [list \
+						    send_contacts $xlib $contacts]]]
+    }
+}
+
+###############################################################################
+
+proc metabackup::send_contacts {xlib contacts continuation} {
+    set updated 0
+
+    foreach {tag jids} $contacts {
+	set added [::plugins::metacontacts::create_contact \
+			    $xlib $tag $jids -merge yes]
+	set updated [expr {$updated || $added}]
+    }
+
+    if {$updated} {
+	::plugins::metacontacts::store_contacts $xlib \
+	    -command [namespace code [list process_sending_result $continuation]]
+    } else {
+	eval $continuation
+    }
+}
+
+###############################################################################
+
+proc metabackup::process_sending_result {continuation result xmldata} {
+    switch -- $result {
+	ok {
+	    eval $continuation
+	}
+	default {
+	    # TODO check whether do we need to handle TIMEOUT specially
+	    NonmodalMessageDlg [epath] \
+		-aspect 50000 \
+		-icon error \
+		-title [::msgcat::mc "Error"] \
+		-message [::msgcat::mc "Error restoring metacontacts: %s" \
+		    [error_to_string $xmldata]]
+	}
+    }
+}
+
+# vim:ts=8:sw=4:sts=4:noet


Property changes on: trunk/tkabber/plugins/roster/bkup_metacontacts.tcl
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Modified: trunk/tkabber/plugins.tcl
===================================================================
--- trunk/tkabber/plugins.tcl	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/plugins.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -23,22 +23,26 @@
 
 proc plugins::load_dir {plugins_dir} {
     foreach dir [lsort [glob -nocomplain -type {d l} [file join $plugins_dir *]]] {
-	set preload_file [file join $dir preload.tcl]
-	if {[file exists $preload_file]} {
-	    debugmsg plugins "Loading plugin preload info from $preload_file"
-	    source $preload_file
+	set file [file join $dir [file tail $dir].tcl]
+	if {[file exists $file]} {
+	    debugmsg plugins "Loading plugin from $file"
+	    source $file
 	} else {
-	    set file [file join $dir [file tail $dir].tcl]
-	    if {[file exists $file]} {
-		debugmsg plugins "Loading plugin from $file"
-		source $file
-	    } else {
-		debugmsg plugins "Can't load plugin from directory $dir"
-	    }
+	    debugmsg plugins "Can't load plugin from directory $dir"
 	}
     }
 }
 
+proc plugins::is_registered {name} {
+    variable loaded
+
+    if {[info exists loaded($name)]} {
+	return 1
+    } else {
+	return 0
+    }
+}
+
 proc plugins::register {name args} {
     foreach {key val} $args {
 	switch -- $key {

Modified: trunk/tkabber/presence.tcl
===================================================================
--- trunk/tkabber/presence.tcl	2009-02-19 19:28:11 UTC (rev 1674)
+++ trunk/tkabber/presence.tcl	2009-02-20 11:11:09 UTC (rev 1675)
@@ -583,7 +583,8 @@
 
 proc custom_presence_menu {m xlib jid} {
     set chatid [chat::chatid $xlib [::xmpp::jid::stripResource $jid]]
-    if {[chat::is_groupchat $chatid]} {
+    set chatid1 [chat::chatid $xlib $jid]
+    if {[chat::is_groupchat $chatid] && ![chat::is_groupchat $chatid1]} {
 	set state disabled
     } else {
 	set state normal



More information about the Tkabber-dev mailing list