Cando has proposed merging lp:~cando/gnome-activity-journal/audio_preview into lp:gnome-activity-journal.
Requested reviews: GNOME Zeitgeist Team (gnome-zeitgeist) In this branch i've added the support for audio preview. -- https://code.launchpad.net/~cando/gnome-activity-journal/audio_preview/+merge/40342 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.
=== modified file 'src/activity_widgets.py' --- src/activity_widgets.py 2010-10-31 14:19:15 +0000 +++ src/activity_widgets.py 2010-11-08 16:19:41 +0000 @@ -6,6 +6,7 @@ # Copyright © 2010 Randal Barlow <[email protected]> # Copyright © 2010 Siegfried Gevatter <[email protected]> # Copyright © 2010 Markus Korn <[email protected]> +# Copyright © 2010 Stefano Candori <[email protected]> # # 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 @@ -33,8 +34,8 @@ import content_objects from config import event_exists, settings, bookmarker, SUPPORTED_SOURCES from store import ContentStruct, CLIENT -from supporting_widgets import DayLabel, ContextMenu, StaticPreviewTooltip, VideoPreviewTooltip, SearchBox - +from supporting_widgets import DayLabel, ContextMenu, StaticPreviewTooltip, VideoPreviewTooltip, SearchBox,\ +AudioPreviewTooltip from zeitgeist.datamodel import ResultType, StorageState, TimeRange @@ -454,6 +455,19 @@ self.btn.connect("button_press_event", self._show_item_popup) self.btn.connect("realize", self.realize_cb, evbox) self.init_multimedia_tooltip() + + self.targets = [("text/uri-list", 0, 0)] + self.btn.drag_source_set( gtk.gdk.BUTTON1_MASK, self.targets, + gtk.gdk.ACTION_COPY) + self.btn.connect("drag_data_get", self.on_drag_data_get) + + def on_drag_data_get(self, treeview, context, selection, target_id, etime): + uri = self.content_obj.uri + #FIXME for the moment we handle only files + if uri.startswith("file://"): + uri = uri.replace("%20"," ") + if os.path.exists(uri[7:]): + selection.set_uris([uri]) def realize_cb(self, widget, evbox): evbox.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2)) @@ -470,12 +484,12 @@ self.connect("query-tooltip", self._handle_tooltip) if "video-x-generic" in icon_names and gst is not None: self.set_tooltip_window(VideoPreviewTooltip) + elif "audio-x-generic" in icon_names and gst is not None: + self.set_tooltip_window(AudioPreviewTooltip) else: self.set_tooltip_window(StaticPreviewTooltip) def _handle_tooltip(self, widget, x, y, keyboard_mode, tooltip): - # nothing to do here, we always show the multimedia tooltip - # if we like video/sound preview later on we can start them here tooltip_window = self.get_tooltip_window() return tooltip_window.preview(self.content_obj) @@ -649,8 +663,7 @@ pass def on_activate(self, event, widget, path, background_area, cell_area, flags): - self.content_obj.launch() - return True + pass class ThumbIconView(gtk.IconView): @@ -667,9 +680,10 @@ self.popupmenu = ContextMenu self.add_events(gtk.gdk.LEAVE_NOTIFY_MASK) self.connect("button-press-event", self.on_button_press) + self.connect("button-release-event", self.on_button_release) self.connect("motion-notify-event", self.on_motion_notify) self.connect("leave-notify-event", self.on_leave_notify) - self.set_selection_mode(gtk.SELECTION_NONE) + self.set_selection_mode(gtk.SELECTION_SINGLE) self.set_column_spacing(6) self.set_row_spacing(6) pcolumn = gtk.TreeViewColumn("Preview") @@ -680,6 +694,11 @@ SearchBox.connect("search", lambda *args: self.queue_draw()) SearchBox.connect("clear", lambda *args: self.queue_draw()) + self.targets = [("text/uri-list", 0, 0)] + self.drag_source_set(gtk.gdk.BUTTON1_MASK, self.targets, + gtk.gdk.ACTION_COPY) + self.connect("drag_data_get", self.on_drag_data_get) + def _set_model_in_thread(self, items): """ A threaded which generates pixbufs and emblems for a list of events. @@ -714,6 +733,17 @@ thread = threading.Thread(target=self._set_model_in_thread, args=(items,)) thread.start() + def on_drag_data_get(self, iconview, context, selection, target_id, etime): + model = iconview.get_model() + selected = iconview.get_selected_items() + content_object = model[selected[0]][0] + uri = content_object.uri + #FIXME for the moment we handle only files + if uri.startswith("file://"): + uri = uri.replace("%20"," ") + if os.path.exists(uri[7:]): + selection.set_uris([uri]) + def on_button_press(self, widget, event): if event.button == 3: val = self.get_item_at_pos(int(event.x), int(event.y)) @@ -722,7 +752,15 @@ model = self.get_model() obj = model[path[0]][0] self.popupmenu.do_popup(event.time, [obj]) - return False + + def on_button_release(self, widget, event): + if event.button == 1: + val = self.get_item_at_pos(int(event.x), int(event.y)) + if val: + path, cell = val + model = self.get_model() + obj = model[path[0]][0] + obj.launch() def on_leave_notify(self, widget, event): try: @@ -740,7 +778,6 @@ self.active_list[path[0]] = True self.last_active = path[0] self.queue_draw() - return True def query_tooltip(self, widget, x, y, keyboard_mode, tooltip): """ @@ -1049,6 +1086,11 @@ SearchBox.connect("search", lambda *args: self.queue_draw()) SearchBox.connect("clear", lambda *args: self.queue_draw()) + self.targets = [("text/uri-list", 0, 0)] + self.drag_source_set( gtk.gdk.BUTTON1_MASK, self.targets, + gtk.gdk.ACTION_COPY) + self.connect("drag_data_get", self.on_drag_data_get) + def set_model_from_list(self, items): """ Sets creates/sets a model from a list of zeitgeist events @@ -1072,6 +1114,17 @@ items = day.get_time_map() self.set_model_from_list(items) + def on_drag_data_get(self, treeview, context, selection, target_id, etime): + tree_selection = treeview.get_selection() + model, iter = tree_selection.get_selected() + content_object = model.get_value(iter, 0) + uri = content_object.uri + #FIXME for the moment we handle only files + if uri.startswith("file://"): + uri = uri.replace("%20"," ") + if os.path.exists(uri[7:]): + selection.set_uris([uri]) + def on_button_press(self, widget, event): if event.button == 3: path = self.get_dest_row_at_pos(int(event.x), int(event.y)) === modified file 'src/common.py' --- src/common.py 2010-10-30 18:41:28 +0000 +++ src/common.py 2010-11-08 16:19:41 +0000 @@ -898,6 +898,7 @@ is_opendocument = filter(lambda name: "application-vnd.oasis.opendocument" in name, icon_names) return "video-x-generic" in icon_names \ or "image-x-generic" in icon_names \ + or "audio-x-generic" in icon_names \ or "application-pdf" in icon_names \ or (("text-x-generic" in icon_names or "text-x-script" in icon_names) and pygments is not None) \ or is_opendocument === modified file 'src/supporting_widgets.py' --- src/supporting_widgets.py 2010-10-30 18:41:28 +0000 +++ src/supporting_widgets.py 2010-11-08 16:19:41 +0000 @@ -6,6 +6,7 @@ # Copyright © 2010 Siegfried Gevatter <[email protected]> # Copyright © 2010 Markus Korn <[email protected]> # Copyright © 2010 Randal Barlow <[email protected]> +# Copyright © 2010 Stefano Candori <[email protected]> # # 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 @@ -665,6 +666,41 @@ finally: gtk.gdk.threads_leave() +class AudioPreviewTooltip(PreviewTooltip): + + def __init__(self): + PreviewTooltip.__init__(self) + #hack:we don't need any window for audio_preview + self.set_default_size(0,0) + self.player = gst.element_factory_make("playbin2", "player") + fakesink = gst.element_factory_make("fakesink", "fakesink") + self.player.set_property("video-sink", fakesink) + bus = self.player.get_bus() + bus.add_signal_watch() + bus.connect("message", self.on_message) + self.connect("hide", self._handle_hide) + self.connect("show", self._handle_show) + + def _handle_hide(self, widget): + self.player.set_state(gst.STATE_NULL) + + def _handle_show(self, widget): + self.player.set_state(gst.STATE_PLAYING) + + def preview(self, gio_file): + if gio_file.uri == self.player.get_property("uri"): + return True + self.player.set_property("uri", gio_file.uri) + return True + + def on_message(self, bus, message): + t = message.type + if t == gst.MESSAGE_EOS: + self.player.set_state(gst.STATE_NULL) + elif t == gst.MESSAGE_ERROR: + self.player.set_state(gst.STATE_NULL) + err, debug = message.parse_error() + print "Error: %s" % err, debug class AnimatedImage(gtk.Image): animating = None @@ -1453,8 +1489,10 @@ ### if gst is not None: VideoPreviewTooltip = VideoPreviewTooltip() + AudioPreviewTooltip = AudioPreviewTooltip() else: VideoPreviewTooltip = None + AudioPreviewTooltip = None StaticPreviewTooltip = StaticPreviewTooltip() ContextMenu = ContextMenu() SearchBox = SearchBox()
_______________________________________________ Mailing list: https://launchpad.net/~gnome-zeitgeist Post to : [email protected] Unsubscribe : https://launchpad.net/~gnome-zeitgeist More help : https://help.launchpad.net/ListHelp

