Commit 00001cda authored by Guido Gunther's avatar Guido Gunther

wwaninfo: Seperate access tec and signal srength

Closes: #118
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 7b143ee8
......@@ -12,6 +12,7 @@
<file preprocess="xml-stripblanks">ui/network-auth-prompt.ui</file>
<file preprocess="xml-stripblanks">ui/settings-menu.ui</file>
<file preprocess="xml-stripblanks">ui/system-prompt.ui</file>
<file preprocess="xml-stripblanks">ui/wwaninfo.ui</file>
<file preprocess="xml-stripblanks">ui/top-panel.ui</file>
<file compressed="true">style.css</file>
<file compressed="true" alias="fake-app.svg">../data/fake-app.svg</file>
......
......@@ -122,7 +122,6 @@
<property name="valign">start</property>
<property name="halign">end</property>
<property name="hexpand">False</property>
<property name="use_fallback">True</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="size">24</property>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="PhoshWWanInfo" parent="GtkBox">
<property name="can_focus">False</property>
<child>
<object class="GtkImage" id="icon">
<property name="can_focus">False</property>
<property name="icon_name">auth-sim-missing-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="access_tec">
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="margin_top">2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</template>
</interface>
......@@ -28,14 +28,17 @@ static GParamSpec *props[PROP_LAST_PROP];
struct _PhoshWWanInfo
{
GtkImage parent;
GtkBox parent;
PhoshWWanMM *wwan;
GtkStyleContext *style_context;
GtkImage *icon;
GtkLabel *access_tec;
gint size;
};
G_DEFINE_TYPE (PhoshWWanInfo, phosh_wwan_info, GTK_TYPE_IMAGE)
G_DEFINE_TYPE (PhoshWWanInfo, phosh_wwan_info, GTK_TYPE_BOX)
static void
phosh_wwan_info_set_property (GObject *object,
......@@ -91,102 +94,10 @@ signal_quality_descriptive(guint quality)
}
static GdkPixbuf *
icon_to_pixbuf (PhoshWWanInfo *self,
const gchar *name,
GtkIconTheme *theme)
{
g_autoptr(GtkIconInfo) info = NULL;
GdkPixbuf *pixbuf;
GError *error = NULL;
info = gtk_icon_theme_lookup_icon (theme,
name,
self->size,
0);
g_return_val_if_fail (info, NULL);
pixbuf = gtk_icon_info_load_symbolic_for_context (info,
self->style_context,
NULL,
&error);
if (pixbuf == NULL) {
g_warning ("Could not load icon pixbuf: %s", error->message);
g_clear_error (&error);
}
return pixbuf;
}
static GdkPixbuf *
pixbuf_overlay_access_tec (PhoshWWanInfo *self,
const char *access_tec,
GdkPixbuf *source)
{
GdkRGBA color;
PangoLayout *layout;
cairo_t *cr;
GdkPixbuf *pixbuf;
cairo_surface_t *cs;
PangoFontDescription *desc;
gint tw = 0, th = 0, scale;
guint width, height;
g_autofree char *font = NULL;
width = gdk_pixbuf_get_width (source);
height = gdk_pixbuf_get_height (source);
cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cr = cairo_create (cs);
gdk_cairo_set_source_pixbuf (cr, source, 0, 0);
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
gtk_style_context_get_color(self->style_context, GTK_STATE_FLAG_NORMAL, &color);
layout = pango_cairo_create_layout (cr);
scale = strlen(access_tec) > 2 ? 5 : 3;
font = g_strdup_printf("Sans Bold %d", height / scale);
desc = pango_font_description_from_string (font);
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_layout_set_text (layout, access_tec, -1);
pango_layout_get_pixel_size (layout, &tw, NULL);
/* Use the baseline instead of text height since we don't have characters below
the baseline. This make sure we align properly at the bottom of the icon */
th = PANGO_PIXELS_FLOOR(pango_layout_get_baseline (layout));
cairo_save (cr);
/* clear rectangle behind the text */
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_rectangle (cr,
(width - 1) - tw,
(height - 1) - th,
tw, th);
cairo_fill (cr);
cairo_restore (cr);
gtk_render_layout (self->style_context, cr,
(width - 1) - tw,
(height - 1) - th,
layout);
pixbuf = gdk_pixbuf_get_from_surface (cs, 0, 0, width, height);
cairo_destroy(cr);
cairo_surface_destroy (cs);
g_object_unref (layout);
return pixbuf;
}
static void
update_icon_data(PhoshWWanInfo *self, GParamSpec *psepc, PhoshWWanMM *wwan)
{
guint quality;
GtkIconTheme *icon_theme;
g_autoptr(GdkPixbuf) src = NULL, dest = NULL;
g_autofree gchar *icon_name = NULL;
const char *access_tec;
......@@ -197,16 +108,18 @@ update_icon_data(PhoshWWanInfo *self, GParamSpec *psepc, PhoshWWanMM *wwan)
g_debug ("Updating wwan icon, shown: %d", visible);
gtk_widget_set_visible (GTK_WIDGET (self), visible);
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET(self)));
/* SIM missing */
if (!phosh_wwan_has_sim (PHOSH_WWAN (self->wwan))) {
gtk_image_set_from_icon_name (GTK_IMAGE (self), "auth-sim-missing-symbolic", -1);
return;
}
if (!phosh_wwan_has_sim (PHOSH_WWAN (self->wwan)))
icon_name = g_strdup ("auth-sim-missing-symbolic");
/* SIM unlock required */
if (!phosh_wwan_is_unlocked (PHOSH_WWAN (self->wwan))) {
gtk_image_set_from_icon_name (GTK_IMAGE (self), "auth-sim-locked-symbolic", -1);
if (!phosh_wwan_is_unlocked (PHOSH_WWAN (self->wwan)))
icon_name = g_strdup ("auth-sim-locked-symbolic");
if (icon_name) {
gtk_image_set_from_icon_name (GTK_IMAGE (self->icon), icon_name, -1);
gtk_widget_show (GTK_WIDGET (self->icon));
gtk_widget_hide (GTK_WIDGET (self->access_tec));
return;
}
......@@ -214,18 +127,18 @@ update_icon_data(PhoshWWanInfo *self, GParamSpec *psepc, PhoshWWanMM *wwan)
quality = phosh_wwan_get_signal_quality (PHOSH_WWAN (self->wwan));
icon_name = g_strdup_printf ("network-cellular-signal-%s-symbolic",
signal_quality_descriptive (quality));
src = icon_to_pixbuf (self, icon_name, icon_theme);
g_return_if_fail (src);
gtk_image_set_from_icon_name (GTK_IMAGE (self->icon), icon_name, -1);
gtk_widget_show (GTK_WIDGET (self->icon));
/* Access technology */
access_tec = phosh_wwan_get_access_tec (PHOSH_WWAN (self->wwan));
if (access_tec)
dest = pixbuf_overlay_access_tec (self, access_tec, src);
else
dest = pixbuf_overlay_access_tec (self, "?", src);
if (access_tec == NULL) {
gtk_widget_hide (GTK_WIDGET(self->access_tec));
return;
}
gtk_image_set_from_pixbuf (GTK_IMAGE (self), dest);
gtk_label_set_text (self->access_tec, access_tec);
gtk_widget_show (GTK_WIDGET(self->access_tec));
}
......@@ -251,7 +164,6 @@ phosh_wwan_info_constructed (GObject *object)
G_OBJECT_CLASS (phosh_wwan_info_parent_class)->constructed (object);
self->style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
self->wwan = phosh_wwan_mm_new();
if (self->size == -1)
......@@ -284,6 +196,7 @@ static void
phosh_wwan_info_class_init (PhoshWWanInfoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->set_property = phosh_wwan_info_set_property;
object_class->get_property = phosh_wwan_info_get_property;
......@@ -302,12 +215,18 @@ phosh_wwan_info_class_init (PhoshWWanInfoClass *klass)
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
gtk_widget_class_set_template_from_resource (widget_class,
"/sm/puri/phosh/ui/wwaninfo.ui");
gtk_widget_class_bind_template_child (widget_class, PhoshWWanInfo, icon);
gtk_widget_class_bind_template_child (widget_class, PhoshWWanInfo, access_tec);
}
static void
phosh_wwan_info_init (PhoshWWanInfo *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
......@@ -326,7 +245,9 @@ phosh_wwan_info_set_size (PhoshWWanInfo *self, gint size)
return;
self->size = size;
gtk_image_set_pixel_size (GTK_IMAGE (self), size);
gtk_image_set_pixel_size (GTK_IMAGE (self->icon), size);
/* fixme: set text size */
//gtk_label_set_ (GTK_IMAGE (self->icon), size);
gtk_widget_queue_resize (GTK_WIDGET (self));
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SIZE]);
......
......@@ -12,7 +12,7 @@ G_BEGIN_DECLS
#define PHOSH_TYPE_WWAN_INFO (phosh_wwan_info_get_type())
G_DECLARE_FINAL_TYPE (PhoshWWanInfo, phosh_wwan_info, PHOSH, WWAN_INFO, GtkImage)
G_DECLARE_FINAL_TYPE (PhoshWWanInfo, phosh_wwan_info, PHOSH, WWAN_INFO, GtkBox)
GtkWidget * phosh_wwan_info_new (void);
void phosh_wwan_info_set_size (PhoshWWanInfo *self, gint size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment