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

« back to all changes in this revision

Viewing changes to plugins/sayit/sayit.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
#TODO:
 
2
#
 
3
# * have an option to have URL's replaced by "URL" for reading
 
4
# * incomming messages should be queued, now they play through eachother (linux only?) 
 
5
 
 
6
namespace eval ::sayit {
 
7
        variable config
 
8
        variable configlist
 
9
 
 
10
        proc InitPlugin { dir } {
 
11
                if { $::tcl_platform(platform) == "windows" } {
 
12
                        if {[string equal $::version "0.94"]} {
 
13
                                load [file join $dir winutils.dll]
 
14
                        } else {
 
15
                                package require WinUtils
 
16
                        }
 
17
                }
 
18
 
 
19
                ::plugins::RegisterPlugin sayit
 
20
                ::plugins::RegisterEvent sayit chat_msg_received newmessage
 
21
                if { [::plugins::CheckRequirements "0.95"] } {
 
22
                        ::plugins::RegisterEvent sayit ContactListColourBarDrawn draw
 
23
                }
 
24
 
 
25
 
 
26
                array set ::sayit::config {
 
27
                        voice {}
 
28
                        linpath {festival}
 
29
                        snd_server_lin {0}
 
30
                        showswitch {0}
 
31
                        sayiton {1}
 
32
                        notonfocus {1}
 
33
                        unfocusstring {$nickname writes $msg}
 
34
                        junkfilter {0}
 
35
                }
 
36
 
 
37
                set ::sayit::configlist [list \
 
38
                        [list str "Voice (Mac only)"  voice] \
 
39
                        [list str "Path to festival (Linux)"  linpath] \
 
40
                        [list bool "Sound server running (Linux)" snd_server_lin] \
 
41
                        [list bool "Don't say message for focussed windows" notonfocus] \
 
42
                        [list bool "Show switch in contactlist (need 0.95)" showswitch] \
 
43
                        [list str "String to say when unfocused" unfocusstring] \
 
44
                        [list bool "Filter out smileys" junkfilter] \
 
45
                ]
 
46
        }
 
47
 
 
48
        proc newmessage {event evpar} {
 
49
                variable config
 
50
                upvar 2 $evpar newvar
 
51
                upvar 2 $newvar(msg) msg
 
52
                upvar 2 $newvar(user) user
 
53
 
 
54
                #Define the 3 variables, email, nickname and message
 
55
                set email $user
 
56
                set nickname [::abook::getDisplayNick $user]
 
57
 
 
58
                if { ($email != [::config::getKey login]) && \
 
59
                        ((!$config(notonfocus)) || ([focus] == "")) && \
 
60
                        ((!$config(showswitch)) || $config(sayiton)) && \
 
61
                        ($msg != "") \
 
62
                } {
 
63
                        # junkfilter
 
64
                        #
 
65
                        # TODO:
 
66
                        #  * Add extra filter level: remove '...' and similar junk.
 
67
 
 
68
                        if { ($config(junkfilter)) } {
 
69
                                foreach smiley [array names ::emotions] {
 
70
                                        while { ([set hit [lsearch $msg $smiley]] != -1) } {
 
71
                                                set msg [lreplace $msg $hit $hit]
 
72
                                        }
 
73
                                }
 
74
                        }
 
75
                        if { (![string compare $msg ""]) } { return }
 
76
                
 
77
                        # if window unfocused, use special string
 
78
                        if { ([focus] == "") } {
 
79
                                set msg [subst $config(unfocusstring)]
 
80
                        }
 
81
 
 
82
                        if { $::tcl_platform(platform) == "windows" } {
 
83
                                after 0 [list WinSayit "$msg"]
 
84
                        } elseif { $::tcl_platform(os)== "Linux" } {
 
85
                                if {$config(snd_server_lin)==1} {
 
86
                                        exec echo "(Parameter.set 'Audio_Method 'Audio_Command)(Parameter.set 'Audio_Command \"esdplay \$FILE\")(Parameter.set 'Audio_Required_Format 'snd)(SayText \"$msg\")" | festival
 
87
                                } else {
 
88
                                        exec echo \"$msg\" | $config(linpath) --tts &
 
89
                                }
 
90
                        } else {
 
91
                                if {$config(voice)!=""} {
 
92
                                        exec say -v $config(voice) $msg
 
93
                                } else {
 
94
                                        exec say $msg
 
95
                                }
 
96
                        }
 
97
                }
 
98
        }
 
99
 
 
100
        proc draw {event evPar} {               
 
101
                upvar 2 $evPar vars
 
102
                variable config
 
103
                if { $config(showswitch) } {
 
104
                        set imag $::pgBuddyTop.mystatus.xxxsayit
 
105
                        if { $config(sayiton) == 1} {
 
106
                                label $imag -image [::skin::loadPixmap bell] -bg [::skin::getKey contactlistbg]
 
107
                        } else {
 
108
                                label $imag -image [::skin::loadPixmap belloff] -bg [::skin::getKey contactlistbg]
 
109
                        }
 
110
                        $imag configure -cursor hand2 -borderwidth 0 -padx 0 -pady 0
 
111
                        $::pgBuddyTop.mystatus window create [$::pgBuddyTop.mystatus index "1.0 lineend"] -window $imag -padx 5 -pady 0
 
112
 
 
113
                        bind $imag <Button1-ButtonRelease> "::sayit::togglespeach"
 
114
                }
 
115
        }
 
116
 
 
117
        proc togglespeach { } {
 
118
                variable config
 
119
                if { $config(sayiton) == 1 } {
 
120
                        set config(sayiton) 0
 
121
                } else {
 
122
                        set config(sayiton) 1
 
123
                }
 
124
                ::cmsn_draw_online
 
125
        }
 
126
}