Implement -e or --execute to perform various commands
Currently any GtkAction in MidoriBrowser is recognized as a command, no arguments are supported. Commands affect either a newly run instance or a currently running one.
This commit is contained in:
parent
7bab565d0e
commit
abccaf02da
3 changed files with 112 additions and 2 deletions
|
@ -1269,6 +1269,7 @@ midori_load_session (gpointer data)
|
|||
KatzeArray* session;
|
||||
KatzeItem* item;
|
||||
guint i;
|
||||
gchar** command = g_object_get_data (G_OBJECT (app), "execute-command");
|
||||
|
||||
browser = midori_app_create_browser (app);
|
||||
midori_app_add_browser (app, browser);
|
||||
|
@ -1323,6 +1324,9 @@ midori_load_session (gpointer data)
|
|||
(GWeakNotify)(midori_browser_weak_notify_cb), browser);
|
||||
}
|
||||
|
||||
if (command)
|
||||
midori_app_send_command (app, command);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -1401,6 +1405,7 @@ main (int argc,
|
|||
gchar* config;
|
||||
gboolean run;
|
||||
gchar* snapshot;
|
||||
gboolean execute;
|
||||
gboolean version;
|
||||
gchar** uris;
|
||||
MidoriApp* app;
|
||||
|
@ -1420,6 +1425,8 @@ main (int argc,
|
|||
{ "snapshot", 's', 0, G_OPTION_ARG_STRING, &snapshot,
|
||||
N_("Take a snapshot of the specified URI"), NULL },
|
||||
#endif
|
||||
{ "execute", 'e', 0, G_OPTION_ARG_NONE, &execute,
|
||||
N_("Execute the specified command"), NULL },
|
||||
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version,
|
||||
N_("Display program version"), NULL },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
||||
|
@ -1463,6 +1470,7 @@ main (int argc,
|
|||
config = NULL;
|
||||
run = FALSE;
|
||||
snapshot = NULL;
|
||||
execute = FALSE;
|
||||
version = FALSE;
|
||||
uris = NULL;
|
||||
error = NULL;
|
||||
|
@ -1594,8 +1602,9 @@ main (int argc,
|
|||
{
|
||||
GtkWidget* dialog;
|
||||
|
||||
/* TODO: Open as many tabs as we have uris, seperated by pipes */
|
||||
if (uris)
|
||||
if (execute)
|
||||
result = midori_app_send_command (app, uris);
|
||||
else if (uris) /* TODO: Open a tab per URI, seperated by pipes */
|
||||
result = midori_app_instance_send_uris (app, uris);
|
||||
else
|
||||
result = midori_app_instance_send_new_browser (app);
|
||||
|
@ -1755,6 +1764,9 @@ main (int argc,
|
|||
}
|
||||
g_string_free (error_messages, TRUE);
|
||||
|
||||
/* If -e or --execute was specified, "uris" refers to the command. */
|
||||
if (!execute)
|
||||
{
|
||||
/* Open as many tabs as we have uris, seperated by pipes */
|
||||
i = 0;
|
||||
while (uris && uris[i])
|
||||
|
@ -1772,6 +1784,7 @@ main (int argc,
|
|||
g_free (uri);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
katze_assign (config_file, build_config_filename ("config"));
|
||||
if (is_writable (config_file))
|
||||
|
@ -1870,6 +1883,9 @@ main (int argc,
|
|||
katze_item_set_parent (KATZE_ITEM (_session), app);
|
||||
g_idle_add (midori_load_session, _session);
|
||||
|
||||
if (execute)
|
||||
g_object_set_data (G_OBJECT (app), "execute-command", uris);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
#if HAVE_HILDON
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
typedef gpointer MidoriAppInstance;
|
||||
#define MidoriAppInstanceNull NULL
|
||||
#include <unique/unique.h>
|
||||
#define MIDORI_UNIQUE_COMMAND 1
|
||||
#else
|
||||
typedef gint MidoriAppInstance;
|
||||
#define MidoriAppInstanceNull -1
|
||||
|
@ -203,6 +204,7 @@ _midori_app_add_browser (MidoriApp* app,
|
|||
|
||||
katze_array_add_item (app->browsers, browser);
|
||||
|
||||
app->browser = browser;
|
||||
#if HAVE_UNIQUE
|
||||
if (app->instance)
|
||||
unique_app_watch_window (app->instance, GTK_WINDOW (browser));
|
||||
|
@ -395,6 +397,14 @@ midori_app_command_received (MidoriApp* app,
|
|||
gchar** uris,
|
||||
GdkScreen* screen)
|
||||
{
|
||||
if (!screen)
|
||||
{
|
||||
if (app->browser && gtk_widget_has_screen (GTK_WIDGET (app->browser)))
|
||||
screen = gtk_widget_get_screen (GTK_WIDGET (app->browser));
|
||||
else
|
||||
screen = gdk_screen_get_default ();
|
||||
}
|
||||
|
||||
if (g_str_equal (command, "activate"))
|
||||
{
|
||||
gtk_window_set_screen (GTK_WINDOW (app->browser), screen);
|
||||
|
@ -453,6 +463,13 @@ midori_app_command_received (MidoriApp* app,
|
|||
return TRUE;
|
||||
}
|
||||
}
|
||||
else if (g_str_equal (command, "command"))
|
||||
{
|
||||
if (!uris || !app->browser)
|
||||
return FALSE;
|
||||
midori_browser_activate_action (app->browser, *uris);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -483,6 +500,13 @@ midori_browser_message_received_cb (UniqueApp* instance,
|
|||
/* g_strfreev (uris); */
|
||||
break;
|
||||
}
|
||||
case MIDORI_UNIQUE_COMMAND:
|
||||
{
|
||||
gchar** uris = unique_message_data_get_uris (message);
|
||||
success = midori_app_command_received (app, "command", uris, screen);
|
||||
/* g_strfreev (uris); */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
success = FALSE;
|
||||
break;
|
||||
|
@ -524,6 +548,20 @@ midori_app_io_channel_watch_cb (GIOChannel* channel,
|
|||
g_strfreev (uris);
|
||||
}
|
||||
}
|
||||
else if (strncmp (buf, "command", 7) == 0)
|
||||
{
|
||||
guint i = 0;
|
||||
gchar** uris = g_new (gchar, 100);
|
||||
while (fd_gets (sock, buf, sizeof (buf)) != -1 && *buf != '.')
|
||||
{
|
||||
uris[i++] = g_strdup (g_strstrip (buf));
|
||||
if (i == 99)
|
||||
break;
|
||||
}
|
||||
uris[i] = NULL;
|
||||
midori_app_command_received (app, "command", uris, screen);
|
||||
g_strfreev (uris);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_window_present (GTK_WINDOW (app->browser));
|
||||
|
@ -563,6 +601,7 @@ midori_app_create_instance (MidoriApp* app,
|
|||
|
||||
#if HAVE_UNIQUE
|
||||
instance = unique_app_new (instance_name, NULL);
|
||||
unique_app_add_command (instance, "midori-command", MIDORI_UNIQUE_COMMAND);
|
||||
g_signal_connect (instance, "message-received",
|
||||
G_CALLBACK (midori_browser_message_received_cb), app);
|
||||
#else
|
||||
|
@ -883,6 +922,57 @@ midori_app_instance_send_uris (MidoriApp* app,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* midori_app_send_command:
|
||||
* @app: a #MidoriApp
|
||||
* @command: a string vector of a command to execute
|
||||
*
|
||||
* Sends a command to an instance of Midori, which
|
||||
* is either the current process or an already running
|
||||
* instance with the same name on the default display.
|
||||
*
|
||||
* Names of GtkAction objects of MidoriBrowser are recognized as commands.
|
||||
*
|
||||
* Return value: %TRUE if the message was sent successfully
|
||||
*
|
||||
* Since: 0.1.8
|
||||
**/
|
||||
gboolean
|
||||
midori_app_send_command (MidoriApp* app,
|
||||
gchar** command)
|
||||
{
|
||||
#if HAVE_UNIQUE
|
||||
UniqueMessageData* message;
|
||||
UniqueResponse response;
|
||||
#endif
|
||||
|
||||
/* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
|
||||
g_return_val_if_fail (command != NULL, FALSE);
|
||||
|
||||
if (!midori_app_instance_is_running (app))
|
||||
return midori_app_command_received (app, "command", command, NULL);
|
||||
|
||||
#if HAVE_UNIQUE
|
||||
if (app->instance)
|
||||
{
|
||||
message = unique_message_data_new ();
|
||||
unique_message_data_set_uris (message, command);
|
||||
response = unique_app_send_message (app->instance,
|
||||
MIDORI_UNIQUE_COMMAND, message);
|
||||
unique_message_data_free (message);
|
||||
if (response == UNIQUE_RESPONSE_OK)
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
if (app->instance > -1)
|
||||
{
|
||||
send_open_command (app->instance, "command", command);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* midori_app_add_browser:
|
||||
* @app: a #MidoriApp
|
||||
|
|
|
@ -54,6 +54,10 @@ gboolean
|
|||
midori_app_instance_send_uris (MidoriApp* app,
|
||||
gchar** uris);
|
||||
|
||||
gboolean
|
||||
midori_app_send_command (MidoriApp* app,
|
||||
gchar** command);
|
||||
|
||||
void
|
||||
midori_app_add_browser (MidoriApp* app,
|
||||
MidoriBrowser* browser);
|
||||
|
|
Loading…
Reference in a new issue