~jezra/vattery/trunk

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: jezra
  • Date: 2010-09-29 22:01:36 UTC
  • Revision ID: jezra@fatlappy-20100929220136-vc7qostpjsa8pp0e
handle text mode config

Show diffs side-by-side

added added

removed removed

Lines of Context:
163
163
Configuration* configuration_construct (GType object_type, const char* config_file_path);
164
164
char* configuration_get_value (Configuration* self, const char* group, const char* key);
165
165
void configuration_set_key_value (Configuration* self, const char* group, const char* key, const char* val);
 
166
gboolean configuration_get_boolean_value (Configuration* self, const char* group, const char* key);
166
167
GQuark config_error_quark (void);
167
168
void configuration_save_config (Configuration* self, GError** error);
168
169
static void main_controller_status_icon_menu (main_controller* self, guint button, guint time);
256
257
        char* color_background;
257
258
        char* color_border;
258
259
        char* color_text;
259
 
        char* text_mode;
260
260
        char* warn_percent;
261
261
        char* warn_command;
262
262
        char* crit_percent;
336
336
                configuration_set_key_value (self->priv->config, "colors", "text", self->priv->color_text);
337
337
                color_changed = TRUE;
338
338
        }
339
 
        text_mode = configuration_get_value (self->priv->config, "mode", "text");
340
 
        if (text_mode != NULL) {
341
 
                self->priv->text_mode = (gboolean) text_mode;
 
339
        self->priv->text_mode = configuration_get_boolean_value (self->priv->config, "mode", "text");
 
340
        if (self->priv->text_mode) {
342
341
        } else {
343
342
                configuration_set_key_value (self->priv->config, "mode", "text", "false");
344
343
        }
390
389
                                _g_free0 (crit_percent);
391
390
                                _g_free0 (warn_command);
392
391
                                _g_free0 (warn_percent);
393
 
                                _g_free0 (text_mode);
394
392
                                _g_free0 (color_text);
395
393
                                _g_free0 (color_border);
396
394
                                _g_free0 (color_background);
420
418
                        _g_free0 (crit_percent);
421
419
                        _g_free0 (warn_command);
422
420
                        _g_free0 (warn_percent);
423
 
                        _g_free0 (text_mode);
424
421
                        _g_free0 (color_text);
425
422
                        _g_free0 (color_border);
426
423
                        _g_free0 (color_background);
445
442
                        _g_free0 (crit_percent);
446
443
                        _g_free0 (warn_command);
447
444
                        _g_free0 (warn_percent);
448
 
                        _g_free0 (text_mode);
449
445
                        _g_free0 (color_text);
450
446
                        _g_free0 (color_border);
451
447
                        _g_free0 (color_background);
476
472
                _g_free0 (crit_percent);
477
473
                _g_free0 (warn_command);
478
474
                _g_free0 (warn_percent);
479
 
                _g_free0 (text_mode);
480
475
                _g_free0 (color_text);
481
476
                _g_free0 (color_border);
482
477
                _g_free0 (color_background);
500
495
                        _g_free0 (crit_percent);
501
496
                        _g_free0 (warn_command);
502
497
                        _g_free0 (warn_percent);
503
 
                        _g_free0 (text_mode);
504
498
                        _g_free0 (color_text);
505
499
                        _g_free0 (color_border);
506
500
                        _g_free0 (color_background);
531
525
                _g_free0 (crit_percent);
532
526
                _g_free0 (warn_command);
533
527
                _g_free0 (warn_percent);
534
 
                _g_free0 (text_mode);
535
528
                _g_free0 (color_text);
536
529
                _g_free0 (color_border);
537
530
                _g_free0 (color_background);
555
548
                        _g_free0 (crit_percent);
556
549
                        _g_free0 (warn_command);
557
550
                        _g_free0 (warn_percent);
558
 
                        _g_free0 (text_mode);
559
551
                        _g_free0 (color_text);
560
552
                        _g_free0 (color_border);
561
553
                        _g_free0 (color_background);
586
578
                _g_free0 (crit_percent);
587
579
                _g_free0 (warn_command);
588
580
                _g_free0 (warn_percent);
589
 
                _g_free0 (text_mode);
590
581
                _g_free0 (color_text);
591
582
                _g_free0 (color_border);
592
583
                _g_free0 (color_background);
609
600
        _g_free0 (crit_percent);
610
601
        _g_free0 (warn_command);
611
602
        _g_free0 (warn_percent);
612
 
        _g_free0 (text_mode);
613
603
        _g_free0 (color_text);
614
604
        _g_free0 (color_border);
615
605
        _g_free0 (color_background);
814
804
        double brect_width = 0.0;
815
805
        gint border_width;
816
806
        char* _tmp4_;
817
 
        char* _tmp11_;
818
 
        guchar* _tmp13_;
 
807
        char* _tmp5_;
 
808
        char* _tmp12_;
 
809
        guchar* _tmp14_;
819
810
        gint _svg_data_size_;
820
811
        gint svg_data_length1;
821
 
        gint _tmp12_;
 
812
        gint _tmp13_;
822
813
        guchar* svg_data;
823
814
        g_return_if_fail (self != NULL);
824
815
        _inner_error_ = NULL;
849
840
                        frect_color = (_tmp3_ = g_strdup (self->priv->color_draining), _g_free0 (frect_color), _tmp3_);
850
841
                }
851
842
        }
852
 
        svg_str = (_tmp4_ = g_strdup ("<?xml version=\"1.0\" standalone=\"no\"?>\n" \
853
 
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/G" \
854
 
"raphics/SVG/1.1/DTD/svg11.dtd\">\n" \
855
 
"<svg width=\"100px\" height=\"100px\" version=\"1.1\" xmlns=\"http://w" \
856
 
"ww.w3.org/2000/svg\">\n"), _g_free0 (svg_str), _tmp4_);
 
843
        svg_str = (_tmp4_ = g_strdup ("<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C" \
 
844
"//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" \
 
845
"\">\n"), _g_free0 (svg_str), _tmp4_);
 
846
        svg_str = (_tmp5_ = g_strconcat (svg_str, "<svg width=\"100px\" height=\"100px\" viewbox=\"0 0 200 200\" preserve" \
 
847
"AspectRatio=\"meet\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/sv" \
 
848
"g\">\n", NULL), _g_free0 (svg_str), _tmp5_);
857
849
        if (self->priv->text_mode) {
 
850
                char* _tmp7_;
858
851
                char* _tmp6_;
859
 
                char* _tmp5_;
860
 
                svg_str = (_tmp6_ = g_strconcat (svg_str, _tmp5_ = g_strdup_printf (" <text x = \"0\" y = \"65\" fill = \"%s\" font-size = \"50\">%d%</text" \
861
 
">", frect_color, self->priv->bat_percent), NULL), _g_free0 (svg_str), _tmp6_);
862
 
                _g_free0 (_tmp5_);
 
852
                svg_str = (_tmp7_ = g_strconcat (svg_str, _tmp6_ = g_strdup_printf (" <text style=\"text-align:center;\" x=\"0\" y=\"65\" fill=\"%s\" font-" \
 
853
"size = \"40\">%d%</text>", frect_color, self->priv->bat_percent), NULL), _g_free0 (svg_str), _tmp7_);
 
854
                _g_free0 (_tmp6_);
863
855
        } else {
 
856
                char* _tmp9_;
864
857
                char* _tmp8_;
865
 
                char* _tmp7_;
 
858
                char* _tmp11_;
866
859
                char* _tmp10_;
867
 
                char* _tmp9_;
868
 
                svg_str = (_tmp8_ = g_strconcat (svg_str, _tmp7_ = g_strdup_printf ("<rect x=\"%.0f\" y=\"0\" width=\"%.0fpx\" height=\"100px\" fill=\"%s\"" \
869
 
" stroke=\"%s\" stroke-width=\"%i\"  />\n", brect_x, brect_width, self->priv->color_background, self->priv->color_border, border_width), NULL), _g_free0 (svg_str), _tmp8_);
870
 
                _g_free0 (_tmp7_);
 
860
                svg_str = (_tmp9_ = g_strconcat (svg_str, _tmp8_ = g_strdup_printf ("<rect x=\"%.0f\" y=\"0\" width=\"%.0fpx\" height=\"100px\" fill=\"%s\"" \
 
861
" stroke=\"%s\" stroke-width=\"%i\"  />\n", brect_x, brect_width, self->priv->color_background, self->priv->color_border, border_width), NULL), _g_free0 (svg_str), _tmp9_);
 
862
                _g_free0 (_tmp8_);
871
863
                frect_height = (double) (self->priv->bat_percent - (border_width * 2));
872
864
                frect_y = 100 - (frect_height + (border_width / 2));
873
 
                svg_str = (_tmp10_ = g_strconcat (svg_str, _tmp9_ = g_strdup_printf ("<rect x=\"%.0f\" y=\"%0.1f\" width=\"48px\" height=\"%0.1fpx\" fill=\"" \
874
 
"%s\" stroke-width=\"0\"  />\n", frect_x, frect_y, frect_height, frect_color), NULL), _g_free0 (svg_str), _tmp10_);
875
 
                _g_free0 (_tmp9_);
 
865
                svg_str = (_tmp11_ = g_strconcat (svg_str, _tmp10_ = g_strdup_printf ("<rect x=\"%.0f\" y=\"%0.1f\" width=\"48px\" height=\"%0.1fpx\" fill=\"" \
 
866
"%s\" stroke-width=\"0\"  />\n", frect_x, frect_y, frect_height, frect_color), NULL), _g_free0 (svg_str), _tmp11_);
 
867
                _g_free0 (_tmp10_);
876
868
        }
877
 
        svg_str = (_tmp11_ = g_strconcat (svg_str, "</svg>\n", NULL), _g_free0 (svg_str), _tmp11_);
878
 
        svg_data = (_tmp13_ = g_new0 (guchar, _tmp12_ = string_get_length (svg_str)), svg_data_length1 = _tmp12_, _svg_data_size_ = svg_data_length1, _tmp13_);
 
869
        svg_str = (_tmp12_ = g_strconcat (svg_str, "</svg>\n", NULL), _g_free0 (svg_str), _tmp12_);
 
870
        svg_data = (_tmp14_ = g_new0 (guchar, _tmp13_ = string_get_length (svg_str)), svg_data_length1 = _tmp13_, _svg_data_size_ = svg_data_length1, _tmp14_);
879
871
        {
880
872
                gint i;
881
873
                i = 0;
882
874
                {
883
 
                        gboolean _tmp14_;
884
 
                        _tmp14_ = TRUE;
 
875
                        gboolean _tmp15_;
 
876
                        _tmp15_ = TRUE;
885
877
                        while (TRUE) {
886
 
                                if (!_tmp14_) {
 
878
                                if (!_tmp15_) {
887
879
                                        i++;
888
880
                                }
889
 
                                _tmp14_ = FALSE;
 
881
                                _tmp15_ = FALSE;
890
882
                                if (!(i < string_get_length (svg_str))) {
891
883
                                        break;
892
884
                                }
895
887
                }
896
888
        }
897
889
        {
898
 
                GdkPixbufLoader* _tmp15_;
899
890
                GdkPixbufLoader* _tmp16_;
900
 
                GdkPixbuf* _tmp17_;
901
 
                char* _tmp18_;
902
 
                _tmp15_ = gdk_pixbuf_loader_new_with_type ("svg", &_inner_error_);
 
891
                GdkPixbufLoader* _tmp17_;
 
892
                GdkPixbuf* _tmp18_;
 
893
                char* _tmp19_;
 
894
                _tmp16_ = gdk_pixbuf_loader_new_with_type ("svg", &_inner_error_);
903
895
                if (_inner_error_ != NULL) {
904
896
                        goto __catch5_g_error;
905
897
                }
906
 
                ploader = (_tmp16_ = _tmp15_, _g_object_unref0 (ploader), _tmp16_);
 
898
                ploader = (_tmp17_ = _tmp16_, _g_object_unref0 (ploader), _tmp17_);
907
899
                gdk_pixbuf_loader_write (ploader, svg_data, (gsize) string_get_length (svg_str), &_inner_error_);
908
900
                if (_inner_error_ != NULL) {
909
901
                        goto __catch5_g_error;
912
904
                if (_inner_error_ != NULL) {
913
905
                        goto __catch5_g_error;
914
906
                }
915
 
                pb = (_tmp17_ = _g_object_ref0 (gdk_pixbuf_loader_get_pixbuf (ploader)), _g_object_unref0 (pb), _tmp17_);
 
907
                pb = (_tmp18_ = _g_object_ref0 (gdk_pixbuf_loader_get_pixbuf (ploader)), _g_object_unref0 (pb), _tmp18_);
916
908
                gtk_status_icon_set_from_pixbuf (self->priv->si, pb);
917
 
                main_controller_set_tooltip_text (self, _tmp18_ = g_strdup_printf ("%i%%", self->priv->bat_percent));
918
 
                _g_free0 (_tmp18_);
 
909
                main_controller_set_tooltip_text (self, _tmp19_ = g_strdup_printf ("%i%%", self->priv->bat_percent));
 
910
                _g_free0 (_tmp19_);
919
911
        }
920
912
        goto __finally5;
921
913
        __catch5_g_error: