[retro-gtk] core: Add the user-name property
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] core: Add the user-name property
- Date: Sat, 10 Apr 2021 07:39:07 +0000 (UTC)
commit 7fe4930fd50face74ab495f7ec03163ffbd224af
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Dec 17 00:33:58 2020 +0100
core: Add the user-name property
This also implements RETRO_ENVIRONMENT_GET_USERNAME.
UNIMPLEMENTED.md | 16 ----------
retro-gtk/retro-core.c | 62 +++++++++++++++++++++++++++++++++++++++
retro-gtk/retro-core.h | 3 ++
retro-runner/ipc-runner-impl.c | 3 ++
retro-runner/retro-core-private.h | 1 +
retro-runner/retro-core.c | 61 ++++++++++++++++++++++++++++++++++++++
retro-runner/retro-core.h | 3 ++
retro-runner/retro-environment.c | 18 +++++++++++-
shared/org.gnome.Retro.Runner.xml | 1 +
9 files changed, 151 insertions(+), 17 deletions(-)
---
diff --git a/UNIMPLEMENTED.md b/UNIMPLEMENTED.md
index 66fb967..95eee46 100644
--- a/UNIMPLEMENTED.md
+++ b/UNIMPLEMENTED.md
@@ -1214,22 +1214,6 @@ RETRO_API bool retro_load_game_special(
);
```
-## User Name
-
-The user name accessor is unimplemented.
-
-```
-#define RETRO_ENVIRONMENT_GET_USERNAME 38
- /* const char **
- * Returns the specified username of the frontend, if specified
by the user.
- * This username can be used as a nickname for a core that has
online facilities
- * or any other mode where personalization of the user is
desirable.
- * The returned value can be NULL.
- * If this environ callback is used by a core that requires a
valid username,
- * a default username should be specified by the core.
- */
-```
-
## Variables
The varibles system is implemented but unused.
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index 6d5c6e2..a290e15 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -68,6 +68,7 @@ struct _RetroCore
gchar *system_directory;
gchar *content_directory;
gchar *save_directory;
+ gchar *user_name;
gchar **media_uris;
gdouble frames_per_second;
@@ -100,6 +101,7 @@ enum {
PROP_SYSTEM_DIRECTORY,
PROP_CONTENT_DIRECTORY,
PROP_SAVE_DIRECTORY,
+ PROP_USER_NAME,
PROP_IS_INITIATED,
PROP_GAME_LOADED,
PROP_SUPPORT_NO_GAME,
@@ -221,6 +223,10 @@ retro_core_get_property (GObject *object,
case PROP_SAVE_DIRECTORY:
g_value_set_string (value, retro_core_get_save_directory (self));
+ break;
+ case PROP_USER_NAME:
+ g_value_set_string (value, retro_core_get_user_name (self));
+
break;
case PROP_IS_INITIATED:
g_value_set_boolean (value, retro_core_get_is_initiated (self));
@@ -277,6 +283,10 @@ retro_core_set_property (GObject *object,
case PROP_SAVE_DIRECTORY:
retro_core_set_save_directory (self, g_value_get_string (value));
+ break;
+ case PROP_USER_NAME:
+ retro_core_set_user_name (self, g_value_get_string (value));
+
break;
case PROP_RUNAHEAD:
retro_core_set_runahead (self, g_value_get_uint (value));
@@ -382,6 +392,21 @@ retro_core_class_init (RetroCoreClass *klass)
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
+ /**
+ * RetroCore:user-name:
+ *
+ * The name of the user.
+ */
+ properties[PROP_USER_NAME] =
+ g_param_spec_string ("user-name",
+ "User name",
+ "The user name",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+
/**
* RetroCore:is-initiated:
*
@@ -818,6 +843,43 @@ retro_core_set_save_directory (RetroCore *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SAVE_DIRECTORY]);
}
+/**
+ * retro_core_get_user_name:
+ * @self: a #RetroCore
+ *
+ * Gets the name of the user.
+ *
+ * Returns: the name of the user
+ */
+const gchar *
+retro_core_get_user_name (RetroCore *self)
+{
+ g_return_val_if_fail (RETRO_IS_CORE (self), NULL);
+
+ return self->user_name;
+}
+
+/**
+ * retro_core_set_user_name:
+ * @self: a #RetroCore
+ * @user_name: the user name
+ *
+ * Sets the name of the user.
+ */
+void
+retro_core_set_user_name (RetroCore *self,
+ const gchar *user_name)
+{
+ g_return_if_fail (RETRO_IS_CORE (self));
+
+ if (g_strcmp0 (user_name, retro_core_get_user_name (self)) == 0)
+ return;
+
+ g_free (self->user_name);
+ self->user_name = g_strdup (user_name);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER_NAME]);
+}
+
/**
* retro_core_get_is_initiated:
* @self: a #RetroCore
diff --git a/retro-gtk/retro-core.h b/retro-gtk/retro-core.h
index 3834e2c..6a7d6e4 100644
--- a/retro-gtk/retro-core.h
+++ b/retro-gtk/retro-core.h
@@ -29,6 +29,9 @@ void retro_core_set_content_directory (RetroCore *self,
const gchar *retro_core_get_save_directory (RetroCore *self);
void retro_core_set_save_directory (RetroCore *self,
const gchar *save_directory);
+const gchar *retro_core_get_user_name (RetroCore *self);
+void retro_core_set_user_name (RetroCore *self,
+ const gchar *user_name);
gboolean retro_core_get_is_initiated (RetroCore *self);
gboolean retro_core_get_game_loaded (RetroCore *self);
gboolean retro_core_get_support_no_game (RetroCore *self);
diff --git a/retro-runner/ipc-runner-impl.c b/retro-runner/ipc-runner-impl.c
index db3325c..f317ea0 100644
--- a/retro-runner/ipc-runner-impl.c
+++ b/retro-runner/ipc-runner-impl.c
@@ -503,6 +503,9 @@ ipc_runner_impl_constructed (GObject *object)
g_object_bind_property (self->core, "save-directory",
self, "save-directory",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ g_object_bind_property (self->core, "user-name",
+ self, "user-name",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
g_object_bind_property (self->core, "game-loaded",
self, "game-loaded",
G_BINDING_SYNC_CREATE);
diff --git a/retro-runner/retro-core-private.h b/retro-runner/retro-core-private.h
index 34b2c33..a7cd2b2 100644
--- a/retro-runner/retro-core-private.h
+++ b/retro-runner/retro-core-private.h
@@ -32,6 +32,7 @@ struct _RetroCore
gchar *libretro_path;
gchar *content_directory;
gchar *save_directory;
+ gchar *user_name;
gboolean is_initiated;
gboolean game_loaded;
gboolean support_no_game;
diff --git a/retro-runner/retro-core.c b/retro-runner/retro-core.c
index 7ec0936..a1f86d2 100644
--- a/retro-runner/retro-core.c
+++ b/retro-runner/retro-core.c
@@ -33,6 +33,7 @@ enum {
PROP_SYSTEM_DIRECTORY,
PROP_CONTENT_DIRECTORY,
PROP_SAVE_DIRECTORY,
+ PROP_USER_NAME,
PROP_IS_INITIATED,
PROP_GAME_LOADED,
PROP_SUPPORT_NO_GAME,
@@ -163,6 +164,10 @@ retro_core_get_property (GObject *object,
case PROP_SAVE_DIRECTORY:
g_value_set_string (value, retro_core_get_save_directory (self));
+ break;
+ case PROP_USER_NAME:
+ g_value_set_string (value, retro_core_get_user_name (self));
+
break;
case PROP_GAME_LOADED:
g_value_set_boolean (value, retro_core_get_game_loaded (self));
@@ -215,6 +220,10 @@ retro_core_set_property (GObject *object,
case PROP_SAVE_DIRECTORY:
retro_core_set_save_directory (self, g_value_get_string (value));
+ break;
+ case PROP_USER_NAME:
+ retro_core_set_user_name (self, g_value_get_string (value));
+
break;
case PROP_RUNAHEAD:
retro_core_set_runahead (self, g_value_get_uint (value));
@@ -320,6 +329,21 @@ retro_core_class_init (RetroCoreClass *klass)
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
+ /**
+ * RetroCore:user-name:
+ *
+ * The name of the user.
+ */
+ properties[PROP_USER_NAME] =
+ g_param_spec_string ("user-name",
+ "User name",
+ "The user name",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+
/**
* RetroCore:is-initiated:
*
@@ -1184,6 +1208,43 @@ retro_core_set_save_directory (RetroCore *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SAVE_DIRECTORY]);
}
+/**
+ * retro_core_get_user_name:
+ * @self: a #RetroCore
+ *
+ * Gets the name of the user.
+ *
+ * Returns: the name of the user
+ */
+const gchar *
+retro_core_get_user_name (RetroCore *self)
+{
+ g_return_val_if_fail (RETRO_IS_CORE (self), NULL);
+
+ return self->user_name;
+}
+
+/**
+ * retro_core_set_user_name:
+ * @self: a #RetroCore
+ * @user_name: the user name
+ *
+ * Sets the name of the user.
+ */
+void
+retro_core_set_user_name (RetroCore *self,
+ const gchar *user_name)
+{
+ g_return_if_fail (RETRO_IS_CORE (self));
+
+ if (g_strcmp0 (user_name, retro_core_get_user_name (self)) == 0)
+ return;
+
+ g_free (self->user_name);
+ self->user_name = g_strdup (user_name);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER_NAME]);
+}
+
/**
* retro_core_get_is_initiated:
* @self: a #RetroCore
diff --git a/retro-runner/retro-core.h b/retro-runner/retro-core.h
index 23a1a1a..47f3663 100644
--- a/retro-runner/retro-core.h
+++ b/retro-runner/retro-core.h
@@ -28,6 +28,9 @@ void retro_core_set_content_directory (RetroCore *self,
const gchar *retro_core_get_save_directory (RetroCore *self);
void retro_core_set_save_directory (RetroCore *self,
const gchar *save_directory);
+const gchar *retro_core_get_user_name (RetroCore *self);
+void retro_core_set_user_name (RetroCore *self,
+ const gchar *user_name);
gboolean retro_core_get_is_initiated (RetroCore *self);
gboolean retro_core_get_game_loaded (RetroCore *self);
gboolean retro_core_get_support_no_game (RetroCore *self);
diff --git a/retro-runner/retro-environment.c b/retro-runner/retro-environment.c
index 1f1072a..7bddcc3 100644
--- a/retro-runner/retro-environment.c
+++ b/retro-runner/retro-environment.c
@@ -355,6 +355,20 @@ get_system_directory (RetroCore *self,
return TRUE;
}
+static gboolean
+get_username (RetroCore *self,
+ const gchar **username)
+{
+ *(username) = retro_core_get_user_name (self);
+
+ if (**username == '\0')
+ *(username) = NULL;
+
+ retro_debug ("Get username: %s", *username);
+
+ return TRUE;
+}
+
static gboolean
get_variable (RetroCore *self,
RetroVariable *variable)
@@ -652,6 +666,9 @@ environment_core_command (RetroCore *self,
case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY:
return get_system_directory (self, (const gchar **) data);
+ case RETRO_ENVIRONMENT_GET_USERNAME:
+ return get_username (self, (const gchar **) data);
+
case RETRO_ENVIRONMENT_GET_VARIABLE:
return get_variable (self, (RetroVariable *) data);
@@ -700,7 +717,6 @@ environment_core_command (RetroCore *self,
RETRO_UNIMPLEMENT_ENVIRONMENT (RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE);
RETRO_UNIMPLEMENT_ENVIRONMENT (RETRO_ENVIRONMENT_GET_PERF_INTERFACE);
RETRO_UNIMPLEMENT_ENVIRONMENT (RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE);
- RETRO_UNIMPLEMENT_ENVIRONMENT (RETRO_ENVIRONMENT_GET_USERNAME);
RETRO_UNIMPLEMENT_ENVIRONMENT (RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK);
RETRO_UNIMPLEMENT_ENVIRONMENT (RETRO_ENVIRONMENT_SET_CONTROLLER_INFO);
RETRO_UNIMPLEMENT_ENVIRONMENT (RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK);
diff --git a/shared/org.gnome.Retro.Runner.xml b/shared/org.gnome.Retro.Runner.xml
index 9c7f81d..9865303 100644
--- a/shared/org.gnome.Retro.Runner.xml
+++ b/shared/org.gnome.Retro.Runner.xml
@@ -7,6 +7,7 @@
<property name="SystemDirectory" type="s" access="readwrite"/>
<property name="ContentDirectory" type="s" access="readwrite"/>
<property name="SaveDirectory" type="s" access="readwrite"/>
+ <property name="UserName" type="s" access="readwrite"/>
<property name="GameLoaded" type="b" access="read"/>
<property name="FramesPerSecond" type="d" access="read"/>
<property name="SupportNoGame" type="b" access="read"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]