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>
55 size_t poshist[TRHISTSIZE];
56 double timehist[TRHISTSIZE];
62 GtkTextBuffer *textbuf;
71 GtkTreeRowReference *ref;
82 GtkListStore *fnmodel, *ulmodel, *dlmodel, *reslist;
83 GtkTreeStore *srchmodel;
84 GtkTreeModelFilter *srchmodelfilter;
85 GtkTextTagTable *chattags;
86 int dcfd = -1, gdkread = -1, gdkwrite = -1;
88 char *pubhubaddr = NULL;
89 char *connectas = NULL;
90 char *dcserver = NULL;
92 int srchautoupdate = 0;
93 int cursrch = -1, nextsrch = -1;
95 struct srchsize *srchsizes = NULL;
96 struct knownspeed *knownspeeds = NULL;
97 int numsizes = 0, numspeeds = 0, ksqueryseq = -1, ksquerytag = -1, lsrestag = -1;
99 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition);
100 void srchstatupdate(void);
102 #include "mainwnd.gtkh"
103 #include "inpdialog.gtkh"
105 #include "reslist.gtkh"
107 void updatewrite(void)
114 gdkwrite = gdk_input_add(dcfd, GDK_INPUT_WRITE, dcfdcallback, NULL);
118 gdk_input_remove(gdkwrite);
128 gettimeofday(&tv, NULL);
129 return((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
132 void fndestroycb(struct dc_fnetnode *fn)
135 GtkTextBuffer *textbuf;
138 g_object_unref(data->textbuf);
140 if(curchat == fn->id)
142 textbuf = gtk_text_buffer_new(chattags);
143 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), textbuf);
144 g_object_unref(textbuf);
148 void addfndata(struct dc_fnetnode *fn)
152 if(fn->udata != NULL)
154 fn->destroycb = fndestroycb;
155 data = smalloc(sizeof(*data));
156 data->textbuf = gtk_text_buffer_new(chattags);
160 void trdestroycb(struct dc_transfer *tr)
165 void addtrdata(struct dc_transfer *tr)
169 if(tr->udata != NULL)
171 tr->destroycb = trdestroycb;
172 data = smalloc(sizeof(*data));
173 memset(data, 0, sizeof(*data));
177 void updatetrdata(struct dc_transfer *tr)
183 if(data->hc < TRHISTSIZE)
185 data->poshist[data->hc] = tr->curpos;
186 data->timehist[data->hc] = ntime();
189 for(i = 0; i < TRHISTSIZE - 1; i++)
191 data->poshist[i] = data->poshist[i + 1];
192 data->timehist[i] = data->timehist[i + 1];
194 data->poshist[i] = tr->curpos;
195 data->timehist[i] = ntime();
199 char *getfnstatestock(int state)
201 if(state == DC_FNN_STATE_SYN)
202 return("gtk-jump-to");
203 if(state == DC_FNN_STATE_HS)
204 return("gtk-execute");
205 if(state == DC_FNN_STATE_EST)
207 if(state == DC_FNN_STATE_DEAD)
208 return("gtk-cancel");
212 void updatehublist(void)
215 struct dc_fnetnode *fn;
222 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
228 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
232 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
233 if((fn = dc_findfnetnode(id)) == NULL)
235 /* I can't seem to get a sensible reply fromp
236 * gtk_list_store, so I'm just doing this
238 gtk_list_store_remove(fnmodel, &iter);
242 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 1, &name, 2, &state, 3, &numusers, -1);
246 buf = icswcstombs(fn->name, "UTF-8", NULL);
247 if(strcmp(buf, name))
248 gtk_list_store_set(fnmodel, &iter, 1, buf, -1);
249 if(state != fn->state)
251 gtk_list_store_set(fnmodel, &iter, 2, fn->state, -1);
252 gtk_list_store_set(fnmodel, &iter, 4, getfnstatestock(fn->state), -1);
254 if(numusers != fn->numusers)
255 gtk_list_store_set(fnmodel, &iter, 3, fn->numusers, -1);
259 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
262 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
269 buf = icswcstombs(fn->name, "UTF-8", NULL);
270 gtk_list_store_append(fnmodel, &iter);
271 gtk_list_store_set(fnmodel, &iter, 0, fn->id, 1, buf, 2, fn->state, 3, fn->numusers, 4, getfnstatestock(fn->state), -1);
277 char *bytes2si(long long bytes)
282 static char pfx[] = {'k', 'M', 'G', 'T'};
285 for(i = 0; (b >= 1024) && (i < sizeof(pfx)); i++)
288 snprintf(ret, 64, "%.1f B", b);
290 snprintf(ret, 64, "%.1f %ciB", b, pfx[i - 1]);
294 void progressfunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
300 totalc = (GPOINTER_TO_INT(data) & 0xff00) >> 8;
301 curc = GPOINTER_TO_INT(data) & 0xff;
302 gtk_tree_model_get(model, iter, totalc, &total, curc, &cur, -1);
304 g_object_set(rend, "value", GINT_TO_POINTER(0), NULL);
306 g_object_set(rend, "value", GINT_TO_POINTER((int)(((double)cur / (double)total) * 100)), NULL);
308 g_object_set(rend, "text", "", NULL);
310 snprintf(buf, 64, "%'i", cur);
311 g_object_set(rend, "text", buf, NULL);
315 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
321 colnum = GPOINTER_TO_INT(data);
322 gtk_tree_model_get(model, iter, colnum, &val, -1);
323 snprintf(buf, 64, "%.2f%%", (double)(val * 100.0));
324 g_object_set(rend, "text", buf, NULL);
327 void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
332 colnum = GPOINTER_TO_INT(data);
333 gtk_tree_model_get(model, iter, colnum, &val, -1);
335 snprintf(buf, 64, "%'i", val);
337 strcpy(buf, _("Unknown"));
338 g_object_set(rend, "text", buf, NULL);
341 void transnicebytefunc2(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
347 colnum = GPOINTER_TO_INT(data);
348 gtk_tree_model_get(model, iter, colnum, &val, -1);
350 strcpy(buf, bytes2si(val));
352 strcpy(buf, _("Unknown"));
353 g_object_set(rend, "text", buf, NULL);
356 void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
361 colnum = GPOINTER_TO_INT(data);
362 gtk_tree_model_get(model, iter, colnum, &val, -1);
364 snprintf(buf, 64, "%i", val);
367 g_object_set(rend, "text", buf, NULL);
370 void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
372 int speed, size, time;
375 gtk_tree_model_get(model, iter, 4, &size, 8, &speed, -1);
378 time = (size / speed) / 60;
380 snprintf(buf, 64, "%'i (<00:01)", speed);
382 snprintf(buf, 64, "%'i (%02i:%02i)", speed, time / 60, time % 60);
383 } else if(speed == 0) {
386 strcpy(buf, _("Unknown"));
388 g_object_set(rend, "text", buf, NULL);
391 void transspeedinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
394 struct dc_transfer *tr;
399 gtk_tree_model_get(model, iter, 0, &id, -1);
400 if((tr = dc_findtransfer(id)) != NULL)
403 if((tr->state != DC_TRNS_MAIN) || (d == NULL))
406 } else if(d->hc < 2) {
409 speed = (((double)(d->poshist[d->hc - 1] - d->poshist[0])) / (d->timehist[d->hc - 1] - d->timehist[0]));
410 snprintf(buf, 64, "%s/s", bytes2si(speed));
415 g_object_set(rend, "text", buf, NULL);
418 void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
422 char finbuf[64], tbuf[64], *errstr;
424 gtk_tree_model_get(model, iter, 10, &error, 11, &errortime, -1);
425 if(error != DC_TRNSE_NOERROR)
427 if(error == DC_TRNSE_NOTFOUND)
428 errstr = _("Not found");
429 else if(error == DC_TRNSE_NOSLOTS)
430 errstr = _("No slots");
431 strftime(tbuf, 64, _("%H:%M:%S"), localtime(&errortime));
432 snprintf(finbuf, 64, _("%s (reported at %s)"), errstr, tbuf);
436 g_object_set(rend, "text", finbuf, NULL);
439 char *gettrstatestock(int state)
441 if(state == DC_TRNS_WAITING)
442 return("gtk-jump-to");
443 if(state == DC_TRNS_HS)
444 return("gtk-execute");
445 if(state == DC_TRNS_MAIN)
446 return("gtk-network");
447 if(state == DC_TRNS_DONE)
452 gint updatetransfers(gpointer data)
454 struct dc_transfer *tr;
459 for(tr = dc_transfers; tr != NULL; tr = tr->next)
461 if((d = tr->udata) != NULL)
463 if((d->hc > 0) && ((now - d->timehist[d->hc - 1]) > 2))
470 void updatetransferlists(void)
474 struct dc_transfer *transfer;
478 char *peerid, *peernick, *path, *hash;
479 int state, dir, size, curpos, error;
481 GtkListStore *stores[3];
483 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
485 stores[DC_TRNSD_UNKNOWN] = NULL;
486 stores[DC_TRNSD_UP] = ulmodel;
487 stores[DC_TRNSD_DOWN] = dlmodel;
488 for(i = 0; i < 3; i++)
490 if(stores[i] == NULL)
496 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(stores[i]), &iter))
500 gtk_tree_model_get(GTK_TREE_MODEL(stores[i]), &iter, 0, &id, 1, &dir, -1);
501 if(((transfer = dc_findtransfer(id)) == NULL) || (transfer->dir != dir))
503 gtk_list_store_remove(stores[i], &iter);
508 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);
509 if(state != transfer->state)
510 gtk_list_store_set(stores[i], &iter, 2, transfer->state, 8, gettrstatestock(transfer->state), -1);
511 if(size != transfer->size)
512 gtk_list_store_set(stores[i], &iter, 6, transfer->size, -1);
513 if(curpos != transfer->curpos)
515 gtk_list_store_set(stores[i], &iter, 7, transfer->curpos, -1);
516 if(transfer->udata != NULL)
517 updatetrdata(transfer);
519 if(error != transfer->error)
520 gtk_list_store_set(stores[i], &iter, 10, transfer->error, -1);
521 if(errortime != transfer->errortime)
522 gtk_list_store_set(stores[i], &iter, 11, transfer->errortime, -1);
523 if((transfer->size > 0) && (transfer->curpos > 0))
524 gtk_list_store_set(stores[i], &iter, 9, (float)transfer->curpos / (float)transfer->size, -1);
525 buf = icswcstombs(transfer->peerid, "UTF-8", NULL);
526 if(strcmp(buf, peerid))
527 gtk_list_store_set(stores[i], &iter, 3, buf, -1);
528 buf = icswcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8", NULL);
529 if(strcmp(buf, peernick))
530 gtk_list_store_set(stores[i], &iter, 4, buf, -1);
531 buf = (transfer->path == NULL)?_("Unknown"):icswcstombs(transfer->path, "UTF-8", NULL);
532 if(strcmp(buf, path))
533 gtk_list_store_set(stores[i], &iter, 5, buf, -1);
534 buf = (transfer->hash == NULL)?"":icswcstombs(transfer->hash, "UTF-8", NULL);
535 if(strcmp(buf, path))
536 gtk_list_store_set(stores[i], &iter, 12, buf, -1);
542 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(stores[i]), &iter));
546 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
550 if(stores[transfer->dir] != NULL)
552 peerid = icwcstombs(transfer->peerid, "UTF-8");
553 peernick = icwcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8");
554 path = (transfer->path == NULL)?_("Unknown"):icwcstombs(transfer->path, "UTF-8");
555 hash = (transfer->hash == NULL)?"":icwcstombs(transfer->hash, "UTF-8");
556 gtk_list_store_append(stores[transfer->dir], &iter);
557 gtk_list_store_set(stores[transfer->dir], &iter,
566 8, gettrstatestock(transfer->state),
569 11, transfer->errortime,
574 if(transfer->path != NULL)
576 if(transfer->hash != NULL)
584 void updatesbar(char *msg)
586 gtk_statusbar_pop(GTK_STATUSBAR(main_statusbar), 0);
587 gtk_statusbar_push(GTK_STATUSBAR(main_statusbar), 0, msg);
590 void freesrchsizes(void)
594 for(i = 0; i < numsizes; i++)
596 if(srchsizes[i].ref != NULL)
597 gtk_tree_row_reference_free(srchsizes[i].ref);
599 if(srchsizes != NULL)
605 void dcdisconnected(void)
609 gdk_input_remove(gdkread);
614 updatetransferlists();
615 cursrch = nextsrch = -1;
616 gtk_tree_store_clear(srchmodel);
618 gtk_widget_set_sensitive(main_connmenu, TRUE);
619 gtk_widget_set_sensitive(main_dconnmenu, FALSE);
620 gtk_widget_set_sensitive(main_simplesrch, TRUE);
621 gtk_widget_set_sensitive(main_realsrch, TRUE);
622 gtk_widget_set_sensitive(main_srchbtn, TRUE);
623 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
624 updatesbar(_("Disconnected"));
627 char *inputbox(char *title, char *prompt, char *def, int echo)
633 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);
634 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(inpdialog)->vbox), swnd = create_inpdialog_wnd(), TRUE, TRUE, 0);
635 gtk_widget_show(swnd);
637 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), FALSE);
638 gtk_label_set_text(GTK_LABEL(inpdialog_prompt), prompt);
639 gtk_entry_set_text(GTK_ENTRY(inpdialog_entry), def);
640 resp = gtk_dialog_run(GTK_DIALOG(inpdialog));
642 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), TRUE);
643 if(resp == GTK_RESPONSE_ACCEPT)
644 buf = strdup(gtk_entry_get_text(GTK_ENTRY(inpdialog_entry)));
647 gtk_widget_destroy(inpdialog);
652 int msgbox(int type, int buttons, char *format, ...)
659 va_start(args, format);
660 buf = vsprintf2(format, args);
662 swnd = gtk_message_dialog_new(GTK_WINDOW(main_wnd), GTK_DIALOG_MODAL, type, buttons, "%s", buf);
663 resp = gtk_dialog_run(GTK_DIALOG(swnd));
664 gtk_widget_destroy(swnd);
669 void readconfigfile(void)
672 char *homedir, *buf, *p;
675 if((homedir = getenv("HOME")) == NULL)
677 fprintf(stderr, "warning: could not find home directory!\n");
680 buf = sprintf2("%s/.dolconrc", homedir);
681 if((cfgfile = fopen(buf, "r")) == NULL)
690 while(fgets(buf, 1024, cfgfile) != NULL)
694 p = buf + strlen(buf);
697 if((p = strchr(buf, ':')) == NULL)
700 while((*p == ' ') || (*p == '\t'))
702 if(!strcmp(buf, "wnd-width"))
705 } else if(!strcmp(buf, "wnd-height")) {
707 } else if(!strcmp(buf, "pane1-pos")) {
708 gtk_paned_set_position(GTK_PANED(main_pane1), atoi(p));
709 } else if(!strcmp(buf, "pane2-pos")) {
710 gtk_paned_set_position(GTK_PANED(main_pane2), atoi(p));
711 } else if(!strcmp(buf, "pane3-pos")) {
712 gtk_paned_set_position(GTK_PANED(main_pane3), atoi(p));
713 } else if(!strcmp(buf, "pubhubaddr")) {
715 pubhubaddr = sstrdup(p);
716 } else if(!strcmp(buf, "dcserver")) {
718 dcserver = sstrdup(p);
719 } else if(!strcmp(buf, "advexpanded")) {
720 gtk_expander_set_expanded(GTK_EXPANDER(main_advexp), atoi(p));
721 } else if(!strcmp(buf, "connectas")) {
723 connectas = sstrdup(p);
724 } else if(!strcmp(buf, "autoconn")) {
726 } else if(!strcmp(buf, "filternoslots")) {
727 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(main_filternoslots), atoi(p));
736 gtk_window_resize(GTK_WINDOW(main_wnd), w, h);
739 void updateconfigfile(void)
745 if((homedir = getenv("HOME")) == NULL)
747 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not get your home directory!"));
750 buf = sprintf2("%s/.dolconrc", homedir);
751 if((cfgfile = fopen(buf, "w")) == NULL)
754 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not open configuration file for writing: %s"), strerror(errno));
758 gtk_window_get_size(GTK_WINDOW(main_wnd), &w, &h);
759 fprintf(cfgfile, "wnd-width: %i\n", w);
760 fprintf(cfgfile, "wnd-height: %i\n", h);
761 fprintf(cfgfile, "pane1-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane1)));
762 fprintf(cfgfile, "pane2-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane2)));
763 fprintf(cfgfile, "pane3-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane3)));
764 fprintf(cfgfile, "pubhubaddr: %s\n", pubhubaddr);
765 fprintf(cfgfile, "dcserver: %s\n", dcserver);
766 fprintf(cfgfile, "advexpanded: %i\n", gtk_expander_get_expanded(GTK_EXPANDER(main_advexp)));
767 fprintf(cfgfile, "connectas: %s\n", connectas);
768 fprintf(cfgfile, "autoconn: %i\n", autoconn);
769 fprintf(cfgfile, "filternoslots: %i\n", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots)));
773 gboolean initdeath(GtkWidget *widget, gpointer data)
780 void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data)
782 gtk_dialog_response(GTK_DIALOG(inpdialog), GTK_RESPONSE_ACCEPT);
785 int loginconv(int type, wchar_t *prompt, char **resp, void *data)
791 buf = icwcstombs(prompt, "UTF-8");
794 case DC_LOGIN_CONV_NOECHO:
795 if((*resp = inputbox(_("Login"), buf, "", 0)) == NULL)
798 case DC_LOGIN_CONV_ECHO:
799 if((*resp = inputbox(_("Login"), buf, "", 1)) == NULL)
802 case DC_LOGIN_CONV_INFO:
803 msgbox(GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", buf);
805 case DC_LOGIN_CONV_ERROR:
806 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", buf);
814 void getfnlistcallback(int resp, void *data)
819 void gettrlistcallback(int resp, void *data)
821 updatetransferlists();
824 void logincallback(int err, wchar_t *reason, void *data)
828 case DC_LOGIN_ERR_SUCCESS:
829 dc_queuecmd(NULL, NULL, L"notify", L"all", L"on", NULL);
830 dc_getfnlistasync(getfnlistcallback, NULL);
831 dc_gettrlistasync(gettrlistcallback, NULL);
832 updatesbar("Authenticated");
834 case DC_LOGIN_ERR_NOLOGIN:
835 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not negotiate an acceptable authentication mechanism"));
839 case DC_LOGIN_ERR_SERVER:
840 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has encountered an error"));
844 case DC_LOGIN_ERR_USER:
845 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Internal client error"));
849 case DC_LOGIN_ERR_CONV:
853 case DC_LOGIN_ERR_AUTHFAIL:
854 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Login attempt failed!"));
862 GtkTreeIter *ref2iter(GtkTreeRowReference *ref)
864 static GtkTreeIter iter;
867 assert((path = gtk_tree_row_reference_get_path(ref)) != NULL);
868 assert(gtk_tree_model_get_iter(GTK_TREE_MODEL(srchmodel), &iter, path));
869 gtk_tree_path_free(path);
873 GtkTreeRowReference *iter2ref(GtkTreeIter *iter)
876 GtkTreeRowReference *ref;
878 assert((path = gtk_tree_model_get_path(GTK_TREE_MODEL(srchmodel), iter)) != NULL);
879 assert((ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(srchmodel), path)) != NULL);
880 gtk_tree_path_free(path);
884 struct srchsize *finddiscsize(void)
889 for(i = 0; i < numsizes; i++)
891 if(srchsizes[i].size == -1)
892 return(&srchsizes[i]);
894 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
895 srchsizes[i].size = -1;
896 srchsizes[i].num = 1;
897 srchsizes[i].slots = 0;
898 srchsizes[i].resptime = 0.0;
899 gtk_tree_store_append(srchmodel, &iter, NULL);
900 gtk_tree_store_set(srchmodel, &iter, 3, _("Discrete sizes"), 7, 1, -1);
901 srchsizes[i].ref = iter2ref(&iter);
902 return(&srchsizes[i]);
905 struct knownspeed *findksentbyname(char *userid)
909 for(i = 0; i < numspeeds; i++)
911 if(!strcmp(knownspeeds[i].userid, userid))
912 return(&knownspeeds[i]);
917 struct knownspeed *findksentbyseq(int seq)
921 for(i = 0; i < numspeeds; i++)
923 if(knownspeeds[i].seq == seq)
924 return(&knownspeeds[i]);
929 gboolean ksupdaterow(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
931 struct knownspeed *ks;
934 gtk_tree_model_get(GTK_TREE_MODEL(model), iter, 1, &userid, -1);
937 ks = findksentbyname(userid);
940 knownspeeds = srealloc(knownspeeds, (numspeeds + 1) * sizeof(*knownspeeds));
941 ks = &knownspeeds[numspeeds];
943 ks->userid = sstrdup(userid);
950 gtk_tree_store_set(GTK_TREE_STORE(model), iter, 8, ks->speed, -1);
954 gint ksupdatecb(gpointer data)
958 wchar_t **users, *buf;
959 size_t userssize, usersdata;
965 for(i = 0; i < numspeeds;)
967 if(now - knownspeeds[i].fetched > 60)
969 free(knownspeeds[i].userid);
970 memmove(&knownspeeds[i], &knownspeeds[i + 1], (--numspeeds - i) * sizeof(*knownspeeds));
975 if(oldnum != numspeeds)
982 knownspeeds = srealloc(knownspeeds, numspeeds * sizeof(*knownspeeds));
985 gtk_tree_model_foreach(GTK_TREE_MODEL(srchmodel), ksupdaterow, NULL);
989 userssize = usersdata = 0;
991 for(i = 0; i < numspeeds; i++)
993 if(knownspeeds[i].seq == -2)
995 assert((buf = icmbstowcs(knownspeeds[i].userid, "UTF-8")) != NULL);
996 knownspeeds[i].seq = ksqueryseq++;
997 addtobuf(users, buf);
1000 addtobuf(users, NULL);
1001 ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%a", users, NULL);
1002 dc_freewcsarr(users);
1008 void handleresps(void)
1011 struct dc_response *resp;
1012 struct dc_intresp *ires;
1013 struct dc_fnetnode *fn;
1014 struct fndata *fndata;
1016 GtkTreeIter titer, piter;
1019 struct srchsize *ss;
1020 struct knownspeed *ks;
1022 while((resp = dc_getresp()) != NULL)
1024 if(!wcscmp(resp->cmdname, L".connect"))
1026 if(resp->code != 201)
1028 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server refused the connection"));
1031 } else if(dc_checkprotocol(resp, DC_LATEST)) {
1032 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Server protocol revision mismatch"));
1036 tosbuf = 0x10; /* Minimum delay */
1037 setsockopt(dcfd, IPPROTO_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
1038 updatesbar(_("Connected"));
1039 dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
1041 } else if(!wcscmp(resp->cmdname, L".notify")) {
1042 dc_uimisc_handlenotify(resp);
1046 if((ires = dc_interpret(resp)) != NULL)
1048 if((fn = dc_findfnetnode(ires->argv[0].val.num)) != NULL)
1051 gtk_text_buffer_get_end_iter(fndata->textbuf, &iter);
1052 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1054 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, "<", -1, "sender", NULL);
1055 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, buf, -1, "sender", NULL);
1056 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, ">", -1, "sender", NULL);
1057 gtk_text_buffer_insert(fndata->textbuf, &iter, " ", -1);
1060 if((buf = icwcstombs(ires->argv[4].val.str, "UTF-8")) != NULL)
1062 gtk_text_buffer_insert(fndata->textbuf, &iter, buf, -1);
1063 gtk_text_buffer_insert(fndata->textbuf, &iter, "\n", -1);
1065 if(curchat == fn->id)
1066 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(main_chatview), &iter, 0, 0, 0, 0);
1088 updatetransferlists();
1091 if((ires = dc_interpret(resp)) != NULL)
1093 if(ires->argv[0].val.num == nextsrch)
1094 srcheta = time(NULL) + ires->argv[0].val.num;
1099 if((ires = dc_interpret(resp)) != NULL)
1101 if(ires->argv[0].val.num == nextsrch)
1104 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", cursrch, NULL);
1107 gtk_widget_set_sensitive(main_realsrch, TRUE);
1108 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1109 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1110 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1112 gtk_entry_set_text(GTK_ENTRY(main_realsrch), "");
1113 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1114 gtk_tree_store_clear(srchmodel);
1121 if((ires = dc_interpret(resp)) != NULL)
1123 if(ires->argv[0].val.num == cursrch)
1125 for(i = 0; i < numsizes; i++)
1127 if(srchsizes[i].size == ires->argv[4].val.num)
1132 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
1133 srchsizes[i].size = ires->argv[4].val.num;
1134 srchsizes[i].num = 1;
1135 srchsizes[i].slots = ires->argv[5].val.num;
1136 srchsizes[i].resptime = ires->argv[7].val.flnum;
1137 ss = finddiscsize();
1138 ss->slots += ires->argv[5].val.num;
1139 if((ss->resptime == 0.0) || (ss->resptime > ires->argv[7].val.flnum))
1140 ss->resptime = ires->argv[7].val.flnum;
1141 piter = *ref2iter(ss->ref);
1142 gtk_tree_store_set(srchmodel, &piter, 5, ss->slots, 6, ss->resptime, -1);
1143 gtk_tree_store_append(srchmodel, &titer, &piter);
1144 srchsizes[i].ref = iter2ref(&titer);
1145 } else if(srchsizes[i].num == 1) {
1146 char *filename, *peername, *fnetname, *hash;
1150 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);
1151 gtk_tree_store_remove(srchmodel, ref2iter(srchsizes[i].ref));
1152 gtk_tree_row_reference_free(srchsizes[i].ref);
1153 ss = finddiscsize();
1155 gtk_tree_store_set(srchmodel, ref2iter(ss->ref), 5, ss->slots, -1);
1156 gtk_tree_store_append(srchmodel, &piter, NULL);
1157 srchsizes[i].slots = ires->argv[5].val.num + slots;
1158 srchsizes[i].resptime = (ires->argv[7].val.flnum < resptime)?ires->argv[7].val.flnum:resptime;
1159 srchsizes[i].num = 2;
1160 srchsizes[i].ref = iter2ref(&piter);
1161 gtk_tree_store_set(srchmodel, &piter, 4, srchsizes[i].size, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, 2, -1);
1162 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1165 /* XXX: Too NMDC-specific! */
1166 if(strrchr(p, '\\') != NULL)
1167 p = strrchr(p, '\\') + 1;
1168 gtk_tree_store_set(srchmodel, &piter, 3, p, -1);
1171 gtk_tree_store_append(srchmodel, &titer, &piter);
1172 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);
1173 g_free(filename); g_free(peername); g_free(fnetname); g_free(hash);
1174 gtk_tree_store_append(srchmodel, &titer, &piter);
1177 srchsizes[i].slots += ires->argv[5].val.num;
1178 if(ires->argv[7].val.flnum < srchsizes[i].resptime)
1179 srchsizes[i].resptime = ires->argv[7].val.flnum;
1180 piter = *ref2iter(srchsizes[i].ref);
1181 gtk_tree_store_set(srchmodel, &piter, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, srchsizes[i].num, -1);
1182 gtk_tree_store_append(srchmodel, &titer, &piter);
1184 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1186 gtk_tree_store_set(srchmodel, &titer, 3, buf, -1);
1189 if((buf = icwcstombs(ires->argv[2].val.str, "UTF-8")) != NULL)
1191 gtk_tree_store_set(srchmodel, &titer, 0, buf, -1);
1194 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1196 gtk_tree_store_set(srchmodel, &titer, 1, buf, -1);
1197 gtk_tree_store_set(srchmodel, &titer, 2, buf, -1);
1200 if((buf = icwcstombs(ires->argv[8].val.str, "UTF-8")) != NULL)
1202 gtk_tree_store_set(srchmodel, &titer, 9, buf, -1);
1205 gtk_tree_store_set(srchmodel, &titer, 4, ires->argv[4].val.num, 5, ires->argv[5].val.num, 6, ires->argv[7].val.flnum, 8, -1, -1);
1213 } else if(!wcscmp(resp->cmdname, L"filtercmd")) {
1214 if((ksquerytag >= 0) && (ksquerytag == resp->tag))
1216 for(i = 0; i < resp->numlines; i++)
1218 assert((ks = findksentbyseq(i)) != NULL);
1219 ks->speed = wcstol(resp->rlines[i].argv[1], NULL, 10);
1221 ks->fetched = time(NULL);
1225 } else if((lsrestag >= 0) && (lsrestag == resp->tag)) {
1226 for(i = 0; i < resp->numlines; i++)
1228 if(!wcsncmp(resp->rlines[i].argv[1], L"id:", 3))
1230 gtk_list_store_append(reslist, &titer);
1231 gtk_list_store_set(reslist, &titer, 0, icswcstombs(resp->rlines[i].argv[1] + 3, "UTF-8", NULL), -1);
1232 } else if(!wcsncmp(resp->rlines[i].argv[1], L"size:", 5)) {
1233 gtk_list_store_set(reslist, &titer, 1, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1234 } else if(!wcsncmp(resp->rlines[i].argv[1], L"prog:", 5)) {
1235 gtk_list_store_set(reslist, &titer, 2, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1236 } else if(!wcsncmp(resp->rlines[i].argv[1], L"name:", 5)) {
1237 gtk_list_store_set(reslist, &titer, 3, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1238 } else if(!wcsncmp(resp->rlines[i].argv[1], L"lock:", 5)) {
1239 if(!wcscmp(resp->rlines[i].argv[1] + 5, L"yes"))
1240 gtk_list_store_set(reslist, &titer, 4, TRUE, -1);
1242 gtk_list_store_set(reslist, &titer, 4, FALSE, -1);
1243 } else if(!wcsncmp(resp->rlines[i].argv[1], L"hash:", 5)) {
1244 gtk_list_store_set(reslist, &titer, 5, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1248 gtk_widget_set_sensitive(reslist_reload, TRUE);
1256 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition)
1260 if(((condition & GDK_INPUT_READ) && dc_handleread()) || ((condition & GDK_INPUT_WRITE) && dc_handlewrite()))
1266 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has closed the connection"));
1268 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The connection to the server failed:\n\n%s"), strerror(errnobak));
1275 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data)
1283 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data)
1285 GtkWidget *dialog, *swnd;
1288 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);
1289 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), swnd = create_pref_wnd(), TRUE, TRUE, 0);
1290 gtk_entry_set_text(GTK_ENTRY(pref_pubhuburl), pubhubaddr);
1291 gtk_entry_set_text(GTK_ENTRY(pref_connectas), connectas);
1292 gtk_entry_set_text(GTK_ENTRY(pref_dcserver), dcserver);
1293 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref_autoconn), autoconn);
1294 gtk_widget_show(swnd);
1295 resp = gtk_dialog_run(GTK_DIALOG(dialog));
1296 if(resp == GTK_RESPONSE_ACCEPT)
1299 pubhubaddr = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_pubhuburl)));
1301 connectas = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_connectas)));
1303 dcserver = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_dcserver)));
1304 autoconn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_autoconn));
1306 gtk_widget_destroy(dialog);
1309 void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
1311 gtk_list_store_clear(reslist);
1312 gtk_widget_set_sensitive(reslist_delete, FALSE);
1313 gtk_widget_set_sensitive(reslist_search, FALSE);
1314 gtk_widget_show(reslist_wnd);
1317 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
1318 gtk_widget_set_sensitive(reslist_reload, FALSE);
1323 void dcconnect(char *host)
1325 dcfd = dc_connect(host);
1328 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect:\n\n%s"), strerror(errno));
1331 gdkread = gdk_input_add(dcfd, GDK_INPUT_READ, dcfdcallback, NULL);
1333 gtk_widget_set_sensitive(main_connmenu, FALSE);
1334 gtk_widget_set_sensitive(main_dconnmenu, TRUE);
1335 updatesbar(_("Connecting..."));
1338 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data)
1344 if((buf = inputbox(_("Connect"), _("Server address:"), dcserver, 1)) == NULL)
1350 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data)
1353 struct dc_response *resp;
1357 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1360 tag = dc_queuecmd(NULL, NULL, L"shutdown", NULL);
1361 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1363 if(resp->code == 502)
1364 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1370 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
1373 struct dc_response *resp;
1378 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1381 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_fnaddr)), "UTF-8", NULL));
1384 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Illegal address entered"));
1387 if(wcschr(toks[0], L':') == NULL)
1389 toks[0] = srealloc(toks[0], (wcslen(toks[0]) + 5) * sizeof(wchar_t));
1390 wcscat(toks[0], L":411");
1392 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%a", toks, NULL);
1393 dc_freewcsarr(toks);
1394 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1396 if(resp->code == 502)
1397 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1398 if(resp->code == 509)
1399 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1400 if(resp->code == 515)
1401 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1404 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1408 void setpubhubmodel(GtkTreeModel *model, int sortcol, int numcols, int *cols, char **names)
1410 GtkTreeViewColumn *col;
1411 GtkCellRenderer *rnd;
1412 GtkTreeModel *sortmodel;
1415 while((col = gtk_tree_view_get_column(GTK_TREE_VIEW(main_phublist), 0)) != NULL)
1416 gtk_tree_view_remove_column(GTK_TREE_VIEW(main_phublist), col);
1417 for(i = 0; i < numcols; i++) {
1418 if(gtk_tree_model_get_column_type(model, cols[i]) == G_TYPE_INT64)
1420 col = gtk_tree_view_column_new();
1421 gtk_tree_view_column_set_title(col, names[i]);
1422 rnd = gtk_cell_renderer_text_new();
1423 gtk_tree_view_column_pack_start(col, rnd, TRUE);
1424 gtk_tree_view_column_set_cell_data_func(col, rnd, transnicebytefunc2, GINT_TO_POINTER(cols[i]), NULL);
1426 col = gtk_tree_view_column_new_with_attributes(names[i], gtk_cell_renderer_text_new(), "text", cols[i], NULL);
1428 gtk_tree_view_column_set_sort_column_id(col, cols[i]);
1429 gtk_tree_view_column_set_resizable(col, TRUE);
1430 gtk_tree_view_append_column(GTK_TREE_VIEW(main_phublist), col);
1432 sortmodel = gtk_tree_model_sort_new_with_model(model);
1433 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), sortcol, GTK_SORT_DESCENDING);
1434 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), sortmodel);
1435 g_object_unref(sortmodel);
1438 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
1445 buf = gtk_entry_get_text(GTK_ENTRY(main_pubhubfilter));
1448 filter = smalloc(sizeof(*filter));
1449 if((err = regcomp(filter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
1451 regerror(err, filter, errbuf, sizeof(errbuf));
1452 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not compile regex: %s", errbuf);
1460 fetchhublist(pubhubaddr, filter);
1463 void cb_main_pubhubabort_clicked(GtkWidget *widget, gpointer data)
1468 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
1472 struct dc_response *resp;
1476 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1479 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_fnetnodes)), NULL, &iter))
1481 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1484 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1485 tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%i", id, NULL);
1486 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1488 if(resp->code == 502)
1489 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1495 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data)
1498 GtkTreeModel *model;
1501 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_phublist)), &model, &iter))
1503 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &addr, -1);
1504 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), addr);
1508 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1511 struct dc_response *resp;
1513 GtkTreeModel *model;
1518 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1521 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1522 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1524 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &buf, -1);
1525 if(strchr(buf, ':') == NULL)
1527 buf = g_realloc(buf, strlen(buf) + 5);
1528 strcat(buf, ":411");
1530 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%s", buf, NULL);
1532 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1533 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1535 if(resp->code == 502)
1536 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1537 if(resp->code == 509)
1538 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1539 if(resp->code == 515)
1540 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1546 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer uudata)
1550 struct dc_fnetnode *fn;
1551 struct fndata *data;
1553 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(fnmodel), &iter, path))
1555 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1556 if((fn = dc_findfnetnode(id)) == NULL)
1560 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
1564 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1566 gtk_list_store_set(fnmodel, &iter, 5, "gtk-apply", -1);
1568 gtk_list_store_set(fnmodel, &iter, 5, NULL, -1);
1569 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
1571 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), GTK_TEXT_BUFFER(data->textbuf));
1574 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data)
1578 struct dc_response *resp;
1582 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1587 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1590 buf = gtk_entry_get_text(GTK_ENTRY(main_chatstr));
1591 tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%i", curchat, L"1", L"", L"%s", buf, NULL);
1592 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1594 if(resp->code == 502)
1595 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1596 else if(resp->code == 504)
1597 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub could not support all the types of characters in your chat message"));
1598 else if(resp->code == 513)
1599 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub does not support chatting"));
1600 else if(resp->code != 200)
1601 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to chat (%i)"), resp->code);
1604 gtk_entry_set_text(GTK_ENTRY(main_chatstr), "");
1608 void updatesrchfld(const char *simple)
1612 size_t bufsize, bufdata;
1614 s = sstrdup(simple);
1616 bufsize = bufdata = 0;
1620 p2 = strchr(p, ' ');
1626 bufcat(buf, " & ", 3);
1627 bufcat(buf, "N~", 2);
1630 if(strchr("[]()$^.*?+\\|\"!", *p) != NULL)
1631 addtobuf(buf, '\\');
1636 } while(p2 != NULL);
1638 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1643 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data)
1648 updatesrchfld(gtk_entry_get_text(GTK_ENTRY(main_simplesrch)));
1652 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data)
1657 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1661 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data)
1665 struct dc_response *resp;
1666 struct dc_intresp *ires;
1670 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1673 if(nextsrch != -1) /* Impossible case, but oh well... */
1675 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_realsrch)), "UTF-8", NULL));
1678 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Please enter a search expression before searching"));
1681 tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%a", toks, NULL);
1682 dc_freewcsarr(toks);
1683 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1685 if(resp->code == 501)
1686 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not find any hubs to search on"));
1687 else if(resp->code == 502)
1688 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1689 else if(resp->code == 509)
1690 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse your search expression"));
1691 else if(resp->code != 200)
1692 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to search (%i)"), resp->code);
1693 if(resp->code == 200)
1695 if((ires = dc_interpret(resp)) != NULL)
1697 nextsrch = ires->argv[0].val.num;
1698 srcheta = time(NULL) + ires->argv[1].val.num;
1701 gtk_widget_set_sensitive(main_realsrch, FALSE);
1702 gtk_widget_set_sensitive(main_simplesrch, FALSE);
1703 gtk_widget_set_sensitive(main_srchbtn, FALSE);
1704 gtk_widget_set_sensitive(main_srchcanbtn, TRUE);
1712 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data)
1716 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", nextsrch, NULL);
1718 gtk_widget_set_sensitive(main_realsrch, TRUE);
1719 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1720 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1721 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1725 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
1728 GtkTreeSelection *sel;
1729 GtkTreeModel *model;
1731 struct dc_response *resp;
1733 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
1735 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1736 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1738 gtk_tree_model_get(model, &iter, 0, &id, -1);
1739 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1740 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1742 if(resp->code == 502)
1743 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1744 else if(resp->code != 200)
1745 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1755 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1758 struct dc_response *resp;
1760 GtkTreeModel *model;
1762 char *tfnet, *tpeerid, *tfilename, *thash, *arg;
1763 wchar_t *fnet, *peerid, *filename, *hash;
1767 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1770 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1771 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1773 gtk_tree_model_get(model, &iter, 7, &num, -1);
1776 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &tfnet, 1, &tpeerid, 3, &tfilename, 4, &size, 9, &thash, -1);
1777 fnet = icmbstowcs(tfnet, "UTF-8");
1778 peerid = icmbstowcs(tpeerid, "UTF-8");
1779 filename = icmbstowcs(tfilename, "UTF-8");
1780 hash = (thash == NULL)?NULL:icmbstowcs(thash, "UTF-8");
1781 if((fnet == NULL) || (peerid == NULL) || (filename == NULL))
1787 if(filename != NULL)
1801 arg = (char *)gtk_entry_get_text(GTK_ENTRY(main_dlarg));
1803 tag = dc_queuecmd(NULL, NULL, L"download", fnet, L"%ls", peerid, L"%ls", filename, L"%i", size, L"hash", L"%ls", (hash == NULL)?L"":hash, L"user", L"%s", arg, NULL);
1805 tag = dc_queuecmd(NULL, NULL, L"download", fnet, L"%ls", peerid, L"%ls", filename, L"%i", size, L"hash", L"%ls", (hash == NULL)?L"":hash, NULL);
1811 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1813 if(resp->code == 502)
1814 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1815 if(resp->code != 200)
1816 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to queue the download (%i)"), resp->code);
1822 gboolean srchfilterfunc(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1827 filteratall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots));
1830 gtk_tree_model_get(model, iter, 5, &slots, -1);
1836 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data)
1838 gtk_tree_model_filter_refilter(srchmodelfilter);
1841 void cb_main_srhash_activate(GtkWidget *widget, gpointer data)
1843 GtkTreeSelection *sel;
1844 GtkTreeModel *model;
1850 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1851 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1853 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1854 buf = sprintf2("H=%s", hash);
1855 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1858 cb_main_srchbtn_clicked(widget, NULL);
1864 void cb_main_srcopy_activate(GtkWidget *widget, gpointer data)
1867 GtkTreeSelection *sel;
1868 GtkTreeModel *model;
1874 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1875 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1877 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1878 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1879 gtk_clipboard_set_text(cb, hash, -1);
1883 void cb_main_trhash_activate(GtkWidget *widget, gpointer data)
1885 GtkTreeSelection *sel;
1886 GtkTreeModel *model;
1892 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1893 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1895 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1896 buf = sprintf2("H=%s", hash);
1897 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1900 cb_main_srchbtn_clicked(widget, NULL);
1906 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data)
1909 GtkTreeSelection *sel;
1910 GtkTreeModel *model;
1914 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1915 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1917 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1918 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1919 gtk_clipboard_set_text(cb, hash, -1);
1923 void cb_main_trreset_activate(GtkWidget *widget, gpointer data)
1925 GtkTreeSelection *sel;
1926 GtkTreeModel *model;
1929 struct dc_response *resp;
1931 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1932 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1934 gtk_tree_model_get(model, &iter, 0, &id, -1);
1935 tag = dc_queuecmd(NULL, NULL, L"reset", L"%i", id, NULL);
1936 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1938 if(resp->code == 502)
1939 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1940 else if(resp->code != 200)
1941 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to reset (%i)"), resp->code);
1950 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
1952 GtkTreeSelection *sel;
1953 GtkTreeModel *model;
1956 struct dc_response *resp;
1958 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1959 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1961 gtk_tree_model_get(model, &iter, 0, &id, -1);
1962 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1963 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1965 if(resp->code == 502)
1966 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1967 else if(resp->code != 200)
1968 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1977 /* XXX: This is quite a hack, since the calling convention is
1978 * different for the popup-menu sig and the button-press-event sig. It
1979 * most certainly works, but I don't know how portable it is. */
1980 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
1982 GtkTreeSelection *sel;
1983 GtkTreeModel *model;
1987 if((event != NULL) && (event->button != 3))
1989 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1990 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1992 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1993 if((hash == NULL) || (*hash == 0))
1995 gtk_widget_set_sensitive(main_srhash, FALSE);
1996 gtk_widget_set_sensitive(main_srcopy, FALSE);
1999 gtk_widget_set_sensitive(main_srhash, TRUE);
2001 gtk_widget_set_sensitive(main_srhash, FALSE);
2002 gtk_widget_set_sensitive(main_srcopy, TRUE);
2009 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2011 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2015 /* The above hack note goes for this one too. */
2016 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
2018 GtkTreeSelection *sel;
2019 GtkTreeModel *model;
2023 if((event != NULL) && (event->button != 3))
2025 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2026 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2028 gtk_tree_model_get(model, &iter, 12, &hash, -1);
2029 if((hash == NULL) || (*hash == 0))
2031 gtk_widget_set_sensitive(main_trhash, FALSE);
2032 gtk_widget_set_sensitive(main_trcopy, FALSE);
2035 gtk_widget_set_sensitive(main_trhash, TRUE);
2037 gtk_widget_set_sensitive(main_trhash, FALSE);
2038 gtk_widget_set_sensitive(main_trcopy, TRUE);
2045 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2047 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2051 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data)
2055 gtk_widget_set_sensitive(reslist_delete, FALSE);
2056 gtk_widget_set_sensitive(reslist_search, FALSE);
2057 gtk_list_store_clear(reslist);
2058 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
2059 gtk_widget_set_sensitive(reslist_reload, FALSE);
2066 struct dc_response *resp;
2069 tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%s", id, NULL);
2070 if((resp = dc_gettaggedrespsync(tag)) != NULL)
2072 if(resp->numlines > 0)
2074 if(!wcscmp(resp->rlines[0].argv[1], L"ok"))
2076 else if(!wcsncmp(resp->rlines[0].argv[1], L"err:", 4))
2077 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred (%ls)"), resp->rlines[0].argv[1] + 4);
2085 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data)
2088 GtkTreeModel *model;
2094 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2096 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &id, 4, &locked, -1);
2103 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2107 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data)
2110 GtkTreeModel *model;
2115 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2117 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 5, &hash, -1);
2118 buf = sprintf2("H=%s", hash);
2119 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2122 cb_main_srchbtn_clicked(widget, NULL);
2125 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data)
2128 GtkTreeModel *model;
2132 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2134 gtk_widget_set_sensitive(reslist_delete, FALSE);
2135 gtk_widget_set_sensitive(reslist_search, FALSE);
2138 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 4, &locked, 5, &hash, -1);
2139 gtk_widget_set_sensitive(reslist_delete, !locked);
2140 gtk_widget_set_sensitive(reslist_search, hash && *hash);
2144 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
2147 GtkTreeModel *model;
2150 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
2151 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
2155 gtk_tree_model_get(model, &iter, 5, &hash, -1);
2156 buf = sprintf2("H=%s", hash);
2157 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2160 cb_main_srchbtn_clicked(widget, NULL);
2163 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
2165 GtkTreeSelection *sel;
2166 GtkTreeModel *model;
2171 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
2173 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2174 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2176 gtk_tree_model_get(model, &iter, 0, &id, 4, &locked, -1);
2180 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2189 void srchstatupdate(void)
2195 snprintf(buf, 1024, _("Ready to search"));
2197 snprintf(buf, 1024, _("Search scheduled and will be submitted in %i seconds"), (int)(srcheta - time(NULL)));
2199 if(strcmp(gtk_label_get_text(GTK_LABEL(main_srchstatus)), buf))
2200 gtk_label_set_text(GTK_LABEL(main_srchstatus), buf);
2203 gint srchstatupdatecb(gpointer data)
2209 void initchattags(void)
2213 chattags = gtk_text_tag_table_new();
2214 tag = gtk_text_tag_new("sender");
2215 g_object_set(tag, "foreground", "blue", NULL);
2216 gtk_text_tag_table_add(chattags, tag);
2219 #include "../dolda-icon.xpm"
2221 int main(int argc, char **argv)
2225 PangoFontDescription *monospacefont;
2226 GtkTreeModel *sortmodel;
2227 struct passwd *pwent;
2229 setlocale(LC_ALL, "");
2230 bindtextdomain(PACKAGE, LOCALEDIR);
2231 textdomain(PACKAGE);
2232 gtk_init(&argc, &argv);
2234 while((c = getopt(argc, argv, "lhV")) != -1) {
2240 printf("usage: dolcon [-hlV]\n");
2241 printf("\t-h\tDisplay this help message\n");
2242 printf("\t-l\tConnect to the locally running daemon\n");
2243 printf("\t-V\tDisplay version info and exit\n");
2246 printf("%s", RELEASEINFO);
2249 fprintf(stderr, "usage: dolcon [-hlV]\n");
2254 signal(SIGCHLD, SIG_IGN);
2255 pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.xml.bz2");
2256 dcserver = sstrdup("");
2257 if((pwent = getpwuid(getuid())) == NULL)
2259 fprintf(stderr, "could not get your passwd data");
2262 connectas = sstrdup(pwent->pw_name);
2263 gtk_window_set_default_icon(gdk_pixbuf_new_from_xpm_data((const char **)dolda_icon_xpm));
2264 wnd = create_main_wnd();
2265 create_reslist_wnd();
2266 gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400);
2269 fnmodel = gtk_list_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
2270 gtk_tree_view_set_model(GTK_TREE_VIEW(main_fnetnodes), GTK_TREE_MODEL(fnmodel));
2271 gtk_tree_view_set_model(GTK_TREE_VIEW(main_chatnodes), GTK_TREE_MODEL(fnmodel));
2273 reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
2274 gtk_tree_view_set_model(GTK_TREE_VIEW(reslist_list), GTK_TREE_MODEL(reslist));
2276 dlmodel = gtk_list_store_new(13, G_TYPE_INT, /* id */
2277 G_TYPE_INT, /* dir */
2278 G_TYPE_INT, /* state */
2279 G_TYPE_STRING, /* peerid */
2280 G_TYPE_STRING, /* peernick */
2281 G_TYPE_STRING, /* path */
2282 G_TYPE_INT, /* size */
2283 G_TYPE_INT, /* curpos */
2284 G_TYPE_STRING, /* stock */
2285 G_TYPE_FLOAT, /* percentage */
2286 G_TYPE_INT, /* error */
2287 G_TYPE_INT, /* errortime */
2288 G_TYPE_STRING); /* hash */
2289 gtk_tree_view_set_model(GTK_TREE_VIEW(main_downloads), GTK_TREE_MODEL(dlmodel));
2291 ulmodel = gtk_list_store_new(13, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_FLOAT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
2292 gtk_tree_view_set_model(GTK_TREE_VIEW(main_uploads), GTK_TREE_MODEL(ulmodel));
2294 srchmodel = gtk_tree_store_new(10, G_TYPE_STRING, /* fnetname */
2295 G_TYPE_STRING, /* peerid */
2296 G_TYPE_STRING, /* peername */
2297 G_TYPE_STRING, /* filename */
2298 G_TYPE_INT, /* size */
2299 G_TYPE_INT, /* slots */
2300 G_TYPE_DOUBLE, /* resptime */
2301 G_TYPE_INT, /* sizenum */
2302 G_TYPE_INT, /* speed */
2303 G_TYPE_STRING); /* hash */
2304 srchmodelfilter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(srchmodel), NULL));
2305 gtk_tree_model_filter_set_visible_func(srchmodelfilter, srchfilterfunc, NULL, NULL);
2306 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(srchmodelfilter));
2307 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 4, GTK_SORT_DESCENDING);
2308 gtk_tree_view_set_model(GTK_TREE_VIEW(main_srchres), GTK_TREE_MODEL(sortmodel));
2309 g_object_unref(sortmodel);
2311 monospacefont = pango_font_description_from_string("Monospace 10");
2312 gtk_widget_modify_font(main_chatview, monospacefont);
2313 pango_font_description_free(monospacefont);
2315 updatesbar(_("Disconnected"));
2316 gtk_widget_show(wnd);
2318 dcconnect(dc_srv_local);
2320 dcconnect(dcserver);
2321 g_timeout_add(500, srchstatupdatecb, NULL);
2322 g_timeout_add(5000, ksupdatecb, NULL);
2323 g_timeout_add(1000, updatetransfers, NULL);
2328 #include "mainwnd.gtk"
2329 #include "inpdialog.gtk"
2331 #include "reslist.gtk"