Fix #635: Export in JPG
[geeqie.git] / src / remote.c
index 9979079..15cb871 100644 (file)
@@ -29,7 +29,9 @@
 #include "img-view.h"
 #include "layout.h"
 #include "layout_image.h"
+#include "layout_util.h"
 #include "misc.h"
+#include "pixbuf-renderer.h"
 #include "slideshow.h"
 #include "ui_fileops.h"
 #include "rcfile.h"
@@ -55,6 +57,7 @@ static RemoteConnection *remote_client_open(const gchar *path);
 static gint remote_client_send(RemoteConnection *rc, const gchar *text);
 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data);
 
+static LayoutWindow *lw_id = NULL; /* points to the window set by the --id option */
 
 typedef struct _RemoteClient RemoteClient;
 struct _RemoteClient {
@@ -75,6 +78,7 @@ static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition conditi
        RemoteConnection *rc;
        GIOStatus status = G_IO_STATUS_NORMAL;
 
+       lw_id = NULL;
        rc = client->rc;
 
        if (condition & G_IO_IN)
@@ -180,7 +184,7 @@ static gboolean remote_server_read_cb(GIOChannel *source, GIOCondition condition
        return TRUE;
 }
 
-static gboolean remote_server_exists(const gchar *path)
+gboolean remote_server_exists(const gchar *path)
 {
        RemoteConnection *rc;
 
@@ -279,11 +283,11 @@ static RemoteConnection *remote_client_open(const gchar *path)
        return rc;
 }
 
-static sig_atomic_t sigpipe_occured = FALSE;
+static sig_atomic_t sigpipe_occurred = FALSE;
 
 static void sighandler_sigpipe(gint sig)
 {
-       sigpipe_occured = TRUE;
+       sigpipe_occurred = TRUE;
 }
 
 static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
@@ -296,7 +300,7 @@ static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
        if (!rc || rc->server) return FALSE;
        if (!text) return TRUE;
 
-       sigpipe_occured = FALSE;
+       sigpipe_occurred = FALSE;
 
        new_action.sa_handler = sighandler_sigpipe;
        sigemptyset(&new_action.sa_mask);
@@ -387,37 +391,70 @@ void remote_close(RemoteConnection *rc)
 
 static void gr_image_next(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_next(NULL);
+       layout_image_next(lw_id);
+}
+
+static void gr_new_window(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       LayoutWindow *lw = NULL;
+
+       if (!layout_valid(&lw)) return;
+
+       lw_id = layout_menu_new_window(NULL, lw);
+}
+
+static gboolean gr_close_window_cb()
+{
+       if (!layout_valid(&lw_id)) return FALSE;
+
+       layout_menu_close_cb(NULL, lw_id);
+
+       return FALSE;
+}
+
+static void gr_close_window(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       g_idle_add(gr_close_window_cb, NULL);
 }
 
 static void gr_image_prev(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_prev(NULL);
+       layout_image_prev(lw_id);
 }
 
 static void gr_image_first(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_first(NULL);
+       layout_image_first(lw_id);
 }
 
 static void gr_image_last(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_last(NULL);
+       layout_image_last(lw_id);
 }
 
 static void gr_fullscreen_toggle(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_full_screen_toggle(NULL);
+       layout_image_full_screen_toggle(lw_id);
 }
 
 static void gr_fullscreen_start(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_full_screen_start(NULL);
+       layout_image_full_screen_start(lw_id);
 }
 
 static void gr_fullscreen_stop(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_full_screen_stop(NULL);
+       layout_image_full_screen_stop(lw_id);
+}
+
+static void gr_lw_id(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       lw_id = layout_find_by_layout_id(text);
+       if (!lw_id)
+               {
+               log_printf("remote sent window ID that does not exist:\"%s\"\n",text);
+               }
+       layout_valid(&lw_id);
 }
 
 static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpointer data)
@@ -428,8 +465,8 @@ static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpoin
        file_data_unref(dir_fd);
        if (!list) return;
 //printf("length: %d\n", g_list_length(list));
-       layout_image_slideshow_stop(NULL);
-       layout_image_slideshow_start_from_list(NULL, list);
+       layout_image_slideshow_stop(lw_id);
+       layout_image_slideshow_start_from_list(lw_id, list);
 }
 
 static void gr_cache_thumb(const gchar *text, GIOChannel *channel, gpointer data)
@@ -477,17 +514,17 @@ static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *chan
 
 static void gr_slideshow_toggle(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_slideshow_toggle(NULL);
+       layout_image_slideshow_toggle(lw_id);
 }
 
 static void gr_slideshow_start(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_slideshow_start(NULL);
+       layout_image_slideshow_start(lw_id);
 }
 
 static void gr_slideshow_stop(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_slideshow_stop(NULL);
+       layout_image_slideshow_stop(lw_id);
 }
 
 static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer data)
@@ -502,7 +539,7 @@ static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer
                if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
                                t1 >= 24 || t2 >= 60 || t3 >= 60)
                        {
-                       printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
+                       printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
                                                                SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
                        return;
                        }
@@ -513,7 +550,7 @@ static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer
                if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
                                t1 >= 60 || t2 >= 60)
                        {
-                       printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
+                       printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
                                                                SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
                        return;
                        }
@@ -523,7 +560,7 @@ static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer
                n = t1;
                if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
                        {
-                       printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
+                       printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
                                                                SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
                        return;
                        }
@@ -541,9 +578,9 @@ static void gr_tools_show(const gchar *text, GIOChannel *channel, gpointer data)
        gboolean popped;
        gboolean hidden;
 
-       if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
+       if (layout_tools_float_get(lw_id, &popped, &hidden) && hidden)
                {
-               layout_tools_float_set(NULL, popped, FALSE);
+               layout_tools_float_set(lw_id, popped, FALSE);
                }
 }
 
@@ -552,9 +589,9 @@ static void gr_tools_hide(const gchar *text, GIOChannel *channel, gpointer data)
        gboolean popped;
        gboolean hidden;
 
-       if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
+       if (layout_tools_float_get(lw_id, &popped, &hidden) && !hidden)
                {
-               layout_tools_float_set(NULL, popped, TRUE);
+               layout_tools_float_set(lw_id, popped, TRUE);
                }
 }
 
@@ -585,17 +622,17 @@ static void gr_file_load_no_raise(const gchar *text, GIOChannel *channel, gpoint
                        }
                else
                        {
-                       layout_set_path(NULL, filename);
+                       layout_set_path(lw_id, filename);
                        }
                }
        else if (isdir(filename))
                {
-               layout_set_path(NULL, filename);
+               layout_set_path(lw_id, filename);
                }
        else
                {
                log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
-               layout_set_path(NULL, homedir());
+               layout_set_path(lw_id, homedir());
                }
 
        g_free(filename);
@@ -608,13 +645,115 @@ static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
        gr_raise(text, channel, data);
 }
 
+static void gr_pixel_info(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *pixel_info;
+       gint x_pixel, y_pixel;
+       gint width, height;
+       gint r_mouse, g_mouse, b_mouse;
+       PixbufRenderer *pr;
+       LayoutWindow *lw = NULL;
+
+       if (!layout_valid(&lw_id)) return;
+
+       pr = (PixbufRenderer*)lw_id->image->pr;
+
+       if (pr)
+               {
+               pixbuf_renderer_get_image_size(pr, &width, &height);
+               if (width < 1 || height < 1) return;
+
+               pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
+
+               if (x_pixel >= 0 && y_pixel >= 0)
+                       {
+                       pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
+                                                        &r_mouse, &g_mouse, &b_mouse);
+
+                       pixel_info = g_strdup_printf(_("[%d,%d]: RGB(%3d,%3d,%3d)"),
+                                                x_pixel, y_pixel,
+                                                r_mouse, g_mouse, b_mouse);
+
+                       g_io_channel_write_chars(channel, pixel_info, -1, NULL, NULL);
+                       g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+                       g_free(pixel_info);
+                       }
+               else
+                       {
+                       return;
+                       }
+               }
+       else
+               {
+               return;
+               }
+}
+
+static void gr_rectangle(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *rectangle_info;
+       PixbufRenderer *pr;
+       LayoutWindow *lw = NULL;
+       gint x1, y1, x2, y2;
+
+       if (!options->draw_rectangle) return;
+       if (!layout_valid(&lw_id)) return;
+
+       pr = (PixbufRenderer*)lw_id->image->pr;
+
+       if (pr)
+               {
+               image_get_rectangle(&x1, &y1, &x2, &y2);
+               rectangle_info = g_strdup_printf(_("%dx%d+%d+%d"),
+                                       (x2 > x1) ? x2 - x1 : x1 - x2,
+                                       (y2 > y1) ? y2 - y1 : y1 - y2,
+                                       (x2 > x1) ? x1 : x2,
+                                       (y2 > y1) ? y1 : y2);
+
+               g_io_channel_write_chars(channel, rectangle_info, -1, NULL, NULL);
+               g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+               g_free(rectangle_info);
+               }
+}
+
+static void gr_render_intent(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *render_intent;
+
+       switch (options->color_profile.render_intent)
+               {
+               case 0:
+                       render_intent = g_strdup("Perceptual");
+                       break;
+               case 1:
+                       render_intent = g_strdup("Relative Colorimetric");
+                       break;
+               case 2:
+                       render_intent = g_strdup("Saturation");
+                       break;
+               case 3:
+                       render_intent = g_strdup("Absolute Colorimetric");
+                       break;
+               default:
+                       render_intent = g_strdup("none");
+                       break;
+               }
+
+       g_io_channel_write_chars(channel, render_intent, -1, NULL, NULL);
+       g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+       g_free(render_intent);
+}
+
 static void gr_file_tell(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       LayoutWindow *lw = NULL; /* NULL to force layout_valid() to do some magic */
-       if (!layout_valid(&lw)) return;
-       if (image_get_path(lw->image))
+       if (!layout_valid(&lw_id)) return;
+
+       if (image_get_path(lw_id->image))
                {
-               g_io_channel_write_chars(channel, image_get_path(lw->image), -1, NULL, NULL);
+               g_io_channel_write_chars(channel, image_get_path(lw_id->image), -1, NULL, NULL);
                g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
                }
 }
@@ -725,9 +864,9 @@ static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data)
 {
        LayoutWindow *lw = NULL;
 
-       if (layout_valid(&lw))
+       if (layout_valid(&lw_id))
                {
-               gtk_window_present(GTK_WINDOW(lw->window));
+               gtk_window_present(GTK_WINDOW(lw_id->window));
                }
 }
 
@@ -798,10 +937,16 @@ static RemoteCommandEntry remote_commands[] = {
        { NULL, "file:",                gr_file_load,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE, bring Geeqie window to the top") },
        { NULL, "File:",                gr_file_load_no_raise,  TRUE,  FALSE, N_("<FILE>"), N_("open FILE, do not bring Geeqie window to the top") },
        { NULL, "--tell",               gr_file_tell,           FALSE, FALSE, NULL, N_("print filename of current image") },
+       { NULL, "--pixel-info",         gr_pixel_info,          FALSE, FALSE, NULL, N_("print pixel info of mouse pointer on current image") },
+       { NULL, "--get-rectangle",      gr_rectangle,           FALSE, FALSE, NULL, N_("get rectangle co-ordinates") },
+       { NULL, "--get-render-intent",  gr_render_intent,       FALSE, FALSE, NULL, N_("get render intent") },
        { NULL, "view:",                gr_file_view,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE in new window") },
        { NULL, "--list-clear",         gr_list_clear,          FALSE, FALSE, NULL, N_("clear command line collection list") },
        { NULL, "--list-add:",          gr_list_add,            TRUE,  FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },
        { NULL, "raise",                gr_raise,               FALSE, FALSE, NULL, N_("bring the Geeqie window to the top") },
+       { NULL, "--id:",                gr_lw_id,               TRUE, FALSE, N_("<ID>"), N_("window id for following commands") },
+       { NULL, "--new-window",         gr_new_window,          FALSE, FALSE, NULL, N_("new window") },
+       { NULL, "--close-window",       gr_close_window,        FALSE, FALSE, NULL, N_("close window") },
        { "-ct:", "--cache-thumbs:",    gr_cache_thumb,         TRUE, FALSE, N_("clear|clean"), N_("clear or clean thumbnail cache") },
        { "-cs:", "--cache-shared:",    gr_cache_shared,        TRUE, FALSE, N_("clear|clean"), N_("clear or clean shared thumbnail cache") },
        { "-cm","--cache-metadata",      gr_cache_metadata,               FALSE, FALSE, NULL, N_("    clean the metadata cache") },
@@ -876,7 +1021,7 @@ void remote_help(void)
        gchar *s_opt_param;
        gchar *l_opt_param;
 
-       print_term(_("Remote command list:\n"));
+       print_term(FALSE, _("Remote command list:\n"));
 
        i = 0;
        while (remote_commands[i].func != NULL)
@@ -885,7 +1030,7 @@ void remote_help(void)
                        {
                        s_opt_param = g_strconcat(remote_commands[i].opt_s, remote_commands[i].parameter, NULL);
                        l_opt_param = g_strconcat(remote_commands[i].opt_l, remote_commands[i].parameter, NULL);
-                       printf_term("  %-11s%-1s %-30s%-s\n",
+                       printf_term(FALSE, "  %-11s%-1s %-30s%-s\n",
                                    (remote_commands[i].opt_s) ? s_opt_param : "",
                                    (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
                                    (remote_commands[i].opt_l) ? l_opt_param : "",
@@ -895,7 +1040,7 @@ void remote_help(void)
                        }
                i++;
                }
-       printf_term(N_("\n  All other command line parameters are used as plain files if they exists.\n"));
+       printf_term(FALSE, N_("\n  All other command line parameters are used as plain files if they exists.\n"));
 }
 
 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
@@ -945,7 +1090,7 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                gint retry_count = 12;
                gboolean blank = FALSE;
 
-               printf_term(_("Remote %s not running, starting..."), GQ_APPNAME);
+               printf_term(FALSE, _("Remote %s not running, starting..."), GQ_APPNAME);
 
                command = g_string_new(arg_exec);
 
@@ -985,11 +1130,11 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                        {
                        usleep((retry_count > 10) ? 500000 : 1000000);
                        rc = remote_client_open(buf);
-                       if (!rc) print_term(".");
+                       if (!rc) print_term(FALSE, ".");
                        retry_count--;
                        }
 
-               print_term("\n");
+               print_term(FALSE, "\n");
 
                started = TRUE;
                }
@@ -1081,7 +1226,7 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                }
        else
                {
-               print_term(_("Remote not available\n"));
+               print_term(TRUE, _("Remote not available\n"));
                }
 
        _exit(0);