Skip to content

Commit

Permalink
feat: Add debug-info
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jun 16, 2024
1 parent 0d029f8 commit acb2d14
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ set(LICENSE "GPLv2+")
set(PRJ_GROUP "System Environment/Libraries")
set(RRJ_URL "https://github.com/chewing/${PROJECT_NAME}")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

enable_testing()
include(GNUInstallDirs)

Expand Down Expand Up @@ -75,6 +77,8 @@ add_compile_definitions(
PRJ_DATA_DIR=${PRJ_DATA_DIR}
PRJ_VER=${PRJ_VER}
PRJ_URL=${PRJ_URL}
IBUS_VERSION=${IBUS_VERSION}
CHEWING_VERSION=${CHEWING_VERSION}
LIBEXEC_DIR=${LIBEXEC_DIR}
CHEWING_DATADIR_REAL=${CHEWING_DATADIR_REAL}
)
Expand Down
100 changes: 99 additions & 1 deletion src/setup/ibus-setup-chewing-about.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,103 @@
#define QUOTE_ME_INNER(s) #s
#define QUOTE_ME(s) QUOTE_ME_INNER(s)

static char *generate_debug_info(void) {
GString *string = g_string_new(NULL);

g_string_append_printf(string, "ibus-chewing: %s\n\n", QUOTE_ME(PRJ_VER));
g_string_append(string, "Compiled against:\n");
g_string_append_printf(string, "- ibus: %s\n", QUOTE_ME(IBUS_VERSION));
g_string_append_printf(string, "- libchewing: %s\n",
QUOTE_ME(CHEWING_VERSION));

g_string_append(string, "\nRunning against:\n");
g_string_append_printf(string, "- libchewing: n/a\n");

g_string_append(string, "\n");
{
g_autoptr(GSettings) settings =
g_settings_new("org.freedesktop.IBus.Chewing");
gchar *kb_type = g_settings_get_string(settings, "kb-type");
gchar *sel_keys = g_settings_get_string(settings, "sel-keys");
gchar *chi_eng_mode_toggle =
g_settings_get_string(settings, "chi-eng-mode-toggle");
gchar *sync_caps_lock =
g_settings_get_string(settings, "sync-caps-lock");
gchar *default_english_case =
g_settings_get_string(settings, "default-english-case");

g_string_append(string, "Settings:\n");
g_string_append_printf(string, "- kb-type: %s\n", kb_type);
g_string_append_printf(string, "- sel-keys: %s\n", sel_keys);
g_string_append_printf(
string, "- plain-zhuyin: %d\n",
g_settings_get_boolean(settings, "plain-zhuyin"));
g_string_append_printf(
string, "- auto-shift-cur: %d\n",
g_settings_get_boolean(settings, "auto-shift-cur"));
g_string_append_printf(
string, "- add-phrase-direction: %d\n",
g_settings_get_boolean(settings, "add-phrase-direction"));
g_string_append_printf(
string, "- clean-buffer-focus-out: %d\n",
g_settings_get_boolean(settings, "clean-buffer-focus-out"));
g_string_append_printf(
string, "- easy-symbol-input: %d\n",
g_settings_get_boolean(settings, "easy-symbol-input"));
g_string_append_printf(
string, "- esc-clean-all-buf: %d\n",
g_settings_get_boolean(settings, "esc-clean-all-buf"));
g_string_append_printf(
string, "- max-chi-symbol-len: %d\n",
g_settings_get_int(settings, "max-chi-symbol-len"));
g_string_append_printf(string, "- chi-eng-mode-toggle: %s\n",
chi_eng_mode_toggle);
g_string_append_printf(string, "- sync-caps-lock: %s\n",
sync_caps_lock);
g_string_append_printf(string, "- default-english-case: %s\n",
default_english_case);
g_string_append_printf(string, "- cand-per-page: %d\n",
g_settings_get_uint(settings, "cand-per-page"));
g_string_append_printf(
string, "- show-page-number: %d\n",
g_settings_get_boolean(settings, "show-page-number"));
g_string_append_printf(
string, "- phrase-choice-from-last: %d\n",
g_settings_get_boolean(settings, "phrase-choice-from-last"));
g_string_append_printf(
string, "- space-as-selection: %d\n",
g_settings_get_boolean(settings, "space-as-selection"));
g_string_append_printf(
string, "- vertical-lookup-table: %d\n",
g_settings_get_boolean(settings, "vertical-lookup-table"));

g_free(kb_type);
g_free(sel_keys);
g_free(chi_eng_mode_toggle);
g_free(sync_caps_lock);
g_free(default_english_case);
}

g_string_append(string, "\n");
{
const char *desktop = g_getenv("XDG_CURRENT_DESKTOP");
const char *session_desktop = g_getenv("XDG_SESSION_DESKTOP");
const char *session_type = g_getenv("XDG_SESSION_TYPE");
const char *lang = g_getenv("LANG");

g_string_append(string, "Environment:\n");
g_string_append_printf(string, "- Desktop: %s\n", desktop);
g_string_append_printf(string, "- Session: %s (%s)\n", session_desktop,
session_type);
g_string_append_printf(string, "- Language: %s\n", lang);
}

return g_string_free_and_steal(string);
}

void show_about(GtkWidget *self) {
char *debug_info = generate_debug_info();

// clang-format off
const char *developers[] = {
"Peng Huang",
Expand All @@ -46,12 +142,14 @@ void show_about(GtkWidget *self) {
"website", "https://chewing.im",
"issue-url", "https://github.com/chewing/ibus-chewing",
"support-url", "https://github.com/chewing/ibus-chewing/discussions",
//"debug-info", TODO return settings,
"debug-info", debug_info,
"copyright", "© 2024 libchewing Core Team",
"license-type", GTK_LICENSE_GPL_2_0,
"developers", developers,
"translator-credits", _("translator-credits"),
NULL
);
// clang-format on

g_free(debug_info);
}
6 changes: 5 additions & 1 deletion src/setup/ibus-setup-chewing-about.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@

#include <adwaita.h>

void show_about(GtkWidget *self);
G_BEGIN_DECLS

void show_about(GtkWidget *self);

G_END_DECLS

0 comments on commit acb2d14

Please sign in to comment.