~cairo-dock-team/ubuntu/oneiric/cairo-dock-plug-ins/2.3.0-3

« back to all changes in this revision

Viewing changes to netspeed/src/applet-netspeed.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-09-07 02:38:17 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100907023817-ish9a53i2wn0m7zg
Tags: 2.2.0~0rc1-0ubuntu1
* New Upstream Version (LP: #632054)
* Fixed a few bugs on LP:
 - LP: #616176 Dust Bin Hang and Incorrect Configuration
 - LP: #604034 Change terminal tab's name lost the color
 - LP: #582452 GMenu does not contain any applications
* Fixed a few bugs on glx-dock forum:
 - Fixed support of GMusicBrowser.
 - AlsaMixer has no emblem.
 - Status-Notifier doesn't be drawed into the dock.
* Updated translations
* debian/control:
 - Added cairo-dock-core as build-depends in order to prevent
   some builds errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
 
35
35
// Prend un debit en octet par seconde et le transforme en une chaine de la forme : xxx yB/s
36
 
static void cd_netspeed_formatRate (CairoDockModuleInstance *myApplet, unsigned long long rate, gchar* debit) {
 
36
static void cd_netspeed_formatRate (unsigned long long rate, gchar* debit, int iBufferSize, gboolean bLong)
 
37
{
37
38
        int smallRate;
38
 
        
39
39
        if (rate <= 0)
40
40
        {
41
 
                if (myDesklet)
42
 
                        g_sprintf(debit, "0 %s/s", D_("B"));
 
41
                if (bLong)
 
42
                        snprintf (debit, iBufferSize, "0 %s/s", D_("B"));
43
43
                else
44
 
                        g_sprintf(debit, "0");
 
44
                        snprintf (debit, iBufferSize, "0");
45
45
        }
46
46
        else if (rate < 1024)
47
47
        {
48
48
                smallRate = rate;
49
 
                if (myDesklet)
50
 
                        g_sprintf(debit, "%i %s/s", smallRate, D_("B"));
 
49
                if (bLong)
 
50
                        snprintf (debit, iBufferSize, "%i %s/s", smallRate, D_("B"));
51
51
                else
52
 
                        g_sprintf(debit, "%iB", smallRate);
 
52
                        snprintf (debit, iBufferSize, "%iB", smallRate);
53
53
        }
54
54
        else if (rate < (1<<20))
55
55
        {
56
56
                smallRate = rate >> 10;
57
 
                if (myDesklet)
58
 
                        g_sprintf(debit, "%i %s/s", smallRate, D_("KB"));
 
57
                if (bLong)
 
58
                        snprintf (debit, iBufferSize, "%i %s/s", smallRate, D_("KB"));
59
59
                else
60
 
                        g_sprintf(debit, "%iK", smallRate);
 
60
                        snprintf (debit, iBufferSize, "%iK", smallRate);
61
61
        }
62
62
        else if (rate < (1<<30))
63
63
        {
64
64
                smallRate = rate >> 20;
65
 
                if (myDesklet)
66
 
                        g_sprintf(debit, "%i %s/s", smallRate, D_("MB"));
 
65
                if (bLong)
 
66
                        snprintf (debit, iBufferSize, "%i %s/s", smallRate, D_("MB"));
67
67
                else
68
 
                        g_sprintf(debit, "%iM", smallRate);
 
68
                        snprintf (debit, iBufferSize, "%iM", smallRate);
69
69
        }
70
70
        else if (rate < ((unsigned long long)1<<40))
71
71
        {
72
72
                smallRate = rate >> 30;
73
 
                if (myDesklet)
74
 
                        g_sprintf(debit, "%i %s/s", smallRate, D_("GB"));
 
73
                if (bLong)
 
74
                        snprintf (debit, iBufferSize, "%i %s/s", smallRate, D_("GB"));
75
75
                else
76
 
                        g_sprintf(debit, "%iG", smallRate);
 
76
                        snprintf (debit, iBufferSize, "%iG", smallRate);
77
77
        }
78
78
        else  // c'est vraiment pour dire qu'on est exhaustif :-)
79
79
        {
80
80
                smallRate = rate >> 40;
81
 
                if (myDesklet)
82
 
                        g_sprintf(debit, "%i %s/s", smallRate, D_("TB"));
 
81
                if (bLong)
 
82
                        snprintf (debit, iBufferSize, "%i %s/s", smallRate, D_("TB"));
83
83
                else
84
 
                        g_sprintf(debit, "%iT", smallRate);
 
84
                        snprintf (debit, iBufferSize, "%iT", smallRate);
85
85
        }
86
86
}
87
87
 
88
88
 
 
89
void cd_netspeed_format_value (CairoDataRenderer *pRenderer, int iNumValue, gchar *cFormatBuffer, int iBufferLength, CairoDockModuleInstance *myApplet)
 
90
{
 
91
        static gchar s_upRateFormatted[11];
 
92
        double fValue = cairo_data_renderer_get_normalized_current_value_with_latency (pRenderer, iNumValue);
 
93
        
 
94
        fValue *= (iNumValue == 0 ? myData.iMaxUpRate : myData.iMaxDownRate);
 
95
        cd_netspeed_formatRate (fValue, s_upRateFormatted, 11, FALSE);
 
96
        snprintf (cFormatBuffer, iBufferLength,
 
97
                "%s%s",
 
98
                cairo_data_renderer_can_write_values (pRenderer) ? (iNumValue == 0 ?"↓" : "↑") : "",
 
99
                s_upRateFormatted);
 
100
}
 
101
 
89
102
void cd_netspeed_get_data (CairoDockModuleInstance *myApplet)
90
103
{
91
104
        g_timer_stop (myData.pClock);
188
201
                {
189
202
                        if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_NONE)
190
203
                        {
191
 
                                cd_netspeed_formatRate (myApplet, myData.iUploadSpeed, s_upRateFormatted);
192
 
                                cd_netspeed_formatRate (myApplet, myData.iDownloadSpeed, s_downRateFormatted);
 
204
                                cd_netspeed_formatRate (myData.iUploadSpeed, s_upRateFormatted, 11, myDesklet != NULL);
 
205
                                cd_netspeed_formatRate (myData.iDownloadSpeed, s_downRateFormatted, 11, myDesklet != NULL);
 
206
                                
193
207
                                if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON)
194
208
                                {
195
 
                                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("↓%s\n↑%s", s_downRateFormatted, s_upRateFormatted);
 
209
                                        CairoDataRenderer *pRenderer = cairo_dock_get_icon_data_renderer (myIcon);
 
210
                                        if (!pRenderer || ! cairo_data_renderer_can_write_values (pRenderer))
 
211
                                                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("↓%s\n↑%s", s_downRateFormatted, s_upRateFormatted);
196
212
                                }
197
213
                                else
198
214
                                {