Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

progress_window.c

Go to the documentation of this file.
00001 /*
00002  * Yattm 
00003  *
00004  * Copyright (C) 1999, Torrey Searle <tsearle@uci.edu>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #  include <config.h>
00025 #endif
00026 
00027 #include "intl.h"
00028 #include <gtk/gtk.h>
00029 #include <string.h>
00030 
00031 #include "progress_window.h"
00032 
00033 
00034 typedef struct {
00035     int tag;
00036     GtkWidget * progress_meter;
00037     GtkWidget * progress_window;
00038     unsigned long size;
00039 } progress_window_data;
00040 
00041 static GList *bars = NULL;
00042 static int last = 0;
00043 
00044 static void destroy(GtkWidget * widget, gpointer data)
00045 {
00046     progress_window_data * pwd = data;
00047     GList * l;
00048 
00049     for(l = bars; l; l = l->next)
00050     {
00051         if(pwd == l->data) {
00052             bars = g_list_remove_link(bars, l);
00053             g_free(pwd);
00054 
00055             /* small hack - reset last if there are no more bars */
00056             if(bars == NULL)
00057                 last = 0;
00058 
00059             break;
00060         }
00061     }
00062 }
00063 
00064 int progress_window_new( char * filename, unsigned long size )
00065 {
00066     progress_window_data *pwd = g_new0(progress_window_data, 1);
00067     
00068     GtkWidget * vbox = gtk_vbox_new( FALSE, 5);
00069     GtkWidget * label;
00070     gchar buff[2048];
00071 
00072     pwd->size = size;
00073     pwd->tag = ++last;
00074 
00075     g_snprintf( buff, sizeof(buff), _("Transfering %s"), filename);
00076     label = gtk_label_new(buff);
00077 
00078     gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5);
00079     gtk_widget_show(label);
00080 
00081     pwd->progress_meter = gtk_progress_bar_new();
00082     gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(pwd->progress_meter), 
00083             GTK_PROGRESS_LEFT_TO_RIGHT );
00084 
00085     gtk_box_pack_start(GTK_BOX(vbox),pwd->progress_meter, TRUE, TRUE, 5);
00086     gtk_widget_show(pwd->progress_meter);
00087 
00088     pwd->progress_window = gtk_window_new(GTK_WINDOW_DIALOG);
00089     gtk_window_set_position(GTK_WINDOW(pwd->progress_window), GTK_WIN_POS_MOUSE);
00090     gtk_container_add(GTK_CONTAINER(pwd->progress_window), vbox);
00091         gtk_signal_connect( GTK_OBJECT(pwd->progress_window), "destroy",
00092                             GTK_SIGNAL_FUNC(destroy), pwd );
00093 
00094     gtk_widget_show(vbox);
00095     gtk_widget_show(pwd->progress_window);
00096 
00097     bars = g_list_append(bars, pwd);
00098 
00099     return pwd->tag;
00100 }
00101         
00102 void update_progress(int tag, unsigned long progress)
00103 {
00104     GList * l;
00105     for(l = bars; l; l=l->next)
00106     {
00107         progress_window_data * pwd = l->data;
00108         if(pwd->tag == tag) {
00109             gtk_progress_bar_update(GTK_PROGRESS_BAR(pwd->progress_meter), ((float)progress)/((float)pwd->size));
00110             break;
00111         }
00112     }
00113 }
00114 
00115 void progress_window_close(int tag)
00116 {
00117     GList * l;
00118     for(l = bars; l; l=l->next)
00119     {
00120         progress_window_data * pwd = l->data;
00121         if(pwd->tag == tag) {
00122             gtk_widget_destroy(pwd->progress_window);
00123             break;
00124         }
00125     }
00126 }
00127 

Contact: Andy Maloney     [Documentation generated by doxygen]