2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <doldaconnect/uilib.h>
30 #include <doldaconnect/uimisc.h>
31 #include <doldaconnect/utils.h>
44 #include "progressbar.h"
49 GtkTextBuffer *textbuf;
58 GtkTreeRowReference *ref;
69 GtkListStore *fnmodel, *ulmodel, *dlmodel, *pubhubmodel, *reslist;
70 GtkTreeStore *srchmodel;
71 GtkTreeModelFilter *srchmodelfilter;
72 GtkTextTagTable *chattags;
73 int dcfd = -1, gdkread = -1, gdkwrite = -1;
74 int pubhubfd = -1, pubhubtag = -1, filterpubhub = 0;
78 char *pubhubaddr = NULL;
79 char *connectas = NULL;
80 char *dcserver = NULL;
82 int srchautoupdate = 0;
83 int cursrch = -1, nextsrch = -1;
85 struct srchsize *srchsizes = NULL;
86 struct knownspeed *knownspeeds = NULL;
87 int numsizes = 0, numspeeds = 0, ksqueryseq = -1, ksquerytag = -1, lsrestag = -1;
89 gboolean initdeath(GtkWidget *, gpointer);
90 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data);
91 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data);
92 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data);
93 void cb_main_lsres_activate(GtkWidget *widget, gpointer data);
94 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data);
95 void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data);
96 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data);
97 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data);
98 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data);
99 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data);
100 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
101 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
102 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
103 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data);
104 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data);
105 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data);
106 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data);
107 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data);
108 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data);
109 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data);
110 void cb_main_srhash_activate(GtkWidget *widget, gpointer data);
111 void cb_main_srcopy_activate(GtkWidget *widget, gpointer data);
112 void cb_main_trhash_activate(GtkWidget *widget, gpointer data);
113 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data);
114 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data);
115 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data);
116 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data);
117 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data);
118 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data);
119 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data);
120 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data);
121 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
122 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data);
123 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition);
124 void srchstatupdate(void);
125 void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
126 void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
127 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
128 void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
129 void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
131 #define DCCHARSET "windows-1252"
133 #define _(text) gettext(text)
135 #include "mainwnd.gtk"
136 #include "inpdialog.gtk"
138 #include "reslist.gtk"
140 void updatewrite(void)
147 gdkwrite = gdk_input_add(dcfd, GDK_INPUT_WRITE, dcfdcallback, NULL);
151 gdk_input_remove(gdkwrite);
157 void fndestroycb(struct dc_fnetnode *fn)
160 GtkTextBuffer *textbuf;
163 g_object_unref(data->textbuf);
165 if(curchat == fn->id)
167 textbuf = gtk_text_buffer_new(chattags);
168 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), textbuf);
169 g_object_unref(textbuf);
173 void addfndata(struct dc_fnetnode *fn)
177 if(fn->udata != NULL)
179 fn->destroycb = fndestroycb;
180 data = smalloc(sizeof(*data));
181 data->textbuf = gtk_text_buffer_new(chattags);
185 char *getfnstatestock(int state)
187 if(state == DC_FNN_STATE_SYN)
188 return("gtk-jump-to");
189 if(state == DC_FNN_STATE_HS)
190 return("gtk-execute");
191 if(state == DC_FNN_STATE_EST)
193 if(state == DC_FNN_STATE_DEAD)
194 return("gtk-cancel");
198 void updatehublist(void)
201 struct dc_fnetnode *fn;
208 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
214 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
218 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
219 if((fn = dc_findfnetnode(id)) == NULL)
221 /* I can't seem to get a sensible reply fromp
222 * gtk_list_store, so I'm just doing this
224 gtk_list_store_remove(fnmodel, &iter);
228 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 1, &name, 2, &state, 3, &numusers, -1);
232 buf = icswcstombs(fn->name, "UTF-8", NULL);
233 if(strcmp(buf, name))
234 gtk_list_store_set(fnmodel, &iter, 1, buf, -1);
235 if(state != fn->state)
237 gtk_list_store_set(fnmodel, &iter, 2, fn->state, -1);
238 gtk_list_store_set(fnmodel, &iter, 4, getfnstatestock(fn->state), -1);
240 if(numusers != fn->numusers)
241 gtk_list_store_set(fnmodel, &iter, 3, fn->numusers, -1);
245 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
248 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
255 buf = icswcstombs(fn->name, "UTF-8", NULL);
256 gtk_list_store_append(fnmodel, &iter);
257 gtk_list_store_set(fnmodel, &iter, 0, fn->id, 1, buf, 2, fn->state, 3, fn->numusers, 4, getfnstatestock(fn->state), -1);
263 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
270 gtk_tree_model_get(model, iter, colnum, &val, -1);
271 snprintf(buf, 64, "%.2f%%", (double)(val * 100.0));
272 g_object_set(rend, "text", buf, NULL);
275 void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
281 gtk_tree_model_get(model, iter, colnum, &val, -1);
283 snprintf(buf, 64, "%'i", val);
285 strcpy(buf, _("Unknown"));
286 g_object_set(rend, "text", buf, NULL);
289 void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
295 gtk_tree_model_get(model, iter, colnum, &val, -1);
297 snprintf(buf, 64, "%i", val);
300 g_object_set(rend, "text", buf, NULL);
303 void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
305 int speed, size, time;
308 gtk_tree_model_get(model, iter, 4, &size, 8, &speed, -1);
311 time = (size / speed) / 60;
313 snprintf(buf, 64, "%'i (<00:01)", speed);
315 snprintf(buf, 64, "%'i (%02i:%02i)", speed, time / 60, time % 60);
316 } else if(speed == 0) {
319 strcpy(buf, _("Unknown"));
321 g_object_set(rend, "text", buf, NULL);
324 void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
328 char finbuf[64], tbuf[64], *errstr;
330 gtk_tree_model_get(model, iter, 10, &error, 11, &errortime, -1);
331 if(error != DC_TRNSE_NOERROR)
333 if(error == DC_TRNSE_NOTFOUND)
334 errstr = _("Not found");
335 else if(error == DC_TRNSE_NOSLOTS)
336 errstr = _("No slots");
337 strftime(tbuf, 64, _("%H:%M:%S"), localtime(&errortime));
338 snprintf(finbuf, 64, _("%s (reported at %s)"), errstr, tbuf);
342 g_object_set(rend, "text", finbuf, NULL);
345 char *gettrstatestock(int state)
347 if(state == DC_TRNS_WAITING)
348 return("gtk-jump-to");
349 if(state == DC_TRNS_HS)
350 return("gtk-execute");
351 if(state == DC_TRNS_MAIN)
352 return("gtk-network");
353 if(state == DC_TRNS_DONE)
358 void updatetransferlists(void)
362 struct dc_transfer *transfer;
366 char *peerid, *peernick, *path, *hash;
367 int state, dir, size, curpos, error;
369 GtkListStore *stores[3];
371 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
373 stores[DC_TRNSD_UNKNOWN] = NULL;
374 stores[DC_TRNSD_UP] = ulmodel;
375 stores[DC_TRNSD_DOWN] = dlmodel;
376 for(i = 0; i < 3; i++)
378 if(stores[i] == NULL)
384 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(stores[i]), &iter))
388 gtk_tree_model_get(GTK_TREE_MODEL(stores[i]), &iter, 0, &id, 1, &dir, -1);
389 if(((transfer = dc_findtransfer(id)) == NULL) || (transfer->dir != dir))
391 gtk_list_store_remove(stores[i], &iter);
396 gtk_tree_model_get(GTK_TREE_MODEL(stores[i]), &iter, 2, &state, 3, &peerid, 4, &peernick, 5, &path, 6, &size, 7, &curpos, 10, &error, 11, &errortime, 12, &hash, -1);
397 if(state != transfer->state)
398 gtk_list_store_set(stores[i], &iter, 2, transfer->state, 8, gettrstatestock(transfer->state), -1);
399 if(size != transfer->size)
400 gtk_list_store_set(stores[i], &iter, 6, transfer->size, -1);
401 if(curpos != transfer->curpos)
402 gtk_list_store_set(stores[i], &iter, 7, transfer->curpos, -1);
403 if(error != transfer->error)
404 gtk_list_store_set(stores[i], &iter, 10, transfer->error, -1);
405 if(errortime != transfer->errortime)
406 gtk_list_store_set(stores[i], &iter, 11, transfer->errortime, -1);
407 if((transfer->size > 0) && (transfer->curpos > 0))
408 gtk_list_store_set(stores[i], &iter, 9, (float)transfer->curpos / (float)transfer->size, -1);
409 buf = icswcstombs(transfer->peerid, "UTF-8", NULL);
410 if(strcmp(buf, peerid))
411 gtk_list_store_set(stores[i], &iter, 3, buf, -1);
412 buf = icswcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8", NULL);
413 if(strcmp(buf, peernick))
414 gtk_list_store_set(stores[i], &iter, 4, buf, -1);
415 buf = (transfer->path == NULL)?_("Unknown"):icswcstombs(transfer->path, "UTF-8", NULL);
416 if(strcmp(buf, path))
417 gtk_list_store_set(stores[i], &iter, 5, buf, -1);
418 buf = (transfer->hash == NULL)?"":icswcstombs(transfer->hash, "UTF-8", NULL);
419 if(strcmp(buf, path))
420 gtk_list_store_set(stores[i], &iter, 12, buf, -1);
426 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(stores[i]), &iter));
430 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
434 if(stores[transfer->dir] != NULL)
436 peerid = icwcstombs(transfer->peerid, "UTF-8");
437 peernick = icwcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8");
438 path = (transfer->path == NULL)?_("Unknown"):icwcstombs(transfer->path, "UTF-8");
439 hash = (transfer->hash == NULL)?"":icwcstombs(transfer->hash, "UTF-8");
440 gtk_list_store_append(stores[transfer->dir], &iter);
441 gtk_list_store_set(stores[transfer->dir], &iter,
450 8, gettrstatestock(transfer->state),
453 11, transfer->errortime,
458 if(transfer->path != NULL)
460 if(transfer->hash != NULL)
467 void updatesbar(char *msg)
469 gtk_statusbar_pop(GTK_STATUSBAR(main_statusbar), 0);
470 gtk_statusbar_push(GTK_STATUSBAR(main_statusbar), 0, msg);
473 void freesrchsizes(void)
477 for(i = 0; i < numsizes; i++)
479 if(srchsizes[i].ref != NULL)
480 gtk_tree_row_reference_free(srchsizes[i].ref);
482 if(srchsizes != NULL)
488 void dcdisconnected(void)
492 gdk_input_remove(gdkread);
497 updatetransferlists();
498 cursrch = nextsrch = -1;
499 gtk_tree_store_clear(srchmodel);
501 gtk_widget_set_sensitive(main_connmenu, TRUE);
502 gtk_widget_set_sensitive(main_dconnmenu, FALSE);
503 gtk_widget_set_sensitive(main_simplesrch, TRUE);
504 gtk_widget_set_sensitive(main_realsrch, TRUE);
505 gtk_widget_set_sensitive(main_srchbtn, TRUE);
506 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
507 updatesbar(_("Disconnected"));
510 char *inputbox(char *title, char *prompt, char *def, int echo)
516 inpdialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(main_wnd), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
517 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(inpdialog)->vbox), swnd = create_inpdialog_wnd(), TRUE, TRUE, 0);
518 gtk_widget_show(swnd);
520 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), FALSE);
521 gtk_label_set_text(GTK_LABEL(inpdialog_prompt), prompt);
522 gtk_entry_set_text(GTK_ENTRY(inpdialog_entry), def);
523 resp = gtk_dialog_run(GTK_DIALOG(inpdialog));
525 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), TRUE);
526 if(resp == GTK_RESPONSE_ACCEPT)
527 buf = strdup(gtk_entry_get_text(GTK_ENTRY(inpdialog_entry)));
530 gtk_widget_destroy(inpdialog);
535 int msgbox(int type, int buttons, char *format, ...)
542 va_start(args, format);
543 buf = vsprintf2(format, args);
545 swnd = gtk_message_dialog_new(GTK_WINDOW(main_wnd), GTK_DIALOG_MODAL, type, buttons, "%s", buf);
546 resp = gtk_dialog_run(GTK_DIALOG(swnd));
547 gtk_widget_destroy(swnd);
552 void readconfigfile(void)
555 char *homedir, *buf, *p;
558 if((homedir = getenv("HOME")) == NULL)
560 fprintf(stderr, "warning: could not find home directory!\n");
563 buf = sprintf2("%s/.dolconrc", homedir);
564 if((cfgfile = fopen(buf, "r")) == NULL)
573 while(fgets(buf, 1024, cfgfile) != NULL)
577 p = buf + strlen(buf);
580 if((p = strchr(buf, ':')) == NULL)
583 while((*p == ' ') || (*p == '\t'))
585 if(!strcmp(buf, "wnd-width"))
588 } else if(!strcmp(buf, "wnd-height")) {
590 } else if(!strcmp(buf, "pane1-pos")) {
591 gtk_paned_set_position(GTK_PANED(main_pane1), atoi(p));
592 } else if(!strcmp(buf, "pane2-pos")) {
593 gtk_paned_set_position(GTK_PANED(main_pane2), atoi(p));
594 } else if(!strcmp(buf, "pane3-pos")) {
595 gtk_paned_set_position(GTK_PANED(main_pane3), atoi(p));
596 } else if(!strcmp(buf, "pubhubaddr")) {
598 pubhubaddr = sstrdup(p);
599 } else if(!strcmp(buf, "dcserver")) {
601 dcserver = sstrdup(p);
602 } else if(!strcmp(buf, "advexpanded")) {
603 gtk_expander_set_expanded(GTK_EXPANDER(main_advexp), atoi(p));
604 } else if(!strcmp(buf, "connectas")) {
606 connectas = sstrdup(p);
607 } else if(!strcmp(buf, "autoconn")) {
609 } else if(!strcmp(buf, "filternoslots")) {
610 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(main_filternoslots), atoi(p));
619 gtk_window_resize(GTK_WINDOW(main_wnd), w, h);
622 void updateconfigfile(void)
628 if((homedir = getenv("HOME")) == NULL)
630 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not get your home directory!"));
633 buf = sprintf2("%s/.dolconrc", homedir);
634 if((cfgfile = fopen(buf, "w")) == NULL)
637 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not open configuration file for writing: %s"), strerror(errno));
641 gtk_window_get_size(GTK_WINDOW(main_wnd), &w, &h);
642 fprintf(cfgfile, "wnd-width: %i\n", w);
643 fprintf(cfgfile, "wnd-height: %i\n", h);
644 fprintf(cfgfile, "pane1-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane1)));
645 fprintf(cfgfile, "pane2-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane2)));
646 fprintf(cfgfile, "pane3-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane3)));
647 fprintf(cfgfile, "pubhubaddr: %s\n", pubhubaddr);
648 fprintf(cfgfile, "dcserver: %s\n", dcserver);
649 fprintf(cfgfile, "advexpanded: %i\n", gtk_expander_get_expanded(GTK_EXPANDER(main_advexp)));
650 fprintf(cfgfile, "connectas: %s\n", connectas);
651 fprintf(cfgfile, "autoconn: %i\n", autoconn);
652 fprintf(cfgfile, "filternoslots: %i\n", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots)));
656 gboolean initdeath(GtkWidget *widget, gpointer data)
663 void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data)
665 gtk_dialog_response(GTK_DIALOG(inpdialog), GTK_RESPONSE_ACCEPT);
668 int loginconv(int type, wchar_t *prompt, char **resp, void *data)
674 buf = icwcstombs(prompt, "UTF-8");
677 case DC_LOGIN_CONV_NOECHO:
678 if((*resp = inputbox(_("Login"), buf, "", 0)) == NULL)
681 case DC_LOGIN_CONV_ECHO:
682 if((*resp = inputbox(_("Login"), buf, "", 1)) == NULL)
685 case DC_LOGIN_CONV_INFO:
686 msgbox(GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", buf);
688 case DC_LOGIN_CONV_ERROR:
689 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", buf);
697 void getfnlistcallback(int resp, void *data)
702 void gettrlistcallback(int resp, void *data)
704 updatetransferlists();
707 void logincallback(int err, wchar_t *reason, void *data)
711 case DC_LOGIN_ERR_SUCCESS:
712 dc_queuecmd(NULL, NULL, L"notify", L"all", L"on", NULL);
713 dc_getfnlistasync(getfnlistcallback, NULL);
714 dc_gettrlistasync(gettrlistcallback, NULL);
715 updatesbar("Authenticated");
717 case DC_LOGIN_ERR_NOLOGIN:
718 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not negotiate an acceptable authentication mechanism"));
722 case DC_LOGIN_ERR_SERVER:
723 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has encountered an error"));
727 case DC_LOGIN_ERR_USER:
728 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Internal client error"));
732 case DC_LOGIN_ERR_CONV:
736 case DC_LOGIN_ERR_AUTHFAIL:
737 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Login attempt failed!"));
745 GtkTreeIter *ref2iter(GtkTreeRowReference *ref)
747 static GtkTreeIter iter;
750 assert((path = gtk_tree_row_reference_get_path(ref)) != NULL);
751 assert(gtk_tree_model_get_iter(GTK_TREE_MODEL(srchmodel), &iter, path));
752 gtk_tree_path_free(path);
756 GtkTreeRowReference *iter2ref(GtkTreeIter *iter)
759 GtkTreeRowReference *ref;
761 assert((path = gtk_tree_model_get_path(GTK_TREE_MODEL(srchmodel), iter)) != NULL);
762 assert((ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(srchmodel), path)) != NULL);
763 gtk_tree_path_free(path);
767 struct srchsize *finddiscsize(void)
772 for(i = 0; i < numsizes; i++)
774 if(srchsizes[i].size == -1)
775 return(&srchsizes[i]);
777 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
778 srchsizes[i].size = -1;
779 srchsizes[i].num = 1;
780 srchsizes[i].slots = 0;
781 srchsizes[i].resptime = 0.0;
782 gtk_tree_store_append(srchmodel, &iter, NULL);
783 gtk_tree_store_set(srchmodel, &iter, 3, _("Discrete sizes"), 7, 1, -1);
784 srchsizes[i].ref = iter2ref(&iter);
785 return(&srchsizes[i]);
788 struct knownspeed *findksentbyname(char *userid)
792 for(i = 0; i < numspeeds; i++)
794 if(!strcmp(knownspeeds[i].userid, userid))
795 return(&knownspeeds[i]);
800 struct knownspeed *findksentbyseq(int seq)
804 for(i = 0; i < numspeeds; i++)
806 if(knownspeeds[i].seq == seq)
807 return(&knownspeeds[i]);
812 gboolean ksupdaterow(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
814 struct knownspeed *ks;
817 gtk_tree_model_get(GTK_TREE_MODEL(model), iter, 1, &userid, -1);
820 ks = findksentbyname(userid);
823 knownspeeds = srealloc(knownspeeds, (numspeeds + 1) * sizeof(*knownspeeds));
824 ks = &knownspeeds[numspeeds];
826 ks->userid = sstrdup(userid);
833 gtk_tree_store_set(GTK_TREE_STORE(model), iter, 8, ks->speed, -1);
837 gint ksupdatecb(gpointer data)
841 wchar_t **users, *buf;
842 size_t userssize, usersdata;
848 for(i = 0; i < numspeeds;)
850 if(now - knownspeeds[i].fetched > 60)
852 free(knownspeeds[i].userid);
853 memmove(&knownspeeds[i], &knownspeeds[i + 1], (--numspeeds - i) * sizeof(*knownspeeds));
858 if(oldnum != numspeeds)
865 knownspeeds = srealloc(knownspeeds, numspeeds * sizeof(*knownspeeds));
868 gtk_tree_model_foreach(GTK_TREE_MODEL(srchmodel), ksupdaterow, NULL);
872 userssize = usersdata = 0;
874 for(i = 0; i < numspeeds; i++)
876 if(knownspeeds[i].seq == -2)
878 assert((buf = icmbstowcs(knownspeeds[i].userid, "UTF-8")) != NULL);
879 knownspeeds[i].seq = ksqueryseq++;
880 addtobuf(users, buf);
883 addtobuf(users, NULL);
884 ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%%a", users, NULL);
885 dc_freewcsarr(users);
890 void handleresps(void)
893 struct dc_response *resp;
894 struct dc_intresp *ires;
895 struct dc_fnetnode *fn;
896 struct fndata *fndata;
898 GtkTreeIter titer, piter;
902 struct knownspeed *ks;
904 while((resp = dc_getresp()) != NULL)
906 if(!wcscmp(resp->cmdname, L".connect"))
908 if(resp->code == 200)
910 tosbuf = 0x10; /* Minimum cost */
911 setsockopt(dcfd, SOL_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
912 updatesbar(_("Connected"));
913 dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
915 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server refused the connection"));
919 } else if(!wcscmp(resp->cmdname, L".notify")) {
920 dc_uimisc_handlenotify(resp);
924 if((ires = dc_interpret(resp)) != NULL)
926 if((fn = dc_findfnetnode(ires->argv[0].val.num)) != NULL)
929 gtk_text_buffer_get_end_iter(fndata->textbuf, &iter);
930 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
932 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, "<", -1, "sender", NULL);
933 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, buf, -1, "sender", NULL);
934 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, ">", -1, "sender", NULL);
935 gtk_text_buffer_insert(fndata->textbuf, &iter, " ", -1);
938 if((buf = icwcstombs(ires->argv[4].val.str, "UTF-8")) != NULL)
940 gtk_text_buffer_insert(fndata->textbuf, &iter, buf, -1);
941 gtk_text_buffer_insert(fndata->textbuf, &iter, "\n", -1);
943 if(curchat == fn->id)
944 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(main_chatview), &iter, 0, 0, 0, 0);
966 updatetransferlists();
969 if((ires = dc_interpret(resp)) != NULL)
971 if(ires->argv[0].val.num == nextsrch)
972 srcheta = time(NULL) + ires->argv[0].val.num;
977 if((ires = dc_interpret(resp)) != NULL)
979 if(ires->argv[0].val.num == nextsrch)
982 dc_queuecmd(NULL, NULL, L"cansrch", L"%%i", cursrch, NULL);
985 gtk_widget_set_sensitive(main_realsrch, TRUE);
986 gtk_widget_set_sensitive(main_simplesrch, TRUE);
987 gtk_widget_set_sensitive(main_srchbtn, TRUE);
988 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
990 gtk_entry_set_text(GTK_ENTRY(main_realsrch), "");
991 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
992 gtk_tree_store_clear(srchmodel);
999 if((ires = dc_interpret(resp)) != NULL)
1001 if(ires->argv[0].val.num == cursrch)
1003 for(i = 0; i < numsizes; i++)
1005 if(srchsizes[i].size == ires->argv[4].val.num)
1010 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
1011 srchsizes[i].size = ires->argv[4].val.num;
1012 srchsizes[i].num = 1;
1013 srchsizes[i].slots = ires->argv[5].val.num;
1014 srchsizes[i].resptime = ires->argv[7].val.flnum;
1015 ss = finddiscsize();
1016 ss->slots += ires->argv[5].val.num;
1017 if((ss->resptime == 0.0) || (ss->resptime > ires->argv[7].val.flnum))
1018 ss->resptime = ires->argv[7].val.flnum;
1019 piter = *ref2iter(ss->ref);
1020 gtk_tree_store_set(srchmodel, &piter, 5, ss->slots, 6, ss->resptime, -1);
1021 gtk_tree_store_append(srchmodel, &titer, &piter);
1022 srchsizes[i].ref = iter2ref(&titer);
1023 } else if(srchsizes[i].num == 1) {
1024 char *filename, *peername, *fnetname, *hash;
1028 gtk_tree_model_get(GTK_TREE_MODEL(srchmodel), ref2iter(srchsizes[i].ref), 0, &fnetname, 1, &peername, 3, &filename, 5, &slots, 6, &resptime, 8, &speed, 9, &hash, -1);
1029 gtk_tree_store_remove(srchmodel, ref2iter(srchsizes[i].ref));
1030 gtk_tree_row_reference_free(srchsizes[i].ref);
1031 ss = finddiscsize();
1033 gtk_tree_store_set(srchmodel, ref2iter(ss->ref), 5, ss->slots, -1);
1034 gtk_tree_store_append(srchmodel, &piter, NULL);
1035 srchsizes[i].slots = ires->argv[5].val.num + slots;
1036 srchsizes[i].resptime = (ires->argv[7].val.flnum < resptime)?ires->argv[7].val.flnum:resptime;
1037 srchsizes[i].num = 2;
1038 srchsizes[i].ref = iter2ref(&piter);
1039 gtk_tree_store_set(srchmodel, &piter, 4, srchsizes[i].size, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, 2, -1);
1040 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1043 /* XXX: Too NMDC-specific! */
1044 if(strrchr(p, '\\') != NULL)
1045 p = strrchr(p, '\\') + 1;
1046 gtk_tree_store_set(srchmodel, &piter, 3, p, -1);
1049 gtk_tree_store_append(srchmodel, &titer, &piter);
1050 gtk_tree_store_set(srchmodel, &titer, 0, fnetname, 1, peername, 2, peername, 3, filename, 4, srchsizes[i].size, 5, slots, 6, resptime, 8, speed, 9, hash, -1);
1051 g_free(filename); g_free(peername); g_free(fnetname); g_free(hash);
1052 gtk_tree_store_append(srchmodel, &titer, &piter);
1055 srchsizes[i].slots += ires->argv[5].val.num;
1056 if(ires->argv[7].val.flnum < srchsizes[i].resptime)
1057 srchsizes[i].resptime = ires->argv[7].val.flnum;
1058 piter = *ref2iter(srchsizes[i].ref);
1059 gtk_tree_store_set(srchmodel, &piter, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, srchsizes[i].num, -1);
1060 gtk_tree_store_append(srchmodel, &titer, &piter);
1062 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1064 gtk_tree_store_set(srchmodel, &titer, 3, buf, -1);
1067 if((buf = icwcstombs(ires->argv[2].val.str, "UTF-8")) != NULL)
1069 gtk_tree_store_set(srchmodel, &titer, 0, buf, -1);
1072 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1074 gtk_tree_store_set(srchmodel, &titer, 1, buf, -1);
1075 gtk_tree_store_set(srchmodel, &titer, 2, buf, -1);
1078 if((buf = icwcstombs(ires->argv[8].val.str, "UTF-8")) != NULL)
1080 gtk_tree_store_set(srchmodel, &titer, 9, buf, -1);
1083 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);
1091 } else if(!wcscmp(resp->cmdname, L"filtercmd")) {
1092 if((ksquerytag >= 0) && (ksquerytag == resp->tag))
1094 for(i = 0; i < resp->numlines; i++)
1096 assert((ks = findksentbyseq(i)) != NULL);
1097 ks->speed = wcstol(resp->rlines[i].argv[1], NULL, 10);
1099 ks->fetched = time(NULL);
1103 } else if((lsrestag >= 0) && (lsrestag == resp->tag)) {
1104 for(i = 0; i < resp->numlines; i++)
1106 if(!wcsncmp(resp->rlines[i].argv[1], L"id:", 3))
1108 gtk_list_store_append(reslist, &titer);
1109 gtk_list_store_set(reslist, &titer, 0, icswcstombs(resp->rlines[i].argv[1] + 3, "UTF-8", NULL), -1);
1110 } else if(!wcsncmp(resp->rlines[i].argv[1], L"size:", 5)) {
1111 gtk_list_store_set(reslist, &titer, 1, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1112 } else if(!wcsncmp(resp->rlines[i].argv[1], L"prog:", 5)) {
1113 gtk_list_store_set(reslist, &titer, 2, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1114 } else if(!wcsncmp(resp->rlines[i].argv[1], L"name:", 5)) {
1115 gtk_list_store_set(reslist, &titer, 3, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1116 } else if(!wcsncmp(resp->rlines[i].argv[1], L"lock:", 5)) {
1117 if(!wcscmp(resp->rlines[i].argv[1] + 5, L"yes"))
1118 gtk_list_store_set(reslist, &titer, 4, TRUE, -1);
1120 gtk_list_store_set(reslist, &titer, 4, FALSE, -1);
1121 } else if(!wcsncmp(resp->rlines[i].argv[1], L"hash:", 5)) {
1122 gtk_list_store_set(reslist, &titer, 5, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1126 gtk_widget_set_sensitive(reslist_reload, TRUE);
1134 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition)
1138 if(((condition & GDK_INPUT_READ) && dc_handleread()) || ((condition & GDK_INPUT_WRITE) && dc_handlewrite()))
1144 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has closed the connection"));
1146 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The connection to the server failed:\n\n%s"), strerror(errnobak));
1153 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data)
1161 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data)
1163 GtkWidget *dialog, *swnd;
1166 dialog = gtk_dialog_new_with_buttons(_("Preferences"), GTK_WINDOW(main_wnd), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
1167 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), swnd = create_pref_wnd(), TRUE, TRUE, 0);
1168 gtk_entry_set_text(GTK_ENTRY(pref_pubhuburl), pubhubaddr);
1169 gtk_entry_set_text(GTK_ENTRY(pref_connectas), connectas);
1170 gtk_entry_set_text(GTK_ENTRY(pref_dcserver), dcserver);
1171 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref_autoconn), autoconn);
1172 gtk_widget_show(swnd);
1173 resp = gtk_dialog_run(GTK_DIALOG(dialog));
1174 if(resp == GTK_RESPONSE_ACCEPT)
1177 pubhubaddr = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_pubhuburl)));
1179 connectas = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_connectas)));
1181 dcserver = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_dcserver)));
1182 autoconn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_autoconn));
1184 gtk_widget_destroy(dialog);
1187 void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
1189 gtk_list_store_clear(reslist);
1190 gtk_widget_set_sensitive(reslist_delete, FALSE);
1191 gtk_widget_set_sensitive(reslist_search, FALSE);
1192 gtk_widget_show(reslist_wnd);
1195 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
1196 gtk_widget_set_sensitive(reslist_reload, FALSE);
1200 void dcconnect(char *host)
1202 dcfd = dc_connect(host, -1);
1205 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect:\n\n%s"), strerror(errno));
1208 gdkread = gdk_input_add(dcfd, GDK_INPUT_READ, dcfdcallback, NULL);
1210 gtk_widget_set_sensitive(main_connmenu, FALSE);
1211 gtk_widget_set_sensitive(main_dconnmenu, TRUE);
1212 updatesbar(_("Connecting..."));
1215 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data)
1221 if((buf = inputbox(_("Connect"), _("Server address:"), dcserver, 1)) == NULL)
1227 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data)
1230 struct dc_response *resp;
1234 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1237 tag = dc_queuecmd(NULL, NULL, L"shutdown", NULL);
1238 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1240 if(resp->code == 502)
1241 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1247 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
1250 struct dc_response *resp;
1255 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1258 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_fnaddr)), "UTF-8", NULL));
1261 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Illegal address entered"));
1264 if(wcschr(toks[0], L':') == NULL)
1266 toks[0] = srealloc(toks[0], (wcslen(toks[0]) + 5) * sizeof(wchar_t));
1267 wcscat(toks[0], L":411");
1269 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%%a", toks, NULL);
1270 dc_freewcsarr(toks);
1271 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1273 if(resp->code == 502)
1274 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1275 if(resp->code == 509)
1276 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1279 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1283 void pubhubfdcallback(gpointer data, gint source, GdkInputCondition condition)
1285 static char buf[65536];
1286 static int bufpos = 0;
1292 int sorted, sortcol;
1293 GtkSortType sortorder;
1294 GtkTreeModel *sortmodel;
1296 if(!(condition & GDK_INPUT_READ))
1300 ret = read(pubhubfd, buf + bufpos, sizeof(buf) - bufpos);
1304 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not read from public hub listing process: %s"), strerror(errno));
1306 gdk_input_remove(pubhubtag);
1307 kill(pubhubproc, SIGINT);
1308 pubhubfd = pubhubtag = -1;
1313 regfree(&pubhubfilter);
1319 sortmodel = gtk_tree_view_get_model(GTK_TREE_VIEW(main_phublist));
1320 sorted = gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(sortmodel), &sortcol, &sortorder);
1321 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), NULL);
1322 while((p = memchr(buf, '\n', bufpos)) != NULL)
1325 if(!filterpubhub || !regexec(&pubhubfilter, buf, 0, NULL, 0))
1328 for(i = 0; i < 4; i++)
1331 if((p2 = strchr(p2, '|')) == NULL)
1337 for(i = 0; i < 4; i++)
1339 if((wbuf = icsmbstowcs(fields[i], DCCHARSET, NULL)) == NULL)
1341 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not decode hublist - aborting at this point: %s"), strerror(errno));
1342 kill(pubhubproc, SIGINT);
1345 if((fields[i] = icwcstombs(wbuf, "UTF-8")) == NULL)
1350 gtk_list_store_append(pubhubmodel, &iter);
1351 gtk_list_store_set(pubhubmodel, &iter, 0, fields[0], 1, fields[1], 2, fields[2], 3, atoi(fields[3]), -1);
1353 for(i--; i >= 0; i--)
1357 memmove(buf, p, bufpos -= p - buf);
1359 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(pubhubmodel));
1361 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), sortcol, sortorder);
1362 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), sortmodel);
1365 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
1367 int pipe1[2], pipe2[2];
1373 gdk_input_remove(pubhubtag);
1377 kill(pubhubproc, SIGINT);
1380 regfree(&pubhubfilter);
1383 buf = gtk_entry_get_text(GTK_ENTRY(main_pubhubfilter));
1386 if((err = regcomp(&pubhubfilter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
1388 regerror(err, &pubhubfilter, errbuf, sizeof(errbuf));
1389 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not compile regex: %s", errbuf);
1390 regfree(&pubhubfilter);
1396 gtk_list_store_clear(pubhubmodel);
1398 if((pubhubproc = fork()) == 0)
1403 execlp("wget", "wget", "-qO", "-", pubhubaddr, NULL);
1408 pubhubfd = pipe1[0];
1409 len = strlen(pubhubaddr);
1410 if((len > 4) && !strcmp(pubhubaddr + len - 4, ".bz2"))
1420 execlp("bzcat", "bzcat", NULL);
1426 pubhubfd = pipe2[0];
1428 pubhubtag = gdk_input_add(pubhubfd, GDK_INPUT_READ, pubhubfdcallback, NULL);
1431 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
1435 struct dc_response *resp;
1439 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1442 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_fnetnodes)), NULL, &iter))
1444 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1447 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1448 tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%%i", id, NULL);
1449 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1451 if(resp->code == 502)
1452 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1458 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data)
1461 GtkTreeModel *model;
1464 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_phublist)), &model, &iter))
1466 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &addr, -1);
1467 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), addr);
1471 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1474 struct dc_response *resp;
1476 GtkTreeModel *model;
1481 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1484 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1485 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1487 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &buf, -1);
1488 if(strchr(buf, ':') == NULL)
1490 buf = g_realloc(buf, strlen(buf) + 5);
1491 strcat(buf, ":411");
1493 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%%s", buf, NULL);
1495 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1496 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1498 if(resp->code == 502)
1499 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1500 if(resp->code == 509)
1501 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1507 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer uudata)
1511 struct dc_fnetnode *fn;
1512 struct fndata *data;
1514 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(fnmodel), &iter, path))
1516 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1517 if((fn = dc_findfnetnode(id)) == NULL)
1521 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
1525 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1527 gtk_list_store_set(fnmodel, &iter, 5, "gtk-apply", -1);
1529 gtk_list_store_set(fnmodel, &iter, 5, NULL, -1);
1530 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
1532 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), GTK_TEXT_BUFFER(data->textbuf));
1535 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data)
1539 struct dc_response *resp;
1543 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1548 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1551 buf = gtk_entry_get_text(GTK_ENTRY(main_chatstr));
1552 tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%%i", curchat, L"1", L"", L"%%s", buf, NULL);
1553 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1555 if(resp->code == 502)
1556 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1557 else if(resp->code == 504)
1558 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub could not support all the types of characters in your chat message"));
1559 else if(resp->code == 513)
1560 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub does not support chatting"));
1561 else if(resp->code != 200)
1562 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to chat (%i)"), resp->code);
1565 gtk_entry_set_text(GTK_ENTRY(main_chatstr), "");
1569 void updatesrchfld(const char *simple)
1573 size_t bufsize, bufdata;
1575 s = sstrdup(simple);
1577 bufsize = bufdata = 0;
1581 p2 = strchr(p, ' ');
1587 bufcat(buf, " & ", 3);
1588 bufcat(buf, "N~", 2);
1591 if(strchr("[]()$^.*?+\\|\"!", *p) != NULL)
1592 addtobuf(buf, '\\');
1597 } while(p2 != NULL);
1599 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1604 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data)
1609 updatesrchfld(gtk_entry_get_text(GTK_ENTRY(main_simplesrch)));
1613 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data)
1618 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1622 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data)
1626 struct dc_response *resp;
1627 struct dc_intresp *ires;
1631 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1634 if(nextsrch != -1) /* Impossible case, but oh well... */
1636 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_realsrch)), "UTF-8", NULL));
1639 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Please enter a search expression before searching"));
1642 tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%%a", toks, NULL);
1643 dc_freewcsarr(toks);
1644 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1646 if(resp->code == 501)
1647 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not find any hubs to search on"));
1648 else if(resp->code == 502)
1649 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1650 else if(resp->code == 509)
1651 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse your search expression"));
1652 else if(resp->code != 200)
1653 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to search (%i)"), resp->code);
1654 if(resp->code == 200)
1656 if((ires = dc_interpret(resp)) != NULL)
1658 nextsrch = ires->argv[0].val.num;
1659 srcheta = time(NULL) + ires->argv[1].val.num;
1662 gtk_widget_set_sensitive(main_realsrch, FALSE);
1663 gtk_widget_set_sensitive(main_simplesrch, FALSE);
1664 gtk_widget_set_sensitive(main_srchbtn, FALSE);
1665 gtk_widget_set_sensitive(main_srchcanbtn, TRUE);
1673 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data)
1677 dc_queuecmd(NULL, NULL, L"cansrch", L"%%i", nextsrch, NULL);
1679 gtk_widget_set_sensitive(main_realsrch, TRUE);
1680 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1681 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1682 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1686 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
1689 GtkTreeSelection *sel;
1690 GtkTreeModel *model;
1692 struct dc_response *resp;
1694 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
1696 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1697 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1699 gtk_tree_model_get(model, &iter, 0, &id, -1);
1700 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%%i", id, NULL);
1701 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1703 if(resp->code == 502)
1704 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1705 else if(resp->code != 200)
1706 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1716 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1719 struct dc_response *resp;
1721 GtkTreeModel *model;
1723 char *tfnet, *tpeerid, *tfilename, *thash, *arg;
1724 wchar_t *fnet, *peerid, *filename, *hash;
1728 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1731 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1732 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1734 gtk_tree_model_get(model, &iter, 7, &num, -1);
1737 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &tfnet, 1, &tpeerid, 3, &tfilename, 4, &size, 9, &thash, -1);
1738 fnet = icmbstowcs(tfnet, "UTF-8");
1739 peerid = icmbstowcs(tpeerid, "UTF-8");
1740 filename = icmbstowcs(tfilename, "UTF-8");
1741 hash = (thash == NULL)?NULL:icmbstowcs(thash, "UTF-8");
1742 if((fnet == NULL) || (peerid == NULL) || (filename == NULL))
1748 if(filename != NULL)
1762 arg = (char *)gtk_entry_get_text(GTK_ENTRY(main_dlarg));
1764 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);
1766 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);
1772 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1774 if(resp->code == 502)
1775 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1776 if(resp->code != 200)
1777 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to queue the download (%i)"), resp->code);
1783 gboolean srchfilterfunc(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1788 filteratall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots));
1791 gtk_tree_model_get(model, iter, 5, &slots, -1);
1797 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data)
1799 gtk_tree_model_filter_refilter(srchmodelfilter);
1802 void cb_main_srhash_activate(GtkWidget *widget, gpointer data)
1804 GtkTreeSelection *sel;
1805 GtkTreeModel *model;
1811 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1812 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1814 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1815 buf = sprintf2("H=%s", hash);
1816 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1819 cb_main_srchbtn_clicked(widget, NULL);
1825 void cb_main_srcopy_activate(GtkWidget *widget, gpointer data)
1828 GtkTreeSelection *sel;
1829 GtkTreeModel *model;
1835 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1836 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1838 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1839 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1840 gtk_clipboard_set_text(cb, hash, -1);
1844 void cb_main_trhash_activate(GtkWidget *widget, gpointer data)
1846 GtkTreeSelection *sel;
1847 GtkTreeModel *model;
1853 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1854 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1856 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1857 buf = sprintf2("H=%s", hash);
1858 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1861 cb_main_srchbtn_clicked(widget, NULL);
1867 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data)
1870 GtkTreeSelection *sel;
1871 GtkTreeModel *model;
1875 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1876 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1878 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1879 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1880 gtk_clipboard_set_text(cb, hash, -1);
1884 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
1886 GtkTreeSelection *sel;
1887 GtkTreeModel *model;
1890 struct dc_response *resp;
1894 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1895 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1897 gtk_tree_model_get(model, &iter, 0, &id, -1);
1898 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%%i", id, NULL);
1899 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1901 if(resp->code == 502)
1902 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1903 else if(resp->code != 200)
1904 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1913 /* XXX: This is quite a hack, since the calling convention is
1914 * different for the popup-menu sig and the button-press-event sig. It
1915 * most certainly works, but I don't know how portable it is. */
1916 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
1918 GtkTreeSelection *sel;
1919 GtkTreeModel *model;
1923 if((event != NULL) && (event->button != 3))
1925 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1926 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1928 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1929 if((hash == NULL) || (*hash == 0))
1931 gtk_widget_set_sensitive(main_srhash, FALSE);
1932 gtk_widget_set_sensitive(main_srcopy, FALSE);
1935 gtk_widget_set_sensitive(main_srhash, TRUE);
1937 gtk_widget_set_sensitive(main_srhash, FALSE);
1938 gtk_widget_set_sensitive(main_srcopy, TRUE);
1945 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
1947 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, event->button, event->time);
1951 /* The above hack note goes for this one too. */
1952 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
1954 GtkTreeSelection *sel;
1955 GtkTreeModel *model;
1959 if((event != NULL) && (event->button != 3))
1961 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1962 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1964 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1965 if((hash == NULL) || (*hash == 0))
1967 gtk_widget_set_sensitive(main_trhash, FALSE);
1968 gtk_widget_set_sensitive(main_trcopy, FALSE);
1971 gtk_widget_set_sensitive(main_trhash, TRUE);
1973 gtk_widget_set_sensitive(main_trhash, FALSE);
1974 gtk_widget_set_sensitive(main_trcopy, TRUE);
1981 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
1983 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, event->button, event->time);
1987 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data)
1991 gtk_widget_set_sensitive(reslist_delete, FALSE);
1992 gtk_widget_set_sensitive(reslist_search, FALSE);
1993 gtk_list_store_clear(reslist);
1994 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
1995 gtk_widget_set_sensitive(reslist_reload, FALSE);
2001 struct dc_response *resp;
2004 tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%%s", id, NULL);
2005 if((resp = dc_gettaggedrespsync(tag)) != NULL)
2007 if(resp->numlines > 0)
2009 if(!wcscmp(resp->rlines[0].argv[1], L"ok"))
2011 else if(!wcsncmp(resp->rlines[0].argv[1], L"err:", 4))
2012 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred (%ls)"), resp->rlines[0].argv[1] + 4);
2020 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data)
2023 GtkTreeModel *model;
2029 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2031 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &id, 4, &locked, -1);
2038 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2042 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data)
2045 GtkTreeModel *model;
2050 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2052 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 5, &hash, -1);
2053 buf = sprintf2("H=%s", hash);
2054 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2057 cb_main_srchbtn_clicked(widget, NULL);
2060 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data)
2063 GtkTreeModel *model;
2067 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2069 gtk_widget_set_sensitive(reslist_delete, FALSE);
2070 gtk_widget_set_sensitive(reslist_search, FALSE);
2073 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 4, &locked, 5, &hash, -1);
2074 gtk_widget_set_sensitive(reslist_delete, !locked);
2075 gtk_widget_set_sensitive(reslist_search, hash && *hash);
2079 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
2082 GtkTreeModel *model;
2085 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
2086 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
2090 gtk_tree_model_get(model, &iter, 5, &hash, -1);
2091 buf = sprintf2("H=%s", hash);
2092 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2095 cb_main_srchbtn_clicked(widget, NULL);
2098 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
2100 GtkTreeSelection *sel;
2101 GtkTreeModel *model;
2106 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
2108 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2109 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2111 gtk_tree_model_get(model, &iter, 0, &id, 4, &locked, -1);
2115 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2124 void srchstatupdate(void)
2130 snprintf(buf, 1024, _("Ready to search"));
2132 snprintf(buf, 1024, _("Search scheduled and will be submitted in %i seconds"), (int)(srcheta - time(NULL)));
2134 if(strcmp(gtk_label_get_text(GTK_LABEL(main_srchstatus)), buf))
2135 gtk_label_set_text(GTK_LABEL(main_srchstatus), buf);
2138 gint srchstatupdatecb(gpointer data)
2144 void initchattags(void)
2148 chattags = gtk_text_tag_table_new();
2149 tag = gtk_text_tag_new("sender");
2150 g_object_set(tag, "foreground", "blue", NULL);
2151 gtk_text_tag_table_add(chattags, tag);
2154 int main(int argc, char **argv)
2157 PangoFontDescription *monospacefont;
2158 GtkTreeModel *sortmodel;
2159 struct passwd *pwent;
2161 setlocale(LC_ALL, "");
2162 bindtextdomain(PACKAGE, LOCALEDIR);
2163 textdomain(PACKAGE);
2164 gtk_init(&argc, &argv);
2166 signal(SIGCHLD, SIG_IGN);
2167 pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.config.bz2");
2168 dcserver = sstrdup("localhost");
2169 if((pwent = getpwuid(getuid())) == NULL)
2171 fprintf(stderr, "could not get your passwd data");
2174 connectas = sstrdup(pwent->pw_name);
2175 wnd = create_main_wnd();
2176 create_reslist_wnd();
2177 gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400);
2180 fnmodel = gtk_list_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
2181 gtk_tree_view_set_model(GTK_TREE_VIEW(main_fnetnodes), GTK_TREE_MODEL(fnmodel));
2182 gtk_tree_view_set_model(GTK_TREE_VIEW(main_chatnodes), GTK_TREE_MODEL(fnmodel));
2184 reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
2185 gtk_tree_view_set_model(GTK_TREE_VIEW(reslist_list), GTK_TREE_MODEL(reslist));
2187 pubhubmodel = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
2188 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(pubhubmodel));
2189 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 3, GTK_SORT_DESCENDING);
2190 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), GTK_TREE_MODEL(sortmodel));
2191 g_object_unref(sortmodel);
2193 dlmodel = gtk_list_store_new(13, G_TYPE_INT, /* id */
2194 G_TYPE_INT, /* dir */
2195 G_TYPE_INT, /* state */
2196 G_TYPE_STRING, /* peerid */
2197 G_TYPE_STRING, /* peernick */
2198 G_TYPE_STRING, /* path */
2199 G_TYPE_INT, /* size */
2200 G_TYPE_INT, /* curpos */
2201 G_TYPE_STRING, /* stock */
2202 G_TYPE_FLOAT, /* percentage */
2203 G_TYPE_INT, /* error */
2204 G_TYPE_INT, /* errortime */
2205 G_TYPE_STRING); /* hash */
2206 gtk_tree_view_set_model(GTK_TREE_VIEW(main_downloads), GTK_TREE_MODEL(dlmodel));
2208 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);
2209 gtk_tree_view_set_model(GTK_TREE_VIEW(main_uploads), GTK_TREE_MODEL(ulmodel));
2211 srchmodel = gtk_tree_store_new(10, G_TYPE_STRING, /* fnetname */
2212 G_TYPE_STRING, /* peerid */
2213 G_TYPE_STRING, /* peername */
2214 G_TYPE_STRING, /* filename */
2215 G_TYPE_INT, /* size */
2216 G_TYPE_INT, /* slots */
2217 G_TYPE_DOUBLE, /* resptime */
2218 G_TYPE_INT, /* sizenum */
2219 G_TYPE_INT, /* speed */
2220 G_TYPE_STRING); /* hash */
2221 srchmodelfilter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(srchmodel), NULL));
2222 gtk_tree_model_filter_set_visible_func(srchmodelfilter, srchfilterfunc, NULL, NULL);
2223 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(srchmodelfilter));
2224 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 4, GTK_SORT_DESCENDING);
2225 gtk_tree_view_set_model(GTK_TREE_VIEW(main_srchres), GTK_TREE_MODEL(sortmodel));
2226 g_object_unref(sortmodel);
2228 monospacefont = pango_font_description_from_string("Monospace 10");
2229 gtk_widget_modify_font(main_chatview, monospacefont);
2230 pango_font_description_free(monospacefont);
2232 updatesbar(_("Disconnected"));
2233 gtk_widget_show(wnd);
2235 dcconnect(dcserver);
2236 g_timeout_add(500, srchstatupdatecb, NULL);
2237 g_timeout_add(5000, ksupdatecb, NULL);