summaryrefslogtreecommitdiff
path: root/src/progress.c
blob: 495729598f718211b504a7c7fbce4d9c3448c963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 * Hacked (C) 1996 Tristan Tarrant
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include "../include/sane/config.h"

#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include "progress.h"

static const int progress_x = 5;
static const int progress_y = 5;

void
progress_cancel (GtkWidget * widget, gpointer data)
{
  Progress_t *p = (Progress_t *) data;

  (*p->callback) ();
}


Progress_t *
progress_new (char *title, char *text,
	      GtkSignalFunc callback, gpointer callback_data)
{
  GtkWidget *button, *label;
  GtkBox *vbox, *hbox;
  Progress_t *p;

  p = (Progress_t *) malloc (sizeof (Progress_t));
  p->callback = callback;

  p->shell = gtk_dialog_new ();
  gtk_widget_set_uposition (p->shell, progress_x, progress_y);
  gtk_window_set_title (GTK_WINDOW (p->shell), title);
  vbox = GTK_BOX (GTK_DIALOG (p->shell)->vbox);
  hbox = GTK_BOX (GTK_DIALOG (p->shell)->action_area);

  gtk_container_border_width (GTK_CONTAINER (vbox), 7);

  label = gtk_label_new (text);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (vbox, label, FALSE, TRUE, 0);

  p->pbar = gtk_progress_bar_new ();
  gtk_widget_set_usize (p->pbar, 200, 20);
  gtk_box_pack_start (vbox, p->pbar, TRUE, TRUE, 0);

  button = gtk_toggle_button_new_with_label ("Cancel");
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      (GtkSignalFunc) progress_cancel, p);
  gtk_box_pack_start (hbox, button, TRUE, TRUE, 0);

  gtk_widget_show (label);
  gtk_widget_show (p->pbar);
  gtk_widget_show (button);
  gtk_widget_show (GTK_WIDGET (p->shell));
  gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), 0);
  return p;
}

void
progress_free (Progress_t * p)
{
  if (p)
    {
      gtk_widget_destroy (p->shell);
      free (p);
    }
}

void
progress_update (Progress_t * p, gfloat newval)
{
  if (p)
    gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval);
}