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
20 /* This file is a complete and total mess, mostly because of my
21 * inability to structure GUI programs properly. Looking at it too
22 * closely may cause ocular hemorrhaging. */
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <doldaconnect/uilib.h>
34 #include <doldaconnect/uimisc.h>
35 #include <doldaconnect/utils.h>
56 dc_lnum_t poshist[TRHISTSIZE];
57 double timehist[TRHISTSIZE];
63 GtkTextBuffer *textbuf;
72 GtkTreeRowReference *ref;
83 GtkListStore *fnmodel, *ulmodel, *dlmodel, *reslist;
84 GtkTreeStore *srchmodel;
85 GtkTreeModelFilter *srchmodelfilter;
86 GtkTextTagTable *chattags;
87 int dcfd = -1, gdkread = -1, gdkwrite = -1;
89 char *pubhubaddr = NULL;
90 char *connectas = NULL;
91 char *dcserver = NULL;
93 int srchautoupdate = 0;
94 int cursrch = -1, nextsrch = -1;
96 struct srchsize *srchsizes = NULL;
97 struct knownspeed *knownspeeds = NULL;
98 int numsizes = 0, numspeeds = 0, ksqueryseq = -1, ksquerytag = -1, lsrestag = -1;
100 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition);
101 void srchstatupdate(void);
103 #include "mainwnd.gtkh"
104 #include "inpdialog.gtkh"
106 #include "reslist.gtkh"
108 void updatewrite(void)
115 gdkwrite = gdk_input_add(dcfd, GDK_INPUT_WRITE, dcfdcallback, NULL);
119 gdk_input_remove(gdkwrite);
129 gettimeofday(&tv, NULL);
130 return((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
133 void fndestroycb(struct dc_fnetnode *fn)
136 GtkTextBuffer *textbuf;
139 g_object_unref(data->textbuf);
141 if(curchat == fn->id)
143 textbuf = gtk_text_buffer_new(chattags);
144 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), textbuf);
145 g_object_unref(textbuf);
149 void addfndata(struct dc_fnetnode *fn)
153 if(fn->udata != NULL)
155 fn->destroycb = fndestroycb;
156 data = smalloc(sizeof(*data));
157 data->textbuf = gtk_text_buffer_new(chattags);
161 void trdestroycb(struct dc_transfer *tr)
166 void addtrdata(struct dc_transfer *tr)
170 if(tr->udata != NULL)
172 tr->destroycb = trdestroycb;
173 data = smalloc(sizeof(*data));
174 memset(data, 0, sizeof(*data));
178 void updatetrdata(struct dc_transfer *tr)
184 if(data->hc < TRHISTSIZE)
186 data->poshist[data->hc] = tr->curpos;
187 data->timehist[data->hc] = ntime();
190 for(i = 0; i < TRHISTSIZE - 1; i++)
192 data->poshist[i] = data->poshist[i + 1];
193 data->timehist[i] = data->timehist[i + 1];
195 data->poshist[i] = tr->curpos;
196 data->timehist[i] = ntime();
200 char *getfnstatestock(int state)
202 if(state == DC_FNN_STATE_SYN)
203 return("gtk-jump-to");
204 if(state == DC_FNN_STATE_HS)
205 return("gtk-execute");
206 if(state == DC_FNN_STATE_EST)
208 if(state == DC_FNN_STATE_DEAD)
209 return("gtk-cancel");
213 void updatehublist(void)
216 struct dc_fnetnode *fn;
223 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
229 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
233 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
234 if((fn = dc_findfnetnode(id)) == NULL)
236 /* I can't seem to get a sensible reply fromp
237 * gtk_list_store, so I'm just doing this
239 gtk_list_store_remove(fnmodel, &iter);
243 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 1, &name, 2, &state, 3, &numusers, -1);
247 buf = icswcstombs(fn->name, "UTF-8", NULL);
248 if(strcmp(buf, name))
249 gtk_list_store_set(fnmodel, &iter, 1, buf, -1);
250 if(state != fn->state)
252 gtk_list_store_set(fnmodel, &iter, 2, fn->state, -1);
253 gtk_list_store_set(fnmodel, &iter, 4, getfnstatestock(fn->state), -1);
255 if(numusers != fn->numusers)
256 gtk_list_store_set(fnmodel, &iter, 3, fn->numusers, -1);
260 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
263 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
270 buf = icswcstombs(fn->name, "UTF-8", NULL);
271 gtk_list_store_append(fnmodel, &iter);
272 gtk_list_store_set(fnmodel, &iter, 0, fn->id, 1, buf, 2, fn->state, 3, fn->numusers, 4, getfnstatestock(fn->state), -1);
278 char *bytes2si(long long bytes)
283 static char pfx[] = {'k', 'M', 'G', 'T'};
286 for(i = 0; (b >= 1024) && (i < sizeof(pfx)); i++)
289 snprintf(ret, 64, "%.1f B", b);
291 snprintf(ret, 64, "%.1f %ciB", b, pfx[i - 1]);
295 void progressfunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
301 totalc = (GPOINTER_TO_INT(data) & 0xff00) >> 8;
302 curc = GPOINTER_TO_INT(data) & 0xff;
303 gtk_tree_model_get(model, iter, totalc, &total, curc, &cur, -1);
305 g_object_set(rend, "value", GINT_TO_POINTER(0), NULL);
307 g_object_set(rend, "value", GINT_TO_POINTER((int)(((double)cur / (double)total) * 100)), NULL);
309 g_object_set(rend, "text", "", NULL);
311 snprintf(buf, 64, "%'ji", (intmax_t)cur);
312 g_object_set(rend, "text", buf, NULL);
316 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
322 colnum = GPOINTER_TO_INT(data);
323 gtk_tree_model_get(model, iter, colnum, &val, -1);
324 snprintf(buf, 64, "%.2f%%", (double)(val * 100.0));
325 g_object_set(rend, "text", buf, NULL);
328 void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
334 colnum = GPOINTER_TO_INT(data);
335 gtk_tree_model_get(model, iter, colnum, &val, -1);
337 snprintf(buf, 64, "%'ji", (intmax_t)val);
339 strcpy(buf, _("Unknown"));
340 g_object_set(rend, "text", buf, NULL);
343 void transnicebytefunc2(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
349 colnum = GPOINTER_TO_INT(data);
350 gtk_tree_model_get(model, iter, colnum, &val, -1);
352 strcpy(buf, bytes2si(val));
354 strcpy(buf, _("Unknown"));
355 g_object_set(rend, "text", buf, NULL);
358 void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
363 colnum = GPOINTER_TO_INT(data);
364 gtk_tree_model_get(model, iter, colnum, &val, -1);
366 snprintf(buf, 64, "%i", val);
369 g_object_set(rend, "text", buf, NULL);
372 void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
378 gtk_tree_model_get(model, iter, 4, &size, 8, &speed, -1);
381 time = (size / speed) / 60;
383 snprintf(buf, 64, "%'i (<00:01)", speed);
385 snprintf(buf, 64, "%'i (%02i:%02i)", speed, time / 60, time % 60);
386 } else if(speed == 0) {
389 strcpy(buf, _("Unknown"));
391 g_object_set(rend, "text", buf, NULL);
394 void transspeedinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
397 struct dc_transfer *tr;
402 gtk_tree_model_get(model, iter, 0, &id, -1);
403 if((tr = dc_findtransfer(id)) != NULL)
406 if((tr->state != DC_TRNS_MAIN) || (d == NULL))
409 } else if(d->hc < 2) {
412 speed = (((double)(d->poshist[d->hc - 1] - d->poshist[0])) / (d->timehist[d->hc - 1] - d->timehist[0]));
413 snprintf(buf, 64, "%s/s", bytes2si(speed));
418 g_object_set(rend, "text", buf, NULL);
421 void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
425 char finbuf[64], tbuf[64], *errstr;
427 gtk_tree_model_get(model, iter, 10, &error, 11, &errortime, -1);
428 if(error != DC_TRNSE_NOERROR)
430 if(error == DC_TRNSE_NOTFOUND)
431 errstr = _("Not found");
432 else if(error == DC_TRNSE_NOSLOTS)
433 errstr = _("No slots");
434 strftime(tbuf, 64, _("%H:%M:%S"), localtime((const time_t[]){errortime}));
435 snprintf(finbuf, 64, _("%s (reported at %s)"), errstr, tbuf);
439 g_object_set(rend, "text", finbuf, NULL);
442 char *gettrstatestock(int state)
444 if(state == DC_TRNS_WAITING)
445 return("gtk-jump-to");
446 if(state == DC_TRNS_HS)
447 return("gtk-execute");
448 if(state == DC_TRNS_MAIN)
449 return("gtk-network");
450 if(state == DC_TRNS_DONE)
455 gint updatetransfers(gpointer data)
457 struct dc_transfer *tr;
462 for(tr = dc_transfers; tr != NULL; tr = tr->next)
464 if((d = tr->udata) != NULL)
466 if((d->hc > 0) && ((now - d->timehist[d->hc - 1]) > 2))
473 void updatetransferlists(void)
477 struct dc_transfer *transfer;
481 char *peerid, *peernick, *path, *hash;
482 int state, dir, error;
483 gint64 size, curpos, errortime;
484 GtkListStore *stores[3];
486 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
488 stores[DC_TRNSD_UNKNOWN] = NULL;
489 stores[DC_TRNSD_UP] = ulmodel;
490 stores[DC_TRNSD_DOWN] = dlmodel;
491 for(i = 0; i < 3; i++)
493 if(stores[i] == NULL)
499 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(stores[i]), &iter))
503 gtk_tree_model_get(GTK_TREE_MODEL(stores[i]), &iter, 0, &id, 1, &dir, -1);
504 if(((transfer = dc_findtransfer(id)) == NULL) || (transfer->dir != dir))
506 gtk_list_store_remove(stores[i], &iter);
511 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);
512 if(state != transfer->state)
513 gtk_list_store_set(stores[i], &iter, 2, transfer->state, 8, gettrstatestock(transfer->state), -1);
514 if(size != transfer->size)
515 gtk_list_store_set(stores[i], &iter, 6, (gint64)transfer->size, -1);
516 if(curpos != transfer->curpos)
518 gtk_list_store_set(stores[i], &iter, 7, (gint64)transfer->curpos, -1);
519 if(transfer->udata != NULL)
520 updatetrdata(transfer);
522 if(error != transfer->error)
523 gtk_list_store_set(stores[i], &iter, 10, transfer->error, -1);
524 if(errortime != transfer->errortime)
525 gtk_list_store_set(stores[i], &iter, 11, transfer->errortime, -1);
526 if((transfer->size > 0) && (transfer->curpos > 0))
527 gtk_list_store_set(stores[i], &iter, 9, (float)transfer->curpos / (float)transfer->size, -1);
528 buf = icswcstombs(transfer->peerid, "UTF-8", NULL);
529 if(strcmp(buf, peerid))
530 gtk_list_store_set(stores[i], &iter, 3, buf, -1);
531 buf = icswcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8", NULL);
532 if(strcmp(buf, peernick))
533 gtk_list_store_set(stores[i], &iter, 4, buf, -1);
534 buf = (transfer->path == NULL)?_("Unknown"):icswcstombs(transfer->path, "UTF-8", NULL);
535 if(strcmp(buf, path))
536 gtk_list_store_set(stores[i], &iter, 5, buf, -1);
537 buf = (transfer->hash == NULL)?"":icswcstombs(transfer->hash, "UTF-8", NULL);
538 if(strcmp(buf, path))
539 gtk_list_store_set(stores[i], &iter, 12, buf, -1);
545 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(stores[i]), &iter));
549 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
553 if(stores[transfer->dir] != NULL)
555 peerid = icwcstombs(transfer->peerid, "UTF-8");
556 peernick = icwcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8");
557 path = (transfer->path == NULL)?_("Unknown"):icwcstombs(transfer->path, "UTF-8");
558 hash = (transfer->hash == NULL)?"":icwcstombs(transfer->hash, "UTF-8");
559 gtk_list_store_append(stores[transfer->dir], &iter);
560 gtk_list_store_set(stores[transfer->dir], &iter,
567 6, (gint64)transfer->size,
568 7, (gint64)transfer->curpos,
569 8, gettrstatestock(transfer->state),
572 11, (gint64)transfer->errortime,
577 if(transfer->path != NULL)
579 if(transfer->hash != NULL)
587 void updatesbar(char *msg)
589 gtk_statusbar_pop(GTK_STATUSBAR(main_statusbar), 0);
590 gtk_statusbar_push(GTK_STATUSBAR(main_statusbar), 0, msg);
593 void freesrchsizes(void)
597 for(i = 0; i < numsizes; i++)
599 if(srchsizes[i].ref != NULL)
600 gtk_tree_row_reference_free(srchsizes[i].ref);
602 if(srchsizes != NULL)
608 void dcdisconnected(void)
612 gdk_input_remove(gdkread);
617 updatetransferlists();
618 cursrch = nextsrch = -1;
619 gtk_tree_store_clear(srchmodel);
621 gtk_widget_set_sensitive(main_connmenu, TRUE);
622 gtk_widget_set_sensitive(main_dconnmenu, FALSE);
623 gtk_widget_set_sensitive(main_simplesrch, TRUE);
624 gtk_widget_set_sensitive(main_realsrch, TRUE);
625 gtk_widget_set_sensitive(main_srchbtn, TRUE);
626 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
627 updatesbar(_("Disconnected"));
630 char *inputbox(char *title, char *prompt, char *def, int echo)
636 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);
637 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(inpdialog)->vbox), swnd = create_inpdialog_wnd(), TRUE, TRUE, 0);
638 gtk_widget_show(swnd);
640 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), FALSE);
641 gtk_label_set_text(GTK_LABEL(inpdialog_prompt), prompt);
642 gtk_entry_set_text(GTK_ENTRY(inpdialog_entry), def);
643 resp = gtk_dialog_run(GTK_DIALOG(inpdialog));
645 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), TRUE);
646 if(resp == GTK_RESPONSE_ACCEPT)
647 buf = strdup(gtk_entry_get_text(GTK_ENTRY(inpdialog_entry)));
650 gtk_widget_destroy(inpdialog);
655 int msgbox(int type, int buttons, char *format, ...)
662 va_start(args, format);
663 buf = vsprintf2(format, args);
665 swnd = gtk_message_dialog_new(GTK_WINDOW(main_wnd), GTK_DIALOG_MODAL, type, buttons, "%s", buf);
666 resp = gtk_dialog_run(GTK_DIALOG(swnd));
667 gtk_widget_destroy(swnd);
672 void readconfigfile(void)
675 char *homedir, *buf, *p;
678 if((homedir = getenv("HOME")) == NULL)
680 fprintf(stderr, "warning: could not find home directory!\n");
683 buf = sprintf2("%s/.dolconrc", homedir);
684 if((cfgfile = fopen(buf, "r")) == NULL)
693 while(fgets(buf, 1024, cfgfile) != NULL)
697 p = buf + strlen(buf);
700 if((p = strchr(buf, ':')) == NULL)
703 while((*p == ' ') || (*p == '\t'))
705 if(!strcmp(buf, "wnd-width"))
708 } else if(!strcmp(buf, "wnd-height")) {
710 } else if(!strcmp(buf, "pane1-pos")) {
711 gtk_paned_set_position(GTK_PANED(main_pane1), atoi(p));
712 } else if(!strcmp(buf, "pane2-pos")) {
713 gtk_paned_set_position(GTK_PANED(main_pane2), atoi(p));
714 } else if(!strcmp(buf, "pane3-pos")) {
715 gtk_paned_set_position(GTK_PANED(main_pane3), atoi(p));
716 } else if(!strcmp(buf, "pubhubaddr")) {
718 pubhubaddr = sstrdup(p);
719 } else if(!strcmp(buf, "dcserver")) {
721 dcserver = sstrdup(p);
722 } else if(!strcmp(buf, "advexpanded")) {
723 gtk_expander_set_expanded(GTK_EXPANDER(main_advexp), atoi(p));
724 } else if(!strcmp(buf, "connectas")) {
726 connectas = sstrdup(p);
727 } else if(!strcmp(buf, "autoconn")) {
729 } else if(!strcmp(buf, "filternoslots")) {
730 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(main_filternoslots), atoi(p));
739 gtk_window_resize(GTK_WINDOW(main_wnd), w, h);
742 void updateconfigfile(void)
748 if((homedir = getenv("HOME")) == NULL)
750 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not get your home directory!"));
753 buf = sprintf2("%s/.dolconrc", homedir);
754 if((cfgfile = fopen(buf, "w")) == NULL)
757 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not open configuration file for writing: %s"), strerror(errno));
761 gtk_window_get_size(GTK_WINDOW(main_wnd), &w, &h);
762 fprintf(cfgfile, "wnd-width: %i\n", w);
763 fprintf(cfgfile, "wnd-height: %i\n", h);
764 fprintf(cfgfile, "pane1-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane1)));
765 fprintf(cfgfile, "pane2-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane2)));
766 fprintf(cfgfile, "pane3-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane3)));
767 fprintf(cfgfile, "pubhubaddr: %s\n", pubhubaddr);
768 fprintf(cfgfile, "dcserver: %s\n", dcserver);
769 fprintf(cfgfile, "advexpanded: %i\n", gtk_expander_get_expanded(GTK_EXPANDER(main_advexp)));
770 fprintf(cfgfile, "connectas: %s\n", connectas);
771 fprintf(cfgfile, "autoconn: %i\n", autoconn);
772 fprintf(cfgfile, "filternoslots: %i\n", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots)));
776 gboolean initdeath(GtkWidget *widget, gpointer data)
783 void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data)
785 gtk_dialog_response(GTK_DIALOG(inpdialog), GTK_RESPONSE_ACCEPT);
788 int loginconv(int type, wchar_t *prompt, char **resp, void *data)
794 buf = icwcstombs(prompt, "UTF-8");
797 case DC_LOGIN_CONV_NOECHO:
798 if((*resp = inputbox(_("Login"), buf, "", 0)) == NULL)
801 case DC_LOGIN_CONV_ECHO:
802 if((*resp = inputbox(_("Login"), buf, "", 1)) == NULL)
805 case DC_LOGIN_CONV_INFO:
806 msgbox(GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", buf);
808 case DC_LOGIN_CONV_ERROR:
809 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", buf);
817 void getfnlistcallback(int resp, void *data)
822 void gettrlistcallback(int resp, void *data)
824 updatetransferlists();
827 void logincallback(int err, wchar_t *reason, void *data)
831 case DC_LOGIN_ERR_SUCCESS:
832 dc_queuecmd(NULL, NULL, L"notify", L"all", L"on", L"fn:peer", L"off", NULL);
833 dc_getfnlistasync(getfnlistcallback, NULL);
834 dc_gettrlistasync(gettrlistcallback, NULL);
835 updatesbar("Authenticated");
837 case DC_LOGIN_ERR_NOLOGIN:
838 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not negotiate an acceptable authentication mechanism"));
842 case DC_LOGIN_ERR_SERVER:
843 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has encountered an error"));
847 case DC_LOGIN_ERR_USER:
848 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Internal client error"));
852 case DC_LOGIN_ERR_CONV:
856 case DC_LOGIN_ERR_AUTHFAIL:
857 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Login attempt failed!"));
865 GtkTreeIter *ref2iter(GtkTreeRowReference *ref)
867 static GtkTreeIter iter;
870 assert((path = gtk_tree_row_reference_get_path(ref)) != NULL);
871 assert(gtk_tree_model_get_iter(GTK_TREE_MODEL(srchmodel), &iter, path));
872 gtk_tree_path_free(path);
876 GtkTreeRowReference *iter2ref(GtkTreeIter *iter)
879 GtkTreeRowReference *ref;
881 assert((path = gtk_tree_model_get_path(GTK_TREE_MODEL(srchmodel), iter)) != NULL);
882 assert((ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(srchmodel), path)) != NULL);
883 gtk_tree_path_free(path);
887 struct srchsize *finddiscsize(void)
892 for(i = 0; i < numsizes; i++)
894 if(srchsizes[i].size == -1)
895 return(&srchsizes[i]);
897 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
898 srchsizes[i].size = -1;
899 srchsizes[i].num = 1;
900 srchsizes[i].slots = 0;
901 srchsizes[i].resptime = 0.0;
902 gtk_tree_store_append(srchmodel, &iter, NULL);
903 gtk_tree_store_set(srchmodel, &iter, 3, _("Discrete sizes"), 7, 1, -1);
904 srchsizes[i].ref = iter2ref(&iter);
905 return(&srchsizes[i]);
908 struct knownspeed *findksentbyname(char *userid)
912 for(i = 0; i < numspeeds; i++)
914 if(!strcmp(knownspeeds[i].userid, userid))
915 return(&knownspeeds[i]);
920 struct knownspeed *findksentbyseq(int seq)
924 for(i = 0; i < numspeeds; i++)
926 if(knownspeeds[i].seq == seq)
927 return(&knownspeeds[i]);
932 gboolean ksupdaterow(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
934 struct knownspeed *ks;
937 gtk_tree_model_get(GTK_TREE_MODEL(model), iter, 1, &userid, -1);
940 ks = findksentbyname(userid);
943 knownspeeds = srealloc(knownspeeds, (numspeeds + 1) * sizeof(*knownspeeds));
944 ks = &knownspeeds[numspeeds];
946 ks->userid = sstrdup(userid);
953 gtk_tree_store_set(GTK_TREE_STORE(model), iter, 8, ks->speed, -1);
957 gint ksupdatecb(gpointer data)
961 wchar_t **users, *buf;
962 size_t userssize, usersdata;
968 for(i = 0; i < numspeeds;)
970 if(now - knownspeeds[i].fetched > 60)
972 free(knownspeeds[i].userid);
973 memmove(&knownspeeds[i], &knownspeeds[i + 1], (--numspeeds - i) * sizeof(*knownspeeds));
978 if(oldnum != numspeeds)
985 knownspeeds = srealloc(knownspeeds, numspeeds * sizeof(*knownspeeds));
988 gtk_tree_model_foreach(GTK_TREE_MODEL(srchmodel), ksupdaterow, NULL);
992 userssize = usersdata = 0;
994 for(i = 0; i < numspeeds; i++)
996 if(knownspeeds[i].seq == -2)
998 assert((buf = icmbstowcs(knownspeeds[i].userid, "UTF-8")) != NULL);
999 knownspeeds[i].seq = ksqueryseq++;
1000 addtobuf(users, buf);
1003 addtobuf(users, NULL);
1004 ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%a", users, NULL);
1005 dc_freewcsarr(users);
1011 void handleresps(void)
1014 struct dc_response *resp;
1015 struct dc_intresp *ires;
1016 struct dc_fnetnode *fn;
1017 struct fndata *fndata;
1019 GtkTreeIter titer, piter;
1022 struct srchsize *ss;
1023 struct knownspeed *ks;
1025 while((resp = dc_getresp()) != NULL)
1027 if(!wcscmp(resp->cmdname, L".connect"))
1029 if(resp->code != 201)
1031 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server refused the connection"));
1034 } else if(dc_checkprotocol(resp, DC_LATEST)) {
1035 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Server protocol revision mismatch"));
1039 tosbuf = 0x10; /* Minimum delay */
1040 setsockopt(dcfd, IPPROTO_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
1041 updatesbar(_("Connected"));
1042 dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
1044 } else if(!wcscmp(resp->cmdname, L".notify")) {
1045 dc_uimisc_handlenotify(resp);
1049 if((ires = dc_interpret(resp)) != NULL)
1051 if((fn = dc_findfnetnode(ires->argv[0].val.num)) != NULL)
1054 gtk_text_buffer_get_end_iter(fndata->textbuf, &iter);
1055 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1057 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, "<", -1, "sender", NULL);
1058 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, buf, -1, "sender", NULL);
1059 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, ">", -1, "sender", NULL);
1060 gtk_text_buffer_insert(fndata->textbuf, &iter, " ", -1);
1063 if((buf = icwcstombs(ires->argv[4].val.str, "UTF-8")) != NULL)
1065 gtk_text_buffer_insert(fndata->textbuf, &iter, buf, -1);
1066 gtk_text_buffer_insert(fndata->textbuf, &iter, "\n", -1);
1068 if(curchat == fn->id)
1069 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(main_chatview), &iter, 0, 0, 0, 0);
1091 updatetransferlists();
1094 if((ires = dc_interpret(resp)) != NULL)
1096 if(ires->argv[0].val.num == nextsrch)
1097 srcheta = time(NULL) + ires->argv[0].val.num;
1102 if((ires = dc_interpret(resp)) != NULL)
1104 if(ires->argv[0].val.num == nextsrch)
1107 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", cursrch, NULL);
1110 gtk_widget_set_sensitive(main_realsrch, TRUE);
1111 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1112 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1113 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1115 gtk_entry_set_text(GTK_ENTRY(main_realsrch), "");
1116 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1117 gtk_tree_store_clear(srchmodel);
1124 if((ires = dc_interpret(resp)) != NULL)
1126 if(ires->argv[0].val.num == cursrch)
1128 for(i = 0; i < numsizes; i++)
1130 if(srchsizes[i].size == ires->argv[4].val.lnum)
1135 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
1136 srchsizes[i].size = (gint64)ires->argv[4].val.lnum;
1137 srchsizes[i].num = 1;
1138 srchsizes[i].slots = ires->argv[5].val.num;
1139 srchsizes[i].resptime = ires->argv[7].val.flnum;
1140 ss = finddiscsize();
1141 ss->slots += ires->argv[5].val.num;
1142 if((ss->resptime == 0.0) || (ss->resptime > ires->argv[7].val.flnum))
1143 ss->resptime = ires->argv[7].val.flnum;
1144 piter = *ref2iter(ss->ref);
1145 gtk_tree_store_set(srchmodel, &piter, 5, ss->slots, 6, ss->resptime, -1);
1146 gtk_tree_store_append(srchmodel, &titer, &piter);
1147 srchsizes[i].ref = iter2ref(&titer);
1148 } else if(srchsizes[i].num == 1) {
1149 char *filename, *peername, *fnetname, *hash;
1153 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);
1154 gtk_tree_store_remove(srchmodel, ref2iter(srchsizes[i].ref));
1155 gtk_tree_row_reference_free(srchsizes[i].ref);
1156 ss = finddiscsize();
1158 gtk_tree_store_set(srchmodel, ref2iter(ss->ref), 5, ss->slots, -1);
1159 gtk_tree_store_append(srchmodel, &piter, NULL);
1160 srchsizes[i].slots = ires->argv[5].val.num + slots;
1161 srchsizes[i].resptime = (ires->argv[7].val.flnum < resptime)?ires->argv[7].val.flnum:resptime;
1162 srchsizes[i].num = 2;
1163 srchsizes[i].ref = iter2ref(&piter);
1164 gtk_tree_store_set(srchmodel, &piter, 4, srchsizes[i].size, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, 2, -1);
1165 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1168 if(strrchr(p, '/') != NULL)
1169 p = strrchr(p, '/') + 1;
1170 gtk_tree_store_set(srchmodel, &piter, 3, p, -1);
1173 gtk_tree_store_append(srchmodel, &titer, &piter);
1174 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);
1175 g_free(filename); g_free(peername); g_free(fnetname); g_free(hash);
1176 gtk_tree_store_append(srchmodel, &titer, &piter);
1179 srchsizes[i].slots += ires->argv[5].val.num;
1180 if(ires->argv[7].val.flnum < srchsizes[i].resptime)
1181 srchsizes[i].resptime = ires->argv[7].val.flnum;
1182 piter = *ref2iter(srchsizes[i].ref);
1183 gtk_tree_store_set(srchmodel, &piter, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, srchsizes[i].num, -1);
1184 gtk_tree_store_append(srchmodel, &titer, &piter);
1186 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1188 gtk_tree_store_set(srchmodel, &titer, 3, buf, -1);
1191 if((buf = icwcstombs(ires->argv[2].val.str, "UTF-8")) != NULL)
1193 gtk_tree_store_set(srchmodel, &titer, 0, buf, -1);
1196 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1198 gtk_tree_store_set(srchmodel, &titer, 1, buf, -1);
1199 gtk_tree_store_set(srchmodel, &titer, 2, buf, -1);
1202 if((buf = icwcstombs(ires->argv[8].val.str, "UTF-8")) != NULL)
1204 gtk_tree_store_set(srchmodel, &titer, 9, buf, -1);
1207 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);
1215 } else if(!wcscmp(resp->cmdname, L"filtercmd")) {
1216 if((ksquerytag >= 0) && (ksquerytag == resp->tag))
1218 for(i = 0; i < resp->numlines; i++)
1220 assert((ks = findksentbyseq(i)) != NULL);
1221 ks->speed = wcstol(resp->rlines[i].argv[1], NULL, 10);
1223 ks->fetched = time(NULL);
1227 } else if((lsrestag >= 0) && (lsrestag == resp->tag)) {
1228 for(i = 0; i < resp->numlines; i++)
1230 if(!wcsncmp(resp->rlines[i].argv[1], L"id:", 3))
1232 gtk_list_store_append(reslist, &titer);
1233 gtk_list_store_set(reslist, &titer, 0, icswcstombs(resp->rlines[i].argv[1] + 3, "UTF-8", NULL), -1);
1234 } else if(!wcsncmp(resp->rlines[i].argv[1], L"size:", 5)) {
1235 gtk_list_store_set(reslist, &titer, 1, (gint64)wcstoll(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1236 } else if(!wcsncmp(resp->rlines[i].argv[1], L"prog:", 5)) {
1237 gtk_list_store_set(reslist, &titer, 2, (gint64)wcstoll(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1238 } else if(!wcsncmp(resp->rlines[i].argv[1], L"name:", 5)) {
1239 gtk_list_store_set(reslist, &titer, 3, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1240 } else if(!wcsncmp(resp->rlines[i].argv[1], L"lock:", 5)) {
1241 if(!wcscmp(resp->rlines[i].argv[1] + 5, L"yes"))
1242 gtk_list_store_set(reslist, &titer, 4, TRUE, -1);
1244 gtk_list_store_set(reslist, &titer, 4, FALSE, -1);
1245 } else if(!wcsncmp(resp->rlines[i].argv[1], L"hash:", 5)) {
1246 gtk_list_store_set(reslist, &titer, 5, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1250 gtk_widget_set_sensitive(reslist_reload, TRUE);
1258 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition)
1262 if(((condition & GDK_INPUT_READ) && dc_handleread()) || ((condition & GDK_INPUT_WRITE) && dc_handlewrite()))
1268 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has closed the connection"));
1270 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The connection to the server failed:\n\n%s"), strerror(errnobak));
1277 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data)
1285 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data)
1287 GtkWidget *dialog, *swnd;
1290 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);
1291 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), swnd = create_pref_wnd(), TRUE, TRUE, 0);
1292 gtk_entry_set_text(GTK_ENTRY(pref_pubhuburl), pubhubaddr);
1293 gtk_entry_set_text(GTK_ENTRY(pref_connectas), connectas);
1294 gtk_entry_set_text(GTK_ENTRY(pref_dcserver), dcserver);
1295 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref_autoconn), autoconn);
1296 gtk_widget_show(swnd);
1297 resp = gtk_dialog_run(GTK_DIALOG(dialog));
1298 if(resp == GTK_RESPONSE_ACCEPT)
1301 pubhubaddr = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_pubhuburl)));
1303 connectas = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_connectas)));
1305 dcserver = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_dcserver)));
1306 autoconn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_autoconn));
1308 gtk_widget_destroy(dialog);
1311 void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
1313 gtk_list_store_clear(reslist);
1314 gtk_widget_set_sensitive(reslist_delete, FALSE);
1315 gtk_widget_set_sensitive(reslist_search, FALSE);
1316 gtk_widget_show(reslist_wnd);
1319 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
1320 gtk_widget_set_sensitive(reslist_reload, FALSE);
1325 void dcconnect(char *host)
1327 dcfd = dc_connect(host);
1330 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect:\n\n%s"), strerror(errno));
1333 gdkread = gdk_input_add(dcfd, GDK_INPUT_READ, dcfdcallback, NULL);
1335 gtk_widget_set_sensitive(main_connmenu, FALSE);
1336 gtk_widget_set_sensitive(main_dconnmenu, TRUE);
1337 updatesbar(_("Connecting..."));
1340 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data)
1346 if((buf = inputbox(_("Connect"), _("Server address:"), dcserver, 1)) == NULL)
1352 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data)
1355 struct dc_response *resp;
1359 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1362 tag = dc_queuecmd(NULL, NULL, L"shutdown", NULL);
1363 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1365 if(resp->code == 502)
1366 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1372 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
1375 struct dc_response *resp;
1380 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1383 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_fnaddr)), "UTF-8", NULL));
1386 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Illegal address entered"));
1389 if(wcschr(toks[0], L':') == NULL)
1391 toks[0] = srealloc(toks[0], (wcslen(toks[0]) + 5) * sizeof(wchar_t));
1392 wcscat(toks[0], L":411");
1394 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%a", toks, NULL);
1395 dc_freewcsarr(toks);
1396 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1398 if(resp->code == 502)
1399 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1400 if(resp->code == 509)
1401 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1402 if(resp->code == 515)
1403 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1406 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1410 void setpubhubmodel(GtkTreeModel *model, int sortcol, int numcols, int *cols, char **names)
1412 GtkTreeViewColumn *col;
1413 GtkCellRenderer *rnd;
1414 GtkTreeModel *sortmodel;
1417 while((col = gtk_tree_view_get_column(GTK_TREE_VIEW(main_phublist), 0)) != NULL)
1418 gtk_tree_view_remove_column(GTK_TREE_VIEW(main_phublist), col);
1419 for(i = 0; i < numcols; i++) {
1420 if(gtk_tree_model_get_column_type(model, cols[i]) == G_TYPE_INT64)
1422 col = gtk_tree_view_column_new();
1423 gtk_tree_view_column_set_title(col, names[i]);
1424 rnd = gtk_cell_renderer_text_new();
1425 gtk_tree_view_column_pack_start(col, rnd, TRUE);
1426 gtk_tree_view_column_set_cell_data_func(col, rnd, transnicebytefunc2, GINT_TO_POINTER(cols[i]), NULL);
1428 col = gtk_tree_view_column_new_with_attributes(names[i], gtk_cell_renderer_text_new(), "text", cols[i], NULL);
1430 gtk_tree_view_column_set_sort_column_id(col, cols[i]);
1431 gtk_tree_view_column_set_resizable(col, TRUE);
1432 gtk_tree_view_append_column(GTK_TREE_VIEW(main_phublist), col);
1434 sortmodel = gtk_tree_model_sort_new_with_model(model);
1435 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), sortcol, GTK_SORT_DESCENDING);
1436 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), sortmodel);
1437 g_object_unref(sortmodel);
1440 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
1447 buf = gtk_entry_get_text(GTK_ENTRY(main_pubhubfilter));
1450 filter = smalloc(sizeof(*filter));
1451 if((err = regcomp(filter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
1453 regerror(err, filter, errbuf, sizeof(errbuf));
1454 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not compile regex: %s", errbuf);
1462 fetchhublist(pubhubaddr, filter);
1465 void cb_main_pubhubabort_clicked(GtkWidget *widget, gpointer data)
1470 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
1474 struct dc_response *resp;
1478 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1481 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_fnetnodes)), NULL, &iter))
1483 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1486 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1487 tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%i", id, NULL);
1488 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1490 if(resp->code == 502)
1491 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1497 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data)
1500 GtkTreeModel *model;
1503 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_phublist)), &model, &iter))
1505 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &addr, -1);
1506 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), addr);
1510 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1513 struct dc_response *resp;
1515 GtkTreeModel *model;
1520 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1523 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1524 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1526 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &buf, -1);
1527 if(strchr(buf, ':') == NULL)
1529 buf = g_realloc(buf, strlen(buf) + 5);
1530 strcat(buf, ":411");
1532 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%s", buf, NULL);
1534 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1535 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1537 if(resp->code == 502)
1538 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1539 if(resp->code == 509)
1540 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1541 if(resp->code == 515)
1542 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1548 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer uudata)
1552 struct dc_fnetnode *fn;
1553 struct fndata *data;
1555 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(fnmodel), &iter, path))
1557 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1558 if((fn = dc_findfnetnode(id)) == NULL)
1562 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
1566 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1568 gtk_list_store_set(fnmodel, &iter, 5, "gtk-apply", -1);
1570 gtk_list_store_set(fnmodel, &iter, 5, NULL, -1);
1571 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
1573 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), GTK_TEXT_BUFFER(data->textbuf));
1576 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data)
1580 struct dc_response *resp;
1584 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1589 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1592 buf = gtk_entry_get_text(GTK_ENTRY(main_chatstr));
1593 tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%i", curchat, L"1", L"", L"%s", buf, NULL);
1594 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1596 if(resp->code == 502)
1597 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1598 else if(resp->code == 504)
1599 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub could not support all the types of characters in your chat message"));
1600 else if(resp->code == 513)
1601 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub does not support chatting"));
1602 else if(resp->code != 200)
1603 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to chat (%i)"), resp->code);
1606 gtk_entry_set_text(GTK_ENTRY(main_chatstr), "");
1610 void updatesrchfld(const char *simple)
1614 size_t bufsize, bufdata;
1616 s = sstrdup(simple);
1618 bufsize = bufdata = 0;
1622 p2 = strchr(p, ' ');
1628 bufcat(buf, " & ", 3);
1629 bufcat(buf, "N~", 2);
1632 if(strchr("[]()$^.*?+\\|\"!", *p) != NULL)
1633 addtobuf(buf, '\\');
1638 } while(p2 != NULL);
1640 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1645 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data)
1650 updatesrchfld(gtk_entry_get_text(GTK_ENTRY(main_simplesrch)));
1654 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data)
1659 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1663 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data)
1667 struct dc_response *resp;
1668 struct dc_intresp *ires;
1672 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1675 if(nextsrch != -1) /* Impossible case, but oh well... */
1677 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_realsrch)), "UTF-8", NULL));
1680 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Please enter a search expression before searching"));
1683 tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%a", toks, NULL);
1684 dc_freewcsarr(toks);
1685 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1687 if(resp->code == 501)
1688 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not find any hubs to search on"));
1689 else if(resp->code == 502)
1690 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1691 else if(resp->code == 509)
1692 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse your search expression"));
1693 else if(resp->code != 200)
1694 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to search (%i)"), resp->code);
1695 if(resp->code == 200)
1697 if((ires = dc_interpret(resp)) != NULL)
1699 nextsrch = ires->argv[0].val.num;
1700 srcheta = time(NULL) + ires->argv[1].val.num;
1703 gtk_widget_set_sensitive(main_realsrch, FALSE);
1704 gtk_widget_set_sensitive(main_simplesrch, FALSE);
1705 gtk_widget_set_sensitive(main_srchbtn, FALSE);
1706 gtk_widget_set_sensitive(main_srchcanbtn, TRUE);
1714 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data)
1718 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", nextsrch, NULL);
1720 gtk_widget_set_sensitive(main_realsrch, TRUE);
1721 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1722 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1723 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1727 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
1730 GtkTreeSelection *sel;
1731 GtkTreeModel *model;
1733 struct dc_response *resp;
1735 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
1737 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1738 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1740 gtk_tree_model_get(model, &iter, 0, &id, -1);
1741 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1742 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1744 if(resp->code == 502)
1745 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1746 else if(resp->code != 200)
1747 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1757 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1760 struct dc_response *resp;
1762 GtkTreeModel *model;
1765 char *tfnet, *tpeerid, *tfilename, *thash, *arg;
1766 wchar_t *fnet, *peerid, *filename, *hash;
1770 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1773 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1774 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1776 gtk_tree_model_get(model, &iter, 7, &num, -1);
1779 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &tfnet, 1, &tpeerid, 3, &tfilename, 4, &size, 9, &thash, -1);
1780 fnet = icmbstowcs(tfnet, "UTF-8");
1781 peerid = icmbstowcs(tpeerid, "UTF-8");
1782 filename = icmbstowcs(tfilename, "UTF-8");
1783 hash = (thash == NULL)?NULL:icmbstowcs(thash, "UTF-8");
1784 if((fnet == NULL) || (peerid == NULL) || (filename == NULL))
1790 if(filename != NULL)
1804 arg = (char *)gtk_entry_get_text(GTK_ENTRY(main_dlarg));
1806 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);
1808 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);
1814 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1816 if(resp->code == 502)
1817 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1818 if(resp->code != 200)
1819 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to queue the download (%i)"), resp->code);
1825 gboolean srchfilterfunc(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1830 filteratall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots));
1833 gtk_tree_model_get(model, iter, 5, &slots, -1);
1839 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data)
1841 gtk_tree_model_filter_refilter(srchmodelfilter);
1844 void cb_main_srhash_activate(GtkWidget *widget, gpointer data)
1846 GtkTreeSelection *sel;
1847 GtkTreeModel *model;
1853 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1854 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1856 gtk_tree_model_get(model, &iter, 9, &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_srcopy_activate(GtkWidget *widget, gpointer data)
1870 GtkTreeSelection *sel;
1871 GtkTreeModel *model;
1877 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1878 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1880 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1881 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1882 gtk_clipboard_set_text(cb, hash, -1);
1886 void cb_main_trhash_activate(GtkWidget *widget, gpointer data)
1888 GtkTreeSelection *sel;
1889 GtkTreeModel *model;
1895 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1896 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1898 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1899 buf = sprintf2("H=%s", hash);
1900 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1903 cb_main_srchbtn_clicked(widget, NULL);
1909 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data)
1912 GtkTreeSelection *sel;
1913 GtkTreeModel *model;
1917 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1918 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1920 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1921 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1922 gtk_clipboard_set_text(cb, hash, -1);
1926 void cb_main_trreset_activate(GtkWidget *widget, gpointer data)
1928 GtkTreeSelection *sel;
1929 GtkTreeModel *model;
1932 struct dc_response *resp;
1934 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1935 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1937 gtk_tree_model_get(model, &iter, 0, &id, -1);
1938 tag = dc_queuecmd(NULL, NULL, L"reset", L"%i", id, NULL);
1939 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1941 if(resp->code == 502)
1942 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1943 else if(resp->code != 200)
1944 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to reset (%i)"), resp->code);
1953 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
1955 GtkTreeSelection *sel;
1956 GtkTreeModel *model;
1959 struct dc_response *resp;
1961 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1962 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1964 gtk_tree_model_get(model, &iter, 0, &id, -1);
1965 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1966 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1968 if(resp->code == 502)
1969 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1970 else if(resp->code != 200)
1971 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1980 /* XXX: This is quite a hack, since the calling convention is
1981 * different for the popup-menu sig and the button-press-event sig. It
1982 * most certainly works, but I don't know how portable it is. */
1983 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
1985 GtkTreeSelection *sel;
1986 GtkTreeModel *model;
1990 if((event != NULL) && (event->button != 3))
1992 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1993 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1995 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1996 if((hash == NULL) || (*hash == 0))
1998 gtk_widget_set_sensitive(main_srhash, FALSE);
1999 gtk_widget_set_sensitive(main_srcopy, FALSE);
2002 gtk_widget_set_sensitive(main_srhash, TRUE);
2004 gtk_widget_set_sensitive(main_srhash, FALSE);
2005 gtk_widget_set_sensitive(main_srcopy, TRUE);
2012 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2014 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2018 /* The above hack note goes for this one too. */
2019 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
2021 GtkTreeSelection *sel;
2022 GtkTreeModel *model;
2026 if((event != NULL) && (event->button != 3))
2028 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2029 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2031 gtk_tree_model_get(model, &iter, 12, &hash, -1);
2032 if((hash == NULL) || (*hash == 0))
2034 gtk_widget_set_sensitive(main_trhash, FALSE);
2035 gtk_widget_set_sensitive(main_trcopy, FALSE);
2038 gtk_widget_set_sensitive(main_trhash, TRUE);
2040 gtk_widget_set_sensitive(main_trhash, FALSE);
2041 gtk_widget_set_sensitive(main_trcopy, TRUE);
2048 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2050 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2054 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data)
2058 gtk_widget_set_sensitive(reslist_delete, FALSE);
2059 gtk_widget_set_sensitive(reslist_search, FALSE);
2060 gtk_list_store_clear(reslist);
2061 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
2062 gtk_widget_set_sensitive(reslist_reload, FALSE);
2069 struct dc_response *resp;
2072 tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%s", id, NULL);
2073 if((resp = dc_gettaggedrespsync(tag)) != NULL)
2075 if(resp->numlines > 0)
2077 if(!wcscmp(resp->rlines[0].argv[1], L"ok"))
2079 else if(!wcsncmp(resp->rlines[0].argv[1], L"err:", 4))
2080 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred (%ls)"), resp->rlines[0].argv[1] + 4);
2088 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data)
2091 GtkTreeModel *model;
2097 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2099 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &id, 4, &locked, -1);
2106 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2110 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data)
2113 GtkTreeModel *model;
2118 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2120 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 5, &hash, -1);
2121 buf = sprintf2("H=%s", hash);
2122 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2125 cb_main_srchbtn_clicked(widget, NULL);
2128 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data)
2131 GtkTreeModel *model;
2135 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2137 gtk_widget_set_sensitive(reslist_delete, FALSE);
2138 gtk_widget_set_sensitive(reslist_search, FALSE);
2141 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 4, &locked, 5, &hash, -1);
2142 gtk_widget_set_sensitive(reslist_delete, !locked);
2143 gtk_widget_set_sensitive(reslist_search, hash && *hash);
2147 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
2150 GtkTreeModel *model;
2153 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
2154 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
2158 gtk_tree_model_get(model, &iter, 5, &hash, -1);
2159 buf = sprintf2("H=%s", hash);
2160 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2163 cb_main_srchbtn_clicked(widget, NULL);
2166 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
2168 GtkTreeSelection *sel;
2169 GtkTreeModel *model;
2174 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
2176 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2177 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2179 gtk_tree_model_get(model, &iter, 0, &id, 4, &locked, -1);
2183 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2192 void srchstatupdate(void)
2198 snprintf(buf, 1024, _("Ready to search"));
2200 snprintf(buf, 1024, _("Search scheduled and will be submitted in %i seconds"), (int)(srcheta - time(NULL)));
2202 if(strcmp(gtk_label_get_text(GTK_LABEL(main_srchstatus)), buf))
2203 gtk_label_set_text(GTK_LABEL(main_srchstatus), buf);
2206 gint srchstatupdatecb(gpointer data)
2212 void initchattags(void)
2216 chattags = gtk_text_tag_table_new();
2217 tag = gtk_text_tag_new("sender");
2218 g_object_set(tag, "foreground", "blue", NULL);
2219 gtk_text_tag_table_add(chattags, tag);
2222 #include "../dolda-icon.xpm"
2224 int main(int argc, char **argv)
2228 PangoFontDescription *monospacefont;
2229 GtkTreeModel *sortmodel;
2230 struct passwd *pwent;
2232 setlocale(LC_ALL, "");
2233 bindtextdomain(PACKAGE, LOCALEDIR);
2234 textdomain(PACKAGE);
2235 gtk_init(&argc, &argv);
2237 while((c = getopt(argc, argv, "lhV")) != -1) {
2243 printf("usage: dolcon [-hlV]\n");
2244 printf("\t-h\tDisplay this help message\n");
2245 printf("\t-l\tConnect to the locally running daemon\n");
2246 printf("\t-V\tDisplay version info and exit\n");
2249 printf("%s", RELEASEINFO);
2252 fprintf(stderr, "usage: dolcon [-hlV]\n");
2257 signal(SIGCHLD, SIG_IGN);
2258 pubhubaddr = sstrdup("http://dchublist.com/hublist.xml.bz2");
2259 dcserver = sstrdup("");
2260 if((pwent = getpwuid(getuid())) == NULL)
2262 fprintf(stderr, "could not get your passwd data");
2265 connectas = sstrdup(pwent->pw_name);
2266 gtk_window_set_default_icon(gdk_pixbuf_new_from_xpm_data((const char **)dolda_icon_xpm));
2267 wnd = create_main_wnd();
2268 create_reslist_wnd();
2269 gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400);
2272 fnmodel = gtk_list_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
2273 gtk_tree_view_set_model(GTK_TREE_VIEW(main_fnetnodes), GTK_TREE_MODEL(fnmodel));
2274 gtk_tree_view_set_model(GTK_TREE_VIEW(main_chatnodes), GTK_TREE_MODEL(fnmodel));
2276 reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
2277 gtk_tree_view_set_model(GTK_TREE_VIEW(reslist_list), GTK_TREE_MODEL(reslist));
2279 dlmodel = gtk_list_store_new(13, G_TYPE_INT, /* id */
2280 G_TYPE_INT, /* dir */
2281 G_TYPE_INT, /* state */
2282 G_TYPE_STRING, /* peerid */
2283 G_TYPE_STRING, /* peernick */
2284 G_TYPE_STRING, /* path */
2285 G_TYPE_INT64, /* size */
2286 G_TYPE_INT64, /* curpos */
2287 G_TYPE_STRING, /* stock */
2288 G_TYPE_FLOAT, /* percentage */
2289 G_TYPE_INT, /* error */
2290 G_TYPE_INT64, /* errortime */
2291 G_TYPE_STRING); /* hash */
2292 gtk_tree_view_set_model(GTK_TREE_VIEW(main_downloads), GTK_TREE_MODEL(dlmodel));
2294 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);
2295 gtk_tree_view_set_model(GTK_TREE_VIEW(main_uploads), GTK_TREE_MODEL(ulmodel));
2297 srchmodel = gtk_tree_store_new(10, G_TYPE_STRING, /* fnetname */
2298 G_TYPE_STRING, /* peerid */
2299 G_TYPE_STRING, /* peername */
2300 G_TYPE_STRING, /* filename */
2301 G_TYPE_INT64, /* size */
2302 G_TYPE_INT, /* slots */
2303 G_TYPE_DOUBLE, /* resptime */
2304 G_TYPE_INT, /* sizenum */
2305 G_TYPE_INT, /* speed */
2306 G_TYPE_STRING); /* hash */
2307 srchmodelfilter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(srchmodel), NULL));
2308 gtk_tree_model_filter_set_visible_func(srchmodelfilter, srchfilterfunc, NULL, NULL);
2309 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(srchmodelfilter));
2310 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 4, GTK_SORT_DESCENDING);
2311 gtk_tree_view_set_model(GTK_TREE_VIEW(main_srchres), GTK_TREE_MODEL(sortmodel));
2312 g_object_unref(sortmodel);
2314 monospacefont = pango_font_description_from_string("Monospace 10");
2315 gtk_widget_modify_font(main_chatview, monospacefont);
2316 pango_font_description_free(monospacefont);
2318 updatesbar(_("Disconnected"));
2319 gtk_widget_show(wnd);
2321 dcconnect(dc_srv_local);
2323 dcconnect(dcserver);
2324 g_timeout_add(500, srchstatupdatecb, NULL);
2325 g_timeout_add(5000, ksupdatecb, NULL);
2326 g_timeout_add(1000, updatetransfers, NULL);
2331 #include "mainwnd.gtk"
2332 #include "inpdialog.gtk"
2334 #include "reslist.gtk"