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);
1007 void handleresps(void)
1010 struct dc_response *resp;
1011 struct dc_intresp *ires;
1012 struct dc_fnetnode *fn;
1013 struct fndata *fndata;
1015 GtkTreeIter titer, piter;
1018 struct srchsize *ss;
1019 struct knownspeed *ks;
1021 while((resp = dc_getresp()) != NULL)
1023 if(!wcscmp(resp->cmdname, L".connect"))
1025 if(resp->code != 201)
1027 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server refused the connection"));
1030 } else if(dc_checkprotocol(resp, DC_LATEST)) {
1031 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Server protocol revision mismatch"));
1035 tosbuf = 0x10; /* Minimum delay */
1036 setsockopt(dcfd, IPPROTO_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
1037 updatesbar(_("Connected"));
1038 dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
1040 } else if(!wcscmp(resp->cmdname, L".notify")) {
1041 dc_uimisc_handlenotify(resp);
1045 if((ires = dc_interpret(resp)) != NULL)
1047 if((fn = dc_findfnetnode(ires->argv[0].val.num)) != NULL)
1050 gtk_text_buffer_get_end_iter(fndata->textbuf, &iter);
1051 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1053 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, "<", -1, "sender", NULL);
1054 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, buf, -1, "sender", NULL);
1055 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, ">", -1, "sender", NULL);
1056 gtk_text_buffer_insert(fndata->textbuf, &iter, " ", -1);
1059 if((buf = icwcstombs(ires->argv[4].val.str, "UTF-8")) != NULL)
1061 gtk_text_buffer_insert(fndata->textbuf, &iter, buf, -1);
1062 gtk_text_buffer_insert(fndata->textbuf, &iter, "\n", -1);
1064 if(curchat == fn->id)
1065 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(main_chatview), &iter, 0, 0, 0, 0);
1087 updatetransferlists();
1090 if((ires = dc_interpret(resp)) != NULL)
1092 if(ires->argv[0].val.num == nextsrch)
1093 srcheta = time(NULL) + ires->argv[0].val.num;
1098 if((ires = dc_interpret(resp)) != NULL)
1100 if(ires->argv[0].val.num == nextsrch)
1103 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", cursrch, NULL);
1106 gtk_widget_set_sensitive(main_realsrch, TRUE);
1107 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1108 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1109 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1111 gtk_entry_set_text(GTK_ENTRY(main_realsrch), "");
1112 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1113 gtk_tree_store_clear(srchmodel);
1120 if((ires = dc_interpret(resp)) != NULL)
1122 if(ires->argv[0].val.num == cursrch)
1124 for(i = 0; i < numsizes; i++)
1126 if(srchsizes[i].size == ires->argv[4].val.num)
1131 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
1132 srchsizes[i].size = ires->argv[4].val.num;
1133 srchsizes[i].num = 1;
1134 srchsizes[i].slots = ires->argv[5].val.num;
1135 srchsizes[i].resptime = ires->argv[7].val.flnum;
1136 ss = finddiscsize();
1137 ss->slots += ires->argv[5].val.num;
1138 if((ss->resptime == 0.0) || (ss->resptime > ires->argv[7].val.flnum))
1139 ss->resptime = ires->argv[7].val.flnum;
1140 piter = *ref2iter(ss->ref);
1141 gtk_tree_store_set(srchmodel, &piter, 5, ss->slots, 6, ss->resptime, -1);
1142 gtk_tree_store_append(srchmodel, &titer, &piter);
1143 srchsizes[i].ref = iter2ref(&titer);
1144 } else if(srchsizes[i].num == 1) {
1145 char *filename, *peername, *fnetname, *hash;
1149 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);
1150 gtk_tree_store_remove(srchmodel, ref2iter(srchsizes[i].ref));
1151 gtk_tree_row_reference_free(srchsizes[i].ref);
1152 ss = finddiscsize();
1154 gtk_tree_store_set(srchmodel, ref2iter(ss->ref), 5, ss->slots, -1);
1155 gtk_tree_store_append(srchmodel, &piter, NULL);
1156 srchsizes[i].slots = ires->argv[5].val.num + slots;
1157 srchsizes[i].resptime = (ires->argv[7].val.flnum < resptime)?ires->argv[7].val.flnum:resptime;
1158 srchsizes[i].num = 2;
1159 srchsizes[i].ref = iter2ref(&piter);
1160 gtk_tree_store_set(srchmodel, &piter, 4, srchsizes[i].size, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, 2, -1);
1161 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1164 /* XXX: Too NMDC-specific! */
1165 if(strrchr(p, '\\') != NULL)
1166 p = strrchr(p, '\\') + 1;
1167 gtk_tree_store_set(srchmodel, &piter, 3, p, -1);
1170 gtk_tree_store_append(srchmodel, &titer, &piter);
1171 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);
1172 g_free(filename); g_free(peername); g_free(fnetname); g_free(hash);
1173 gtk_tree_store_append(srchmodel, &titer, &piter);
1176 srchsizes[i].slots += ires->argv[5].val.num;
1177 if(ires->argv[7].val.flnum < srchsizes[i].resptime)
1178 srchsizes[i].resptime = ires->argv[7].val.flnum;
1179 piter = *ref2iter(srchsizes[i].ref);
1180 gtk_tree_store_set(srchmodel, &piter, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, srchsizes[i].num, -1);
1181 gtk_tree_store_append(srchmodel, &titer, &piter);
1183 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1185 gtk_tree_store_set(srchmodel, &titer, 3, buf, -1);
1188 if((buf = icwcstombs(ires->argv[2].val.str, "UTF-8")) != NULL)
1190 gtk_tree_store_set(srchmodel, &titer, 0, buf, -1);
1193 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1195 gtk_tree_store_set(srchmodel, &titer, 1, buf, -1);
1196 gtk_tree_store_set(srchmodel, &titer, 2, buf, -1);
1199 if((buf = icwcstombs(ires->argv[8].val.str, "UTF-8")) != NULL)
1201 gtk_tree_store_set(srchmodel, &titer, 9, buf, -1);
1204 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);
1212 } else if(!wcscmp(resp->cmdname, L"filtercmd")) {
1213 if((ksquerytag >= 0) && (ksquerytag == resp->tag))
1215 for(i = 0; i < resp->numlines; i++)
1217 assert((ks = findksentbyseq(i)) != NULL);
1218 ks->speed = wcstol(resp->rlines[i].argv[1], NULL, 10);
1220 ks->fetched = time(NULL);
1224 } else if((lsrestag >= 0) && (lsrestag == resp->tag)) {
1225 for(i = 0; i < resp->numlines; i++)
1227 if(!wcsncmp(resp->rlines[i].argv[1], L"id:", 3))
1229 gtk_list_store_append(reslist, &titer);
1230 gtk_list_store_set(reslist, &titer, 0, icswcstombs(resp->rlines[i].argv[1] + 3, "UTF-8", NULL), -1);
1231 } else if(!wcsncmp(resp->rlines[i].argv[1], L"size:", 5)) {
1232 gtk_list_store_set(reslist, &titer, 1, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1233 } else if(!wcsncmp(resp->rlines[i].argv[1], L"prog:", 5)) {
1234 gtk_list_store_set(reslist, &titer, 2, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1235 } else if(!wcsncmp(resp->rlines[i].argv[1], L"name:", 5)) {
1236 gtk_list_store_set(reslist, &titer, 3, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1237 } else if(!wcsncmp(resp->rlines[i].argv[1], L"lock:", 5)) {
1238 if(!wcscmp(resp->rlines[i].argv[1] + 5, L"yes"))
1239 gtk_list_store_set(reslist, &titer, 4, TRUE, -1);
1241 gtk_list_store_set(reslist, &titer, 4, FALSE, -1);
1242 } else if(!wcsncmp(resp->rlines[i].argv[1], L"hash:", 5)) {
1243 gtk_list_store_set(reslist, &titer, 5, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1247 gtk_widget_set_sensitive(reslist_reload, TRUE);
1255 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition)
1259 if(((condition & GDK_INPUT_READ) && dc_handleread()) || ((condition & GDK_INPUT_WRITE) && dc_handlewrite()))
1265 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has closed the connection"));
1267 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The connection to the server failed:\n\n%s"), strerror(errnobak));
1274 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data)
1282 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data)
1284 GtkWidget *dialog, *swnd;
1287 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);
1288 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), swnd = create_pref_wnd(), TRUE, TRUE, 0);
1289 gtk_entry_set_text(GTK_ENTRY(pref_pubhuburl), pubhubaddr);
1290 gtk_entry_set_text(GTK_ENTRY(pref_connectas), connectas);
1291 gtk_entry_set_text(GTK_ENTRY(pref_dcserver), dcserver);
1292 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref_autoconn), autoconn);
1293 gtk_widget_show(swnd);
1294 resp = gtk_dialog_run(GTK_DIALOG(dialog));
1295 if(resp == GTK_RESPONSE_ACCEPT)
1298 pubhubaddr = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_pubhuburl)));
1300 connectas = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_connectas)));
1302 dcserver = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_dcserver)));
1303 autoconn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_autoconn));
1305 gtk_widget_destroy(dialog);
1308 void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
1310 gtk_list_store_clear(reslist);
1311 gtk_widget_set_sensitive(reslist_delete, FALSE);
1312 gtk_widget_set_sensitive(reslist_search, FALSE);
1313 gtk_widget_show(reslist_wnd);
1316 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
1317 gtk_widget_set_sensitive(reslist_reload, FALSE);
1321 void dcconnect(char *host)
1323 dcfd = dc_connect(host);
1326 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect:\n\n%s"), strerror(errno));
1329 gdkread = gdk_input_add(dcfd, GDK_INPUT_READ, dcfdcallback, NULL);
1331 gtk_widget_set_sensitive(main_connmenu, FALSE);
1332 gtk_widget_set_sensitive(main_dconnmenu, TRUE);
1333 updatesbar(_("Connecting..."));
1336 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data)
1342 if((buf = inputbox(_("Connect"), _("Server address:"), dcserver, 1)) == NULL)
1348 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data)
1351 struct dc_response *resp;
1355 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1358 tag = dc_queuecmd(NULL, NULL, L"shutdown", NULL);
1359 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1361 if(resp->code == 502)
1362 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1368 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
1371 struct dc_response *resp;
1376 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1379 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_fnaddr)), "UTF-8", NULL));
1382 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Illegal address entered"));
1385 if(wcschr(toks[0], L':') == NULL)
1387 toks[0] = srealloc(toks[0], (wcslen(toks[0]) + 5) * sizeof(wchar_t));
1388 wcscat(toks[0], L":411");
1390 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%a", toks, NULL);
1391 dc_freewcsarr(toks);
1392 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1394 if(resp->code == 502)
1395 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1396 if(resp->code == 509)
1397 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1398 if(resp->code == 515)
1399 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1402 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1406 void setpubhubmodel(GtkTreeModel *model, int sortcol, int numcols, int *cols, char **names)
1408 GtkTreeViewColumn *col;
1409 GtkCellRenderer *rnd;
1410 GtkTreeModel *sortmodel;
1413 while((col = gtk_tree_view_get_column(GTK_TREE_VIEW(main_phublist), 0)) != NULL)
1414 gtk_tree_view_remove_column(GTK_TREE_VIEW(main_phublist), col);
1415 for(i = 0; i < numcols; i++) {
1416 if(gtk_tree_model_get_column_type(model, cols[i]) == G_TYPE_INT64)
1418 col = gtk_tree_view_column_new();
1419 gtk_tree_view_column_set_title(col, names[i]);
1420 rnd = gtk_cell_renderer_text_new();
1421 gtk_tree_view_column_pack_start(col, rnd, TRUE);
1422 gtk_tree_view_column_set_cell_data_func(col, rnd, transnicebytefunc2, GINT_TO_POINTER(cols[i]), NULL);
1424 col = gtk_tree_view_column_new_with_attributes(names[i], gtk_cell_renderer_text_new(), "text", cols[i], NULL);
1426 gtk_tree_view_column_set_sort_column_id(col, cols[i]);
1427 gtk_tree_view_column_set_resizable(col, TRUE);
1428 gtk_tree_view_append_column(GTK_TREE_VIEW(main_phublist), col);
1430 sortmodel = gtk_tree_model_sort_new_with_model(model);
1431 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), sortcol, GTK_SORT_DESCENDING);
1432 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), sortmodel);
1433 g_object_unref(sortmodel);
1436 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
1443 buf = gtk_entry_get_text(GTK_ENTRY(main_pubhubfilter));
1446 filter = smalloc(sizeof(*filter));
1447 if((err = regcomp(filter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
1449 regerror(err, filter, errbuf, sizeof(errbuf));
1450 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not compile regex: %s", errbuf);
1458 fetchhublist(pubhubaddr, filter);
1461 void cb_main_pubhubabort_clicked(GtkWidget *widget, gpointer data)
1466 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
1470 struct dc_response *resp;
1474 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1477 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_fnetnodes)), NULL, &iter))
1479 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1482 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1483 tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%i", id, NULL);
1484 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1486 if(resp->code == 502)
1487 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1493 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data)
1496 GtkTreeModel *model;
1499 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_phublist)), &model, &iter))
1501 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &addr, -1);
1502 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), addr);
1506 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1509 struct dc_response *resp;
1511 GtkTreeModel *model;
1516 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1519 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1520 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1522 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &buf, -1);
1523 if(strchr(buf, ':') == NULL)
1525 buf = g_realloc(buf, strlen(buf) + 5);
1526 strcat(buf, ":411");
1528 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%s", buf, NULL);
1530 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1531 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1533 if(resp->code == 502)
1534 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1535 if(resp->code == 509)
1536 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1537 if(resp->code == 515)
1538 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1544 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer uudata)
1548 struct dc_fnetnode *fn;
1549 struct fndata *data;
1551 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(fnmodel), &iter, path))
1553 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1554 if((fn = dc_findfnetnode(id)) == NULL)
1558 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
1562 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1564 gtk_list_store_set(fnmodel, &iter, 5, "gtk-apply", -1);
1566 gtk_list_store_set(fnmodel, &iter, 5, NULL, -1);
1567 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
1569 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), GTK_TEXT_BUFFER(data->textbuf));
1572 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data)
1576 struct dc_response *resp;
1580 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1585 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1588 buf = gtk_entry_get_text(GTK_ENTRY(main_chatstr));
1589 tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%i", curchat, L"1", L"", L"%s", buf, NULL);
1590 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1592 if(resp->code == 502)
1593 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1594 else if(resp->code == 504)
1595 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub could not support all the types of characters in your chat message"));
1596 else if(resp->code == 513)
1597 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub does not support chatting"));
1598 else if(resp->code != 200)
1599 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to chat (%i)"), resp->code);
1602 gtk_entry_set_text(GTK_ENTRY(main_chatstr), "");
1606 void updatesrchfld(const char *simple)
1610 size_t bufsize, bufdata;
1612 s = sstrdup(simple);
1614 bufsize = bufdata = 0;
1618 p2 = strchr(p, ' ');
1624 bufcat(buf, " & ", 3);
1625 bufcat(buf, "N~", 2);
1628 if(strchr("[]()$^.*?+\\|\"!", *p) != NULL)
1629 addtobuf(buf, '\\');
1634 } while(p2 != NULL);
1636 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1641 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data)
1646 updatesrchfld(gtk_entry_get_text(GTK_ENTRY(main_simplesrch)));
1650 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data)
1655 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1659 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data)
1663 struct dc_response *resp;
1664 struct dc_intresp *ires;
1668 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1671 if(nextsrch != -1) /* Impossible case, but oh well... */
1673 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_realsrch)), "UTF-8", NULL));
1676 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Please enter a search expression before searching"));
1679 tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%a", toks, NULL);
1680 dc_freewcsarr(toks);
1681 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1683 if(resp->code == 501)
1684 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not find any hubs to search on"));
1685 else if(resp->code == 502)
1686 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1687 else if(resp->code == 509)
1688 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse your search expression"));
1689 else if(resp->code != 200)
1690 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to search (%i)"), resp->code);
1691 if(resp->code == 200)
1693 if((ires = dc_interpret(resp)) != NULL)
1695 nextsrch = ires->argv[0].val.num;
1696 srcheta = time(NULL) + ires->argv[1].val.num;
1699 gtk_widget_set_sensitive(main_realsrch, FALSE);
1700 gtk_widget_set_sensitive(main_simplesrch, FALSE);
1701 gtk_widget_set_sensitive(main_srchbtn, FALSE);
1702 gtk_widget_set_sensitive(main_srchcanbtn, TRUE);
1710 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data)
1714 dc_queuecmd(NULL, NULL, L"cansrch", L"%i", nextsrch, NULL);
1716 gtk_widget_set_sensitive(main_realsrch, TRUE);
1717 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1718 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1719 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1723 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
1726 GtkTreeSelection *sel;
1727 GtkTreeModel *model;
1729 struct dc_response *resp;
1731 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
1733 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1734 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1736 gtk_tree_model_get(model, &iter, 0, &id, -1);
1737 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1738 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1740 if(resp->code == 502)
1741 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1742 else if(resp->code != 200)
1743 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1753 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1756 struct dc_response *resp;
1758 GtkTreeModel *model;
1760 char *tfnet, *tpeerid, *tfilename, *thash, *arg;
1761 wchar_t *fnet, *peerid, *filename, *hash;
1765 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1768 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1769 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1771 gtk_tree_model_get(model, &iter, 7, &num, -1);
1774 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &tfnet, 1, &tpeerid, 3, &tfilename, 4, &size, 9, &thash, -1);
1775 fnet = icmbstowcs(tfnet, "UTF-8");
1776 peerid = icmbstowcs(tpeerid, "UTF-8");
1777 filename = icmbstowcs(tfilename, "UTF-8");
1778 hash = (thash == NULL)?NULL:icmbstowcs(thash, "UTF-8");
1779 if((fnet == NULL) || (peerid == NULL) || (filename == NULL))
1785 if(filename != NULL)
1799 arg = (char *)gtk_entry_get_text(GTK_ENTRY(main_dlarg));
1801 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);
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, NULL);
1809 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1811 if(resp->code == 502)
1812 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1813 if(resp->code != 200)
1814 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to queue the download (%i)"), resp->code);
1820 gboolean srchfilterfunc(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1825 filteratall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots));
1828 gtk_tree_model_get(model, iter, 5, &slots, -1);
1834 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data)
1836 gtk_tree_model_filter_refilter(srchmodelfilter);
1839 void cb_main_srhash_activate(GtkWidget *widget, gpointer data)
1841 GtkTreeSelection *sel;
1842 GtkTreeModel *model;
1848 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1849 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1851 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1852 buf = sprintf2("H=%s", hash);
1853 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1856 cb_main_srchbtn_clicked(widget, NULL);
1862 void cb_main_srcopy_activate(GtkWidget *widget, gpointer data)
1865 GtkTreeSelection *sel;
1866 GtkTreeModel *model;
1872 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1873 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1875 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1876 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1877 gtk_clipboard_set_text(cb, hash, -1);
1881 void cb_main_trhash_activate(GtkWidget *widget, gpointer data)
1883 GtkTreeSelection *sel;
1884 GtkTreeModel *model;
1890 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1891 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1893 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1894 buf = sprintf2("H=%s", hash);
1895 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1898 cb_main_srchbtn_clicked(widget, NULL);
1904 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data)
1907 GtkTreeSelection *sel;
1908 GtkTreeModel *model;
1912 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1913 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1915 gtk_tree_model_get(model, &iter, 12, &hash, -1);
1916 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1917 gtk_clipboard_set_text(cb, hash, -1);
1921 void cb_main_trreset_activate(GtkWidget *widget, gpointer data)
1923 GtkTreeSelection *sel;
1924 GtkTreeModel *model;
1927 struct dc_response *resp;
1929 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1930 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1932 gtk_tree_model_get(model, &iter, 0, &id, -1);
1933 tag = dc_queuecmd(NULL, NULL, L"reset", L"%i", id, NULL);
1934 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1936 if(resp->code == 502)
1937 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1938 else if(resp->code != 200)
1939 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to reset (%i)"), resp->code);
1948 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
1950 GtkTreeSelection *sel;
1951 GtkTreeModel *model;
1954 struct dc_response *resp;
1956 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1957 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1959 gtk_tree_model_get(model, &iter, 0, &id, -1);
1960 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%i", id, NULL);
1961 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1963 if(resp->code == 502)
1964 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1965 else if(resp->code != 200)
1966 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1975 /* XXX: This is quite a hack, since the calling convention is
1976 * different for the popup-menu sig and the button-press-event sig. It
1977 * most certainly works, but I don't know how portable it is. */
1978 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
1980 GtkTreeSelection *sel;
1981 GtkTreeModel *model;
1985 if((event != NULL) && (event->button != 3))
1987 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1988 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1990 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1991 if((hash == NULL) || (*hash == 0))
1993 gtk_widget_set_sensitive(main_srhash, FALSE);
1994 gtk_widget_set_sensitive(main_srcopy, FALSE);
1997 gtk_widget_set_sensitive(main_srhash, TRUE);
1999 gtk_widget_set_sensitive(main_srhash, FALSE);
2000 gtk_widget_set_sensitive(main_srcopy, TRUE);
2007 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2009 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2013 /* The above hack note goes for this one too. */
2014 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
2016 GtkTreeSelection *sel;
2017 GtkTreeModel *model;
2021 if((event != NULL) && (event->button != 3))
2023 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2024 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2026 gtk_tree_model_get(model, &iter, 12, &hash, -1);
2027 if((hash == NULL) || (*hash == 0))
2029 gtk_widget_set_sensitive(main_trhash, FALSE);
2030 gtk_widget_set_sensitive(main_trcopy, FALSE);
2033 gtk_widget_set_sensitive(main_trhash, TRUE);
2035 gtk_widget_set_sensitive(main_trhash, FALSE);
2036 gtk_widget_set_sensitive(main_trcopy, TRUE);
2043 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2045 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2049 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data)
2053 gtk_widget_set_sensitive(reslist_delete, FALSE);
2054 gtk_widget_set_sensitive(reslist_search, FALSE);
2055 gtk_list_store_clear(reslist);
2056 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
2057 gtk_widget_set_sensitive(reslist_reload, FALSE);
2063 struct dc_response *resp;
2066 tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%s", id, NULL);
2067 if((resp = dc_gettaggedrespsync(tag)) != NULL)
2069 if(resp->numlines > 0)
2071 if(!wcscmp(resp->rlines[0].argv[1], L"ok"))
2073 else if(!wcsncmp(resp->rlines[0].argv[1], L"err:", 4))
2074 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred (%ls)"), resp->rlines[0].argv[1] + 4);
2082 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data)
2085 GtkTreeModel *model;
2091 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2093 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &id, 4, &locked, -1);
2100 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2104 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data)
2107 GtkTreeModel *model;
2112 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2114 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 5, &hash, -1);
2115 buf = sprintf2("H=%s", hash);
2116 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2119 cb_main_srchbtn_clicked(widget, NULL);
2122 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data)
2125 GtkTreeModel *model;
2129 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2131 gtk_widget_set_sensitive(reslist_delete, FALSE);
2132 gtk_widget_set_sensitive(reslist_search, FALSE);
2135 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 4, &locked, 5, &hash, -1);
2136 gtk_widget_set_sensitive(reslist_delete, !locked);
2137 gtk_widget_set_sensitive(reslist_search, hash && *hash);
2141 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
2144 GtkTreeModel *model;
2147 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
2148 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
2152 gtk_tree_model_get(model, &iter, 5, &hash, -1);
2153 buf = sprintf2("H=%s", hash);
2154 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2157 cb_main_srchbtn_clicked(widget, NULL);
2160 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
2162 GtkTreeSelection *sel;
2163 GtkTreeModel *model;
2168 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
2170 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2171 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2173 gtk_tree_model_get(model, &iter, 0, &id, 4, &locked, -1);
2177 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2186 void srchstatupdate(void)
2192 snprintf(buf, 1024, _("Ready to search"));
2194 snprintf(buf, 1024, _("Search scheduled and will be submitted in %i seconds"), (int)(srcheta - time(NULL)));
2196 if(strcmp(gtk_label_get_text(GTK_LABEL(main_srchstatus)), buf))
2197 gtk_label_set_text(GTK_LABEL(main_srchstatus), buf);
2200 gint srchstatupdatecb(gpointer data)
2206 void initchattags(void)
2210 chattags = gtk_text_tag_table_new();
2211 tag = gtk_text_tag_new("sender");
2212 g_object_set(tag, "foreground", "blue", NULL);
2213 gtk_text_tag_table_add(chattags, tag);
2216 #include "../dolda-icon.xpm"
2218 int main(int argc, char **argv)
2222 PangoFontDescription *monospacefont;
2223 GtkTreeModel *sortmodel;
2224 struct passwd *pwent;
2226 setlocale(LC_ALL, "");
2227 bindtextdomain(PACKAGE, LOCALEDIR);
2228 textdomain(PACKAGE);
2229 gtk_init(&argc, &argv);
2231 while((c = getopt(argc, argv, "lhV")) != -1) {
2237 printf("usage: dolcon [-hlV]\n");
2238 printf("\t-h\tDisplay this help message\n");
2239 printf("\t-l\tConnect to the locally running daemon\n");
2240 printf("\t-V\tDisplay version info and exit\n");
2243 printf("%s", RELEASEINFO);
2246 fprintf(stderr, "usage: dolcon [-hlV]\n");
2251 signal(SIGCHLD, SIG_IGN);
2252 pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.xml.bz2");
2253 dcserver = sstrdup("");
2254 if((pwent = getpwuid(getuid())) == NULL)
2256 fprintf(stderr, "could not get your passwd data");
2259 connectas = sstrdup(pwent->pw_name);
2260 gtk_window_set_default_icon(gdk_pixbuf_new_from_xpm_data((const char **)dolda_icon_xpm));
2261 wnd = create_main_wnd();
2262 create_reslist_wnd();
2263 gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400);
2266 fnmodel = gtk_list_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
2267 gtk_tree_view_set_model(GTK_TREE_VIEW(main_fnetnodes), GTK_TREE_MODEL(fnmodel));
2268 gtk_tree_view_set_model(GTK_TREE_VIEW(main_chatnodes), GTK_TREE_MODEL(fnmodel));
2270 reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
2271 gtk_tree_view_set_model(GTK_TREE_VIEW(reslist_list), GTK_TREE_MODEL(reslist));
2273 dlmodel = gtk_list_store_new(13, G_TYPE_INT, /* id */
2274 G_TYPE_INT, /* dir */
2275 G_TYPE_INT, /* state */
2276 G_TYPE_STRING, /* peerid */
2277 G_TYPE_STRING, /* peernick */
2278 G_TYPE_STRING, /* path */
2279 G_TYPE_INT, /* size */
2280 G_TYPE_INT, /* curpos */
2281 G_TYPE_STRING, /* stock */
2282 G_TYPE_FLOAT, /* percentage */
2283 G_TYPE_INT, /* error */
2284 G_TYPE_INT, /* errortime */
2285 G_TYPE_STRING); /* hash */
2286 gtk_tree_view_set_model(GTK_TREE_VIEW(main_downloads), GTK_TREE_MODEL(dlmodel));
2288 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);
2289 gtk_tree_view_set_model(GTK_TREE_VIEW(main_uploads), GTK_TREE_MODEL(ulmodel));
2291 srchmodel = gtk_tree_store_new(10, G_TYPE_STRING, /* fnetname */
2292 G_TYPE_STRING, /* peerid */
2293 G_TYPE_STRING, /* peername */
2294 G_TYPE_STRING, /* filename */
2295 G_TYPE_INT, /* size */
2296 G_TYPE_INT, /* slots */
2297 G_TYPE_DOUBLE, /* resptime */
2298 G_TYPE_INT, /* sizenum */
2299 G_TYPE_INT, /* speed */
2300 G_TYPE_STRING); /* hash */
2301 srchmodelfilter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(srchmodel), NULL));
2302 gtk_tree_model_filter_set_visible_func(srchmodelfilter, srchfilterfunc, NULL, NULL);
2303 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(srchmodelfilter));
2304 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 4, GTK_SORT_DESCENDING);
2305 gtk_tree_view_set_model(GTK_TREE_VIEW(main_srchres), GTK_TREE_MODEL(sortmodel));
2306 g_object_unref(sortmodel);
2308 monospacefont = pango_font_description_from_string("Monospace 10");
2309 gtk_widget_modify_font(main_chatview, monospacefont);
2310 pango_font_description_free(monospacefont);
2312 updatesbar(_("Disconnected"));
2313 gtk_widget_show(wnd);
2315 dcconnect(dc_srv_local);
2317 dcconnect(dcserver);
2318 g_timeout_add(500, srchstatupdatecb, NULL);
2319 g_timeout_add(5000, ksupdatecb, NULL);
2320 g_timeout_add(1000, updatetransfers, NULL);
2325 #include "mainwnd.gtk"
2326 #include "inpdialog.gtk"
2328 #include "reslist.gtk"