Merge lp:~stolowski/unity-lens-video/unity-lens-video.previews into lp:unity-lens-video

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 95
Merged at revision: 85
Proposed branch: lp:~stolowski/unity-lens-video/unity-lens-video.previews
Merge into: lp:unity-lens-video
Diff against target: 108 lines (+63/-1)
1 file modified
src/unity-lens-video (+63/-1)
To merge this branch: bzr merge lp:~stolowski/unity-lens-video/unity-lens-video.previews
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Unity Videos lens Pending
Review via email: mp+118720@code.launchpad.net

Commit message

Implementation of previews.

Description of the change

Initial implementation of previews.

To post a comment you must log in.
89. By Paweł Stołowski

Preview: require Gst/GstPbutils 1.0. Combined width, height info hints into "Dimensions" hint with aspect ratio.

90. By Paweł Stołowski

Preview: added 'Size' hint. Changed order of Format & Dimensions hints.

91. By Paweł Stołowski

Preview: use GLib.format_size function instead of custom one.

Revision history for this message
Michal Hruby (mhr3) wrote :

51 + while iter != end_iter:
52 + if model.get_value(iter, 0) == uri:

Linear iteration of the model :/ Not too nice, but hopefully it shouldn't be too much of an issue. s/get_value/get_string/

72 + preview.add_info(Unity.InfoHint.new("dimensions", "Dimensions", None, dimensions))

Please use gettext for the user-visible strings.

GLib.format_size(os.path.getsize(uri[7:]))))

Uris escape some characters, so they don't map exactly to path, this should be fixed.

87 + return Unity.ActivationResponse(goto_uri=uri, handled=2 )

Just because this is python doesn't make it ok to use numeric values for enums :) Anyway, you don't really need to connect to the activated signal here, the activation response will by default return NOT_HANDLED, so unity will run the default handler for the file.

review: Needs Fixing
92. By Paweł Stołowski

Previews: properly handle uri when passing it to os.path.getsize().
Use is_last and get_string when iterating over dee model.

93. By Paweł Stołowski

Previews: added 'Show in folder' action for local videos.

94. By Paweł Stołowski

Previews: display modification time as subtitle.

95. By Paweł Stołowski

Previews: use gettext for user-visible strings.

Revision history for this message
Michal Hruby (mhr3) wrote :

Looking good now. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-lens-video'
2--- src/unity-lens-video 2012-07-04 16:13:49 +0000
3+++ src/unity-lens-video 2012-08-14 12:58:18 +0000
4@@ -25,6 +25,11 @@
5 from zeitgeist.client import ZeitgeistClient
6 from zeitgeist import client, datamodel
7 import time
8+import fractions
9+
10+import gi
11+gi.require_version("Gst", "1.0")
12+gi.require_version("GstPbutils", "1.0")
13
14 #pylint: disable=E0611
15 from gi.repository import (
16@@ -33,6 +38,8 @@
17 Gio,
18 Unity,
19 Dee,
20+ Gst,
21+ GstPbutils
22 )
23 #pylint: enable=E0611
24
25@@ -70,7 +77,6 @@
26 """Creation of a lens with a local scope."""
27
28 def __init__(self):
29-
30 #Create the lens
31 self._lens = Unity.Lens.new("/net/launchpad/lens/video", "video")
32 self._lens.props.search_hint = HINT
33@@ -108,6 +114,7 @@
34 self._scope.connect("filters-changed",self.on_filtering_changed)
35 self._scope.props.sources.connect("notify::filtering",
36 self.on_filtering_changed)
37+ self._scope.connect('preview-uri', self.on_preview_uri)
38 self._lens.add_local_scope(self._scope)
39 self._lens.export()
40
41@@ -124,6 +131,60 @@
42 else:
43 return False
44
45+ def on_preview_uri(self, scope, uri):
46+ """Preview request handler"""
47+ preview = None
48+ model = self._scope.props.results_model
49+ iter = model.get_first_iter()
50+ while not model.is_last(iter):
51+ if model.get_string(iter, 0) == uri:
52+ title = model.get_string(iter, 4);
53+ subtitle = time.strftime("%x, %X", time.localtime(os.path.getmtime(GLib.filename_from_uri(uri, None))))
54+ desc = model.get_string(iter, 5);
55+ preview = Unity.MoviePreview.new(title, subtitle, desc, None)
56+ # we may get remote uris from zeitgeist - fetch details for local files only
57+ if uri.startswith("file://"):
58+ preview.props.image_source_uri = uri
59+ try:
60+ discoverer = GstPbutils.Discoverer.new(2 * 1000000000) #2 seconds
61+ discoverer_info = discoverer.discover_uri(uri)
62+ video_streams = discoverer_info.get_video_streams()
63+ # note: the container may have multiple video and audio streams, we just get properties of the first one
64+ if video_streams and len(video_streams) > 0:
65+ vstream = video_streams[0]
66+ dimensions = str(vstream.get_width()) + "*" + str(vstream.get_height())
67+ if vstream.get_width() > 0 and vstream.get_height() > 0:
68+ gcd = fractions.gcd(vstream.get_width(), vstream.get_height())
69+ dimensions += ", " + str(vstream.get_width() / gcd) + ":" + str(vstream.get_height() / gcd)
70+ preview.add_info(Unity.InfoHint.new("format", _("Format"), None, GstPbutils.pb_utils_get_codec_description(vstream.get_caps())))
71+ preview.add_info(Unity.InfoHint.new("dimensions", _("Dimensions"), None, dimensions))
72+ preview.add_info(Unity.InfoHint.new("size", _("Size"), None, GLib.format_size(os.path.getsize(GLib.filename_from_uri(uri, None)))))
73+ except Exception as e:
74+ print "Couldn't get video details", e
75+ show_folder = Unity.PreviewAction.new("show-in-folder", _("Show in Folder"), None)
76+ show_folder.connect('activated', self.show_in_folder)
77+ preview.add_action(show_folder)
78+ play_video = Unity.PreviewAction.new("play", _("Play"), None)
79+ preview.add_action(play_video)
80+ break
81+ iter = model.next(iter)
82+ if preview == None:
83+ print "Couldn't find model row for requested preview uri:", uri
84+ return preview
85+
86+ def show_in_folder(self, scope, uri):
87+ """ Open folder that contains given video """
88+ file = Gio.file_new_for_uri (uri)
89+ parent = file.get_parent()
90+ if parent == None:
91+ parent = Gio.file_new_for_path("/")
92+ try:
93+ Gio.app_info_launch_default_for_uri(parent.get_uri(), None)
94+ except Exception as e:
95+ print "Couldn't launch default app for uri", parent.get_uri(), e
96+ return Unity.ActivationResponse(handled=Unity.HandledType.NOT_HANDLED)
97+ return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH)
98+
99 def on_lens_active(self, *_):
100 """ Run a search when the lens is opened """
101 if self._lens.props.active:
102@@ -437,6 +498,7 @@
103 except:
104 raise SystemExit(1)
105
106+ Gst.init(sys.argv)
107 daemon = Daemon()
108 GObject.MainLoop().run()
109

Subscribers

People subscribed via source and target branches