please help!!!



hi everyone,

i'll get to my question:
i want to make a countdown clock to zero and then execute a command.  I want 
to know how to update a label after 1 second to achieve a countdown look & 
feel?

eg:  countdown started... default time = 4 minutes
4:00
3:59
3:58 
(catch another countdown started and add onto current one)
7:58
7:57
7:56
and so forth...

- - snip (main.c)

int
main (int argc, char *argv[])
{
  GtkWidget *window1;

#ifdef ENABLE_NLS
  bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
  textdomain (PACKAGE);
#endif

  gnome_init ("timer3", VERSION, argc, argv);

  window1 = create_window1 ();
  gtk_widget_show (window1);

  gtk_main ();
  return 0;
}

- - snip (end)

- - snip ( callback.c )
#include <gnome.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <glib.h>
#include <errno.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"

GtkLabel *label;

guint timeout; /* timeout identifier           */
guint counter; /* count down value in seconds  */

/* display a counter value in the label in mm:ss format */
void counter_display(guint seconds) {
  guint minutes = seconds / 60;
  gchar *text = g_strdup_printf("%02d:%02d", minutes, seconds % 60);
  gtk_label_set_text(label, text);
  g_free(text);
}

/* decrement the counter, called every second */
int countdown_update(gpointer ignored) {
  counter_display(--counter);
  return (counter > 0);
}

/* start a counter */
void countdown_start(guint seconds) {
  counter = seconds;
  counter_display(counter);
  timeout = gtk_timeout_add(1000, (GtkFunction) countdown_update, NULL);
}

/* stop a counter */
void countdown_stop() {
  gtk_timeout_remove(timeout);
}
- - snip (end)



Please, any help would be very very good.

rgds, 
Trav.



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