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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
|
# GotMsg.tcl ---
#
# This file is part of The Coccinella application.
# It implements a dialog for jabber messages.
#
# Copyright (c) 2002-2008 Mats Bengtsson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# $Id: GotMsg.tcl,v 1.59 2008-06-09 09:50:59 matben Exp $
package provide GotMsg 1.0
namespace eval ::GotMsg:: {
# Add all event hooks.
::hooks::register quitAppHook ::GotMsg::QuitAppHook
::hooks::register presenceHook ::GotMsg::PresenceHook
#::hooks::register newMessageHook ::GotMsg::MessageHook
# Wait for this variable to be set.
variable finished
# msgId for the one in the dialog.
variable msgIdDisplay 0
variable locals
set locals(updateDateid) ""
set locals(updateDatems) [expr {1000*60}]
}
proc ::GotMsg::QuitAppHook {} {
global wDlgs
::UI::SaveWinGeom $wDlgs(jgotmsg)
}
# @@@ Enable this when solved the uidmsg vs. uuid mixup.
proc ::GotMsg::MessageHook {xmldata uuid} {
global jprefs
set body [wrapper::getcdata [wrapper::getfirstchildwithtag $xmldata body]]
if {$jprefs(showMsgNewWin) && ($body ne "")} {
GotMsg $uuid
}
}
# GotMsg::GotMsg --
#
# Called when we get an incoming message.
# Calls 'GotMsg::Show' if not mapped.
#
# Arguments:
# uid the message uuid
#
# Results:
# may show message window.
proc ::GotMsg::GotMsg {uid} {
global wDlgs
variable w
variable wbtnext
::Debug 2 "GotMsg::GotMsg uid=$uid"
set w $wDlgs(jgotmsg)
# Queue up this message or show right away?
if {[winfo exists $w]} {
$wbtnext state {!disabled}
} else {
Show $uid
}
}
# GotMsg::Show --
#
# Fills in all entries etc in message window.
proc ::GotMsg::Show {thisMsgId} {
global prefs jprefs
variable w
variable msgIdDisplay
variable jid
variable jidtxt
variable username
variable subject
variable smartdate
variable prestext
variable wtext
variable wbtnext
variable wpresence
variable body
variable date
::Debug 2 "::GotMsg::Show thisMsgId=$thisMsgId"
# Build if not mapped.
Build
set msgIdDisplay $thisMsgId
lassign [::MailBox::GetContentList $thisMsgId] subject jid date body
set jid [::Jabber::Jlib getrecipientjid $jid]
set jidtxt $jid
set smartdate [::Utils::SmartClockFormat [clock scan $date]]
# Split jid into jid2 and resource.
jlib::splitjid $jid jid2 res
set jlib [::Jabber::GetJlib]
# Use nick name.
set rname [$jlib roster getname $jid2]
set ujid [jlib::unescapejid $jid]
if {[string length $rname]} {
set username "$rname <$ujid>"
} else {
set username $ujid
}
set myjid [::Jabber::Jlib myjid]
if {[jlib::jidequal $jid $myjid]} {
set show [::Jabber::GetMyStatus]
} else {
if {$res eq ""} {
array set presArr [lindex [$jlib roster getpresence $jid2] 0]
} else {
array set presArr [$jlib roster getpresence $jid2 -resource $res]
}
set show $presArr(-type)
if {[info exists presArr(-show)]} {
set show $presArr(-show)
}
set prestext [::Roster::MapShowToText $show]
}
set icon [::Roster::GetPresenceIconFromJid $jid]
$wpresence configure -image $icon
# Insert the actual body of the message.
$wtext configure -state normal
$wtext delete 1.0 end
$wtext mark set insert end
::Text::ParseMsg normal $jid $wtext $body normal
$wtext insert end \n
$wtext configure -state disabled
# If no more messages after this one...
if {[::MailBox::IsLastMessage $msgIdDisplay]} {
$wbtnext state {disabled}
}
# Run display message hook (speech).
set opts [list -subject $subject -from $jid -time $date -msgid $thisMsgId]
eval {::hooks::run displayMessageHook $body} $opts
}
# GotMsg::Build --
#
# Builds the standard got message dialog.
#
# Arguments:
#
# Results:
# shows window.
proc ::GotMsg::Build {} {
global this prefs wDlgs jprefs
variable w
variable finished
variable msgStorage
variable msgIdDisplay
variable jid
variable username
variable jidtxt
variable subject
variable smartdate
variable prestext
variable wtext
variable wbtnext
variable wpresence
variable locals
::Debug 2 "::GotMsg::Build"
set w $wDlgs(jgotmsg)
if {[winfo exists $w]} {
raise $w
return
}
set finished 0
# Toplevel with class GotMsg.
::UI::Toplevel $w -class GotMsg \
-usemacmainmenu 1 -macstyle documentProc -closecommand ::GotMsg::CloseHook
# TRANSLATORS; Window title of popup dialog when receiving a message (instead of a chat message!)
wm title $w [mc "Incoming Message"]
set bg [option get . backgroundGeneral {}]
# Global frame.
ttk::frame $w.frall
pack $w.frall -fill both -expand 1
set wbox $w.frall.f
ttk::frame $wbox -padding [option get . dialogPadding {}]
pack $wbox -fill both -expand 1
# Button part.
set frbot $wbox.b
ttk::frame $frbot
set wbtnext $frbot.btnext
ttk::button $wbtnext -text [mc "Next"] -default active \
-width -8 -command [list ::GotMsg::NextMsg]
ttk::button $frbot.btfwd -text [mc "Forward"] \
-width -8 -command [list ::GotMsg::Forward]
ttk::button $frbot.btreply -text [mc "Reply"] \
-width -8 -command [list ::GotMsg::Reply]
set padx [option get . buttonPadX {}]
pack $wbtnext -side right
pack $frbot.btfwd -side right -padx $padx
pack $frbot.btreply -side right
pack $frbot -side bottom -fill x
ttk::checkbutton $wbox.ch -style Small.TCheckbutton \
-text [mc "Show incoming messages in this window"] \
-variable jprefs(showMsgNewWin)
pack $wbox.ch -side bottom -anchor w -pady 4
# From, subject, and time fields.
set frmid $wbox.frmid
ttk::frame $frmid
pack $frmid -side top -fill x
# From field.
set wfrom $frmid.lfrom
set wpresence $frmid.ifrom
ttk::label $frmid.lfrom -text [mc "From"]:
ttk::label $frmid.efrom \
-textvariable [namespace current]::username
ttk::label $frmid.time -style Small.TLabel \
-textvariable [namespace current]::smartdate
ttk::label $frmid.ifrom -style Small.TLabel \
-compound left -compound left -image "" \
-textvariable [namespace current]::prestext
# Subject field.
ttk::label $frmid.lsub -text [mc "Subject"]: -anchor e
ttk::label $frmid.esub \
-textvariable [namespace current]::subject
grid $frmid.lfrom $frmid.efrom $frmid.time -sticky e -padx 2 -pady 2
grid $frmid.lsub $frmid.esub $frmid.ifrom -sticky e -padx 2 -pady 2
grid $frmid.efrom $frmid.esub -sticky w
grid $frmid.time $frmid.ifrom -sticky w
grid columnconfigure $frmid 1 -weight 1
# Text.
set wtxtfr $wbox.frtxt
set wtext $wtxtfr.text
set wysc $wtxtfr.ysc
ttk::frame $wtxtfr -padding {0 4 0 0}
pack $wtxtfr -side top -fill both -expand 1
text $wtext -highlightthickness 0 -height 6 -width 48 -wrap word \
-borderwidth 1 -relief sunken \
-yscrollcommand [list ::UI::ScrollSet $wysc \
[list grid $wysc -column 1 -row 0 -sticky ns]]
$wtext tag configure normal
ttk::scrollbar $wysc -orient vertical -command [list $wtext yview]
bindtags $wtext [linsert [bindtags $wtext] 0 ReadOnlyText]
grid $wtext -column 0 -row 0 -sticky news
grid $wysc -column 1 -row 0 -sticky ns
grid columnconfigure $wtxtfr 0 -weight 1
grid rowconfigure $wtxtfr 0 -weight 1
::UI::SetWindowGeometry $w
wm minsize $w 240 220
wm maxsize $w 600 600
set locals(updateDateid) [after $locals(updateDatems) \
[namespace current]::UpdateDate]
bind $wtext <<Copy>> {
::JUI::CopyEvent %W
break
}
# Grab and focus.
focus $w
}
proc ::GotMsg::UpdateDate {} {
variable w
variable locals
variable date
variable smartdate
if {![winfo exists $w] || ![info exists date]} {
return
}
set smartdate [::Utils::SmartClockFormat [clock scan $date]]
# Reschedule ourselves.
set locals(updateDateid) [after $locals(updateDatems) \
[namespace current]::UpdateDate]
}
proc ::GotMsg::CloseHook {wclose} {
variable locals
::UI::SaveWinGeom $wclose
if {$locals(updateDateid) != ""} {
after cancel $locals(updateDateid)
}
}
proc ::GotMsg::PresenceHook {pjid2 type args} {
global wDlgs
variable w
variable wpresence
variable prestext
variable jid
::Debug 4 "::GotMsg::PresenceHook pjid2=$pjid2, type=$type"
set w $wDlgs(jgotmsg)
if {[winfo exists $w]} {
array set argsArr $args
set from $pjid2
if {[info exists argsArr(-from)]} {
set from $argsArr(-from)
}
jlib::splitjid $jid jid2 res
if {[jlib::jidequal $pjid2 $jid2]} {
set show $type
if {[info exists argsArr(-show)]} {
set show $argsArr(-show)
}
set prestext [::Roster::MapShowToText $show]
set icon [::Roster::GetPresenceIconFromJid $from]
$wpresence configure -image $icon
}
}
}
proc ::GotMsg::NextMsg {} {
variable msgIdDisplay
# Query the mailbox for next message id.
set nextid [::MailBox::GetNextMsgID $msgIdDisplay]
if {$nextid ne ""} {
Show $nextid
}
}
proc ::GotMsg::Forward {} {
variable jid
variable subject
variable date
variable body
if {![regexp -nocase {^ *fwd:} $subject]} {
set fwdsubject "Fwd: $subject"
} else {
set fwdsubject $subject
}
::NewMsg::Build -subject $fwdsubject -forwardmessage $body -time $date \
-from $jid
}
proc ::GotMsg::Reply {} {
variable jid
variable subject
variable date
variable body
if {![regexp -nocase {^ *re:} $subject]} {
set resubject "Re: $subject"
} else {
set resubject $subject
}
::NewMsg::Build -to $jid -subject $resubject \
-quotemessage $body -time $date
}
proc ::GotMsg::Close {w} {
::UI::SaveWinGeom $w
destroy $w
}
#-------------------------------------------------------------------------------
|