[gnome-games] Use display name instead of basename for user-facing strings Fixes #228



commit 94fe3b0c3204c28a2680ceeafb9a2d69f28db81d
Author: Neville <nevilleantony98 gmail com>
Date:   Tue Feb 25 19:34:04 2020 +0530

    Use display name instead of basename for user-facing strings
    Fixes #228

 plugins/love/src/love-title.vala | 12 +++++++++++-
 src/dummy/dummy-game.vala        | 12 +++++++++++-
 src/ui/application.vala          | 12 +++++++++++-
 src/utils/filename-title.vala    | 12 +++++++++++-
 4 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/plugins/love/src/love-title.vala b/plugins/love/src/love-title.vala
index 61646299..08bb4bc1 100644
--- a/plugins/love/src/love-title.vala
+++ b/plugins/love/src/love-title.vala
@@ -22,7 +22,17 @@ private class Games.LoveTitle : Object, Title {
 
                var uri = package.get_uri ();
                var file = uri.to_file ();
-               title = file.get_basename ();
+
+               try {
+                       var fileinfo = file.query_info (FileAttribute.STANDARD_DISPLAY_NAME,
+                                                       FileQueryInfoFlags.NONE,
+                                                       null);
+                       title = fileinfo.get_display_name ();
+               } catch (Error e) {
+                       critical ("Couldn't retrieve filename: %s", e.message);
+                       title = file.get_basename ();
+               }
+
                title = title.split (".")[0];
                title = title.split ("(")[0];
                title = title.strip ();
diff --git a/src/dummy/dummy-game.vala b/src/dummy/dummy-game.vala
index 2917bf83..dcc4a70e 100644
--- a/src/dummy/dummy-game.vala
+++ b/src/dummy/dummy-game.vala
@@ -16,7 +16,17 @@ private class Games.DummyGame : Object, Game {
                this.uri = uri;
 
                var file = uri.to_file ();
-               var name = file.get_basename ();
+               string name;
+               try {
+                       var fileinfo = file.query_info (FileAttribute.STANDARD_DISPLAY_NAME,
+                                                       FileQueryInfoFlags.NONE,
+                                                       null);
+                       name = fileinfo.get_display_name ();
+               } catch (Error e) {
+                       critical ("Couldn't retrieve filename: %s", e.message);
+                       name = file.get_basename();
+               }
+
                name = name.split (".")[0];
                name = name.split ("(")[0];
                _name = name.strip ();
diff --git a/src/ui/application.vala b/src/ui/application.vala
index bdb9e1e9..0d8c002e 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -187,7 +187,17 @@ public class Games.Application : Gtk.Application {
                var game = game_for_uris (uris);
 
                if (game == null) {
-                       var filename = file.get_basename ();
+                       string filename;
+                       try {
+                               var fileinfo = file.query_info (FileAttribute.STANDARD_DISPLAY_NAME,
+                                                               FileQueryInfoFlags.NONE,
+                                                               null);
+                               filename = fileinfo.get_display_name ();
+                       } catch (Error e) {
+                               critical ("Couldn't retrieve filename: %s", e.message);
+                               filename = file.get_basename ();
+                       }
+
                        var error_msg = _("An unexpected error occurred while trying to run %s").printf 
(filename);
                        window.show_error (error_msg);
                        return;
diff --git a/src/utils/filename-title.vala b/src/utils/filename-title.vala
index 975e86e8..25027c57 100644
--- a/src/utils/filename-title.vala
+++ b/src/utils/filename-title.vala
@@ -15,7 +15,17 @@ public class Games.FilenameTitle : Object, Title {
 
        public string get_title () throws Error {
                var file = uri.to_file ();
-               var name = file.get_basename ();
+               string name;
+               try {
+                       var fileinfo = file.query_info (FileAttribute.STANDARD_DISPLAY_NAME,
+                                                       FileQueryInfoFlags.NONE,
+                                                       null);
+                       name = fileinfo.get_display_name ();
+               } catch (Error e) {
+                       critical ("Couldn't retrieve filename: %s", e.message);
+                       name = file.get_basename ();
+               }
+
                name = filename_ext_regex.replace (name, name.length, 0, "");
                name = name.split ("(")[0];
                name = name.strip ();


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