[postr] Added missing file to implemente Content Type upload



commit 2f036530bbad1e72d9d6129d82ce25db0c913466
Author: Karl Svensson <kalle maxflow org>
Date:   Tue Nov 10 01:07:22 2009 -0300

    Added missing file to implemente Content Type upload
    Signed-off-by: Germán Póo-Caamaño <gpoo gnome org>

 src/ContentTypeCombo.py |   41 +++++++++++++++++++++++++++++++++++++++++
 src/ImageStore.py       |    6 ++++--
 src/postr.glade         |   36 ++++++++++++++++++++++++++++++++----
 src/postr.py            |   35 +++++++++++++++++++++++++++++++----
 4 files changed, 108 insertions(+), 10 deletions(-)
---
diff --git a/src/ContentTypeCombo.py b/src/ContentTypeCombo.py
new file mode 100644
index 0000000..3064b6d
--- /dev/null
+++ b/src/ContentTypeCombo.py
@@ -0,0 +1,41 @@
+# Postr, a Flickr Uploader
+#
+# Copyright (C) 2006-2008 Ross Burton <ross burtonini com>
+#
+# 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 the Free Software
+# Foundation; either version 2, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
+# St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gobject, gtk
+
+class ContentTypeCombo(gtk.ComboBox):
+    def __init__(self):
+        gtk.ComboBox.__init__(self)
+        # Name, content_type
+        model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT)
+        model.set(model.append(), 0, "Photo", 1, 1)
+        model.set(model.append(), 0, "Screenshot", 1, 2)
+        model.set(model.append(), 0, "Other", 1, 3)
+        self.model = model
+        self.set_model(model)
+        self.set_active(0)
+
+        cell = gtk.CellRendererText()
+        self.pack_start(cell)
+        self.add_attribute(cell, "text", 0)
+
+    def get_content_type_for_iter(self, it):
+        if it is None: return None
+        return self.model.get_value(it, 1)
+
+    def get_active_content_type(self):
+        return self.get_content_type_for_iter(self.get_active_iter())
diff --git a/src/ImageStore.py b/src/ImageStore.py
index 2187d97..b58eb39 100644
--- a/src/ImageStore.py
+++ b/src/ImageStore.py
@@ -32,7 +32,8 @@ import gobject, gtk
  COL_SAFETY, # Iterator containing safety
  COL_VISIBLE, # If the image is searchable
  COL_CONTENT_TYPE, # Iterator containing content type
- ) = range (0, 14)
+ COL_LICENSE # Iterator containing license
+ ) = range (0, 15)
 
 class ImageStore (gtk.ListStore):
     def __init__(self):
@@ -49,7 +50,8 @@ class ImageStore (gtk.ListStore):
                                gtk.TreeIter, # COL_PRIVACY
                                gtk.TreeIter, # COL_SAFETY
                                gobject.TYPE_BOOLEAN, # COL_VISIBLE
-                               gtk.TreeIter) # COL_CONTENT_TYPE
+                               gtk.TreeIter, # COL_CONTENT_TYPE
+                               gtk.TreeIter) # COL_LICENSE
         self._dirty = False
         self.connect("row-changed", self._on_row_changed)
 
diff --git a/src/postr.glade b/src/postr.glade
index 23b576e..9ea0a90 100644
--- a/src/postr.glade
+++ b/src/postr.glade
@@ -472,7 +472,7 @@
                       <widget class="GtkTable" id="table2">
                         <property name="visible">True</property>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                        <property name="n_rows">4</property>
+                        <property name="n_rows">5</property>
                         <property name="n_columns">2</property>
                         <property name="column_spacing">4</property>
                         <property name="row_spacing">6</property>
@@ -560,8 +560,8 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="right_attach">2</property>
-                            <property name="top_attach">3</property>
-                            <property name="bottom_attach">4</property>
+                            <property name="top_attach">4</property>
+                            <property name="bottom_attach">5</property>
                           </packing>
                         </child>
                         <child>
@@ -577,13 +577,41 @@
                             <property name="bottom_attach">3</property>
                           </packing>
                         </child>
+                        <child>
+                          <widget class="GtkLabel" id="license_label">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">_License:</property>
+                            <property name="use_underline">True</property>
+                            <property name="mnemonic_widget">tags_entry</property>
+                          </widget>
+                          <packing>
+                            <property name="top_attach">3</property>
+                            <property name="bottom_attach">4</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options">GTK_FILL</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="Custom" id="license_combo">
+                            <property name="visible">True</property>
+                            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                            <property name="creation_function">license_combo_new</property>
+                          </widget>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">3</property>
+                            <property name="bottom_attach">4</property>
+                          </packing>
+                        </child>
                       </widget>
                     </child>
                     <child>
                       <widget class="GtkLabel" id="label5">
                         <property name="visible">True</property>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                        <property name="label" translatable="yes">Privacy, Safety and Type</property>
+                        <property name="label" translatable="yes">Privacy, Safety, Type and License</property>
                       </widget>
                       <packing>
                         <property name="type">label_item</property>
diff --git a/src/postr.py b/src/postr.py
index fbc4634..788362e 100644
--- a/src/postr.py
+++ b/src/postr.py
@@ -96,6 +96,7 @@ class Postr(UniqueApp):
                             "safety_combo",
                             "visible_check",
                             "content_type_combo",
+                            "license_combo",
                             "thumbview")
                            )
         align_labels(glade, ("title_label", "desc_label",
@@ -148,6 +149,7 @@ class Postr(UniqueApp):
         self.change_signals.append((self.safety_combo, self.safety_combo.connect('changed', self.on_field_changed, ImageStore.COL_SAFETY)))
         self.change_signals.append((self.visible_check, self.visible_check.connect('toggled', self.on_field_changed, ImageStore.COL_VISIBLE)))
         self.change_signals.append((self.content_type_combo, self.content_type_combo.connect('changed', self.on_field_changed, ImageStore.COL_CONTENT_TYPE)))
+        self.change_signals.append((self.license_combo, self.license_combo.connect('changed', self.on_field_changed, ImageStore.COL_LICENSE)))
         
         self.thumbnail_image.connect('size-allocate', self.update_thumbnail)
         self.old_thumb_allocation = None
@@ -227,6 +229,12 @@ class Postr(UniqueApp):
         w = SetCombo.SetCombo(self.flickr)
         w.show()
         return w
+
+    def license_combo_new(self, *args):
+        import LicenseCombo
+        w = LicenseCombo.LicenseCombo(self.flickr)
+        w.show()
+        return w
     
     def image_list_new(self, *args):
         """Custom widget creation function to make the image list."""
@@ -273,6 +281,7 @@ class Postr(UniqueApp):
             self.statusbar.update_quota()
             self.group_selector.update()
             self.set_combo.update()
+            self.license_combo.update()
             self.update_avatar()
 
     def on_statusbar_box_expose(self, widget, event):
@@ -588,7 +597,7 @@ class Postr(UniqueApp):
             self.current_it = self.model.get_iter(items[0])
             (title, desc, tags, set_it, groups,
              privacy_it, safety_it, visible,
-             content_type_it) = self.model.get(self.current_it,
+             content_type_it, license_it) = self.model.get(self.current_it,
                            ImageStore.COL_TITLE,
                            ImageStore.COL_DESCRIPTION,
                            ImageStore.COL_TAGS,
@@ -597,7 +606,8 @@ class Postr(UniqueApp):
                            ImageStore.COL_PRIVACY,
                            ImageStore.COL_SAFETY,
                            ImageStore.COL_VISIBLE,
-                           ImageStore.COL_CONTENT_TYPE)
+                           ImageStore.COL_CONTENT_TYPE,
+                           ImageStore.COL_LICENSE)
 
             enable_field(self.title_entry, title)
             enable_field(self.desc_view, desc)
@@ -608,6 +618,7 @@ class Postr(UniqueApp):
             enable_field(self.safety_combo, safety_it)
             enable_field(self.visible_check, visible)
             enable_field(self.content_type_combo, content_type_it)
+            enable_field(self.license_combo, license_it)
 
             self.update_thumbnail(self.thumbnail_image)
         else:
@@ -621,6 +632,7 @@ class Postr(UniqueApp):
             disable_field(self.safety_combo)
             disable_field(self.visible_check)
             disable_field(self.content_type_combo)
+            disable_field(self.license_combo)
 
             self.thumbnail_image.set_from_icon_name("postr", self.logo_icon_size)
         [obj.handler_unblock(i) for obj,i in self.change_signals]
@@ -818,6 +830,13 @@ class Postr(UniqueApp):
             self.flickr.groups_pools_add(photo_id=photo_id, group_id=group).addErrback(error)
         return rsp
 
+    def set_license(self, rsp, license):
+        """Callback from the upload method to set license for the picture."""
+        photo_id=rsp.find("photoid").text
+        self.flickr.photos_licenses_setLicense(photo_id=photo_id,
+                                               license_id=license).addErrback(self.twisted_error)
+        return rsp
+
     def upload_done(self):
         self.cancel_upload = False
         self.window.set_title(_("Flickr Uploader"))
@@ -851,7 +870,7 @@ class Postr(UniqueApp):
 
         (filename, thumb, pixbuf, title, desc,
          tags, set_it, groups, privacy_it, safety_it,
-         visible, content_type_it) = self.model.get(it,
+         visible, content_type_it, license_it) = self.model.get(it,
                        ImageStore.COL_FILENAME,
                        ImageStore.COL_THUMBNAIL,
                        ImageStore.COL_IMAGE,
@@ -863,7 +882,8 @@ class Postr(UniqueApp):
                        ImageStore.COL_PRIVACY,
                        ImageStore.COL_SAFETY,
                        ImageStore.COL_VISIBLE,
-                       ImageStore.COL_CONTENT_TYPE)
+                       ImageStore.COL_CONTENT_TYPE,
+                       ImageStore.COL_LICENSE)
         # Lookup the set ID from the iterator
         if set_it:
             (set_id,) = self.set_combo.get_id_for_iter(set_it)
@@ -885,6 +905,11 @@ class Postr(UniqueApp):
         else:
             content_type = None
 
+        if license_it:
+            license = self.license_combo.get_license_for_iter(license_it)
+        else:
+            license = None
+
         self.update_progress(filename, title, thumb)
         self.upload_index += 1
         self.current_upload_it = it
@@ -911,6 +936,8 @@ class Postr(UniqueApp):
             d.addCallback(self.add_to_set, set_id)
         if groups:
             d.addCallback(self.add_to_groups, groups)
+        if license is not None: # 0 is a valid license.
+            d.addCallback(self.set_license, license)
         d.addCallbacks(self.upload, self.upload_error)
 
     def on_double_click_selection(self, tree ,event, entry):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]