Random image patch



Hello everyone,

Eye of GNOME is a great program. But it had one little annoyance for me: no random image button! I've decided to write my very first patch ever. :)

I'm not sure how to post it, so I'm just going to paste it here.

I changed the following things:

typedef enum EogThumbViewSelectionChange (eog-thumb-view.h)
eog_thumb_view_select_single (eog-thumb-view.c)
eog_window_cmd_go_random (eog-window.c) (new function)
static const GtkActionEntry action_entries_collection (eog-window.c)
set_action_properties (eog-window.c)

Here are my changes:

eog-thumb-view.h:

typedef enum {
    EOG_THUMB_VIEW_SELECT_CURRENT = 0,
    EOG_THUMB_VIEW_SELECT_LEFT,
    EOG_THUMB_VIEW_SELECT_RIGHT,
    EOG_THUMB_VIEW_SELECT_FIRST,
    EOG_THUMB_VIEW_SELECT_LAST,
    EOG_THUMB_VIEW_SELECT_RANDOM
} EogThumbViewSelectionChange;

eog-thumb-view.c:

    if (eog_thumb_view_get_n_selected (thumbview) == 0) {
        switch (change) {
        case EOG_THUMB_VIEW_SELECT_CURRENT:
            break;
        case EOG_THUMB_VIEW_SELECT_RIGHT:
        case EOG_THUMB_VIEW_SELECT_FIRST:
            path = gtk_tree_path_new_first ();
            break;
        case EOG_THUMB_VIEW_SELECT_LEFT:
        case EOG_THUMB_VIEW_SELECT_LAST:
            path = gtk_tree_path_new_from_indices (n_items - 1, -1);
            break;
        case EOG_THUMB_VIEW_SELECT_RANDOM:
            path = gtk_tree_path_new_from_indices ((int)(((float)(n_items - 1) * rand()) / (float)(RAND_MAX + 1.f)), -1);
            break;
        }

    } else {
        list = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (thumbview));
        path = gtk_tree_path_copy ((GtkTreePath *) list->data);
        g_list_foreach (list, (GFunc) gtk_tree_path_free , NULL);
        g_list_free (list);

        gtk_icon_view_unselect_all (GTK_ICON_VIEW (thumbview));

        switch (change) {
        case EOG_THUMB_VIEW_SELECT_CURRENT:
            break;
        case EOG_THUMB_VIEW_SELECT_LEFT:
            if (!gtk_tree_path_prev (path)) {
                gtk_tree_path_free (path);
                path = gtk_tree_path_new_from_indices (n_items - 1, -1);
            }
            break;
        case EOG_THUMB_VIEW_SELECT_RIGHT:
            if (gtk_tree_path_get_indices (path) [0] == n_items - 1) {
                gtk_tree_path_free (path);
                path = gtk_tree_path_new_first ();
            } else {
                gtk_tree_path_next (path);
            }
            break;
        case EOG_THUMB_VIEW_SELECT_FIRST:
            gtk_tree_path_free (path);
            path = gtk_tree_path_new_first ();
            break;
        case EOG_THUMB_VIEW_SELECT_LAST:
            gtk_tree_path_free (path);
            path = gtk_tree_path_new_from_indices (n_items - 1, -1);
            break;
        case EOG_THUMB_VIEW_SELECT_RANDOM:
            gtk_tree_path_free (path);
            path = gtk_tree_path_new_from_indices ((int)(((float)(n_items - 1) * rand()) / (float)(RAND_MAX + 1.f)), -1);
            break;
        }

    }

eog-window.c:

static void
eog_window_cmd_go_random (GtkAction *action, gpointer user_data)
{
    EogWindowPrivate *priv;

    g_return_if_fail (EOG_IS_WINDOW (user_data));

    eog_debug (DEBUG_WINDOW);

    priv = EOG_WINDOW (user_data)->priv;

    eog_thumb_view_select_single (EOG_THUMB_VIEW (priv->thumbview),
                      EOG_THUMB_VIEW_SELECT_RANDOM);
}


eog-window.c:

static const GtkActionEntry action_entries_collection[] = {
    { "GoPrevious", GTK_STOCK_GO_BACK, N_("_Previous Image"), "<Alt>Left",
      N_("Go to the previous image of the collection"),
      G_CALLBACK (eog_window_cmd_go_prev) },
    { "GoNext", GTK_STOCK_GO_FORWARD, N_("_Next Image"), "<Alt>Right",
      N_("Go to the next image of the collection"),
      G_CALLBACK (eog_window_cmd_go_next) },
    { "GoRandom", GTK_STOCK_JUMP_TO, N_("Random Image"), "<Ctrl>M",
      N_("Go to the a random image in the collection"),
      G_CALLBACK (eog_window_cmd_go_random) },

    { "GoFirst", GTK_STOCK_GOTO_FIRST, N_("_First Image"), "<Alt>Home",
      N_("Go to the first image of the collection"),
      G_CALLBACK (eog_window_cmd_go_first) },
    { "GoLast", GTK_STOCK_GOTO_LAST, N_("_Last Image"), "<Alt>End",
      N_("Go to the last image of the collection"),
      G_CALLBACK (eog_window_cmd_go_last) },
    { "BackSpace", NULL, N_("_Previous Image"), "BackSpace",
      NULL,
      G_CALLBACK (eog_window_cmd_go_prev) },
    { "Home", NULL, N_("_First Image"), "Home",
      NULL,
      G_CALLBACK (eog_window_cmd_go_first) },
    { "End", NULL, N_("_Last Image"), "End",
      NULL,
      G_CALLBACK (eog_window_cmd_go_last) },
};

eog-window.c:

static void
set_action_properties (GtkActionGroup *window_group,
               GtkActionGroup *image_group,
               GtkActionGroup *collection_group)
{
        GtkAction *action;

        action = "" (collection_group, "GoPrevious");
        g_object_set (action, "short_label", _("Previous"), NULL);
        g_object_set (action, "is-important", TRUE, NULL);

        action = "" (collection_group, "GoNext");
        g_object_set (action, "short_label", _("Next"), NULL);
        g_object_set (action, "is-important", TRUE, NULL);

        action = "" (image_group, "EditRotate90");
        g_object_set (action, "short_label", _("Right"), NULL);

        action = "" (image_group, "EditRotate270");
        g_object_set (action, "short_label", _("Left"), NULL);

        action = "" (image_group, "ViewZoomIn");
        g_object_set (action, "short_label", _("In"), NULL);

        action = "" (image_group, "ViewZoomOut");
        g_object_set (action, "short_label", _("Out"), NULL);

        action = "" (image_group, "ViewZoomNormal");
        g_object_set (action, "short_label", _("Normal"), NULL);

        action = "" (image_group, "ViewZoomFit");
        g_object_set (action, "short_label", _("Fit"), NULL);

        action = "" (window_group, "ViewImageCollection");
        g_object_set (action, "short_label", _("Collection"), NULL);

        action = "" (collection_group, "GoRandom");
        g_object_set (action, "short_label", _("Random image"), NULL);


        action = "" (image_group, "EditMoveToTrash");
        g_object_set (action, "short_label", C_("action (to trash)", "Trash"), NULL);
}

I hope you don't mind me posting in this manner and that my patch can be integrated into Eye of GNOME. :)

Keep up the good work!

-knight666 (Quinten Lansu)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]