← Back to team overview

gnome-zeitgeist team mailing list archive

[Merge] lp:~cando/gnome-activity-journal/dnd-pinning into lp:gnome-activity-journal

 

Stefano Candori has proposed merging lp:~cando/gnome-activity-journal/dnd-pinning into lp:gnome-activity-journal.

Requested reviews:
  GNOME Zeitgeist Team (gnome-zeitgeist)


This merge proposal include this one: https://code.launchpad.net/~cando/gnome-activity-journal/fix-pinning/+merge/41754 (so forget about it).

In this branch I've:
 * fixed bug #680653 ;
 * added DND support to bookmarking/pinning area ;
 * refactored a little DND code, as asked by RainCT.


-- 
https://code.launchpad.net/~cando/gnome-activity-journal/dnd-pinning/+merge/41866
Your team GNOME Zeitgeist Team is requested to review the proposed merge of lp:~cando/gnome-activity-journal/dnd-pinning into lp:gnome-activity-journal.
=== modified file 'src/activity_widgets.py'
--- src/activity_widgets.py	2010-11-11 16:43:36 +0000
+++ src/activity_widgets.py	2010-11-25 14:45:55 +0000
@@ -41,7 +41,27 @@
 #DND support variables
 TYPE_TARGET_TEXT = 80
 TYPE_TARGET_URI = 81
-
+ 
+class Draggable():
+
+    def __init__(self, widget):
+        targets = [("text/plain", 0, TYPE_TARGET_TEXT),
+                   ("text/uri-list", 0, TYPE_TARGET_URI)]
+        widget.drag_source_set( gtk.gdk.BUTTON1_MASK, targets,
+                gtk.gdk.ACTION_COPY)
+        widget.connect("drag_data_get", self.on_drag_data_get)
+
+class Droppable():
+
+    def __init__(self, widget):
+        targets = [("text/plain", 0, TYPE_TARGET_TEXT),]
+        widget.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
+  	                            gtk.DEST_DEFAULT_HIGHLIGHT |
+	                            gtk.DEST_DEFAULT_DROP, 
+                                    targets, gtk.gdk.ACTION_COPY)
+        widget.connect("drag_data_received", self.on_drag_data_received)
+
+    
 class _GenericViewWidget(gtk.VBox):
     day = None
     day_signal_id = None
@@ -172,7 +192,7 @@
         self.day = day
         if pinbox in self.box.get_children():
             self.box.remove(pinbox)
-        if (day.date - datetime.date.today()) == 0:
+        if (day.date - datetime.date.today()) == datetime.timedelta(days=0):
             self.box.pack_start(pinbox, False, False)
             self.box.reorder_child(pinbox, 0)
         self.daylabel.set_date(day.date)
@@ -360,7 +380,7 @@
         self._set_up_box(self.event_structs)
 
 
-class Item(gtk.HBox):
+class Item(gtk.HBox, Draggable):
 
     def __init__(self, content_struct, allow_pin = False, do_style=True):
         event = content_struct.event
@@ -368,6 +388,7 @@
         self.set_border_width(2)
         self.allow_pin = allow_pin
         self.btn = gtk.Button()
+        Draggable.__init__(self, self.btn)
         self.search_results = []
         self.subject = event.subjects[0]
         self.content_obj = content_struct.content_object
@@ -459,11 +480,6 @@
         self.btn.connect("realize", self.realize_cb, evbox)
         self.init_multimedia_tooltip()
         
-        self.targets = [("text/plain", 0, TYPE_TARGET_TEXT),
-                        ("text/uri-list", 0, TYPE_TARGET_URI),]
-        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
@@ -672,7 +688,7 @@
         pass
 
 
-class ThumbIconView(gtk.IconView):
+class ThumbIconView(gtk.IconView, Draggable):
     """
     A iconview which uses a custom cellrenderer to render square pixbufs
     based on zeitgeist events
@@ -681,7 +697,8 @@
     child_width = _ThumbViewRenderer.width
     child_height = _ThumbViewRenderer.height
     def __init__(self):
-        super(ThumbIconView, self).__init__()
+        gtk.IconView.__init__(self)
+        Draggable.__init__(self, self)
         self.active_list = []
         self.popupmenu = ContextMenu
         self.add_events(gtk.gdk.LEAVE_NOTIFY_MASK)
@@ -700,12 +717,6 @@
         SearchBox.connect("search", lambda *args: self.queue_draw())
         SearchBox.connect("clear", lambda *args: self.queue_draw())
 
-        self.targets = [("text/plain", 0, TYPE_TARGET_TEXT),
-                        ("text/uri-list", 0, TYPE_TARGET_URI),]
-        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.
@@ -751,7 +762,7 @@
             if uri.startswith("file://"):
                 unquoted_uri = urllib.unquote(uri)
                 if os.path.exists(unquoted_uri[7:]):
-                    selection.set_uris([uri])
+                    selection.set_uris([uri])     
 
     def on_button_press(self, widget, event):
         if event.button == 3:
@@ -1060,7 +1071,7 @@
         pass
 
 
-class TimelineView(gtk.TreeView):
+class TimelineView(gtk.TreeView, Draggable):
     child_width = _TimelineRenderer.width
     child_height = _TimelineRenderer.height
 
@@ -1078,7 +1089,8 @@
         return [x, w]
 
     def __init__(self):
-        super(TimelineView, self).__init__()
+        gtk.TreeView.__init__(self)
+        Draggable.__init__(self, self)
         self.popupmenu = ContextMenu
         self.add_events(gtk.gdk.LEAVE_NOTIFY_MASK)
         self.connect("button-press-event", self.on_button_press)
@@ -1095,12 +1107,6 @@
         SearchBox.connect("search", lambda *args: self.queue_draw())
         SearchBox.connect("clear", lambda *args: self.queue_draw())
 
-        self.targets = [("text/plain", 0, TYPE_TARGET_TEXT),
-                        ("text/uri-list", 0, TYPE_TARGET_URI),]
-        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
@@ -1228,11 +1234,14 @@
         self.line_color = get_gtk_rgba(widget.style, "bg", 0, 0.94)
 
 
-class PinBox(DayView):
+class PinBox(DayView, Droppable):
 
     def __init__(self):
         self.event_timerange = TimeRange.until_now()
-        super(PinBox, self).__init__(title=_("Pinned Items"))#_("Pinned items"))
+        DayView.__init__(self, title=_("Pinned Items"))#_("Pinned items"))
+        self.notebook = gtk.Notebook()
+        Droppable.__init__(self, self.notebook)
+
         bookmarker.connect("reload", self.set_from_templates)
         self.set_from_templates()
 
@@ -1254,6 +1263,8 @@
                 self.event_templates, self.do_set,
                 self.event_timerange,
                 StorageState.Any, 10000, ResultType.MostRecentSubjects)
+        else:
+            self.do_set([])
 
     def do_set(self, event_ids):
         objs = []
@@ -1270,12 +1281,17 @@
         self.view.pack_start(box)
         for w in self:
             self.remove(w)
-        notebook = gtk.Notebook()
-        notebook.append_page(self.view, self.label)
+        self.notebook.append_page(self.view, self.label)
         self.label.set_alignment(0.01, 0.5)
-        notebook.set_tab_label_packing(self.view, True, True, gtk.PACK_START)
+        self.notebook.set_tab_label_packing(self.view, True, True, gtk.PACK_START)
         self.set_border_width(4)
-        if len(items) > 0: self.pack_start(notebook)
+        if len(items) > 0: self.pack_start(self.notebook)
+
+    def on_drag_data_received(self, wid, context, x, y, selection, target_type, time):
+        uri = unicode(selection.data.strip())
+        isbookmarked = bookmarker.is_bookmarked(uri)
+        if not isbookmarked:
+            bookmarker.bookmark(uri)
 
 
 ## gobject registration

=== modified file 'src/supporting_widgets.py'
--- src/supporting_widgets.py	2010-11-09 20:25:08 +0000
+++ src/supporting_widgets.py	2010-11-25 14:45:55 +0000
@@ -917,7 +917,7 @@
             uri = obj.uri
             uri = unicode(uri)
             isbookmarked = bookmarker.is_bookmarked(uri)
-            if isbookmarked:
+            if isbookmarked:               
                 bookmarker.unbookmark(uri)
 
     def do_delete(self, menuitem):


Follow ups