2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <doldaconnect/uilib.h>
30 #include <doldaconnect/uimisc.h>
31 #include <doldaconnect/utils.h>
45 #include "progressbar.h"
51 size_t poshist[TRHISTSIZE];
52 double timehist[TRHISTSIZE];
58 GtkTextBuffer *textbuf;
67 GtkTreeRowReference *ref;
78 GtkListStore *fnmodel, *ulmodel, *dlmodel, *pubhubmodel, *reslist;
79 GtkTreeStore *srchmodel;
80 GtkTreeModelFilter *srchmodelfilter;
81 GtkTextTagTable *chattags;
82 int dcfd = -1, gdkread = -1, gdkwrite = -1;
83 int pubhubfd = -1, pubhubtag = -1, filterpubhub = 0;
87 char *pubhubaddr = NULL;
88 char *connectas = NULL;
89 char *dcserver = NULL;
91 int srchautoupdate = 0;
92 int cursrch = -1, nextsrch = -1;
94 struct srchsize *srchsizes = NULL;
95 struct knownspeed *knownspeeds = NULL;
96 int numsizes = 0, numspeeds = 0, ksqueryseq = -1, ksquerytag = -1, lsrestag = -1;
98 gboolean initdeath(GtkWidget *, gpointer);
99 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data);
100 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data);
101 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data);
102 void cb_main_lsres_activate(GtkWidget *widget, gpointer data);
103 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data);
104 void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data);
105 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data);
106 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data);
107 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data);
108 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data);
109 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
110 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
111 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
112 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data);
113 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data);
114 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data);
115 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data);
116 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data);
117 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data);
118 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data);
119 void cb_main_srhash_activate(GtkWidget *widget, gpointer data);
120 void cb_main_srcopy_activate(GtkWidget *widget, gpointer data);
121 void cb_main_trhash_activate(GtkWidget *widget, gpointer data);
122 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data);
123 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data);
124 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data);
125 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data);
126 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data);
127 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data);
128 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data);
129 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data);
130 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data);
131 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data);
132 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition);
133 void srchstatupdate(void);
134 void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
135 void transspeedinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
136 void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
137 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
138 void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
139 void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
141 #define DCCHARSET "windows-1252"
143 #define _(text) gettext(text)
145 #include "mainwnd.gtk"
146 #include "inpdialog.gtk"
148 #include "reslist.gtk"
150 void updatewrite(void)
157 gdkwrite = gdk_input_add(dcfd, GDK_INPUT_WRITE, dcfdcallback, NULL);
161 gdk_input_remove(gdkwrite);
171 gettimeofday(&tv, NULL);
172 return((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
175 void fndestroycb(struct dc_fnetnode *fn)
178 GtkTextBuffer *textbuf;
181 g_object_unref(data->textbuf);
183 if(curchat == fn->id)
185 textbuf = gtk_text_buffer_new(chattags);
186 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), textbuf);
187 g_object_unref(textbuf);
191 void addfndata(struct dc_fnetnode *fn)
195 if(fn->udata != NULL)
197 fn->destroycb = fndestroycb;
198 data = smalloc(sizeof(*data));
199 data->textbuf = gtk_text_buffer_new(chattags);
203 void trdestroycb(struct dc_transfer *tr)
208 void addtrdata(struct dc_transfer *tr)
212 if(tr->udata != NULL)
214 tr->destroycb = trdestroycb;
215 data = smalloc(sizeof(*data));
216 memset(data, 0, sizeof(*data));
220 void updatetrdata(struct dc_transfer *tr)
226 if(data->hc < TRHISTSIZE)
228 data->poshist[data->hc] = tr->curpos;
229 data->timehist[data->hc] = ntime();
232 for(i = 0; i < TRHISTSIZE - 1; i++)
234 data->poshist[i] = data->poshist[i + 1];
235 data->timehist[i] = data->timehist[i + 1];
237 data->poshist[i] = tr->curpos;
238 data->timehist[i] = ntime();
242 char *getfnstatestock(int state)
244 if(state == DC_FNN_STATE_SYN)
245 return("gtk-jump-to");
246 if(state == DC_FNN_STATE_HS)
247 return("gtk-execute");
248 if(state == DC_FNN_STATE_EST)
250 if(state == DC_FNN_STATE_DEAD)
251 return("gtk-cancel");
255 void updatehublist(void)
258 struct dc_fnetnode *fn;
265 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
271 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
275 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
276 if((fn = dc_findfnetnode(id)) == NULL)
278 /* I can't seem to get a sensible reply fromp
279 * gtk_list_store, so I'm just doing this
281 gtk_list_store_remove(fnmodel, &iter);
285 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 1, &name, 2, &state, 3, &numusers, -1);
289 buf = icswcstombs(fn->name, "UTF-8", NULL);
290 if(strcmp(buf, name))
291 gtk_list_store_set(fnmodel, &iter, 1, buf, -1);
292 if(state != fn->state)
294 gtk_list_store_set(fnmodel, &iter, 2, fn->state, -1);
295 gtk_list_store_set(fnmodel, &iter, 4, getfnstatestock(fn->state), -1);
297 if(numusers != fn->numusers)
298 gtk_list_store_set(fnmodel, &iter, 3, fn->numusers, -1);
302 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
305 for(fn = dc_fnetnodes; fn != NULL; fn = fn->next)
312 buf = icswcstombs(fn->name, "UTF-8", NULL);
313 gtk_list_store_append(fnmodel, &iter);
314 gtk_list_store_set(fnmodel, &iter, 0, fn->id, 1, buf, 2, fn->state, 3, fn->numusers, 4, getfnstatestock(fn->state), -1);
320 char *bytes2si(int bytes)
328 for(i = 0; (b > 1024) && (i < 4); i++)
340 snprintf(ret, 64, "%.1f %s", b, sd);
344 void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
351 gtk_tree_model_get(model, iter, colnum, &val, -1);
352 snprintf(buf, 64, "%.2f%%", (double)(val * 100.0));
353 g_object_set(rend, "text", buf, NULL);
356 void transnicebytefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
362 gtk_tree_model_get(model, iter, colnum, &val, -1);
365 strcpy(buf, bytes2si(val));
368 snprintf(buf, 64, "%'i", val);
370 strcpy(buf, _("Unknown"));
371 g_object_set(rend, "text", buf, NULL);
374 void hidezerofunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
380 gtk_tree_model_get(model, iter, colnum, &val, -1);
382 snprintf(buf, 64, "%i", val);
385 g_object_set(rend, "text", buf, NULL);
388 void speedtimefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
390 int speed, size, time;
393 gtk_tree_model_get(model, iter, 4, &size, 8, &speed, -1);
396 time = (size / speed) / 60;
398 snprintf(buf, 64, "%'i (<00:01)", speed);
400 snprintf(buf, 64, "%'i (%02i:%02i)", speed, time / 60, time % 60);
401 } else if(speed == 0) {
404 strcpy(buf, _("Unknown"));
406 g_object_set(rend, "text", buf, NULL);
409 void transspeedinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
412 struct dc_transfer *tr;
417 gtk_tree_model_get(model, iter, 0, &id, -1);
418 if((tr = dc_findtransfer(id)) != NULL)
421 if((tr->state != DC_TRNS_MAIN) || (d == NULL))
424 } else if(d->hc < 2) {
427 speed = (((double)(d->poshist[d->hc - 1] - d->poshist[0])) / (d->timehist[d->hc - 1] - d->timehist[0]));
428 snprintf(buf, 64, "%s/s", bytes2si(speed));
433 g_object_set(rend, "text", buf, NULL);
436 void transerrorinfo(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
440 char finbuf[64], tbuf[64], *errstr;
442 gtk_tree_model_get(model, iter, 10, &error, 11, &errortime, -1);
443 if(error != DC_TRNSE_NOERROR)
445 if(error == DC_TRNSE_NOTFOUND)
446 errstr = _("Not found");
447 else if(error == DC_TRNSE_NOSLOTS)
448 errstr = _("No slots");
449 strftime(tbuf, 64, _("%H:%M:%S"), localtime(&errortime));
450 snprintf(finbuf, 64, _("%s (reported at %s)"), errstr, tbuf);
454 g_object_set(rend, "text", finbuf, NULL);
457 char *gettrstatestock(int state)
459 if(state == DC_TRNS_WAITING)
460 return("gtk-jump-to");
461 if(state == DC_TRNS_HS)
462 return("gtk-execute");
463 if(state == DC_TRNS_MAIN)
464 return("gtk-network");
465 if(state == DC_TRNS_DONE)
470 gint updatetransfers(gpointer data)
472 struct dc_transfer *tr;
477 for(tr = dc_transfers; tr != NULL; tr = tr->next)
479 if((d = tr->udata) != NULL)
481 if((d->hc > 0) && ((now - d->timehist[d->hc - 1]) > 2))
488 void updatetransferlists(void)
492 struct dc_transfer *transfer;
496 char *peerid, *peernick, *path, *hash;
497 int state, dir, size, curpos, error;
499 GtkListStore *stores[3];
501 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
503 stores[DC_TRNSD_UNKNOWN] = NULL;
504 stores[DC_TRNSD_UP] = ulmodel;
505 stores[DC_TRNSD_DOWN] = dlmodel;
506 for(i = 0; i < 3; i++)
508 if(stores[i] == NULL)
514 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(stores[i]), &iter))
518 gtk_tree_model_get(GTK_TREE_MODEL(stores[i]), &iter, 0, &id, 1, &dir, -1);
519 if(((transfer = dc_findtransfer(id)) == NULL) || (transfer->dir != dir))
521 gtk_list_store_remove(stores[i], &iter);
526 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);
527 if(state != transfer->state)
528 gtk_list_store_set(stores[i], &iter, 2, transfer->state, 8, gettrstatestock(transfer->state), -1);
529 if(size != transfer->size)
530 gtk_list_store_set(stores[i], &iter, 6, transfer->size, -1);
531 if(curpos != transfer->curpos)
533 gtk_list_store_set(stores[i], &iter, 7, transfer->curpos, -1);
534 if(transfer->udata != NULL)
535 updatetrdata(transfer);
537 if(error != transfer->error)
538 gtk_list_store_set(stores[i], &iter, 10, transfer->error, -1);
539 if(errortime != transfer->errortime)
540 gtk_list_store_set(stores[i], &iter, 11, transfer->errortime, -1);
541 if((transfer->size > 0) && (transfer->curpos > 0))
542 gtk_list_store_set(stores[i], &iter, 9, (float)transfer->curpos / (float)transfer->size, -1);
543 buf = icswcstombs(transfer->peerid, "UTF-8", NULL);
544 if(strcmp(buf, peerid))
545 gtk_list_store_set(stores[i], &iter, 3, buf, -1);
546 buf = icswcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8", NULL);
547 if(strcmp(buf, peernick))
548 gtk_list_store_set(stores[i], &iter, 4, buf, -1);
549 buf = (transfer->path == NULL)?_("Unknown"):icswcstombs(transfer->path, "UTF-8", NULL);
550 if(strcmp(buf, path))
551 gtk_list_store_set(stores[i], &iter, 5, buf, -1);
552 buf = (transfer->hash == NULL)?"":icswcstombs(transfer->hash, "UTF-8", NULL);
553 if(strcmp(buf, path))
554 gtk_list_store_set(stores[i], &iter, 12, buf, -1);
560 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(stores[i]), &iter));
564 for(transfer = dc_transfers; transfer != NULL; transfer = transfer->next)
568 if(stores[transfer->dir] != NULL)
570 peerid = icwcstombs(transfer->peerid, "UTF-8");
571 peernick = icwcstombs(((transfer->peernick == NULL) || (transfer->peernick[0] == L'\0'))?transfer->peerid:transfer->peernick, "UTF-8");
572 path = (transfer->path == NULL)?_("Unknown"):icwcstombs(transfer->path, "UTF-8");
573 hash = (transfer->hash == NULL)?"":icwcstombs(transfer->hash, "UTF-8");
574 gtk_list_store_append(stores[transfer->dir], &iter);
575 gtk_list_store_set(stores[transfer->dir], &iter,
584 8, gettrstatestock(transfer->state),
587 11, transfer->errortime,
592 if(transfer->path != NULL)
594 if(transfer->hash != NULL)
602 void updatesbar(char *msg)
604 gtk_statusbar_pop(GTK_STATUSBAR(main_statusbar), 0);
605 gtk_statusbar_push(GTK_STATUSBAR(main_statusbar), 0, msg);
608 void freesrchsizes(void)
612 for(i = 0; i < numsizes; i++)
614 if(srchsizes[i].ref != NULL)
615 gtk_tree_row_reference_free(srchsizes[i].ref);
617 if(srchsizes != NULL)
623 void dcdisconnected(void)
627 gdk_input_remove(gdkread);
632 updatetransferlists();
633 cursrch = nextsrch = -1;
634 gtk_tree_store_clear(srchmodel);
636 gtk_widget_set_sensitive(main_connmenu, TRUE);
637 gtk_widget_set_sensitive(main_dconnmenu, FALSE);
638 gtk_widget_set_sensitive(main_simplesrch, TRUE);
639 gtk_widget_set_sensitive(main_realsrch, TRUE);
640 gtk_widget_set_sensitive(main_srchbtn, TRUE);
641 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
642 updatesbar(_("Disconnected"));
645 char *inputbox(char *title, char *prompt, char *def, int echo)
651 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);
652 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(inpdialog)->vbox), swnd = create_inpdialog_wnd(), TRUE, TRUE, 0);
653 gtk_widget_show(swnd);
655 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), FALSE);
656 gtk_label_set_text(GTK_LABEL(inpdialog_prompt), prompt);
657 gtk_entry_set_text(GTK_ENTRY(inpdialog_entry), def);
658 resp = gtk_dialog_run(GTK_DIALOG(inpdialog));
660 gtk_entry_set_visibility(GTK_ENTRY(inpdialog_entry), TRUE);
661 if(resp == GTK_RESPONSE_ACCEPT)
662 buf = strdup(gtk_entry_get_text(GTK_ENTRY(inpdialog_entry)));
665 gtk_widget_destroy(inpdialog);
670 int msgbox(int type, int buttons, char *format, ...)
677 va_start(args, format);
678 buf = vsprintf2(format, args);
680 swnd = gtk_message_dialog_new(GTK_WINDOW(main_wnd), GTK_DIALOG_MODAL, type, buttons, "%s", buf);
681 resp = gtk_dialog_run(GTK_DIALOG(swnd));
682 gtk_widget_destroy(swnd);
687 void readconfigfile(void)
690 char *homedir, *buf, *p;
693 if((homedir = getenv("HOME")) == NULL)
695 fprintf(stderr, "warning: could not find home directory!\n");
698 buf = sprintf2("%s/.dolconrc", homedir);
699 if((cfgfile = fopen(buf, "r")) == NULL)
708 while(fgets(buf, 1024, cfgfile) != NULL)
712 p = buf + strlen(buf);
715 if((p = strchr(buf, ':')) == NULL)
718 while((*p == ' ') || (*p == '\t'))
720 if(!strcmp(buf, "wnd-width"))
723 } else if(!strcmp(buf, "wnd-height")) {
725 } else if(!strcmp(buf, "pane1-pos")) {
726 gtk_paned_set_position(GTK_PANED(main_pane1), atoi(p));
727 } else if(!strcmp(buf, "pane2-pos")) {
728 gtk_paned_set_position(GTK_PANED(main_pane2), atoi(p));
729 } else if(!strcmp(buf, "pane3-pos")) {
730 gtk_paned_set_position(GTK_PANED(main_pane3), atoi(p));
731 } else if(!strcmp(buf, "pubhubaddr")) {
733 pubhubaddr = sstrdup(p);
734 } else if(!strcmp(buf, "dcserver")) {
736 dcserver = sstrdup(p);
737 } else if(!strcmp(buf, "advexpanded")) {
738 gtk_expander_set_expanded(GTK_EXPANDER(main_advexp), atoi(p));
739 } else if(!strcmp(buf, "connectas")) {
741 connectas = sstrdup(p);
742 } else if(!strcmp(buf, "autoconn")) {
744 } else if(!strcmp(buf, "filternoslots")) {
745 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(main_filternoslots), atoi(p));
754 gtk_window_resize(GTK_WINDOW(main_wnd), w, h);
757 void updateconfigfile(void)
763 if((homedir = getenv("HOME")) == NULL)
765 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not get your home directory!"));
768 buf = sprintf2("%s/.dolconrc", homedir);
769 if((cfgfile = fopen(buf, "w")) == NULL)
772 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not open configuration file for writing: %s"), strerror(errno));
776 gtk_window_get_size(GTK_WINDOW(main_wnd), &w, &h);
777 fprintf(cfgfile, "wnd-width: %i\n", w);
778 fprintf(cfgfile, "wnd-height: %i\n", h);
779 fprintf(cfgfile, "pane1-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane1)));
780 fprintf(cfgfile, "pane2-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane2)));
781 fprintf(cfgfile, "pane3-pos: %i\n", gtk_paned_get_position(GTK_PANED(main_pane3)));
782 fprintf(cfgfile, "pubhubaddr: %s\n", pubhubaddr);
783 fprintf(cfgfile, "dcserver: %s\n", dcserver);
784 fprintf(cfgfile, "advexpanded: %i\n", gtk_expander_get_expanded(GTK_EXPANDER(main_advexp)));
785 fprintf(cfgfile, "connectas: %s\n", connectas);
786 fprintf(cfgfile, "autoconn: %i\n", autoconn);
787 fprintf(cfgfile, "filternoslots: %i\n", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots)));
791 gboolean initdeath(GtkWidget *widget, gpointer data)
798 void cb_inpdialog_entry_activate(GtkWidget *widget, gpointer data)
800 gtk_dialog_response(GTK_DIALOG(inpdialog), GTK_RESPONSE_ACCEPT);
803 int loginconv(int type, wchar_t *prompt, char **resp, void *data)
809 buf = icwcstombs(prompt, "UTF-8");
812 case DC_LOGIN_CONV_NOECHO:
813 if((*resp = inputbox(_("Login"), buf, "", 0)) == NULL)
816 case DC_LOGIN_CONV_ECHO:
817 if((*resp = inputbox(_("Login"), buf, "", 1)) == NULL)
820 case DC_LOGIN_CONV_INFO:
821 msgbox(GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", buf);
823 case DC_LOGIN_CONV_ERROR:
824 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", buf);
832 void getfnlistcallback(int resp, void *data)
837 void gettrlistcallback(int resp, void *data)
839 updatetransferlists();
842 void logincallback(int err, wchar_t *reason, void *data)
846 case DC_LOGIN_ERR_SUCCESS:
847 dc_queuecmd(NULL, NULL, L"notify", L"all", L"on", NULL);
848 dc_getfnlistasync(getfnlistcallback, NULL);
849 dc_gettrlistasync(gettrlistcallback, NULL);
850 updatesbar("Authenticated");
852 case DC_LOGIN_ERR_NOLOGIN:
853 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not negotiate an acceptable authentication mechanism"));
857 case DC_LOGIN_ERR_SERVER:
858 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has encountered an error"));
862 case DC_LOGIN_ERR_USER:
863 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Internal client error"));
867 case DC_LOGIN_ERR_CONV:
871 case DC_LOGIN_ERR_AUTHFAIL:
872 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Login attempt failed!"));
880 GtkTreeIter *ref2iter(GtkTreeRowReference *ref)
882 static GtkTreeIter iter;
885 assert((path = gtk_tree_row_reference_get_path(ref)) != NULL);
886 assert(gtk_tree_model_get_iter(GTK_TREE_MODEL(srchmodel), &iter, path));
887 gtk_tree_path_free(path);
891 GtkTreeRowReference *iter2ref(GtkTreeIter *iter)
894 GtkTreeRowReference *ref;
896 assert((path = gtk_tree_model_get_path(GTK_TREE_MODEL(srchmodel), iter)) != NULL);
897 assert((ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(srchmodel), path)) != NULL);
898 gtk_tree_path_free(path);
902 struct srchsize *finddiscsize(void)
907 for(i = 0; i < numsizes; i++)
909 if(srchsizes[i].size == -1)
910 return(&srchsizes[i]);
912 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
913 srchsizes[i].size = -1;
914 srchsizes[i].num = 1;
915 srchsizes[i].slots = 0;
916 srchsizes[i].resptime = 0.0;
917 gtk_tree_store_append(srchmodel, &iter, NULL);
918 gtk_tree_store_set(srchmodel, &iter, 3, _("Discrete sizes"), 7, 1, -1);
919 srchsizes[i].ref = iter2ref(&iter);
920 return(&srchsizes[i]);
923 struct knownspeed *findksentbyname(char *userid)
927 for(i = 0; i < numspeeds; i++)
929 if(!strcmp(knownspeeds[i].userid, userid))
930 return(&knownspeeds[i]);
935 struct knownspeed *findksentbyseq(int seq)
939 for(i = 0; i < numspeeds; i++)
941 if(knownspeeds[i].seq == seq)
942 return(&knownspeeds[i]);
947 gboolean ksupdaterow(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
949 struct knownspeed *ks;
952 gtk_tree_model_get(GTK_TREE_MODEL(model), iter, 1, &userid, -1);
955 ks = findksentbyname(userid);
958 knownspeeds = srealloc(knownspeeds, (numspeeds + 1) * sizeof(*knownspeeds));
959 ks = &knownspeeds[numspeeds];
961 ks->userid = sstrdup(userid);
968 gtk_tree_store_set(GTK_TREE_STORE(model), iter, 8, ks->speed, -1);
972 gint ksupdatecb(gpointer data)
976 wchar_t **users, *buf;
977 size_t userssize, usersdata;
983 for(i = 0; i < numspeeds;)
985 if(now - knownspeeds[i].fetched > 60)
987 free(knownspeeds[i].userid);
988 memmove(&knownspeeds[i], &knownspeeds[i + 1], (--numspeeds - i) * sizeof(*knownspeeds));
993 if(oldnum != numspeeds)
1000 knownspeeds = srealloc(knownspeeds, numspeeds * sizeof(*knownspeeds));
1003 gtk_tree_model_foreach(GTK_TREE_MODEL(srchmodel), ksupdaterow, NULL);
1004 if(ksqueryseq == -2)
1007 userssize = usersdata = 0;
1009 for(i = 0; i < numspeeds; i++)
1011 if(knownspeeds[i].seq == -2)
1013 assert((buf = icmbstowcs(knownspeeds[i].userid, "UTF-8")) != NULL);
1014 knownspeeds[i].seq = ksqueryseq++;
1015 addtobuf(users, buf);
1018 addtobuf(users, NULL);
1019 ksquerytag = dc_queuecmd(NULL, NULL, L"filtercmd", L"userspeeda", L"%%a", users, NULL);
1020 dc_freewcsarr(users);
1025 void handleresps(void)
1028 struct dc_response *resp;
1029 struct dc_intresp *ires;
1030 struct dc_fnetnode *fn;
1031 struct fndata *fndata;
1033 GtkTreeIter titer, piter;
1036 struct srchsize *ss;
1037 struct knownspeed *ks;
1039 while((resp = dc_getresp()) != NULL)
1041 if(!wcscmp(resp->cmdname, L".connect"))
1043 if(resp->code == 200)
1045 tosbuf = 0x10; /* Minimum cost */
1046 setsockopt(dcfd, SOL_IP, IP_TOS, &tosbuf, sizeof(tosbuf));
1047 updatesbar(_("Connected"));
1048 dc_loginasync(connectas, 1, loginconv, logincallback, NULL);
1050 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server refused the connection"));
1054 } else if(!wcscmp(resp->cmdname, L".notify")) {
1055 dc_uimisc_handlenotify(resp);
1059 if((ires = dc_interpret(resp)) != NULL)
1061 if((fn = dc_findfnetnode(ires->argv[0].val.num)) != NULL)
1064 gtk_text_buffer_get_end_iter(fndata->textbuf, &iter);
1065 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1067 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, "<", -1, "sender", NULL);
1068 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, buf, -1, "sender", NULL);
1069 gtk_text_buffer_insert_with_tags_by_name(fndata->textbuf, &iter, ">", -1, "sender", NULL);
1070 gtk_text_buffer_insert(fndata->textbuf, &iter, " ", -1);
1073 if((buf = icwcstombs(ires->argv[4].val.str, "UTF-8")) != NULL)
1075 gtk_text_buffer_insert(fndata->textbuf, &iter, buf, -1);
1076 gtk_text_buffer_insert(fndata->textbuf, &iter, "\n", -1);
1078 if(curchat == fn->id)
1079 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(main_chatview), &iter, 0, 0, 0, 0);
1101 updatetransferlists();
1104 if((ires = dc_interpret(resp)) != NULL)
1106 if(ires->argv[0].val.num == nextsrch)
1107 srcheta = time(NULL) + ires->argv[0].val.num;
1112 if((ires = dc_interpret(resp)) != NULL)
1114 if(ires->argv[0].val.num == nextsrch)
1117 dc_queuecmd(NULL, NULL, L"cansrch", L"%%i", cursrch, NULL);
1120 gtk_widget_set_sensitive(main_realsrch, TRUE);
1121 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1122 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1123 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1125 gtk_entry_set_text(GTK_ENTRY(main_realsrch), "");
1126 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1127 gtk_tree_store_clear(srchmodel);
1134 if((ires = dc_interpret(resp)) != NULL)
1136 if(ires->argv[0].val.num == cursrch)
1138 for(i = 0; i < numsizes; i++)
1140 if(srchsizes[i].size == ires->argv[4].val.num)
1145 srchsizes = srealloc(srchsizes, sizeof(*srchsizes) * ++numsizes);
1146 srchsizes[i].size = ires->argv[4].val.num;
1147 srchsizes[i].num = 1;
1148 srchsizes[i].slots = ires->argv[5].val.num;
1149 srchsizes[i].resptime = ires->argv[7].val.flnum;
1150 ss = finddiscsize();
1151 ss->slots += ires->argv[5].val.num;
1152 if((ss->resptime == 0.0) || (ss->resptime > ires->argv[7].val.flnum))
1153 ss->resptime = ires->argv[7].val.flnum;
1154 piter = *ref2iter(ss->ref);
1155 gtk_tree_store_set(srchmodel, &piter, 5, ss->slots, 6, ss->resptime, -1);
1156 gtk_tree_store_append(srchmodel, &titer, &piter);
1157 srchsizes[i].ref = iter2ref(&titer);
1158 } else if(srchsizes[i].num == 1) {
1159 char *filename, *peername, *fnetname, *hash;
1163 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);
1164 gtk_tree_store_remove(srchmodel, ref2iter(srchsizes[i].ref));
1165 gtk_tree_row_reference_free(srchsizes[i].ref);
1166 ss = finddiscsize();
1168 gtk_tree_store_set(srchmodel, ref2iter(ss->ref), 5, ss->slots, -1);
1169 gtk_tree_store_append(srchmodel, &piter, NULL);
1170 srchsizes[i].slots = ires->argv[5].val.num + slots;
1171 srchsizes[i].resptime = (ires->argv[7].val.flnum < resptime)?ires->argv[7].val.flnum:resptime;
1172 srchsizes[i].num = 2;
1173 srchsizes[i].ref = iter2ref(&piter);
1174 gtk_tree_store_set(srchmodel, &piter, 4, srchsizes[i].size, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, 2, -1);
1175 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1178 /* XXX: Too NMDC-specific! */
1179 if(strrchr(p, '\\') != NULL)
1180 p = strrchr(p, '\\') + 1;
1181 gtk_tree_store_set(srchmodel, &piter, 3, p, -1);
1184 gtk_tree_store_append(srchmodel, &titer, &piter);
1185 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);
1186 g_free(filename); g_free(peername); g_free(fnetname); g_free(hash);
1187 gtk_tree_store_append(srchmodel, &titer, &piter);
1190 srchsizes[i].slots += ires->argv[5].val.num;
1191 if(ires->argv[7].val.flnum < srchsizes[i].resptime)
1192 srchsizes[i].resptime = ires->argv[7].val.flnum;
1193 piter = *ref2iter(srchsizes[i].ref);
1194 gtk_tree_store_set(srchmodel, &piter, 5, srchsizes[i].slots, 6, srchsizes[i].resptime, 7, srchsizes[i].num, -1);
1195 gtk_tree_store_append(srchmodel, &titer, &piter);
1197 if((buf = icwcstombs(ires->argv[1].val.str, "UTF-8")) != NULL)
1199 gtk_tree_store_set(srchmodel, &titer, 3, buf, -1);
1202 if((buf = icwcstombs(ires->argv[2].val.str, "UTF-8")) != NULL)
1204 gtk_tree_store_set(srchmodel, &titer, 0, buf, -1);
1207 if((buf = icwcstombs(ires->argv[3].val.str, "UTF-8")) != NULL)
1209 gtk_tree_store_set(srchmodel, &titer, 1, buf, -1);
1210 gtk_tree_store_set(srchmodel, &titer, 2, buf, -1);
1213 if((buf = icwcstombs(ires->argv[8].val.str, "UTF-8")) != NULL)
1215 gtk_tree_store_set(srchmodel, &titer, 9, buf, -1);
1218 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);
1226 } else if(!wcscmp(resp->cmdname, L"filtercmd")) {
1227 if((ksquerytag >= 0) && (ksquerytag == resp->tag))
1229 for(i = 0; i < resp->numlines; i++)
1231 assert((ks = findksentbyseq(i)) != NULL);
1232 ks->speed = wcstol(resp->rlines[i].argv[1], NULL, 10);
1234 ks->fetched = time(NULL);
1238 } else if((lsrestag >= 0) && (lsrestag == resp->tag)) {
1239 for(i = 0; i < resp->numlines; i++)
1241 if(!wcsncmp(resp->rlines[i].argv[1], L"id:", 3))
1243 gtk_list_store_append(reslist, &titer);
1244 gtk_list_store_set(reslist, &titer, 0, icswcstombs(resp->rlines[i].argv[1] + 3, "UTF-8", NULL), -1);
1245 } else if(!wcsncmp(resp->rlines[i].argv[1], L"size:", 5)) {
1246 gtk_list_store_set(reslist, &titer, 1, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1247 } else if(!wcsncmp(resp->rlines[i].argv[1], L"prog:", 5)) {
1248 gtk_list_store_set(reslist, &titer, 2, wcstol(resp->rlines[i].argv[1] + 5, NULL, 10), -1);
1249 } else if(!wcsncmp(resp->rlines[i].argv[1], L"name:", 5)) {
1250 gtk_list_store_set(reslist, &titer, 3, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1251 } else if(!wcsncmp(resp->rlines[i].argv[1], L"lock:", 5)) {
1252 if(!wcscmp(resp->rlines[i].argv[1] + 5, L"yes"))
1253 gtk_list_store_set(reslist, &titer, 4, TRUE, -1);
1255 gtk_list_store_set(reslist, &titer, 4, FALSE, -1);
1256 } else if(!wcsncmp(resp->rlines[i].argv[1], L"hash:", 5)) {
1257 gtk_list_store_set(reslist, &titer, 5, icswcstombs(resp->rlines[i].argv[1] + 5, "UTF-8", NULL), -1);
1261 gtk_widget_set_sensitive(reslist_reload, TRUE);
1269 void dcfdcallback(gpointer data, gint source, GdkInputCondition condition)
1273 if(((condition & GDK_INPUT_READ) && dc_handleread()) || ((condition & GDK_INPUT_WRITE) && dc_handlewrite()))
1279 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The server has closed the connection"));
1281 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("The connection to the server failed:\n\n%s"), strerror(errnobak));
1288 void cb_main_dconnmenu_activate(GtkWidget *widget, gpointer data)
1296 void cb_main_prefmenu_activate(GtkWidget *widget, gpointer data)
1298 GtkWidget *dialog, *swnd;
1301 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);
1302 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), swnd = create_pref_wnd(), TRUE, TRUE, 0);
1303 gtk_entry_set_text(GTK_ENTRY(pref_pubhuburl), pubhubaddr);
1304 gtk_entry_set_text(GTK_ENTRY(pref_connectas), connectas);
1305 gtk_entry_set_text(GTK_ENTRY(pref_dcserver), dcserver);
1306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref_autoconn), autoconn);
1307 gtk_widget_show(swnd);
1308 resp = gtk_dialog_run(GTK_DIALOG(dialog));
1309 if(resp == GTK_RESPONSE_ACCEPT)
1312 pubhubaddr = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_pubhuburl)));
1314 connectas = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_connectas)));
1316 dcserver = sstrdup(gtk_entry_get_text(GTK_ENTRY(pref_dcserver)));
1317 autoconn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_autoconn));
1319 gtk_widget_destroy(dialog);
1322 void cb_main_lsres_activate(GtkWidget *widget, gpointer data)
1324 gtk_list_store_clear(reslist);
1325 gtk_widget_set_sensitive(reslist_delete, FALSE);
1326 gtk_widget_set_sensitive(reslist_search, FALSE);
1327 gtk_widget_show(reslist_wnd);
1330 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
1331 gtk_widget_set_sensitive(reslist_reload, FALSE);
1335 void dcconnect(char *host)
1337 dcfd = dc_connect(host, -1);
1340 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not connect:\n\n%s"), strerror(errno));
1343 gdkread = gdk_input_add(dcfd, GDK_INPUT_READ, dcfdcallback, NULL);
1345 gtk_widget_set_sensitive(main_connmenu, FALSE);
1346 gtk_widget_set_sensitive(main_dconnmenu, TRUE);
1347 updatesbar(_("Connecting..."));
1350 void cb_main_connmenu_activate(GtkWidget *widget, gpointer data)
1356 if((buf = inputbox(_("Connect"), _("Server address:"), dcserver, 1)) == NULL)
1362 void cb_main_sdmenu_activate(GtkWidget *widget, gpointer data)
1365 struct dc_response *resp;
1369 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1372 tag = dc_queuecmd(NULL, NULL, L"shutdown", NULL);
1373 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1375 if(resp->code == 502)
1376 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1382 void cb_main_fnaddr_activate(GtkWidget *widget, gpointer data)
1385 struct dc_response *resp;
1390 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1393 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_fnaddr)), "UTF-8", NULL));
1396 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Illegal address entered"));
1399 if(wcschr(toks[0], L':') == NULL)
1401 toks[0] = srealloc(toks[0], (wcslen(toks[0]) + 5) * sizeof(wchar_t));
1402 wcscat(toks[0], L":411");
1404 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%%a", toks, NULL);
1405 dc_freewcsarr(toks);
1406 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1408 if(resp->code == 502)
1409 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1410 if(resp->code == 509)
1411 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1412 if(resp->code == 515)
1413 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1416 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1420 void pubhubfdcallback(gpointer data, gint source, GdkInputCondition condition)
1422 static char buf[65536];
1423 static int bufpos = 0;
1429 int sorted, sortcol;
1430 GtkSortType sortorder;
1431 GtkTreeModel *sortmodel;
1433 if(!(condition & GDK_INPUT_READ))
1437 ret = read(pubhubfd, buf + bufpos, sizeof(buf) - bufpos);
1441 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not read from public hub listing process: %s"), strerror(errno));
1443 gdk_input_remove(pubhubtag);
1444 kill(pubhubproc, SIGINT);
1445 pubhubfd = pubhubtag = -1;
1450 regfree(&pubhubfilter);
1456 sortmodel = gtk_tree_view_get_model(GTK_TREE_VIEW(main_phublist));
1457 sorted = gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(sortmodel), &sortcol, &sortorder);
1458 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), NULL);
1459 while((p = memchr(buf, '\n', bufpos)) != NULL)
1462 if(!filterpubhub || !regexec(&pubhubfilter, buf, 0, NULL, 0))
1465 for(i = 0; i < 4; i++)
1468 if((p2 = strchr(p2, '|')) == NULL)
1474 for(i = 0; i < 4; i++)
1476 if((wbuf = icsmbstowcs(fields[i], DCCHARSET, NULL)) == NULL)
1479 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Could not decode hublist - aborting at this point: %s"), strerror(errno));
1480 kill(pubhubproc, SIGINT);
1483 fields[i] = sstrdup(_("(Invalid character)"));
1485 if((fields[i] = icwcstombs(wbuf, "UTF-8")) == NULL)
1491 gtk_list_store_append(pubhubmodel, &iter);
1492 gtk_list_store_set(pubhubmodel, &iter, 0, fields[0], 1, fields[1], 2, fields[2], 3, atoi(fields[3]), -1);
1494 for(i--; i >= 0; i--)
1498 memmove(buf, p, bufpos -= p - buf);
1500 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(pubhubmodel));
1502 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), sortcol, sortorder);
1503 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), sortmodel);
1506 void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data)
1508 int pipe1[2], pipe2[2];
1514 gdk_input_remove(pubhubtag);
1518 kill(pubhubproc, SIGINT);
1521 regfree(&pubhubfilter);
1524 buf = gtk_entry_get_text(GTK_ENTRY(main_pubhubfilter));
1527 if((err = regcomp(&pubhubfilter, buf, REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
1529 regerror(err, &pubhubfilter, errbuf, sizeof(errbuf));
1530 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not compile regex: %s", errbuf);
1531 regfree(&pubhubfilter);
1537 gtk_list_store_clear(pubhubmodel);
1539 if((pubhubproc = fork()) == 0)
1544 execlp("wget", "wget", "-qO", "-", pubhubaddr, NULL);
1549 pubhubfd = pipe1[0];
1550 len = strlen(pubhubaddr);
1551 if((len > 4) && !strcmp(pubhubaddr + len - 4, ".bz2"))
1561 execlp("bzcat", "bzcat", NULL);
1567 pubhubfd = pipe2[0];
1569 pubhubtag = gdk_input_add(pubhubfd, GDK_INPUT_READ, pubhubfdcallback, NULL);
1572 void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data)
1576 struct dc_response *resp;
1580 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1583 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_fnetnodes)), NULL, &iter))
1585 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1588 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1589 tag = dc_queuecmd(NULL, NULL, L"dcnct", L"%%i", id, 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"));
1599 void cb_main_phublist_cchange(GtkWidget *widget, gpointer data)
1602 GtkTreeModel *model;
1605 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(main_phublist)), &model, &iter))
1607 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &addr, -1);
1608 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), addr);
1612 void cb_main_phublist_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1615 struct dc_response *resp;
1617 GtkTreeModel *model;
1622 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1625 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1626 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1628 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &buf, -1);
1629 if(strchr(buf, ':') == NULL)
1631 buf = g_realloc(buf, strlen(buf) + 5);
1632 strcat(buf, ":411");
1634 tag = dc_queuecmd(NULL, NULL, L"cnct", L"dc", L"%%s", buf, NULL);
1636 gtk_entry_set_text(GTK_ENTRY(main_fnaddr), "");
1637 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1639 if(resp->code == 502)
1640 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1641 if(resp->code == 509)
1642 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse that address"));
1643 if(resp->code == 515)
1644 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("There are too many hubs connected"));
1650 void cb_main_chatnodes_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer uudata)
1654 struct dc_fnetnode *fn;
1655 struct fndata *data;
1657 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(fnmodel), &iter, path))
1659 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1660 if((fn = dc_findfnetnode(id)) == NULL)
1664 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(fnmodel), &iter))
1668 gtk_tree_model_get(GTK_TREE_MODEL(fnmodel), &iter, 0, &id, -1);
1670 gtk_list_store_set(fnmodel, &iter, 5, "gtk-apply", -1);
1672 gtk_list_store_set(fnmodel, &iter, 5, NULL, -1);
1673 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(fnmodel), &iter));
1675 gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_chatview), GTK_TEXT_BUFFER(data->textbuf));
1678 void cb_main_chatstr_activate(GtkWidget *widget, gpointer data)
1682 struct dc_response *resp;
1686 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1691 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("No hub selected"));
1694 buf = gtk_entry_get_text(GTK_ENTRY(main_chatstr));
1695 tag = dc_queuecmd(NULL, NULL, L"sendchat", L"%%i", curchat, L"1", L"", L"%%s", buf, NULL);
1696 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1698 if(resp->code == 502)
1699 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1700 else if(resp->code == 504)
1701 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub could not support all the types of characters in your chat message"));
1702 else if(resp->code == 513)
1703 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("This hub does not support chatting"));
1704 else if(resp->code != 200)
1705 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to chat (%i)"), resp->code);
1708 gtk_entry_set_text(GTK_ENTRY(main_chatstr), "");
1712 void updatesrchfld(const char *simple)
1716 size_t bufsize, bufdata;
1718 s = sstrdup(simple);
1720 bufsize = bufdata = 0;
1724 p2 = strchr(p, ' ');
1730 bufcat(buf, " & ", 3);
1731 bufcat(buf, "N~", 2);
1734 if(strchr("[]()$^.*?+\\|\"!", *p) != NULL)
1735 addtobuf(buf, '\\');
1740 } while(p2 != NULL);
1742 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1747 void cb_main_simplesrch_changed(GtkWidget *widget, gpointer data)
1752 updatesrchfld(gtk_entry_get_text(GTK_ENTRY(main_simplesrch)));
1756 void cb_main_realsrch_changed(GtkWidget *widget, gpointer data)
1761 gtk_entry_set_text(GTK_ENTRY(main_simplesrch), "");
1765 void cb_main_srchbtn_clicked(GtkWidget *widget, gpointer data)
1769 struct dc_response *resp;
1770 struct dc_intresp *ires;
1774 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1777 if(nextsrch != -1) /* Impossible case, but oh well... */
1779 toks = dc_lexsexpr(icsmbstowcs((char *)gtk_entry_get_text(GTK_ENTRY(main_realsrch)), "UTF-8", NULL));
1782 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Please enter a search expression before searching"));
1785 tag = dc_queuecmd(NULL, NULL, L"search", L"all", L"%%a", toks, NULL);
1786 dc_freewcsarr(toks);
1787 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1789 if(resp->code == 501)
1790 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not find any hubs to search on"));
1791 else if(resp->code == 502)
1792 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1793 else if(resp->code == 509)
1794 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("The server could not parse your search expression"));
1795 else if(resp->code != 200)
1796 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to search (%i)"), resp->code);
1797 if(resp->code == 200)
1799 if((ires = dc_interpret(resp)) != NULL)
1801 nextsrch = ires->argv[0].val.num;
1802 srcheta = time(NULL) + ires->argv[1].val.num;
1805 gtk_widget_set_sensitive(main_realsrch, FALSE);
1806 gtk_widget_set_sensitive(main_simplesrch, FALSE);
1807 gtk_widget_set_sensitive(main_srchbtn, FALSE);
1808 gtk_widget_set_sensitive(main_srchcanbtn, TRUE);
1816 void cb_main_srchcanbtn_clicked(GtkWidget *widget, gpointer data)
1820 dc_queuecmd(NULL, NULL, L"cansrch", L"%%i", nextsrch, NULL);
1822 gtk_widget_set_sensitive(main_realsrch, TRUE);
1823 gtk_widget_set_sensitive(main_simplesrch, TRUE);
1824 gtk_widget_set_sensitive(main_srchbtn, TRUE);
1825 gtk_widget_set_sensitive(main_srchcanbtn, FALSE);
1829 gboolean cb_main_trlist_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
1832 GtkTreeSelection *sel;
1833 GtkTreeModel *model;
1835 struct dc_response *resp;
1837 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
1839 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
1840 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1842 gtk_tree_model_get(model, &iter, 0, &id, -1);
1843 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%%i", id, NULL);
1844 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1846 if(resp->code == 502)
1847 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1848 else if(resp->code != 200)
1849 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
1859 void cb_main_srchres_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
1862 struct dc_response *resp;
1864 GtkTreeModel *model;
1866 char *tfnet, *tpeerid, *tfilename, *thash, *arg;
1867 wchar_t *fnet, *peerid, *filename, *hash;
1871 msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Not connected to DC server"));
1874 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1875 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
1877 gtk_tree_model_get(model, &iter, 7, &num, -1);
1880 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &tfnet, 1, &tpeerid, 3, &tfilename, 4, &size, 9, &thash, -1);
1881 fnet = icmbstowcs(tfnet, "UTF-8");
1882 peerid = icmbstowcs(tpeerid, "UTF-8");
1883 filename = icmbstowcs(tfilename, "UTF-8");
1884 hash = (thash == NULL)?NULL:icmbstowcs(thash, "UTF-8");
1885 if((fnet == NULL) || (peerid == NULL) || (filename == NULL))
1891 if(filename != NULL)
1905 arg = (char *)gtk_entry_get_text(GTK_ENTRY(main_dlarg));
1907 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);
1909 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);
1915 if((resp = dc_gettaggedrespsync(tag)) != NULL)
1917 if(resp->code == 502)
1918 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
1919 if(resp->code != 200)
1920 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to queue the download (%i)"), resp->code);
1926 gboolean srchfilterfunc(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1931 filteratall = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(main_filternoslots));
1934 gtk_tree_model_get(model, iter, 5, &slots, -1);
1940 void cb_main_filternoslots_toggled(GtkToggleButton *widget, gpointer data)
1942 gtk_tree_model_filter_refilter(srchmodelfilter);
1945 void cb_main_srhash_activate(GtkWidget *widget, gpointer data)
1947 GtkTreeSelection *sel;
1948 GtkTreeModel *model;
1954 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1955 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1957 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1958 buf = sprintf2("H=%s", hash);
1959 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
1962 cb_main_srchbtn_clicked(widget, NULL);
1968 void cb_main_srcopy_activate(GtkWidget *widget, gpointer data)
1971 GtkTreeSelection *sel;
1972 GtkTreeModel *model;
1978 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_srchres));
1979 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
1981 gtk_tree_model_get(model, &iter, 9, &hash, -1);
1982 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
1983 gtk_clipboard_set_text(cb, hash, -1);
1987 void cb_main_trhash_activate(GtkWidget *widget, gpointer data)
1989 GtkTreeSelection *sel;
1990 GtkTreeModel *model;
1996 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
1997 if(gtk_tree_selection_get_selected(sel, &model, &iter))
1999 gtk_tree_model_get(model, &iter, 12, &hash, -1);
2000 buf = sprintf2("H=%s", hash);
2001 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2004 cb_main_srchbtn_clicked(widget, NULL);
2010 void cb_main_trcopy_activate(GtkWidget *widget, gpointer data)
2013 GtkTreeSelection *sel;
2014 GtkTreeModel *model;
2018 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
2019 if(!gtk_tree_selection_get_selected(sel, &model, &iter))
2021 gtk_tree_model_get(model, &iter, 12, &hash, -1);
2022 cb = gtk_clipboard_get(gdk_atom_intern("PRIMARY", FALSE));
2023 gtk_clipboard_set_text(cb, hash, -1);
2027 void cb_main_trcancel_activate(GtkWidget *widget, gpointer data)
2029 GtkTreeSelection *sel;
2030 GtkTreeModel *model;
2033 struct dc_response *resp;
2037 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_downloads));
2038 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2040 gtk_tree_model_get(model, &iter, 0, &id, -1);
2041 tag = dc_queuecmd(NULL, NULL, L"cancel", L"%%i", id, NULL);
2042 if((resp = dc_gettaggedrespsync(tag)) != NULL)
2044 if(resp->code == 502)
2045 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("You do not have permission to do that"));
2046 else if(resp->code != 200)
2047 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred while trying to cancel (%i)"), resp->code);
2056 /* XXX: This is quite a hack, since the calling convention is
2057 * different for the popup-menu sig and the button-press-event sig. It
2058 * most certainly works, but I don't know how portable it is. */
2059 gboolean cb_main_srpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
2061 GtkTreeSelection *sel;
2062 GtkTreeModel *model;
2066 if((event != NULL) && (event->button != 3))
2068 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2069 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2071 gtk_tree_model_get(model, &iter, 9, &hash, -1);
2072 if((hash == NULL) || (*hash == 0))
2074 gtk_widget_set_sensitive(main_srhash, FALSE);
2075 gtk_widget_set_sensitive(main_srcopy, FALSE);
2078 gtk_widget_set_sensitive(main_srhash, TRUE);
2080 gtk_widget_set_sensitive(main_srhash, FALSE);
2081 gtk_widget_set_sensitive(main_srcopy, TRUE);
2088 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2090 gtk_menu_popup(GTK_MENU(main_srpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2094 /* The above hack note goes for this one too. */
2095 gboolean cb_main_trpopup(GtkWidget *widget, GdkEventButton *event, gpointer data)
2097 GtkTreeSelection *sel;
2098 GtkTreeModel *model;
2102 if((event != NULL) && (event->button != 3))
2104 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2105 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2107 gtk_tree_model_get(model, &iter, 12, &hash, -1);
2108 if((hash == NULL) || (*hash == 0))
2110 gtk_widget_set_sensitive(main_trhash, FALSE);
2111 gtk_widget_set_sensitive(main_trcopy, FALSE);
2114 gtk_widget_set_sensitive(main_trhash, TRUE);
2116 gtk_widget_set_sensitive(main_trhash, FALSE);
2117 gtk_widget_set_sensitive(main_trcopy, TRUE);
2124 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
2126 gtk_menu_popup(GTK_MENU(main_trpopup), NULL, NULL, NULL, NULL, event->button, event->time);
2130 void cb_reslist_reload_clicked(GtkWidget *widget, gpointer data)
2134 gtk_widget_set_sensitive(reslist_delete, FALSE);
2135 gtk_widget_set_sensitive(reslist_search, FALSE);
2136 gtk_list_store_clear(reslist);
2137 lsrestag = dc_queuecmd(NULL, NULL, L"filtercmd", L"lsres", NULL);
2138 gtk_widget_set_sensitive(reslist_reload, FALSE);
2144 struct dc_response *resp;
2147 tag = dc_queuecmd(NULL, NULL, L"filtercmd", L"rmres", L"%%s", id, NULL);
2148 if((resp = dc_gettaggedrespsync(tag)) != NULL)
2150 if(resp->numlines > 0)
2152 if(!wcscmp(resp->rlines[0].argv[1], L"ok"))
2154 else if(!wcsncmp(resp->rlines[0].argv[1], L"err:", 4))
2155 msgbox(GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("An error occurred (%ls)"), resp->rlines[0].argv[1] + 4);
2163 void cb_reslist_delete_clicked(GtkWidget *widget, gpointer data)
2166 GtkTreeModel *model;
2172 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2174 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 0, &id, 4, &locked, -1);
2181 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2185 void cb_reslist_search_clicked(GtkWidget *widget, gpointer data)
2188 GtkTreeModel *model;
2193 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2195 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 5, &hash, -1);
2196 buf = sprintf2("H=%s", hash);
2197 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2200 cb_main_srchbtn_clicked(widget, NULL);
2203 void cb_reslist_list_cchange(GtkWidget *widget, gpointer data)
2206 GtkTreeModel *model;
2210 if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(reslist_list)), &model, &iter))
2212 gtk_widget_set_sensitive(reslist_delete, FALSE);
2213 gtk_widget_set_sensitive(reslist_search, FALSE);
2216 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 4, &locked, 5, &hash, -1);
2217 gtk_widget_set_sensitive(reslist_delete, !locked);
2218 gtk_widget_set_sensitive(reslist_search, hash && *hash);
2222 void cb_reslist_list_activate(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
2225 GtkTreeModel *model;
2228 model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
2229 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
2233 gtk_tree_model_get(model, &iter, 5, &hash, -1);
2234 buf = sprintf2("H=%s", hash);
2235 gtk_entry_set_text(GTK_ENTRY(main_realsrch), buf);
2238 cb_main_srchbtn_clicked(widget, NULL);
2241 gboolean cb_reslist_list_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
2243 GtkTreeSelection *sel;
2244 GtkTreeModel *model;
2249 if((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_Delete))
2251 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
2252 if(gtk_tree_selection_get_selected(sel, &model, &iter))
2254 gtk_tree_model_get(model, &iter, 0, &id, 4, &locked, -1);
2258 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2267 void srchstatupdate(void)
2273 snprintf(buf, 1024, _("Ready to search"));
2275 snprintf(buf, 1024, _("Search scheduled and will be submitted in %i seconds"), (int)(srcheta - time(NULL)));
2277 if(strcmp(gtk_label_get_text(GTK_LABEL(main_srchstatus)), buf))
2278 gtk_label_set_text(GTK_LABEL(main_srchstatus), buf);
2281 gint srchstatupdatecb(gpointer data)
2287 void initchattags(void)
2291 chattags = gtk_text_tag_table_new();
2292 tag = gtk_text_tag_new("sender");
2293 g_object_set(tag, "foreground", "blue", NULL);
2294 gtk_text_tag_table_add(chattags, tag);
2297 int main(int argc, char **argv)
2300 PangoFontDescription *monospacefont;
2301 GtkTreeModel *sortmodel;
2302 struct passwd *pwent;
2304 setlocale(LC_ALL, "");
2305 bindtextdomain(PACKAGE, LOCALEDIR);
2306 textdomain(PACKAGE);
2307 gtk_init(&argc, &argv);
2309 signal(SIGCHLD, SIG_IGN);
2310 pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.config.bz2");
2311 dcserver = sstrdup("localhost");
2312 if((pwent = getpwuid(getuid())) == NULL)
2314 fprintf(stderr, "could not get your passwd data");
2317 connectas = sstrdup(pwent->pw_name);
2318 wnd = create_main_wnd();
2319 create_reslist_wnd();
2320 gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400);
2323 fnmodel = gtk_list_store_new(6, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
2324 gtk_tree_view_set_model(GTK_TREE_VIEW(main_fnetnodes), GTK_TREE_MODEL(fnmodel));
2325 gtk_tree_view_set_model(GTK_TREE_VIEW(main_chatnodes), GTK_TREE_MODEL(fnmodel));
2327 reslist = gtk_list_store_new(6, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
2328 gtk_tree_view_set_model(GTK_TREE_VIEW(reslist_list), GTK_TREE_MODEL(reslist));
2330 pubhubmodel = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
2331 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(pubhubmodel));
2332 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 3, GTK_SORT_DESCENDING);
2333 gtk_tree_view_set_model(GTK_TREE_VIEW(main_phublist), GTK_TREE_MODEL(sortmodel));
2334 g_object_unref(sortmodel);
2336 dlmodel = gtk_list_store_new(13, G_TYPE_INT, /* id */
2337 G_TYPE_INT, /* dir */
2338 G_TYPE_INT, /* state */
2339 G_TYPE_STRING, /* peerid */
2340 G_TYPE_STRING, /* peernick */
2341 G_TYPE_STRING, /* path */
2342 G_TYPE_INT, /* size */
2343 G_TYPE_INT, /* curpos */
2344 G_TYPE_STRING, /* stock */
2345 G_TYPE_FLOAT, /* percentage */
2346 G_TYPE_INT, /* error */
2347 G_TYPE_INT, /* errortime */
2348 G_TYPE_STRING); /* hash */
2349 gtk_tree_view_set_model(GTK_TREE_VIEW(main_downloads), GTK_TREE_MODEL(dlmodel));
2351 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);
2352 gtk_tree_view_set_model(GTK_TREE_VIEW(main_uploads), GTK_TREE_MODEL(ulmodel));
2354 srchmodel = gtk_tree_store_new(10, G_TYPE_STRING, /* fnetname */
2355 G_TYPE_STRING, /* peerid */
2356 G_TYPE_STRING, /* peername */
2357 G_TYPE_STRING, /* filename */
2358 G_TYPE_INT, /* size */
2359 G_TYPE_INT, /* slots */
2360 G_TYPE_DOUBLE, /* resptime */
2361 G_TYPE_INT, /* sizenum */
2362 G_TYPE_INT, /* speed */
2363 G_TYPE_STRING); /* hash */
2364 srchmodelfilter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(srchmodel), NULL));
2365 gtk_tree_model_filter_set_visible_func(srchmodelfilter, srchfilterfunc, NULL, NULL);
2366 sortmodel = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(srchmodelfilter));
2367 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortmodel), 4, GTK_SORT_DESCENDING);
2368 gtk_tree_view_set_model(GTK_TREE_VIEW(main_srchres), GTK_TREE_MODEL(sortmodel));
2369 g_object_unref(sortmodel);
2371 monospacefont = pango_font_description_from_string("Monospace 10");
2372 gtk_widget_modify_font(main_chatview, monospacefont);
2373 pango_font_description_free(monospacefont);
2375 updatesbar(_("Disconnected"));
2376 gtk_widget_show(wnd);
2378 dcconnect(dcserver);
2379 g_timeout_add(500, srchstatupdatecb, NULL);
2380 g_timeout_add(5000, ksupdatecb, NULL);
2381 g_timeout_add(1000, updatetransfers, NULL);