-
Notifications
You must be signed in to change notification settings - Fork 0
/
infopart.py
102 lines (87 loc) · 3.43 KB
/
infopart.py
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
from qt import QWidget
from qt import PYSIGNAL, SIGNAL
from kdecore import KURL
from kdeui import KMessageBox
from useless.base.util import Url
from useless.kdebase.htmlpart import BaseInfoPart
from useless.kdebase.dcopclient import Kaffeine
from base import get_application_pointer
from base import MyUrl
from infodoc import InfoDoc
#from dialogs import BaseEntityDialog
from dialogs import MainEntityDialog
from dialogs import BaseTagsDialog
from dialogs import AddTagsDialog
from dialogs import RemoveTagsDialog
myurl = MyUrl()
class InfoPart(BaseInfoPart):
def __init__(self, parent, name='InfoPart'):
BaseInfoPart.__init__(self, parent, name=name)
self.doc = InfoDoc(self.app)
def set_info(self, entity):
self.clear_view()
self.app.processEvents()
self.begin()
self.doc.set_info(entity)
# don't know if we need this anymore
# or if we need self.entity = entity
# or maybe self.current_entity = entity
self.entityid = entity.entityid
self.current_entity = entity
self.write(self.doc.output())
self.end()
#self.emit(PYSIGNAL('EntityInfoUpdated'), (entityid,))
####################################################
# the methods in this section map url's to actions #
####################################################
def urlSelected(self, url, button, state, target, args):
if url.find('||') > -1:
self._perform_url_action(url)
else:
self.openURL(KURL(url))
def _perform_url_action(self, url):
parsed = myurl.parse(str(url))
print parsed
action, atype, ident = parsed
if ident.isdigit():
ident = int(ident)
if ident != self.current_entity.entityid:
msg = "ident != current_entity.entityid, %d, %d" \
% (ident, self.current_entity.entityid)
raise RuntimeError, msg
if action == 'edit':
dlg = MainEntityDialog(self.dialog_parent,
dtype='update', entity=self.current_entity)
dlg.show()
elif action == 'delete':
print 'delete selected'
elif action == 'addtag':
dlg = AddTagsDialog(self.dialog_parent, self.current_entity)
dlg.show()
elif action == 'deltag':
dlg = RemoveTagsDialog(self.dialog_parent, self.current_entity)
dlg.show()
elif action == 'play':
print "play", ident
kaffeine = Kaffeine()
entity = self.current_entity
filename = str(entity.extfields['local-filename'].value)
filehandler = self.app.filehandler
dpath = filehandler.main_path / 'downloads'
fullpath = dpath / filename
url = 'file://%s' % fullpath
kaffeine.openURL(url)
elif action == 'download':
print "download", ident
entity = self.current_entity
#print "entity url", entity.url
if entity.url is None:
url = "http://youtube.com/watch?v=%s" % entity.extfields['youtubeid'].value
else:
url = entity.url
url = Url(url)
print "url is", url
self.app.urlhandler.handle_youtube_url(url)
else:
KMessageBox.error(self.dialog_parent,
'Unknown action: %s' % action)