~ubuntu-branches/ubuntu/quantal/cairo-dock-plug-ins/quantal-201208191523

« back to all changes in this revision

Viewing changes to Doncky/src/applet-draw.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "applet-disk-usage.h"
30
30
#include "applet-rame.h"
31
31
 
32
 
gchar* ltrim( gchar* str, const gchar* t )  // Couper tout depuis la gauche
33
 
{
34
 
        char* curStr = NULL;
35
 
 
36
 
        char look[ 256 ] = { 1, 0 };
37
 
        while( *t )
38
 
                look[ (unsigned char)*t++ ] = 1;
39
 
 
40
 
        curStr = str;
41
 
        while( *curStr && look[ *curStr ] )
42
 
                ++curStr;
43
 
        strcpy( str, curStr );
44
 
        
45
 
        return str; 
46
 
47
32
 
48
33
gchar* rtrim( gchar* str, const gchar* t )  // Couper tout depuis la droite
49
34
{
50
 
        char* curEnd = str, *end = str;
51
 
 
52
 
        char look[ 256 ] = { 1, 0 };
 
35
        gchar* curEnd = str, *end = str;
 
36
        gchar look[ 256 ] = { 1, 0 };
53
37
        while( *t )
54
38
                look[ (unsigned char)*t++ ] = 1;
55
 
 
56
39
        while( *end )
57
40
        {
58
41
                if ( !look[ *end ] )
62
45
        *curEnd = '\0';
63
46
 
64
47
        return str;
 
48
        g_free (curEnd);
 
49
        g_free (end);
 
50
        g_free (look);
65
51
}
66
52
 
 
53
gchar* ltrim( gchar* str, const gchar* t )  // Couper tout depuis la gauche
 
54
{
 
55
        g_strreverse (str);
 
56
        gchar* cSearch = g_strdup_printf("%s", t);
 
57
        g_strreverse (cSearch);
 
58
        rtrim( str, cSearch);
 
59
        g_strreverse (str);     
 
60
        g_free (cSearch);
 
61
        
 
62
        return str; 
 
63
 
64
 
67
65
 
68
66
gchar *g_str_replace (const gchar *cString, const gchar *cWord, const gchar *cReplace)
69
67
{
 
68
        gchar *cPart1;
 
69
        gchar *cPart2;
 
70
        gchar *cWordTemp;
70
71
        if (g_strstr_len (cString, -1, cWord) != NULL) // On remplace
71
72
        {
72
73
                gchar *cFinalString = g_strdup_printf("%s", cString);
73
74
                while (g_strstr_len (cFinalString, -1, cWord) != NULL)
74
75
                {
75
 
                        gchar *cPart1 = g_strdup_printf("%s", cFinalString);
76
 
                        gchar *cWordTemp = g_strdup_printf("%s", cWord);
 
76
                        cPart1 = g_strdup_printf("%s", cFinalString);
 
77
                        cWordTemp = g_strdup_printf("%s", cWord);
77
78
                        g_strreverse (cPart1);
78
79
                        g_strreverse (cWordTemp);
79
80
                        cPart1 = strstr(cPart1, cWordTemp) ;
80
81
                        ltrim( cPart1, cWordTemp );
81
82
                        g_strreverse (cPart1);
82
 
                        gchar *cPart2 = g_strdup_printf("%s", cFinalString);
 
83
                        cPart2 = g_strdup_printf("%s", cFinalString);
83
84
                        
84
85
                        while (g_strstr_len (cPart2, -1, cWord) != NULL)
85
86
                        {
86
 
                                cPart2 = strstr(cPart2, cWord);
 
87
                                cPart2 = strstr(cPart2, cWord);                         
87
88
                                ltrim( cPart2, cWord );
88
89
                        }
89
90
                        // On colle le texte au milieu
90
91
                        cFinalString = g_strdup_printf ("%s%s%s", cPart1,  g_strdup_printf("%s",cReplace), cPart2);
91
92
                        
92
93
                }
93
 
                return g_strdup_printf("%s", cFinalString);     
94
 
        }
95
 
        else
96
 
                return g_strdup_printf("%s",cString); // On retourne la phrase d'origine        
 
94
                return g_strdup_printf("%s", cFinalString);
 
95
                g_free (cFinalString);
 
96
        }
 
97
        else
 
98
                return g_strdup_printf("%s",cString); // Remplacement non trouvé -> On retourne la phrase d'origine
 
99
        g_free (cPart1);
 
100
        g_free (cPart2);
 
101
        g_free (cWordTemp);
 
102
}
 
103
 
 
104
 
 
105
gchar *g_str_position (const gchar *cString, const int iPosition, const char cSeparator)
 
106
{
 
107
        gchar *strSeparator = g_strdup_printf("%c", cSeparator);
 
108
        
 
109
        if ((g_strstr_len (cString, -1, strSeparator) != NULL) && (iPosition > 0)) // Separator trouvé -> On coupe
 
110
        {
 
111
                gchar *cFinalString = g_strdup_printf("%s", cString);
 
112
                
 
113
                if (iPosition == 1)
 
114
                {                       
 
115
                        g_strreverse (cFinalString);
 
116
                        cFinalString = strrchr(cFinalString, cSeparator);
 
117
                        ltrim( cFinalString, strSeparator);
 
118
                        g_strreverse (cFinalString);
 
119
                }
 
120
                else
 
121
                {
 
122
                        int i = 1;
 
123
                        do
 
124
                        {
 
125
                                if (g_strstr_len (cFinalString, -1, strSeparator) == NULL) // Il n'y a plus de séparateur -> Mauvais champ spécifié
 
126
                                {
 
127
                                        cd_debug ("DONCKY-debug :  /!\\ Missing values detected. Search for the string '%s' to fix it.", cString);
 
128
                                        // On retourne 0 pour le champ non trouvé :
 
129
                                        cFinalString = g_strdup_printf("0");
 
130
                                        i = iPosition;
 
131
                                }
 
132
                                else
 
133
                                {
 
134
                                        cFinalString = strchr(cFinalString, cSeparator);
 
135
                                        ltrim( cFinalString, strSeparator);
 
136
                                        i++;
 
137
                                }
 
138
                        }
 
139
                        while (i != iPosition);
 
140
                        
 
141
                        if ((g_strstr_len (cFinalString, -1, strSeparator) != NULL) && (iPosition > 0)) // Il reste des séparateurs -> On coupe les derniers champs
 
142
                        {
 
143
                                g_strreverse (cFinalString);
 
144
                                cFinalString = strrchr(cFinalString, cSeparator);
 
145
                                ltrim( cFinalString, strSeparator);
 
146
                                g_strreverse (cFinalString);
 
147
                        }
 
148
                }
 
149
                return g_strdup_printf("%s", cFinalString);
 
150
                g_free (cFinalString);
 
151
                g_free (strSeparator);
 
152
        
 
153
        }
 
154
        else
 
155
                return g_strdup_printf("%s",cString); // Pas de séparateur -> On retourne la phrase d'origine
97
156
}
98
157
 
99
158
 
122
181
                cd_sysmonitor_get_ram_data (myApplet);
123
182
        if (myConfig.bShowNvidia)
124
183
        {
125
 
                if ((myData.iTimerCount % 3) == 0)  // la temperature ne varie pas tres vite et le script nvidia-settings est lours, on decide donc de ne mettre a jour qu'une fois sur 3.
 
184
                if ((myData.iTimerCount % 3) == 0)  // la temperature ne varie pas tres vite et le script nvidia-settings est lourd, on decide donc de ne mettre a jour qu'une fois sur 3.
126
185
                        cd_sysmonitor_get_nvidia_data (myApplet);
127
186
        }       
128
187
        if (! myData.bInitialized)
142
201
        {
143
202
                pTextZone = it->data;
144
203
                
145
 
                
146
 
                
147
204
                if (!pTextZone->bImgDraw && pTextZone->cImgPath != NULL) // L'image n'a pas encore été chargée
148
205
                {
149
206
                        
175
232
                }
176
233
                
177
234
                
178
 
                
179
 
                
180
 
                                
181
235
                if (pTextZone->iRefresh != 0)
182
236
                                pTextZone->iTimer++;
183
237
                
184
 
                
185
238
                if (pTextZone->bRefresh)
186
239
                {
187
240
                        if (pTextZone->bIsBash) // C'est une commande bash !
232
285
                                        else
233
286
                                                pTextZone->cResult = g_strdup_printf ("%.0f", myData.fRamPercent);
234
287
                                }
235
 
        
236
288
                                                                                
237
289
                                else if (strcmp (pTextZone->cCommand, "mem") == 0) // en Mo
238
290
                                {
257
309
                                        pTextZone->cResult = g_strdup_printf ("%f", _Ko_to_Go(myApplet, myData.ramTotal));
258
310
                                        pTextZone->cResult = g_strdup_printf ("%.2f", atof(pTextZone->cResult));
259
311
                                }
260
 
                                
261
312
                                                                
262
313
                                else if (strcmp (pTextZone->cCommand, "swapperc") == 0)
263
314
                                {
311
362
                                        pTextZone->cResult = g_strdup_printf ("%.2f", atof(pTextZone->cResult));
312
363
                                }
313
364
                                
314
 
                                
315
 
                                
316
365
                                else if (strcmp (pTextZone->cCommand, "nvtemp") == 0)
317
366
                                {
318
367
                                        myConfig.bShowNvidia = TRUE;
340
389
                                        pTextZone->cResult = g_strdup_printf ("%i", myData.iVideoRam);                                  
341
390
                                }
342
391
                                
343
 
                                
344
 
                                
345
 
                                
346
392
                                else if (strcmp (pTextZone->cCommand, "uptime") == 0)
347
393
                                {
348
394
                                        gchar *cUpTime = NULL, *cActivityTime = NULL;
376
422
                                        pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 5));
377
423
                                
378
424
                                else if (strcmp (pTextZone->cCommand, "fs_device") == 0)
379
 
                                        pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 6));                               
380
 
                                
381
 
                        }                       
 
425
                                        pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 6));
 
426
                        }
 
427
        
382
428
                }
383
429
        }       
384
430
}
385
431
 
386
432
gboolean cd_retrieve_command_result (CairoDockModuleInstance *myApplet)
387
433
{
388
 
        
389
 
        // SYSTEM-MONITOR
390
 
        static double s_fValues[CD_SYSMONITOR_NB_MAX_VALUES];
391
 
        CD_APPLET_ENTER;
392
 
        
393
 
        if ( ! myData.bAcquisitionOK)
394
 
        {
395
 
                cd_warning ("One or more datas couldn't be retrieved"); 
396
 
                memset (s_fValues, 0, sizeof (s_fValues));
397
 
                CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
398
 
        }
399
 
        else
400
 
        {
401
 
                if (! myData.bInitialized)
402
 
                {
403
 
                        memset (s_fValues, 0, sizeof (s_fValues));
404
 
                        CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
405
 
                }
406
 
                else
407
 
                {
408
 
                        // Copier les donnes en memoire partagee...
409
 
                        
410
 
                        //~ if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON || (myDock && myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL))  // on affiche les valeurs soit en info-rapide, soit sur l'etiquette en mode dock.
411
 
                        //~ {
412
 
                                //~ gboolean bOneLine = (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL);
413
 
                                //~ GString *sInfo = g_string_new ("");
414
 
                                //~ if (myConfig.bShowCpu)
415
 
                                //~ {
416
 
                                        //~ g_string_printf (sInfo, (myData.fCpuPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
417
 
                                                //~ (myDesklet ? "CPU:" : ""),
418
 
                                                //~ myData.fCpuPercent,
419
 
                                                //~ (bOneLine ? " - " : "\n"));
420
 
                                //~ }
421
 
                                //~ if (myConfig.bShowRam)
422
 
                                //~ {
423
 
                                        //~ g_string_append_printf (sInfo, (myData.fRamPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
424
 
                                                //~ (myDesklet ? "RAM:" : ""),
425
 
                                                //~ myData.fRamPercent,
426
 
                                                //~ (bOneLine ? " - " : "\n"));
427
 
                                //~ }
428
 
                                //~ if (myConfig.bShowSwap)
429
 
                                //~ {
430
 
                                        //~ g_string_append_printf (sInfo, (myData.fSwapPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
431
 
                                                //~ (myDesklet ? "SWAP:" : ""),
432
 
                                                //~ myData.fSwapPercent,
433
 
                                                //~ (bOneLine ? " - " : "\n"));
434
 
                                //~ }
435
 
                                //~ if (myConfig.bShowNvidia)
436
 
                                //~ {
437
 
                                        //~ g_string_append_printf (sInfo, "%s%d°C%s",
438
 
                                                //~ (myDesklet ? "GPU:" : ""),
439
 
                                                //~ myData.iGPUTemp,
440
 
                                                //~ (bOneLine ? " - " : "\n"));
441
 
                                //~ }
442
 
                                //~ sInfo->str[sInfo->len-(bOneLine?3:1)] = '\0';
443
 
                                //~ if (bOneLine)
444
 
                                        //~ CD_APPLET_SET_NAME_FOR_MY_ICON (sInfo->str);
445
 
                                //~ else
446
 
                                        //~ CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (sInfo->str);
447
 
                                //~ g_string_free (sInfo, TRUE);
448
 
                        //~ }
449
 
                        
450
 
                        if (myData.bNeedsUpdate || myConfig.iDisplayType == CD_SYSMONITOR_GRAPH)
451
 
                        {
452
 
                                int i = 0;
453
 
                                if (myConfig.bShowCpu)
454
 
                                {
455
 
                                        s_fValues[i++] = myData.fCpuPercent / 100.;
456
 
                                }
457
 
                                if (myConfig.bShowRam)
458
 
                                {
459
 
                                        s_fValues[i++] = myData.fRamPercent / 100.;
460
 
                                }
461
 
                                if (myConfig.bShowSwap)
462
 
                                        s_fValues[i++] = (myData.swapTotal ? ((double)myData.swapUsed) / myData.swapTotal : 0.);
463
 
                                if (myConfig.bShowNvidia)
464
 
                                        s_fValues[i++] = myData.fGpuTempPercent / 100.;
465
 
                                
466
 
                                CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
467
 
                        }
468
 
                }
469
 
        }
470
 
        
471
 
        
472
 
        
473
 
        // Autre :
474
 
        
475
434
        GList *it;
476
435
        TextZone *pTextZone;
477
436
        
478
 
 
479
437
        for (it = myData.pTextZoneList; it != NULL; it = it->next)
480
438
        {
481
439
                pTextZone = it->data;
482
 
                        
 
440
                
483
441
                if (pTextZone->iRefresh != 0 || pTextZone->bRefresh)
484
442
                {
485
443
                        if (pTextZone->bRefresh && pTextZone->cResult != NULL)
486
444
                        {
487
445
                                pTextZone->cText = g_strdup_printf ("%s",pTextZone->cResult);
488
446
                        }
489
 
                                                    
 
447
                        
490
448
                        if (pTextZone->iRefresh != 0 && pTextZone->iTimer >= pTextZone->iRefresh)
491
449
                        {
492
450
                                pTextZone->bRefresh = TRUE;
494
452
                        }
495
453
                        else // Pas de refresh de spécifié
496
454
                        {
497
 
                                
498
 
                                if (pTextZone->cText == NULL || strcmp (pTextZone->cText, "") == 0) // La récupération s'est mal passé -> On relance !
 
455
                                if (pTextZone->cText == NULL || strcmp (pTextZone->cText, "Please wait...") == 0) // La récupération s'est mal passé -> On relance !
 
456
                                {
499
457
                                        pTextZone->bRefresh = TRUE;
 
458
                                        pTextZone->iTimer = 0; // On remet le timer à 0
 
459
                                        
 
460
                                        cd_debug ("DONCKY-debug : Commande non passée =  %s", pTextZone->cCommand);     
 
461
                                }       
500
462
                                else                    
501
463
                                        pTextZone->bRefresh = FALSE; // On a récupéré l'info -> On arrête là !
502
464
                        }
503
 
                }       
 
465
                }
504
466
        }
505
467
        cd_applet_update_my_icon (myApplet); // Quand tous les textes sont chargés, on peut dessiner
506
 
        myData.pPeriodicRefreshTask = NULL;
507
 
                
508
 
        CD_APPLET_LEAVE (myData.bAcquisitionOK);
509
468
}
510
469
 
511
470
 
 
471
 
512
472
void cd_applet_draw_my_desklet (CairoDockModuleInstance *myApplet, int iWidth, int iHeight)
513
473
{
514
474
        PangoLayout *pLayout = pango_cairo_create_layout (myDrawContext);
562
522
                cairo_restore (myDrawContext);
563
523
        }
564
524
        
565
 
        
566
 
        
567
525
        // ################################################################################################################################################################
568
526
        // ############ DEBUT DU DESSIN DU TEXTE
569
527
        // ################################################################################################################################################################
637
595
                        it = it->next;
638
596
                } while (it != NULL && ! pTextZone->bEndOfLine);
639
597
                
640
 
                
641
 
                
 
598
 
642
599
                
643
600
                //\_______ boucle sur it de it1 jusqu'à retour chariot => DESSIN
644
601
                it = it1;
645
602
                do
646
603
                {
647
 
        
648
604
                        pTextZone = it->data;
649
 
                        
650
 
                        
651
 
                        
652
 
                        
653
 
                        
654
 
                        
655
 
                
656
 
                        
657
 
                        
658
 
                        
659
 
                        
660
 
                        
661
 
                        
662
 
                        
663
 
                        
664
 
                        
665
 
                        
666
 
                        
667
 
                        
668
 
                        
669
 
                        
670
 
                        
671
 
                        
672
 
                        
673
 
                        
674
 
                        
675
 
                        
676
 
                        
677
 
                        
678
 
                        
679
 
                        
680
 
                        
681
 
                        
682
 
                        
683
605
                                                
684
606
                        if (pTextZone->cFont == NULL || pTextZone->cFont =="") // Si aucune font -> on prend celle de la config
685
607
                                pTextZone->cFont = g_strdup_printf("%s", myConfig.cDefaultFont);
686
608
                        
687
 
                        
688
609
                         // On calcule le décalage WIDTH nécéssaire pour respecter l'alignement sur la largeur souhaité
689
610
                        if (bFirstTextInLine)
690
611
                        {
706
627
                                                myData.fCurrentX = iWidth - iMargin - myConfig.iTextMargin - pTextZone->iWidth - pTextZone->iFontSizeWidth;
707
628
                                        else
708
629
                                                myData.fCurrentX = iWidth - iMargin - myConfig.iTextMargin - fCurrentLineWidth - pTextZone->iFontSizeWidth;
709
 
                                        
710
630
                                }
711
631
                                
712
632
                                if (pTextZone->bBar)
937
857
 
938
858
void cd_applet_update_my_icon (CairoDockModuleInstance *myApplet)
939
859
{
940
 
        //~ if (myDesklet)
941
 
        //~ {
942
 
                // taille de la texture.
943
 
                int iWidth, iHeight;
944
 
                CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
945
 
                
946
 
                cd_applet_draw_my_desklet (myApplet, iWidth, iHeight);          
947
 
                
948
 
                CD_APPLET_REDRAW_MY_ICON;
949
 
        //~ }
 
860
        // taille de la texture.
 
861
        int iWidth, iHeight;
 
862
        CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);       
 
863
        cd_applet_draw_my_desklet (myApplet, iWidth, iHeight);
 
864
        
 
865
        CD_APPLET_REDRAW_MY_ICON;
950
866
}