[geary/mjog/special-type-cleanup: 2/6] Geary.Folder, Geary.SpecialFolderType: Move folder name i18n to client



commit 19d29b9e9dd252b6a9e91ec76996079aa8279c06
Author: Michael Gratton <mike vee net>
Date:   Fri Mar 27 17:45:50 2020 +1100

    Geary.Folder, Geary.SpecialFolderType: Move folder name i18n to client
    
    Remove `Geary.Folder::get_display_name` method, and
    `display-name-changed` signal, and
    `Geary.SpecialFolderType::get_display_name`. Add new equivalent methods
    for client in `Util.I18n` and use those instead.

 src/client/application/application-controller.vala | 16 +++---
 .../application-folder-store-factory.vala          |  2 +-
 .../application/application-main-window.vala       | 21 ++++----
 .../folder-list/folder-list-folder-entry.vala      |  8 +--
 src/client/util/util-i18n.vala                     | 59 ++++++++++++++++++++++
 src/engine/api/geary-folder.vala                   | 36 +------------
 src/engine/api/geary-special-folder-type.vala      | 44 +---------------
 7 files changed, 84 insertions(+), 102 deletions(-)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 00b37cd3..1035930d 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -597,7 +597,7 @@ internal class Application.Controller : Geary.BaseObject {
                         "Conversation moved to %s",
                         "Conversations moved to %s",
                         conversations.size
-                    ).printf(destination.get_display_name()),
+                    ).printf(Util.I18n.to_folder_display_name(destination)),
                     /// Translators: Label for in-app
                     /// notification. String substitution is the name
                     /// of the source folder.
@@ -605,7 +605,7 @@ internal class Application.Controller : Geary.BaseObject {
                         "Conversation restored to %s",
                         "Conversations restored to %s",
                         conversations.size
-                    ).printf(source.get_display_name())
+                    ).printf(Util.I18n.to_folder_display_name(source))
                 ),
                 context.cancellable
             );
@@ -627,7 +627,7 @@ internal class Application.Controller : Geary.BaseObject {
                 "Conversation restored to %s",
                 "Conversations restored to %s",
                 messages.size
-            ).printf(source.get_display_name());
+            ).printf(Util.I18n.to_folder_display_name(source));
 
             if (destination == ARCHIVE) {
                 Geary.FolderSupport.Archive? archive_source = (
@@ -681,7 +681,7 @@ internal class Application.Controller : Geary.BaseObject {
                         "Conversation moved to %s",
                         "Conversations moved to %s",
                         messages.size
-                    ).printf(destination.get_display_name()),
+                    ).printf(Util.I18n.to_folder_display_name(dest)),
                     undone_tooltip
                 );
             }
@@ -704,7 +704,7 @@ internal class Application.Controller : Geary.BaseObject {
                 "Message restored to %s",
                 "Messages restored to %s",
                 messages.size
-            ).printf(source.get_display_name());
+            ).printf(Util.I18n.to_folder_display_name(source));
 
             if (destination == ARCHIVE) {
                 Geary.FolderSupport.Archive? archive_source = (
@@ -760,7 +760,7 @@ internal class Application.Controller : Geary.BaseObject {
                         "Message moved to %s",
                         "Messages moved to %s",
                         messages.size
-                    ).printf(destination.get_display_name()),
+                    ).printf(Util.I18n.to_folder_display_name(dest)),
                     undone_tooltip
                 );
             }
@@ -788,7 +788,7 @@ internal class Application.Controller : Geary.BaseObject {
                         "Conversation labelled as %s",
                         "Conversations labelled as %s",
                         conversations.size
-                    ).printf(destination.get_display_name()),
+                    ).printf(Util.I18n.to_folder_display_name(destination)),
                     /// Translators: Label for in-app
                     /// notification. String substitution is the name
                     /// of the destination folder.
@@ -796,7 +796,7 @@ internal class Application.Controller : Geary.BaseObject {
                         "Conversation un-labelled as %s",
                         "Conversations un-labelled as %s",
                         conversations.size
-                    ).printf(destination.get_display_name())
+                    ).printf(Util.I18n.to_folder_display_name(destination))
                 ),
                 context.cancellable
             );
diff --git a/src/client/application/application-folder-store-factory.vala 
b/src/client/application/application-folder-store-factory.vala
index f69d91fd..6e063858 100644
--- a/src/client/application/application-folder-store-factory.vala
+++ b/src/client/application/application-folder-store-factory.vala
@@ -150,7 +150,7 @@ internal class Application.FolderStoreFactory : Geary.BaseObject {
 
         internal void folder_type_changed() {
             notify_property("folder-type");
-            this._display_name = this.backing.get_display_name();
+            this._display_name = Util.I18n.to_folder_display_name(this.backing);
             notify_property("display-name");
         }
 
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index 3f531e86..d8ff505f 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -593,7 +593,7 @@ public class Application.MainWindow :
             /// substitution being the currently selected folder name,
             /// the second being the selected account name.
             title = _("%s — %s").printf(
-                this.selected_folder.get_display_name(),
+                Util.I18n.to_folder_display_name(this.selected_folder),
                 this.selected_folder.account.information.display_name
             );
         }
@@ -606,7 +606,7 @@ public class Application.MainWindow :
         );
         this.main_toolbar.folder = (
             this.selected_folder != null
-            ? this.selected_folder.get_display_name()
+            ? Util.I18n.to_folder_display_name(this.selected_folder)
             : ""
         );
     }
@@ -1284,14 +1284,13 @@ public class Application.MainWindow :
     }
 
     internal bool prompt_empty_folder(Geary.SpecialFolderType type) {
+        var folder_name = Util.I18n.to_folder_type_display_name(type);
         ConfirmationDialog dialog = new ConfirmationDialog(
             this,
-            _("Empty all email from your %s folder?").printf(
-                type.get_display_name()
-            ),
+            _("Empty all email from your %s folder?").printf(folder_name),
             _("This removes the email from Geary and your email server.") +
             "  <b>" + _("This cannot be undone.") + "</b>",
-            _("Empty %s").printf(type.get_display_name()),
+            _("Empty %s").printf(folder_name),
             "destructive-action"
         );
         dialog.use_secondary_markup(true);
@@ -1693,10 +1692,12 @@ public class Application.MainWindow :
             break;
         }
 
-        if (count > 0)
-            this.main_toolbar.folder = _("%s (%d)").printf(this.selected_folder.get_display_name(), count);
-        else
-            this.main_toolbar.folder = this.selected_folder.get_display_name();
+        var folder_name = Util.I18n.to_folder_display_name(this.selected_folder);
+        this.main_toolbar.folder = (
+            count > 0
+            ? _("%s (%d)").printf(folder_name, count)
+            : folder_name
+        );
     }
 
     private void update_conversation_actions(ConversationCount count) {
diff --git a/src/client/folder-list/folder-list-folder-entry.vala 
b/src/client/folder-list/folder-list-folder-entry.vala
index 99aeacc0..26fb8697 100644
--- a/src/client/folder-list/folder-list-folder-entry.vala
+++ b/src/client/folder-list/folder-list-folder-entry.vala
@@ -14,17 +14,15 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In
         has_new = false;
         folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_TOTAL].connect(on_counts_changed);
         folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_UNREAD].connect(on_counts_changed);
-        folder.display_name_changed.connect(on_display_name_changed);
     }
 
     ~FolderEntry() {
         folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_TOTAL].disconnect(on_counts_changed);
         
folder.properties.notify[Geary.FolderProperties.PROP_NAME_EMAIL_UNREAD].disconnect(on_counts_changed);
-        folder.display_name_changed.disconnect(on_display_name_changed);
     }
 
     public override string get_sidebar_name() {
-        return folder.get_display_name();
+        return Util.I18n.to_folder_display_name(this.folder);
     }
 
     public override string? get_sidebar_tooltip() {
@@ -120,10 +118,6 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In
         sidebar_tooltip_changed(get_sidebar_tooltip());
     }
 
-    private void on_display_name_changed() {
-        sidebar_name_changed(folder.get_display_name());
-    }
-
     public override int get_count() {
         switch (folder.special_folder_type) {
             // for Drafts and Outbox, interested in showing total count, not unread count
diff --git a/src/client/util/util-i18n.vala b/src/client/util/util-i18n.vala
index b6dc731f..7b6a6ddb 100644
--- a/src/client/util/util-i18n.vala
+++ b/src/client/util/util-i18n.vala
@@ -247,4 +247,63 @@ namespace Util.I18n {
         return country_name;
     }
 
+    /**
+     * Returns the localised display name name for specific folder.
+     *
+     * If the folder has a special type, the result of {@link
+     * to_folder_type_display_name} is returned, otherwise the last
+     * folder path step is returned.
+     */
+    public string? to_folder_display_name(Geary.Folder folder) {
+        var name = to_folder_type_display_name(folder.special_folder_type);
+        if (Geary.String.is_empty_or_whitespace(name)) {
+            name = folder.path.name;
+        }
+        return name;
+    }
+
+    /**
+     * Returns the localised name for a specific folder type, if any.
+     */
+    public unowned string? to_folder_type_display_name(Geary.SpecialFolderType type) {
+        switch (type) {
+            case INBOX:
+                return _("Inbox");
+
+            case DRAFTS:
+                return _("Drafts");
+
+            case SENT:
+                return _("Sent");
+
+            case FLAGGED:
+                return _("Starred");
+
+            case IMPORTANT:
+                return _("Important");
+
+            case ALL_MAIL:
+                return _("All Mail");
+
+            case SPAM:
+                return _("Spam");
+
+            case TRASH:
+                return _("Trash");
+
+            case OUTBOX:
+                return _("Outbox");
+
+            case SEARCH:
+                return _("Search");
+
+            case ARCHIVE:
+                return _("Archive");
+
+            case NONE:
+            default:
+                return null;
+        }
+    }
+
 }
diff --git a/src/engine/api/geary-folder.vala b/src/engine/api/geary-folder.vala
index 2602f87e..422cae80 100644
--- a/src/engine/api/geary-folder.vala
+++ b/src/engine/api/geary-folder.vala
@@ -393,15 +393,6 @@ public abstract class Geary.Folder : BaseObject, Logging.Source {
     public signal void special_folder_type_changed(Geary.SpecialFolderType old_type,
         Geary.SpecialFolderType new_type);
 
-    /**
-     * Fired when the Folder's display name has changed.
-     *
-     * @see get_display_name
-     */
-    public signal void display_name_changed();
-
-    protected Folder() {
-    }
 
     protected virtual void notify_opened(Geary.Folder.OpenState state, int count) {
         opened(state, count);
@@ -448,32 +439,9 @@ public abstract class Geary.Folder : BaseObject, Logging.Source {
         email_locally_complete(ids);
     }
 
-    /**
-     * In its default implementation, this will also call {@link notify_display_name_changed} since
-     * that's often the case; if not, subclasses should override.
-     */
-    protected virtual void notify_special_folder_type_changed(Geary.SpecialFolderType old_type,
-        Geary.SpecialFolderType new_type) {
+    protected virtual void notify_special_folder_type_changed(SpecialFolderType old_type,
+                                                              SpecialFolderType new_type) {
         special_folder_type_changed(old_type, new_type);
-
-        // in default implementation, this may also mean the display name changed; subclasses may
-        // override this behavior, but no way to detect this, so notify
-        notify_display_name_changed();
-    }
-
-    protected virtual void notify_display_name_changed() {
-        display_name_changed();
-    }
-
-    /**
-     * Returns a name suitable for displaying to the user.
-     *
-     * Default is to display the name of the Folder's path, unless it's a special folder,
-     * in which case {@link SpecialFolderType.get_display_name} is returned.
-     */
-    public virtual string get_display_name() {
-        return (special_folder_type == Geary.SpecialFolderType.NONE)
-            ? path.name : special_folder_type.get_display_name();
     }
 
     /** Determines if a folder has been opened, and if so in which way. */
diff --git a/src/engine/api/geary-special-folder-type.vala b/src/engine/api/geary-special-folder-type.vala
index 9d1b9865..a5fea1a4 100644
--- a/src/engine/api/geary-special-folder-type.vala
+++ b/src/engine/api/geary-special-folder-type.vala
@@ -5,6 +5,7 @@
  */
 
 public enum Geary.SpecialFolderType {
+
     NONE,
     INBOX,
     SEARCH,
@@ -18,49 +19,8 @@ public enum Geary.SpecialFolderType {
     OUTBOX,
     ARCHIVE;
 
-    public unowned string get_display_name() {
-        switch (this) {
-            case INBOX:
-                return _("Inbox");
-
-            case DRAFTS:
-                return _("Drafts");
-
-            case SENT:
-                return _("Sent Mail");
-
-            case FLAGGED:
-                return _("Starred");
-
-            case IMPORTANT:
-                return _("Important");
-
-            case ALL_MAIL:
-                return _("All Mail");
-
-            case SPAM:
-                return _("Spam");
-
-            case TRASH:
-                return _("Trash");
-
-            case OUTBOX:
-                return _("Outbox");
-
-            case SEARCH:
-                return _("Search");
-
-            case ARCHIVE:
-                return _("Archive");
-
-            case NONE:
-            default:
-                return _("None");
-        }
-    }
-
     public bool is_outgoing() {
         return this == SENT || this == OUTBOX;
     }
-}
 
+}


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