xed-utils: Clean up code styling
This commit is contained in:
parent
55317e21b0
commit
4ef02d4837
171
xed/xed-utils.c
171
xed/xed-utils.c
|
@ -98,9 +98,7 @@ xed_utils_uri_has_writable_scheme (const gchar *uri)
|
|||
writable_schemes = xed_prefs_manager_get_writable_vfs_schemes ();
|
||||
|
||||
/* CHECK: should we use g_ascii_strcasecmp? - Paolo (Nov 6, 2005) */
|
||||
res = (g_slist_find_custom (writable_schemes,
|
||||
scheme,
|
||||
(GCompareFunc)strcmp) != NULL);
|
||||
res = (g_slist_find_custom (writable_schemes, scheme, (GCompareFunc)strcmp) != NULL);
|
||||
|
||||
g_slist_foreach (writable_schemes, (GFunc)g_free, NULL);
|
||||
g_slist_free (writable_schemes);
|
||||
|
@ -111,7 +109,9 @@ xed_utils_uri_has_writable_scheme (const gchar *uri)
|
|||
}
|
||||
|
||||
static void
|
||||
widget_get_origin (GtkWidget *widget, gint *x, gint *y)
|
||||
widget_get_origin (GtkWidget *widget,
|
||||
gint *x,
|
||||
gint *y)
|
||||
|
||||
{
|
||||
GdkWindow *window;
|
||||
|
@ -197,9 +197,7 @@ xed_utils_menu_position_under_tree_view (GtkMenu *menu,
|
|||
else
|
||||
{
|
||||
/* no selection -> regular "under widget" positioning */
|
||||
xed_utils_menu_position_under_widget (menu,
|
||||
x, y, push_in,
|
||||
tree);
|
||||
xed_utils_menu_position_under_widget (menu, x, y, push_in, tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,10 +205,7 @@ xed_utils_menu_position_under_tree_view (GtkMenu *menu,
|
|||
gchar *
|
||||
xed_gdk_color_to_string (GdkColor color)
|
||||
{
|
||||
return g_strdup_printf ("#%04x%04x%04x",
|
||||
color.red,
|
||||
color.green,
|
||||
color.blue);
|
||||
return g_strdup_printf ("#%04x%04x%04x", color.red, color.green, color.blue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,9 +222,7 @@ xed_gtk_button_new_with_stock_icon (const gchar *label,
|
|||
GtkWidget *button;
|
||||
|
||||
button = gtk_button_new_with_mnemonic (label);
|
||||
gtk_button_set_image (GTK_BUTTON (button),
|
||||
gtk_image_new_from_stock (stock_id,
|
||||
GTK_ICON_SIZE_BUTTON));
|
||||
gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
@ -271,7 +264,10 @@ xed_dialog_add_button (GtkDialog *dialog,
|
|||
* n: len of the string in bytes
|
||||
*/
|
||||
gboolean
|
||||
g_utf8_caselessnmatch (const char *s1, const char *s2, gssize n1, gssize n2)
|
||||
g_utf8_caselessnmatch (const char *s1,
|
||||
const char *s2,
|
||||
gssize n1,
|
||||
gssize n2)
|
||||
{
|
||||
gchar *casefold;
|
||||
gchar *normalized_s1;
|
||||
|
@ -297,7 +293,9 @@ g_utf8_caselessnmatch (const char *s1, const char *s2, gssize n1, gssize n2)
|
|||
len_s2 = strlen (normalized_s2);
|
||||
|
||||
if (len_s1 < len_s2)
|
||||
{
|
||||
goto finally_2;
|
||||
}
|
||||
|
||||
ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0);
|
||||
|
||||
|
@ -327,14 +325,20 @@ xed_utils_set_atk_name_description (GtkWidget *widget,
|
|||
aobj = gtk_widget_get_accessible (widget);
|
||||
|
||||
if (!(GTK_IS_ACCESSIBLE (aobj)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (name)
|
||||
{
|
||||
atk_object_set_name (aobj, name);
|
||||
}
|
||||
|
||||
if (description)
|
||||
{
|
||||
atk_object_set_description (aobj, description);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xed_set_atk_relation:
|
||||
|
@ -359,7 +363,9 @@ xed_utils_set_atk_relation (GtkWidget *obj1,
|
|||
atk_obj2 = gtk_widget_get_accessible (obj2);
|
||||
|
||||
if (!(GTK_IS_ACCESSIBLE (atk_obj1)) || !(GTK_IS_ACCESSIBLE (atk_obj2)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
relation_set = atk_object_ref_relation_set (atk_obj1);
|
||||
targets[0] = atk_obj2;
|
||||
|
@ -399,7 +405,9 @@ xed_utils_escape_search_text (const gchar* text)
|
|||
const gchar *end;
|
||||
|
||||
if (text == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xed_debug_message (DEBUG_SEARCH, "Text: %s", text);
|
||||
|
||||
|
@ -409,7 +417,9 @@ xed_utils_escape_search_text (const gchar* text)
|
|||
* The short circuit works only for ascii, but we only
|
||||
* care about not escaping a single '\' */
|
||||
if (length == 1)
|
||||
{
|
||||
return g_strdup (text);
|
||||
}
|
||||
|
||||
str = g_string_new ("");
|
||||
|
||||
|
@ -457,7 +467,9 @@ xed_utils_unescape_search_text (const gchar *text)
|
|||
const gchar *prev;
|
||||
|
||||
if (text == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
length = strlen (text);
|
||||
|
||||
|
@ -521,7 +533,9 @@ xed_utils_unescape_search_text (const gchar *text)
|
|||
}
|
||||
|
||||
void
|
||||
xed_warning (GtkWindow *parent, const gchar *format, ...)
|
||||
xed_warning (GtkWindow *parent,
|
||||
const gchar *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
gchar *str;
|
||||
|
@ -531,14 +545,15 @@ xed_warning (GtkWindow *parent, const gchar *format, ...)
|
|||
g_return_if_fail (format != NULL);
|
||||
|
||||
if (parent != NULL)
|
||||
{
|
||||
wg = gtk_window_get_group (parent);
|
||||
}
|
||||
|
||||
va_start (args, format);
|
||||
str = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
dialog = gtk_message_dialog_new_with_markup (
|
||||
parent,
|
||||
dialog = gtk_message_dialog_new_with_markup (parent,
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_OK,
|
||||
|
@ -547,16 +562,16 @@ xed_warning (GtkWindow *parent, const gchar *format, ...)
|
|||
g_free (str);
|
||||
|
||||
if (wg != NULL)
|
||||
{
|
||||
gtk_window_group_add_window (wg, GTK_WINDOW (dialog));
|
||||
}
|
||||
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
||||
|
||||
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
||||
|
||||
g_signal_connect (G_OBJECT (dialog),
|
||||
"response",
|
||||
G_CALLBACK (gtk_widget_destroy),
|
||||
NULL);
|
||||
g_signal_connect (G_OBJECT (dialog), "response",
|
||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
|
@ -575,7 +590,9 @@ xed_utils_escape_underscores (const gchar* text,
|
|||
g_return_val_if_fail (text != NULL, NULL);
|
||||
|
||||
if (length < 0)
|
||||
{
|
||||
length = strlen (text);
|
||||
}
|
||||
|
||||
str = g_string_sized_new (length);
|
||||
|
||||
|
@ -629,14 +646,16 @@ xed_utils_str_truncate (const gchar *string,
|
|||
* side)
|
||||
*/
|
||||
delimiter_length = g_utf8_strlen (delimiter, -1);
|
||||
if (truncate_length < (delimiter_length + 2)) {
|
||||
if (truncate_length < (delimiter_length + 2))
|
||||
{
|
||||
return g_strdup (string);
|
||||
}
|
||||
|
||||
n_chars = g_utf8_strlen (string, length);
|
||||
|
||||
/* Make sure the string is not already small enough. */
|
||||
if (n_chars <= truncate_length) {
|
||||
if (n_chars <= truncate_length)
|
||||
{
|
||||
return g_strdup (string);
|
||||
}
|
||||
|
||||
|
@ -646,16 +665,14 @@ xed_utils_str_truncate (const gchar *string,
|
|||
num_left_chars = (truncate_length - delimiter_length) / 2;
|
||||
right_offset = n_chars - truncate_length + num_left_chars + delimiter_length;
|
||||
|
||||
truncated = g_string_new_len (string,
|
||||
g_utf8_offset_to_pointer (string, num_left_chars) - string);
|
||||
truncated = g_string_new_len (string, g_utf8_offset_to_pointer (string, num_left_chars) - string);
|
||||
g_string_append (truncated, delimiter);
|
||||
g_string_append (truncated, g_utf8_offset_to_pointer (string, right_offset));
|
||||
}
|
||||
else
|
||||
{
|
||||
num_left_chars = truncate_length - delimiter_length;
|
||||
truncated = g_string_new_len (string,
|
||||
g_utf8_offset_to_pointer (string, num_left_chars) - string);
|
||||
truncated = g_string_new_len (string, g_utf8_offset_to_pointer (string, num_left_chars) - string);
|
||||
g_string_append (truncated, delimiter);
|
||||
}
|
||||
|
||||
|
@ -689,13 +706,16 @@ xed_utils_make_valid_utf8 (const char *name)
|
|||
remainder = name;
|
||||
remaining_bytes = strlen (name);
|
||||
|
||||
while (remaining_bytes != 0) {
|
||||
if (g_utf8_validate (remainder, remaining_bytes, &invalid)) {
|
||||
while (remaining_bytes != 0)
|
||||
{
|
||||
if (g_utf8_validate (remainder, remaining_bytes, &invalid))
|
||||
{
|
||||
break;
|
||||
}
|
||||
valid_bytes = invalid - remainder;
|
||||
|
||||
if (string == NULL) {
|
||||
if (string == NULL)
|
||||
{
|
||||
string = g_string_sized_new (remaining_bytes);
|
||||
}
|
||||
g_string_append_len (string, remainder, valid_bytes);
|
||||
|
@ -706,7 +726,8 @@ xed_utils_make_valid_utf8 (const char *name)
|
|||
remainder = invalid + 1;
|
||||
}
|
||||
|
||||
if (string == NULL) {
|
||||
if (string == NULL)
|
||||
{
|
||||
return g_strdup (name);
|
||||
}
|
||||
|
||||
|
@ -834,11 +855,15 @@ xed_utils_replace_home_dir_with_tilde (const gchar *uri)
|
|||
tmp = (gchar *)g_get_home_dir ();
|
||||
|
||||
if (tmp == NULL)
|
||||
{
|
||||
return g_strdup (uri);
|
||||
}
|
||||
|
||||
home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
|
||||
if (home == NULL)
|
||||
{
|
||||
return g_strdup (uri);
|
||||
}
|
||||
|
||||
if (strcmp (uri, home) == 0)
|
||||
{
|
||||
|
@ -906,10 +931,14 @@ xed_utils_get_current_workspace (GdkScreen *screen)
|
|||
err = gdk_error_trap_pop ();
|
||||
|
||||
if (err != Success || result != Success)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (type == XA_CARDINAL && format == 32 && nitems > 0)
|
||||
{
|
||||
ret = current_desktop[0];
|
||||
}
|
||||
|
||||
XFree (current_desktop);
|
||||
return ret;
|
||||
|
@ -957,10 +986,14 @@ xed_utils_get_window_workspace (GtkWindow *gtkwindow)
|
|||
err = gdk_error_trap_pop ();
|
||||
|
||||
if (err != Success || result != Success)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (type == XA_CARDINAL && format == 32 && nitems > 0)
|
||||
{
|
||||
ret = workspace[0];
|
||||
}
|
||||
|
||||
XFree (workspace);
|
||||
return ret;
|
||||
|
@ -1013,7 +1046,9 @@ xed_utils_get_current_viewport (GdkScreen *screen,
|
|||
err = gdk_error_trap_pop ();
|
||||
|
||||
if (err != Success || result != Success)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (type != XA_CARDINAL || format != 32 || nitems < 2)
|
||||
{
|
||||
|
@ -1045,11 +1080,13 @@ has_valid_scheme (const gchar *uri)
|
|||
|
||||
p = uri;
|
||||
|
||||
if (!is_valid_scheme_character (*p)) {
|
||||
if (!is_valid_scheme_character (*p))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
p++;
|
||||
} while (is_valid_scheme_character (*p));
|
||||
|
||||
|
@ -1062,35 +1099,47 @@ xed_utils_is_valid_uri (const gchar *uri)
|
|||
const guchar *p;
|
||||
|
||||
if (uri == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!has_valid_scheme (uri))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* We expect to have a fully valid set of characters */
|
||||
for (p = (const guchar *)uri; *p; p++) {
|
||||
for (p = (const guchar *)uri; *p; p++)
|
||||
{
|
||||
if (*p == '%')
|
||||
{
|
||||
++p;
|
||||
if (!g_ascii_isxdigit (*p))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
++p;
|
||||
if (!g_ascii_isxdigit (*p))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*p <= 32 || *p >= 128)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
handle_builder_error (const gchar *message, ...)
|
||||
handle_builder_error (const gchar *message,
|
||||
...)
|
||||
{
|
||||
GtkWidget *label;
|
||||
gchar *msg;
|
||||
|
@ -1165,16 +1214,11 @@ xed_utils_get_ui_objects (const gchar *filename,
|
|||
|
||||
if (root_objects != NULL)
|
||||
{
|
||||
gtk_builder_add_objects_from_file (builder,
|
||||
filename,
|
||||
root_objects,
|
||||
&error);
|
||||
gtk_builder_add_objects_from_file (builder, filename, root_objects, &error);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_builder_add_from_file (builder,
|
||||
filename,
|
||||
&error);
|
||||
gtk_builder_add_from_file (builder, filename, &error);
|
||||
}
|
||||
|
||||
if (error != NULL)
|
||||
|
@ -1260,7 +1304,9 @@ xed_utils_make_canonical_uri_from_shell_arg (const gchar *str)
|
|||
g_object_unref (gfile);
|
||||
|
||||
if (xed_utils_is_valid_uri (uri))
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
g_free (uri);
|
||||
return NULL;
|
||||
|
@ -1283,7 +1329,9 @@ xed_utils_file_has_parent (GFile *gfile)
|
|||
ret = parent != NULL;
|
||||
|
||||
if (parent)
|
||||
{
|
||||
g_object_unref (parent);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1353,10 +1401,14 @@ xed_utils_basename_for_display (gchar const *uri)
|
|||
gchar *hn_utf8;
|
||||
|
||||
if (hn != NULL)
|
||||
{
|
||||
hn_utf8 = xed_utils_make_valid_utf8 (hn);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* we should never get here */
|
||||
hn_utf8 = g_strdup ("?");
|
||||
}
|
||||
|
||||
/* Translators: '/ on <remote-share>' */
|
||||
name = g_strdup_printf (_("/ on %s"), hn_utf8);
|
||||
|
@ -1423,8 +1475,10 @@ xed_utils_drop_get_uris (GtkSelectionData *selection_data)
|
|||
|
||||
/* Silently ignore malformed URI/filename */
|
||||
if (uri != NULL)
|
||||
{
|
||||
uri_list[p++] = uri;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (uris);
|
||||
|
||||
|
@ -1441,8 +1495,10 @@ static void
|
|||
null_ptr (gchar **ptr)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
*ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xed_utils_decode_uri:
|
||||
|
@ -1495,21 +1551,24 @@ xed_utils_decode_uri (const gchar *uri,
|
|||
*/
|
||||
|
||||
if (!g_ascii_isalpha (*p))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = *p++;
|
||||
|
||||
if (c == ':')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(g_ascii_isalnum(c) ||
|
||||
c == '+' ||
|
||||
c == '-' ||
|
||||
c == '.'))
|
||||
if (!(g_ascii_isalnum(c) || c == '+' || c == '-' || c == '.'))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (scheme)
|
||||
{
|
||||
|
@ -1517,7 +1576,9 @@ xed_utils_decode_uri (const gchar *uri,
|
|||
out = *scheme;
|
||||
|
||||
for (in = uri; in < p - 1; in++)
|
||||
{
|
||||
*out++ = g_ascii_tolower (*in);
|
||||
}
|
||||
|
||||
*out = '\0';
|
||||
}
|
||||
|
@ -1537,7 +1598,9 @@ xed_utils_decode_uri (const gchar *uri,
|
|||
authority_end = memchr (authority_start, '/', hier_part_end - authority_start);
|
||||
|
||||
if (authority_end == NULL)
|
||||
{
|
||||
authority_end = hier_part_end;
|
||||
}
|
||||
|
||||
/* 3.2:
|
||||
* authority = [ userinfo "@" ] host [ ":" port ]
|
||||
|
@ -1550,12 +1613,16 @@ xed_utils_decode_uri (const gchar *uri,
|
|||
userinfo_start = authority_start;
|
||||
|
||||
if (user)
|
||||
{
|
||||
*user = g_uri_unescape_segment (userinfo_start, userinfo_end, NULL);
|
||||
}
|
||||
|
||||
if (user && *user == NULL)
|
||||
{
|
||||
if (scheme)
|
||||
{
|
||||
g_free (*scheme);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -1563,7 +1630,9 @@ xed_utils_decode_uri (const gchar *uri,
|
|||
host_start = userinfo_end + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
host_start = authority_start;
|
||||
}
|
||||
|
||||
port_start = memchr (host_start, ':', authority_end - host_start);
|
||||
|
||||
|
@ -1572,19 +1641,27 @@ xed_utils_decode_uri (const gchar *uri,
|
|||
host_end = port_start++;
|
||||
|
||||
if (port)
|
||||
{
|
||||
*port = g_strndup (port_start, authority_end - port_start);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
host_end = authority_end;
|
||||
}
|
||||
|
||||
if (host)
|
||||
{
|
||||
*host = g_strndup (host_start, host_end - host_start);
|
||||
}
|
||||
|
||||
hier_part_start = authority_end;
|
||||
}
|
||||
|
||||
if (path)
|
||||
{
|
||||
*path = g_uri_unescape_segment (hier_part_start, hier_part_end, "/");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue