Fixed bz-decompress error message bug.
[doldaconnect.git] / clients / gtk2 / hublist.c
index 37ad850..2420ff8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Dolda Connect - Modular multiuser Direct Connect-style client
- *  Copyright (C) 2007 Fredrik Tolf (fredrik@dolda2000.com)
+ *  Copyright (C) 2007 Fredrik Tolf <fredrik@dolda2000.com>
  *  
  *  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
@@ -48,6 +48,8 @@ static bz_stream *bzs;
 static char *mybuf;
 static size_t mybufsize, mybufdata;
 
+#include "mainwnd.gtkh"
+
 void aborthublist(void)
 {
     if(mybuf != NULL) {
@@ -56,6 +58,7 @@ void aborthublist(void)
        mybufsize = mybufdata = 0;
     }
     if(hc != NULL) {
+       gtk_widget_hide(main_pubhubbarbox);
        if(itag != -1)
            gdk_input_remove(itag);
        if(otag != -1)
@@ -66,6 +69,7 @@ void aborthublist(void)
        if(bzs != NULL) {
            BZ2_bzDecompressEnd(bzs);
            free(bzs);
+           bzs = NULL;
        }
        if(filter != NULL) {
            regfree(filter);
@@ -121,9 +125,16 @@ static void fdcb(gpointer data, gint source, GdkInputCondition cond)
                return;
            }
            state = 1;
+           gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_pubhubbar), _("Getting list..."));
        }
     }
     if(state == 1) {
+       if(hc->tlen > 0) {
+           gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_pubhubbar), ((double)hc->rxd) / ((double)hc->tlen));
+       } else {
+           gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(main_pubhubbar), ((double)hc->databufdata) / 10000.0);
+           gtk_progress_bar_pulse(GTK_PROGRESS_BAR(main_pubhubbar));
+       }
        if(hc->databufdata > 0) {
            if(bzs == NULL) {
                bufcat(mybuf, hc->databuf, hc->databufdata);
@@ -137,7 +148,7 @@ static void fdcb(gpointer data, gint source, GdkInputCondition cond)
                    bzs->avail_out = mybufsize - mybufdata;
                    bzret = BZ2_bzDecompress(bzs);
                    if((bzret != BZ_OK) && (bzret != BZ_STREAM_END)) {
-                       msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not decompress hublist (%i)"), hret);
+                       msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not decompress hublist (%i)"), bzret);
                        aborthublist();
                        return;
                    }
@@ -155,6 +166,9 @@ static void fdcb(gpointer data, gint source, GdkInputCondition cond)
                memmove(mybuf, mybuf + hret, mybufdata -= hret);
        }
        if(ret) {
+           gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_pubhubbar), 1);
+           gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_pubhubbar), _("Finalizing list..."));
+           gdk_window_process_updates(main_pubhubbar->window, FALSE);
            handler(PHO_EOF, NULL, 0);
            aborthublist();
        }
@@ -182,12 +196,22 @@ void fetchhublist(char *url, regex_t *flt)
     u = parseurl(url);
     hc = htconnect(u);
     freeurl(u);
+    if(hc == NULL) {
+       msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not read hublist from server: %s"), strerror(errno));
+       return;
+    }
+    hc->autoredir = 1;
     state = 0;
     settags();
+    gtk_widget_show(main_pubhubbarbox);
+    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_pubhubbar), _("Connecting..."));
+    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_pubhubbar), 0);
+    gdk_window_process_updates(main_pubhubbarbox->window, TRUE);
 
     len = strlen(url);
     p = url + len;
     if((len > 4) && !strncmp(p - 4, ".bz2", 4)) {
+       /* Because using Transfer-Encoding would just be too good! */
        p -= 4;
        len -= 4;
        bzs = memset(smalloc(sizeof(*bzs)), 0, sizeof(*bzs));
@@ -200,6 +224,7 @@ void fetchhublist(char *url, regex_t *flt)
        }
     }
     if((len > 4) && !strncmp(p - 4, ".xml", 4)) {
+       /* Because using Content-Type would just be too good! */
        p -= 4;
        len -= 4;
        handler = pubhubxmlhandler;