Replace handmade spinner with GtkSpinner
authorArkadiy Illarionov <qarkai@gmail.com>
Fri, 11 Aug 2023 19:48:32 +0000 (22:48 +0300)
committerColin Clark <colin.clark@cclark.uk>
Sat, 12 Aug 2023 09:03:39 +0000 (10:03 +0100)
po/POTFILES
src/cache-maint.cc
src/editors.cc
src/meson.build
src/preferences.cc
src/search.cc
src/ui-spinner.cc [deleted file]
src/ui-spinner.h [deleted file]
src/ui-tabcomp.cc
src/ui_spinner.png [deleted file]

index 19f7a13..bf8e258 100644 (file)
@@ -117,7 +117,6 @@ src/ui-menu.cc
 src/ui-misc.cc
 src/ui-pathsel.cc
 src/ui/search-and-run.ui
-src/ui-spinner.cc
 src/ui-tabcomp.cc
 src/ui-tree-edit.cc
 src/ui-utildlg.cc
index d2f02e4..b1b9410 100644 (file)
@@ -30,7 +30,6 @@
 #include "thumb-standard.h"
 #include "ui-fileops.h"
 #include "ui-misc.h"
-#include "ui-spinner.h"
 #include "ui-tabcomp.h"
 #include "ui-utildlg.h"
 #include "window.h"
@@ -180,7 +179,7 @@ static void cache_maintain_home_stop(CMData *cm)
        if (!cm->remote)
                {
                gtk_entry_set_text(GTK_ENTRY(cm->entry), _("done"));
-               spinner_set_interval(cm->spinner, -1);
+               gtk_spinner_stop(GTK_SPINNER(cm->spinner));
 
                gtk_widget_set_sensitive(cm->button_stop, FALSE);
                gtk_widget_set_sensitive(cm->button_close, TRUE);
@@ -404,7 +403,8 @@ void cache_maintain_home(gboolean metadata, gboolean clear, GtkWidget *parent)
        gtk_box_pack_start(GTK_BOX(hbox), cm->entry, TRUE, TRUE, 0);
        gtk_widget_show(cm->entry);
 
-       cm->spinner = spinner_new(nullptr, SPINNER_SPEED);
+       cm->spinner = gtk_spinner_new();
+       gtk_spinner_start(GTK_SPINNER(cm->spinner));
        gtk_box_pack_start(GTK_BOX(hbox), cm->spinner, FALSE, FALSE, 0);
        gtk_widget_show(cm->spinner);
 
@@ -678,7 +678,7 @@ static void cache_manager_render_finish(CacheOpsData *cd)
        if (!cd->remote)
                {
                gtk_entry_set_text(GTK_ENTRY(cd->progress), _("done"));
-               spinner_set_interval(cd->spinner, -1);
+               gtk_spinner_stop(GTK_SPINNER(cd->spinner));
 
                gtk_widget_set_sensitive(cd->group, TRUE);
                gtk_widget_set_sensitive(cd->button_start, TRUE);
@@ -829,7 +829,7 @@ static void cache_manager_render_start_cb(GenericDialog *, gpointer data)
                        gtk_widget_set_sensitive(cd->button_stop, TRUE);
                        gtk_widget_set_sensitive(cd->button_close, FALSE);
 
-                       spinner_set_interval(cd->spinner, SPINNER_SPEED);
+                       gtk_spinner_start(GTK_SPINNER(cd->spinner));
                        }
                dir_fd = file_data_new_dir(path);
                cache_manager_render_folder(cd, dir_fd);
@@ -925,7 +925,7 @@ static void cache_manager_render_dialog(GtkWidget *widget, const gchar *path)
        gtk_box_pack_start(GTK_BOX(cd->gd->vbox), cd->progress_bar, TRUE, TRUE, 0);
        gtk_widget_show(cd->progress_bar);
 
-       cd->spinner = spinner_new(nullptr, -1);
+       cd->spinner = gtk_spinner_new();
        gtk_box_pack_start(GTK_BOX(hbox), cd->spinner, FALSE, FALSE, 0);
        gtk_widget_show(cd->spinner);
 
@@ -1314,7 +1314,7 @@ static void cache_manager_sim_finish(CacheOpsData *cd)
        cache_manager_sim_reset(cd);
        if (!cd->remote)
                {
-               spinner_set_interval(cd->spinner, -1);
+               gtk_spinner_stop(GTK_SPINNER(cd->spinner));
 
                gtk_widget_set_sensitive(cd->group, TRUE);
                gtk_widget_set_sensitive(cd->button_start, TRUE);
@@ -1498,7 +1498,7 @@ static void cache_manager_sim_start_cb(GenericDialog *, gpointer data)
                        gtk_widget_set_sensitive(cd->button_stop, TRUE);
                        gtk_widget_set_sensitive(cd->button_close, FALSE);
 
-                       spinner_set_interval(cd->spinner, SPINNER_SPEED);
+                       gtk_spinner_start(GTK_SPINNER(cd->spinner));
                        }
                dir_fd = file_data_new_dir(path);
                cache_manager_sim_folder(cd, dir_fd);
@@ -1563,7 +1563,7 @@ static void cache_manager_sim_load_dialog(GtkWidget *widget, const gchar *path)
        gtk_box_pack_start(GTK_BOX(cd->gd->vbox), cd->progress_bar, TRUE, TRUE, 0);
        gtk_widget_show(cd->progress_bar);
 
-       cd->spinner = spinner_new(nullptr, -1);
+       cd->spinner = gtk_spinner_new();
        gtk_box_pack_start(GTK_BOX(hbox), cd->spinner, FALSE, FALSE, 0);
        gtk_widget_show(cd->spinner);
 
index 807d16e..ec246fc 100644 (file)
@@ -26,7 +26,6 @@
 #include "filefilter.h"
 #include "pixbuf-util.h"
 #include "ui-fileops.h"
-#include "ui-spinner.h"
 #include "utilops.h"
 
 #define EDITOR_WINDOW_WIDTH 500
@@ -568,7 +567,7 @@ static void editor_verbose_window_enable_close(EditorVerboseData *vd)
 {
        vd->gd->cancel_cb = editor_verbose_window_close;
 
-       spinner_set_interval(vd->spinner, -1);
+       gtk_spinner_stop(GTK_SPINNER(vd->spinner));
        gtk_widget_set_sensitive(vd->button_stop, FALSE);
        gtk_widget_set_sensitive(vd->button_close, TRUE);
 }
@@ -619,7 +618,8 @@ static EditorVerboseData *editor_verbose_window(EditorData *ed, const gchar *tex
        gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(vd->progress), TRUE);
        gtk_widget_show(vd->progress);
 
-       vd->spinner = spinner_new(nullptr, SPINNER_SPEED);
+       vd->spinner = gtk_spinner_new();
+       gtk_spinner_start(GTK_SPINNER(vd->spinner));
        gtk_box_pack_start(GTK_BOX(hbox), vd->spinner, FALSE, FALSE, 0);
        gtk_widget_show(vd->spinner);
 
index 69d80a9..78e39c4 100644 (file)
@@ -208,8 +208,6 @@ main_sources = files('advanced-exif.cc',
 'ui-misc.h',
 'ui-pathsel.cc',
 'ui-pathsel.h',
-'ui-spinner.cc',
-'ui-spinner.h',
 'ui-tabcomp.cc',
 'ui-tabcomp.h',
 'ui-tree-edit.cc',
@@ -256,7 +254,6 @@ gq_marshal_pragma = custom_target('gq-marshal-pragma',
 project_sources += gq_marshal_pragma
 
 icon_pairs = [
-'icon_spinner', files('ui_spinner.png'),
 'icon_tabcomp', files('ui_tabcomp.png'),
 ]
 
index de5dc59..390bbea 100644 (file)
 
 #include "bar-keywords.h"
 #include "cache.h"
+#include "color-man.h"
 #include "editors.h"
 #include "filedata.h"
 #include "filefilter.h"
 #include "fullscreen.h"
 #include "image.h"
 #include "image-overlay.h"
-#include "color-man.h"
 #include "img-view.h"
 #include "layout-util.h"
 #include "metadata.h"
@@ -44,7 +44,6 @@
 #include "utilops.h"
 #include "ui-fileops.h"
 #include "ui-misc.h"
-#include "ui-spinner.h"
 #include "ui-tabcomp.h"
 #include "window.h"
 #include "zonedetect.h"
@@ -3013,7 +3012,7 @@ static void keywords_find_finish(KeywordFindData *kfd)
        keywords_find_reset(kfd);
 
        gtk_entry_set_text(GTK_ENTRY(kfd->progress), _("done"));
-       spinner_set_interval(kfd->spinner, -1);
+       gtk_spinner_stop(GTK_SPINNER(kfd->spinner));
 
        gtk_widget_set_sensitive(kfd->group, TRUE);
        gtk_widget_set_sensitive(kfd->button_start, TRUE);
@@ -3106,7 +3105,7 @@ static void keywords_find_start_cb(GenericDialog *, gpointer data)
                gtk_widget_set_sensitive(kfd->button_start, FALSE);
                gtk_widget_set_sensitive(kfd->button_stop, TRUE);
                gtk_widget_set_sensitive(kfd->button_close, FALSE);
-               spinner_set_interval(kfd->spinner, SPINNER_SPEED);
+               gtk_spinner_start(GTK_SPINNER(kfd->spinner));
 
                dir_fd = file_data_new_dir(path);
                keywords_find_folder(kfd, dir_fd);
@@ -3165,7 +3164,7 @@ static void keywords_find_dialog(GtkWidget *widget, const gchar *path)
        gtk_box_pack_start(GTK_BOX(hbox), kfd->progress, TRUE, TRUE, 0);
        gtk_widget_show(kfd->progress);
 
-       kfd->spinner = spinner_new(nullptr, -1);
+       kfd->spinner = gtk_spinner_new();
        gtk_box_pack_start(GTK_BOX(hbox), kfd->spinner, FALSE, FALSE, 0);
        gtk_widget_show(kfd->spinner);
 
index 314a2a9..b9c5d6d 100644 (file)
 #include "ui-fileops.h"
 #include "ui-menu.h"
 #include "ui-misc.h"
-#include "ui-spinner.h"
 #include "ui-tabcomp.h"
 #include "ui-tree-edit.h"
 #include "uri-utils.h"
 #include "utilops.h"
 #include "window.h"
+
 #include <cmath>
 
 #define DEF_SEARCH_WIDTH  700
@@ -1730,7 +1730,7 @@ static void search_stop(SearchData *sd)
        sd->match_broken_enable = FALSE;
 
        gtk_widget_set_sensitive(sd->box_search, TRUE);
-       spinner_set_interval(sd->spinner, -1);
+       gtk_spinner_stop(GTK_SPINNER(sd->spinner));
        gtk_widget_set_sensitive(sd->button_start, TRUE);
        gtk_widget_set_sensitive(sd->button_stop, FALSE);
        search_progress_update(sd, TRUE, -1.0);
@@ -2607,7 +2607,7 @@ static void search_start(SearchData *sd)
        sd->search_total = 0;
 
        gtk_widget_set_sensitive(sd->box_search, FALSE);
-       spinner_set_interval(sd->spinner, SPINNER_SPEED);
+       gtk_spinner_start(GTK_SPINNER(sd->spinner));
        gtk_widget_set_sensitive(sd->button_start, FALSE);
        gtk_widget_set_sensitive(sd->button_stop, TRUE);
        search_progress_update(sd, TRUE, -1.0);
@@ -3697,7 +3697,7 @@ void search_new(FileData *dir_fd, FileData *example_file)
        gtk_box_pack_start(GTK_BOX(hbox), sd->label_progress, TRUE, TRUE, 0);
        gtk_widget_show(sd->label_progress);
 
-       sd->spinner = spinner_new(nullptr, -1);
+       sd->spinner = gtk_spinner_new();
        gtk_box_pack_start(GTK_BOX(hbox), sd->spinner, FALSE, FALSE, 0);
        gtk_widget_show(sd->spinner);
 
diff --git a/src/ui-spinner.cc b/src/ui-spinner.cc
deleted file mode 100644 (file)
index 9307529..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (C) 2004 John Ellis
- * Copyright (C) 2008 - 2016 The Geeqie Team
- *
- * Author: John Ellis
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "main.h"
-#include "ui-spinner.h"
-
-#include "ui_icons.h"
-#include "ui-fileops.h"
-
-
-#define SPINNER_FRAMES 19
-
-
-/*
- *-----------------------------------------------------------------------------
- * spinner utility
- *-----------------------------------------------------------------------------
- */
-
-struct SpinnerData {
-       GtkWidget *image;
-       GList *list;            /* list of pixbufs */
-       guint frame;
-       guint timer_id; /* event source id */
-};
-
-static void spinner_set_frame(SpinnerData *sp, guint frame)
-{
-       GdkPixbuf *pb;
-
-       pb = static_cast<GdkPixbuf *>(g_list_nth_data(sp->list, frame));
-       if (pb) gtk_image_set_from_pixbuf(GTK_IMAGE(sp->image), pb);
-
-       sp->frame = frame;
-}
-
-static void spinner_increment_frame(SpinnerData *sp)
-{
-       sp->frame++;
-       if (sp->frame >= g_list_length(sp->list)) sp->frame = 1;
-       spinner_set_frame(sp, sp->frame);
-}
-
-static gboolean spinner_loop_cb(gpointer data)
-{
-       auto sp = static_cast<SpinnerData *>(data);
-
-       if (sp->list) spinner_increment_frame(sp);
-
-       return TRUE;
-}
-
-static void spinner_set_timeout(SpinnerData *sp, gint interval)
-{
-       if (!sp) return;
-
-       if (sp->timer_id)
-               {
-               g_source_remove(sp->timer_id);
-               sp->timer_id = 0;
-               }
-
-       if (interval > 0)
-               {
-               sp->timer_id = g_timeout_add(interval, spinner_loop_cb, sp);
-               }
-       else if (interval < 0)
-               {
-               spinner_set_frame(sp, 0);
-               }
-
-       gtk_widget_set_sensitive(sp->image, (interval >= 0));
-}
-
-static void spinner_destroy_cb(GtkWidget *, gpointer data)
-{
-       auto sp = static_cast<SpinnerData *>(data);
-
-       spinner_set_timeout(sp, 0);
-
-       g_list_free_full(sp->list, g_object_unref);
-       g_free(sp);
-}
-
-GtkWidget *spinner_new(const gchar *path, gint interval)
-{
-       SpinnerData *sp;
-
-       sp = g_new0(SpinnerData, 1);
-
-       if (path)
-               {
-               gchar *pathl;
-               GdkPixbuf *pb;
-               gint n;
-               gchar *buf;
-
-               pathl = path_from_utf8(path);
-
-               n = 0;
-               buf = g_strdup_printf("%s%02d.png", pathl, n);
-               while ((pb = gdk_pixbuf_new_from_file(buf, nullptr)))
-                       {
-                       sp->list = g_list_append(sp->list, pb);
-
-                       n++;
-                       g_free(buf);
-                       buf = g_strdup_printf("%s%02d.png", pathl, n);
-                       }
-               g_free(buf);
-
-               g_free(pathl);
-               }
-
-       if (!sp->list)
-               {
-               GdkPixbuf *pb;
-               gint n;
-               gint w, h;
-
-               pb = gdk_pixbuf_new_from_inline(-1, icon_spinner, FALSE, nullptr);
-               w = gdk_pixbuf_get_width(pb);
-               h = gdk_pixbuf_get_height(pb) / SPINNER_FRAMES;
-               for (n = 0; n < SPINNER_FRAMES; n++)
-                       {
-                       sp->list = g_list_append(sp->list,
-                                                gdk_pixbuf_new_subpixbuf(pb, 0, n * h, w, h));
-                       }
-               /* pb pixels is inline static, so the subpixbufs in sp->list will be ok */
-               g_object_unref(pb);
-               }
-
-       if (sp->list)
-               {
-               GdkPixbuf *pb;
-
-               pb = static_cast<GdkPixbuf *>(sp->list->data);
-               sp->image = gtk_image_new_from_pixbuf(pb);
-               }
-       else
-               {
-               sp->image = gtk_image_new_from_icon_name(GQ_ICON_MISSING_IMAGE, GTK_ICON_SIZE_DIALOG);
-               }
-
-       g_object_set_data(G_OBJECT(sp->image), "spinner", sp);
-
-       g_signal_connect(G_OBJECT(sp->image), "destroy",
-                        G_CALLBACK(spinner_destroy_cb), sp);
-
-       spinner_set_timeout(sp, interval);
-
-       return sp->image;
-}
-
-void spinner_set_interval(GtkWidget *spinner, gint interval)
-{
-       SpinnerData *sp;
-
-       sp = static_cast<SpinnerData *>(g_object_get_data(G_OBJECT(spinner), "spinner"));
-
-       spinner_set_timeout(sp, interval);
-}
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-function"
-void spinner_step_unused(GtkWidget *spinner, gboolean reset)
-{
-       SpinnerData *sp;
-
-       sp = static_cast<SpinnerData *>(g_object_get_data(G_OBJECT(spinner), "spinner"));
-       if (sp->timer_id)
-               {
-               log_printf("spinner warning: attempt to step with timer set\n");
-               return;
-               }
-
-       if (reset)
-               {
-               spinner_set_frame(sp, 0);
-               }
-       else
-               {
-               spinner_increment_frame(sp);
-               }
-}
-#pragma GCC diagnostic pop
-/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
diff --git a/src/ui-spinner.h b/src/ui-spinner.h
deleted file mode 100644 (file)
index 66d7e89..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2004 John Ellis
- * Copyright (C) 2008 - 2016 The Geeqie Team
- *
- * Author: John Ellis
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef UI_SPINNER_H
-#define UI_SPINNER_H
-
-
-#define SPINNER_SPEED 100
-
-
-extern const guint8 icon_spinner[];
-extern const guint8 icon_tabcomp[];
-
-/**
- * @headerfile spinner_new
- * if path is NULL, the built in spinner is used,
- * otherwise path must be the location of the first image of the
- * spinner without the 00.png portion of the pathname, example: \n
- *
- *     /path/to/spinnerimg_ \n
- *
- * the files required are then: \n
- *
- *     /path/to/spinnerimg_00.png   non-animated state \n
- *     /path/to/spinnerimg_01.png   animation frame 1 \n
- *     /path/to/spinnerimg_02.png   animation frame 2 \n
- *     [continues to last frame...]
- */
-GtkWidget *spinner_new(const gchar *path, gint interval);
-
-void spinner_set_interval(GtkWidget *spinner, gint interval);
-
-#endif
-/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 7a27588..dd3588f 100644 (file)
@@ -29,7 +29,7 @@
 #include "history-list.h"
 #include "misc.h"      /* expand_tilde() */
 #include "ui-fileops.h"
-#include "ui-spinner.h"
+#include "ui_icons.h"
 #include "ui-utildlg.h"
 
 /* define this to enable a pop-up menu that shows possible matches
diff --git a/src/ui_spinner.png b/src/ui_spinner.png
deleted file mode 100644 (file)
index 440f8a2..0000000
Binary files a/src/ui_spinner.png and /dev/null differ