patch for PicasaModule



Hi,
 
 I've hoped that i'm able to add a patch file to the ticket, but I can't, so I've attached to this email which implements the modification for: http://www.conduit-project.org/ticket/814
I hope, you can include it in conduit for the next release

BR,
 Zsombor
Index: conduit/modules/PicasaModule/config.glade
===================================================================
--- conduit/modules/PicasaModule/config.glade	(revision 973)
+++ conduit/modules/PicasaModule/config.glade	(working copy)
@@ -107,6 +107,27 @@
           </packing>
         </child>
         <child>
+          <widget class="GtkLabel" id="label3">
+            <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="xalign">0</property>
+            <property name="label" translatable="yes">Album Key:</property>
+          </widget>
+          <packing>
+            <property name="position">10</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkEntry" id="albumKey">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+          </widget>
+          <packing>
+            <property name="position">11</property>
+          </packing>
+        </child>
+        <child>
           <widget class="GtkLabel" id="label1">
             <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>
@@ -116,7 +137,7 @@
           <packing>
             <property name="expand">False</property>
             <property name="fill">False</property>
-            <property name="position">10</property>
+            <property name="position">12</property>
           </packing>
         </child>
         <child>
@@ -127,7 +148,7 @@
           <packing>
             <property name="expand">False</property>
             <property name="fill">False</property>
-            <property name="position">11</property>
+            <property name="position">13</property>
           </packing>
         </child>
         <child internal-child="action_area">
Index: conduit/modules/PicasaModule/PicasaAPI/picasaweb.py
===================================================================
--- conduit/modules/PicasaModule/PicasaAPI/picasaweb.py	(revision 973)
+++ conduit/modules/PicasaModule/PicasaAPI/picasaweb.py	(working copy)
@@ -128,6 +128,7 @@
     entry = "http://picasaweb.google.com/data/entry/api/";
     gallery = "user/%(userid)s?kind=album"
     album_by_id = "user/%(userid)s/albumid/%(aid)s?kind=photo"
+    album_with_auth = "user/%(userid)s/album/%(album)s?kind=photo&authkey=%(albumKey)s"
     picture_by_id = "user/%(userid)s/albumid/%(aid)s/photoid/%(pid)s"
     delete_picture = entry + "user/%(userid)s/albumid/%(aid)s/photoid/%(pid)s/%(version)s" 
     post_url = feed + "user/%(userid)s"
@@ -139,6 +140,9 @@
     def _getalbumfeedbyid (userid, aid):
         return GDataApi.feed + GDataApi.album_by_id % {"userid" : userid, "aid" : aid }
 
+    def _getalbumfeedWithAuth (userid, album, albumKey):
+        return GDataApi.feed + GDataApi.album_with_auth % {"userid" : userid, "album" : album, "albumKey" : albumKey }
+
     def _getpicturefeed (userid, aid, pid):
         return GDataApi.feed + GDataApi.picture_by_id % {"userid" : userid, "aid" : aid, "pid" : pid }
 
@@ -153,6 +157,7 @@
 
     # create the static methods
     getalbumfeedbyid = staticmethod (_getalbumfeedbyid)
+    getalbumfeedWithAuth = staticmethod (_getalbumfeedWithAuth)
     getgalleryfeed = staticmethod (_getgalleryfeed)
     getpicturefeed = staticmethod (_getpicturefeed)
     getposturl = staticmethod (_getposturl)
@@ -170,13 +175,17 @@
     auth=property (lambda s: s.__auth)
 
     def getauthheaders (self, headers={}):
-        headers['Authorization'] = 'GoogleLogin auth=' + self.auth
+	if (self.auth!=None):
+            headers['Authorization'] = 'GoogleLogin auth=' + self.auth
+
         return headers
 
     def __init__(self,u,p):
         u=utf8(u)
         p=utf8(p)
         self.__user = u
+        if (p==None or u==None or len(p)==0): 
+	    return
 
         headers = {"Content-type": "application/x-www-form-urlencoded",}
         data =    { "null":"Sign in",
@@ -270,8 +279,11 @@
         name = getText(element.getElementsByTagName("title")[0]) # title
         id = getText(element.getElementsByTagName("gphoto:id")[0])  # gphoto:id
 
-        return PicasaAlbum (self.__gc, id, name)
+        return PicasaAlbum (self.__gc, id=id, name=name)
 
+    def getUnlistedAlbum (self, album, albumKey):
+        return PicasaAlbum(self.__gc,name=self.__gc.user, album=album, albumKey=albumKey)
+  
 
 ###############################################################################
 class PicasaAlbum(object):
@@ -283,16 +295,27 @@
     __id=None
     __gc=None
 
-    def __init__(self,gc,id,name):
+    __album=None
+    __albumKey=None
+
+    def __init__(self,gc,id=None,name=None,album=None,albumKey=None):
         """ should be only called by PicasaWeb """
         self.__gc = gc
         self.__name = name
-        self.__id = utf8(id)
+        self.__album = album
+        self.__albumKey = albumKey
+        if (id!=None):
+            self.__id = utf8(id)
 
+
     def getPhotos(self):
-        feed = GDataApi.getalbumfeedbyid (self.__gc.user, self.__id)
+        if (self.__album != None and self.__albumKey != None):
+            feed = GDataApi.getalbumfeedWithAuth (self.__name, self.__album, self.__albumKey)
+            request = mkRequest(feed)
+        else: 
+            feed = GDataApi.getalbumfeedbyid (self.__gc.user, self.__id)
+            request = mkRequest(feed, headers=self.__gc.getauthheaders())
 
-        request = mkRequest(feed, headers=self.__gc.getauthheaders())
         response = opener.open(request)
         xml=response.read()
 
Index: conduit/modules/PicasaModule/PicasaModule.py
===================================================================
--- conduit/modules/PicasaModule/PicasaModule.py	(revision 973)
+++ conduit/modules/PicasaModule/PicasaModule.py	(working copy)
@@ -34,6 +34,7 @@
         self.username = ""
         self.password = ""
         self.album = ""
+        self.albumKey = ""
         self.imageSize = "None"
 
         self.gapi = None
@@ -55,15 +56,19 @@
     def refresh(self):
         Image.ImageTwoWay.refresh(self)
         self.gapi = PicasaWeb(self.username, self.password)
-
-        albums = self.gapi.getAlbums ()
-        if not albums.has_key (self.album):
-            self.galbum = self.gapi.createAlbum (self.album, public=False)
+	if (self.is_private_album()):
+            self.galbum = self.gapi.getUnlistedAlbum(self.album, self.albumKey)
         else:
-            self.galbum = albums[self.album]
+            albums = self.gapi.getAlbums ()
+            if not albums.has_key (self.album):
+                self.galbum = self.gapi.createAlbum (self.album, public=False)
+            else:
+                self.galbum = albums[self.album]
 
         self.gphotos = self.galbum.getPhotos()
 
+    def is_private_album(self):
+        return (self.albumKey != None and len(self.albumKey)>0)
 
     def get_all (self):
         return self.gphotos.keys()
@@ -80,6 +85,10 @@
         return f
 
     def delete(self, LUID):
+	if (self.is_private_album()):
+            logw("Unable to delete from a private album")
+            return
+
         if not self.gphotos.has_key(LUID):
             logw("Photo does not exit")
             return
@@ -89,8 +98,10 @@
 
     def _upload_photo (self, url, mimeType, name):
         try:
-            ret = self.galbum.uploadPhoto(url, mimeType, name)
-            return ret.id
+            if (not self.is_private_album()):
+                ret = self.galbum.uploadPhoto(url, mimeType, name)
+                return ret.id
+            return None
         except Exception, e:
             raise Exceptions.SyncronizeError("Picasa Upload Error.")
 
@@ -109,12 +120,14 @@
         #get a whole bunch of widgets
         username = widget.get_widget("username")
         password = widget.get_widget("password")
-        album = widget.get_widget("album")                
+        album = widget.get_widget("album")
+        albumKey = widget.get_widget("albumKey")                
         
         #preload the widgets        
         username.set_text(self.username)
         password.set_text(self.password)
         album.set_text (self.album)
+        albumKey.set_text(self.albumKey)
 
         resizecombobox = widget.get_widget("combobox1")
         self._resize_combobox_build(resizecombobox, self.imageSize)
@@ -127,6 +140,7 @@
             self.username = username.get_text()
             self.password = password.get_text()
             self.album = album.get_text()
+            self.albumKey = albumKey.get_text()
 
             self.imageSize = self._resize_combobox_get_active(resizecombobox)
 
@@ -139,14 +153,15 @@
             "imageSize" : self.imageSize,
             "username" : self.username,
             "password" : self.password,
-            "album" : self.album
+            "album" : self.album,
+            "albumKey" : self.albumKey
             }
             
     def is_configured (self):
         if len(self.username) < 1:
             return False
         
-        if len(self.password) < 1:
+        if (len(self.password) < 1) and (len(self.albumKey) < 1):
             return False
             
         if len(self.album) < 1:


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