[shotwell] Allow rating to be uploaded via piwigo publish - option in piwigo publish pane to control uploading



commit 81df0c2a8a495524dd18cba18f72f19b2252779d
Author: Suen Chun Hui <23443533+suenchunhui users noreply github com>
Date:   Sat Dec 14 17:52:43 2019 +0800

    Allow rating to be uploaded via piwigo publish
    - option in piwigo publish pane to control uploading of rating

 data/gsettings/org.yorba.shotwell.gschema.xml      |  6 +++
 plugins/shotwell-publishing/PiwigoPublishing.vala  | 56 +++++++++++++++++++++-
 .../piwigo_publishing_options_pane.ui              | 18 ++++++-
 src/plugins/PublishingInterfaces.vala              |  5 ++
 src/publishing/APIGlue.vala                        |  4 ++
 5 files changed, 86 insertions(+), 3 deletions(-)
---
diff --git a/data/gsettings/org.yorba.shotwell.gschema.xml b/data/gsettings/org.yorba.shotwell.gschema.xml
index fa83b97a..d45af6c7 100644
--- a/data/gsettings/org.yorba.shotwell.gschema.xml
+++ b/data/gsettings/org.yorba.shotwell.gschema.xml
@@ -578,6 +578,12 @@
         <summary>do not upload tags when uploading to Piwigo</summary>
         <description>Whether images being uploaded to Piwigo should have their tags removed on upload, such 
that these tags will not appear on the remote Piwigo server.</description>
     </key>
+
+    <key name="last-no-upload-ratings" type="b">
+        <default>false</default>
+        <summary>do not upload ratings when uploading to Piwigo</summary>
+        <description>Whether images being uploaded to Piwigo should have their ratings uploaded, such that 
these ratings will not appear on the remote Piwigo server.</description>
+    </key>
 </schema>
 
 <schema id="org.yorba.shotwell.sharing.publishing-gallery3">
diff --git a/plugins/shotwell-publishing/PiwigoPublishing.vala 
b/plugins/shotwell-publishing/PiwigoPublishing.vala
index 8a10eee0..58d638e7 100644
--- a/plugins/shotwell-publishing/PiwigoPublishing.vala
+++ b/plugins/shotwell-publishing/PiwigoPublishing.vala
@@ -117,6 +117,7 @@ internal class PublishingParameters {
     public SizeEntry photo_size = null;
     public bool title_as_comment = false;
     public bool no_upload_tags = false;
+    public bool no_upload_ratings = false;
 
     public PublishingParameters() {
     }
@@ -256,6 +257,14 @@ public class PiwigoPublisher : Spit.Publishing.Publisher, GLib.Object {
         host.set_config_bool("last-no-upload-tags", no_upload_tags);
     }
     
+    private bool get_last_no_upload_ratings() {
+        return host.get_config_bool("last-no-upload-ratings", false);
+    }
+
+    private void set_last_no_upload_ratings(bool no_upload_ratings) {
+        host.set_config_bool("last-no-upload-ratings", no_upload_ratings);
+    }
+
     private bool get_metadata_removal_choice() {
         return host.get_config_bool("strip_metadata", false);
     }
@@ -678,7 +687,7 @@ public class PiwigoPublisher : Spit.Publishing.Publisher, GLib.Object {
         host.set_service_locked(false);
         PublishingOptionsPane opts_pane = new PublishingOptionsPane(
             this, categories, get_last_category(), get_last_permission_level(), get_last_photo_size(),
-            get_last_title_as_comment(), get_last_no_upload_tags(), get_metadata_removal_choice());
+            get_last_title_as_comment(), get_last_no_upload_tags(), get_last_no_upload_ratings(), 
get_metadata_removal_choice());
         opts_pane.logout.connect(on_publishing_options_pane_logout_clicked);
         opts_pane.publish.connect(on_publishing_options_pane_publish_clicked);
         host.install_dialog_pane(opts_pane, Spit.Publishing.PluginHost.ButtonMode.CLOSE);
@@ -842,6 +851,7 @@ public class PiwigoPublisher : Spit.Publishing.Publisher, GLib.Object {
         set_last_photo_size(parameters.photo_size.id);
         set_last_title_as_comment(parameters.title_as_comment);
         set_last_no_upload_tags(parameters.no_upload_tags);
+        set_last_no_upload_ratings(parameters.no_upload_ratings);
         set_metadata_removal_choice(strip_metadata);
 
         progress_reporter = host.serialize_publishables(parameters.photo_size.id, this.strip_metadata);
@@ -1206,6 +1216,7 @@ internal class PublishingOptionsPane : Shotwell.Plugins.Common.BuilderPane {
     private Gtk.CheckButton strip_metadata_check = null;
     private Gtk.CheckButton title_as_comment_check = null;
     private Gtk.CheckButton no_upload_tags_check = null;
+    private Gtk.CheckButton no_upload_ratings_check = null;
     private Gtk.Button logout_button;
     private Gtk.Button publish_button;
     private Gtk.TextView album_comment;
@@ -1219,6 +1230,7 @@ internal class PublishingOptionsPane : Shotwell.Plugins.Common.BuilderPane {
     public int last_photo_size { private get; construct; }
     public bool last_title_as_comment { private get; construct; }
     public bool last_no_upload_tags { private get; construct; }
+    public bool last_no_upload_ratings { private get; construct; }
     public bool strip_metadata_enabled { private get; construct; }
     public Gee.List<Category> existing_categories { private get; construct; }
     public string default_comment { private get; construct; }
@@ -1233,6 +1245,7 @@ internal class PublishingOptionsPane : Shotwell.Plugins.Common.BuilderPane {
                                  int last_photo_size,
                                  bool last_title_as_comment,
                                  bool last_no_upload_tags,
+                                 bool last_no_upload_ratings,
                                  bool strip_metadata_enabled) {
         Object (resource_path : Resources.RESOURCE_PATH +
                                 "/piwigo_publishing_options_pane.ui",
@@ -1243,6 +1256,7 @@ internal class PublishingOptionsPane : Shotwell.Plugins.Common.BuilderPane {
                 last_photo_size : last_photo_size,
                 last_title_as_comment : last_title_as_comment,
                 last_no_upload_tags : last_no_upload_tags,
+                last_no_upload_ratings : last_no_upload_ratings,
                 strip_metadata_enabled : strip_metadata_enabled,
                 existing_categories : new Gee.ArrayList<Category>.wrap (categories,
                                                           Category.equal),
@@ -1276,6 +1290,9 @@ internal class PublishingOptionsPane : Shotwell.Plugins.Common.BuilderPane {
         no_upload_tags_check = builder.get_object("no_upload_tags_check") as Gtk.CheckButton;
         no_upload_tags_check.set_active(last_no_upload_tags);
 
+        no_upload_ratings_check = builder.get_object("no_upload_ratings_check") as Gtk.CheckButton;
+        no_upload_ratings_check.set_active(last_no_upload_ratings);
+
         logout_button = builder.get_object("logout_button") as Gtk.Button;
         logout_button.clicked.connect(on_logout_button_clicked);
 
@@ -1326,6 +1343,7 @@ internal class PublishingOptionsPane : Shotwell.Plugins.Common.BuilderPane {
         params.photo_size = photo_sizes[size_combo.get_active()];
         params.title_as_comment = title_as_comment_check.get_active();
         params.no_upload_tags = no_upload_tags_check.get_active();
+        params.no_upload_ratings = no_upload_ratings_check.get_active();
         if (create_new_radio.get_active()) {
             string uploadcomment = album_comment.buffer.text.strip();
             int a = within_existing_combo.get_active();
@@ -1721,12 +1739,14 @@ private class CategoriesAddTransaction : Transaction {
 
 private class ImagesAddTransaction : Publishing.RESTSupport.UploadTransaction {
     private PublishingParameters parameters = null;
+    private Session session = null;
 
     public ImagesAddTransaction(Session session, PublishingParameters parameters, 
Spit.Publishing.Publishable publishable) {
         base.with_endpoint_url(session, publishable, session.get_pwg_url());
         if (session.is_authenticated()) {
             add_header("Cookie", "pwg_id=".concat(session.get_pwg_id()));
         }
+        this.session = session;
         this.parameters = parameters;
 
         string[] keywords = publishable.get_publishing_keywords();
@@ -1790,8 +1810,40 @@ private class ImagesAddTransaction : Publishing.RESTSupport.UploadTransaction {
         disposition_table.insert("name", "image");
 
         set_binary_disposition_table(disposition_table);
+        base.completed.connect(on_completed);
+    }
+
+    private void on_completed() {
+        try{
+            Publishing.RESTSupport.XmlDocument resp_doc = Publishing.RESTSupport.XmlDocument.parse_string(
+                base.get_response(), Transaction.validate_xml);
+            Xml.Node* image_node = resp_doc.get_named_child(resp_doc.get_root_node(), "image_id");
+            string image_id = image_node->get_content();
+
+            if (!parameters.no_upload_ratings)
+                new ImagesAddRating(session, publishable, image_id);
+        } catch(Spit.Publishing.PublishingError err) {
+            debug("Response parse error");
+        }
     }
 }
 
-} // namespace
+private class ImagesAddRating : Publishing.RESTSupport.UploadTransaction {
+    public ImagesAddRating(Session session, Spit.Publishing.Publishable publishable, string image_id) {
+        base.with_endpoint_url(session, publishable, session.get_pwg_url());
+        if (session.is_authenticated()) {
+            add_header("Cookie", "pwg_id=".concat(session.get_pwg_id()));
+        }
+        add_argument("method", "pwg.images.rate");
+        add_argument("image_id", image_id);
+        add_argument("rate", publishable.get_rating().to_string());
+
+        try {
+            base.execute();
+        } catch (Spit.Publishing.PublishingError err) {
+            debug("Rating upload error");
+        }
+    }
+}
 
+} // namespace
diff --git a/plugins/shotwell-publishing/piwigo_publishing_options_pane.ui 
b/plugins/shotwell-publishing/piwigo_publishing_options_pane.ui
index 50f43030..c17d6164 100644
--- a/plugins/shotwell-publishing/piwigo_publishing_options_pane.ui
+++ b/plugins/shotwell-publishing/piwigo_publishing_options_pane.ui
@@ -246,6 +246,22 @@
             <property name="position">4</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkCheckButton" id="no_upload_ratings_check">
+            <property name="label" translatable="yes">_Do not upload ratings</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="halign">start</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">5</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkButtonBox" id="hbuttonbox1">
             <property name="visible">True</property>
@@ -280,7 +296,7 @@
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">5</property>
+            <property name="position">6</property>
           </packing>
         </child>
       </object>
diff --git a/src/plugins/PublishingInterfaces.vala b/src/plugins/PublishingInterfaces.vala
index 99017a73..e5915ece 100644
--- a/src/plugins/PublishingInterfaces.vala
+++ b/src/plugins/PublishingInterfaces.vala
@@ -565,6 +565,11 @@ public interface Publishable : GLib.Object {
      */
     public abstract GLib.DateTime get_exposure_date_time();
     
+    /**
+     * Returns the rating on the file.
+     */
+    public abstract uint get_rating();
+
     //
     // For future expansion.
     //
diff --git a/src/publishing/APIGlue.vala b/src/publishing/APIGlue.vala
index 23c4e8c5..2946e39e 100644
--- a/src/publishing/APIGlue.vala
+++ b/src/publishing/APIGlue.vala
@@ -128,6 +128,10 @@ public class MediaSourcePublishableWrapper : Spit.Publishing.Publishable, GLib.O
     public GLib.DateTime get_exposure_date_time() {
         return new GLib.DateTime.from_unix_local(wrapped.get_exposure_time());
     }
+
+    public uint get_rating() {
+        return wrapped.get_rating();
+    }
 }
 
 }


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