Beispiel #1
0
static void battery_handler(BatteryChargeState charge_state) {
    if (get_prefs()->battery_as_number) {

        if (charge_state.is_charging) {
            text_layer_set_text(s_component->text_layer, "+%");
        } else {
            static char battery_text[8];
            snprintf(battery_text, sizeof(battery_text), "%d%%", charge_state.charge_percent);
            text_layer_set_text(s_component->text_layer, battery_text);
        }
        layer_mark_dirty(text_layer_get_layer(s_component->text_layer));

    } else {

        if (s_component->icon_bitmap != NULL) {
            gbitmap_destroy(s_component->icon_bitmap);
        }
        s_component->icon_bitmap = gbitmap_create_with_resource(battery_icon_id(charge_state));
        bitmap_layer_set_bitmap(s_component->icon_layer, s_component->icon_bitmap);

        // bitmap_layer_set_bitmap is supposed to trigger this automatically.
        // https://forums.getpebble.com/discussion/comment/129517/#Comment_129517
        layer_mark_dirty(bitmap_layer_get_layer(s_component->icon_layer));

    }
}
Beispiel #2
0
BatteryComponent* battery_component_create(Layer *parent, int16_t x, int16_t y, bool align_right) {
    battery_state_service_subscribe(battery_handler);

    BatteryComponent *c = malloc(sizeof(BatteryComponent));
    c->icon_layer = NULL;
    c->icon_bitmap = NULL;
    c->text_layer = NULL;

    if (get_prefs()->battery_as_number) {

        FontChoice font = get_font(BATTERY_FONT);
        c->text_layer = add_text_layer(
                            parent,
                            GRect(x, y - font.padding_top + font.padding_bottom, BATTERY_TEXT_WIDTH, font.height + font.padding_top + font.padding_bottom),
                            fonts_get_system_font(font.key),
                            element_fg(parent),
                            align_right ? GTextAlignmentRight : GTextAlignmentLeft
                        );

    } else {

        c->icon_layer = bitmap_layer_create(GRect(x, y + BATTERY_ICON_TOP_FUDGE, BATTERY_ICON_WIDTH, BATTERY_ICON_HEIGHT));
        bitmap_layer_set_compositing_mode(c->icon_layer, element_comp_op(parent));
        layer_add_child(parent, bitmap_layer_get_layer(c->icon_layer));

    }

    // XXX
    s_component = c;
    battery_handler(battery_state_service_peek());

    return c;
}
Beispiel #3
0
static Layer* get_layer_for_element(int element) {
  for(int i = 0; i < get_prefs()->num_elements; i++) {
    if(get_element_data(s_layers[i])->el == element) {
      return s_layers[i];
    }
  }
  return NULL;
}
Beispiel #4
0
/* Connect UI event signals to callback functions */
static void connect_signals(GtkWidget* window) {
	GObject* signaltmp;
	GObject* photo;

	g_signal_connect(G_OBJECT(window), "delete-event", gtk_main_quit, NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_file_open"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(file_open), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_file_saveas_xml"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(file_save), "xml");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_file_saveas_csv"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(file_save), "csv");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_file_reader_auto"));
	g_signal_connect(signaltmp, "toggled", G_CALLBACK(auto_reader), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_file_close"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(file_close), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_file_print"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(do_print), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_file_quit"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(gtk_main_quit), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_lang_de"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(translate), "de_BE.UTF-8");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_lang_en"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(translate), "en_US.UTF-8");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_lang_fr"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(translate), "fr_BE.UTF-8");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_lang_nl"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(translate), "nl_BE.UTF-8");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_help_about"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(showabout), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_help_faq"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(showurl), "faq");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_help_test"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(showurl), "test");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_cert_detail"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(certdetail), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_cert_export_der"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(certexport), "DER");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_cert_export_pem"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(certexport), "PEM");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "mi_cert_export_chain"));
	g_signal_connect(signaltmp, "activate", G_CALLBACK(certexport), "chain");
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "pintestbut"));
	g_signal_connect(signaltmp, "clicked", G_CALLBACK(pinop), (void*)EID_VWR_PINOP_TEST);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "pinchangebut"));
	g_signal_connect(signaltmp, "clicked", G_CALLBACK(pinop), (void*)EID_VWR_PINOP_CHG);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "photobox"));
	photo = G_OBJECT(gtk_builder_get_object(builder, "photo"));
	g_signal_connect(signaltmp, "drag-data-get", G_CALLBACK(drag_data_get), photo);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "validate_now"));
	g_signal_connect(signaltmp, "clicked", G_CALLBACK(validate_all), NULL);
	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "validate_always"));
	g_signal_connect(signaltmp, "toggled", G_CALLBACK(validate_toggle), NULL);

	signaltmp = G_OBJECT(gtk_builder_get_object(builder, "cert_paned"));
	g_settings_bind(get_prefs(), "cert-paned-pos", signaltmp, "position", 0);
}
StatusBarElement* status_bar_element_create(Layer *parent) {
  GRect bounds = element_get_bounds(parent);

  int sm_text_margin = 2;
  FontChoice font = get_font(FONT_18_BOLD);

  int text_y, height;
  if (bounds.size.h <= font.height + font.padding_top + font.padding_bottom) {
    // vertically center text if there is only room for one line
    text_y = (bounds.size.h - font.height) / 2 - font.padding_top;
    height = font.height + font.padding_top + font.padding_bottom;
  } else {
    // otherwise take up all the space, with half the default padding
    text_y = -1 * font.padding_top / 2;
    height = bounds.size.h - text_y;
  }

  TextLayer *text = text_layer_create(GRect(
    sm_text_margin,
    text_y,
    bounds.size.w - sm_text_margin,
    height
  ));
  text_layer_set_text_alignment(text, GTextAlignmentLeft);
  text_layer_set_background_color(text, GColorClear);
  text_layer_set_text_color(text, element_fg(parent));

  text_layer_set_font(text, fonts_get_system_font(font.key));
  text_layer_set_overflow_mode(text, GTextOverflowModeWordWrap);
  layer_add_child(parent, text_layer_get_layer(text));

  BatteryComponent *battery = NULL;
  if (get_prefs()->battery_loc == BATTERY_LOC_STATUS_RIGHT) {
    // align the battery to the middle of the lowest line of text
    int lines = (bounds.size.h - text_y) / (font.height + font.padding_top);
    int battery_y = text_y + (font.height + font.padding_top) * (lines - 1) + font.padding_top + font.height / 2 - battery_component_height() / 2;
    // ...unless that places it too close to the bottom
    if (battery_y + battery_component_height() - battery_component_vertical_padding() > bounds.size.h - sm_text_margin) {
      battery_y = bounds.size.h - battery_component_height() + battery_component_vertical_padding() - sm_text_margin;
    }

    battery = battery_component_create(parent, bounds.size.w - battery_component_width() - sm_text_margin, battery_y, true);
  }

  StatusBarElement *el = malloc(sizeof(StatusBarElement));
  el->text = text;
  el->battery = battery;
  return el;
}
Beispiel #6
0
void delta_text_layer_update(TextLayer *text_layer, DataMessage *data) {
  static char delta_buffer[8];
  int delta;
  if (sgv_graph_padding() > 0) {
    delta = NO_DELTA_VALUE;
  } else {
    delta = data->delta;
  }

  if (delta == NO_DELTA_VALUE) {
    text_layer_set_text(text_layer, "-");
  } else {
    format_bg(delta_buffer, sizeof(delta_buffer), delta, true, get_prefs()->mmol);
    text_layer_set_text(text_layer, delta_buffer);
  }
}
int main(int argc, char **argv)
{
    if (parse_options(argc, argv))
        return EXIT_SUCCESS;

    if (verbose > 1)
    {
        fprintf(stderr, "head:         %d\n", head);
        fprintf(stderr, "wrap_columns: %d\n", wrap_columns);
        if (nyarlathotep_p)
            fprintf(stderr, "nyarlathotep is enabled\n");
    }

    if (load_p)
        get_prefs();

    output();

    return EXIT_SUCCESS;
}
StatusBarElement* status_bar_element_create(Layer *parent) {
  GRect bounds = element_get_bounds(parent);

  int sm_text_margin = 2;

  int y, height;
  if (bounds.size.h <= ACTUAL_TEXT_HEIGHT_18 + PADDING_TOP_18 + PADDING_BOTTOM_18) {
    // vertically center text if there is only room for one line
    y = (bounds.size.h - ACTUAL_TEXT_HEIGHT_18) / 2 - PADDING_TOP_18;
    height = ACTUAL_TEXT_HEIGHT_18 + PADDING_TOP_18 + PADDING_BOTTOM_18;
  } else {
    // otherwise take up all the space, with half the default padding
    y = -1 * PADDING_TOP_18 / 2;
    height = bounds.size.h - y;
  }
  TextLayer *text = text_layer_create(GRect(
    sm_text_margin,
    y,
    bounds.size.w - sm_text_margin,
    height
  ));
  text_layer_set_text_alignment(text, GTextAlignmentLeft);
  text_layer_set_background_color(text, GColorClear);
  text_layer_set_text_color(text, element_fg(parent));

  text_layer_set_font(text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_overflow_mode(text, GTextOverflowModeWordWrap);
  layer_add_child(parent, text_layer_get_layer(text));

  BatteryComponent *battery = NULL;
  if (get_prefs()->battery_loc == BATTERY_LOC_STATUS_RIGHT) {
    battery = battery_component_create(parent, bounds.size.w - battery_component_width() - battery_component_vertical_padding(), (bounds.size.h - battery_component_height()) / 2);
  }

  StatusBarElement *el = malloc(sizeof(StatusBarElement));
  el->text = text;
  el->battery = battery;
  return el;
}
Beispiel #9
0
void last_bg_text_layer_update(TextLayer *text_layer, DataMessage *data) {
  static char last_bg_buffer[8];
  format_bg(last_bg_buffer, sizeof(last_bg_buffer), data->last_sgv, false, get_prefs()->mmol);
  text_layer_set_text(text_layer, last_bg_buffer);
}
Beispiel #10
0
uint8_t battery_component_vertical_padding() {
    return get_prefs()->battery_as_number ? get_font(BATTERY_FONT).padding_bottom : BATTERY_ICON_PADDING;
}
Beispiel #11
0
uint8_t battery_component_height() {
    return get_prefs()->battery_as_number ? get_font(BATTERY_FONT).height + 2 * get_font(BATTERY_FONT).padding_bottom : BATTERY_ICON_HEIGHT;
}
Beispiel #12
0
uint8_t battery_component_width() {
    return get_prefs()->battery_as_number ? BATTERY_TEXT_WIDTH : BATTERY_ICON_WIDTH;
}