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