Properly process Gtk2 error-times as gint64s.
[doldaconnect.git] / clients / gtk2 / dolcon.c
index 5b286f3..a5adc12 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Dolda Connect - Modular multiuser Direct Connect-style client
- *  Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
+ *  Copyright (C) 2004 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
 #include <sys/time.h>
 #include <pwd.h>
 #include <locale.h>
-#include <libintl.h>
 #include <assert.h>
-
-/* "Programming with libxml2 is like the thrilling embrace of an
- * exotic strangler."
- *    --Me */
-#include <libxml/parser.h>
-#include <libxml/tree.h>
+#include <stdint.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
-#include "progressbar.h"
+#include "dolcon.h"
+#include "hublist.h"
 
 #define TRHISTSIZE 10
-#define PHO_INIT 0
-#define PHO_DATA 1
-#define PHO_EOF 2
-#define PHO_FINI 3
 
 struct trdata
 {
-    size_t poshist[TRHISTSIZE];
+    dc_lnum_t poshist[TRHISTSIZE];
     double timehist[TRHISTSIZE];
     int hc;
 };
@@ -74,7 +65,7 @@ struct fndata
 
 struct srchsize
 {
-    int size;
+    gint64 size;
     int num;
     int slots;
     double resptime;
@@ -90,15 +81,11 @@ struct knownspeed
 
 GtkWidget *inpdialog;
 GtkListStore *fnmodel, *ulmodel, *dlmodel, *reslist;
-int (*pubhubhandler)(int, char *, size_t *) = NULL;
 GtkTreeStore *srchmodel;
 GtkTreeModelFilter *srchmodelfilter;
 GtkTextTagTable *chattags;
 int dcfd = -1, gdkread = -1, gdkwrite = -1;
-int pubhubfd = -1, pubhubtag = -1, filterpubhub = 0;
 int curchat = -1;
-regex_t pubhubfilter;
-pid_t pubhubproc = 0;
 char *pubhubaddr = NULL;
 char *connectas = NULL;
 char *dcserver = NULL;
@@ -110,59 +97,13 @@ struct srchsize *srchsizes = NULL;
 struct knownspeed *knownspeeds = NULL;
 int numsizes = 0, numspeeds = 0, ksqueryseq = -1, ksquerytag = -1, lsrestag = -1;
 
-gboolean initdeath(GtkWidget *, gpointer);
-void cb_main_connmenu_activate(GtkWidget *widget, gpointer data);
-void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data);
-void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data);
-void cb_main_lsres_activate(GtkWidget *widget, gpointer data);
-void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data);
-void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data);
-void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data);
-void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data);
-void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data);
-void cb_main_phublist_cchange(GtkWidget *widget, gpointer data);
-void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
-void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
-void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
-void cb_main_chatstr_activate(GtkWidget *widget, gpointer data);
-void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data);
-void cb_main_realsrch_changed(GtkWidget *widget, gpointer data);
-void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data);
-void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data);
-gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data);
-void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data);
-void cb_main_srhash_activate(GtkWidget *widget, gpointer data);
-void cb_main_srcopy_activate(GtkWidget *widget, gpointer data);
-void cb_main_trhash_activate(GtkWidget *widget, gpointer data);
-void cb_main_trcopy_activate(GtkWidget *widget, gpointer data);
-void cb_main_trreset_activate(GtkWidget *widget, gpointer data);
-void cb_main_trcancel_activate(GtkWidget *widget, gpointer data);
-gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data);
-gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data);
-void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data);
-void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data);
-void cb_reslist_search_clicked(GtkWidget *widget, gpointer data);
-void cb_reslist_list_cchange(GtkWidget *widget, gpointer data);
-void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
-gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data);
 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition);
 void srchstatupdate(void);
-void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
-void transnicebytefunc2(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
-void transspeedinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
-void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
-void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
-void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
-void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
-
-#define DCCHARSET "windows-1252"
 
-#define _(text) gettext(text)
-
-#include "mainwnd.gtk"
-#include "inpdialog.gtk"
-#include "pref.gtk"
-#include "reslist.gtk"
+#include "mainwnd.gtkh"
+#include "inpdialog.gtkh"
+#include "pref.gtkh"
+#include "reslist.gtkh"
 
 void updatewrite(void)
 {
@@ -338,26 +279,40 @@ char *bytes2si(long long bytes)
 {
     int i;
     double b;
-    char *sd;
     static char ret[64];
+    static char pfx[] = {'k', 'M', 'G', 'T'};
     
     b = bytes;
-    for(i = 0; (b >= 1024) && (i < 4); i++)
+    for(i = 0; (b >= 1024) && (i < sizeof(pfx)); i++)
        b /= 1024;
     if(i == 0)
-       sd = "B";
-    else if(i == 1)
-       sd = "kiB";
-    else if(i == 2)
-       sd = "MiB";
-    else if(i == 3)
-       sd = "GiB";
+       snprintf(ret, 64, "%.1f B", b);
     else
-       sd = "TiB";
-    snprintf(ret, 64, "%.1f %s", b, sd);
+       snprintf(ret, 64, "%.1f %ciB", b, pfx[i - 1]);
     return(ret);
 }
 
+void progressfunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+    int totalc, curc;
+    gint64 total, cur;
+    char buf[64];
+    
+    totalc = (GPOINTER_TO_INT(data) & 0xff00) >> 8;
+    curc = GPOINTER_TO_INT(data) & 0xff;
+    gtk_tree_model_get(model, iter, totalc, &total, curc, &cur, -1);
+    if(total < 1)
+       g_object_set(rend, "value", GINT_TO_POINTER(0), NULL);
+    else
+       g_object_set(rend, "value", GINT_TO_POINTER((int)(((double)cur / (double)total) * 100)), NULL);
+    if(cur < 0) {
+       g_object_set(rend, "text", "", NULL);
+    } else {
+       snprintf(buf, 64, "%'ji", (intmax_t)cur);
+       g_object_set(rend, "text", buf, NULL);
+    }
+}
+
 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
     int colnum;
@@ -372,13 +327,14 @@ void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel
 
 void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
-    int colnum, val;
+    int colnum;
+    gint64 val;
     char buf[64];
     
     colnum = GPOINTER_TO_INT(data);
     gtk_tree_model_get(model, iter, colnum, &val, -1);
     if(val >= 0)
-       snprintf(buf, 64, "%'i", val);
+       snprintf(buf, 64, "%'ji", (intmax_t)val);
     else
        strcpy(buf, _("Unknown"));
     g_object_set(rend, "text", buf, NULL);
@@ -387,7 +343,7 @@ void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeMod
 void transnicebytefunc2(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
     int colnum;
-    long long val;
+    gint64 val;
     char buf[64];
     
     colnum = GPOINTER_TO_INT(data);
@@ -415,7 +371,8 @@ void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *m
 
 void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
-    int speed, size, time;
+    int speed, time;
+    gint64 size;
     char buf[64];
     
     gtk_tree_model_get(model, iter, 4, &size, 8, &speed, -1);
@@ -464,7 +421,7 @@ void transspeedinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel
 void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
     int error;
-    time_t errortime;
+    gint64 errortime;
     char finbuf[64], tbuf[64], *errstr;
     
     gtk_tree_model_get(model, iter, 10, &error, 11, &errortime, -1);
@@ -474,7 +431,7 @@ void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel
            errstr = _("Not found");
        else if(error == DC_TRNSE_NOSLOTS)
            errstr = _("No slots");
-       strftime(tbuf, 64, _("%H:%M:%S"), localtime(&errortime));
+       strftime(tbuf, 64, _("%H:%M:%S"), localtime((const time_t[]){errortime}));
        snprintf(finbuf, 64, _("%s (reported at %s)"), errstr, tbuf);
     } else {
        *finbuf = 0;
@@ -522,8 +479,8 @@ void updatetransferlists(void)
     int id;
     char *buf;
     char *peerid, *peernick, *path, *hash;
-    int state, dir, size, curpos, error;
-    time_t errortime;
+    int state, dir, error;
+    gint64 size, curpos, errortime;
     GtkListStore *stores[3];
     
     for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
@@ -555,10 +512,10 @@ void updatetransferlists(void)
                        if(state != transfer->state)
                            gtk_list_store_set(stores[i], &iter, 2, transfer->state, 8, gettrstatestock(transfer->state), -1);
                        if(size != transfer->size)
-                           gtk_list_store_set(stores[i], &iter, 6, transfer->size, -1);
+                           gtk_list_store_set(stores[i], &iter, 6, (gint64)transfer->size, -1);
                        if(curpos != transfer->curpos)
                        {
-                           gtk_list_store_set(stores[i], &iter, 7, transfer->curpos, -1);
+                           gtk_list_store_set(stores[i], &iter, 7, (gint64)transfer->curpos, -1);
                            if(transfer->udata != NULL)
                                updatetrdata(transfer);
                        }
@@ -607,12 +564,12 @@ void updatetransferlists(void)
                                   3, peerid,
                                   4, peernick,
                                   5, path,
-                                  6, transfer->size,
-                                  7, transfer->curpos,
+                                  6, (gint64)transfer->size,
+                                  7, (gint64)transfer->curpos,
                                   8, gettrstatestock(transfer->state),
                                   9, 0.0,
                                   10, transfer->error,
-                                  11, transfer->errortime,
+                                  11, (gint64)transfer->errortime,
                                   12, hash,
                                   -1);
                free(peerid);
@@ -696,12 +653,6 @@ char *inputbox(char *title, char *prompt, char *def, int echo)
 }
 
 int msgbox(int type, int buttons, char *format, ...)
-#if defined(__GNUC__)
-    __attribute__ ((format (printf, 3, 4)))
-#endif
-;
-
-int msgbox(int type, int buttons, char *format, ...)
 {
     GtkWidget *swnd;
     va_list args;
@@ -878,7 +829,7 @@ void logincallback(int err, wchar_t *reason, void *data)
     switch(err)
     {
     case DC_LOGIN_ERR_SUCCESS:
-       dc_queuecmd(NULL, NULL, L"notify", L"all", L"on", NULL);
+       dc_queuecmd(NULL, NULL, L"notify", L"all", L"on", L"fn:peer", L"off", NULL);
        dc_getfnlistasync(getfnlistcallback, NULL);
        dc_gettrlistasync(gettrlistcallback, NULL);
        updatesbar("Authenticated");
@@ -1053,6 +1004,7 @@ gint ksupdatecb(gpointer data)
        ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%a", users, NULL);
        dc_freewcsarr(users);
     }
+    updatewrite();
     return(TRUE);
 }
 
@@ -1175,13 +1127,13 @@ void handleresps(void)
                    {
                        for(i = 0; i < numsizes; i++)
                        {
-                           if(srchsizes[i].size == ires->argv[4].val.num)
+                           if(srchsizes[i].size == ires->argv[4].val.lnum)
                                break;
                        }
                        if(i == numsizes)
                        {
                            srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
-                           srchsizes[i].size = ires->argv[4].val.num;
+                           srchsizes[i].size = (gint64)ires->argv[4].val.lnum;
                            srchsizes[i].num = 1;
                            srchsizes[i].slots = ires->argv[5].val.num;
                            srchsizes[i].resptime = ires->argv[7].val.flnum;
@@ -1213,9 +1165,8 @@ void handleresps(void)
                            if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
                            {
                                p = buf;
-                               /* XXX: Too NMDC-specific! */
-                               if(strrchr(p, '\\') != NULL)
-                                   p = strrchr(p, '\\') + 1;
+                               if(strrchr(p, '/') != NULL)
+                                   p = strrchr(p, '/') + 1;
                                gtk_tree_store_set(srchmodel, &piter, 3, p, -1);
                                free(buf);
                            }
@@ -1253,7 +1204,7 @@ void handleresps(void)
                            gtk_tree_store_set(srchmodel, &titer, 9, buf, -1);
                            free(buf);
                        }
-                       gtk_tree_store_set(srchmodel, &titer, 4, ires->argv[4].val.num, 5, ires->argv[5].val.num, 6, ires->argv[7].val.flnum, 8, -1, -1);
+                       gtk_tree_store_set(srchmodel, &titer, 4, (gint64)ires->argv[4].val.lnum, 5, ires->argv[5].val.num, 6, ires->argv[7].val.flnum, 8, -1, -1);
                    }
                    dc_freeires(ires);
                }
@@ -1281,9 +1232,9 @@ void handleresps(void)
                        gtk_list_store_append(reslist, &titer);
                        gtk_list_store_set(reslist, &titer, 0, icswcstombs(resp->rlines[i].argv[1] + 3, "UTF-8", NULL), -1);
                    } else if(!wcsncmp(resp->rlines[i].argv[1], L"size:", 5)) {
-                       gtk_list_store_set(reslist, &titer, 1, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
+                       gtk_list_store_set(reslist, &titer, 1, (gint64)wcstoll(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
                    } else if(!wcsncmp(resp->rlines[i].argv[1], L"prog:", 5)) {
-                       gtk_list_store_set(reslist, &titer, 2, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
+                       gtk_list_store_set(reslist, &titer, 2, (gint64)wcstoll(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
                    } else if(!wcsncmp(resp->rlines[i].argv[1], L"name:", 5)) {
                        gtk_list_store_set(reslist, &titer, 3, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
                    } else if(!wcsncmp(resp->rlines[i].argv[1], L"lock:", 5)) {
@@ -1368,6 +1319,7 @@ void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
        lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
        gtk_widget_set_sensitive(reslist_reload, FALSE);
     }
+    updatewrite();
 }
 
 void dcconnect(char *host)
@@ -1485,371 +1437,34 @@ void setpubhubmodel(GtkTreeModel *model, int sortcol, int numcols, int *cols, ch
     g_object_unref(sortmodel);
 }
 
-xmlNodePtr findnode(xmlNodePtr node, char *name)
-{
-    for(; node != NULL; node = node->next)
-    {
-       if(!strcmp((char *)node->name, name))
-           break;
-    }
-    return(node);
-}
-
-int pubhubxmlhandler(int op, char *buf, size_t *len)
-{
-    static xmlParserCtxtPtr ctxt = NULL;
-    int i, match;
-    xmlNodePtr dr, r, cr, c, n;
-    int numcols, *cols, sortcol;
-    GType type, *types;
-    char **names, *name, *stype, *attr;
-    GtkListStore *model;
-    GtkTreeIter iter;
-    
-    numcols = 0;
-    names = NULL;
-    types = NULL;
-    switch(op)
-    {
-    case PHO_INIT:
-       break;
-    case PHO_DATA:
-       if(ctxt == NULL) {
-           ctxt = xmlCreatePushParserCtxt(NULL, NULL, buf, *len, pubhubaddr);
-           *len = 0;
-           if(ctxt == NULL)
-               return(1);
-       } else {
-           xmlParseChunk(ctxt, buf, *len, 0);
-           *len = 0;
-       }
-       break;
-    case PHO_EOF:
-       if(ctxt == NULL)
-       {
-           msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("A hub list could not be read from %s"), pubhubaddr);
-           break;
-       }
-       xmlParseChunk(ctxt, NULL, 0, 1);
-       if(!ctxt->wellFormed)
-       {
-           msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The hub list at %s is not valid"), pubhubaddr);
-           break;
-       }
-       dr = r = cr = NULL;
-       dr = xmlDocGetRootElement(ctxt->myDoc);
-       if(dr != NULL)
-           r = findnode(dr->children, "Hubs");
-       if(r != NULL)
-           cr = findnode(r->children, "Columns");
-       if(cr == NULL)
-       {
-           msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The hub list at %s cannot be understood"), pubhubaddr);
-           break;
-       }
-       for(c = findnode(cr->children, "Column"); c != NULL; c = findnode(c->next, "Column"))
-       {
-           name = (char *)xmlGetProp(c, (xmlChar *)"Name");
-           stype = (char *)xmlGetProp(c, (xmlChar *)"Type");
-           type = G_TYPE_INVALID;
-           if(stype != NULL)
-           {
-               if(!strcmp(stype, "string"))
-                   type = G_TYPE_STRING;
-               else if(!strcmp(stype, "int"))
-                   type = G_TYPE_INT;
-               else if(!strcmp(stype, "bytes"))
-                   type = G_TYPE_INT64;
-           }
-           if((name != NULL) && (type != G_TYPE_INVALID))
-           {
-               names = srealloc(names, (numcols + 1) * sizeof(*names));
-               types = srealloc(types, (numcols + 1) * sizeof(*names));
-               names[numcols] = sstrdup(name);
-               types[numcols] = type;
-               numcols++;
-           }
-           if(name != NULL)
-               xmlFree(name);
-           if(stype != NULL)
-               xmlFree(stype);
-       }
-       if(numcols == 0)
-       {
-           msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The hub list at %s did not contain any columns"), pubhubaddr);
-           break;
-       }
-       for(i = 0; i < numcols; i++)
-       {
-           if(!strcmp(names[i], "Address"))
-           {
-               name = names[0];
-               names[0] = names[i];
-               names[i] = name;
-               type = types[0];
-               types[0] = types[i];
-               types[i] = type;
-               break;
-           }
-       }
-       if(i == numcols)
-       {
-           msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The hub list at %s did not contain the address to any hubs"), pubhubaddr);
-           break;
-       }
-       model = gtk_list_store_newv(numcols, types);
-       for(n = findnode(r->children, "Hub"); n != NULL; n = findnode(n->next, "Hub"))
-       {
-           if(!xmlHasProp(n, (xmlChar *)"Address") || !xmlHasProp(n, (xmlChar *)"Name"))
-               continue;
-           if(filterpubhub)
-           {
-               match = 0;
-               attr = (char *)xmlGetProp(n, (xmlChar *)"Name");
-               if(!regexec(&pubhubfilter, attr, 0, NULL, 0))
-                   match = 1;
-               xmlFree(attr);
-               if((attr = (char *)xmlGetProp(n, (xmlChar *)"Description")) != NULL)
-               {
-                   if(!regexec(&pubhubfilter, attr, 0, NULL, 0))
-                       match = 1;
-                   xmlFree(attr);
-               }
-               if(!match)
-                   continue;
-           }
-           gtk_list_store_append(model, &iter);
-           for(i = 0; i < numcols; i++)
-           {
-               attr = (char *)xmlGetProp(n, (xmlChar *)names[i]);
-               if(attr != NULL)
-               {
-                   if(types[i] == G_TYPE_STRING)
-                       gtk_list_store_set(model, &iter, i, attr, -1);
-                   else if(types[i] == G_TYPE_INT)
-                       gtk_list_store_set(model, &iter, i, atoi(attr), -1);
-                   else if(types[i] == G_TYPE_INT64)
-                       gtk_list_store_set(model, &iter, i, strtoll(attr, NULL, 0), -1);
-                   xmlFree(attr);
-               }
-           }
-       }
-       cols = smalloc((numcols - 1) * sizeof(*cols));
-       for(i = 1; i < numcols; i++)
-           cols[i - 1] = i;
-       sortcol = 0;
-       for(i = 0; i < numcols; i++)
-       {
-           if(!strcmp(names[i], "Users"))
-               sortcol = i;
-       }
-       setpubhubmodel(GTK_TREE_MODEL(model), sortcol, numcols - 1, cols, names + 1);
-       free(cols);
-       g_object_unref(model);
-       break;
-    case PHO_FINI:
-       if(ctxt != NULL)
-       {
-           if(ctxt->myDoc != NULL)
-               xmlFreeDoc(ctxt->myDoc);
-           xmlFreeParserCtxt(ctxt);
-           ctxt = NULL;
-       }
-       break;
-    }
-    if(numcols != 0)
-    {
-       for(i = 0; i < numcols; i++)
-           free(names[i]);
-       free(names);
-       free(types);
-    }
-    return(0);
-}
-
-int pubhuboldhandler(int op, char *buf, size_t *len)
-{
-    static GtkListStore *model = NULL;
-    int i;
-    char *p, *p2;
-    wchar_t *wbuf;
-    char *fields[4], *names[3];
-    int cols[3];
-    GtkTreeIter iter;
-    
-    switch(op)
-    {
-    case PHO_INIT:
-       model = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
-       break;
-    case PHO_DATA:
-       while((p = memchr(buf, '\n', *len)) != NULL)
-       {
-           *(p++) = 0;
-           for(i = 0, p2 = buf; i < 4; i++) {
-               fields[i] = p2;
-               if((p2 = strchr(p2, '|')) == NULL)
-                   break;
-               *(p2++) = 0;
-           }
-           if(i == 4) {
-               for(i = 0; i < 4; i++) {
-                   if((wbuf = icsmbstowcs(fields[i], DCCHARSET, NULL)) == NULL) {
-                       fields[i] = sstrdup(_("(Invalid character)"));
-                   } else {
-                       if((fields[i] = icwcstombs(wbuf, "UTF-8")) == NULL)
-                           break;
-                   }
-               }
-               if(i == 4) {
-                   if(!filterpubhub || !regexec(&pubhubfilter, fields[0], 0, NULL, 0) || !regexec(&pubhubfilter, fields[2], 0, NULL, 0)) {
-                       gtk_list_store_append(model, &iter);
-                       gtk_list_store_set(model, &iter, 0, fields[1], 1, fields[0], 2, fields[2], 3, atoi(fields[3]), -1);
-                   }
-               }
-               for(i--; i >= 0; i--)
-                   free(fields[i]);
-           }
-           memmove(buf, p, *len -= p - buf);
-       }
-       break;
-    case PHO_EOF:
-       cols[0] = 3; names[0] = _("# users");
-       cols[1] = 1; names[1] = _("Name");
-       cols[2] = 2; names[2] = _("Description");
-       setpubhubmodel(GTK_TREE_MODEL(model), 3, 3, cols, names);
-       break;
-    case PHO_FINI:
-       if(model != NULL)
-           g_object_unref(model);
-       model = NULL;
-       break;
-    }
-    return(0);
-}
-
-void pubhubfdcallback(gpointer data, gint source, GdkInputCondition condition)
-{
-    static char buf[65536];
-    static size_t bufpos = 0;
-    int ret, reset;
-    
-    if(!(condition & GDK_INPUT_READ))
-       return;
-    if(bufpos == sizeof(buf))
-       bufpos = 0;
-    ret = read(pubhubfd, buf + bufpos, sizeof(buf) - bufpos);
-    reset = 0;
-    if(ret <= 0)
-    {
-       if(ret < 0)
-           msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not read from public hub listing process: %s"), strerror(errno));
-       else
-           pubhubhandler(PHO_EOF, NULL, NULL);
-       reset = 1;
-    } else {
-       bufpos += ret;
-       if(pubhubhandler(PHO_DATA, buf, &bufpos))
-           reset = 1;
-    }
-    if(reset)
-    {
-       pubhubhandler(PHO_FINI, NULL, NULL);
-       pubhubhandler = NULL;
-       gdk_input_remove(pubhubtag);
-       close(pubhubfd);
-       kill(pubhubproc, SIGINT);
-       pubhubfd = pubhubtag = -1;
-       pubhubproc = 0;
-       bufpos = 0;
-       if(filterpubhub)
-       {
-           regfree(&pubhubfilter);
-           filterpubhub = 0;
-       }
-    }
-}
-
 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
 {
-    int pipe1[2], pipe2[2];
-    int len, err;
-    const char *buf, *p;
+    int err;
+    const char *buf;
     char errbuf[1024];
+    regex_t *filter;
     
-    if(pubhubtag >= 0)
-       gdk_input_remove(pubhubtag);
-    if(pubhubfd >= 0)
-       close(pubhubfd);
-    if(pubhubproc > 0)
-       kill(pubhubproc, SIGINT);
-    if(pubhubhandler != NULL)
-    {
-       pubhubhandler(PHO_FINI, NULL, NULL);
-       pubhubhandler = NULL;
-    }
-    if(filterpubhub)
-    {
-       regfree(&pubhubfilter);
-       filterpubhub = 0;
-    }
     buf = gtk_entry_get_text(GTK_ENTRY(main_pubhubfilter));
     if(*buf)
     {
-       if((err = regcomp(&pubhubfilter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
+       filter = smalloc(sizeof(*filter));
+       if((err = regcomp(filter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
        {
-           regerror(err, &pubhubfilter, errbuf, sizeof(errbuf));
+           regerror(err, filter, errbuf, sizeof(errbuf));
            msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not compile regex: %s", errbuf);
-           regfree(&pubhubfilter);
-           filterpubhub = 0;
+           regfree(filter);
+           free(filter);
            return;
        }
-       filterpubhub = 1;
-    }
-    pipe(pipe1);
-    if((pubhubproc = fork()) == 0)
-    {
-       dup2(pipe1[1], 1);
-       close(pipe1[0]);
-       close(pipe1[1]);
-       execlp("wget", "wget", "-qO", "-", pubhubaddr, NULL);
-       perror("wget");
-       exit(127);
-    }
-    close(pipe1[1]);
-    pubhubfd = pipe1[0];
-    len = strlen(pubhubaddr);
-    p = pubhubaddr + len;
-    if((len > 4) && !strncmp(p - 4, ".bz2", 4))
-    {
-       p -= 4;
-       len -= 4;
-       pipe(pipe2);
-       if(fork() == 0)
-       {
-           dup2(pipe1[0], 0);
-           dup2(pipe2[1], 1);
-           close(pipe1[0]);
-           close(pipe2[0]);
-           close(pipe2[1]);
-           execlp("bzcat", "bzcat", NULL);
-           perror("bzcat");
-           exit(127);
-       }
-       close(pipe1[0]);
-       close(pipe2[1]);
-       pubhubfd = pipe2[0];
-    }
-    if((len > 4) && !strncmp(p - 4, ".xml", 4))
-    {
-       p -= 4;
-       len -= 4;
-       pubhubhandler = pubhubxmlhandler;
     } else {
-       pubhubhandler = pubhuboldhandler;
+       filter = NULL;
     }
-    pubhubhandler(PHO_INIT, NULL, NULL);
-    pubhubtag = gdk_input_add(pubhubfd, GDK_INPUT_READ, pubhubfdcallback, NULL);
+    fetchhublist(pubhubaddr, filter);
+}
+
+void cb_main_pubhubabort_clicked(GtkWidget *widget, gpointer data)
+{
+    aborthublist();
 }
 
 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
@@ -2145,7 +1760,8 @@ void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewC
     struct dc_response *resp;
     GtkTreeIter iter;
     GtkTreeModel *model;
-    int size, num;
+    int num;
+    gint64 size;
     char *tfnet, *tpeerid, *tfilename, *thash, *arg;
     wchar_t *fnet, *peerid, *filename, *hash;
     
@@ -2187,9 +1803,9 @@ void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewC
     g_free(tfilename);
     arg = (char *)gtk_entry_get_text(GTK_ENTRY(main_dlarg));
     if(*arg)
-       tag = dc_queuecmd(NULL, NULL, L"download", fnet, L"%ls", peerid, L"%ls", filename, L"%i", size, L"hash", L"%ls", (hash == NULL)?L"":hash, L"user", L"%s", arg, NULL);
+       tag = dc_queuecmd(NULL, NULL, L"download", fnet, L"%ls", peerid, L"%ls", filename, L"%li", (dc_lnum_t)size, L"hash", L"%ls", (hash == NULL)?L"":hash, L"user", L"%s", arg, NULL);
     else
-       tag = dc_queuecmd(NULL, NULL, L"download", fnet, L"%ls", peerid, L"%ls", filename, L"%i", size, L"hash", L"%ls", (hash == NULL)?L"":hash, NULL);
+       tag = dc_queuecmd(NULL, NULL, L"download", fnet, L"%ls", peerid, L"%ls", filename, L"%li", (dc_lnum_t)size, L"hash", L"%ls", (hash == NULL)?L"":hash, NULL);
     free(fnet);
     free(peerid);
     free(filename);
@@ -2444,6 +2060,7 @@ void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data)
     gtk_list_store_clear(reslist);
     lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
     gtk_widget_set_sensitive(reslist_reload, FALSE);
+    updatewrite();
 }
 
 int rmres(char *id)
@@ -2602,8 +2219,11 @@ void initchattags(void)
     gtk_text_tag_table_add(chattags, tag);
 }
 
+#include "../dolda-icon.xpm"
+
 int main(int argc, char **argv)
 {
+    int c, connlocal;
     GtkWidget *wnd;
     PangoFontDescription *monospacefont;
     GtkTreeModel *sortmodel;
@@ -2613,9 +2233,29 @@ int main(int argc, char **argv)
     bindtextdomain(PACKAGE, LOCALEDIR);
     textdomain(PACKAGE);
     gtk_init(&argc, &argv);
+    connlocal = 0;
+    while((c = getopt(argc, argv, "lhV")) != -1) {
+       switch(c) {
+       case 'l':
+           connlocal = 1;
+           break;
+       case 'h':
+           printf("usage: dolcon [-hlV]\n");
+           printf("\t-h\tDisplay this help message\n");
+           printf("\t-l\tConnect to the locally running daemon\n");
+           printf("\t-V\tDisplay version info and exit\n");
+           exit(0);
+       case 'V':
+           printf("%s", RELEASEINFO);
+           exit(0);
+       default:
+           fprintf(stderr, "usage: dolcon [-hlV]\n");
+           exit(1);
+       }
+    }
     dc_init();
     signal(SIGCHLD, SIG_IGN);
-    pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.xml.bz2");
+    pubhubaddr = sstrdup("http://dchublist.com/hublist.xml.bz2");
     dcserver = sstrdup("");
     if((pwent = getpwuid(getuid())) == NULL)
     {
@@ -2623,6 +2263,7 @@ int main(int argc, char **argv)
        exit(1);
     }
     connectas = sstrdup(pwent->pw_name);
+    gtk_window_set_default_icon(gdk_pixbuf_new_from_xpm_data((const char **)dolda_icon_xpm));
     wnd = create_main_wnd();
     create_reslist_wnd();
     gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400);
@@ -2632,7 +2273,7 @@ int main(int argc, char **argv)
     gtk_tree_view_set_model(GTK_TREE_VIEW(main_fnetnodes), GTK_TREE_MODEL(fnmodel));
     gtk_tree_view_set_model(GTK_TREE_VIEW(main_chatnodes), GTK_TREE_MODEL(fnmodel));
     
-    reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
+    reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
     gtk_tree_view_set_model(GTK_TREE_VIEW(reslist_list), GTK_TREE_MODEL(reslist));
     
     dlmodel = gtk_list_store_new(13, G_TYPE_INT, /* id */
@@ -2641,23 +2282,23 @@ int main(int argc, char **argv)
                                 G_TYPE_STRING,  /* peerid */
                                 G_TYPE_STRING,  /* peernick */
                                 G_TYPE_STRING,  /* path */
-                                G_TYPE_INT,     /* size */
-                                G_TYPE_INT,     /* curpos */
+                                G_TYPE_INT64,   /* size */
+                                G_TYPE_INT64,   /* curpos */
                                 G_TYPE_STRING,  /* stock */
                                 G_TYPE_FLOAT,   /* percentage */
                                 G_TYPE_INT,     /* error */
-                                G_TYPE_INT,     /* errortime */
+                                G_TYPE_INT64,   /* errortime */
                                 G_TYPE_STRING); /* hash */
     gtk_tree_view_set_model(GTK_TREE_VIEW(main_downloads), GTK_TREE_MODEL(dlmodel));
 
-    ulmodel = gtk_list_store_new(13, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_FLOAT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
+    ulmodel = gtk_list_store_new(13, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64, G_TYPE_STRING, G_TYPE_FLOAT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
     gtk_tree_view_set_model(GTK_TREE_VIEW(main_uploads), GTK_TREE_MODEL(ulmodel));
 
     srchmodel = gtk_tree_store_new(10, G_TYPE_STRING, /* fnetname */
                                   G_TYPE_STRING,     /* peerid */
                                   G_TYPE_STRING,     /* peername */
                                   G_TYPE_STRING,     /* filename */
-                                  G_TYPE_INT,        /* size */
+                                  G_TYPE_INT64,      /* size */
                                   G_TYPE_INT,        /* slots */
                                   G_TYPE_DOUBLE,     /* resptime */
                                   G_TYPE_INT,        /* sizenum */
@@ -2676,7 +2317,9 @@ int main(int argc, char **argv)
     readconfigfile();
     updatesbar(_("Disconnected"));
     gtk_widget_show(wnd);
-    if(autoconn)
+    if(connlocal)
+       dcconnect(dc_srv_local);
+    else if(autoconn)
        dcconnect(dcserver);
     g_timeout_add(500, srchstatupdatecb, NULL);
     g_timeout_add(5000, ksupdatecb, NULL);
@@ -2684,3 +2327,8 @@ int main(int argc, char **argv)
     gtk_main();
     return(0);
 }
+
+#include "mainwnd.gtk"
+#include "inpdialog.gtk"
+#include "pref.gtk"
+#include "reslist.gtk"