File: MeBeam.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (135 lines) | stat: -rw-r--r-- 3,739 bytes parent folder | download | duplicates (4)
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
# MeBeam.tcl --
# 
#       Interface for MeBeam web based video conferencing.
#
#  Copyright (c) 2007 Mats Bengtsson
#  
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: MeBeam.tcl,v 1.6 2008-03-27 15:15:26 matben Exp $

namespace eval ::MeBeam {
    
    component::define MeBeam "MeBeam web based video conferencing"

    # Where shall the MeBeam menu be?
    set ::config(mebeam,menu-action) 0
    set ::config(mebeam,menu-roster) 1
}

proc ::MeBeam::Init {} {
    global  config

    if {$config(mebeam,menu-action)} {
	set menuDef [list command "Invite MeBeam" {::MeBeam::Cmd} {} {}]
	::JUI::RegisterMenuEntry action $menuDef
	
	::hooks::register menuPostCommand         ::MeBeam::MainMenuPostHook
	::hooks::register menuChatActionPostHook  ::MeBeam::ChatMenuPostHook
    }
    if {$config(mebeam,menu-roster)} {
	# TRANSLATORS: check http://www.mebeam.com/
	set mDef [list command "Invite MeBeam" {[mc "Invite MeBeam"]} {::MeBeam::RosterCmd $jid3}]
	set mType {"Invite MeBeam" {user available}}
	::Roster::RegisterPopupEntry $mDef $mType    
    }    
    
    variable url "http://www.mebeam.com/coccinella.php?ccn_"
    
    component::register MeBeam
}

proc ::MeBeam::RosterCmd {jid} {    
    Start $jid
}

proc ::MeBeam::MainMenuPostHook {type m} {
    
    if {$type eq "main-action"} {
	::UI::MenuMethod $m entryconfigure "Invite MeBeam" -state disabled
	
	# If selected single online roster item.
	if {[::JUI::GetConnectState] eq "connectfin"} {
	    set jidL [::RosterTree::GetSelectedJID]
	    if {[llength $jidL] == 1} {
		set jid [lindex $jidL 0]
		if {[::Jabber::RosterCmd isavailable $jid]} {
		    ::UI::MenuMethod $m entryconfigure "Invite MeBeam" -state normal
		}
	    }
	}
    }
}

# Active chat dialog. This works only for Mac OS X.

proc ::MeBeam::ChatMenuPostHook {m} {
    if {[::JUI::GetConnectState] eq "connectfin"} {
	::UI::MenuMethod $m entryconfigure "Invite MeBeam" -state normal
    }
}

proc ::MeBeam::Cmd {} {

    if {[::JUI::GetConnectState] ne "connectfin"} {
	return
    }
    
    # Active chat dialog. This works only for Mac OS X.
    if {[winfo exists [focus]]} {
	set top [winfo toplevel [focus]]
	set wclass [winfo class $top]
	if {$wclass eq "Chat"} {
	    set dlgtoken [::Chat::GetTokenFrom dlg w $top]
	    set token [::Chat::GetActiveChatToken $dlgtoken]
	    ::Chat::SendText $token [Invite]
	    return
	}
    }
    
    # Selected roster item.
    set jidL [::RosterTree::GetSelectedJID]
    if {[llength $jidL] == 1} {
	set jid [lindex $jidL 0]
	if {[::Jabber::RosterCmd isavailable $jid]} {
	    Start $jid
	}
    }
}

proc ::MeBeam::Start {jid} {
    
    set jid2 [jlib::barejid $jid]
    set mjid2 [jlib::jidmap $jid2]
    set token [::Chat::GetTokenFrom chat jid [jlib::ESC $mjid2]*]
    if {$token ne ""} {
	::Chat::SendText $token [Invite]
    } else {
	::Chat::StartThread $jid2 -message [Invite]
    }
}

proc ::MeBeam::Invite {} {
    variable url
    
    set newurl $url[uuid::uuid generate]
    set str [mc "Please join me for video chat on"]
    append str " "
    append str $newurl
    ::Utils::OpenURLInBrowser $newurl
    
    return $str
}