[Tkabber-dev] r1597 - trunk/tkabber

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Nov 2 12:50:10 MSK 2008


Author: sergei
Date: 2008-11-02 12:50:10 +0300 (Sun, 02 Nov 2008)
New Revision: 1597

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/datagathering.tcl
   trunk/tkabber/register.tcl
   trunk/tkabber/search.tcl
Log:
	* datagathering.tcl: Removed predefined form fields.

	* register.tcl: Switched to xmpp::register package.

	* search.tcl: Cleanup form data upon search window is destroyed.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2008-11-02 08:11:04 UTC (rev 1596)
+++ trunk/tkabber/ChangeLog	2008-11-02 09:50:10 UTC (rev 1597)
@@ -9,6 +9,12 @@
 
 	* msgs/de.msg: Updated German translation (thanks to Roger Sondermann).
 
+	* datagathering.tcl: Removed predefined form fields.
+
+	* register.tcl: Switched to xmpp::register package.
+
+	* search.tcl: Cleanup form data upon search window is destroyed.
+
 2008-11-01  Sergei Golovan  <sgolovan at nes.ru>
 
 	* Makefile: Added rules to make documentation (tkabber.html and

Modified: trunk/tkabber/datagathering.tcl
===================================================================
--- trunk/tkabber/datagathering.tcl	2008-11-02 08:11:04 UTC (rev 1596)
+++ trunk/tkabber/datagathering.tcl	2008-11-02 09:50:10 UTC (rev 1597)
@@ -6,29 +6,6 @@
 package require xmpp::data
 
 namespace eval data {
-    set winid 0
-
-    # Registration & search fields (see XEP-0077 & XEP-0055)
-
-    array set field_labels [list \
-	username     [::msgcat::mc "Username:"] \
-	nick         [::msgcat::mc "Nickname:"] \
-	password     [::msgcat::mc "Password:"] \
-	name         [::msgcat::mc "Full Name:"] \
-	first        [::msgcat::mc "First Name:"] \
-	last         [::msgcat::mc "Last Name:"] \
-	email        [::msgcat::mc "E-mail:"] \
-	address      [::msgcat::mc "Address:"] \
-	city         [::msgcat::mc "City:"] \
-	state        [::msgcat::mc "State:"] \
-	zip          [::msgcat::mc "Zip:"] \
-	phone        [::msgcat::mc "Phone:"] \
-	url          [::msgcat::mc "URL:"] \
-	date         [::msgcat::mc "Date:"] \
-	misc         [::msgcat::mc "Misc:"] \
-	text         [::msgcat::mc "Text:"] \
-	key          [::msgcat::mc "Key:"]]
-
     disco::register_feature jabber:x:data
 }
 
@@ -54,8 +31,6 @@
 
 
 proc data::parse_fields {items} {
-    variable field_labels
-
     set res {}
     foreach item $items {
 	::xmpp::xml::split $item tag xmlns attrs cdata subels
@@ -73,14 +48,8 @@
 		    default    {set type text-single}
 		}
 
-		if {[info exists field_labels($tag)]} {
-		    set label $field_labels($tag)
-		} else {
-		    set label $tag
-		}
-
                 lappend res field \
-			[list $tag $type $label "" false {} [list $cdata] {}]
+			[list $tag $type "" "" false {} [list $cdata] {}]
 	    }
 	}
     }
@@ -330,6 +299,9 @@
     if {$type == ""} {
 	set type text-single
     }
+    if {$label == ""} {
+	set label $var
+    }
     set data(var,$var,$g) [lindex $vals 0]
     set widget ""
 
@@ -530,9 +502,12 @@
 proc data::draw_window {items send_cmd {cancel_cmd destroy}} {
     variable winid
 
-    set w .datagathering$winid
-    incr winid
+    if {![info exists winid]} {
+	set winid 0
+    }
 
+    set w .datagathering[incr winid]
+
     if {[winfo exists $w]} {
 	destroy $w
     }

Modified: trunk/tkabber/register.tcl
===================================================================
--- trunk/tkabber/register.tcl	2008-11-02 08:11:04 UTC (rev 1596)
+++ trunk/tkabber/register.tcl	2008-11-02 09:50:10 UTC (rev 1597)
@@ -1,13 +1,17 @@
 # $Id$
 
-namespace eval register {
-    set winid 0
-}
+package require xmpp::register
 
+namespace eval register {}
+
 proc register::open {xlib jid args} {
     variable winid
 
-    set w .register$winid
+    if {![info exists winid]} {
+	set winid 0
+    }
+
+    set w .register[incr winid]
     toplevel $w
     wm group $w .
     set title [::msgcat::mc "Register in %s" $jid]
@@ -35,10 +39,10 @@
 
     set bbox [ButtonBox $w.bbox -spacing 0 -padx 10 -default 0]
     $bbox add -text [::msgcat::mc "Register"] \
-	-command [list register::register $w $f $xlib $jid] \
+	-command [namespace code [list Register $w $f $xlib $jid false]] \
         -state disabled
     $bbox add -text [::msgcat::mc "Unregister"] \
-	-command [list register::unregister $w $xlib $jid] \
+	-command [namespace code [list Unregister $w $xlib $jid]] \
         -state disabled
     $bbox add -text [::msgcat::mc "Cancel"] -command [list destroy $w]
     bind $w <Return> "ButtonBox::invoke $bbox default"
@@ -54,34 +58,33 @@
 
     wm withdraw $w
 
-    ::xmpp::sendIQ $xlib get \
-	-query [::xmpp::xml::create query \
-			-xmlns $::NS(register)] \
-	-to $jid \
-	-command [list register::recv_fields $w $f $xlib $jid]
-    
-    incr winid
+    ::xmpp::register::request $xlib $jid \
+	-command [namespace code [list RecvFields $w $f $xlib $jid]]
 }
 
+proc register::RecvFields {w f xlib jid status fields args} {
+    debugmsg register "$status $fields"
 
-proc register::recv_fields {w f xlib jid status xml} {
-    debugmsg register "$status $xml"
-
     switch -- $status {
 	error {
 	    destroy $w
 	    MessageDlg ${w}_err -aspect 50000 -icon error \
 		-message [::msgcat::mc "Registration: %s" \
-				       [error_to_string $xml]] \
+				       [error_to_string $fields]] \
 		-type user -buttons ok -default 0 -cancel 0
 	}
 	ok {
-	    ::xmpp::xml::split $xml tag xmlns attrs cdata subels
-
-	    if {$xmlns == $::NS(register)} {
-		set focus [data::fill_fields $f $subels]
+	    foreach {key val} $args {
+		switch -- $key {
+		    -old {
+			$w.bbox itemconfigure 0 \
+				-command [namespace code [list Register $w $f $xlib $jid $val]]
+		    }
+		}
 	    }
 
+	    set focus [data::fill_fields_x $f $fields]
+
 	    $w.bbox itemconfigure 0 -state normal
 	    if {$jid != [connection_server $xlib]} {
 		$w.bbox itemconfigure 1 -state normal
@@ -108,42 +111,34 @@
     }
 }
 
-
-proc register::register {w f xlib jid} {
+proc register::Register {w f xlib jid old} {
     variable data
 
     destroy $w.error.msg
     $w.bbox itemconfigure 0 -state disabled
     $w.bbox itemconfigure 1 -state disabled
 
-    set restags [data::get_tags $f]
+    set fields [data::get_fields $f]
 
-    ::xmpp::sendIQ $xlib set \
-	-query [::xmpp::xml::create query \
-			-xmlns $::NS(register) \
-			-subelements $restags] \
-	-to $jid \
-	-command [list register::recv_result $w $xlib $jid]
+    ::xmpp::register::submit $xlib $jid $fields \
+	-command [namespace code [list RecvResult $w $xlib $jid]] \
+	-old $old
 }
 
 
-proc register::unregister {w xlib jid} {
+proc register::Unregister {w xlib jid} {
     variable data
 
     destroy $w.error.msg
     $w.bbox itemconfigure 0 -state disabled
     $w.bbox itemconfigure 1 -state disabled
 
-    ::xmpp::sendIQ $xlib set \
-	-query [::xmpp::xml::create query \
-			-xmlns $::NS(register) \
-			-subelement [::xmpp::xml::create remove]] \
-	-to $jid \
-	-command [list register::recv_result $w $xlib $jid]
+    ::xmpp::register::remove $xlib $jid \
+	-command [namespace code [list RecvResult $w $xlib $jid]]
 }
 
 
-proc register::recv_result {w xlib jid status xml} {
+proc register::RecvResult {w xlib jid status xml} {
     variable data
 
     debugmsg register "$status $xml"

Modified: trunk/tkabber/search.tcl
===================================================================
--- trunk/tkabber/search.tcl	2008-11-02 08:11:04 UTC (rev 1596)
+++ trunk/tkabber/search.tcl	2008-11-02 09:50:10 UTC (rev 1597)
@@ -47,6 +47,7 @@
     frame $sw.fields -class Search
 
     pack $sw.fields -expand yes -fill both -anchor nw -padx 2m -pady 2m
+    bind $sw.fields <Destroy> [list data::cleanup $sw.fields]
 
     ::xmpp::search::request $xlib $jid \
 		-command [namespace code [list RecvFields $sw $xlib $jid]]



More information about the Tkabber-dev mailing list