Browse Source

preferences: make icon and css theme selection dropdowns

audio_region_bpm_change_fix
parent
commit
6aacf22df9
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 26
      inc/utils/io.h
  2. 12
      inc/zrythm.h
  3. 80
      src/gui/widgets/preferences.c
  4. 20
      src/gui/widgets/ruler.c
  5. 55
      src/utils/io.c
  6. 30
      src/utils/ui.c
  7. 21
      src/zrythm.c
  8. 48
      src/zrythm_app.c

26
inc/utils/io.h

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2018-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/**
* \file
@ -132,6 +116,12 @@ NONNULL @@ -132,6 +116,12 @@ NONNULL
int
io_rmdir (const char * path, bool force);
char **
io_get_files_in_dir_as_basenames (
const char * dir,
bool allow_empty,
bool with_ext);
/**
* Returns a list of the files in the given
* directory.

12
inc/zrythm.h

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
/* SPDX-License-Identifier: LicenseRef-ZrythmLicense */
/*
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*/
// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/**
* \file
@ -126,6 +124,9 @@ typedef enum ZrythmDirType @@ -126,6 +124,9 @@ typedef enum ZrythmDirType
/** CSS themes. */
ZRYTHM_DIR_SYSTEM_THEMES_CSS_DIR,
/** Icon themes. */
ZRYTHM_DIR_SYSTEM_THEMES_ICONS_DIR,
/**
* Special external Zrythm plugins path (not
* part of the Zrythm source code).
@ -157,6 +158,9 @@ typedef enum ZrythmDirType @@ -157,6 +158,9 @@ typedef enum ZrythmDirType
/** User CSS themes. */
ZRYTHM_DIR_USER_THEMES_CSS,
/** User icon themes. */
ZRYTHM_DIR_USER_THEMES_ICONS,
/** User scripts. */
ZRYTHM_DIR_USER_SCRIPTS,

80
src/gui/widgets/preferences.c

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
#include "settings/settings.h"
#include "utils/flags.h"
#include "utils/gtk.h"
#include "utils/io.h"
#include "utils/localization.h"
#include "utils/objects.h"
#include "utils/resources.h"
@ -91,6 +92,23 @@ on_enum_drop_down_selection_changed ( @@ -91,6 +92,23 @@ on_enum_drop_down_selection_changed (
(int) gtk_drop_down_get_selected (dropdown));
}
static void
on_string_drop_down_selection_changed (
GObject * gobject,
GParamSpec * pspec,
gpointer user_data)
{
CallbackData * data = (CallbackData *) user_data;
GtkDropDown * dropdown = GTK_DROP_DOWN (gobject);
GtkStringObject * str_obj = GTK_STRING_OBJECT (
gtk_drop_down_get_selected_item (dropdown));
g_return_if_fail (str_obj);
const char * str =
gtk_string_object_get_string (str_obj);
g_settings_set_string (
data->info->settings, data->key, str);
}
static void
on_string_combo_box_active_changed (
GtkComboBoxText * combo,
@ -461,6 +479,68 @@ make_control ( @@ -461,6 +479,68 @@ make_control (
G_CALLBACK (font_scale_adjustment_changed),
NULL);
}
else if (
KEY_IS ("UI", "General", "css-theme")
|| KEY_IS ("UI", "General", "icon-theme"))
{
char * user_css_theme_path = zrythm_get_dir (
(KEY_IS ("UI", "General", "css-theme"))
? ZRYTHM_DIR_USER_THEMES_CSS
: ZRYTHM_DIR_USER_THEMES_ICONS);
char ** css_themes =
io_get_files_in_dir_as_basenames (
user_css_theme_path, true, true);
const char * default_themes[] = {
(KEY_IS ("UI", "General", "css-theme"))
? "zrythm-theme.css"
: "zrythm-dark",
NULL
};
GtkStringList * string_list =
gtk_string_list_new (default_themes);
gtk_string_list_splice (
string_list, 1, 0,
(const char **) css_themes);
g_strfreev (css_themes);
widget = gtk_drop_down_new (
G_LIST_MODEL (string_list), NULL);
/* select */
char * selected_str = g_settings_get_string (
info->settings, key);
guint n_items = g_list_model_get_n_items (
G_LIST_MODEL (string_list));
guint selected_idx = 0;
for (guint i = 0; i < n_items; i++)
{
const char * cur_str =
gtk_string_list_get_string (
string_list, i);
if (string_is_equal (
cur_str, selected_str))
{
selected_idx = i;
break;
}
}
g_free (selected_str);
gtk_drop_down_set_selected (
GTK_DROP_DOWN (widget), selected_idx);
CallbackData * data =
object_new (CallbackData);
data->info = info;
data->preferences_widget = self;
data->key = g_strdup (key);
g_signal_connect_data (
G_OBJECT (widget), "notify::selected",
G_CALLBACK (
on_string_drop_down_selection_changed),
data,
(GClosureNotify)
on_closure_notify_delete_data,
G_CONNECT_AFTER);
}
else if (TYPE_EQUALS (BOOLEAN))
{
widget = gtk_switch_new ();

20
src/gui/widgets/ruler.c

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2018-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
#include <math.h>

55
src/utils/io.c

@ -1,24 +1,11 @@ @@ -1,24 +1,11 @@
// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/*
* Copyright (C) 2018-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* ---
*
* Copyright 2000 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
@ -33,6 +20,8 @@ @@ -33,6 +20,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* ---
*/
#include "zrythm-config.h"
@ -56,6 +45,7 @@ @@ -56,6 +45,7 @@
#include "utils/io.h"
#include "utils/objects.h"
#include "utils/string.h"
#include "utils/strv_builder.h"
#include "utils/system.h"
#include "zrythm.h"
@ -467,6 +457,37 @@ io_copy_dir ( @@ -467,6 +457,37 @@ io_copy_dir (
g_dir_close (srcdir);
}
char **
io_get_files_in_dir_as_basenames (
const char * dir,
bool allow_empty,
bool with_ext)
{
if (!with_ext)
{
g_critical ("unimplemented");
return NULL;
}
char ** files =
io_get_files_in_dir (dir, allow_empty);
if (!files)
return NULL;
int i = 0;
StrvBuilder * builder = strv_builder_new ();
char * f;
while ((f = files[i++]))
{
char * new_str = g_path_get_basename (f);
strv_builder_add (builder, new_str);
g_free (new_str);
}
g_strfreev (files);
return strv_builder_end (builder);
}
/**
* Returns a list of the files in the given
* directory.

30
src/utils/ui.c

@ -1,22 +1,6 @@ @@ -1,22 +1,6 @@
/*
* Copyright (C) 2018-2022 Alexandros Theodotou <alex at zrythm dot org>
* Copyright (C) 2020 Ryan Gonzalez <rymg19 at gmail dot com>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-FileCopyrightText: © 2020 Ryan Gonzalez <rymg19 at gmail dot com>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
#include "zrythm-config.h"
@ -1361,7 +1345,13 @@ ui_caches_new () @@ -1361,7 +1345,13 @@ ui_caches_new ()
#define GET_COLOR_FROM_THEME(cname) \
ret = gtk_style_context_lookup_color ( \
context, #cname, &colors->cname); \
g_return_val_if_fail (ret, NULL)
if (!ret) \
{ \
g_warning ( \
"failed to find color " #cname \
" in theme"); \
gdk_rgba_parse (&colors->cname, "grey"); \
}
GET_COLOR_FROM_THEME (bright_green);
GET_COLOR_FROM_THEME (darkish_green);

21
src/zrythm.c

@ -559,9 +559,20 @@ zrythm_get_dir (ZrythmDirType type) @@ -559,9 +559,20 @@ zrythm_get_dir (ZrythmDirType type)
NULL);
break;
case ZRYTHM_DIR_SYSTEM_THEMES_CSS_DIR:
res = g_build_filename (
prefix, "share", "zrythm", "themes",
"css", NULL);
{
char * parent_path = zrythm_get_dir (
ZRYTHM_DIR_SYSTEM_THEMESDIR);
res = g_build_filename (
parent_path, "css", NULL);
}
break;
case ZRYTHM_DIR_SYSTEM_THEMES_ICONS_DIR:
{
char * parent_path = zrythm_get_dir (
ZRYTHM_DIR_SYSTEM_THEMESDIR);
res = g_build_filename (
parent_path, "icons", NULL);
}
break;
case ZRYTHM_DIR_SYSTEM_SPECIAL_LV2_PLUGINS_DIR:
res = g_build_filename (
@ -612,6 +623,10 @@ zrythm_get_dir (ZrythmDirType type) @@ -612,6 +623,10 @@ zrythm_get_dir (ZrythmDirType type)
res = g_build_filename (
user_dir, "themes", "css", NULL);
break;
case ZRYTHM_DIR_USER_THEMES_ICONS:
res = g_build_filename (
user_dir, "themes", "icons", NULL);
break;
case ZRYTHM_DIR_USER_PROFILING:
res = g_build_filename (
user_dir, "profiling", NULL);

48
src/zrythm_app.c

@ -1208,30 +1208,28 @@ zrythm_app_startup (GApplication * app) @@ -1208,30 +1208,28 @@ zrythm_app_startup (GApplication * app)
g_free (freedesktop_icon_theme_dir);
/* prepend zrythm system icons to search path */
char * system_themes_dir =
zrythm_get_dir (ZRYTHM_DIR_SYSTEM_THEMESDIR);
char * system_icon_theme_dir = g_build_filename (
system_themes_dir, "icons", NULL);
gtk_icon_theme_add_search_path (
icon_theme, system_icon_theme_dir);
g_message (
"added icon theme search path: %s",
system_icon_theme_dir);
g_free (system_themes_dir);
g_free (system_icon_theme_dir);
{
char * system_icon_theme_dir = zrythm_get_dir (
ZRYTHM_DIR_SYSTEM_THEMES_ICONS_DIR);
gtk_icon_theme_add_search_path (
icon_theme, system_icon_theme_dir);
g_message (
"added icon theme search path: %s",
system_icon_theme_dir);
g_free (system_icon_theme_dir);
}
/* prepend user custom icons to search path */
char * user_themes_dir =
zrythm_get_dir (ZRYTHM_DIR_USER_THEMES);
char * user_icon_theme_dir = g_build_filename (
user_themes_dir, "icons", NULL);
gtk_icon_theme_add_search_path (
icon_theme, user_icon_theme_dir);
g_message (
"added icon theme search path: %s",
user_icon_theme_dir);
g_free (user_themes_dir);
g_free (user_icon_theme_dir);
{
char * user_icon_theme_dir = zrythm_get_dir (
ZRYTHM_DIR_USER_THEMES_ICONS);
gtk_icon_theme_add_search_path (
icon_theme, user_icon_theme_dir);
g_message (
"added icon theme search path: %s",
user_icon_theme_dir);
g_free (user_icon_theme_dir);
}
/* --- end icon paths --- */
@ -1292,7 +1290,7 @@ zrythm_app_startup (GApplication * app) @@ -1292,7 +1290,7 @@ zrythm_app_startup (GApplication * app)
/* get css theme file path */
GtkCssProvider * css_provider =
gtk_css_provider_new ();
user_themes_dir =
char * user_themes_dir =
zrythm_get_dir (ZRYTHM_DIR_USER_THEMES_CSS);
char * css_theme_file = g_settings_get_string (
S_P_UI_GENERAL, "css-theme");
@ -1304,7 +1302,7 @@ zrythm_app_startup (GApplication * app) @@ -1304,7 +1302,7 @@ zrythm_app_startup (GApplication * app)
{
/* fallback to theme in system path */
g_free (css_theme_path);
system_themes_dir = zrythm_get_dir (
char * system_themes_dir = zrythm_get_dir (
ZRYTHM_DIR_SYSTEM_THEMES_CSS_DIR);
css_theme_path = g_build_filename (
system_themes_dir, css_theme_file, NULL);
@ -1315,7 +1313,7 @@ zrythm_app_startup (GApplication * app) @@ -1315,7 +1313,7 @@ zrythm_app_startup (GApplication * app)
{
/* fallback to zrythm-theme.css */
g_free (css_theme_path);
system_themes_dir = zrythm_get_dir (
char * system_themes_dir = zrythm_get_dir (
ZRYTHM_DIR_SYSTEM_THEMES_CSS_DIR);
css_theme_path = g_build_filename (
system_themes_dir, "zrythm-theme.css",

Loading…
Cancel
Save