[epiphany/pgriffis/web-extension/commands: 3/5] WebExtensions: Fix code style
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/commands: 3/5] WebExtensions: Fix code style
- Date: Thu, 7 Jul 2022 01:13:38 +0000 (UTC)
commit f580900b63b6f3788d37658f1dbe5e85bf0ebab4
Author: Jamie Murphy <hello itsjamie dev>
Date: Tue Jul 5 15:24:49 2022 -0700
WebExtensions: Fix code style
src/webextension/api/commands.c | 97 +++++++++++++++++------------------
src/webextension/ephy-web-extension.c | 79 ++++++++++++++--------------
2 files changed, 87 insertions(+), 89 deletions(-)
---
diff --git a/src/webextension/api/commands.c b/src/webextension/api/commands.c
index a9b329d04..fde025f72 100644
--- a/src/webextension/api/commands.c
+++ b/src/webextension/api/commands.c
@@ -35,7 +35,7 @@ typedef struct {
static void
command_destroy (Command *cmd)
{
- //g_clear_pointer (&cmd->name);
+ /* g_clear_pointer (&cmd->name); */
g_free (cmd);
}
@@ -60,22 +60,22 @@ setup_actions (Command *cmd)
{
GSimpleAction *action = g_simple_action_new (cmd->name, NULL);
g_signal_connect (action, "activate", G_CALLBACK (on_command_activated), cmd);
- g_action_map_add_action (G_ACTION_MAP (ephy_shell_get_default ()), (GAction *) action);
+ g_action_map_add_action (G_ACTION_MAP (ephy_shell_get_default ()), (GAction *)action);
gtk_application_set_accels_for_action (GTK_APPLICATION (ephy_shell_get_default ()),
g_strdup_printf ("app.%s", cmd->name),
(const char *[]) {
- cmd->accelerator,
- NULL,
- });
+ cmd->accelerator,
+ NULL,
+ });
}
static Command *
create_command (EphyWebExtension *self,
- guint cmd)
+ guint cmd)
{
- char * shortcut;
- char * suggested_key;
- char * description;
+ char *shortcut;
+ char *suggested_key;
+ char *description;
Command *command = g_new0 (Command, 1);
ephy_web_extension_get_command_data_from_index (self,
@@ -85,9 +85,9 @@ create_command (EphyWebExtension *self,
&description);
command->web_extension = self;
- command->name = g_strdup(shortcut);
- command->accelerator = g_strdup(suggested_key);
- command->description = g_strdup(description);
+ command->name = g_strdup (shortcut);
+ command->accelerator = g_strdup (suggested_key);
+ command->description = g_strdup (description);
setup_actions (command);
@@ -102,7 +102,7 @@ get_commands (EphyWebExtension *self)
GHashTable *cmds = g_object_get_data (G_OBJECT (self), "commands");
if (cmds)
- return cmds;
+ return cmds;
cmds = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)command_destroy);
g_object_set_data_full (G_OBJECT (self), "commands", cmds, (GDestroyNotify)g_hash_table_destroy);
@@ -136,16 +136,16 @@ command_to_node (Command *cmd)
char *
create_accelerator (char *orig_string)
{
- char ** accelerator_keys = NULL;
- char * accelerator = "";
+ char **accelerator_keys = NULL;
+ char *accelerator = "";
- if (strchr(orig_string, '<') != NULL || strchr (orig_string, '>') != NULL)
+ if (strchr (orig_string, '<') != NULL || strchr (orig_string, '>') != NULL)
return orig_string;
- accelerator_keys = g_strsplit((const gchar *) orig_string, "+", 0);
+ accelerator_keys = g_strsplit ((const gchar *)orig_string, "+", 0);
for (int i = 0; accelerator_keys[i]; i++) {
- // We have to use 2 here, as F# keys are treated like normal keys.
+ /* We have to use 2 here, as F# keys are treated like normal keys. */
if (strlen (accelerator_keys[i]) > 3) {
accelerator = g_strdup_printf ("%s<%s>", accelerator, accelerator_keys[i]);
} else {
@@ -157,11 +157,11 @@ create_accelerator (char *orig_string)
}
static char *
-commands_handler_get_all (EphyWebExtension *self,
- char *name,
- JSCValue *args,
- WebKitWebView *web_view,
- GError **error)
+commands_handler_get_all (EphyWebExtension *self,
+ char *name,
+ JSCValue *args,
+ WebKitWebView *web_view,
+ GError **error)
{
GHashTable *commands = get_commands (self);
g_autoptr (JsonNode) node = json_node_init_array (json_node_alloc (), json_array_new ());
@@ -177,19 +177,19 @@ commands_handler_get_all (EphyWebExtension *self,
}
static char *
-commands_handler_reset (EphyWebExtension *self,
- char *name,
- JSCValue *args,
- WebKitWebView *web_view,
- GError **error)
+commands_handler_reset (EphyWebExtension *self,
+ char *name,
+ JSCValue *args,
+ WebKitWebView *web_view,
+ GError **error)
{
GHashTable *commands = get_commands (self);
g_autoptr (JSCValue) name_value = jsc_value_object_get_property_at_index (args, 0);
g_autofree char *name_str = NULL;
Command *cmd = NULL;
- char * shortcut;
- char * suggested_key;
- char * description;
+ char *shortcut;
+ char *suggested_key;
+ char *description;
if (!jsc_value_is_string (name_value))
name_str = g_strdup ("");
@@ -204,20 +204,20 @@ commands_handler_reset (EphyWebExtension *self,
&suggested_key,
&description);
- cmd->name = g_strdup(shortcut);
- cmd->accelerator = g_strdup(suggested_key);
- cmd->description = g_strdup(description);
+ cmd->name = g_strdup (shortcut);
+ cmd->accelerator = g_strdup (suggested_key);
+ cmd->description = g_strdup (description);
}
return NULL;
}
static char *
-commands_handler_update (EphyWebExtension *self,
- char *name,
- JSCValue *args,
- WebKitWebView *web_view,
- GError **error)
+commands_handler_update (EphyWebExtension *self,
+ char *name,
+ JSCValue *args,
+ WebKitWebView *web_view,
+ GError **error)
{
GHashTable *commands = get_commands (self);
g_autoptr (JSCValue) obj = jsc_value_object_get_property_at_index (args, 0);
@@ -245,18 +245,17 @@ commands_handler_update (EphyWebExtension *self,
if (g_hash_table_lookup (commands, name_str)) {
cmd = g_hash_table_lookup (commands, name_str);
- cmd->name = g_strdup(name_str);
- cmd->accelerator = g_strdup(shortcut_str);
- cmd->description = g_strdup(desc_str);
+ cmd->name = g_strdup (name_str);
+ cmd->accelerator = g_strdup (shortcut_str);
+ cmd->description = g_strdup (desc_str);
+ gtk_application_set_accels_for_action (GTK_APPLICATION (ephy_shell_get_default ()),
+ g_strdup_printf ("app.%s", cmd->name),
+ (const char *[]) {
+ cmd->accelerator,
+ NULL,
+ });
}
- gtk_application_set_accels_for_action (GTK_APPLICATION (ephy_shell_get_default ()),
- g_strdup_printf ("app.%s", cmd->name),
- (const char *[]) {
- cmd->accelerator,
- NULL,
- });
-
return NULL;
}
diff --git a/src/webextension/ephy-web-extension.c b/src/webextension/ephy-web-extension.c
index 66210a8b6..58285be54 100644
--- a/src/webextension/ephy-web-extension.c
+++ b/src/webextension/ephy-web-extension.c
@@ -762,30 +762,29 @@ web_extension_add_web_accessible_resource (JsonArray *array,
char *
ephy_web_extension_get_command_accelerator (JsonObject *suggested_key_object)
{
- const char * orig_string = NULL;
- char ** accelerator_keys = NULL;
- char * accelerator = "";
+ const char *orig_string = NULL;
+ char **accelerator_keys = NULL;
+ char *accelerator = "";
if (!ephy_json_object_get_string (suggested_key_object, "default") &&
- !ephy_json_object_get_string (suggested_key_object, "linux"))
- {
- return NULL;
- } else if (ephy_json_object_get_string (suggested_key_object, "default")) {
- orig_string = ephy_json_object_get_string (suggested_key_object, "default");
- } else if (ephy_json_object_get_string (suggested_key_object, "linux")) {
- orig_string = ephy_json_object_get_string (suggested_key_object, "linux");
- }
+ !ephy_json_object_get_string (suggested_key_object, "linux")) {
+ return NULL;
+ } else if (ephy_json_object_get_string (suggested_key_object, "default")) {
+ orig_string = ephy_json_object_get_string (suggested_key_object, "default");
+ } else if (ephy_json_object_get_string (suggested_key_object, "linux")) {
+ orig_string = ephy_json_object_get_string (suggested_key_object, "linux");
+ }
- accelerator_keys = g_strsplit((const gchar *) orig_string, "+", 0);
+ accelerator_keys = g_strsplit ((const gchar *)orig_string, "+", 0);
- for (int i = 0; accelerator_keys[i]; i++) {
- // We have to use 2 here, as F# keys are treated like normal keys.
- if (strlen (accelerator_keys[i]) > 2) {
- accelerator = g_strdup_printf ("%s<%s>", accelerator, accelerator_keys[i]);
- } else {
- accelerator = g_strdup_printf ("%s%s", accelerator, accelerator_keys[i]);
- }
+ for (int i = 0; accelerator_keys[i]; i++) {
+ /* We have to use 2 here, as F# keys are treated like normal keys. */
+ if (strlen (accelerator_keys[i]) > 2) {
+ accelerator = g_strdup_printf ("%s<%s>", accelerator, accelerator_keys[i]);
+ } else {
+ accelerator = g_strdup_printf ("%s%s", accelerator, accelerator_keys[i]);
}
+ }
return accelerator;
}
@@ -803,7 +802,7 @@ web_extension_parse_commands (EphyWebExtension *self,
const char *suggested_key;
for (GList *list = json_object_get_members (object); list && list->data; list = list->next) {
- node = json_object_get_member (object, (gchar *) list->data);
+ node = json_object_get_member (object, (gchar *)list->data);
cmd_object = ephy_json_node_get_object (node);
key_object = ephy_json_object_get_object (cmd_object, "suggested_key");
@@ -814,46 +813,46 @@ web_extension_parse_commands (EphyWebExtension *self,
description = ephy_json_object_get_string (cmd_object, "description");
- shortcut = (gchar *) list->data;
+ shortcut = (gchar *)list->data;
if (!shortcut) {
LOG ("Skipping command as value is invalid");
return;
}
- cmd->description = g_strdup(description);
- cmd->shortcut = g_strdup(shortcut);
+ cmd->description = g_strdup (description);
+ cmd->shortcut = g_strdup (shortcut);
suggested_key = ephy_web_extension_get_command_accelerator (key_object);
if (!g_strcmp0 (suggested_key, "") == 0)
- cmd->suggested_key = g_strdup(suggested_key);
+ cmd->suggested_key = g_strdup (suggested_key);
self->commands = g_list_append (self->commands, cmd);
}
}
void *
-ephy_web_extension_get_command_data_from_index (EphyWebExtension *self,
- guint command,
- char** shortcut,
- char** suggested_key,
- char** description)
+ephy_web_extension_get_command_data_from_index (EphyWebExtension *self,
+ guint command,
+ char **shortcut,
+ char **suggested_key,
+ char **description)
{
WebExtensionCommand *cmd = g_list_nth_data (self->commands, command);
- *shortcut = strdup(cmd->shortcut);
- *suggested_key = strdup(cmd->suggested_key);
- *description = strdup(cmd->description);
+ *shortcut = strdup (cmd->shortcut);
+ *suggested_key = strdup (cmd->suggested_key);
+ *description = strdup (cmd->description);
return NULL;
}
void *
-ephy_web_extension_get_command_data_from_name (EphyWebExtension *self,
- const char *name,
- char** shortcut,
- char** suggested_key,
- char** description)
+ephy_web_extension_get_command_data_from_name (EphyWebExtension *self,
+ guint command,
+ char **shortcut,
+ char **suggested_key,
+ char **description)
{
WebExtensionCommand *cmd = NULL;
@@ -861,9 +860,9 @@ ephy_web_extension_get_command_data_from_name (EphyWebExtension *self,
cmd = list->data;
if (strcmp (cmd->shortcut, name) == 0) {
- *shortcut = strdup(cmd->shortcut);
- *suggested_key = strdup(cmd->suggested_key);
- *description = strdup(cmd->description);
+ *shortcut = strdup (cmd->shortcut);
+ *suggested_key = strdup (cmd->suggested_key);
+ *description = strdup (cmd->description);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]