📄 nudge.tcl
字号:
############################################# ::Nudge => Nudges for aMSN ## ====================================== ## Nudge is a kind of notification ## that was introduced in MSN 7 ######################################################################### All nudges related code ############################namespace eval ::Nudge { ############################################### # ::Nudge::Init (dir) # # ------------------------------------------- # # Registration & initialization of the plugin # ############################################### proc Init { dir } { ::plugins::RegisterPlugin Nudge #Register the events to the plugin system ::Nudge::RegisterEvent #Save in a config key where is the Nudge plugin ::config::setKey nudgepluginpath $dir #Get default value for config ::Nudge::config_array #Loads language files ::Nudge::load_nudge_languages $dir #Config to show in configuration window ::Nudge::configlist_values #Load the pictures ::Nudge::setPixmap #Wait 5 seconds after all the plugins are loaded to register #the command /nudge to amsnplus plugin after 5000 "catch {::Nudge::add_command 0 0}" } ##################################### # ::Nudge::RegisterEvent # # --------------------------------- # # Register events to plugin system # ##################################### proc RegisterEvent {} { ::plugins::RegisterEvent Nudge PacketReceived received ::plugins::RegisterEvent Nudge chatwindowbutton sendbutton ::plugins::RegisterEvent Nudge chatmenu itemmenu ::plugins::RegisterEvent Nudge right_menu clitemmenu ::plugins::RegisterEvent Nudge AllPluginsLoaded add_command ::plugins::RegisterEvent Nudge chatwindowbutton blockbutton } ######################################## # ::Nudge::config_array # # -------------------------------------# # Add config array with default values # ######################################## proc config_array {} { array set ::Nudge::config { notify {1} notsentinwin {1} notrecdinwin {1} soundnotsend {1} soundnotrec {1} shake {0} shakes {10} shaketoo {0} addbutton {1} addclmenuitem {0} limit {1} delay {60} } } ######################################## # ::Nudge::configlist_values # # -------------------------------------# # List of items for config window # ######################################## proc configlist_values {} { set ::Nudge::configlist [list \ [list bool "$::Nudge::language(shake_receive)" shake] \ [list bool "$::Nudge::language(shake_send)" shaketoo] \ [list str "\t$::Nudge::language(shake_nudge):" shakes] \ [list bool "$::Nudge::language(popup_nudge)" notify] \ [list bool "$::Nudge::language(notify_send)" notsentinwin] \ [list bool "$::Nudge::language(notify_receive)" notrecdinwin] \ [list bool "$::Nudge::language(sound_send)" soundnotsend] \ [list bool "$::Nudge::language(sound_receive)" soundnotrec] \ [list bool "$::Nudge::language(add_button)" addbutton] \ [list bool "$::Nudge::language(add_clmenuitem)" addclmenuitem] \ [list bool "$::Nudge::language(limit)" limit] \ [list str "\t$::Nudge::language(delay):" delay] \ ] } ######################################## # ::Nudge::load_nudge_languages dir # # -------------------------------------# # Load languages files # # Compatible with aMSN >0.94 # ######################################## proc load_nudge_languages {dir} { #Verify if aMSN version is 0.94 or better if { [::Nudge::version_094] } { #If 0.94, use only english keys because 0.94 is not compatible with langfiles in plugins ::Nudge::language_array_094 } else { #Load lang files set langdir [file join $dir "lang"] set lang [::config::getGlobalKey language] load_lang en $langdir load_lang $lang $langdir #Create array ::Nudge::language ::Nudge::language_array } } ######################################## # ::Nudge::language_array_094 # # -------------------------------------# # Load default english keys in array # # For aMSN 0.94 only # ######################################## proc language_array_094 {} { array set ::Nudge::language [list shake_receive "Shake the window when receiving a nudge" \ shake_send "Shake the window when sending a nudge" \ shake_nudge "Shakes per nudge" \ popup_nudge "Notify nudges with popup-window" \ notify_send "Notify sent nudges in the chatwindow" \ notify_receive "Notify received nudges in the chatwindow" \ sound_send "Play a sound upon sending a nudge" \ sound_receive "Play a sound upon receiving a nudge." \ add_button "Add a button to send a nudge in the chatwindow" \ add_clmenuitem "Add an item to the contactlist popup-menu" \ send_nudge "Send nudge" \ no_nudge_support "You cannot sent a nudge to your contact because he or she doesn't use a client that supports nudges" \ nudge_sent "You have just sent a Nudge" \ limit "Activate Nudge receive limitation" \ delay "Minimum time between 2 nudge from the same contact (in seconds)" \ block_nudge "Block/Unblock Nudges" \ no_nudge_support "You cannot sent a nudge to your contact because he or she doesn't use a client that supports nudges" \ nudge_sent "You have just sent a Nudge" \ ] } ######################################## # ::Nudge::language_array # # -------------------------------------# # Create ::Nudge::language array # # Compatible with lang files # ######################################## proc language_array {} { array set ::Nudge::language [list shake_receive "[trans shake_receive]" \ shake_send "[trans shake_send]" shake_nudge "[trans shake_nudge]" \ popup_nudge "[trans popup_nudge]" notify_send "[trans notify_send]" \ notify_receive "[trans notify_receive]" sound_send "[trans sound_send]" \ sound_receive "[trans sound_receive]" add_button "[trans add_button]" \ add_clmenuitem "[trans add_clmenuitem]" send_nudge "[trans send_nudge]" \ no_nudge_support "[trans no_nudge_support]" nudge_sent "[trans nudge_sent]" \ limit "[trans limit]" delay "[trans delay]" block_nudge "[trans block_nudge]" \ ] } ############################################### # ::Nudge::received event evpar # # ------------------------------------------- # # Is the event handler. Simply checks our # # config and do what it says. # ############################################### proc received { event evpar } { upvar 2 $evpar args upvar 2 $args(chatid) chatid upvar 2 $args(nick) nick upvar 2 $args(msg) msg set timestamp [clock seconds] set lastnudge [::abook::getVolatileData $chatid last_nudge] set auth [::abook::getContactData $chatid auth_nudge] if {$auth == ""} { set auth 1 } if {$lastnudge == ""} { set lastnudge 0 } set lastnudge [expr $timestamp-$lastnudge] #The way to get headers change on 0.95 if {[::Nudge::version_094]} { set header "[::MSN::GetHeaderValue $msg Content-Type]" set ID "[::MSN::GetHeaderValue $msg ID]" } else { set header "[$msg getHeader Content-Type]" set ID "[$msg getField ID]" } #If the user choosed to desactivate nudge receive limitation if {$::Nudge::config(limit) == 0} { set lastnudge [expr $lastnudge+$::Nudge::config(delay)] set auth 1 } if {$header == "text/x-msnmsgr-datacast" && $ID == "1" && $lastnudge > $::Nudge::config(delay) && $auth=="1"} { ::Nudge::log "Start receiving nudge from <[::abook::getDisplayNick $chatid]>" #If the user choosed to have the nudge notified in the window if { $::Nudge::config(notsentinwin) == 1 } { ::ChatWindow::MakeFor $chatid ::Nudge::winwrite $chatid "[trans nudge $nick]!" nudge } #If the user choosed to have a sound-notify if { $::Nudge::config(soundnotrec) == 1 } { ::Nudge::sound } #If the user choosed to have a notify window if { $::Nudge::config(notify) == 1 } { ::Nudge::notify $nick $chatid } #If the user choosed to make the window shake if { $::Nudge::config(shake) == 1 } { #Get the name of the window from the people who sent the nudge set lowuser [string tolower $chatid] set win_name [::ChatWindow::For $lowuser] #Shake that window ::Nudge::shake ${win_name} $::Nudge::config(shakes) } #If Growl plugin is loaded, show the notification, Mac OS X only if { [info commands ::growl::InitPlugin] != "" } { catch {growl post Nudge Nudge [trans nudge $nick] [::growl::getpicture $chatid]} ::Nudge::log "Show growl notification" } ::abook::setVolatileData $chatid last_nudge $timestamp ::Nudge::log "Receiving nudge from <[::abook::getDisplayNick $chatid]> is finished" } } ############################################### # ::Nudge::notify nickname email # # ------------------------------------------- # # Pops-up a notification telling that # # someone has sent you a nudge # ############################################### proc notify { nick email } { #Get a shorter nick-name for the notify window set maxw [expr {[::skin::getKey notifwidth]-20}] set nickname [trunc $nick . $maxw splainf] #Show the notification ::amsn::notifyAdd "Nudge\n[trans nudge $nickname]." "::amsn::chatUser $email" "" plugins ::Nudge::log "Notify window created" } ############################################### # ::Nudge::shake window n # # ------------------------------------------- # # The window $window will 'shake' $n times. # ############################################### proc shake { window n } { #Tab support on 0.95 if {![::Nudge::version_094]} { if {[::ChatWindow::GetContainerFromWindow $window] != ""} { set window [::ChatWindow::GetContainerFromWindow $window] } } #If a strange user decide to use a letter, nothing, or 0, as a number of shake #Rechange the variable to 10 shakes if {![string is digit -strict $n]} { set n "10" set ::Nudge::config(shakes) 10 } #Avoid a bug if the user close the chat window just after pressing the button if {[catch {set geometry [wm geometry $window]}]} { return } set index11 [string first "+" $geometry] set index12 [string first "-" $geometry] if {[expr $index11 > $index12 && $index12 != -1] || $index11 == -1} {set index1 $index12} {set index1 $index11} set index21 [string first "+" $geometry [expr $index1 + 1]] set index22 [string first "-" $geometry [expr $index1 + 1]] if {$index21 == -1} {set index2 $index22} {set index2 $index21} #set index2 [string last "+" $geometry] set x [string range $geometry [expr $index1 + 1] [expr $index2 -1]] set y [string range $geometry [expr $index2 + 1] end] #Make the window shake until we have reached the number of times to shake #I added catch to avoid bug if we close the chatwindow before the end of the nudge for {set i 0} {$i < $n && [winfo exists $window] } {incr i} { catch {wm geometry $window +[expr $x + 10]+[expr $y + 8]} update after 10 catch {wm geometry $window +[expr $x + 15 ]+[expr $y + 1]} update after 10 catch {wm geometry $window +$x+$y} update after 10 } ::Nudge::log "Window shaked $n times" } ################################################ # ::Nudge::sendbutton event epvar # # ------------------------------------------- # # Button to add in the chat window # # When we click on that button, we send a nudge# # to the other contact # ################################################ proc sendbutton { event evpar } { if { $::Nudge::config(addbutton) == 1 } { upvar 2 $evpar newvar set nudgebutton $newvar(bottom).nudge #Create the button with an actual Pixmal #Use after 1 to avoid a bug on Mac OS X when we close the chatwindow before the end of the nudge #Keep compatibility with 0.94 for the getColor if {[::Nudge::version_094]} { label $nudgebutton -image [::skin::loadPixmap nudgebutton] -relief flat -padx 0 \ -background [::skin::getColor background2] -highlightthickness 0 -borderwidth 0 \ -highlightbackground [::skin::getColor background2] -activebackground [::skin::getColor background2]\ } else { label $nudgebutton -image [::skin::loadPixmap nudgebutton] -relief flat -padx 0 \ -background [::skin::getKey buttonbarbg] -highlightthickness 0 -borderwidth 0 \ -highlightbackground [::skin::getKey buttonbarbg] -activebackground [::skin::getKey buttonbarbg]\ } bind $nudgebutton <<Button1>> "after 1 ::Nudge::send_via_queue $newvar(window_name)" #Configure hover button bind $nudgebutton <Enter> "$nudgebutton configure -image [::skin::loadPixmap nudgebutton_hover]" bind $nudgebutton <Leave> "$nudgebutton configure -image [::skin::loadPixmap nudgebutton]" #Define baloon info set_balloon $nudgebutton "$::Nudge::language(send_nudge)" #Pack the button in the right area pack $nudgebutton -side right ::Nudge::log "Nudge button added the new window: $newvar(window_name)" } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -