[console] util: Move URI quoting to kgx-util.c
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [console] util: Move URI quoting to kgx-util.c
- Date: Tue, 17 May 2022 15:00:51 +0000 (UTC)
commit 2129d4b03e37815781e28c4377641c873dcafd00
Author: Colin Kinloch <colin kinlo ch>
Date: Tue May 17 03:02:36 2022 +0100
util: Move URI quoting to kgx-util.c
src/kgx-tab.c | 76 ++++++------------------------------------------------
src/kgx-util.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/kgx-util.h | 30 ++++++++++++++++++++++
src/meson.build | 2 ++
4 files changed, 120 insertions(+), 68 deletions(-)
---
diff --git a/src/kgx-tab.c b/src/kgx-tab.c
index bc182e5..706400c 100644
--- a/src/kgx-tab.c
+++ b/src/kgx-tab.c
@@ -30,6 +30,7 @@
#include "kgx-tab.h"
#include "kgx-pages.h"
#include "kgx-terminal.h"
+#include "kgx-util.h"
#include "kgx-application.h"
@@ -1224,67 +1225,6 @@ kgx_tab_get_children (KgxTab *self)
}
-/**
- * terminal_util_transform_uris_to_quoted_fuse_paths:
- * @uris:
- *
- * Transforms those URIs in @uris to shell-quoted paths that point to
- * GIO fuse paths.
- */
-static void
-terminal_util_transform_uris_to_quoted_fuse_paths (GStrv uris)
-{
- guint i;
-
- if (!uris)
- return;
-
- for (i = 0; uris[i]; ++i)
- {
- g_autoptr (GFile) file = NULL;
- g_autofree char *path = NULL;
-
- file = g_file_new_for_uri (uris[i]);
-
- path = g_file_get_path (file);
- if (path)
- {
- char *quoted;
-
- quoted = g_shell_quote (path);
- g_free (uris[i]);
-
- uris[i] = quoted;
- }
- }
-}
-
-
-static char *
-terminal_util_concat_uris (GStrv uris,
- gsize *length)
-{
- GString *string;
- gsize len;
- guint i;
-
- len = 0;
- for (i = 0; uris[i]; ++i)
- len += strlen (uris[i]) + 1;
-
- if (length)
- *length = len;
-
- string = g_string_sized_new (len + 1);
- for (i = 0; uris[i]; ++i)
- {
- g_string_append (string, uris[i]);
- g_string_append_c (string, ' ');
- }
-
- return g_string_free (string, FALSE);
-}
-
void
kgx_tab_accept_drop (KgxTab *self,
GtkSelectionData *selection_data)
@@ -1302,21 +1242,21 @@ kgx_tab_accept_drop (KgxTab *self,
if (gtk_selection_data_get_length (selection_data) < 0)
return;
- if (gtk_targets_include_uri (&selection_data_target, 1))
- {
+ if (gtk_targets_include_uri (&selection_data_target, 1)) {
g_auto (GStrv) uris = NULL;
uris = gtk_selection_data_get_uris (selection_data);
- terminal_util_transform_uris_to_quoted_fuse_paths (uris);
+ kgx_util_transform_uris_to_quoted_fuse_paths (uris);
- text = terminal_util_concat_uris (uris, NULL);
- }
- else
+ text = kgx_util_concat_uris (uris, NULL);
+ } else {
text = (char *) gtk_selection_data_get_text (selection_data);
+ }
- if (priv->terminal)
+ if (priv->terminal) {
kgx_terminal_accept_paste (KGX_TERMINAL (priv->terminal), text);
+ }
}
diff --git a/src/kgx-util.c b/src/kgx-util.c
new file mode 100644
index 0000000..766af58
--- /dev/null
+++ b/src/kgx-util.c
@@ -0,0 +1,80 @@
+/* kgx-util.c
+ *
+ * Copyright 2022 Zander Brown
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "kgx-util.h"
+
+/**
+ * kgx_util_transform_uris_to_quoted_fuse_paths:
+ * @uris:
+ *
+ * Transforms those URIs in @uris to shell-quoted paths that point to
+ * GIO fuse paths.
+ */
+void
+kgx_util_transform_uris_to_quoted_fuse_paths (GStrv uris)
+{
+ guint i;
+
+ if (!uris) {
+ return;
+ }
+
+ for (i = 0; uris[i]; ++i) {
+ g_autoptr (GFile) file = NULL;
+ g_autofree char *path = NULL;
+
+ file = g_file_new_for_uri (uris[i]);
+
+ path = g_file_get_path (file);
+ if (path) {
+ char *quoted;
+
+ quoted = g_shell_quote (path);
+ g_free (uris[i]);
+
+ uris[i] = quoted;
+ }
+ }
+}
+
+
+char *
+kgx_util_concat_uris (GStrv uris,
+ gsize *length)
+{
+ GString *string;
+ gsize len;
+ guint i;
+
+ len = 0;
+ for (i = 0; uris[i]; ++i) {
+ len += strlen (uris[i]) + 1;
+ }
+
+ if (length) {
+ *length = len;
+ }
+
+ string = g_string_sized_new (len + 1);
+ for (i = 0; uris[i]; ++i) {
+ g_string_append (string, uris[i]);
+ g_string_append_c (string, ' ');
+ }
+
+ return g_string_free (string, FALSE);
+}
diff --git a/src/kgx-util.h b/src/kgx-util.h
new file mode 100644
index 0000000..f6354af
--- /dev/null
+++ b/src/kgx-util.h
@@ -0,0 +1,30 @@
+/* kgx-util.h
+ *
+ * Copyright 2022 Zander Brown
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+void kgx_util_transform_uris_to_quoted_fuse_paths (GStrv uris);
+char *kgx_util_concat_uris (GStrv uris,
+ gsize *length);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index 90e78f3..83c1107 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -29,6 +29,8 @@ kgx_sources = [
'kgx-window.h',
'kgx-process.c',
'kgx-process.h',
+ 'kgx-util.c',
+ 'kgx-util.h',
]
kgx_deps = [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]