Improved the tooltip on the Gnome applet.
[doldaconnect.git] / clients / gnome-trans-applet / dolcon-trans-applet.c
index b73b46e..5520776 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  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
@@ -59,7 +59,7 @@ static void cancel_transfer(BonoboUIComponent *uic, struct appletdata *data, con
 static BonoboUIVerb ctxtmenuverbs[] =
 {
     BONOBO_UI_VERB("dca_pref", run_pref_dialog),
-    BONOBO_UI_VERB("dca_cancel", cancel_transfer),
+    BONOBO_UI_VERB("dca_cancel", (void (*)(BonoboUIComponent*, gpointer, const char *))cancel_transfer),
     BONOBO_UI_VERB_END
 };
 
@@ -75,8 +75,10 @@ static gboolean updatetip(struct appletdata *data)
     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)
     {
@@ -89,7 +91,12 @@ static gboolean updatetip(struct appletdata *data)
            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);
@@ -99,6 +106,7 @@ static gboolean updatetip(struct appletdata *data)
 static void update(struct appletdata *data)
 {
     char buf[256];
+    size_t l;
     
     switch(data->conduit->state)
     {
@@ -123,14 +131,22 @@ static void update(struct appletdata *data)
        } 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;
     }