/usr/share/amsn/plugins/notify/notify.tcl is in amsn-data 0.98.9-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #
# Notify plugin by Yoda-BZH (yodabzh gmail com)
#
# Display contact's login/logout/state changes using notify-send
#
# You need both libnotify-bin and notify-deamon packages installed
#
# Conversion to UTF-8 is handled
#
# TODO:
# * find why there's no dp
# * find why we get a wrong/unexistant dp
# * handle user prefs', if s/he want contact's connection, contact's disco, contact's state changes (partially done)
# * handle email notifications
# * -- add more here --
# * finally clean the code
#
# 2008-05-10
#
# 2008-10-19 :
# * Added "dash hack", thanks to nico@nc - http://www.amsn-project.net/forums/profile.php?mode=viewprofile&u=5798
# * Re-enable sounds on events: http://www.amsn-project.net/forums/viewtopic.php?t=5824&postdays=0&postorder=asc&start=15 , thanks to nico@nc too
# * bumped to version 1.3
# 2009-03-01 :
# * Don't show the event if the user is bloqued (and the "don't show blocked user notification" config is set)
# * Added OS Check
# * Code cleaning
# * Bumped to version 1.4
#
# 2010-03-18
# * Fix UTF8 detection, thanks to bardo <ilbardo gmail.com>
# * Version 1.5
#
namespace eval ::notify {
# variables
variable config
variable configlist
proc initPlugin { dir } {
#log "::notify::initPlugin"
# register the plugin
if { [::OnLinux] || [::OnBSD] || [::OnX11] || [::OnUnix] } {
::plugins::RegisterPlugin "Notify"
# register events
::notify::registerEvents
::config::setKey notifyonlysound 1
# set the default values for config
::notify::configArray
checkForBin "notify-send"
log "Plugin Notify activated" 1
} else {
tk_messageBox -parent .main -title "Warning" -icon warning -type ok -message "This plugin is not aviable on this platform."
}
}
proc deInit { } {
#log "::notify::deInit"
::config::setKey notifyonlysound 0
log "Plugin Notify disactivated" 1
}
proc registerEvents { } {
# ::plugins::RegisterEvent "name" type localProc
::plugins::RegisterEvent "Notify" ChangeState userChangeState
::plugins::RegisterEvent "Notify" chat_msg_received new_message
#::plugins::RegisterEvent "Notify" contactStateChange userChangeState
#::plugins::RegisterEvent "Notify" UserConnect userConnected
}
proc configArray { } {
array set ::notify::config {
notify_send {notify-send}
enable {}
pic_size {32}
notify_header {aMSN: %dispname}
notify_busy {1}
notify_msg {1}
show_nick {1}
debug {0}
}
set ::notify::configlist [list \
[list str "notify send path" notify_send] \
[list bool "enable" enable] \
[list str "Pic size" pic_size ] \
[list str "Header" notify_header ] \
[list bool "Show notifications when busy" notify_busy ] \
[list bool "Notify messages when unfocused" notify_msg ] \
[list bool "Display nicknames instead of e-mail" show_nick ] \
[list bool "Debug" debug ] \
]
}
proc log { mess {force 0}} {
variable config
if { $config(debug) == 1 || $force == 1} {
plugins_log Notify $mess
#status_log "Notify: $mess"
# TODO: when finished, remove status_log, just keep plugins_log
}
}
proc checkForBin { bin } {
variable config
#log "::notify::checkForBin $bin"
if {![catch {exec $bin -v}]} {
set $config(notify_send) "$bin"
} elseif {![catch {exec "/opt/local/bin/$bin" -v}]} {
set $config(notify_send) "/opt/local/bin/$bin"
} elseif {![catch {exec "/usr/bin/$bin" -v}]} {
set $config(notify_send) "/usr/bin/$bin"
} elseif {![catch {exec "/usr/local/bin/$bin" -v}]} {
set $config(notify_send) "/usr/local/bin/$bin"
} elseif {![catch {exec "/sw/bin/$bin" -v}]} {
set $config(notify_send) "/sw/bin/$bin"
} else {
set $config(notify_send) "plop"
}
}
# thx authors of the music plugin
proc exec_notify { txt {email ""} {urgency "normal"} {expire -1} {category "im.received"} {hint ""} } {
global HOME
variable config
#log "exec_notify lvl 1"
set status [::MSN::myStatusIs]
if { $status == "BSY" && $config(notify_busy) != 1} {
log "You are busy, so not disturbing you"
return
}
set notify $config(notify_send)
set urgency "--urgency=$urgency"
if { $expire == -1 } {
set expire [::config::getKey notifytimeout]
}
set expire "--expire-time=$expire"
set nopreview 0
set icon 0
#log "exec_notify lvl 2"
if { $email != "" } {
# see protocol.tcl line ~6500 for this code
set filename [::abook::getContactData $email displaypicfile ""]
set icon "[file join $HOME displaypic cache $email ${filename}].png"
if { "$icon" == "" } {
log "icon is empty, breaking"
set icon "--icon="
#continue;
# TODO: try to find out why there's no DP, and set the NoDP pic
} else {
#log "email check 1: icon is $icon"
set callid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
#log "email check 1.1"
if { [catch {set filesize [file size $icon]} res] } {
log "oops, set filesize returned $res, continue-ing"
set icon "--icon="
# TODO: try to find out why there's no DP, and set the NoDP pic (bis)
#continue
} else {
#log "catch set filesize returned: $res"
#log "email check 1.2"
set context "[binary format i 574][binary format i 2][binary format i $filesize][binary format i 0][binary format i $nopreview]"
#log "email check 2"
set file [ToUnicode [getfilename $icon]]
set file [binary format a550 $file]
set context "${context}${file}\xFF\xFF\xFF\xFF"
#log "email check 3"
#Here we resize the picture and save it in /FT/cache for the preview (we send it and we see it)
create_dir [file join [set ::HOME] notify cache]
if {[catch {set image [image create photo [TmpImgName] -file $icon]}]} {
set image [::skin::getNoDisplayPicture]
}
#log "email check 4"
if {[catch {::picture::ResizeWithRatio $image $config(pic_size) $config(pic_size)} res]} {
#status_log "$res"
}
#log "email check 5"
set file "[file join [set ::HOME] notify cache ${callid}.png]"
if {[catch {::picture::Save $image $file cxpng} res] } {
#status_log "$res"
}
#log "email check 6"
if {$image != "displaypicture_std_none"} {
image delete $image
}
#log "email check 7"
::skin::setPixmap ${callid}.png $file
#log "email check 8"
if { [catch { open $file} fd] == 0 } {
fconfigure $fd -translation {binary binary }
set context "$context[read $fd]"
close $fd
}
#log "email check 9"
set icon "--icon=$file"
#log "email check 10"
}
}
}
#log "exec_notify after email check"
if { "$category" != "" } {
set category "--category=$category"
}
if { "$hint" != "" } {
set hint "--hint=$hint"
}
if { $config(notify_header) == "" } {
set config(notify_header) "aMSN"
}
if { $config(show_nick) == 1} {
set dispname [::abook::getDisplayNick $email]
} else {
set dispname $email
}
set title [ string map [list "%dispname" "$dispname" ] $config(notify_header) ]
#log "plop 1"
#log "plop 2"
#set txt [ string map { "[" "\\[" "]" "\\]" "(" "\\(" ")" "\\)" "\$" "\\\$" "-" "\\\\-" ">" "\\\\>" "<" "\\\\<" } $txt ]
#set title [ string map { "[" "\\[" "]" "\\]" "(" "\\(" ")" "\\)" "\$" "\\\$" "-" "\\\\-" ">" "\\\\>" "<" "\\\\<" } $title ]
set txt [ ::notify::protect $txt ]
set title [ ::notify::protect $title ]
#log "plop 3"
# libnotify WANTS them to be in utf8
#log "We are in ${::env(LANG)}"
if { [string match -nocase "*UTF*" $::env(LANG) ] == 0 } {
set txt [encoding convertto utf-8 $txt]
set title [encoding convertto utf-8 $title]
#log "Converted to UTF8, because we are in ${::env(LANG)}"
}
#log "plop 4"
# thanks music plugin
set cmd [concat [list "exec" $notify $urgency $expire $icon $category "--" "$title" "$txt" ]]
#log "executing $notify $urgency $expire $icon $category $hint \"$title\" \"$txt\""
#log "executing $notify $cmd"
#if { [catch { eval [concat [list "exec"] $notify $urgency $expire $icon $category $hint "\"$title\"" "\"$txt\"" ]} result ] } {}
if { [catch { eval $cmd } result ] } {
log "Error lauching $notify : $result"
} else {
#log "exec_notify: seems good"
}
file delete $file
}
proc protect { txt } {
#return [ string map { "[" "\\[" "]" "\\]" "(" "\\(" ")" "\\)" "\$" "\\\$" "-" "\\\\-" ">" "\\\\>" "<" "\\\\<" } $txt ]
return [ string map { "<" "<" ">" ">" "&" "&" } $txt ]
#return htmlentities $txt
}
proc userChangeState { event epvar } {
#log "userChangeState called"
#upvar 2 $epvar args
#log "userChangeState lvl 1"
#upvar 2 $args(user) user
#log "userChangeState lvl 2"
#upvar 2 $args(substate) substate
#log "userChangeState lvl 3"
upvar 2 user user
#log "userChangeState lvl 1"
upvar 2 substate substate
#log "userChangeState lvl 2"
#upvar 2 oldsubstate oldsubstate
#log "userChangeState lvl 2.1 old substate: $oldsubstate"
# Ignore user if blocked and we don't want blocked notifs
log "Checking if $user is blocked"
if {[::config::getKey no_blocked_notif 0] == 1 && [::MSN::userIsBlocked $user]} {
log "User $user is blocked !"
return
}
# yeah, getting old state !
# Should be FLN for disconnected
set oldstate [::abook::getVolatileData $user state]
#log "Old status is : $oldstate"
set email $user
set username [::abook::getNick $email]
set state [::MSN::stateToDescription $substate]
set state [ trans $state ]
#log "userChangeState email: $email, username: $username, state: $state ($substate)"
switch -- $substate {
"FLN" {
if { [::config::getKey notifyoffline] == 0 } {
log "Preferences says that disconnections should not make an event"
return
}
log "Ok, preferences says that disconnections can be displayed [::config::getKey display_event_disconnect]"
set txt "[trans disconnect $username]"
}
default {
if { $oldstate == "FLN" } {
if { [::config::getKey notifyonline] == 0 } {
log "Preferences says that connections should not make an event"
return
}
set txt "$username [trans logsin]"
} else {
if { [::config::getKey notifystate] == 0 } {
log "Preferences says that states changes should not make an event"
return
}
set txt "[trans changestate $username $state]"
}
}
}
#log "going to exec"
exec_notify "$txt" "$email"
}
proc new_message {event evpar} {
variable config
upvar 2 $evpar newvar
upvar 2 $newvar(msg) msg
upvar 2 $newvar(user) user
set email $user
if { $config(notify_msg) == 1 && ([focus] == "")} {
exec_notify "$msg" "$email"
}
}
# UNUSED
#proc userConnected { event epvar } {
# log "userConnected called"
# #upvar 2 $epvar args
# upvar 2 user user
# log "userConnected lvl 1"
# #upvar 2 $args(user) user
# upvar 2 user_name user_name
# log "userConnected lvl 2"
# #upvar 2 $args(user_name) user_name
# #log "userConnected lvl 3"
#
# set email $user
# set username [::abook::getNick $user_name]
# set username [lindex 1 $username]
# #exec_notify "$username [trans logsin]" "aMSN: $email" "$email"
# exec_notify "$username [trans logsin]" "$email"
#}
}
|