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);
(GWeakNotify)(midori_browser_weak_notify_cb), browser);
}
+ if (command)
+ midori_app_send_command (app, command);
+
return FALSE;
}
gchar* config;
gboolean run;
gchar* snapshot;
+ gboolean execute;
gboolean version;
gchar** uris;
MidoriApp* app;
{ "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,
config = NULL;
run = FALSE;
snapshot = NULL;
+ execute = FALSE;
version = FALSE;
uris = NULL;
error = NULL;
{
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);
}
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])
g_free (uri);
i++;
}
+ }
katze_assign (config_file, build_config_filename ("config"));
if (is_writable (config_file))
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
typedef gpointer MidoriAppInstance;
#define MidoriAppInstanceNull NULL
#include <unique/unique.h>
+ #define MIDORI_UNIQUE_COMMAND 1
#else
typedef gint MidoriAppInstance;
#define MidoriAppInstanceNull -1
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));
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);
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;
}
/* 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;
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));
#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
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