1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <gegl.h>
21 #include <gtk/gtk.h>
22
23 #include "display-types.h"
24
25 #include "core/gimpprogress.h"
26
27 #include "widgets/gimpwidgets-utils.h"
28
29 #include "gimpdisplayshell.h"
30 #include "gimpdisplayshell-progress.h"
31 #include "gimpstatusbar.h"
32
33
34 static GimpProgress *
gimp_display_shell_progress_start(GimpProgress * progress,gboolean cancellable,const gchar * message)35 gimp_display_shell_progress_start (GimpProgress *progress,
36 gboolean cancellable,
37 const gchar *message)
38 {
39 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
40 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
41
42 return gimp_progress_start (GIMP_PROGRESS (statusbar), cancellable,
43 "%s", message);
44 }
45
46 static void
gimp_display_shell_progress_end(GimpProgress * progress)47 gimp_display_shell_progress_end (GimpProgress *progress)
48 {
49 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
50 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
51
52 gimp_progress_end (GIMP_PROGRESS (statusbar));
53 }
54
55 static gboolean
gimp_display_shell_progress_is_active(GimpProgress * progress)56 gimp_display_shell_progress_is_active (GimpProgress *progress)
57 {
58 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
59 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
60
61 return gimp_progress_is_active (GIMP_PROGRESS (statusbar));
62 }
63
64 static void
gimp_display_shell_progress_set_text(GimpProgress * progress,const gchar * message)65 gimp_display_shell_progress_set_text (GimpProgress *progress,
66 const gchar *message)
67 {
68 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
69 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
70
71 gimp_progress_set_text_literal (GIMP_PROGRESS (statusbar), message);
72 }
73
74 static void
gimp_display_shell_progress_set_value(GimpProgress * progress,gdouble percentage)75 gimp_display_shell_progress_set_value (GimpProgress *progress,
76 gdouble percentage)
77 {
78 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
79 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
80
81 gimp_progress_set_value (GIMP_PROGRESS (statusbar), percentage);
82 }
83
84 static gdouble
gimp_display_shell_progress_get_value(GimpProgress * progress)85 gimp_display_shell_progress_get_value (GimpProgress *progress)
86 {
87 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
88 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
89
90 return gimp_progress_get_value (GIMP_PROGRESS (statusbar));
91 }
92
93 static void
gimp_display_shell_progress_pulse(GimpProgress * progress)94 gimp_display_shell_progress_pulse (GimpProgress *progress)
95 {
96 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
97 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
98
99 gimp_progress_pulse (GIMP_PROGRESS (statusbar));
100 }
101
102 static guint32
gimp_display_shell_progress_get_window_id(GimpProgress * progress)103 gimp_display_shell_progress_get_window_id (GimpProgress *progress)
104 {
105 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (progress));
106
107 if (GTK_IS_WINDOW (toplevel))
108 return gimp_window_get_native_id (GTK_WINDOW (toplevel));
109
110 return 0;
111 }
112
113 static gboolean
gimp_display_shell_progress_message(GimpProgress * progress,Gimp * gimp,GimpMessageSeverity severity,const gchar * domain,const gchar * message)114 gimp_display_shell_progress_message (GimpProgress *progress,
115 Gimp *gimp,
116 GimpMessageSeverity severity,
117 const gchar *domain,
118 const gchar *message)
119 {
120 GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress);
121 GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell);
122
123 switch (severity)
124 {
125 case GIMP_MESSAGE_ERROR:
126 case GIMP_MESSAGE_BUG_WARNING:
127 case GIMP_MESSAGE_BUG_CRITICAL:
128 /* error messages are never handled here */
129 break;
130
131 case GIMP_MESSAGE_WARNING:
132 /* warning messages go to the statusbar, if it's visible */
133 if (! gimp_statusbar_get_visible (statusbar))
134 break;
135 else
136 return gimp_progress_message (GIMP_PROGRESS (statusbar), gimp,
137 severity, domain, message);
138
139 case GIMP_MESSAGE_INFO:
140 /* info messages go to the statusbar;
141 * if they are not handled there, they are swallowed
142 */
143 gimp_progress_message (GIMP_PROGRESS (statusbar), gimp,
144 severity, domain, message);
145 return TRUE;
146 }
147
148 return FALSE;
149 }
150
151 void
gimp_display_shell_progress_iface_init(GimpProgressInterface * iface)152 gimp_display_shell_progress_iface_init (GimpProgressInterface *iface)
153 {
154 iface->start = gimp_display_shell_progress_start;
155 iface->end = gimp_display_shell_progress_end;
156 iface->is_active = gimp_display_shell_progress_is_active;
157 iface->set_text = gimp_display_shell_progress_set_text;
158 iface->set_value = gimp_display_shell_progress_set_value;
159 iface->get_value = gimp_display_shell_progress_get_value;
160 iface->pulse = gimp_display_shell_progress_pulse;
161 iface->get_window_id = gimp_display_shell_progress_get_window_id;
162 iface->message = gimp_display_shell_progress_message;
163 }
164