[gnome-games] utils: Add FilenameTitle



commit 206286f8fed3180ac3f10dc79aa47b33e01c79bd
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Mar 22 18:19:26 2016 +0100

    utils: Add FilenameTitle
    
    This will be used in subsequent commits to create generic games using
    a filename as their title source.

 src/Makefile.am               |    1 +
 src/utils/filename-title.vala |   25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 53dc333..6e0c9f3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -76,6 +76,7 @@ gnome_games_SOURCES = \
        ui/search-bar.vala \
        ui/ui-state.vala \
        \
+       utils/filename-title.vala \
        utils/fingerprint.vala \
        utils/grep.vala \
        \
diff --git a/src/utils/filename-title.vala b/src/utils/filename-title.vala
new file mode 100644
index 0000000..e140dda
--- /dev/null
+++ b/src/utils/filename-title.vala
@@ -0,0 +1,25 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.FilenameTitle : Object, Title {
+       private static Regex filename_ext_regex;
+
+       private string uri;
+
+       static construct {
+               filename_ext_regex = /\.\w+$/;
+       }
+
+       public FilenameTitle (string uri) {
+               this.uri = uri;
+       }
+
+       public string get_title () throws Error {
+               var file = File.new_for_uri (uri);
+               var name = file.get_basename ();
+               name = filename_ext_regex.replace (name, name.length, 0, "");
+               name = name.split ("(")[0];
+               name = name.strip ();
+
+               return name;
+       }
+}


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