X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=clients%2Fgtk2%2Fmain.c;h=d74e19206d93073f19aed2524a078dca8437809a;hb=a2f77326ce99e5eb08b90cee1ee9f14a50d0f181;hp=8aa487c99f2fd557ad0398db98dc7d8eb3786d11;hpb=cac656ef0444b50ab59b96b7f87d56f60bed6c2c;p=doldaconnect.git diff --git a/clients/gtk2/main.c b/clients/gtk2/main.c index 8aa487c..d74e192 100644 --- a/clients/gtk2/main.c +++ b/clients/gtk2/main.c @@ -21,10 +21,10 @@ * inability to structure GUI programs properly. Looking at it too * closely may cause ocular hemorrhaging. */ +#include #include #include #include -#include #include #include #include @@ -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; @@ -363,7 +363,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); @@ -374,7 +374,7 @@ 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) snprintf(buf, 64, "%'i", val); @@ -389,7 +389,7 @@ void transnicebytefunc2(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeMo long long 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)); @@ -403,7 +403,7 @@ void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *m 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); @@ -695,6 +695,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; @@ -1043,7 +1049,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); @@ -1067,16 +1073,20 @@ void handleresps(void) { if(!wcscmp(resp->cmdname, L".connect")) { - if(resp->code == 200) + if(resp->code != 201) { + 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 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(!wcscmp(resp->cmdname, L".notify")) { dc_uimisc_handlenotify(resp); @@ -1141,7 +1151,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); @@ -1361,7 +1371,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)); @@ -1428,7 +1438,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) { @@ -1460,7 +1470,7 @@ void setpubhubmodel(GtkTreeModel *model, int sortcol, int numcols, int *cols, ch 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, (gpointer)cols[i], NULL); + 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); } @@ -1514,6 +1524,11 @@ int pubhubxmlhandler(int op, char *buf, size_t *len) } 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) { @@ -1578,7 +1593,7 @@ int pubhubxmlhandler(int op, char *buf, size_t *len) } if(i == numcols) { - msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The hub list at %s did not contain the address to any hubs")); + 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); @@ -1853,7 +1868,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) @@ -1898,7 +1913,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) @@ -1959,7 +1974,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) @@ -2049,7 +2064,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) { @@ -2084,7 +2099,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); @@ -2107,7 +2122,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) @@ -2171,9 +2186,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); @@ -2305,7 +2320,7 @@ void cb_main_trcancel_activate(GtkWidget *widget, gpointer data) 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) @@ -2411,7 +2426,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) @@ -2574,8 +2589,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");