Here is a small patch for metablog

Oliver Ripka
patches@@bockcay.de

For Programm: gnome-blog
For Version: 0.9.1-3 with debian patches
Debian-Url: http://packages.debian.org/unstable/gnome/gnome-blog
Url: http://www.gnome.org/~seth/gnome-blog/
Original Author: Seth Nickell

This adds category support for the MetaBlog RPC API.
E can only select one category for each post.
I know that the api allows to post in multiple categories but
frankly I do not use that feature and I did not find a adequate
widget in gnome that fitted well in the gnome-blog-post dialog

Category selecton will only work for metablog api (wordpress, etc)

Apply this patch doing so:
:~$ cd gnome-blog-0.8/
:~$ patch -p1 < ../category.patch


diff -u -r gnome-blog-0.9.1/blog_poster.py toHack/blog_poster.py
--- gnome-blog-0.9.1/blog_poster.py     2006-11-01 12:46:41.000000000 +0100
+++ toHack/blog_poster.py       2006-11-01 12:51:16.000000000 +0100
@@ -85,7 +85,34 @@
         titleBox.pack_start(gtk.Label(_("Title:")), expand=False)
         titleBox.pack_start(self.titleEntry)
 
+       client = gconf.client_get_default()
+        protocol= client.get_string(gconf_prefix + "/blog_protocol")
+        self.protocol= protocol
+
+        if protocol == "MetaWeblog":
+            self.categories= blog.getCategories(gconf_prefix)
+                      
+            liststore = gtk.ListStore(gobject.TYPE_STRING)
+            self.catCombo = gtk.ComboBox(liststore)
+            cell = gtk.CellRendererText()
+            self.catCombo.pack_start(cell, True)
+            self.catCombo.add_attribute(cell, 'text', 0)
+            
+            if None != self.categories:
+                for x in self.categories:
+                    self.catCombo.append_text(x['categoryName'])
+            
+                self.catCombo.set_active(0)
+                
+                catBox = gtk.HBox()
+                catBox.set_spacing(12)
+                catBox.pack_start(gtk.Label(_("Category:")), expand=False)
+                catBox.pack_start(self.catCombo, expand=False)
+
+
         box.pack_start(titleBox, expand=False)
+        if protocol == "MetaWeblog" and self.categories!= None: 
+                 box.pack_start(catBox)
         box.pack_start(scroller)
         box.pack_start(buttonBox, expand=False)
 
@@ -133,11 +160,16 @@
         print "Text is: {\n %s \n }\n" % (html_text)
         title = self.titleEntry.get_text().decode('utf-8')
 
+       category = self.catCombo.get_active_text()
+
         # Don't post silly blog entries like blank ones
         if not self._postIsReasonable(html_text):
             return
 
-        successful_post = blog.postEntry(title, html_text, gconf_prefix)
+        if self.protocol== "MetaWeblog":
+            successful_post = blog.postEntry(title, html_text, gconf_prefix, 
category)
+        else:
+            successful_post = blog.postEntry(title, html_text, gconf_prefix)
 
         if successful_post:
             # Only delete the entry if posting was successful
diff -u -r gnome-blog-0.9.1/blog.py toHack/blog.py
--- gnome-blog-0.9.1/blog.py    2006-11-01 12:46:41.000000000 +0100
+++ toHack/blog.py      2006-11-01 12:53:59.000000000 +0100
@@ -23,6 +23,15 @@
     return blog_backend.postEntry(username, password,
                                   url, title, entry,
                                   client, gconf_prefix)
+
+def postEntry (title, entry, gconf_prefix, catName):
+    client = gconf.client_get_default()
+    username, password, protocol, url = _getSettings(client, gconf_prefix)
+    blog_backend = _getBlogBackend(protocol)
+          
+    return blog_backend.postEntry(username, password,
+                                  url, title, entry,
+                                  client, gconf_prefix, catName)
         
 def uploadImage (image, gconf_prefix):
     client = gconf.client_get_default()
@@ -43,6 +52,15 @@
     
     return imageurl
 
+def getCategories(gconf_prefix):
+    client = gconf.client_get_default()
+    username, password, protocol, url = _getSettings(client, gconf_prefix)
+    blog_backend = _getBlogBackend(protocol)
+    
+    print "Protocol: "+ protocol
+    return blog_backend.getCategories(username, password,
+                                  url, client, gconf_prefix)
+
 def _getSettings(client, gconf_prefix):
     print "Using prefix %s" % (gconf_prefix)
     username = client.get_string(gconf_prefix + "/blog_username")
diff -u -r gnome-blog-0.9.1/protocols/MetaWeblog.py 
toHack/protocols/MetaWeblog.py
--- gnome-blog-0.9.1/protocols/MetaWeblog.py    2006-11-01 12:46:41.000000000 
+0100
+++ toHack/protocols/MetaWeblog.py      2006-11-01 13:36:09.000000000 +0100
@@ -16,8 +16,33 @@
     def __init__(self):
         bloggerAPI.Blog.__init__(self)
 
+    def getCategories(self, username, password, base_url, client, 
gconf_prefix):
+        url = self._getURL(base_url, client, gconf_prefix)
+        
+        if (base_url == None):
+            hig_alert.reportError("Could not get categories.")
+            return FALSE
+        
+        blog_id  = client.get_string(gconf_prefix + "/blog_id")
+
+        proxy_transport = proxy.GnomeProxyTransport(client)
+        server = proxy_transport.get_server(url)
+        
+        try:
+            success = server.metaWeblog.getCategories(blog_id, username, 
password)
+        except xmlrpclib.Fault, e:
+            hig_alert.handleBloggerAPIFault(e, "Could not get categories", 
username, blog_id, url)
+            success = None
+        except xmlrpclib.ProtocolError, e:
+            hig_alert.reportError("Could not get categories", 'URL \'%s\' does 
not seem to be a valid bloggerAPI XML-RPC server. Web server reported: %s.' % 
(url, hig_alert.italic(e.errmsg)))
+            success = None    
+        except :
+            success = None
+            
+        return success
+
     def postEntry (self, username, password, base_url, title,
-                   entry, client, gconf_prefix):
+                   entry, client, gconf_prefix, catName):
 
         url = self._getURL(base_url, client, gconf_prefix)
 
@@ -37,6 +62,7 @@
         content = {}
         content['title'] = title
         content['description'] = entry
+       content['categories'] = [catName]
 
         try:
             server.metaWeblog.newPost(blog_id, username, password, content, 
xmlrpclib.True)

Reply via email to