/*
* Dolda Connect - Modular multiuser Direct Connect-style client
- * Copyright (C) 2005 Fredrik Tolf (fredrik@dolda2000.com)
+ * Copyright (C) 2005 Fredrik Tolf <fredrik@dolda2000.com>
*
* 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
static char *ctxtmenu =
"<popup name='button3'>"
-" <menuitem name='Preferences' verb='dca_pref' _label='Preferences' pixtype='stock' pixname='gtk-properties'>"
-" </menuitem>"
+" <menuitem name='Preferences' verb='dca_pref' _label='Preferences' pixtype='stock' pixname='gtk-properties' />"
+" <menuitem name='Cancel transfer' verb='dca_cancel' _label='Cancel transfer' pixtype='stock' pixname='gtk-cancel' />"
"</popup>";
static void run_pref_dialog(BonoboUIComponent *uic, gpointer data, const char *cname)
{
}
+static void cancel_transfer(BonoboUIComponent *uic, struct appletdata *data, const char *cname)
+{
+ if(data->conduit->iface->cancel != NULL)
+ data->conduit->iface->cancel(data->conduit, data->curdisplay);
+}
+
static BonoboUIVerb ctxtmenuverbs[] =
{
BONOBO_UI_VERB("dca_pref", run_pref_dialog),
+ BONOBO_UI_VERB("dca_cancel", (void (*)(BonoboUIComponent*, gpointer, const char *))cancel_transfer),
BONOBO_UI_VERB_END
};
time_t now;
char buf[256];
- if(data->curdisplay == NULL)
+ if(data->curdisplay == NULL) {
+ gtk_tooltips_set_tip(data->tips, GTK_WIDGET(data->applet), _("No transfer selected"), NULL);
return(TRUE);
+ }
now = time(NULL);
- if(data->curdisplay->cmptime == 0)
+ if((data->curdisplay->cmptime == 0) || (now == data->curdisplay->cmptime))
{
strcpy(buf, _("Calculating remaining time..."));
} else {
strcpy(buf, _("Time left: Infinite (Transfer is standing still)"));
} else {
left = (data->curdisplay->size - data->curdisplay->pos) / speed;
- sprintf(buf, _("Time left: %i:%02i"), left / 3600, (left / 60) % 60);
+ if(left >= 86400)
+ sprintf(buf, _("Time left: %id%02ih%02im"), left / 86400, (left / 3600) % 24, (left / 60) % 60);
+ else if(left >= 3600)
+ sprintf(buf, _("Time left: %ih%02im"), left / 3600, (left / 60) % 60);
+ else
+ sprintf(buf, _("Time left: %im"), left / 60);
}
}
gtk_tooltips_set_tip(data->tips, GTK_WIDGET(data->applet), buf, NULL);
static void update(struct appletdata *data)
{
char buf[256];
+ size_t l;
switch(data->conduit->state)
{
} else {
if((data->curdisplay->pos > 0) && (data->curdisplay->size > 0))
{
- sprintf(buf, "%'i/%'i", data->curdisplay->pos, data->curdisplay->size);
+ sprintf(buf, "%'ji/%'ji", (intmax_t)data->curdisplay->pos, (intmax_t)data->curdisplay->size);
gtk_progress_bar_set_fraction(data->pbar, (double)data->curdisplay->pos / (double)data->curdisplay->size);
gtk_progress_bar_set_text(data->pbar, buf);
} else {
gtk_progress_bar_set_fraction(data->pbar, 0);
gtk_progress_bar_set_text(data->pbar, _("Initializing"));
}
- gtk_label_set_text(data->label, data->curdisplay->tag);
+ if((l = strlen(data->curdisplay->tag)) > 50) {
+ memcpy(buf, data->curdisplay->tag, 20);
+ memcpy(buf + 20, "...", 3);
+ memcpy(buf + 23 , data->curdisplay->tag + l - 20, 20);
+ buf[43] = 0;
+ gtk_label_set_text(data->label, buf);
+ } else {
+ gtk_label_set_text(data->label, data->curdisplay->tag);
+ }
}
break;
}
return(FALSE);
}
+static gboolean trview_applet_scroll(GtkWidget *widget, GdkEventScroll *event, struct appletdata *data)
+{
+ struct transfer *tr;
+
+ if(event->direction == GDK_SCROLL_DOWN)
+ {
+ if(data->curdisplay == NULL)
+ data->curdisplay = data->conduit->transfers;
+ else if(data->curdisplay->next == NULL)
+ data->curdisplay = data->conduit->transfers;
+ else
+ data->curdisplay = data->curdisplay->next;
+ update(data);
+ } else if(event->direction == GDK_SCROLL_UP) {
+ if(data->curdisplay == NULL)
+ {
+ data->curdisplay = data->conduit->transfers;
+ } else if(data->curdisplay->prev == NULL) {
+ for(tr = data->conduit->transfers; tr->next != NULL; tr = tr->next);
+ data->curdisplay = tr;
+ } else {
+ data->curdisplay = data->curdisplay->prev;
+ }
+ update(data);
+ }
+ return(TRUE);
+}
+
static void trview_applet_destroy(GtkWidget *widget, struct appletdata *data)
{
freeconduit(data->conduit);
if(strcmp(iid, "OAFIID:Dolcon_Transferapplet"))
return(FALSE);
- panel_applet_setup_menu(applet, ctxtmenu, ctxtmenuverbs, NULL);
-
hbox = gtk_hbox_new(FALSE, 0);
label = gtk_label_new("");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
data->tiptimeout = g_timeout_add(500, (gboolean (*)(gpointer))updatetip, data);
data->label = GTK_LABEL(label);
+ panel_applet_setup_menu(applet, ctxtmenu, ctxtmenuverbs, data);
+
g_signal_connect(applet, "button-press-event", (GCallback)trview_applet_button_press, data);
+ g_signal_connect(applet, "scroll-event", (GCallback)trview_applet_scroll, data);
g_signal_connect(applet, "destroy", (GCallback)trview_applet_destroy, data);
condtryconn(data->conduit);