Yey memory leaks!

This commit is contained in:
Markus Koch 2016-06-04 23:06:46 +02:00
parent a897006a56
commit d91b369050
4 changed files with 40 additions and 6 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkBox" id="previewWidget">
@ -10,9 +10,8 @@
<object class="GtkImage" id="image">
<property name="width_request">200</property>
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixbuf">Screenshot from 2015-10-22 18-13-07.png</property>
<property name="icon_name">applications-graphics</property>
<property name="use_fallback">True</property>
</object>
<packing>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkBox" id="previewWidget">
@ -48,5 +48,19 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="debugfoo" object="image" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</interface>

View File

@ -6,19 +6,33 @@ G_DEFINE_TYPE(PreviewWidget, PreviewWidget, GTK_TYPE_BIN)
void kona_download_image( GtkWidget *widget, gpointer data )
{
PreviewWidget_set_image(data, "/home/kurisu/Pictures/a.xpm"); // DEBUG ONLY!
PreviewWidget_set_image(data, "/home/kurisu/Pictures/Wallpapers/preview.jpg"); // DEBUG ONLY!
}
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
GtkWidget *w;
GList *widgets;
int height, width;
float iheight, iwidth;
widgets = gtk_container_get_children(GTK_CONTAINER(widget));
w = widgets->data; // Grab GtkImage
GdkPixbuf *p;
p = gdk_pixbuf_new_from_file(url, NULL);
p = gdk_pixbuf_scale_simple(p, 200, 150, GDK_INTERP_BILINEAR);
iheight = (float) gdk_pixbuf_get_height(p);
iwidth = (float) gdk_pixbuf_get_width(p);
if (gdk_pixbuf_get_width(p) < gdk_pixbuf_get_height(p)) {
height = 150;
width = iwidth / iheight * 150;
}
else {
width = 200;
height = iheight / iwidth * 200;
}
p = gdk_pixbuf_scale_simple(p, width, height, GDK_INTERP_BILINEAR);
gtk_image_set_from_pixbuf(GTK_IMAGE(w), p);
gtk_widget_set_visible(w, TRUE);
@ -61,3 +75,8 @@ GtkWidget *PreviewWidget_new(KonaImage* ki)
// TODO: DESTROY etc.
void debugfoo(GtkButton *widget, GtkImage *img)
{
gtk_widget_destroy(img);
}

View File

@ -30,6 +30,8 @@ GtkWidget* PreviewWidget_new (KonaImage* ki);
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url);
void debugfoo(GtkButton *widget, GtkImage* img);
G_END_DECLS
#endif // PREVIEWWIDGET_H