~ubuntu-branches/ubuntu/saucy/amsn/saucy

« back to all changes in this revision

Viewing changes to plugins/amsnplus/amsnplus.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-13 23:21:29 UTC
  • mfrom: (1.1.11 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100413232129-vgpx20brdd2qavs7
Tags: 0.98.3-0ubuntu1
* Merge from Debian unstable (LP: #449072), remaining Ubuntu changes:
  - add 08_use_aplay_for_sound.dpatch patch by Festor Wailon Dacoba to use
    aplay to play sounds
  + debian/control:
    - modify iceweasel to firefox | abrowser in amsn Suggests field
    - add xdg-utils and gstreamer0.10-nice to amsn Depends field
    - mofify sox to alsa-utils in amsn Suggests field as we are now using
      aplay
* New upstream release (LP: #562619), tarball repacked according to
  debian/README.source.
* Fix missing-debian-source-format lintian warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
########################################################
 
2
#             AMSNPLUS PLUGIN NAMESPACE
 
3
########################################################
 
4
# Maintainer: markitus (markitus@catmail.homelinux.org)
 
5
# Created: 13/09/2004
 
6
########################################################
 
7
 
 
8
namespace eval ::amsnplus {
 
9
 
 
10
 
 
11
        #//////////////////////////////////////////////////////////////////////////
 
12
        #                          CORE PROCEDURES
 
13
        #//////////////////////////////////////////////////////////////////////////
 
14
 
 
15
        ################################################
 
16
        # this starts amsnplus
 
17
        proc amsnplusStart { dir } {
 
18
                #global vars
 
19
                variable external_commands
 
20
                array set ::amsnplus::external_commands [list]
 
21
                #register plugin
 
22
                ::plugins::RegisterPlugin "aMSN Plus"
 
23
                #set the amsnplus dir in config
 
24
                ::config::setKey amsnpluspluginpath $dir
 
25
                #loading lang - if version is 0.95b (keep compatibility with 0.94)
 
26
                if {[::amsnplus::amsn_version] > 94} {
 
27
                        set langdir [file join $dir "lang"]
 
28
                        set lang [::config::getGlobalKey language]
 
29
                        load_lang en $langdir
 
30
                        load_lang $lang $langdir
 
31
                }
 
32
                #plugin config
 
33
                if {[::amsnplus::amsn_version] <= 94} {
 
34
                        array set ::amsnplus::config {
 
35
                                allow_commands 1
 
36
                                allow_quicktext 1
 
37
                                quick_text [list]
 
38
                        }
 
39
                        set ::amsnplus::configlist [ list \
 
40
                                [list bool "Do you want to allow commands in the chat window?" allow_commands] \
 
41
                                [list bool "Do you want to use the quick text feature?" allow_quicktext] \
 
42
 
 
43
                        ]
 
44
                } else {
 
45
                        array set ::amsnplus::config {
 
46
                                allow_commands 1
 
47
                                allow_colours 1
 
48
                                allow_quicktext 1
 
49
                                quick_text [list]
 
50
                        }
 
51
                        set ::amsnplus::configlist [ list \
 
52
                                [list bool "[trans allowcommands]" allow_commands] \
 
53
                                [list bool "[trans allowcolours]" allow_colours] \
 
54
                                [list bool "[trans allowquicktext]" allow_quicktext] \
 
55
                        ]
 
56
                }
 
57
 
 
58
                #creating the menus
 
59
                catch { after 100 ::amsnplus::add_plus_menu }
 
60
                catch { after 100 ::amsnplus::add_chat_menu }
 
61
 
 
62
                #register events
 
63
                ::plugins::RegisterEvent "aMSN Plus" chat_msg_send parseCommand
 
64
                ::plugins::RegisterEvent "aMSN Plus" chat_msg_receive parse_colours_and_sounds
 
65
                ::plugins::RegisterEvent "aMSN Plus" chatwindowbutton chat_color_button
 
66
                ::plugins::RegisterEvent "aMSN Plus" chatmenu edit_menu
 
67
 
 
68
                if {[::amsnplus::amsn_version] > 94} {
 
69
                        ::amsnplus::setPixmap
 
70
                }
 
71
        }
 
72
 
 
73
        ####################################################
 
74
        # deinit procedure, all to do when unloading the plugin
 
75
        proc amsnplusStop { } {
 
76
                #removing the plus menu and chat window pixmap
 
77
                .main_menu delete last
 
78
                ::amsnplus::remove_from_chatwindow
 
79
        }
 
80
 
 
81
 
 
82
 
 
83
        #//////////////////////////////////////////////////////////////
 
84
        #            PLUS MENUS AND PREFERENCES
 
85
        #//////////////////////////////////////////////////////////////
 
86
 
 
87
        ####################################################
 
88
        # this proc removes every menu in every chat window
 
89
        # and also the pixmap of amsnplus to choose a color
 
90
        proc remove_from_chatwindow { } {
 
91
                #the path of the menu is always $w.menu
 
92
                if { [::ChatWindow::UseContainer] } {
 
93
                        set cont [array get ::ChatWindow::containers]
 
94
                        foreach container $cont {
 
95
                                catch { ${container}.menu delete last }
 
96
                        }
 
97
                } else {
 
98
                        foreach win $::ChatWindow::windows {
 
99
                                catch { ${win}.menu delete last }
 
100
                        }
 
101
                }
 
102
        }
 
103
 
 
104
        ####################################################
 
105
        # creates the plus sub menu in the main gui menu
 
106
        proc add_plus_menu { } {
 
107
                catch {
 
108
                        menu .main_menu.plusmenu -tearoff 0
 
109
                        set plusmenu .main_menu.plusmenu
 
110
 
 
111
                        #entries for the plus menu
 
112
                        $plusmenu add command -label "[trans quicktext]" -command "::amsnplus::qtconfig"
 
113
                }
 
114
                .main_menu add cascade -label "Plus!" -menu .main_menu.plusmenu
 
115
        }
 
116
 
 
117
        ###############################################
 
118
        # creates the chat window menu
 
119
        proc create_chat_menu { win } {
 
120
                set bold [binary format c 2]
 
121
                set italic [binary format c 5]
 
122
                set underline [binary format c 31]
 
123
                set overstrike [binary format c 6]
 
124
                set reset [binary format c 15]
 
125
                set screenshot "/screenshot"
 
126
                
 
127
                catch {
 
128
                        menu ${win}.menu.plusmenu -tearoff 0
 
129
                        set plusmenu ${win}.menu.plusmenu
 
130
                
 
131
                        if { $::amsnplus::config(allow_colours) } {
 
132
                                $plusmenu add command -label "[trans choosecolor]" -command "::amsnplus::choose_color $win"
 
133
                                $plusmenu add command -label "[trans bold]" -command "::amsnplus::insert_text $win $bold"
 
134
                                $plusmenu add command -label "[trans italic]" -command "::amsnplus::insert_text $win $italic"
 
135
                                $plusmenu add command -label "[trans underline]" -command "::amsnplus::insert_text $win $underline"
 
136
                                $plusmenu add command -label "[trans overstrike]" -command "::amsnplus::insert_text $win $overstrike"
 
137
                                $plusmenu add command -label "[trans reset]" -command "::amsnplus::insert_text $win $reset"
 
138
                                $plusmenu add separator
 
139
                        }
 
140
                                $plusmenu add command -label "[trans screenshot]" -command "::amsnplus::insert_text $win $screenshot"
 
141
                        if {$::amsnplus::config(allow_quicktext)} {
 
142
                                $plusmenu add separator
 
143
                                #Menu item to edit the currents quick texts
 
144
                                $plusmenu add command -label "[trans quicktext]" -command "::amsnplus::qtconfig"
 
145
                                set i 0
 
146
                                #Show all the currents quick texts in the menu
 
147
                                foreach {key txt} $::amsnplus::config(quick_text) {
 
148
                                        $plusmenu add command -label $txt -command "::amsnplus::insert_text $win /$key"
 
149
                                }
 
150
                        }
 
151
                }
 
152
                set plusmenu ${win}.menu.plusmenu
 
153
                return $plusmenu
 
154
        }
 
155
 
 
156
        ###############################################
 
157
        # attaches the menu on chat window
 
158
        proc add_chat_menu { } {
 
159
                if { [::ChatWindow::UseContainer] } {
 
160
                        set cont [array get ::ChatWindow::containers]
 
161
                        foreach container $cont {
 
162
                                if { [string equal [string index $container 0] "."] } {
 
163
                                        catch {
 
164
                                                set plusmenu [::amsnplus::create_chat_menu $container]
 
165
                                                ${container}.menu add cascade -label "Plus!" -menu $plusmenu
 
166
                                        }
 
167
                                }
 
168
                        }
 
169
                } else {
 
170
 
 
171
                        foreach win $::ChatWindow::windows {
 
172
                                #I think the catch is useless but it's in case someone close a chatwindow very fast, then we won't have a stupid bugreport
 
173
                                catch {
 
174
                                        set plusmenu [::amsnplus::create_chat_menu $win]
 
175
                                        ${win}.menu add cascade -label "Plus!" -menu $plusmenu
 
176
                                }
 
177
                        }
 
178
                }
 
179
 
 
180
        }
 
181
 
 
182
        ###############################################
 
183
        # this creates some commands for editing in the
 
184
        # chat window packed in the edit menu
 
185
        proc edit_menu {event epvar} {
 
186
                upvar 2 evPar newvar
 
187
                set bold [binary format c 2]
 
188
                set italic [binary format c 5]
 
189
                set underline [binary format c 31]
 
190
                set overstrike [binary format c 6]
 
191
                set reset [binary format c 15]
 
192
                set screenshot "/screenshot"
 
193
 
 
194
                if {![catch {tk windowingsystem} wsystem] && $wsystem == "aqua"} {
 
195
                        set key "Command"
 
196
                } else {
 
197
                        set key "Ctrl"
 
198
                }
 
199
 
 
200
                set menu_name $newvar(menu_name)
 
201
                menu ${menu_name}.plusmenu -tearoff 0
 
202
                $newvar(menu_name) add cascade -label "Plus!" -menu ${menu_name}.plusmenu
 
203
                set plusmenu ${menu_name}.plusmenu
 
204
 
 
205
                if { $::amsnplus::config(allow_colours) } {
 
206
                        $plusmenu add command -label "[trans choosecolor]" -command "::amsnplus::choose_color $newvar(window_name)"
 
207
                        $plusmenu add command -label "[trans bold]" -command "::amsnplus::insert_text $newvar(window_name) $bold" -accelerator "${key}+B"
 
208
                        $plusmenu add command -label "[trans italic]" -command "::amsnplus::insert_text $newvar(window_name) $italic" -accelerator "${key}+I"
 
209
                        $plusmenu add command -label "[trans underline]" -command "::amsnplus::insert_text $newvar(window_name) $underline" -accelerator "${key}+U"
 
210
                        $plusmenu add command -label "[trans overstrike]" -command "::amsnplus::insert_text $newvar(window_name) $overstrike" -accelerator "${key}+O"
 
211
                        $plusmenu add command -label "[trans reset]" -command "::amsnplus::insert_text $newvar(window_name) $reset" -accelerator "${key}+R"
 
212
                }
 
213
 
 
214
                $plusmenu add command -label "[trans screenshot]" -command "::amsnplus::insert_text $newvar(window_name) $screenshot"
 
215
                if {$::amsnplus::config(allow_quicktext)} {
 
216
                        $plusmenu add separator
 
217
                        #Menu item to edit the currents quick texts
 
218
                        $plusmenu add command -label "[trans quicktext]" -command "::amsnplus::qtconfig"
 
219
                        set i 0
 
220
                        #Show all the currents quick texts in the menu
 
221
                        foreach {key txt} $::amsnplus::config(quick_text) {
 
222
                                $plusmenu add command -label $txt -command "::amsnplus::insert_text $newvar(window_name) /$key"
 
223
                        }
 
224
                }
 
225
        }
 
226
 
 
227
 
 
228
 
 
229
        #//////////////////////////////////////////////////////////////////////////
 
230
        #                      GENERAL PURPOSE PROCEDURES
 
231
        #//////////////////////////////////////////////////////////////////////////
 
232
 
 
233
        ###################################################################
 
234
        # this returns the readme content in a variable
 
235
        proc help {} {
 
236
                set dir [::config::getKey amsnpluspluginpath]
 
237
                set channel [open "$dir/readme" "RDONLY"]
 
238
                return "[read $channel]"
 
239
        }
 
240
 
 
241
        ############################################
 
242
        # ::amsnplus::amsn_version                 #
 
243
        # -----------------------------------------#
 
244
        # Verify if the version of aMSN is 0.94    #
 
245
        # Useful if we want to keep compatibility  #
 
246
        ############################################
 
247
        proc amsn_version {} {
 
248
                global version
 
249
                scan $version "%u.%u" y1 y2
 
250
                return [expr {$y1 * 100 + $y2}]
 
251
        }
 
252
 
 
253
        ####################################################
 
254
        # returns 1 if the char is a numbar, otherwise 0
 
255
        proc is_a_number { char } {
 
256
                set clen [string length $char]
 
257
                set i 0
 
258
                while {$i < $clen} {
 
259
                        set digit [string index $char $i]
 
260
                        if {![string match \[0-9\] $digit]} { return 0 }
 
261
                        incr i
 
262
                }
 
263
                return 1
 
264
        }
 
265
 
 
266
        #####################################################
 
267
        # this returns the first word read in a string
 
268
        proc readWord { i msg strlen } {
 
269
                set a $i
 
270
                set str ""
 
271
                while {$a<$strlen} {
 
272
                        set char [string index $msg $a]
 
273
                        if {[string equal $char " "]} {
 
274
                                return $str
 
275
                        }
 
276
                        set str "$str$char"
 
277
                        incr a
 
278
                }
 
279
                return $str
 
280
        }
 
281
 
 
282
        ####################################################################
 
283
        # this is a proc to parse description to state in order to make
 
284
        # more easier to the user to change the state
 
285
        proc descriptionToState { newstate } {
 
286
                if {[string equal $newstate "online"]} { return "NLN" }
 
287
                if {[string equal $newstate "away"]} { return "AWY" }
 
288
                if {[string equal $newstate "busy"]} { return "BSY" }
 
289
                if {[string equal $newstate "rightback"]} { return "BRB" }
 
290
                if {[string equal $newstate "onphone"]} { return "PHN" }
 
291
                if {[string equal $newstate "gonelunch"]} { return "LUN" }
 
292
                if {[string equal $newstate "appearoff"]} { return "HDN" }
 
293
                return $newstate
 
294
        }
 
295
 
 
296
        ###################################################################
 
297
        # this detects if the state user want to change is valid
 
298
        proc stateIsValid { state } {
 
299
                if {[string equal $state "online"]} { return 1 }
 
300
                if {[string equal $state "away"]} { return 1 }
 
301
                if {[string equal $state "busy"]} { return 1 }
 
302
                if {[string equal $state "rightback"]} { return 1 }
 
303
                if {[string equal $state "onphone"]} { return 1 }
 
304
                if {[string equal $state "gonelunch"]} { return 1 }
 
305
                if {[string equal $state "appearoff"]} { return 1 }
 
306
                return 0
 
307
        }
 
308
 
 
309
        ###################################################################
 
310
        # this procs writes msg to the window with chatid and checks the
 
311
        # the config if its a received command (env)
 
312
        proc write_window { chatid msg env {colour "green"} } {
 
313
                ::amsn::WinWrite $chatid $msg $colour
 
314
        }
 
315
 
 
316
 
 
317
 
 
318
        #//////////////////////////////////////////////////////////////////////////
 
319
        #                               QUICK TEXT
 
320
        #//////////////////////////////////////////////////////////////////////////
 
321
 
 
322
        ################################################
 
323
        # this proc lets configure the quick texts
 
324
        proc qtconfig { } {
 
325
 
 
326
                set w .qtconfig
 
327
                #Verify if the window is already opened
 
328
                if {[winfo exists $w]} {
 
329
                        raise $w
 
330
                        return
 
331
                }
 
332
                #Create the window
 
333
                toplevel $w -width 600 -height 400
 
334
                wm title $w "[trans quicktext]"
 
335
 
 
336
                #Text explanation, in frame top.help
 
337
                frame $w.top
 
338
                if {[::amsnplus::amsn_version] <= 94} {
 
339
                        label $w.top.help -text "Here you should configure your quick text, the keyword and the text. \n Then in the chat window, if you do /keyword, \
 
340
                                you'll see the text" -height 2
 
341
                } else {
 
342
                        label $w.top.help -text "[trans qthelp]\n"
 
343
                }
 
344
                pack $w.top.help -side top -expand true
 
345
                pack $w.top -side top -fill y
 
346
 
 
347
                frame $w.middle
 
348
                listbox $w.middle.box -yscrollcommand "$w.middle.ys set" -font splainf -background white -relief flat -highlightthickness 0 -height 10 -width 20 -selectbackground gray
 
349
                scrollbar $w.middle.ys -command "$w.middle.box yview" -highlightthickness 0 -borderwidth 1 -elementborderwidth 2
 
350
                pack $w.middle.ys -side right -fill y
 
351
                pack $w.middle.box -side left -expand true -fill both
 
352
 
 
353
                pack $w.middle -side top -fill both -expand true
 
354
 
 
355
                if { [info exists ::amsnplus::config(quick_text)] } {
 
356
 
 
357
                        foreach {key txt} $::amsnplus::config(quick_text) {
 
358
                                $w.middle.box insert end "/$key -> $txt"
 
359
                        }
 
360
 
 
361
                }
 
362
 
 
363
                frame $w.bottom
 
364
                button $w.bottom.close -text "[trans close]" -command "destroy .qtconfig"
 
365
                button $w.bottom.add -text "[trans add]" -command "::amsnplus::qtconfig_add"
 
366
                button $w.bottom.delete -text "[trans delete]" -command "::amsnplus::qtconfig_delete"
 
367
 
 
368
                pack $w.bottom.close -side right -padx 10 -pady 10
 
369
                pack $w.bottom.add -side left -padx 10 -pady 10
 
370
                pack $w.bottom.delete -side left -padx 10 -pady 10
 
371
 
 
372
                pack $w.bottom -side top -fill y -expand true
 
373
 
 
374
                moveinscreen $w 30
 
375
 
 
376
        }
 
377
 
 
378
 
 
379
        proc qtconfig_add { } {
 
380
 
 
381
                set w .qtconfig_add
 
382
                #Verify if the window is already opened
 
383
                if {[winfo exists $w]} {
 
384
                        raise $w
 
385
                        return
 
386
                }
 
387
                #Create the window
 
388
                toplevel $w -width 340 -height 270
 
389
                wm title $w "[trans quicktext]"
 
390
 
 
391
                frame $w.top
 
392
 
 
393
                frame $w.top.left
 
394
                frame $w.top.right
 
395
 
 
396
                label $w.top.txt -text "[trans edit]"
 
397
                pack $w.top.txt -side top
 
398
 
 
399
                frame $w.top.top
 
400
                label $w.top.top.amsnplusbutton -image [::skin::loadPixmap amsnplusbutton] -relief flat -padx 0 \
 
401
                        -background [::skin::getKey buttonbarbg] -highlightthickness 0 -borderwidth 0 \
 
402
                        -highlightbackground [::skin::getKey buttonbarbg] \
 
403
                        -activebackground [::skin::getKey buttonbarbg]
 
404
                button $w.top.top.boldbutton -text "B" -command "::amsnplus::insert_text $w [binary format c 2] $w.top.right.entry"
 
405
                button $w.top.top.italicbutton -text "I" -command "::amsnplus::insert_text $w [binary format c 5] $w.top.right.entry"
 
406
                button $w.top.top.overstrikebutton -text "S" -command "::amsnplus::insert_text $w [binary format c 6] $w.top.right.entry"
 
407
                button $w.top.top.underlinebutton -text "U" -command "::amsnplus::insert_text $w [binary format c 31] $w.top.right.entry"
 
408
                button $w.top.top.resetbutton -text "R" -command "::amsnplus::insert_text $w [binary format c 15] $w.top.right.entry"
 
409
                pack $w.top.top.amsnplusbutton -side left -padx 5
 
410
                pack $w.top.top.boldbutton -side left -padx 5
 
411
                pack $w.top.top.italicbutton -side left -padx 5
 
412
                pack $w.top.top.overstrikebutton -side left -padx 5
 
413
                pack $w.top.top.underlinebutton -side left -padx 5
 
414
                pack $w.top.top.resetbutton -side left -padx 5
 
415
                pack $w.top.top -side top
 
416
 
 
417
                label $w.top.left.txt -text "[trans keyword]"
 
418
                label $w.top.right.txt -text "[trans text]"
 
419
                pack $w.top.left.txt -side top
 
420
                pack $w.top.right.txt -side top
 
421
 
 
422
                entry $w.top.left.entry -background #FFFFFF
 
423
                entry $w.top.right.entry -background #FFFFFF
 
424
                pack $w.top.left.entry -side top
 
425
                pack $w.top.right.entry -side top
 
426
 
 
427
                pack $w.top.left -side left -fill x -expand true
 
428
                pack $w.top.right -side right -fill x -expand true
 
429
 
 
430
                pack $w.top -side top -fill x -expand true
 
431
 
 
432
                frame $w.bottom
 
433
 
 
434
                button $w.bottom.save -text "[trans save]" -command "::amsnplus::qtconfig_add_save"
 
435
                button $w.bottom.cancel -text "[trans cancel]" -command "destroy $w"
 
436
                pack $w.bottom.save -side right -padx 10 -padx 10
 
437
                pack $w.bottom.cancel -side right -padx 10 -padx 10
 
438
 
 
439
                pack $w.bottom -side top -fill x -expand true
 
440
 
 
441
        }
 
442
 
 
443
 
 
444
        proc qtconfig_add_save { } {
 
445
 
 
446
                set w .qtconfig_add
 
447
 
 
448
                set key [$w.top.left.entry get]
 
449
                set txt [$w.top.right.entry get]
 
450
 
 
451
                if { [string equal $key ""] || [string equal $txt ""] } {
 
452
 
 
453
                } else {
 
454
                        set ::amsnplus::config(quick_text) [lappend ::amsnplus::config(quick_text) "$key" "$txt"]
 
455
                        .qtconfig.middle.box insert end "/$key -> $txt"
 
456
                        destroy $w
 
457
                        ::plugins::save_config
 
458
                }
 
459
 
 
460
        }
 
461
 
 
462
 
 
463
        proc qtconfig_delete { } {
 
464
 
 
465
                set w .qtconfig
 
466
 
 
467
                set selection [$w.middle.box curselection]
 
468
 
 
469
                if { $selection != "" } {
 
470
                        .qtconfig.middle.box delete $selection $selection
 
471
                        set selection [expr $selection * 2 ]
 
472
                        set ::amsnplus::config(quick_text) [lreplace $::amsnplus::config(quick_text) $selection [expr $selection + 1]]
 
473
                        ::plugins::save_config
 
474
                }
 
475
 
 
476
        }
 
477
 
 
478
        ####################################################
 
479
        # returns an rbg color with <num> code
 
480
        proc getColor { num default } {
 
481
                array set colors [list  0  "FFFFFF" \
 
482
                                        1  "000000" \
 
483
                                        2  "00007F" \
 
484
                                        3  "009300" \
 
485
                                        4  "FF0000" \
 
486
                                        5  "7F0000" \
 
487
                                        6  "9C009C" \
 
488
                                        7  "FC7F00" \
 
489
                                        8  "FFFF00" \
 
490
                                        9  "00FC00" \
 
491
                                        10 "009393" \
 
492
                                        11 "00FFFF" \
 
493
                                        12 "2020FC" \
 
494
                                        13 "FF00FF" \
 
495
                                        14 "7F7F7F" \
 
496
                                        15 "D2D2D2" \
 
497
                                        16 "E7E6E4" \
 
498
                                        17 "CFCDD0" \
 
499
                                        18 "FFDEA4" \
 
500
                                        19 "FFAEB9" \
 
501
                                        20 "FFA8FF" \
 
502
                                        21 "B4B4FC" \
 
503
                                        22 "BAFBE5" \
 
504
                                        23 "C1FFA3" \
 
505
                                        24 "FAFDA2" \
 
506
                                        25 "B6B4D7" \
 
507
                                        26 "A2A0A1" \
 
508
                                        27 "F9C152" \
 
509
                                        28 "FF6D66" \
 
510
                                        29 "FF62FF" \
 
511
                                        30 "6C6CFF" \
 
512
                                        31 "68FFC3" \
 
513
                                        32 "8EFF67" \
 
514
                                        33 "F9FF57" \
 
515
                                        34 "858482" \
 
516
                                        35 "6E6B7D" \
 
517
                                        36 "FFA01E" \
 
518
                                        37 "F92611" \
 
519
                                        38 "FF20FF" \
 
520
                                        39 "202BFF" \
 
521
                                        40 "1EFFA5" \
 
522
                                        41 "60F913" \
 
523
                                        42 "FFF813" \
 
524
                                        43 "5E6464" \
 
525
                                        44 "4B494C" \
 
526
                                        45 "D98812" \
 
527
                                        46 "EB0505" \
 
528
                                        47 "DE00DE" \
 
529
                                        48 "0000D3" \
 
530
                                        49 "03CC88" \
 
531
                                        50 "59D80D" \
 
532
                                        51 "D4C804" \
 
533
                                        52 "000268" \
 
534
                                        53 "18171C" \
 
535
                                        54 "944E00" \
 
536
                                        55 "9B0008" \
 
537
                                        56 "980299" \
 
538
                                        57 "01038C" \
 
539
                                        58 "01885F" \
 
540
                                        59 "389600" \
 
541
                                        60 "9A9E15" \
 
542
                                        61 "473400" \
 
543
                                        62 "4D0000" \
 
544
                                        63 "5F0162" \
 
545
                                        64 "000047" \
 
546
                                        65 "06502F" \
 
547
                                        66 "1C5300" \
 
548
                                        67 "544D05" ]
 
549
                if { [info exists colors($num)] } {
 
550
                        return [set colors($num)]
 
551
                } else {
 
552
                        return $default
 
553
                }
 
554
        }
 
555
 
 
556
 
 
557
 
 
558
        #//////////////////////////////////////////////////////////////////////////
 
559
        #                   MULTIPLE FORMATTING TEXT AND COLOR
 
560
        #//////////////////////////////////////////////////////////////////////////
 
561
 
 
562
        ###############################################
 
563
        #This is the proc to be compatible with the new way
 
564
        #in 0.95 to get path of input text (::ChatWindow::GetInputText)
 
565
        proc insert_text {win character {input ""} } {
 
566
                if {[::amsnplus::amsn_version] <= 94} {
 
567
                        $win.f.bottom.left.in.text insert end $character
 
568
                } else {
 
569
                        #if we use tabs then...
 
570
                        if { [::ChatWindow::UseContainer] == 1 } {
 
571
                                set win [::ChatWindow::GetCurrentWindow $win]
 
572
                        }
 
573
                        if { [string equal $input ""] } {
 
574
                                set input [::ChatWindow::GetInputText $win]
 
575
                        }
 
576
                        $input insert end $character
 
577
                }
 
578
        }
 
579
 
 
580
        ###############################################
 
581
        # this adds a button to choose color for our
 
582
        # multi-color text in the chatwindow
 
583
        # now add buttons for multi-format text too
 
584
        proc chat_color_button {event epvar} {
 
585
                if { !$::amsnplus::config(allow_colours) } { return }
 
586
 
 
587
                #get the event vars
 
588
                upvar 2 evPar newvar
 
589
                set amsnplusbutton $newvar(bottom).amsnplus
 
590
                set w $newvar(window_name)
 
591
 
 
592
                #create the widgeds
 
593
                label $amsnplusbutton -image [::skin::loadPixmap amsnplusbutton] -relief flat -padx 3 \
 
594
                        -background [::skin::getKey buttonbarbg] -highlightthickness 0 -borderwidth 0 \
 
595
                        -highlightbackground [::skin::getKey buttonbarbg] -activebackground [::skin::getKey buttonbarbg]
 
596
                set_balloon $amsnplusbutton "[trans multiplecolorsbutton]"
 
597
 
 
598
                #Configure hover button
 
599
                bind $amsnplusbutton <<Button1>> "after 1 ::amsnplus::choose_color $w"
 
600
                bind $amsnplusbutton <Enter> "$amsnplusbutton configure -image [::skin::loadPixmap amsnplusbutton_hover]"
 
601
                bind $amsnplusbutton <Leave> "$amsnplusbutton configure -image [::skin::loadPixmap amsnplusbutton]"
 
602
 
 
603
                #pack the widgeds
 
604
                pack $amsnplusbutton -side left
 
605
        }
 
606
 
 
607
        ############################################
 
608
        # ::amsnplus::setPixmap                    #
 
609
        # -----------------------------------------#
 
610
        # Define the amsnplus pixmaps from the skin#
 
611
        ############################################
 
612
        proc setPixmap {} {
 
613
                        ::skin::setPixmap amsnplusbutton amsnplusbutton.gif
 
614
                        ::skin::setPixmap amsnplusbutton_hover amsnplusbutton_hover.gif
 
615
        }
 
616
 
 
617
        ###############################################
 
618
        # this opens a tk_color_palette to choose an
 
619
        # rgb color in (rrr,ggg,bbb) format
 
620
        # and insert the color code inside the input text
 
621
        proc choose_color { win {input ""} } {
 
622
                set color [tk_chooseColor -parent $win];
 
623
                if {[string equal $color ""]} { return }
 
624
                set color [::amsnplus::hexToRGB [string range $color 1 end]];
 
625
                set code "[binary format c 3]$color"
 
626
                if { [string equal $input ""] } {
 
627
                        ::amsnplus::insert_text $win $code
 
628
                } else {
 
629
                        ::amsnplus::insert_text $win $code $input
 
630
                }
 
631
        }
 
632
 
 
633
        ###############################################
 
634
        # this colours received messages
 
635
        # there are two ways to colorize text:
 
636
        #   - preset colors -> (!FC<num>) or (!FG<num>) for background -> there are from 0 to 15
 
637
        #   - any colour -> (r,g,b) or (r,g,b),(r,g,b) to add background -> palette to choose (take a look at tk widgeds)
 
638
        proc parse_colours_and_sounds {event epvar} {
 
639
                if { !$::amsnplus::config(allow_colours) } { return }
 
640
                upvar 2 message msg
 
641
                upvar 2 chatid chatid
 
642
                if {[::amsnplus::amsn_version] <= 94} {
 
643
                        set fontformat [::config::getKey mychatfont]
 
644
                } else {
 
645
                        upvar 2 evPar newvar
 
646
                        set fontformat $newvar(fontformat)
 
647
                }
 
648
                set color [lindex $fontformat 2]
 
649
                set style [lindex $fontformat 1]
 
650
                set font [lindex $fontformat 0]
 
651
                set strlen [string length $msg]
 
652
                set i 0
 
653
                while {$i<$strlen} {
 
654
                        set char [string index $msg $i]
 
655
                        if {[string equal $char [binary format c 2]]} {
 
656
                                set msg [string replace $msg $i [expr $i - 1] ""]
 
657
                                set strlen [string length $msg]
 
658
                                set str [string range $msg 0 [expr $i - 1]]
 
659
                                set slen [string length $str]
 
660
                                set msg [string replace $msg 0 $slen ""]
 
661
                                set i -1
 
662
                                set strlen [string length $msg]
 
663
                                set customfont [list $font $style $color]
 
664
                                ::amsn::WinWrite $chatid $str "user" $customfont
 
665
                                set index [lsearch $style "bold"]
 
666
                                if {![string equal "-1" $index]} {
 
667
                                        set style [lreplace $style $index $index]
 
668
                                } else {
 
669
                                        set style [linsert $style end "bold"]
 
670
                                }
 
671
                        }
 
672
                        if {[string equal $char [binary format c 4]]} {
 
673
                                #predefined sounds
 
674
                                set soundsdir [::config::getKey amsnpluspluginpath]/sounds
 
675
                                set next_char [string index $msg [expr $i + 1]]
 
676
                                if {[string equal "#" $next_char]} {
 
677
                                        play_sound $soundsdir/shello.wav
 
678
                                } elseif {[string equal "E" $next_char]} {
 
679
                                        play_sound $soundsdir/sbye.wav
 
680
                                } elseif {[string equal "!" $next_char]} {
 
681
                                        play_sound $soundsdir/sbrb.wav
 
682
                                } elseif {[string equal "\$" $next_char]} {
 
683
                                        play_sound $soundsdir/sdoh.wav
 
684
                                } elseif {[string equal "2" $next_char]} {
 
685
                                        play_sound $soundsdir/sboring.wav
 
686
                                } elseif {[string equal "5" $next_char]} {
 
687
                                        play_sound $soundsdir/smad.wav
 
688
                                } elseif {[string equal "9" $next_char]} {
 
689
                                        play_sound $soundsdir/somg.wav
 
690
                                } elseif {[string equal "%" $next_char]} {
 
691
                                        play_sound $soundsdir/skiss.wav
 
692
                                } elseif {[string equal "\"" $next_char]} {
 
693
                                        play_sound $soundsdir/sevillaugh.wav
 
694
                                } elseif {[string equal "J" $next_char]} {
 
695
                                        play_sound $soundsdir/sevil.wav
 
696
                                } elseif {[string equal "*" $next_char]} {
 
697
                                        play_sound $soundsdir/scomeon.wav
 
698
                                } elseif {[string equal "L" $next_char]} {
 
699
                                        play_sound $soundsdir/sright.wav
 
700
                                } elseif {[string equal "&" $next_char]} {
 
701
                                        play_sound $soundsdir/strek.wav
 
702
                                } elseif {[string equal "@" $next_char]} {
 
703
                                        play_sound $soundsdir/sdanger.wav
 
704
                                } elseif {[string equal "'" $next_char]} {
 
705
                                        play_sound $soundsdir/sapplause.wav
 
706
                                } elseif {[string equal "+" $next_char]} {
 
707
                                        play_sound $soundsdir/swoow.wav
 
708
                                } elseif {[string equal "," $next_char]} {
 
709
                                        play_sound $soundsdir/syawnt.wav
 
710
                                }
 
711
                                set msg [string replace $msg $i [expr $i + 1] ""]
 
712
                                set i -1
 
713
                        }
 
714
                        if {[string equal $char [binary format c 5]]} {
 
715
                                set msg [string replace $msg $i [expr $i - 1] ""]
 
716
                                set strlen [string length $msg]
 
717
                                set str [string range $msg 0 [expr $i - 1]]
 
718
                                set slen [string length $str]
 
719
                                set msg [string replace $msg 0 $slen ""]
 
720
                                set i -1
 
721
                                set strlen [string length $msg]
 
722
                                set customfont [list $font $style $color]
 
723
                                ::amsn::WinWrite $chatid $str "user" $customfont
 
724
                                set index [lsearch $style "italic"]
 
725
                                if {![string equal "-1" $index]} {
 
726
                                        set style [lreplace $style $index $index]
 
727
                                } else {
 
728
                                        set style [linsert $style end "italic"]
 
729
                                }
 
730
                        }
 
731
                        if {[string equal $char [binary format c 31]]} {
 
732
                                set msg [string replace $msg $i [expr $i - 1] ""]
 
733
                                set strlen [string length $msg]
 
734
                                set str [string range $msg 0 [expr $i - 1]]
 
735
                                set slen [string length $str]
 
736
                                set msg [string replace $msg 0 $slen ""]
 
737
                                set i -1
 
738
                                set strlen [string length $msg]
 
739
                                set customfont [list $font $style $color]
 
740
                                ::amsn::WinWrite $chatid $str "user" $customfont
 
741
                                set index [lsearch $style "underline"]
 
742
                                if {![string equal "-1" $index]} {
 
743
                                        set style [lreplace $style $index $index]
 
744
                                } else {
 
745
                                        set style [linsert $style end "underline"]
 
746
                                }
 
747
                        }
 
748
                        if {[string equal $char [binary format c 6]]} {
 
749
                                set msg [string replace $msg $i [expr $i - 1] ""]
 
750
                                set strlen [string length $msg]
 
751
                                set str [string range $msg 0 [expr $i - 1]]
 
752
                                set slen [string length $str]
 
753
                                set msg [string replace $msg 0 $slen ""]
 
754
                                set i -1
 
755
                                set strlen [string length $msg]
 
756
                                set customfont [list $font $style $color]
 
757
                                ::amsn::WinWrite $chatid $str "user" $customfont
 
758
                                set index [lsearch $style "overstrike"]
 
759
                                if {![string equal "-1" $index]} {
 
760
                                        set style [lreplace $style $index $index]
 
761
                                } else {
 
762
                                        set style [linsert $style end "overstrike"]
 
763
                                }
 
764
                        }
 
765
                        if {[string equal $char [binary format c 15]]} {
 
766
                                set msg [string replace $msg $i [expr $i - 1] ""]
 
767
                                set strlen [string length $msg]
 
768
                                set str [string range $msg 0 [expr $i - 1]]
 
769
                                set slen [string length $str]
 
770
                                set msg [string replace $msg 0 $slen ""]
 
771
                                set i -1
 
772
                                set strlen [string length $msg]
 
773
                                set customfont [list $font $style $color]
 
774
                                ::amsn::WinWrite $chatid $str "user" $customfont
 
775
                                set style [list]
 
776
                        }
 
777
                        if {[string equal $char [binary format c 3]]} {
 
778
                                #predefined colors format
 
779
                                if {[::amsnplus::is_a_number [string index $msg [expr $i + 1]]]} {
 
780
                                        if {[::amsnplus::is_a_number [string index $msg [expr $i + 2]]]} {
 
781
                                                set new_color [string range $msg [expr $i + 1] [expr $i + 2]]
 
782
                                                set msg [string replace $msg $i [expr $i + 1] ""]
 
783
                                                set strlen [string length $msg]
 
784
                                        } else {
 
785
                                                set new_color [string index $msg [expr $i + 1]]
 
786
                                                set msg [string replace $msg $i $i ""]
 
787
                                                set strlen [string length $msg]
 
788
                                        }
 
789
                                        set str [string range $msg 0 [expr $i - 1]]
 
790
                                        set slen [string length $str]
 
791
                                        set msg [string replace $msg 0 $slen ""]
 
792
                                        set i -1
 
793
                                        set strlen [string length $msg]
 
794
                                        set customfont [list $font $style $color]
 
795
                                        ::amsn::WinWrite $chatid $str "user" $customfont
 
796
                                        if {$new_color < 68 && $new_color >= 0} {
 
797
                                                set color [::amsnplus::getColor $new_color $color]
 
798
                                        }
 
799
                                #(rrr,ggg,bbb) format
 
800
                                }  elseif {[::amsnplus::is_a_number [string range $msg [expr $i + 2] [expr $i + 4]]]} {
 
801
                                        if {[::amsnplus::is_a_number [string range $msg [expr $i + 6] [expr $i + 8]]]} {
 
802
                                                if {[::amsnplus::is_a_number [string range $msg [expr $i + 10] [expr $i + 12]]]} {
 
803
                                                        set rgb [string range $msg [expr $i + 1] [expr $i + 12]]
 
804
                                                        set msg [string replace $msg $i [expr $i + 12] ""]
 
805
                                                        set strlen [string length $msg]
 
806
                                                        set str [string range $msg 0 [expr $i - 1]]
 
807
                                                        set slen [string length $str]
 
808
                                                        set msg [string replace $msg 0 $slen ""]
 
809
                                                        set i -1
 
810
                                                        set strlen [string length $msg]
 
811
                                                        set customfont [list $font $style $color]
 
812
                                                        ::amsn::WinWrite $chatid $str "user" $customfont
 
813
                                                        set color [::amsnplus::RGBToHex $rgb]
 
814
                                                }
 
815
                                        }
 
816
                                }
 
817
                        }
 
818
                        incr i
 
819
                }
 
820
                if {[::amsnplus::amsn_version] <= 94} {
 
821
                        set customfont [list $font $style $color]
 
822
                        ::amsn::WinWrite $chatid $msg "user" $customfont
 
823
                        set msg ""
 
824
                } else {
 
825
                        set newvar(fontformat) [list $font $style $color]
 
826
                }
 
827
        }
 
828
 
 
829
        ###############################################
 
830
        # this proc converts rgb colours into hex colours
 
831
        proc RGBToHex { colour } {
 
832
                scan $colour "(%3u,%3u,%3u)" red green blue
 
833
                return [format "%02X%02X%02X" \
 
834
                        $red $green $blue]
 
835
        }
 
836
 
 
837
        ################################################
 
838
        # this roc converts hex colours into rgb colours
 
839
        proc hexToRGB { colour } {
 
840
                scan $colour "%2x%2x%2x" red green blue
 
841
                return "($red,$green,$blue)"
 
842
        }
 
843
 
 
844
        #//////////////////////////////////////////////////////////////////////////
 
845
        #                            SENDING COMMANDS
 
846
        #//////////////////////////////////////////////////////////////////////////
 
847
 
 
848
        ################################################
 
849
        # this proc add external commands to amsnplus
 
850
        # (useful for other plugins)
 
851
        proc add_command { keyword proc parameters {win_name 0} {chatid 0} } {
 
852
                set ::amsnplus::external_commands($keyword) [list $proc $parameters $win_name $chatid]
 
853
        }
 
854
 
 
855
        #####################################################
 
856
        # this looks chat text for a command
 
857
        # if found, executes what command is supposed to do
 
858
        proc parseCommand {event epvar} {
 
859
                if { !$::amsnplus::config(allow_commands) } { return 0 }
 
860
                upvar 2 nick nick
 
861
                upvar 2 msg msg
 
862
                upvar 2 chatid chatid
 
863
                upvar 2 win_name win_name
 
864
                upvar 2 fontfamily fontfamily
 
865
                upvar 2 fontcolor fontcolor
 
866
                upvar 2 fontstyle fontstyle
 
867
                set strlen [string length $msg]
 
868
                set sound [binary format c 4]
 
869
                set i 0
 
870
 
 
871
                if { [string equal [string index $msg 0] "/"] } {
 
872
                        set char [::amsnplus::readWord $i $msg $strlen]
 
873
                        #check for the quick texts
 
874
                        if {$::amsnplus::config(allow_quicktext)} {
 
875
                                foreach {key txt} $::amsnplus::config(quick_text) {
 
876
                                        if {[string equal $char "/$key"] && ![string equal $char "/"]} {
 
877
                                                set clen [string length $char]
 
878
                                                set msg [string replace $msg $i [expr $i + $clen] $txt]
 
879
                                                set strlen [string length $msg]
 
880
                                                set qtlen [string length $txt]
 
881
                                                set i [expr $i + $qtlen]
 
882
                                                return
 
883
                                        }
 
884
                                }
 
885
                        }
 
886
                        #check for the external_commands
 
887
                        set keyword [string replace $char 0 0 ""]
 
888
                        if {[info exists ::amsnplus::external_commands($keyword)]} {
 
889
                                set clen [string length $char]
 
890
                                set msg [string replace $msg $i [expr $i + $clen]]
 
891
                                set strlen [string length $msg]
 
892
                                set kwdlist $::amsnplus::external_commands($keyword)
 
893
                                set proc [lindex $kwdlist 0]
 
894
                                set parameters [lindex $kwdlist 1]
 
895
                                set values ""
 
896
                                set j 0
 
897
                                while { $j < $parameters } {
 
898
                                        set values [append values [::amsnplus::readWord $i $msg $strlen]]
 
899
                                        incr j
 
900
                                }
 
901
                                if {[string equal $values ""]} {
 
902
                                        if {[lindex $kwdlist 2]} {
 
903
                                                if {[lindex $kwdlist 3]} {
 
904
                                                        $proc $win_name $chatid
 
905
                                                } else {
 
906
                                                        $proc $win_name
 
907
                                                }
 
908
                                        } else {
 
909
                                                if {[lindex $kwdlist 3]} {
 
910
                                                        $proc $chatid
 
911
                                                } else {
 
912
                                                        $proc
 
913
                                                }
 
914
                                        }
 
915
                                } else {
 
916
                                        if {[lindex $kwdlist 2]} {
 
917
                                                if {[lindex $kwdlist 3]} {
 
918
                                                        $proc $win_name $chatid $values
 
919
                                                } else {
 
920
                                                        $proc $win_name $values
 
921
                                                }
 
922
                                        } else {
 
923
                                                if {[lindex $kwdlist 3]} {
 
924
                                                        $proc $chatid $values
 
925
                                                } else {
 
926
                                                        $proc $values
 
927
                                                }
 
928
                                        }
 
929
                                }
 
930
                                set msg ""
 
931
                        }
 
932
                        #amsnplus commands
 
933
                        if {[string equal $char "/all"]} {
 
934
                                set msg [string replace $msg $i [expr $i + 4] ""]
 
935
                                set strlen [string length $msg]
 
936
                                foreach window $::ChatWindow::windows {
 
937
                                        set chat_id [::ChatWindow::Name $win_name]
 
938
                                        ::amsn::MessageSend $window 0 $msg
 
939
                                }
 
940
                                set msg ""
 
941
                        } elseif {[string equal $char "/shello"]} {
 
942
                                set msg [append "" $sound "#" [binary format c 3] "7Hello!"]
 
943
                        } elseif {[string equal $char "/sbye"]} {
 
944
                                set msg [append "" $sound "E" [binary format c 3] "12Bye"]
 
945
                        } elseif {[string equal $char "/sbrb"]} {
 
946
                                set msg [append "" $sound "!" [binary format c 3] "10Be right back"]
 
947
                        } elseif {[string equal $char "/sdoh"]} {
 
948
                                set msg [append "" $sound "\$" [binary format c 3] "4I'm so " [binary format c 2] "stupid" [binary format c 2]]
 
949
                        } elseif {[string equal $char "/sboring"]} {
 
950
                                set msg [append  "" $sound "2" [binary format c 3] "5You're boring! :)"]
 
951
                        } elseif {[string equal $char "/smad"]} {
 
952
                                set msg [append "" $sound "5" [binary format c 3] "14Are you mad?!?"]
 
953
                        } elseif {[string equal $char "/somg"]} {
 
954
                                set msg [append "" $sound "9" [binary format c 3] "4Oh my " [binary format c 2] "God" [binary format c 2]]
 
955
                        } elseif {[string equal $char "/skiss"]} {
 
956
                                set msg [append "" $sound "%" [binary format c 3] "13XxxxXxxxX"]
 
957
                        } elseif {[string equal $char "/sevillaugh"]} {
 
958
                                set msg [append "" $sound "\"" [binary format c 3] "4Mua" [binary format c 3] "5ha" [binary format c 3] "4ha" [binary format c 3] "5ha" [binary format c 3] "4ha" [binary format c 3] "5!"]
 
959
                        } elseif {[string equal $char "/sevil"]} {
 
960
                                set msg [append "" $sound "J" [binary format c 3] "1:\[ :\[ :\["]
 
961
                        } elseif {[string equal $char "/scomeon"]} {
 
962
                                set msg [append "" $sound "*" [binary format c 3] "7Come on!"]
 
963
                        } elseif {[string equal $char "/sright"]} {
 
964
                                set msg [append "" $sound "L" [binary format c 3] "6Right..."]
 
965
                        } elseif {[string equal $char "/strek"]} {
 
966
                                set msg [append "" $sound "&" [binary format c 3] "12Live long and prosper"]
 
967
                        } elseif {[string equal $char "/sdanger"]} {
 
968
                                set msg [append "" $sound "@" [binary format c 3] "2My" [binary format c 3] "55patience " [binary format c 3] "2has its limits" [binary format c 3] "13..." ]
 
969
                        } elseif {[string equal $char "/sapplause"]} {
 
970
                                set msg [append "" $sound "'(h5)(h5)(h5)(h5)(h5)"]
 
971
                        } elseif {[string equal $char "/swoow"]} {
 
972
                                set msg [append "" $sound "+" [binary format c 3] "45" [binary format c 2] "Wooooow!"]
 
973
                        } elseif {[string equal $char "/syawn"]} {
 
974
                                set msg [append "" $sound "," [binary format c 3] "57I'm tired |-)"]
 
975
                        } elseif {[string equal $char "/screenshot"]} {
 
976
                                set msg [string replace $msg $i [expr $i + 11] ""]
 
977
                                set strlen [string length $msg]
 
978
                                global HOME
 
979
                                set shotpng [file join $HOME "screenshot.png"]
 
980
                                set time_wait [::amsnplus::readWord $i $msg $strlen]
 
981
 
 
982
                                #wait if asked
 
983
                                if {![string equal $time_wait ""]} {
 
984
                                        after [expr $time_wait*1000]
 
985
                                }
 
986
 
 
987
                                #check platform and use utility form this one
 
988
                                global tcl_platform
 
989
                                if {![catch {tk windowingsystem} wsystem] && $wsystem == "aqua"} {
 
990
                                        set file ""
 
991
                                } elseif {$tcl_platform(platform) == "windows"} {
 
992
                                        set shotbmp [file nativename [file join $HOME "screenshot.bmp"]]
 
993
                                        plugins_log "aMSN Plus" "BMP is $shotbmp"       
 
994
                                        if { [catch {exec [file join [::config::getKey amsnpluspluginpath] "snapshot.exe"] "$shotbmp"} res] } {
 
995
                                                plugins_log "aMSN Plus"  "execution failed : $res"
 
996
                                                set file ""
 
997
                                        }
 
998
                                        set file [::picture::Convert $shotbmp $shotpng]
 
999
                                        file delete $shotbmp
 
1000
                                } elseif {$tcl_platform(platform) == "unix"} {
 
1001
                                        set file "$shotpng"
 
1002
                                        if { [catch {exec [file join [::config::getKey amsnpluspluginpath] "snapshot"] "$shotpng"} res] } {
 
1003
                                                plugins_log "aMSN Plus"  "execution failed : $res"
 
1004
                                                set file ""
 
1005
                                        }
 
1006
                                }
 
1007
 
 
1008
                                #send the scheenshot if it had been done!
 
1009
                                if {![string equal $file ""]} {
 
1010
                                        ::amsn::FileTransferSend $win_name $file
 
1011
                                } else {
 
1012
                                        ::amsnplus::write_window $chatid "[trans screenshoterr]"
 
1013
                                }
 
1014
                                set msg ""
 
1015
                        } elseif {[string equal $char "/add"]} {
 
1016
                                set msg [string replace $msg $i [expr $i + 4] ""]
 
1017
                                set strlen [string length $msg]
 
1018
                                set userlogin [::amsnplus::readWord $i $msg $strlen]
 
1019
                                set llen [string length $userlogin]
 
1020
                                set msg [string replace $msg $i [expr $i + $llen] ""]
 
1021
                                ::MSN::addUser $userlogin
 
1022
                        } elseif {[string equal $char "/addgroup"]} {
 
1023
                                set msg [string replace $msg $i [expr $i + 9] ""]
 
1024
                                set strlen [string length $msg]
 
1025
                                set groupname $msg
 
1026
                                set msg ""
 
1027
                                ::groups::Add $groupname
 
1028
                                if {[::amsnplus::amsn_version] <= 94} {
 
1029
                                        ::amsnplus::write_window $chatid "\nAdded group $groupname" 0
 
1030
                                } else {
 
1031
                                        ::amsnplus::write_window $chatid "[trans groupadded $groupname]" 0
 
1032
                                }
 
1033
                        } elseif {[string equal $char "/block"]} {
 
1034
                                set msg [string replace $msg $i [expr $i + 6] ""]
 
1035
                                set strlen [string length $msg]
 
1036
                                set user_login [::amsnplus::readWord $i $msg $strlen]
 
1037
                                set ulen [string length $user_login]
 
1038
                                set msg [string replace $msg $i [expr $i + $ulen] ""]
 
1039
                                set strlen [string length $msg]
 
1040
                                set nick [::abook::getNick $user_login]
 
1041
                                ::MSN::blockUser $user_login [urlencode $nick]
 
1042
                        } elseif {[string equal $char "/clear"]} {
 
1043
                                set container [split ::$ChatWindow::msg_windows($chatid) "."]
 
1044
                                set container ".[lindex $container 1]"
 
1045
                                set msg [string replace $msg $i [expr $i + 6] ""]
 
1046
                                set strlen [string length $msg]
 
1047
                                if { [::ChatWindow::UseContainer] } {
 
1048
                                        set chat_win $container
 
1049
                                } else {
 
1050
                                        set chat_win $::ChatWindow::msg_windows($chatid)
 
1051
                                }
 
1052
                                ::ChatWindow::Clear $chat_win
 
1053
                        } elseif {[string equal $char "/delete"]} {
 
1054
                                set msg [string replace $msg $i [expr $i + 7] ""]
 
1055
                                set strlen [string length $msg]
 
1056
                                set user_login [::amsnplus::readWord $i $msg $strlen]
 
1057
                                set ulen [string length $user_login]
 
1058
                                set msg [string replace $msg $i [expr $i + $ulen] ""]
 
1059
                                set strlen [string length $msg]
 
1060
                                ::MSN::deleteUser $user_login
 
1061
                                if {[::amsnplus::amsn_version] <= 94} {
 
1062
                                        ::amsnplus::write_window $chatid "\nDeleted contact $user_login" 0
 
1063
                                } else {
 
1064
                                        ::amsnplus::write_window $chatid "[trans groupdeleted $user_login]" 0
 
1065
                                }
 
1066
                        } elseif {[string equal $char "/deletegroup"]} {
 
1067
                                set msg [string replace $msg $i [expr $i + 12] ""]
 
1068
                                set strlen [string length $msg]
 
1069
                                set groupname $msg
 
1070
                                set msg ""
 
1071
                                ::groups::Delete [::groups::GetId $groupname]
 
1072
                                if {[::amsnplus::amsn_version] <= 94} {
 
1073
                                        ::amsnplus::write_window $chatid "\nDeleted group $groupname" 0
 
1074
                                } else {
 
1075
                                        ::amsnplus::write_window $chatid "[trans groupdeleted $groupname]" 0
 
1076
                                }
 
1077
                        } elseif {[string equal $char "/help"]} {
 
1078
                                set msg [string replace $msg $i [expr $i + 5] ""]
 
1079
                                set strlen [string length $msg]
 
1080
                                set help [::amsnplus::help]
 
1081
                                ::amsnplus::write_window $chatid "\n$help" 0
 
1082
                        } elseif {[string equal $char "/info"]} {
 
1083
                                set msg [string replace $msg $i [expr $i + 5] ""]
 
1084
                                set strlen [string length $msg]
 
1085
                                set field [::amsnplus::readWord $i $msg $strlen]
 
1086
                                set lfield [string length $field]
 
1087
                                set msg [string replace $msg $i [expr $i + $lfield] ""]
 
1088
                                set strlen [string length $msg]
 
1089
                                if {[string equal $field "color"]} {
 
1090
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1091
                                                ::amsnplus::write_window $chatid "\nYour color is: $fontcolor" 0
 
1092
                                        } else {
 
1093
                                                ::amsnplus::write_window $chatid "[trans ccolor $fontcolor]" 0
 
1094
                                        }
 
1095
                                } elseif {[string equal $field "font"]} {
 
1096
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1097
                                                ::amsnplus::write_window $chatid "\nYour font is: $fontfamily" 0
 
1098
                                        } else {
 
1099
                                                ::amsnplus::write_window $chatid "[trans cfont $fontfamily]" 0
 
1100
                                        }
 
1101
                                } elseif {[string equal $field "nick"]} {
 
1102
                                        set nick [::abook::getPersonal nick]
 
1103
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1104
                                                ::amsnplus::write_window $chatid "\nYour nick is: $nick" 0
 
1105
                                        } else {
 
1106
                                                ::amsnplus::write_window $chatid "[trans cnick $nick]" 0
 
1107
                                        }
 
1108
                                } elseif {[string equal $field "state"]} {
 
1109
                                        set status [::MSN::myStatusIs]
 
1110
                                        set status [::MSN::stateToDescription $status]
 
1111
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1112
                                                ::amsnplus::write_window $chatid "\nYour status is: $status" 0
 
1113
                                        } else {
 
1114
                                                ::amsnplus::write_window $chatid "[trans cstatus $status]" 0
 
1115
                                        }
 
1116
                                } elseif {[string equal $field "style"]} {
 
1117
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1118
                                                ::amsnplus::write_window $chatid "\nYour style is: $fontstyle" 0
 
1119
                                        } else {
 
1120
                                                ::amsnplus::write_window $chatid "[trans cstyle $fontstyle]" 0
 
1121
                                        }
 
1122
                                }
 
1123
                        } elseif {[string equal $char "/invite"]} {
 
1124
                                set msg [string replace $msg $i [expr $i + 7] ""]
 
1125
                                set strlen [string length $msg]
 
1126
                                set userlogin [::amsnplus::readWord $i $msg $strlen]
 
1127
                                set llen [string length $userlogin]
 
1128
                                set msg [string replace $msg $i [expr $i + $llen] ""]
 
1129
                                ::MSN::inviteUser $chatid $userlogin
 
1130
                        } elseif {[string equal $char "/kill"]} {
 
1131
                                set msg ""
 
1132
                                close_cleanup;exit
 
1133
                        } elseif {[string equal $char "/leave"]} {
 
1134
                                set msg ""
 
1135
                                ::MSN::leaveChat $chatid
 
1136
                                if {[::amsnplus::amsn_version] <= 94} {
 
1137
                                        ::amsnplus::write_window $chatid "\nYou've left this conversation" 0
 
1138
                                } else {
 
1139
                                        ::amsnplus::write_window $chatid "[trans cleave]" 0
 
1140
                                }
 
1141
                        } elseif {[string equal $char "/login"]} {
 
1142
                                set msg [string replace $msg $i [expr $i + 6] ""]
 
1143
                                set strlen [string length $msg]
 
1144
                                ::MSN::connect
 
1145
                        } elseif {[string equal $char "/logout"]} {
 
1146
                                set msg ""
 
1147
                                ::MSN::logout
 
1148
                        } elseif {[string equal $char "/nick"]} {
 
1149
                                set msg [string replace $msg $i [expr $i + 5] ""]
 
1150
                                set strlen [string length $msg]
 
1151
                                set nick $msg
 
1152
                                set nlen [string length $nick]
 
1153
                                set msg ""
 
1154
                                if {[info args ::MSN::changeName] == [list "newname" "update"] } {
 
1155
                                        ::MSN::changeName $nick
 
1156
                                } else {
 
1157
                                        ::MSN::changeName [::config::getKey login] $nick
 
1158
                                }
 
1159
                                if {[string equal $::version "0.95"]} {
 
1160
                                        ::amsnplus::write_window $chatid "[trans cnewnick $nick]" 0
 
1161
                                } else {
 
1162
                                        ::amsnplus::write_window $chatid "\nYour new nick is: $nick" 0
 
1163
                                }
 
1164
                        } elseif {[string equal $char "/pm"]} {
 
1165
                        set msg [string replace $msg $i [expr $i + 3] ""]
 
1166
                        if { [::config::getKey protocol] >= 11} {
 
1167
                                if { [string length $msg] > 130} {
 
1168
                                        set answer [::amsn::messageBox [trans longpsm] yesno question [trans confirm]]
 
1169
                                        if { $answer == "no" } {
 
1170
                                                set msg ""
 
1171
                                                return
 
1172
                                        }
 
1173
                                }                       
 
1174
                                ::MSN::changePSM $msg
 
1175
                                ::amsnplus::write_window $chatid "\n[trans newpsm $msg]" 0
 
1176
                                set msg ""
 
1177
                        }
 
1178
                        } elseif {[string equal $char "/pm0"]} {
 
1179
                        if { [::config::getKey protocol] >= 11} {
 
1180
                                ::MSN::changePSM ""
 
1181
                                ::amsnplus::write_window $chatid "\n[trans newpsmnone]" 0
 
1182
                                set msg ""
 
1183
                        }
 
1184
                        } elseif {[string equal $char "/qtconfig"]} {
 
1185
                                set msg [string replace $msg $i [expr $i + 9] ""]
 
1186
                                set strlen [string length $msg]
 
1187
                                ::amsnplus::qtconfig
 
1188
                        } elseif {[string equal $char "/sendfile"]} {
 
1189
                                set msg [string replace $msg $i [expr $i + 9] ""]
 
1190
                                set strlen [string length $msg]
 
1191
                                set file [::amsnplus::readWord $i $msg $strlen]
 
1192
                                if {[string equal $file ""]} {
 
1193
                                        ::amsn::FileTransferSend $win_name
 
1194
                                }
 
1195
                                if {![string equal $file ""]} {
 
1196
                                        ::amsn::FileTransferSend $win_name $file
 
1197
                                }
 
1198
                                set msg ""
 
1199
                        } elseif {[string equal $char "/shell"]} {
 
1200
                                set command [string replace $msg $i [expr $i + 6] ""]
 
1201
                                set msg ""
 
1202
                                if {[::amsnplus::amsn_version] <= 94} {
 
1203
                                        ::amsnplus::write_window $chatid "\nExecuting: $command" 0
 
1204
                                } else {
 
1205
                                        ::amsnplus::write_window $chatid "[trans cshell $command]" 0
 
1206
                                }
 
1207
                                set command [linsert [split $command " "] 0 "exec" "--"]
 
1208
                                if {[catch { eval $command } result]} {
 
1209
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1210
                                                ::amsnplus::write_window $chatid "\nYour command is not valid\n$result" 0
 
1211
                                        } else {
 
1212
                                                ::amsnplus::write_window $chatid "[trans cnotvalid]\n$result" 0
 
1213
                                        }
 
1214
                                } else {
 
1215
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1216
                                                ::amsnplus::write_window $chatid "\nThis is the result of the command:\n$result" 0
 
1217
                                        } else {
 
1218
                                                ::amsnplus::write_window $chatid "[trans cresult $result]" 0
 
1219
                                        }
 
1220
                                }
 
1221
                        } elseif {[string equal $char "/shells"]} {
 
1222
                                set command [string replace $msg $i [expr $i + 7] ""]
 
1223
                                set msg ""
 
1224
                                if {[::amsnplus::amsn_version] <= 94} {
 
1225
                                        ::amsnplus::write_window $chatid "\nExecuting: $command" 0
 
1226
                                } else {
 
1227
                                        ::amsnplus::write_window $chatid "[trans cshell $command]" 0
 
1228
                                }
 
1229
                                set command [linsert [split $command " "] 0 "exec" "--"]
 
1230
                                if {[catch { eval $command } result]} {
 
1231
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1232
                                                ::amsnplus::write_window $chatid "\nYour command is not valid\n$result" 0
 
1233
                                        } else {
 
1234
                                                ::amsnplus::write_window $chatid "[trans cnotvalid]\n$result" 0
 
1235
                                        }
 
1236
                                } else {
 
1237
                                        set msg $result
 
1238
                                }
 
1239
                        } elseif {[string equal $char "/speak"]} {
 
1240
                                set msg [string replace $msg $i [expr $i + 6] ""]
 
1241
                                set strlen [string length $msg]
 
1242
                                set userlogin [::amsnplus::readWord $i $msg $strlen]
 
1243
                                set llen [string length $userlogin]
 
1244
                                set msg [string replace $msg $i [expr $i + $llen] ""]
 
1245
                                set strlen [string length $msg]
 
1246
                                ::amsn::chatUser $userlogin
 
1247
                        } elseif {[string equal $char "/state"]} {
 
1248
                                set msg [string replace $msg $i [expr $i + 6] ""]
 
1249
                                set strlen [string length $msg]
 
1250
                                set nstate [::amsnplus::readWord $i $msg $strlen]
 
1251
                                set slen [string length $nstate]
 
1252
                                set msg [string replace $msg $i [expr $i + $slen]]
 
1253
                                set strlen [string length $nick]
 
1254
                                if {[::amsnplus::stateIsValid $nstate]} {
 
1255
                                        set cstate [::amsnplus::descriptionToState $nstate]
 
1256
                                        ::MSN::changeStatus $cstate
 
1257
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1258
                                                ::amsnplus::write_window $chatid "\nNew state is: $nstate" 0
 
1259
                                        } else {
 
1260
                                                ::amsnplus::write_window $chatid "[trans cnewstate $nstate]" 0
 
1261
                                        }
 
1262
                                } else {
 
1263
                                        if {[::amsnplus::amsn_version] <= 94} {
 
1264
                                                ::amsnplus::write_window $chatid "\n$nstate is not valid" 0
 
1265
                                        } else {
 
1266
                                                ::amsnplus::write_window $chatid "[trans cnewstatenotvalid $nstate]" 0
 
1267
                                        }
 
1268
                                }
 
1269
                        } elseif {[string equal $char "/unblock"]} {
 
1270
                                set msg [string replace $msg $i [expr $i + 8] ""]
 
1271
                                set strlen [string length $msg]
 
1272
                                set user_login [::amsnplus::readWord $i $msg $strlen]
 
1273
                                set ulen [string length $user_login]
 
1274
                                set msg [string replace $msg $i [expr $i + $ulen] ""]
 
1275
                                set strlen [string length $msg]
 
1276
                                set nick [::abook::getNick ${user_login}]
 
1277
                                ::MSN::unblockUser ${user_login} [urlencode $nick]
 
1278
                        } elseif {[string equal $char "/whois"]} {
 
1279
                                set msg [string replace $msg $i [expr $i + 6] ""]
 
1280
                                set strlen [string length $msg]
 
1281
                                set user_login [::amsnplus::readWord $i $msg $strlen]
 
1282
                                if {[string equal $user_login ""] || [string equal [::abook::getContactData $user_login nick] ""]} {
 
1283
                                        set user_login [::ChatWindow::Name $win_name]
 
1284
                                }
 
1285
                                set ulen [string length $user_login]
 
1286
                                set msg [string replace $msg $i [expr $i + $ulen] ""]
 
1287
                                set strlen [string length $msg]
 
1288
                                set group [::groups::GetName [::abook::getContactData $user_login group]]
 
1289
                                set nick [::abook::getContactData $user_login nick]
 
1290
                                set client [::abook::getContactData $user_login clientname]
 
1291
                                set os [::abook::getContactData $user_login operatingsystem]
 
1292
                                if {[::amsnplus::amsn_version] <= 94} {
 
1293
                                        ::amsnplus::write_window $chatid "\n$user_login info: $nick $group $client $os" 0
 
1294
                                } else {
 
1295
                                        ::amsnplus::write_window $chatid "[trans cinfo $user_login $nick $group $client $os]" 0
 
1296
                                }
 
1297
                        } else {
 
1298
                                ::amsnplus::write_window $chatid "[trans nosuchcommand $char]"
 
1299
                                set msg ""
 
1300
                        }
 
1301
                }
 
1302
        }
 
1303
 
 
1304
}