[gnome-panel/wip/muktupavels/launcher: 5/6] panel: create launcher applet from drag data
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/muktupavels/launcher: 5/6] panel: create launcher applet from drag data
- Date: Wed, 15 Apr 2020 18:45:04 +0000 (UTC)
commit d1344d2ccd409827d767ca0ed3d470ba8bb4ad72
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Apr 15 21:29:26 2020 +0300
panel: create launcher applet from drag data
gnome-panel/launcher.c | 50 ----
gnome-panel/launcher.h | 8 -
gnome-panel/panel.c | 348 +++++++++++++++++++--------
modules/launcher/gp-custom-launcher-applet.c | 8 +
4 files changed, 259 insertions(+), 155 deletions(-)
---
diff --git a/gnome-panel/launcher.c b/gnome-panel/launcher.c
index b1cd9f0f5..3c09f5e85 100644
--- a/gnome-panel/launcher.c
+++ b/gnome-panel/launcher.c
@@ -1077,56 +1077,6 @@ ask_about_launcher (const char *file,
gtk_widget_show (dialog);
}
-void
-panel_launcher_create_from_info (PanelToplevel *toplevel,
- PanelObjectPackType pack_type,
- int pack_index,
- gboolean exec_info,
- const char *exec_or_uri,
- const char *name,
- const char *comment,
- const char *icon)
-{
- GKeyFile *key_file;
- char *location;
- GError *error;
-
- key_file = panel_key_file_new_desktop ();
-
- /* set current language and the "C" locale to this name,
- * this is kind of evil... */
- panel_key_file_set_string (key_file, "Name", name);
- panel_key_file_set_string (key_file, "Comment", comment);
- panel_key_file_set_string (key_file, "Icon", icon);
- panel_key_file_set_locale_string (key_file, "Name", name);
- panel_key_file_set_locale_string (key_file, "Comment", comment);
- panel_key_file_set_locale_string (key_file, "Icon", icon);
-
- if (exec_info) {
- panel_key_file_set_string (key_file, "Exec", exec_or_uri);
- panel_key_file_set_string (key_file, "Type", "Application");
- } else {
- panel_key_file_set_string (key_file, "URL", exec_or_uri);
- panel_key_file_set_string (key_file, "Type", "Link");
- }
-
- location = panel_make_unique_desktop_uri (NULL, exec_or_uri);
-
- error = NULL;
- if (panel_key_file_to_file (key_file, location, &error)) {
- panel_launcher_create (toplevel, pack_type, pack_index, location);
- } else {
- panel_error_dialog (GTK_WINDOW (toplevel),
- gtk_window_get_screen (GTK_WINDOW (toplevel)),
- "cannot_save_launcher", TRUE,
- _("Could not save launcher"),
- error->message);
- g_error_free (error);
- }
-
- g_key_file_free (key_file);
-}
-
static void
panel_launcher_create_with_id (const char *toplevel_id,
PanelObjectPackType pack_type,
diff --git a/gnome-panel/launcher.h b/gnome-panel/launcher.h
index 875078ab5..7ed6c9a84 100644
--- a/gnome-panel/launcher.h
+++ b/gnome-panel/launcher.h
@@ -33,14 +33,6 @@ void panel_launcher_create (PanelToplevel *toplevel,
PanelObjectPackType pack_type,
int pack_index,
const char *location);
-void panel_launcher_create_from_info (PanelToplevel *toplevel,
- PanelObjectPackType pack_type,
- int pack_index,
- gboolean exec_info,
- const char *exec_or_uri,
- const char *name,
- const char *comment,
- const char *icon);
void launcher_launch (Launcher *launcher,
GtkWidget *widget);
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index 65a862de8..451d06028 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -384,6 +384,211 @@ reset_background (PanelToplevel *toplevel)
return TRUE;
}
+typedef struct
+{
+ PanelWidget *panel;
+
+ PanelObjectPackType pack_type;
+ int pack_index;
+ char *iid;
+} InitialSetupData;
+
+static InitialSetupData *
+initial_setup_data_new (PanelWidget *panel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const gchar *iid)
+{
+ InitialSetupData *data;
+
+ data = g_new0 (InitialSetupData, 1);
+
+ data->panel = panel;
+
+ data->pack_type = pack_type;
+ data->pack_index = pack_index;
+ data->iid = g_strdup (iid);
+
+ return data;
+}
+
+static void
+initial_setup_data_free (gpointer user_data)
+{
+ InitialSetupData *data;
+
+ data = (InitialSetupData *) user_data;
+
+ g_free (data->iid);
+ g_free (data);
+}
+
+static void
+initial_setup_dialog_cb (GpInitialSetupDialog *dialog,
+ gboolean canceled,
+ gpointer user_data)
+{
+ InitialSetupData *data;
+ GVariant *initial_settings;
+
+ data = (InitialSetupData *) user_data;
+
+ if (canceled)
+ return;
+
+ initial_settings = gp_initital_setup_dialog_get_settings (dialog);
+
+ panel_applet_frame_create (data->panel->toplevel,
+ data->pack_type,
+ data->pack_index,
+ data->iid,
+ initial_settings);
+
+ g_variant_unref (initial_settings);
+}
+
+static void
+ask_about_custom_launcher (const char *file,
+ PanelWidget *panel,
+ PanelObjectPackType pack_type)
+{
+ int pack_index;
+ const char *iid;
+ InitialSetupData *initial_setup_data;
+ GVariantBuilder builder;
+ GVariant *variant;
+ GVariant *settings;
+
+ if (panel_lockdown_get_disable_command_line_s ())
+ return;
+
+ iid = "org.gnome.gnome-panel.launcher::custom-launcher";
+ pack_index = panel_widget_get_new_pack_index (panel, pack_type);
+ initial_setup_data = initial_setup_data_new (panel, pack_type, pack_index, iid);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+ variant = g_variant_new_string ("Application");
+ g_variant_builder_add (&builder, "{sv}", "type", variant);
+
+ if (file != NULL)
+ {
+ variant = g_variant_new_string (file);
+ g_variant_builder_add (&builder, "{sv}", "command", variant);
+ }
+
+ settings = g_variant_builder_end (&builder);
+ g_variant_ref_sink (settings);
+
+ panel_applets_manager_open_initial_setup_dialog (iid,
+ settings,
+ NULL,
+ initial_setup_dialog_cb,
+ initial_setup_data,
+ initial_setup_data_free);
+
+ g_variant_unref (settings);
+}
+
+static void
+create_launcher_from_info (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ gboolean exec_info,
+ const char *exec_or_uri,
+ const char *name,
+ const char *comment,
+ const char *icon)
+{
+ GVariantBuilder builder;
+ GVariant *variant;
+ GVariant *settings;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+ variant = g_variant_new_string (name);
+ g_variant_builder_add (&builder, "{sv}", "name", variant);
+
+ variant = g_variant_new_string (exec_or_uri);
+ g_variant_builder_add (&builder, "{sv}", "command", variant);
+
+ variant = g_variant_new_string (comment);
+ g_variant_builder_add (&builder, "{sv}", "comment", variant);
+
+ variant = g_variant_new_string (icon);
+ g_variant_builder_add (&builder, "{sv}", "icon", variant);
+
+ if (exec_info)
+ {
+ variant = g_variant_new_string ("Application");
+ g_variant_builder_add (&builder, "{sv}", "type", variant);
+ }
+ else
+ {
+ variant = g_variant_new_string ("Link");
+ g_variant_builder_add (&builder, "{sv}", "type", variant);
+ }
+
+ settings = g_variant_builder_end (&builder);
+ g_variant_ref_sink (settings);
+
+ panel_applet_frame_create (toplevel,
+ pack_type,
+ pack_index,
+ "org.gnome.gnome-panel.launcher::launcher",
+ settings);
+
+ g_variant_unref (settings);
+}
+
+static void
+create_launcher_from_uri (PanelToplevel *toplevel,
+ PanelObjectPackType pack_type,
+ int pack_index,
+ const char *location)
+{
+ char *no_uri;
+ char *new_location;
+ GVariantBuilder builder;
+ GVariant *variant;
+ GVariant *settings;
+
+ g_return_if_fail (location != NULL);
+
+ no_uri = NULL;
+ /* if we have an URI, it might contain escaped characters (? : etc)
+ * that might get unescaped on disk */
+ if (!g_ascii_strncasecmp (location, "file:", strlen ("file:")))
+ no_uri = g_filename_from_uri (location, NULL, NULL);
+
+ if (no_uri == NULL)
+ no_uri = g_strdup (location);
+
+ new_location = panel_launcher_get_filename (no_uri);
+
+ if (new_location == NULL)
+ new_location = no_uri;
+ else
+ g_free (no_uri);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+ variant = g_variant_new_string (new_location);
+ g_variant_builder_add (&builder, "{sv}", "location", variant);
+ g_free (new_location);
+
+ settings = g_variant_builder_end (&builder);
+ g_variant_ref_sink (settings);
+
+ panel_applet_frame_create (toplevel,
+ pack_type,
+ pack_index,
+ "org.gnome.gnome-panel.launcher::launcher",
+ settings);
+
+ g_variant_unref (settings);
+}
+
static gboolean
drop_url (PanelWidget *panel,
PanelObjectPackType pack_type,
@@ -418,10 +623,14 @@ drop_url (PanelWidget *panel,
else
name = netscape_url[NETSCAPE_URL_NAME];
- panel_launcher_create_from_info (panel->toplevel, pack_type, pack_index,
- FALSE,
- netscape_url[NETSCAPE_URL_URL],
- name, comment, PANEL_ICON_REMOTE);
+ create_launcher_from_info (panel->toplevel,
+ pack_type,
+ pack_index,
+ FALSE,
+ netscape_url[NETSCAPE_URL_URL],
+ name,
+ comment,
+ PANEL_ICON_REMOTE);
g_free (comment);
g_strfreev (netscape_url);
@@ -464,8 +673,14 @@ drop_uri (PanelWidget *panel,
comment = g_strdup_printf (_("Open '%s'"), buf);
g_free (buf);
- panel_launcher_create_from_info (panel->toplevel, pack_type, pack_index,
- FALSE, uri, name, comment, icon);
+ create_launcher_from_info (panel->toplevel,
+ pack_type,
+ pack_index,
+ FALSE,
+ uri,
+ name,
+ comment,
+ icon);
g_free (name);
g_free (comment);
@@ -504,31 +719,34 @@ drop_nautilus_desktop_uri (PanelWidget *panel,
g_free (uri_tmp);
g_object_unref (file);
- panel_launcher_create_from_info (panel->toplevel,
- pack_type, pack_index,
- TRUE, /* is_exec? */
- "nautilus", /* exec */
- name, /* name */
- _("Open your personal folder"), /* comment */
- PANEL_ICON_HOME); /* icon name */
+ create_launcher_from_info (panel->toplevel,
+ pack_type,
+ pack_index,
+ TRUE, /* is_exec? */
+ "nautilus", /* exec */
+ name, /* name */
+ _("Open your personal folder"), /* comment */
+ PANEL_ICON_HOME); /* icon name */
g_free (name);
} else if (strncmp (basename, "computer", strlen ("computer")) == 0)
- panel_launcher_create_from_info (panel->toplevel,
- pack_type, pack_index,
- TRUE, /* is_exec? */
- "nautilus computer://", /* exec */
- _("Computer"), /* name */
- _("Browse all local and remote disks and folders accessible
from this computer"), /* comment */
- PANEL_ICON_COMPUTER); /* icon name */
+ create_launcher_from_info (panel->toplevel,
+ pack_type,
+ pack_index,
+ TRUE, /* is_exec? */
+ "nautilus computer://", /* exec */
+ _("Computer"), /* name */
+ _("Browse all local and remote disks and folders accessible from
this computer"), /* comment */
+ PANEL_ICON_COMPUTER); /* icon name */
else if (strncmp (basename, "network", strlen ("network")) == 0)
- panel_launcher_create_from_info (panel->toplevel,
- pack_type, pack_index,
- TRUE, /* is_exec? */
- "nautilus network://", /* exec */
- _("Network"), /* name */
- _("Browse bookmarked and local network locations"), /*
comment */
- PANEL_ICON_NETWORK); /* icon name */
+ create_launcher_from_info (panel->toplevel,
+ pack_type,
+ pack_index,
+ TRUE, /* is_exec? */
+ "nautilus network://", /* exec */
+ _("Network"), /* name */
+ _("Browse bookmarked and local network locations"), /* comment */
+ PANEL_ICON_NETWORK); /* icon name */
else
success = FALSE;
@@ -641,9 +859,10 @@ drop_urilist (PanelWidget *panel,
!strcmp (mime, "application/x-desktop") ||
!strcmp (mime, "application/x-kde-app-info"))) {
if (panel_layout_is_writable ())
- panel_launcher_create (panel->toplevel,
- pack_type, pack_index,
- uri);
+ create_launcher_from_uri (panel->toplevel,
+ pack_type,
+ pack_index,
+ uri);
else
success = FALSE;
} else if (type != G_FILE_TYPE_DIRECTORY && can_exec) {
@@ -652,10 +871,8 @@ drop_urilist (PanelWidget *panel,
filename = g_file_get_path (file);
if (panel_layout_is_writable ())
- /* executable and local, so add a
- * launcher with it */
- ask_about_launcher (filename, panel,
- pack_type);
+ /* executable and local, so add a launcher with it */
+ ask_about_custom_launcher (filename, panel, pack_type);
else
success = FALSE;
g_free (filename);
@@ -896,69 +1113,6 @@ drag_leave_cb (GtkWidget *widget,
panel_toplevel_queue_auto_hide (toplevel);
}
-typedef struct
-{
- PanelWidget *panel;
-
- PanelObjectPackType pack_type;
- int pack_index;
- gchar *iid;
-} InitialSetupData;
-
-static InitialSetupData *
-initial_setup_data_new (PanelWidget *panel,
- PanelObjectPackType pack_type,
- int pack_index,
- const gchar *iid)
-{
- InitialSetupData *data;
-
- data = g_new0 (InitialSetupData, 1);
-
- data->panel = panel;
-
- data->pack_type = pack_type;
- data->pack_index = pack_index;
- data->iid = g_strdup (iid);
-
- return data;
-}
-
-static void
-initial_setup_data_free (gpointer user_data)
-{
- InitialSetupData *data;
-
- data = (InitialSetupData *) user_data;
-
- g_free (data->iid);
- g_free (data);
-}
-
-static void
-initial_setup_dialog_cb (GpInitialSetupDialog *dialog,
- gboolean canceled,
- gpointer user_data)
-{
- InitialSetupData *data;
- GVariant *initial_settings;
-
- data = (InitialSetupData *) user_data;
-
- if (canceled)
- return;
-
- initial_settings = gp_initital_setup_dialog_get_settings (dialog);
-
- panel_applet_frame_create (data->panel->toplevel,
- data->pack_type,
- data->pack_index,
- data->iid,
- initial_settings);
-
- g_variant_unref (initial_settings);
-}
-
static void
panel_receive_dnd_data (PanelWidget *panel,
guint info,
diff --git a/modules/launcher/gp-custom-launcher-applet.c b/modules/launcher/gp-custom-launcher-applet.c
index 8985bf721..d29724686 100644
--- a/modules/launcher/gp-custom-launcher-applet.c
+++ b/modules/launcher/gp-custom-launcher-applet.c
@@ -208,6 +208,7 @@ gp_custom_launcher_applet_initial_setup_dialog (GpInitialSetupDialog *dialog)
{
GtkWidget *editor;
LauncherData *data;
+ GVariant *variant;
editor = gp_editor_new (FALSE);
@@ -220,6 +221,13 @@ gp_custom_launcher_applet_initial_setup_dialog (GpInitialSetupDialog *dialog)
g_signal_connect (editor, "command-changed", G_CALLBACK (command_changed_cb), data);
g_signal_connect (editor, "comment-changed", G_CALLBACK (comment_changed_cb), data);
+ variant = gp_initital_setup_dialog_get_setting (dialog, "command");
+ if (variant != NULL)
+ {
+ gp_editor_set_command (GP_EDITOR (editor),
+ g_variant_get_string (variant, NULL));
+ }
+
icon_changed_cb (data->editor, data);
type_changed_cb (data->editor, data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]