[gnome-games/wip/exalm/rebrand: 106/124] filename-title: Turn into a simple function
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/rebrand: 106/124] filename-title: Turn into a simple function
- Date: Sat, 19 Jun 2021 14:37:46 +0000 (UTC)
commit c70405631e4e75ae01032a1f17a55e799164937b
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Mar 30 23:43:05 2021 +0500
filename-title: Turn into a simple function
There isn't much need to have FilenameTitle when we can also use
GenericTitle and pass a string into it.
src/core/game-parser.vala | 2 +-
src/meson.build | 2 +-
src/utils/{filename-title.vala => filename.vala} | 26 +++++++++++-------------
3 files changed, 14 insertions(+), 16 deletions(-)
---
diff --git a/src/core/game-parser.vala b/src/core/game-parser.vala
index 243e4eb4..8025a66f 100644
--- a/src/core/game-parser.vala
+++ b/src/core/game-parser.vala
@@ -16,7 +16,7 @@ public class Games.GameParser : Object {
}
public virtual Title get_title () {
- return new FilenameTitle (uri);
+ return new GenericTitle (Filename.get_title (uri));
}
public virtual Icon? get_icon () {
diff --git a/src/meson.build b/src/meson.build
index 18e3fb2b..f10ab197 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -211,7 +211,7 @@ vala_sources = [
'utils/dialog-utils.vala',
'utils/directory.vala',
'utils/file-operations.vala',
- 'utils/filename-title.vala',
+ 'utils/filename.vala',
'utils/fingerprint.vala',
'utils/grep.vala',
'utils/local-cover.vala',
diff --git a/src/utils/filename-title.vala b/src/utils/filename.vala
similarity index 59%
rename from src/utils/filename-title.vala
rename to src/utils/filename.vala
index 25027c57..a995286e 100644
--- a/src/utils/filename-title.vala
+++ b/src/utils/filename.vala
@@ -1,19 +1,9 @@
// This file is part of GNOME Games. License: GPL-3.0+.
-public class Games.FilenameTitle : Object, Title {
- private static Regex filename_ext_regex;
+public class Games.Filename : Object {
+ private static Regex filename_ext_regex = null;
- private Uri uri;
-
- static construct {
- filename_ext_regex = /\.\w+$/;
- }
-
- public FilenameTitle (Uri uri) {
- this.uri = uri;
- }
-
- public string get_title () throws Error {
+ public static string get_title (Uri uri) {
var file = uri.to_file ();
string name;
try {
@@ -26,7 +16,15 @@ public class Games.FilenameTitle : Object, Title {
name = file.get_basename ();
}
- name = filename_ext_regex.replace (name, name.length, 0, "");
+ try {
+ if (filename_ext_regex == null)
+ filename_ext_regex = /\.\w+$/;;
+
+ name = filename_ext_regex.replace (name, name.length, 0, "");
+ } catch (RegexError e) {
+ error ("Regex replacement failed: %s", e.message);
+ }
+
name = name.split ("(")[0];
name = name.strip ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]