X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=clients%2Fgtk2%2Fdolcon.c;h=c96498fd3cf5af836b419ab265dc7744d2105e87;hb=dbdb91fa4abf642a9699b1381abf8bcbb05b202c;hp=02a24230f4cc741beb53168b7354ba3e1ab05e5f;hpb=d05758f6eda21695e6215d60d28b9747d0b8aaa3;p=doldaconnect.git diff --git a/clients/gtk2/dolcon.c b/clients/gtk2/dolcon.c index 02a2423..c96498f 100644 --- a/clients/gtk2/dolcon.c +++ b/clients/gtk2/dolcon.c @@ -1,6 +1,6 @@ /* * Dolda Connect - Modular multiuser Direct Connect-style client - * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) + * Copyright (C) 2004 Fredrik Tolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,7 +47,6 @@ #endif #include "dolcon.h" #include "hublist.h" -#include "progressbar.h" #define TRHISTSIZE 10 @@ -279,26 +278,40 @@ char *bytes2si(long long bytes) { int i; double b; - char *sd; static char ret[64]; + static char pfx[] = {'k', 'M', 'G', 'T'}; b = bytes; - for(i = 0; (b >= 1024) && (i < 4); i++) + for(i = 0; (b >= 1024) && (i < sizeof(pfx)); i++) b /= 1024; if(i == 0) - sd = "B"; - else if(i == 1) - sd = "kiB"; - else if(i == 2) - sd = "MiB"; - else if(i == 3) - sd = "GiB"; + snprintf(ret, 64, "%.1f B", b); else - sd = "TiB"; - snprintf(ret, 64, "%.1f %s", b, sd); + snprintf(ret, 64, "%.1f %ciB", b, pfx[i - 1]); return(ret); } +void progressfunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) +{ + int totalc, curc; + int total, cur; + char buf[64]; + + totalc = (GPOINTER_TO_INT(data) & 0xff00) >> 8; + curc = GPOINTER_TO_INT(data) & 0xff; + gtk_tree_model_get(model, iter, totalc, &total, curc, &cur, -1); + if(total < 1) + g_object_set(rend, "value", GINT_TO_POINTER(0), NULL); + else + g_object_set(rend, "value", GINT_TO_POINTER((int)(((double)cur / (double)total) * 100)), NULL); + if(cur < 0) { + g_object_set(rend, "text", "", NULL); + } else { + snprintf(buf, 64, "%'i", cur); + g_object_set(rend, "text", buf, NULL); + } +} + void percentagefunc(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) { int colnum; @@ -1445,6 +1458,11 @@ void cb_main_pubhubfilter_activate(GtkWidget *widget, gpointer data) fetchhublist(pubhubaddr, filter); } +void cb_main_pubhubabort_clicked(GtkWidget *widget, gpointer data) +{ + aborthublist(); +} + void cb_main_dcnctbtn_clicked(GtkWidget *widget, gpointer data) { GtkTreeIter iter; @@ -2195,8 +2213,11 @@ void initchattags(void) gtk_text_tag_table_add(chattags, tag); } +#include "../dolda-icon.xpm" + int main(int argc, char **argv) { + int c, connlocal; GtkWidget *wnd; PangoFontDescription *monospacefont; GtkTreeModel *sortmodel; @@ -2206,6 +2227,26 @@ int main(int argc, char **argv) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); gtk_init(&argc, &argv); + connlocal = 0; + while((c = getopt(argc, argv, "lhV")) != -1) { + switch(c) { + case 'l': + connlocal = 1; + break; + case 'h': + printf("usage: dolcon [-hlV]\n"); + printf("\t-h\tDisplay this help message\n"); + printf("\t-l\tConnect to the locally running daemon\n"); + printf("\t-V\tDisplay version info and exit\n"); + exit(0); + case 'V': + printf("%s", RELEASEINFO); + exit(0); + default: + fprintf(stderr, "usage: dolcon [-hlV]\n"); + exit(1); + } + } dc_init(); signal(SIGCHLD, SIG_IGN); pubhubaddr = sstrdup("http://www.hublist.org/PublicHubList.xml.bz2"); @@ -2216,6 +2257,7 @@ int main(int argc, char **argv) exit(1); } connectas = sstrdup(pwent->pw_name); + gtk_window_set_default_icon(gdk_pixbuf_new_from_xpm_data((const char **)dolda_icon_xpm)); wnd = create_main_wnd(); create_reslist_wnd(); gtk_window_resize(GTK_WINDOW(reslist_wnd), 600, 400); @@ -2269,7 +2311,9 @@ int main(int argc, char **argv) readconfigfile(); updatesbar(_("Disconnected")); gtk_widget_show(wnd); - if(autoconn) + if(connlocal) + dcconnect(dc_srv_local); + else if(autoconn) dcconnect(dcserver); g_timeout_add(500, srchstatupdatecb, NULL); g_timeout_add(5000, ksupdatecb, NULL);