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(&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;
485 GtkListStore *stores[3];
487 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
489 stores[DC_TRNSD_UNKNOWN] = NULL;
490 stores[DC_TRNSD_UP] = ulmodel;
491 stores[DC_TRNSD_DOWN] = dlmodel;
492 for(i = 0; i < 3; i++)
494 if(stores[i] == NULL)
500 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(stores[i]), &iter))
504 gtk_tree_model_get(GTK_TREE_MODEL(stores[i]), &iter, 0, &id, 1, &dir, -1);
505 if(((transfer = dc_findtransfer(id)) == NULL) || (transfer->dir != dir))
507 gtk_list_store_remove(stores[i], &iter);
512 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);
513 if(state != transfer->state)
514 gtk_list_store_set(stores[i], &iter, 2, transfer->state, 8, gettrstatestock(transfer->state), -1);
515 if(size != transfer->size)
516 gtk_list_store_set(stores[i], &iter, 6, (gint64)transfer->size, -1);
517 if(curpos != transfer->curpos)
519 gtk_list_store_set(stores[i], &iter, 7, (gint64)transfer->curpos, -1);
520 if(transfer->udata != NULL)
521 updatetrdata(transfer);
523 if(error != transfer->error)
524 gtk_list_store_set(stores[i], &iter, 10, transfer->error, -1);
525 if(errortime != transfer->errortime)
526 gtk_list_store_set(stores[i], &iter, 11, transfer->errortime, -1);
527 if((transfer->size > 0) && (transfer->curpos > 0))
528 gtk_list_store_set(stores[i], &iter, 9, (float)transfer->curpos / (float)transfer->size, -1);
529 buf = icswcstombs(transfer->peerid, "UTF-8", NULL);
530 if(strcmp(buf, peerid))
531 gtk_list_store_set(stores[i], &iter, 3, buf, -1);
532 buf = icswcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8", NULL);
533 if(strcmp(buf, peernick))
534 gtk_list_store_set(stores[i], &iter, 4, buf, -1);
535 buf = (transfer->path == NULL)?_("Unknown"):icswcstombs(transfer->path, "UTF-8", NULL);
536 if(strcmp(buf, path))
537 gtk_list_store_set(stores[i], &iter, 5, buf, -1);
538 buf = (transfer->hash == NULL)?"":icswcstombs(transfer->hash, "UTF-8", NULL);
539 if(strcmp(buf, path))
540 gtk_list_store_set(stores[i], &iter, 12, buf, -1);
546 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(stores[i]), &iter));
550 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
554 if(stores[transfer->dir] != NULL)
556 peerid = icwcstombs(transfer->peerid, "UTF-8");
557 peernick = icwcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8");
558 path = (transfer->path == NULL)?_("Unknown"):icwcstombs(transfer->path, "UTF-8");
559 hash = (transfer->hash == NULL)?"":icwcstombs(transfer->hash, "UTF-8");
560 gtk_list_store_append(stores[transfer->dir], &iter);
561 gtk_list_store_set(stores[transfer->dir], &iter,
568 6, (gint64)transfer->size,
569 7, (gint64)transfer->curpos,
570 8, gettrstatestock(transfer->state),
573 11, transfer->errortime,
578 if(transfer->path != NULL)
580 if(transfer->hash != NULL)
588 void updatesbar(char *msg)
590 gtk_statusbar_pop(GTK_STATUSBAR(main_statusbar), 0);
591 gtk_statusbar_push(GTK_STATUSBAR(main_statusbar), 0, msg);
594 void freesrchsizes(void)
598 for(i = 0; i < numsizes; i++)
600 if(srchsizes[i].ref != NULL)
601 gtk_tree_row_reference_free(srchsizes[i].ref);
603 if(srchsizes != NULL)
609 void dcdisconnected(void)
613 gdk_input_remove(gdkread);
618 updatetransferlists();
619 cursrch = nextsrch = -1;
620 gtk_tree_store_clear(srchmodel);
622 gtk_widget_set_sensitive(main_connmenu, TRUE);
623 gtk_widget_set_sensitive(main_dconnmenu, FALSE);
624 gtk_widget_set_sensitive(main_simplesrch, TRUE);
625 gtk_widget_set_sensitive(main_realsrch, TRUE);
626 gtk_widget_set_sensitive(main_srchbtn, TRUE);
627 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
628 updatesbar(_("Disconnected"));
631 char *inputbox(char *title, char *prompt, char *def, int echo)
637 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);
638 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(inpdialog)->vbox), swnd = create_inpdialog_wnd(), TRUE, TRUE, 0);
639 gtk_widget_show(swnd);
641 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), FALSE);
642 gtk_label_set_text(GTK_LABEL(inpdialog_prompt), prompt);
643 gtk_entry_set_text(GTK_ENTRY(inpdialog_entry), def);
644 resp = gtk_dialog_run(GTK_DIALOG(inpdialog));
646 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), TRUE);
647 if(resp == GTK_RESPONSE_ACCEPT)
648 buf = strdup(gtk_entry_get_text(GTK_ENTRY(inpdialog_entry)));
651 gtk_widget_destroy(inpdialog);
656 int msgbox(int type, int buttons, char *format, ...)
663 va_start(args, format);
664 buf = vsprintf2(format, args);
666 swnd = gtk_message_dialog_new(GTK_WINDOW(main_wnd), GTK_DIALOG_MODAL, type, buttons, "%s", buf);
667 resp = gtk_dialog_run(GTK_DIALOG(swnd));
668 gtk_widget_destroy(swnd);
673 void readconfigfile(void)
676 char *homedir, *buf, *p;
679 if((homedir = getenv("HOME")) == NULL)
681 fprintf(stderr, "warning: could not find home directory!\n");
684 buf = sprintf2("%s/.dolconrc", homedir);
685 if((cfgfile = fopen(buf, "r")) == NULL)
694 while(fgets(buf, 1024, cfgfile) != NULL)
698 p = buf + strlen(buf);
701 if((p = strchr(buf, ':')) == NULL)
704 while((*p == ' ') || (*p == '\t'))
706 if(!strcmp(buf, "wnd-width"))
709 } else if(!strcmp(buf, "wnd-height")) {
711 } else if(!strcmp(buf, "pane1-pos")) {
712 gtk_paned_set_position(GTK_PANED(main_pane1), atoi(p));
713 } else if(!strcmp(buf, "pane2-pos")) {
714 gtk_paned_set_position(GTK_PANED(main_pane2), atoi(p));
715 } else if(!strcmp(buf, "pane3-pos")) {
716 gtk_paned_set_position(GTK_PANED(main_pane3), atoi(p));
717 } else if(!strcmp(buf, "pubhubaddr")) {
719 pubhubaddr = sstrdup(p);
720 } else if(!strcmp(buf, "dcserver")) {
722 dcserver = sstrdup(p);
723 } else if(!strcmp(buf, "advexpanded")) {
724 gtk_expander_set_expanded(GTK_EXPANDER(main_advexp), atoi(p));
725 } else if(!strcmp(buf, "connectas")) {
727 connectas = sstrdup(p);
728 } else if(!strcmp(buf, "autoconn")) {
730 } else if(!strcmp(buf, "filternoslots")) {
731 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(main_filternoslots), atoi(p));
740 gtk_window_resize(GTK_WINDOW(main_wnd), w, h);
743 void updateconfigfile(void)
749 if((homedir = getenv("HOME")) == NULL)
751 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not get your home directory!"));
754 buf = sprintf2("%s/.dolconrc", homedir);
755 if((cfgfile = fopen(buf, "w")) == NULL)
758 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not open configuration file for writing: %s"), strerror(errno));
762 gtk_window_get_size(GTK_WINDOW(main_wnd), &w, &h);
763 fprintf(cfgfile, "wnd-width: %i\n", w);
764 fprintf(cfgfile, "wnd-height: %i\n", h);
765 fprintf(cfgfile, "pane1-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane1)));
766 fprintf(cfgfile, "pane2-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane2)));
767 fprintf(cfgfile, "pane3-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane3)));
768 fprintf(cfgfile, "pubhubaddr: %s\n", pubhubaddr);
769 fprintf(cfgfile, "dcserver: %s\n", dcserver);
770 fprintf(cfgfile, "advexpanded: %i\n", gtk_expander_get_expanded(GTK_EXPANDER(main_advexp)));
771 fprintf(cfgfile, "connectas: %s\n", connectas);
772 fprintf(cfgfile, "autoconn: %i\n", autoconn);
773 fprintf(cfgfile, "filternoslots: %i\n", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots)));
777 gboolean initdeath(GtkWidget *widget, gpointer data)
784 void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data)
786 gtk_dialog_response(GTK_DIALOG(inpdialog), GTK_RESPONSE_ACCEPT);
789 int loginconv(int type, wchar_t *prompt, char **resp, void *data)
795 buf = icwcstombs(prompt, "UTF-8");
798 case DC_LOGIN_CONV_NOECHO:
799 if((*resp = inputbox(_("Login"), buf, "", 0)) == NULL)
802 case DC_LOGIN_CONV_ECHO:
803 if((*resp = inputbox(_("Login"), buf, "", 1)) == NULL)
806 case DC_LOGIN_CONV_INFO:
807 msgbox(GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", buf);
809 case DC_LOGIN_CONV_ERROR:
810 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", buf);
818 void getfnlistcallback(int resp, void *data)
823 void gettrlistcallback(int resp, void *data)
825 updatetransferlists();
828 void logincallback(int err, wchar_t *reason, void *data)
832 case DC_LOGIN_ERR_SUCCESS:
833 dc_queuecmd(NULL, NULL, L"notify", L"all", L"on", L"fn:peer", L"off", NULL);
834 dc_getfnlistasync(getfnlistcallback, NULL);
835 dc_gettrlistasync(gettrlistcallback, NULL);
836 updatesbar("Authenticated");
838 case DC_LOGIN_ERR_NOLOGIN:
839 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not negotiate an acceptable authentication mechanism"));
843 case DC_LOGIN_ERR_SERVER:
844 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has encountered an error"));
848 case DC_LOGIN_ERR_USER:
849 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Internal client error"));
853 case DC_LOGIN_ERR_CONV:
857 case DC_LOGIN_ERR_AUTHFAIL:
858 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Login attempt failed!"));
866 GtkTreeIter *ref2iter(GtkTreeRowReference *ref)
868 static GtkTreeIter iter;
871 assert((path = gtk_tree_row_reference_get_path(ref)) != NULL);
872 assert(gtk_tree_model_get_iter(GTK_TREE_MODEL(srchmodel), &iter, path));
873 gtk_tree_path_free(path);
877 GtkTreeRowReference *iter2ref(GtkTreeIter *iter)
880 GtkTreeRowReference *ref;
882 assert((path = gtk_tree_model_get_path(GTK_TREE_MODEL(srchmodel), iter)) != NULL);
883 assert((ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(srchmodel), path)) != NULL);
884 gtk_tree_path_free(path);
888 struct srchsize *finddiscsize(void)
893 for(i = 0; i < numsizes; i++)
895 if(srchsizes[i].size == -1)
896 return(&srchsizes[i]);
898 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
899 srchsizes[i].size = -1;
900 srchsizes[i].num = 1;
901 srchsizes[i].slots = 0;
902 srchsizes[i].resptime = 0.0;
903 gtk_tree_store_append(srchmodel, &iter, NULL);
904 gtk_tree_store_set(srchmodel, &iter, 3, _("Discrete sizes"), 7, 1, -1);
905 srchsizes[i].ref = iter2ref(&iter);
906 return(&srchsizes[i]);
909 struct knownspeed *findksentbyname(char *userid)
913 for(i = 0; i < numspeeds; i++)
915 if(!strcmp(knownspeeds[i].userid, userid))
916 return(&knownspeeds[i]);
921 struct knownspeed *findksentbyseq(int seq)
925 for(i = 0; i < numspeeds; i++)
927 if(knownspeeds[i].seq == seq)
928 return(&knownspeeds[i]);
933 gboolean ksupdaterow(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
935 struct knownspeed *ks;
938 gtk_tree_model_get(GTK_TREE_MODEL(model), iter, 1, &userid, -1);
941 ks = findksentbyname(userid);
944 knownspeeds = srealloc(knownspeeds, (numspeeds + 1) * sizeof(*knownspeeds));
945 ks = &knownspeeds[numspeeds];
947 ks->userid = sstrdup(userid);
954 gtk_tree_store_set(GTK_TREE_STORE(model), iter, 8, ks->speed, -1);
958 gint ksupdatecb(gpointer data)
962 wchar_t **users, *buf;
963 size_t userssize, usersdata;
969 for(i = 0; i < numspeeds;)
971 if(now - knownspeeds[i].fetched > 60)
973 free(knownspeeds[i].userid);
974 memmove(&knownspeeds[i], &knownspeeds[i + 1], (--numspeeds - i) * sizeof(*knownspeeds));
979 if(oldnum != numspeeds)
986 knownspeeds = srealloc(knownspeeds, numspeeds * sizeof(*knownspeeds));
989 gtk_tree_model_foreach(GTK_TREE_MODEL(srchmodel), ksupdaterow, NULL);
993 userssize = usersdata = 0;
995 for(i = 0; i < numspeeds; i++)
997 if(knownspeeds[i].seq == -2)
999 assert((buf = icmbstowcs(knownspeeds[i].userid, "UTF-8")) != NULL);
1000 knownspeeds[i].seq = ksqueryseq++;
1001 addtobuf(users, buf);
1004 addtobuf(users, NULL);
1005 ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%a", users, NULL);
1006 dc_freewcsarr(users);
1012 void handleresps(void)
1015 struct dc_response *resp;
1016 struct dc_intresp *ires;
1017 struct dc_fnetnode *fn;
1018 struct fndata *fndata;
1020 GtkTreeIter titer, piter;
1023 struct srchsize *ss;
1024 struct knownspeed *ks;
1026 while((resp = dc_getresp()) != NULL)
1028 if(!wcscmp(resp->cmdname, L".connect"))
1030 if(resp->code != 201)
1032 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server refused the connection"));
1035 } else if(dc_checkprotocol(resp, DC_LATEST)) {
1036 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Server protocol revision mismatch"));
1040 tosbuf = 0x10; /* Minimum delay */
1041 setsockopt(dcfd, IPPROTO_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
1042 updatesbar(_("Connected"));
1043 dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
1045 } else if(!wcscmp(resp->cmdname, L".notify")) {
1046 dc_uimisc_handlenotify(resp);
1050 if((ires = dc_interpret(resp)) != NULL)
1052 if((fn = dc_findfnetnode(ires->argv[0].val.num)) != NULL)
1055 gtk_text_buffer_get_end_iter(fndata->textbuf, &iter);
1056 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1058 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, "<", -1, "sender", NULL);
1059 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, buf, -1, "sender", NULL);
1060 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, ">", -1, "sender", NULL);
1061 gtk_text_buffer_insert(fndata->textbuf, &iter, " ", -1);
1064 if((buf = icwcstombs(ires->argv[4].val.str, "UTF-8")) != NULL)
1066 gtk_text_buffer_insert(fndata->textbuf, &iter, buf, -1);
1067 gtk_text_buffer_insert(fndata->textbuf, &iter, "\n", -1);
1069 if(curchat == fn->id)
1070 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(main_chatview), &iter, 0, 0, 0, 0);
1092 updatetransferlists();
1095 if((ires = dc_interpret(resp)) != NULL)
1097 if(ires->argv[0].val.num == nextsrch)
1098 srcheta = time(NULL) + ires->argv[0].val.num;
1103 if((ires = dc_interpret(resp)) != NULL)
1105 if(ires->argv[0].val.num == nextsrch)
1108 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", cursrch, NULL);
1111 gtk_widget_set_sensitive(main_realsrch, TRUE);
1112 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1113 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1114 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1116 gtk_entry_set_text(GTK_ENTRY(main_realsrch), "");
1117 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1118 gtk_tree_store_clear(srchmodel);
1125 if((ires = dc_interpret(resp)) != NULL)
1127 if(ires->argv[0].val.num == cursrch)
1129 for(i = 0; i < numsizes; i++)
1131 if(srchsizes[i].size == ires->argv[4].val.lnum)
1136 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
1137 srchsizes[i].size = (gint64)ires->argv[4].val.lnum;
1138 srchsizes[i].num = 1;
1139 srchsizes[i].slots = ires->argv[5].val.num;
1140 srchsizes[i].resptime = ires->argv[7].val.flnum;
1141 ss = finddiscsize();
1142 ss->slots += ires->argv[5].val.num;
1143 if((ss->resptime == 0.0) || (ss->resptime > ires->argv[7].val.flnum))
1144 ss->resptime = ires->argv[7].val.flnum;
1145 piter = *ref2iter(ss->ref);
1146 gtk_tree_store_set(srchmodel, &piter, 5, ss->slots, 6, ss->resptime, -1);
1147 gtk_tree_store_append(srchmodel, &titer, &piter);
1148 srchsizes[i].ref = iter2ref(&titer);
1149 } else if(srchsizes[i].num == 1) {
1150 char *filename, *peername, *fnetname, *hash;
1154 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);
1155 gtk_tree_store_remove(srchmodel, ref2iter(srchsizes[i].ref));
1156 gtk_tree_row_reference_free(srchsizes[i].ref);
1157 ss = finddiscsize();
1159 gtk_tree_store_set(srchmodel, ref2iter(ss->ref), 5, ss->slots, -1);
1160 gtk_tree_store_append(srchmodel, &piter, NULL);
1161 srchsizes[i].slots = ires->argv[5].val.num + slots;
1162 srchsizes[i].resptime = (ires->argv[7].val.flnum < resptime)?ires->argv[7].val.flnum:resptime;
1163 srchsizes[i].num = 2;
1164 srchsizes[i].ref = iter2ref(&piter);
1165 gtk_tree_store_set(srchmodel, &piter, 4, srchsizes[i].size, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, 2, -1);
1166 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1169 if(strrchr(p, '/') != NULL)
1170 p = strrchr(p, '/') + 1;
1171 gtk_tree_store_set(srchmodel, &piter, 3, p, -1);
1174 gtk_tree_store_append(srchmodel, &titer, &piter);
1175 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);
1176 g_free(filename); g_free(peername); g_free(fnetname); g_free(hash);
1177 gtk_tree_store_append(srchmodel, &titer, &piter);
1180 srchsizes[i].slots += ires->argv[5].val.num;
1181 if(ires->argv[7].val.flnum < srchsizes[i].resptime)
1182 srchsizes[i].resptime = ires->argv[7].val.flnum;
1183 piter = *ref2iter(srchsizes[i].ref);
1184 gtk_tree_store_set(srchmodel, &piter, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, srchsizes[i].num, -1);
1185 gtk_tree_store_append(srchmodel, &titer, &piter);
1187 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1189 gtk_tree_store_set(srchmodel, &titer, 3, buf, -1);
1192 if((buf = icwcstombs(ires->argv[2].val.str, "UTF-8")) != NULL)
1194 gtk_tree_store_set(srchmodel, &titer, 0, buf, -1);
1197 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1199 gtk_tree_store_set(srchmodel, &titer, 1, buf, -1);
1200 gtk_tree_store_set(srchmodel, &titer, 2, buf, -1);
1203 if((buf = icwcstombs(ires->argv[8].val.str, "UTF-8")) != NULL)
1205 gtk_tree_store_set(srchmodel, &titer, 9, buf, -1);
1208 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);
1216 } else if(!wcscmp(resp->cmdname, L"filtercmd")) {
1217 if((ksquerytag >= 0) && (ksquerytag == resp->tag))
1219 for(i = 0; i < resp->numlines; i++)
1221 assert((ks = findksentbyseq(i)) != NULL);
1222 ks->speed = wcstol(resp->rlines[i].argv[1], NULL, 10);
1224 ks->fetched = time(NULL);
1228 } else if((lsrestag >= 0) && (lsrestag == resp->tag)) {
1229 for(i = 0; i < resp->numlines; i++)
1231 if(!wcsncmp(resp->rlines[i].argv[1], L"id:", 3))
1233 gtk_list_store_append(reslist, &titer);
1234 gtk_list_store_set(reslist, &titer, 0, icswcstombs(resp->rlines[i].argv[1] + 3, "UTF-8", NULL), -1);
1235 } else if(!wcsncmp(resp->rlines[i].argv[1], L"size:", 5)) {
1236 gtk_list_store_set(reslist, &titer, 1, (gint64)wcstoll(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1237 } else if(!wcsncmp(resp->rlines[i].argv[1], L"prog:", 5)) {
1238 gtk_list_store_set(reslist, &titer, 2, (gint64)wcstoll(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1239 } else if(!wcsncmp(resp->rlines[i].argv[1], L"name:", 5)) {
1240 gtk_list_store_set(reslist, &titer, 3, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1241 } else if(!wcsncmp(resp->rlines[i].argv[1], L"lock:", 5)) {
1242 if(!wcscmp(resp->rlines[i].argv[1] + 5, L"yes"))
1243 gtk_list_store_set(reslist, &titer, 4, TRUE, -1);
1245 gtk_list_store_set(reslist, &titer, 4, FALSE, -1);
1246 } else if(!wcsncmp(resp->rlines[i].argv[1], L"hash:", 5)) {
1247 gtk_list_store_set(reslist, &titer, 5, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1251 gtk_widget_set_sensitive(reslist_reload, TRUE);
1259 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition)
1263 if(((condition & GDK_INPUT_READ) && dc_handleread()) || ((condition & GDK_INPUT_WRITE) && dc_handlewrite()))
1269 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has closed the connection"));
1271 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The connection to the server failed:\n\n%s"), strerror(errnobak));
1278 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data)
1286 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data)
1288 GtkWidget *dialog, *swnd;
1291 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);
1292 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), swnd = create_pref_wnd(), TRUE, TRUE, 0);
1293 gtk_entry_set_text(GTK_ENTRY(pref_pubhuburl), pubhubaddr);
1294 gtk_entry_set_text(GTK_ENTRY(pref_connectas), connectas);
1295 gtk_entry_set_text(GTK_ENTRY(pref_dcserver), dcserver);
1296 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref_autoconn), autoconn);
1297 gtk_widget_show(swnd);
1298 resp = gtk_dialog_run(GTK_DIALOG(dialog));
1299 if(resp == GTK_RESPONSE_ACCEPT)
1302 pubhubaddr = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_pubhuburl)));
1304 connectas = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_connectas)));
1306 dcserver = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_dcserver)));
1307 autoconn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_autoconn));
1309 gtk_widget_destroy(dialog);
1312 void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
1314 gtk_list_store_clear(reslist);
1315 gtk_widget_set_sensitive(reslist_delete, FALSE);
1316 gtk_widget_set_sensitive(reslist_search, FALSE);
1317 gtk_widget_show(reslist_wnd);
1320 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
1321 gtk_widget_set_sensitive(reslist_reload, FALSE);
1326 void dcconnect(char *host)
1328 dcfd = dc_connect(host);
1331 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect:\n\n%s"), strerror(errno));
1334 gdkread = gdk_input_add(dcfd, GDK_INPUT_READ, dcfdcallback, NULL);
1336 gtk_widget_set_sensitive(main_connmenu, FALSE);
1337 gtk_widget_set_sensitive(main_dconnmenu, TRUE);
1338 updatesbar(_("Connecting..."));
1341 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data)
1347 if((buf = inputbox(_("Connect"), _("Server address:"), dcserver, 1)) == NULL)
1353 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data)
1356 struct dc_response *resp;
1360 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1363 tag = dc_queuecmd(NULL, NULL, L"shutdown", NULL);
1364 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1366 if(resp->code == 502)
1367 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1373 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
1376 struct dc_response *resp;
1381 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1384 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_fnaddr)), "UTF-8", NULL));
1387 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Illegal address entered"));
1390 if(wcschr(toks[0], L':') == NULL)
1392 toks[0] = srealloc(toks[0], (wcslen(toks[0]) + 5) * sizeof(wchar_t));
1393 wcscat(toks[0], L":411");
1395 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%a", toks, NULL);
1396 dc_freewcsarr(toks);
1397 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1399 if(resp->code == 502)
1400 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1401 if(resp->code == 509)
1402 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1403 if(resp->code == 515)
1404 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1407 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1411 void setpubhubmodel(GtkTreeModel *model, int sortcol, int numcols, int *cols, char **names)
1413 GtkTreeViewColumn *col;
1414 GtkCellRenderer *rnd;
1415 GtkTreeModel *sortmodel;
1418 while((col = gtk_tree_view_get_column(GTK_TREE_VIEW(main_phublist), 0)) != NULL)
1419 gtk_tree_view_remove_column(GTK_TREE_VIEW(main_phublist), col);
1420 for(i = 0; i < numcols; i++) {
1421 if(gtk_tree_model_get_column_type(model, cols[i]) == G_TYPE_INT64)
1423 col = gtk_tree_view_column_new();
1424 gtk_tree_view_column_set_title(col, names[i]);
1425 rnd = gtk_cell_renderer_text_new();
1426 gtk_tree_view_column_pack_start(col, rnd, TRUE);
1427 gtk_tree_view_column_set_cell_data_func(col, rnd, transnicebytefunc2, GINT_TO_POINTER(cols[i]), NULL);
1429 col = gtk_tree_view_column_new_with_attributes(names[i], gtk_cell_renderer_text_new(), "text", cols[i], NULL);
1431 gtk_tree_view_column_set_sort_column_id(col, cols[i]);
1432 gtk_tree_view_column_set_resizable(col, TRUE);
1433 gtk_tree_view_append_column(GTK_TREE_VIEW(main_phublist), col);
1435 sortmodel = gtk_tree_model_sort_new_with_model(model);
1436 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), sortcol, GTK_SORT_DESCENDING);
1437 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), sortmodel);
1438 g_object_unref(sortmodel);
1441 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
1448 buf = gtk_entry_get_text(GTK_ENTRY(main_pubhubfilter));
1451 filter = smalloc(sizeof(*filter));
1452 if((err = regcomp(filter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
1454 regerror(err, filter, errbuf, sizeof(errbuf));
1455 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not compile regex: %s", errbuf);
1463 fetchhublist(pubhubaddr, filter);
1466 void cb_main_pubhubabort_clicked(GtkWidget *widget, gpointer data)
1471 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
1475 struct dc_response *resp;
1479 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1482 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_fnetnodes)), NULL, &iter))
1484 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1487 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1488 tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%i", id, NULL);
1489 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1491 if(resp->code == 502)
1492 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1498 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data)
1501 GtkTreeModel *model;
1504 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_phublist)), &model, &iter))
1506 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &addr, -1);
1507 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), addr);
1511 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1514 struct dc_response *resp;
1516 GtkTreeModel *model;
1521 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1524 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1525 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1527 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &buf, -1);
1528 if(strchr(buf, ':') == NULL)
1530 buf = g_realloc(buf, strlen(buf) + 5);
1531 strcat(buf, ":411");
1533 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%s", buf, NULL);
1535 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1536 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1538 if(resp->code == 502)
1539 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1540 if(resp->code == 509)
1541 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1542 if(resp->code == 515)
1543 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1549 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer uudata)
1553 struct dc_fnetnode *fn;
1554 struct fndata *data;
1556 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(fnmodel), &iter, path))
1558 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1559 if((fn = dc_findfnetnode(id)) == NULL)
1563 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
1567 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1569 gtk_list_store_set(fnmodel, &iter, 5, "gtk-apply", -1);
1571 gtk_list_store_set(fnmodel, &iter, 5, NULL, -1);
1572 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
1574 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), GTK_TEXT_BUFFER(data->textbuf));
1577 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data)
1581 struct dc_response *resp;
1585 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1590 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1593 buf = gtk_entry_get_text(GTK_ENTRY(main_chatstr));
1594 tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%i", curchat, L"1", L"", L"%s", buf, NULL);
1595 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1597 if(resp->code == 502)
1598 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1599 else if(resp->code == 504)
1600 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub could not support all the types of characters in your chat message"));
1601 else if(resp->code == 513)
1602 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub does not support chatting"));
1603 else if(resp->code != 200)
1604 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to chat (%i)"), resp->code);
1607 gtk_entry_set_text(GTK_ENTRY(main_chatstr), "");
1611 void updatesrchfld(const char *simple)
1615 size_t bufsize, bufdata;
1617 s = sstrdup(simple);
1619 bufsize = bufdata = 0;
1623 p2 = strchr(p, ' ');
1629 bufcat(buf, " & ", 3);
1630 bufcat(buf, "N~", 2);
1633 if(strchr("[]()$^.*?+\\|\"!", *p) != NULL)
1634 addtobuf(buf, '\\');
1639 } while(p2 != NULL);
1641 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1646 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data)
1651 updatesrchfld(gtk_entry_get_text(GTK_ENTRY(main_simplesrch)));
1655 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data)
1660 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1664 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data)
1668 struct dc_response *resp;
1669 struct dc_intresp *ires;
1673 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1676 if(nextsrch != -1) /* Impossible case, but oh well... */
1678 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_realsrch)), "UTF-8", NULL));
1681 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Please enter a search expression before searching"));
1684 tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%a", toks, NULL);
1685 dc_freewcsarr(toks);
1686 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1688 if(resp->code == 501)
1689 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not find any hubs to search on"));
1690 else if(resp->code == 502)
1691 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1692 else if(resp->code == 509)
1693 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse your search expression"));
1694 else if(resp->code != 200)
1695 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to search (%i)"), resp->code);
1696 if(resp->code == 200)
1698 if((ires = dc_interpret(resp)) != NULL)
1700 nextsrch = ires->argv[0].val.num;
1701 srcheta = time(NULL) + ires->argv[1].val.num;
1704 gtk_widget_set_sensitive(main_realsrch, FALSE);
1705 gtk_widget_set_sensitive(main_simplesrch, FALSE);
1706 gtk_widget_set_sensitive(main_srchbtn, FALSE);
1707 gtk_widget_set_sensitive(main_srchcanbtn, TRUE);
1715 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data)
1719 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", nextsrch, NULL);
1721 gtk_widget_set_sensitive(main_realsrch, TRUE);
1722 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1723 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1724 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1728 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
1731 GtkTreeSelection *sel;
1732 GtkTreeModel *model;
1734 struct dc_response *resp;
1736 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
1738 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1739 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1741 gtk_tree_model_get(model, &iter, 0, &id, -1);
1742 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1743 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1745 if(resp->code == 502)
1746 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1747 else if(resp->code != 200)
1748 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1758 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1761 struct dc_response *resp;
1763 GtkTreeModel *model;
1766 char *tfnet, *tpeerid, *tfilename, *thash, *arg;
1767 wchar_t *fnet, *peerid, *filename, *hash;
1771 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1774 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1775 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1777 gtk_tree_model_get(model, &iter, 7, &num, -1);
1780 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &tfnet, 1, &tpeerid, 3, &tfilename, 4, &size, 9, &thash, -1);
1781 fnet = icmbstowcs(tfnet, "UTF-8");
1782 peerid = icmbstowcs(tpeerid, "UTF-8");
1783 filename = icmbstowcs(tfilename, "UTF-8");
1784 hash = (thash == NULL)?NULL:icmbstowcs(thash, "UTF-8");
1785 if((fnet == NULL) || (peerid == NULL) || (filename == NULL))
1791 if(filename != NULL)
1805 arg = (char *)gtk_entry_get_text(GTK_ENTRY(main_dlarg));
1807 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);
1809 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);
1815 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1817 if(resp->code == 502)
1818 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1819 if(resp->code != 200)
1820 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to queue the download (%i)"), resp->code);
1826 gboolean srchfilterfunc(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1831 filteratall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots));
1834 gtk_tree_model_get(model, iter, 5, &slots, -1);
1840 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data)
1842 gtk_tree_model_filter_refilter(srchmodelfilter);
1845 void cb_main_srhash_activate(GtkWidget *widget, gpointer data)
1847 GtkTreeSelection *sel;
1848 GtkTreeModel *model;
1854 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1855 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1857 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1858 buf = sprintf2("H=%s", hash);
1859 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1862 cb_main_srchbtn_clicked(widget, NULL);
1868 void cb_main_srcopy_activate(GtkWidget *widget, gpointer data)
1871 GtkTreeSelection *sel;
1872 GtkTreeModel *model;
1878 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1879 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1881 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1882 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1883 gtk_clipboard_set_text(cb, hash, -1);
1887 void cb_main_trhash_activate(GtkWidget *widget, gpointer data)
1889 GtkTreeSelection *sel;
1890 GtkTreeModel *model;
1896 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1897 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1899 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1900 buf = sprintf2("H=%s", hash);
1901 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1904 cb_main_srchbtn_clicked(widget, NULL);
1910 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data)
1913 GtkTreeSelection *sel;
1914 GtkTreeModel *model;
1918 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1919 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1921 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1922 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1923 gtk_clipboard_set_text(cb, hash, -1);
1927 void cb_main_trreset_activate(GtkWidget *widget, gpointer data)
1929 GtkTreeSelection *sel;
1930 GtkTreeModel *model;
1933 struct dc_response *resp;
1935 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1936 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1938 gtk_tree_model_get(model, &iter, 0, &id, -1);
1939 tag = dc_queuecmd(NULL, NULL, L"reset", L"%i", id, NULL);
1940 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1942 if(resp->code == 502)
1943 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1944 else if(resp->code != 200)
1945 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to reset (%i)"), resp->code);
1954 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
1956 GtkTreeSelection *sel;
1957 GtkTreeModel *model;
1960 struct dc_response *resp;
1962 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1963 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1965 gtk_tree_model_get(model, &iter, 0, &id, -1);
1966 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1967 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1969 if(resp->code == 502)
1970 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1971 else if(resp->code != 200)
1972 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1981 /* XXX: This is quite a hack, since the calling convention is
1982 * different for the popup-menu sig and the button-press-event sig. It
1983 * most certainly works, but I don't know how portable it is. */
1984 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
1986 GtkTreeSelection *sel;
1987 GtkTreeModel *model;
1991 if((event != NULL) && (event->button != 3))
1993 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1994 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1996 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1997 if((hash == NULL) || (*hash == 0))
1999 gtk_widget_set_sensitive(main_srhash, FALSE);
2000 gtk_widget_set_sensitive(main_srcopy, FALSE);
2003 gtk_widget_set_sensitive(main_srhash, TRUE);
2005 gtk_widget_set_sensitive(main_srhash, FALSE);
2006 gtk_widget_set_sensitive(main_srcopy, TRUE);
2013 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2015 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2019 /* The above hack note goes for this one too. */
2020 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
2022 GtkTreeSelection *sel;
2023 GtkTreeModel *model;
2027 if((event != NULL) && (event->button != 3))
2029 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2030 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2032 gtk_tree_model_get(model, &iter, 12, &hash, -1);
2033 if((hash == NULL) || (*hash == 0))
2035 gtk_widget_set_sensitive(main_trhash, FALSE);
2036 gtk_widget_set_sensitive(main_trcopy, FALSE);
2039 gtk_widget_set_sensitive(main_trhash, TRUE);
2041 gtk_widget_set_sensitive(main_trhash, FALSE);
2042 gtk_widget_set_sensitive(main_trcopy, TRUE);
2049 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2051 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2055 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data)
2059 gtk_widget_set_sensitive(reslist_delete, FALSE);
2060 gtk_widget_set_sensitive(reslist_search, FALSE);
2061 gtk_list_store_clear(reslist);
2062 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
2063 gtk_widget_set_sensitive(reslist_reload, FALSE);
2070 struct dc_response *resp;
2073 tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%s", id, NULL);
2074 if((resp = dc_gettaggedrespsync(tag)) != NULL)
2076 if(resp->numlines > 0)
2078 if(!wcscmp(resp->rlines[0].argv[1], L"ok"))
2080 else if(!wcsncmp(resp->rlines[0].argv[1], L"err:", 4))
2081 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred (%ls)"), resp->rlines[0].argv[1] + 4);
2089 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data)
2092 GtkTreeModel *model;
2098 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2100 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &id, 4, &locked, -1);
2107 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2111 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data)
2114 GtkTreeModel *model;
2119 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2121 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 5, &hash, -1);
2122 buf = sprintf2("H=%s", hash);
2123 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2126 cb_main_srchbtn_clicked(widget, NULL);
2129 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data)
2132 GtkTreeModel *model;
2136 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2138 gtk_widget_set_sensitive(reslist_delete, FALSE);
2139 gtk_widget_set_sensitive(reslist_search, FALSE);
2142 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 4, &locked, 5, &hash, -1);
2143 gtk_widget_set_sensitive(reslist_delete, !locked);
2144 gtk_widget_set_sensitive(reslist_search, hash && *hash);
2148 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
2151 GtkTreeModel *model;
2154 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
2155 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
2159 gtk_tree_model_get(model, &iter, 5, &hash, -1);
2160 buf = sprintf2("H=%s", hash);
2161 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2164 cb_main_srchbtn_clicked(widget, NULL);
2167 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
2169 GtkTreeSelection *sel;
2170 GtkTreeModel *model;
2175 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
2177 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2178 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2180 gtk_tree_model_get(model, &iter, 0, &id, 4, &locked, -1);
2184 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2193 void srchstatupdate(void)
2199 snprintf(buf, 1024, _("Ready to search"));
2201 snprintf(buf, 1024, _("Search scheduled and will be submitted in %i seconds"), (int)(srcheta - time(NULL)));
2203 if(strcmp(gtk_label_get_text(GTK_LABEL(main_srchstatus)), buf))
2204 gtk_label_set_text(GTK_LABEL(main_srchstatus), buf);
2207 gint srchstatupdatecb(gpointer data)
2213 void initchattags(void)
2217 chattags = gtk_text_tag_table_new();
2218 tag = gtk_text_tag_new("sender");
2219 g_object_set(tag, "foreground", "blue", NULL);
2220 gtk_text_tag_table_add(chattags, tag);
2223 #include "../dolda-icon.xpm"
2225 int main(int argc, char **argv)
2229 PangoFontDescription *monospacefont;
2230 GtkTreeModel *sortmodel;
2231 struct passwd *pwent;
2233 setlocale(LC_ALL, "");
2234 bindtextdomain(PACKAGE, LOCALEDIR);
2235 textdomain(PACKAGE);
2236 gtk_init(&argc, &argv);
2238 while((c = getopt(argc, argv, "lhV")) != -1) {
2244 printf("usage: dolcon [-hlV]\n");
2245 printf("\t-h\tDisplay this help message\n");
2246 printf("\t-l\tConnect to the locally running daemon\n");
2247 printf("\t-V\tDisplay version info and exit\n");
2250 printf("%s", RELEASEINFO);
2253 fprintf(stderr, "usage: dolcon [-hlV]\n");
2258 signal(SIGCHLD, SIG_IGN);
2259 pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.xml.bz2");
2260 dcserver = sstrdup("");
2261 if((pwent = getpwuid(getuid())) == NULL)
2263 fprintf(stderr, "could not get your passwd data");
2266 connectas = sstrdup(pwent->pw_name);
2267 gtk_window_set_default_icon(gdk_pixbuf_new_from_xpm_data((const char **)dolda_icon_xpm));
2268 wnd = create_main_wnd();
2269 create_reslist_wnd();
2270 gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400);
2273 fnmodel = gtk_list_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
2274 gtk_tree_view_set_model(GTK_TREE_VIEW(main_fnetnodes), GTK_TREE_MODEL(fnmodel));
2275 gtk_tree_view_set_model(GTK_TREE_VIEW(main_chatnodes), GTK_TREE_MODEL(fnmodel));
2277 reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
2278 gtk_tree_view_set_model(GTK_TREE_VIEW(reslist_list), GTK_TREE_MODEL(reslist));
2280 dlmodel = gtk_list_store_new(13, G_TYPE_INT, /* id */
2281 G_TYPE_INT, /* dir */
2282 G_TYPE_INT, /* state */
2283 G_TYPE_STRING, /* peerid */
2284 G_TYPE_STRING, /* peernick */
2285 G_TYPE_STRING, /* path */
2286 G_TYPE_INT64, /* size */
2287 G_TYPE_INT64, /* curpos */
2288 G_TYPE_STRING, /* stock */
2289 G_TYPE_FLOAT, /* percentage */
2290 G_TYPE_INT, /* error */
2291 G_TYPE_INT, /* errortime */
2292 G_TYPE_STRING); /* hash */
2293 gtk_tree_view_set_model(GTK_TREE_VIEW(main_downloads), GTK_TREE_MODEL(dlmodel));
2295 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);
2296 gtk_tree_view_set_model(GTK_TREE_VIEW(main_uploads), GTK_TREE_MODEL(ulmodel));
2298 srchmodel = gtk_tree_store_new(10, G_TYPE_STRING, /* fnetname */
2299 G_TYPE_STRING, /* peerid */
2300 G_TYPE_STRING, /* peername */
2301 G_TYPE_STRING, /* filename */
2302 G_TYPE_INT64, /* size */
2303 G_TYPE_INT, /* slots */
2304 G_TYPE_DOUBLE, /* resptime */
2305 G_TYPE_INT, /* sizenum */
2306 G_TYPE_INT, /* speed */
2307 G_TYPE_STRING); /* hash */
2308 srchmodelfilter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(srchmodel), NULL));
2309 gtk_tree_model_filter_set_visible_func(srchmodelfilter, srchfilterfunc, NULL, NULL);
2310 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(srchmodelfilter));
2311 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 4, GTK_SORT_DESCENDING);
2312 gtk_tree_view_set_model(GTK_TREE_VIEW(main_srchres), GTK_TREE_MODEL(sortmodel));
2313 g_object_unref(sortmodel);
2315 monospacefont = pango_font_description_from_string("Monospace 10");
2316 gtk_widget_modify_font(main_chatview, monospacefont);
2317 pango_font_description_free(monospacefont);
2319 updatesbar(_("Disconnected"));
2320 gtk_widget_show(wnd);
2322 dcconnect(dc_srv_local);
2324 dcconnect(dcserver);
2325 g_timeout_add(500, srchstatupdatecb, NULL);
2326 g_timeout_add(5000, ksupdatecb, NULL);
2327 g_timeout_add(1000, updatetransfers, NULL);
2332 #include "mainwnd.gtk"
2333 #include "inpdialog.gtk"
2335 #include "reslist.gtk"