summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfonso Sánchez-Beato <alfonso.sanchez-beato@canonical.com>2021-09-23 09:24:19 +0200
committerRay Strode <halfline@gmail.com>2021-09-27 10:03:53 +0000
commita3607d7ad478f01e392a0dd3f865066010b630c9 (patch)
tree0e8f4b307270370f05654401c359e44c5a4f048f
parenta4a1afc83f94acf48fffb706e3dc326f45209721 (diff)
main: refactor code for searching the theme path
Refactor code that searched for the theme configuration so it can be reused.
-rw-r--r--src/main.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/main.c b/src/main.c
index eafd94be..06a62c36 100644
--- a/src/main.c
+++ b/src/main.c
@@ -262,6 +262,30 @@ show_messages (state_t *state)
}
static bool
+get_theme_path (const char *splash_string,
+ char **theme_path)
+{
+ const char *paths[] = { PLYMOUTH_RUNTIME_THEME_PATH,
+ PLYMOUTH_THEME_PATH };
+ size_t i;
+
+ for (i = 0; i < PLY_NUMBER_OF_ELEMENTS (paths); ++i) {
+ asprintf (theme_path,
+ "%s/%s/%s.plymouth",
+ paths[i], splash_string, splash_string);
+ if (ply_file_exists (*theme_path)) {
+ ply_trace ("Theme is %s", *theme_path);
+ return true;
+ }
+ ply_trace ("Theme %s not found", *theme_path);
+ free (*theme_path);
+ *theme_path = NULL;
+ }
+
+ return false;
+}
+
+static bool
load_settings (state_t *state,
const char *path,
char **theme_path)
@@ -279,19 +303,8 @@ load_settings (state_t *state,
splash_string = ply_key_file_get_value (key_file, "Daemon", "Theme");
- if (splash_string != NULL) {
- asprintf (theme_path,
- PLYMOUTH_RUNTIME_THEME_PATH "%s/%s.plymouth",
- splash_string, splash_string);
- ply_trace ("Checking if %s exists", *theme_path);
- if (!ply_file_exists (*theme_path)) {
- ply_trace ("%s not found, fallbacking to " PLYMOUTH_THEME_PATH,
- *theme_path);
- asprintf (theme_path,
- PLYMOUTH_THEME_PATH "%s/%s.plymouth",
- splash_string, splash_string);
- }
- }
+ if (splash_string != NULL)
+ get_theme_path (splash_string, theme_path);
if (isnan (state->splash_delay)) {
state->splash_delay = ply_key_file_get_double(key_file, "Daemon", "ShowDelay", NAN);
@@ -354,19 +367,9 @@ find_override_splash (state_t *state)
if (splash_string != NULL) {
ply_trace ("Splash is configured to be '%s'", splash_string);
- asprintf (&state->override_splash_path,
- PLYMOUTH_RUNTIME_THEME_PATH "%s/%s.plymouth",
- splash_string, splash_string);
-
- ply_trace ("Checking if %s exists", state->override_splash_path);
- if (!ply_file_exists (state->override_splash_path)) {
- ply_trace ("%s not found, fallbacking to " PLYMOUTH_THEME_PATH,
- state->override_splash_path);
- free (state->override_splash_path);
- asprintf (&state->override_splash_path,
- PLYMOUTH_THEME_PATH "%s/%s.plymouth",
- splash_string, splash_string);
- }
+
+ get_theme_path (splash_string, &state->override_splash_path);
+
free (splash_string);
}
@@ -402,7 +405,8 @@ find_system_default_splash (state_t *state)
return;
}
- ply_trace ("System configured theme file is '%s'", state->system_default_splash_path);
+ if (state->system_default_splash_path != NULL)
+ ply_trace ("System configured theme file is '%s'", state->system_default_splash_path);
}
static void
@@ -419,7 +423,8 @@ find_distribution_default_splash (state_t *state)
}
}
- ply_trace ("Distribution default theme file is '%s'", state->distribution_default_splash_path);
+ if (state->distribution_default_splash_path != NULL)
+ ply_trace ("Distribution default theme file is '%s'", state->distribution_default_splash_path);
}
static void