Fix erroneous comment.
[doldaconnect.git] / clients / gtk2 / main.c
index 6a2a0c0..a0f44f3 100644 (file)
  * inability to structure GUI programs properly. Looking at it too
  * closely may cause ocular hemorrhaging. */
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
-#include <malloc.h>
 #include <stdarg.h>
 #include <gtk/gtk.h>
 #include <sys/socket.h>
@@ -102,7 +102,7 @@ pid_t pubhubproc = 0;
 char *pubhubaddr = NULL;
 char *connectas = NULL;
 char *dcserver = NULL;
-int autoconn = 0;
+int autoconn = 1;
 int srchautoupdate = 0;
 int cursrch = -1, nextsrch = -1;
 time_t srcheta;
@@ -135,6 +135,7 @@ 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);
@@ -147,6 +148,7 @@ gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointe
 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);
@@ -332,7 +334,7 @@ void updatehublist(void)
     }
 }
 
-char *bytes2si(int bytes)
+char *bytes2si(long long bytes)
 {
     int i;
     double b;
@@ -340,7 +342,7 @@ char *bytes2si(int bytes)
     static char ret[64];
     
     b = bytes;
-    for(i = 0; (b > 1024) && (i < 4); i++)
+    for(i = 0; (b >= 1024) && (i < 4); i++)
        b /= 1024;
     if(i == 0)
        sd = "B";
@@ -362,7 +364,7 @@ void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel
     float val;
     char buf[64];
     
-    colnum = (int)data;
+    colnum = GPOINTER_TO_INT(data);
     gtk_tree_model_get(model, iter, colnum, &val, -1);
     snprintf(buf, 64, "%.2f%%", (double)(val * 100.0));
     g_object_set(rend, "text", buf, NULL);
@@ -373,12 +375,8 @@ void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeMod
     int colnum, val;
     char buf[64];
     
-    colnum = (int)data;
+    colnum = GPOINTER_TO_INT(data);
     gtk_tree_model_get(model, iter, colnum, &val, -1);
-/*
-    if(val >= 0)
-       strcpy(buf, bytes2si(val));
-*/
     if(val >= 0)
        snprintf(buf, 64, "%'i", val);
     else
@@ -386,12 +384,27 @@ void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeMod
     g_object_set(rend, "text", buf, NULL);
 }
 
+void transnicebytefunc2(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+    int colnum;
+    long long val;
+    char buf[64];
+    
+    colnum = GPOINTER_TO_INT(data);
+    gtk_tree_model_get(model, iter, colnum, &val, -1);
+    if(val >= 0)
+       strcpy(buf, bytes2si(val));
+    else
+       strcpy(buf, _("Unknown"));
+    g_object_set(rend, "text", buf, NULL);
+}
+
 void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
     int colnum, val;
     char buf[64];
     
-    colnum = (int)data;
+    colnum = GPOINTER_TO_INT(data);
     gtk_tree_model_get(model, iter, colnum, &val, -1);
     if(val > 0)
        snprintf(buf, 64, "%i", val);
@@ -683,6 +696,12 @@ 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;
@@ -1031,7 +1050,7 @@ gint ksupdatecb(gpointer data)
            }
        }
        addtobuf(users, NULL);
-       ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%%a", users, NULL);
+       ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%a", users, NULL);
        dc_freewcsarr(users);
     }
     return(TRUE);
@@ -1055,16 +1074,20 @@ void handleresps(void)
     {
        if(!wcscmp(resp->cmdname, L".connect"))
        {
-           if(resp->code == 200)
+           if(resp->code != 201)
            {
-               tosbuf = 0x10; /* Minimum cost */
-               setsockopt(dcfd, SOL_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
-               updatesbar(_("Connected"));
-               dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
-           } else {
                msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server refused the connection"));
                dc_disconnect();
                dcdisconnected();
+           } else if(dc_checkprotocol(resp, DC_LATEST)) {
+               msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Server protocol revision mismatch"));
+               dc_disconnect();
+               dcdisconnected();
+           } else {
+               tosbuf = 0x10; /* Minimum delay */
+               setsockopt(dcfd, SOL_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
+               updatesbar(_("Connected"));
+               dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
            }
        } else if(!wcscmp(resp->cmdname, L".notify")) {
            dc_uimisc_handlenotify(resp);
@@ -1129,7 +1152,7 @@ void handleresps(void)
                    if(ires->argv[0].val.num == nextsrch)
                    {
                        if(cursrch != -1)
-                           dc_queuecmd(NULL, NULL, L"cansrch", L"%%i", cursrch, NULL);
+                           dc_queuecmd(NULL, NULL, L"cansrch", L"%i", cursrch, NULL);
                        cursrch = nextsrch;
                        nextsrch = -1;
                        gtk_widget_set_sensitive(main_realsrch, TRUE);
@@ -1349,7 +1372,7 @@ void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
 
 void dcconnect(char *host)
 {
-    dcfd = dc_connect(host, -1);
+    dcfd = dc_connect(host);
     if(dcfd < 0)
     {
        msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect:\n\n%s"), strerror(errno));
@@ -1416,7 +1439,7 @@ void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
        toks[0] = srealloc(toks[0], (wcslen(toks[0]) + 5) * sizeof(wchar_t));
        wcscat(toks[0], L":411");
     }
-    tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%%a", toks, NULL);
+    tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%a", toks, NULL);
     dc_freewcsarr(toks);
     if((resp = dc_gettaggedrespsync(tag)) != NULL)
     {
@@ -1432,36 +1455,226 @@ void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
     handleresps();
 }
 
-void setpubhubmodel(GtkTreeModel *model, int sortcol, ...)
+void setpubhubmodel(GtkTreeModel *model, int sortcol, int numcols, int *cols, char **names)
 {
-    va_list args;
     GtkTreeViewColumn *col;
+    GtkCellRenderer *rnd;
     GtkTreeModel *sortmodel;
-    int f;
+    int i;
     
     while((col = gtk_tree_view_get_column(GTK_TREE_VIEW(main_phublist), 0)) != NULL)
        gtk_tree_view_remove_column(GTK_TREE_VIEW(main_phublist), col);
-    va_start(args, sortcol);
-    while((f = va_arg(args, int)) != -1) {
-       col = gtk_tree_view_column_new_with_attributes(va_arg(args, char *), gtk_cell_renderer_text_new(), "text", f, NULL);
-       gtk_tree_view_column_set_sort_column_id(col, f);
+    for(i = 0; i < numcols; i++) {
+       if(gtk_tree_model_get_column_type(model, cols[i]) == G_TYPE_INT64)
+       {
+           col = gtk_tree_view_column_new();
+           gtk_tree_view_column_set_title(col, names[i]);
+           rnd = gtk_cell_renderer_text_new();
+           gtk_tree_view_column_pack_start(col, rnd, TRUE);
+           gtk_tree_view_column_set_cell_data_func(col, rnd, transnicebytefunc2, GINT_TO_POINTER(cols[i]), NULL);
+       } else {
+           col = gtk_tree_view_column_new_with_attributes(names[i], gtk_cell_renderer_text_new(), "text", cols[i], NULL);
+       }
+       gtk_tree_view_column_set_sort_column_id(col, cols[i]);
        gtk_tree_view_column_set_resizable(col, TRUE);
        gtk_tree_view_append_column(GTK_TREE_VIEW(main_phublist), col);
     }
-    va_end(args);
     sortmodel = gtk_tree_model_sort_new_with_model(model);
     gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), sortcol, GTK_SORT_DESCENDING);
     gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), sortmodel);
     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];
+    char *fields[4], *names[3];
+    int cols[3];
     GtkTreeIter iter;
     
     switch(op)
@@ -1501,7 +1714,10 @@ int pubhuboldhandler(int op, char *buf, size_t *len)
        }
        break;
     case PHO_EOF:
-       setpubhubmodel(GTK_TREE_MODEL(model), 3, 3, _("# users"), 1, _("Name"), 2, _("Description"), -1);
+       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)
@@ -1529,7 +1745,7 @@ void pubhubfdcallback(gpointer data, gint source, GdkInputCondition condition)
        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, buf, &bufpos);
+           pubhubhandler(PHO_EOF, NULL, NULL);
        reset = 1;
     } else {
        bufpos += ret;
@@ -1628,6 +1844,7 @@ void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
     {
        p -= 4;
        len -= 4;
+       pubhubhandler = pubhubxmlhandler;
     } else {
        pubhubhandler = pubhuboldhandler;
     }
@@ -1652,7 +1869,7 @@ void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
        return;
     }
     gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
-    tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%%i", id, NULL);
+    tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%i", id, NULL);
     if((resp = dc_gettaggedrespsync(tag)) != NULL)
     {
        if(resp->code == 502)
@@ -1697,7 +1914,7 @@ void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeView
        buf = g_realloc(buf, strlen(buf) + 5);
        strcat(buf, ":411");
     }
-    tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%%s", buf, NULL);
+    tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%s", buf, NULL);
     g_free(buf);
     gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
     if((resp = dc_gettaggedrespsync(tag)) != NULL)
@@ -1758,7 +1975,7 @@ void cb_main_chatstr_activate(GtkWidget *widget, gpointer data)
        return;
     }
     buf = gtk_entry_get_text(GTK_ENTRY(main_chatstr));
-    tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%%i", curchat, L"1", L"", L"%%s", buf, NULL);
+    tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%i", curchat, L"1", L"", L"%s", buf, NULL);
     if((resp = dc_gettaggedrespsync(tag)) != NULL)
     {
        if(resp->code == 502)
@@ -1848,7 +2065,7 @@ void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data)
        msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Please enter a search expression before searching"));
        return;
     }
-    tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%%a", toks, NULL);
+    tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%a", toks, NULL);
     dc_freewcsarr(toks);
     if((resp = dc_gettaggedrespsync(tag)) != NULL)
     {
@@ -1883,7 +2100,7 @@ void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data)
 {
     if(nextsrch == -1)
        return;
-    dc_queuecmd(NULL, NULL, L"cansrch", L"%%i", nextsrch, NULL);
+    dc_queuecmd(NULL, NULL, L"cansrch", L"%i", nextsrch, NULL);
     nextsrch = -1;
     gtk_widget_set_sensitive(main_realsrch, TRUE);
     gtk_widget_set_sensitive(main_simplesrch, TRUE);
@@ -1906,7 +2123,7 @@ gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer
        if(gtk_tree_selection_get_selected(sel, &model, &iter))
        {
            gtk_tree_model_get(model, &iter, 0, &id, -1);
-           tag = dc_queuecmd(NULL, NULL, L"cancel", L"%%i", id, NULL);
+           tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
            if((resp = dc_gettaggedrespsync(tag)) != NULL)
            {
                if(resp->code == 502)
@@ -1970,9 +2187,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"%i", 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"%i", size, L"hash", L"%ls", (hash == NULL)?L"":hash, NULL);
     free(fnet);
     free(peerid);
     free(filename);
@@ -2090,7 +2307,7 @@ void cb_main_trcopy_activate(GtkWidget *widget, gpointer data)
     g_free(hash);
 }
 
-void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
+void cb_main_trreset_activate(GtkWidget *widget, gpointer data)
 {
     GtkTreeSelection *sel;
     GtkTreeModel *model;
@@ -2098,13 +2315,38 @@ void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
     int id, tag;
     struct dc_response *resp;
     
-    if(nextsrch != -1)
+    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
+    if(gtk_tree_selection_get_selected(sel, &model, &iter))
+    {
+       gtk_tree_model_get(model, &iter, 0, &id, -1);
+       tag = dc_queuecmd(NULL, NULL, L"reset", L"%i", id, NULL);
+       if((resp = dc_gettaggedrespsync(tag)) != NULL)
+       {
+           if(resp->code == 502)
+               msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
+           else if(resp->code != 200)
+               msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to reset (%i)"), resp->code);
+           dc_freeresp(resp);
+       }
+       handleresps();
+    } else {
        return;
+    }
+}
+
+void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
+{
+    GtkTreeSelection *sel;
+    GtkTreeModel *model;
+    GtkTreeIter iter;
+    int id, tag;
+    struct dc_response *resp;
+    
     sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
     if(gtk_tree_selection_get_selected(sel, &model, &iter))
     {
        gtk_tree_model_get(model, &iter, 0, &id, -1);
-       tag = dc_queuecmd(NULL, NULL, L"cancel", L"%%i", id, NULL);
+       tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
        if((resp = dc_gettaggedrespsync(tag)) != NULL)
        {
            if(resp->code == 502)
@@ -2210,7 +2452,7 @@ int rmres(char *id)
     struct dc_response *resp;
     
     ret = -1;
-    tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%%s", id, NULL);
+    tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%s", id, NULL);
     if((resp = dc_gettaggedrespsync(tag)) != NULL)
     {
        if(resp->numlines > 0)
@@ -2373,8 +2615,8 @@ int main(int argc, char **argv)
     gtk_init(&argc, &argv);
     dc_init();
     signal(SIGCHLD, SIG_IGN);
-    pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.config.bz2");
-    dcserver = sstrdup("localhost");
+    pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.xml.bz2");
+    dcserver = sstrdup("");
     if((pwent = getpwuid(getuid())) == NULL)
     {
        fprintf(stderr, "could not get your passwd data");