Skip to content

Commit

Permalink
Clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed Aug 26, 2024
1 parent 4c6a7c7 commit d9f389d
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 256 deletions.
8 changes: 5 additions & 3 deletions src/anki.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ static s8 add_bold_tags_around_word(s8 sent, s8 word) {

static s8 create_furigana(s8 kanji, s8 reading) {
return !kanji.len && !reading.len ? s8dup(S(""))
: !kanji.len ? s8dup(reading)
: !reading.len ? s8dup(kanji)
: concat(kanji, S("["), reading, S("]"));
// cppcheck-suppress knownConditionTrueFalse
: !kanji.len ? s8dup(reading)
// cppcheck-suppress knownConditionTrueFalse
: !reading.len ? s8dup(kanji)
: concat(kanji, S("["), reading, S("]"));
}

// TODO: Improve maintainability?
Expand Down
33 changes: 16 additions & 17 deletions src/frontends/cli.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include "dictpopup.h"
#include "util.h"
#include "dictionary_lookup.h"

int main(int argc, char **argv) {
if (argc < 2) {
puts("Need to provide a lookup string.");
return EXIT_FAILURE;
}
dictpopup_init();
s8 lookup = fromcstr_(argv[1]);
dictentry *dict = create_dictionary(&lookup);

for (isize i = 0; i < dictlen(dict); i++) {
if (i)
putchar('\n');
dictentry_print(dict[i]);
}

dict_free(&dict);
// TODO
// if (argc < 2) {
// puts("Need to provide a lookup string.");
// return EXIT_FAILURE;
// }
// s8 lookup = fromcstr_(argv[1]);
// Dictentry *dict = dictionary_lookup(&lookup);
//
// for (isize i = 0; i < dictlen(dict); i++) {
// if (i)
// putchar('\n');
// dictentry_print(dict[i]);
// }
//
// dict_free(&dict);
}
5 changes: 2 additions & 3 deletions src/frontends/gtk3popup/dictpopup-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ static void set_no_lookup_string(DpApplication *app) {
}

static void set_database_not_found(DpApplication *app) {
s8 no_database_text =
S("No database found. "
"You must first create one in the preferences window.");
s8 no_database_text = S("No database found. "
"You must first create one in the preferences window.");
ui_manager_set_error(&app->ui_manager, no_database_text);
}

Expand Down
4 changes: 2 additions & 2 deletions src/frontends/gtk3popup/dictpopup-config_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ int main(int argc, char *argv[]) {
GtkApplication *app;
int status;

app = gtk_application_new("com.github.Ajatt-Tools.dictpopup-settings",
G_APPLICATION_FLAGS_NONE);
app =
gtk_application_new("com.github.Ajatt-Tools.dictpopup-settings", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
Expand Down
23 changes: 12 additions & 11 deletions src/frontends/gtk3popup/dp-preferences-window.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "dp-preferences-window.h"
#include <glib/gi18n.h>
#include <stdatomic.h>

#include "ankiconnectc.h"
#include "db.h"
#include "dictpopup_create.h"
#include "stdatomic.h"
#include <ankiconnectc.h>
#include <db.h>
#include <glib/gi18n.h>
#include <jppron/jppron.h>
#include "jppron/jppron.h"

#include "dp-preferences-window.h"

static const char* generate_index_str = N_("Generate Index");
static const char* stop_str = N_("Stop");
static const char *generate_index_str = N_("Generate Index");
static const char *stop_str = N_("Stop");

struct _DpPreferencesWindow {
GtkWindow parent_instance;
Expand Down Expand Up @@ -62,8 +63,8 @@ static void restore_generate_index_button(GtkWidget *button) {
gtk_button_set_label(GTK_BUTTON(button), _(generate_index_str));

GtkStyleContext *context = gtk_widget_get_style_context(button);
gtk_style_context_add_class(gtk_widget_get_style_context(button), "suggested-action");
gtk_style_context_remove_class(gtk_widget_get_style_context(button), "destructive-action");
gtk_style_context_add_class(context, "suggested-action");
gtk_style_context_remove_class(context, "destructive-action");
}

static void change_to_stop_button(GtkWidget *button) {
Expand Down Expand Up @@ -542,7 +543,7 @@ void dp_preferences_window_update_dict_order(DpPreferencesWindow *self) {

_drop_(s8_buf_free) s8Buf dict_names = db_get_dictnames(db);
db_close(db);
if (s8_buf_size(dict_names) <= 0) {
if (s8_buf_size(dict_names) == 0) {
list_box_insert_msg(GTK_LIST_BOX(self->dict_order_listbox),
_("No dictionaries found in database"));
return;
Expand Down
17 changes: 8 additions & 9 deletions src/frontends/gtk3popup/main.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#include "dictpopup-application.h"
#include <glib/gi18n.h>
#include <locale.h>
#include "dictpopup-application.h"

int main(int argc, char *argv[]) {
safe_focused_window_title();

setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);

g_autoptr(GtkApplication) app = g_object_new(
DP_TYPE_APPLICATION, "application_id", "com.github.Ajatt-Tools.dictpopup", "flags",
G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_NON_UNIQUE,
NULL);
g_autoptr(GtkApplication) app =
g_object_new(DP_TYPE_APPLICATION, "application_id", "com.github.Ajatt-Tools.dictpopup",
"flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_NON_UNIQUE, NULL);

return g_application_run(G_APPLICATION(app), argc, argv);
}
12 changes: 7 additions & 5 deletions src/frontends/gtk3popup/ui_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void refresh_current_word_with_entry(UiManager *self, Word word) {
_drop_(frees8) s8 txt = {0};
if (word.kanji.len && word.reading.len) {
if (s8equals(word.kanji, word.reading))
txt = s8dup(word.reading.len ? word.reading : word.kanji);
txt = s8dup(word.reading.len > 0 ? word.reading : word.kanji);
else
txt = concat(word.reading, S("【"), word.kanji, S("】"));
} else if (word.reading.len)
Expand Down Expand Up @@ -197,7 +197,7 @@ static void ui_queue_delayed_updates(UiManager *self, PageManager *pm) {
gdk_threads_add_idle((GSourceFunc)process_delayed_updates, args);
}

static gboolean _ui_refresh_impl(gpointer data) {
static gboolean _ui_refresh_quick(gpointer data) {
struct ui_refresh_args_s *args = (struct ui_refresh_args_s *)data;
UiManager *self = args->self;
PageManager *pm = args->pm;
Expand All @@ -214,6 +214,7 @@ static gboolean _ui_refresh_impl(gpointer data) {
refresh_left_right_buttons(self, num_pages);
refresh_title_with_entry(self, de);

free(args);
return G_SOURCE_REMOVE;
}

Expand All @@ -222,7 +223,7 @@ static void ui_queue_quick_updates(UiManager *self, PageManager *pm) {
args->self = self;
args->pm = pm;

gdk_threads_add_idle_full(G_PRIORITY_HIGH, (GSourceFunc)_ui_refresh_impl, args, NULL);
gdk_threads_add_idle_full(G_PRIORITY_HIGH, (GSourceFunc)_ui_refresh_quick, args, NULL);
}

void _nonnull_ ui_refresh(UiManager *self, PageManager *pm) {
Expand Down Expand Up @@ -318,7 +319,7 @@ void ui_manager_show_edit_lookup_dialog(UiManager *self, const char *current_loo
data->user_data = user_data;

g_signal_connect(dialog, "response", G_CALLBACK(on_edit_lookup_dialog_response), data);
// g_signal_connect(entry, "activate", G_CALLBACK(on_entry_activate), dialog);
g_signal_connect(entry, "activate", G_CALLBACK(on_entry_activate), dialog);

gtk_widget_show_all(dialog);
}
Expand All @@ -329,7 +330,8 @@ void ui_manager_show_anki_button_right_click_menu(
gpointer user_data) {
GtkWidget *menu = gtk_menu_new();

GtkWidget *menu_item = gtk_menu_item_new_with_label(_("Add with clipboard content as definition"));
GtkWidget *menu_item =
gtk_menu_item_new_with_label(_("Add with clipboard content as definition"));
g_signal_connect(menu_item, "activate", G_CALLBACK(on_clipboard_definition), user_data);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);

Expand Down
Loading

0 comments on commit d9f389d

Please sign in to comment.