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
|
# -*- coding: utf-8 -*-
# Licensed under the MIT license
# http://opensource.org/licenses/mit-license.php
# Copyright 2008, Frank Scholz <coherence@beebits.net>
from gi.repository import Peas
from gi.repository import Gtk
from gi.repository import Totem
from coherence.ui.av_widgets import TreeWidget
from coherence.ui.av_widgets import UDN_COLUMN,UPNP_CLASS_COLUMN,SERVICE_COLUMN
gettext.textdomain("totem")
D_ = gettext.dgettext
_ = gettext.gettext
class UPnPClient(gobject.GObject, Peas.Activatable):
__gtype_name__ = 'UPnPClient'
object = gobject.property(type = gobject.GObject)
def __init__ (self):
self.totem_object = self.object
self.ui = TreeWidget()
self.ui.window.set_shadow_type(gtk.SHADOW_IN)
self.ui.cb_item_right_click = self.button_pressed
self.ui.window.show_all()
selection = self.ui.treeview.get_selection()
selection.set_mode(gtk.SELECTION_MULTIPLE)
def button_pressed(self, widget, event):
if event.button == 3:
x = int(event.x)
y = int(event.y)
try:
row_path,column,_,_ = self.ui.treeview.get_path_at_pos(x, y)
selection = self.ui.treeview.get_selection()
if not selection.path_is_selected(row_path):
self.ui.treeview.set_cursor(row_path,column,False)
print "button_pressed", row_path, (row_path[0],)
iter = self.ui.store.get_iter((row_path[0],))
udn, = self.ui.store.get(iter,UDN_COLUMN)
iter = self.ui.store.get_iter(row_path)
upnp_class,url = self.ui.store.get(iter,UPNP_CLASS_COLUMN,SERVICE_COLUMN)
print udn, upnp_class, url
if(not upnp_class.startswith('object.container') and
not upnp_class == 'root'):
self.create_item_context(has_delete=self.ui.device_has_action(udn,'ContentDirectory','DestroyObject'))
self.context.popup(None,None,None,event.button,event.time)
return 1
except TypeError:
pass
return 1
def create_item_context(self,has_delete=False):
""" create context menu for right click in treeview item"""
def action(menu, text):
selection = self.ui.treeview.get_selection()
model, selected_rows = selection.get_selected_rows()
if text == 'item.delete':
for row_path in selected_rows:
self.ui.destroy_object(row_path)
return
if(len(selected_rows) > 0 and
text ==' item.play'):
row_path = selected_rows.pop(0)
iter = self.ui.store.get_iter(row_path)
url, = self.ui.store.get(iter,SERVICE_COLUMN)
self.totem_object.action_remote(totem.REMOTE_COMMAND_REPLACE,url)
self.totem_object.action_remote(totem.REMOTE_COMMAND_PLAY,url)
for row_path in selected_rows:
iter = self.ui.store.get_iter(row_path)
url, = self.ui.store.get(iter,SERVICE_COLUMN)
self.totem_object.action_remote(totem.REMOTE_COMMAND_ENQUEUE,url)
self.totem_object.action_remote(totem.REMOTE_COMMAND_PLAY,url)
if not hasattr(self, 'context_no_delete'):
self.context_no_delete = gtk.Menu()
# Translators: this refers to a media file
play_menu = gtk.MenuItem(_(u"Play"))
play_menu.connect("activate", action, 'item.play')
# Translators: this refers to a media file
enqueue_menu = gtk.MenuItem(_(u"Enqueue"))
enqueue_menu.connect("activate", action, 'item.enqueue')
self.context_no_delete.append(play_menu)
self.context_no_delete.append(enqueue_menu)
self.context_no_delete.show_all()
if not hasattr(self, 'context_with_delete'):
self.context_with_delete = gtk.Menu()
# Translators: this refers to a media file
play_menu = gtk.MenuItem(_(u"Play"))
play_menu.connect("activate", action, 'item.play')
# Translators: this refers to a media file
enqueue_menu = gtk.MenuItem(_(u"Enqueue"))
enqueue_menu.connect("activate", action, 'item.enqueue')
self.context_with_delete.append(play_menu)
self.context_with_delete.append(enqueue_menu)
self.context_with_delete.append(gtk.SeparatorMenuItem())
# Translators: this refers to a media file
menu = gtk.MenuItem(_(u"Delete"))
menu.connect("activate", action, 'item.delete')
self.context_with_delete.append(menu)
self.context_with_delete.show_all()
if has_delete:
self.context = self.context_with_delete
else:
self.context = self.context_no_delete
def do_activate (self):
self.totem_object.add_sidebar_page ("upnp-coherence", _(u"Coherence DLNA/UPnP Client"), self.ui.window)
def load_and_play(url):
self.totem_object.add_to_playlist_and_play (url, '', True)
self.ui.cb_item_dbl_click = load_and_play
def do_deactivate (self):
self.totem_object.remove_sidebar_page ("upnp-coherence")
|