Implement 'Run as web application' option on bookmarks

If enabled, the bookmark will run as a standalone process by default.
This commit is contained in:
Christian Dywan 2009-11-18 23:10:47 +01:00
parent d3526d5897
commit 18526f2ac6
2 changed files with 105 additions and 39 deletions

View file

@ -657,6 +657,7 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
GtkWidget* entry_desc;
GtkWidget* entry_uri;
GtkWidget* combo_folder;
GtkWidget* check_app;
if (!browser->bookmarks || !GTK_WIDGET_VISIBLE (browser))
return;
@ -777,6 +778,22 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
gtk_widget_show_all (hbox);
}
check_app = NULL;
if (!KATZE_IS_ARRAY (bookmark))
{
hbox = gtk_hbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
label = gtk_label_new (NULL);
gtk_size_group_add_widget (sizegroup, label);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
check_app = gtk_check_button_new_with_mnemonic (_("Run as _web application"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_app),
katze_item_get_meta_integer (bookmark, "app") != -1);
gtk_box_pack_start (GTK_BOX (hbox), check_app, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), hbox);
gtk_widget_show_all (hbox);
}
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
@ -788,12 +805,15 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
katze_item_set_text (bookmark,
gtk_entry_get_text (GTK_ENTRY (entry_desc)));
if (!KATZE_IS_ARRAY (bookmark))
{
katze_item_set_uri (bookmark,
gtk_entry_get_text (GTK_ENTRY (entry_uri)));
katze_item_set_meta_integer (bookmark, "app",
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_app))
? 1 : -1);
}
folder = browser->bookmarks;
if (1)
{
selected = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_folder));
if (g_strcmp0 (selected, _("Toplevel folder")))
{
@ -812,7 +832,6 @@ midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
katze_array_remove_item (katze_item_get_parent (bookmark), bookmark);
katze_array_add_item (folder, bookmark);
}
}
gtk_widget_destroy (dialog);
}
@ -2812,13 +2831,26 @@ _action_bookmarks_populate_popup (GtkAction* action,
gtk_widget_show (menuitem);
}
static void
midori_browser_open_bookmark (MidoriBrowser* browser,
KatzeItem* item)
{
/* FIXME: Use the same binary that is running right now */
if (katze_item_get_meta_integer (item, "app") != -1)
sokoke_spawn_program ("midori -a", katze_item_get_uri (item), FALSE);
else
{
midori_browser_set_current_uri (browser, katze_item_get_uri (item));
gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
}
}
static void
_action_bookmarks_activate_item (GtkAction* action,
KatzeItem* item,
MidoriBrowser* browser)
{
midori_browser_set_current_uri (browser, katze_item_get_uri (item));
gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
midori_browser_open_bookmark (browser, item);
}
static void
@ -3867,8 +3899,7 @@ midori_browser_menu_bookmarks_item_activate_cb (GtkWidget* widget,
KatzeItem* item;
item = (KatzeItem*)g_object_get_data (G_OBJECT (widget), "KatzeItem");
midori_browser_set_current_uri (browser, katze_item_get_uri (item));
gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
midori_browser_open_bookmark (browser, item);
}
static gboolean

View file

@ -149,16 +149,18 @@ sokoke_show_uri (GdkScreen* screen,
gboolean
sokoke_spawn_program (const gchar* command,
const gchar* argument,
gboolean quote)
gboolean filename)
{
GAppInfo* info;
GFile* file;
GList* files;
GError* error;
g_return_val_if_fail (command != NULL, FALSE);
g_return_val_if_fail (argument != NULL, FALSE);
/* quote is ignored */
if (filename)
{
GAppInfo* info;
GFile* file;
GList* files;
info = g_app_info_create_from_commandline (command,
NULL, G_APP_INFO_CREATE_NONE, NULL);
@ -177,6 +179,39 @@ sokoke_spawn_program (const gchar* command,
g_object_unref (file);
g_list_free (files);
}
else
{
gchar* command_ready;
gchar** argv;
if (strstr (command, "%s"))
command_ready = g_strdup_printf (command, argument);
else
command_ready = g_strconcat (command, " ", argument, NULL);
error = NULL;
if (!g_shell_parse_argv (command_ready, NULL, &argv, &error))
{
error_dialog (_("Could not run external program."), error->message);
g_error_free (error);
g_free (command_ready);
return FALSE;
}
g_free (command_ready);
error = NULL;
if (!g_spawn_async (NULL, argv, NULL,
(GSpawnFlags)G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
NULL, NULL, NULL, &error))
{
error_dialog (_("Could not run external program."), error->message);
g_error_free (error);
}
g_strfreev (argv);
}
return TRUE;
}