Merge lp:~cando/gnome-activity-journal/audio_preview into lp:gnome-activity-journal
- audio_preview
- Merge into trunk
Status: | Merged |
---|---|
Merge reported by: | Seif Lotfy |
Merged at revision: | not available |
Proposed branch: | lp:~cando/gnome-activity-journal/audio_preview |
Merge into: | lp:gnome-activity-journal |
Diff against target: |
250 lines (+102/-10) 3 files modified
src/activity_widgets.py (+62/-9) src/common.py (+2/-1) src/supporting_widgets.py (+38/-0) |
To merge this branch: | bzr merge lp:~cando/gnome-activity-journal/audio_preview |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Seif Lotfy | Pending | ||
Review via email: mp+40342@code.launchpad.net |
Commit message
Description of the change
In this branch i've added the support for audio preview.
Stefano Candori (cando) wrote : | # |
Seif Lotfy (seif) wrote : | # |
ok cool
i wont read or work on code till thursday
mabye tehk or RainCT can merge it
On Mon, Nov 8, 2010 at 5:26 PM, Cando <email address hidden> wrote:
> ehm sorry...this diff also contains my other merge proposal(Drag and drop
> feature) as I worked on the same folder.
> I hope that is not a problem.
> --
>
> https:/
> Your team GNOME Zeitgeist Team is requested to review the proposed merge of
> lp:~cando/gnome-activity-journal/audio_preview into
> lp:gnome-activity-journal.
>
> _______
> Mailing list: https:/
> Post to : <email address hidden>
> Unsubscribe : https:/
> More help : https:/
>
--
This is me doing some advertisement for my blog http://
- 1127. By Stefano Candori
-
Fix ThumbView problem with "audio-x-generic" files
Seif Lotfy (seif) wrote : | # |
works flawlessly :)
Stefano Candori (cando) wrote : | # |
^^ awesome!
Preview Diff
1 | === modified file 'src/activity_widgets.py' |
2 | --- src/activity_widgets.py 2010-10-31 14:19:15 +0000 |
3 | +++ src/activity_widgets.py 2010-11-08 22:27:42 +0000 |
4 | @@ -6,6 +6,7 @@ |
5 | # Copyright © 2010 Randal Barlow <email.tehk@gmail.com> |
6 | # Copyright © 2010 Siegfried Gevatter <siegfried@gevatter.com> |
7 | # Copyright © 2010 Markus Korn <thekorn@gmx.de> |
8 | +# Copyright © 2010 Stefano Candori <stefano.candori@gmail.com> |
9 | # |
10 | # This program is free software: you can redistribute it and/or modify |
11 | # it under the terms of the GNU General Public License as published by |
12 | @@ -33,8 +34,8 @@ |
13 | import content_objects |
14 | from config import event_exists, settings, bookmarker, SUPPORTED_SOURCES |
15 | from store import ContentStruct, CLIENT |
16 | -from supporting_widgets import DayLabel, ContextMenu, StaticPreviewTooltip, VideoPreviewTooltip, SearchBox |
17 | - |
18 | +from supporting_widgets import DayLabel, ContextMenu, StaticPreviewTooltip, VideoPreviewTooltip, SearchBox,\ |
19 | +AudioPreviewTooltip |
20 | from zeitgeist.datamodel import ResultType, StorageState, TimeRange |
21 | |
22 | |
23 | @@ -454,6 +455,19 @@ |
24 | self.btn.connect("button_press_event", self._show_item_popup) |
25 | self.btn.connect("realize", self.realize_cb, evbox) |
26 | self.init_multimedia_tooltip() |
27 | + |
28 | + self.targets = [("text/uri-list", 0, 0)] |
29 | + self.btn.drag_source_set( gtk.gdk.BUTTON1_MASK, self.targets, |
30 | + gtk.gdk.ACTION_COPY) |
31 | + self.btn.connect("drag_data_get", self.on_drag_data_get) |
32 | + |
33 | + def on_drag_data_get(self, treeview, context, selection, target_id, etime): |
34 | + uri = self.content_obj.uri |
35 | + #FIXME for the moment we handle only files |
36 | + if uri.startswith("file://"): |
37 | + uri = uri.replace("%20"," ") |
38 | + if os.path.exists(uri[7:]): |
39 | + selection.set_uris([uri]) |
40 | |
41 | def realize_cb(self, widget, evbox): |
42 | evbox.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2)) |
43 | @@ -470,12 +484,12 @@ |
44 | self.connect("query-tooltip", self._handle_tooltip) |
45 | if "video-x-generic" in icon_names and gst is not None: |
46 | self.set_tooltip_window(VideoPreviewTooltip) |
47 | + elif "audio-x-generic" in icon_names and gst is not None: |
48 | + self.set_tooltip_window(AudioPreviewTooltip) |
49 | else: |
50 | self.set_tooltip_window(StaticPreviewTooltip) |
51 | |
52 | def _handle_tooltip(self, widget, x, y, keyboard_mode, tooltip): |
53 | - # nothing to do here, we always show the multimedia tooltip |
54 | - # if we like video/sound preview later on we can start them here |
55 | tooltip_window = self.get_tooltip_window() |
56 | return tooltip_window.preview(self.content_obj) |
57 | |
58 | @@ -649,8 +663,7 @@ |
59 | pass |
60 | |
61 | def on_activate(self, event, widget, path, background_area, cell_area, flags): |
62 | - self.content_obj.launch() |
63 | - return True |
64 | + pass |
65 | |
66 | |
67 | class ThumbIconView(gtk.IconView): |
68 | @@ -667,9 +680,10 @@ |
69 | self.popupmenu = ContextMenu |
70 | self.add_events(gtk.gdk.LEAVE_NOTIFY_MASK) |
71 | self.connect("button-press-event", self.on_button_press) |
72 | + self.connect("button-release-event", self.on_button_release) |
73 | self.connect("motion-notify-event", self.on_motion_notify) |
74 | self.connect("leave-notify-event", self.on_leave_notify) |
75 | - self.set_selection_mode(gtk.SELECTION_NONE) |
76 | + self.set_selection_mode(gtk.SELECTION_SINGLE) |
77 | self.set_column_spacing(6) |
78 | self.set_row_spacing(6) |
79 | pcolumn = gtk.TreeViewColumn("Preview") |
80 | @@ -680,6 +694,11 @@ |
81 | SearchBox.connect("search", lambda *args: self.queue_draw()) |
82 | SearchBox.connect("clear", lambda *args: self.queue_draw()) |
83 | |
84 | + self.targets = [("text/uri-list", 0, 0)] |
85 | + self.drag_source_set(gtk.gdk.BUTTON1_MASK, self.targets, |
86 | + gtk.gdk.ACTION_COPY) |
87 | + self.connect("drag_data_get", self.on_drag_data_get) |
88 | + |
89 | def _set_model_in_thread(self, items): |
90 | """ |
91 | A threaded which generates pixbufs and emblems for a list of events. |
92 | @@ -714,6 +733,17 @@ |
93 | thread = threading.Thread(target=self._set_model_in_thread, args=(items,)) |
94 | thread.start() |
95 | |
96 | + def on_drag_data_get(self, iconview, context, selection, target_id, etime): |
97 | + model = iconview.get_model() |
98 | + selected = iconview.get_selected_items() |
99 | + content_object = model[selected[0]][0] |
100 | + uri = content_object.uri |
101 | + #FIXME for the moment we handle only files |
102 | + if uri.startswith("file://"): |
103 | + uri = uri.replace("%20"," ") |
104 | + if os.path.exists(uri[7:]): |
105 | + selection.set_uris([uri]) |
106 | + |
107 | def on_button_press(self, widget, event): |
108 | if event.button == 3: |
109 | val = self.get_item_at_pos(int(event.x), int(event.y)) |
110 | @@ -722,7 +752,15 @@ |
111 | model = self.get_model() |
112 | obj = model[path[0]][0] |
113 | self.popupmenu.do_popup(event.time, [obj]) |
114 | - return False |
115 | + |
116 | + def on_button_release(self, widget, event): |
117 | + if event.button == 1: |
118 | + val = self.get_item_at_pos(int(event.x), int(event.y)) |
119 | + if val: |
120 | + path, cell = val |
121 | + model = self.get_model() |
122 | + obj = model[path[0]][0] |
123 | + obj.launch() |
124 | |
125 | def on_leave_notify(self, widget, event): |
126 | try: |
127 | @@ -740,7 +778,6 @@ |
128 | self.active_list[path[0]] = True |
129 | self.last_active = path[0] |
130 | self.queue_draw() |
131 | - return True |
132 | |
133 | def query_tooltip(self, widget, x, y, keyboard_mode, tooltip): |
134 | """ |
135 | @@ -1049,6 +1086,11 @@ |
136 | SearchBox.connect("search", lambda *args: self.queue_draw()) |
137 | SearchBox.connect("clear", lambda *args: self.queue_draw()) |
138 | |
139 | + self.targets = [("text/uri-list", 0, 0)] |
140 | + self.drag_source_set( gtk.gdk.BUTTON1_MASK, self.targets, |
141 | + gtk.gdk.ACTION_COPY) |
142 | + self.connect("drag_data_get", self.on_drag_data_get) |
143 | + |
144 | def set_model_from_list(self, items): |
145 | """ |
146 | Sets creates/sets a model from a list of zeitgeist events |
147 | @@ -1072,6 +1114,17 @@ |
148 | items = day.get_time_map() |
149 | self.set_model_from_list(items) |
150 | |
151 | + def on_drag_data_get(self, treeview, context, selection, target_id, etime): |
152 | + tree_selection = treeview.get_selection() |
153 | + model, iter = tree_selection.get_selected() |
154 | + content_object = model.get_value(iter, 0) |
155 | + uri = content_object.uri |
156 | + #FIXME for the moment we handle only files |
157 | + if uri.startswith("file://"): |
158 | + uri = uri.replace("%20"," ") |
159 | + if os.path.exists(uri[7:]): |
160 | + selection.set_uris([uri]) |
161 | + |
162 | def on_button_press(self, widget, event): |
163 | if event.button == 3: |
164 | path = self.get_dest_row_at_pos(int(event.x), int(event.y)) |
165 | |
166 | === modified file 'src/common.py' |
167 | --- src/common.py 2010-10-30 18:41:28 +0000 |
168 | +++ src/common.py 2010-11-08 22:27:42 +0000 |
169 | @@ -635,7 +635,7 @@ |
170 | gfile = GioFile.create(uri) |
171 | thumb = True |
172 | if gfile: |
173 | - if gfile.has_preview(): |
174 | + if gfile.has_preview() and "audio-x-generic" not in gfile.icon_names: |
175 | pb = gfile.get_thumbnail(size=size) |
176 | else: |
177 | iconsize = int(size[0]*iconscale) |
178 | @@ -898,6 +898,7 @@ |
179 | is_opendocument = filter(lambda name: "application-vnd.oasis.opendocument" in name, icon_names) |
180 | return "video-x-generic" in icon_names \ |
181 | or "image-x-generic" in icon_names \ |
182 | + or "audio-x-generic" in icon_names \ |
183 | or "application-pdf" in icon_names \ |
184 | or (("text-x-generic" in icon_names or "text-x-script" in icon_names) and pygments is not None) \ |
185 | or is_opendocument |
186 | |
187 | === modified file 'src/supporting_widgets.py' |
188 | --- src/supporting_widgets.py 2010-10-30 18:41:28 +0000 |
189 | +++ src/supporting_widgets.py 2010-11-08 22:27:42 +0000 |
190 | @@ -6,6 +6,7 @@ |
191 | # Copyright © 2010 Siegfried Gevatter <siegfried@gevatter.com> |
192 | # Copyright © 2010 Markus Korn <thekorn@gmx.de> |
193 | # Copyright © 2010 Randal Barlow <email.tehk@gmail.com> |
194 | +# Copyright © 2010 Stefano Candori <stefano.candori@gmail.com> |
195 | # |
196 | # This program is free software: you can redistribute it and/or modify |
197 | # it under the terms of the GNU General Public License as published by |
198 | @@ -665,6 +666,41 @@ |
199 | finally: |
200 | gtk.gdk.threads_leave() |
201 | |
202 | +class AudioPreviewTooltip(PreviewTooltip): |
203 | + |
204 | + def __init__(self): |
205 | + PreviewTooltip.__init__(self) |
206 | + #hack:we don't need any window for audio_preview |
207 | + self.set_default_size(0,0) |
208 | + self.player = gst.element_factory_make("playbin2", "player") |
209 | + fakesink = gst.element_factory_make("fakesink", "fakesink") |
210 | + self.player.set_property("video-sink", fakesink) |
211 | + bus = self.player.get_bus() |
212 | + bus.add_signal_watch() |
213 | + bus.connect("message", self.on_message) |
214 | + self.connect("hide", self._handle_hide) |
215 | + self.connect("show", self._handle_show) |
216 | + |
217 | + def _handle_hide(self, widget): |
218 | + self.player.set_state(gst.STATE_NULL) |
219 | + |
220 | + def _handle_show(self, widget): |
221 | + self.player.set_state(gst.STATE_PLAYING) |
222 | + |
223 | + def preview(self, gio_file): |
224 | + if gio_file.uri == self.player.get_property("uri"): |
225 | + return True |
226 | + self.player.set_property("uri", gio_file.uri) |
227 | + return True |
228 | + |
229 | + def on_message(self, bus, message): |
230 | + t = message.type |
231 | + if t == gst.MESSAGE_EOS: |
232 | + self.player.set_state(gst.STATE_NULL) |
233 | + elif t == gst.MESSAGE_ERROR: |
234 | + self.player.set_state(gst.STATE_NULL) |
235 | + err, debug = message.parse_error() |
236 | + print "Error: %s" % err, debug |
237 | |
238 | class AnimatedImage(gtk.Image): |
239 | animating = None |
240 | @@ -1453,8 +1489,10 @@ |
241 | ### |
242 | if gst is not None: |
243 | VideoPreviewTooltip = VideoPreviewTooltip() |
244 | + AudioPreviewTooltip = AudioPreviewTooltip() |
245 | else: |
246 | VideoPreviewTooltip = None |
247 | + AudioPreviewTooltip = None |
248 | StaticPreviewTooltip = StaticPreviewTooltip() |
249 | ContextMenu = ContextMenu() |
250 | SearchBox = SearchBox() |
ehm sorry...this diff also contains my other merge proposal(Drag and drop feature) as I worked on the same folder.
I hope that is not a problem.