Compare commits

..

3 Commits

Author SHA1 Message Date
70dcc379d5 Tried adding click on image stuff 2016-06-06 22:20:38 +02:00
477585cd2d Stuff 2016-06-06 22:01:29 +02:00
ebf28dc49c Added meta callback 2016-06-06 21:27:33 +02:00
7 changed files with 137 additions and 109 deletions

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="GtkEntryCompletion" id="searchCompletion"/>

View File

@ -2,64 +2,69 @@
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkBox" id="previewWidget">
<object class="GtkEventBox" id="evBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage" id="image">
<object class="GtkBox" id="previewWidget">
<property name="width_request">200</property>
<property name="height_request">150</property>
<property name="can_focus">False</property>
<property name="icon_name">applications-graphics</property>
<property name="use_fallback">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinner" id="spinner">
<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="active">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage" id="image">
<property name="height_request">150</property>
<property name="can_focus">False</property>
<property name="icon_name">applications-graphics</property>
<property name="use_fallback">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinner" id="spinner">
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button">
<property name="label" translatable="yes">Download @ 0000 x 0000</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Debug</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>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button">
<property name="label" translatable="yes">Download @ 0000 x 0000</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<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

@ -26,7 +26,8 @@ int buildWindow() {
previewLayout = gtk_flow_box_new();
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(previewLayout), 200);
for (int i = 0; i < 2; ++i) {
for (int i = 0; i < 4; ++i) {
// CUSTOM!!!!!
ki = kona_image_new();
temp = PreviewWidget_new(ki);
@ -38,57 +39,28 @@ int buildWindow() {
gtk_widget_show(previewLayout);
gtk_container_add(GTK_CONTAINER(previewContainer), previewLayout);
gtk_container_add(GTK_CONTAINER(previewContainer), previewLayout);
g_object_unref(G_OBJECT(builder));
g_object_unref(G_OBJECT(builder));
gtk_widget_show(GTK_WIDGET(mainWindow));
gtk_widget_show(GTK_WIDGET(mainWindow));
/* Testing callbacks */
GValue val = G_VALUE_INIT;
GValue sval = G_VALUE_INIT;
kona_image_meta meta;
meta.height = 100;
meta.width = 200;
meta.image_url = "http://meow.cat/fullpic.png";
g_value_init(&sval, G_TYPE_STRING);
g_value_set_string(&sval, "/home/markus/Pictures/FFT-an.png");
g_object_set_property((GObject*) ki, "previewFile", &sval);
GValue sval = G_VALUE_INIT;
g_value_init(&sval, G_TYPE_STRING);
g_value_set_string(&sval, "/home/markus/Pictures/FFT-an.png");
g_object_set_property((GObject*) ki, "previewFile", &sval);
if (0) {
/*** TESTING LIB ***/
GValue val = G_VALUE_INIT;
kona_image_meta meta;
ki = kona_image_new();
g_value_init(&val, G_TYPE_POINTER);
meta.height = 100;
meta.width = 200;
meta.image_url = "MEOWMEOWMEOW";
g_value_set_pointer(&val, (gpointer) &meta);
g_object_set_property((GObject*) ki, "meta", &val);
g_value_init(&sval, G_TYPE_STRING);
g_value_set_string(&sval, "Hello world!");
g_object_set_property((GObject*) ki, "fullFile", &sval);
g_value_reset(&val);
g_value_reset(&sval);
meta.height = 0;
meta.width = 1;
// Read back
g_object_get_property((GObject*) ki, "meta", &val);
kona_image_meta *metret;
metret = g_value_get_pointer(&val);
printf("WIDTH=%i\n", metret->width);
printf("HEIGHT=%i\n", metret->height);
g_object_get_property((GObject*) ki, "fullFile", &sval);
printf("STRING=%s\n", g_value_get_string(&sval));
}
g_value_init(&val, G_TYPE_POINTER);
g_value_set_pointer(&val, (gpointer) &meta);
g_object_set_property((GObject*) ki, "meta", &val);
}
int main(int argc, char **argv)

View File

@ -4,9 +4,17 @@
G_DEFINE_TYPE(PreviewWidget, PreviewWidget, GTK_TYPE_BIN)
void kona_download_image( GtkWidget *widget, gpointer data )
// widget = PreviewWidget
// data = KonaImage
void kona_download_image( GtkWidget *widget, KonaImage* ki )
{
PreviewWidget_set_image(data, "/home/markus/Pictures/ba5431ccdc292f920692d17bdfc2758d.png"); // DEBUG ONLY!
kona_image_meta *meta;
meta = kona_image_get_meta_from_konaimage(ki);
printf("DOWNLOAD %s!\n", meta->image_url);
fflush(stdout);
//PreviewWidget_set_image(data, "/home/markus/Pictures/ba5431ccdc292f920692d17bdfc2758d.png"); // DEBUG ONLY!
}
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
@ -39,7 +47,7 @@ void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
enum {
PROP_KI=1,
PROP_COUNT
PROP_COUNT
};
static GParamSpec *properties [PROP_COUNT];
static void preview_widget_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
@ -85,11 +93,13 @@ void PreviewWidget_init(PreviewWidget *klass)
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "glade/previewWidget.glade", NULL);
widget = GTK_WIDGET(gtk_builder_get_object(GTK_BUILDER(builder), "previewWidget"));
widget = GTK_WIDGET(gtk_builder_get_object(GTK_BUILDER(builder), "evBox"));
gtk_builder_connect_signals(builder, NULL);
gtk_container_add(GTK_CONTAINER(klass), widget);
klass->evBox = widget;
gtk_widget_set_events (klass->evBox, GDK_BUTTON_PRESS_MASK); // TODO: Click event foo here
klass->image = GTK_WIDGET(gtk_builder_get_object(builder, "image"));
klass->button = GTK_WIDGET(gtk_builder_get_object(builder, "button"));
klass->spinner = GTK_WIDGET(gtk_builder_get_object(builder, "spinner"));
@ -100,7 +110,14 @@ void PreviewWidget_init(PreviewWidget *klass)
GtkWidget *PreviewWidget_new(KonaImage* ki)
{
PreviewWidget* w = g_object_new (TYPE_PREVIEWWIDGET, "ki", ki, NULL);
g_signal_connect(ki, "notify::previewFile", (GCallback)previewImage_update_preview_from_konaImage, w);
// Connect KonaImage callbacks
g_signal_connect_swapped(ki, "notify::previewFile", (GCallback)previewImage_update_preview_from_konaImage, w);
g_signal_connect_swapped(ki, "notify::meta", (GCallback)previewImage_update_meta_from_konaImage, w);
// Connect UI handlers
g_signal_connect(w->button, "clicked", (GCallback)kona_download_image, ki);
g_signal_connect(w->evBox, "button_press_event", (GCallback)kona_download_image, ki); // TODO: Click event foo here
return GTK_WIDGET(w);
}
@ -114,11 +131,27 @@ void debugfoo(GtkButton *widget, GtkImage *img)
}
// CALLBACKS FROM KONAIMAGE
void previewImage_update_preview_from_konaImage( KonaImage *ki, guint propId, PreviewWidget *pv)
/* ------------------------ *
* CALLBACKS FROM KONAIMAGE *
* ------------------------ */
void previewImage_update_preview_from_konaImage(PreviewWidget *pv, guint propId, KonaImage *ki)
{
GValue val = G_VALUE_INIT;
g_value_init(&val, G_TYPE_STRING);
g_object_get_property(G_OBJECT(ki), "previewFile", &val);
PreviewWidget_set_image(pv, g_value_get_string(&val));
PreviewWidget_set_image(pv, (gchar*) g_value_get_string(&val));
}
void previewImage_update_meta_from_konaImage(PreviewWidget *pv, guint propId, KonaImage *ki)
{
kona_image_meta *meta;
gchar* text;
meta = kona_image_get_meta_from_konaimage(ki);
text = g_strdup_printf("Download @ %dx%d", meta->width, meta->height);
gtk_button_set_label(GTK_BUTTON(pv->button), text);
g_free(text);
fflush(stdout);
}

View File

@ -18,6 +18,7 @@ typedef struct _PreviewWidgetClass PreviewWidgetClass;
struct _PreviewWidget {
GtkBin bin;
GtkWidget *evBox;
GtkWidget *image;
GtkWidget *button;
GtkWidget *spinner;
@ -37,8 +38,11 @@ void PreviewWidget_set_image(PreviewWidget *widget, gchar *url);
void debugfoo(GtkButton *widget, GtkImage* img);
// CALLBACKS FROM KONAIMAGE
void previewImage_update_preview_from_konaImage(KonaImage *ki, guint propId, PreviewWidget *pv);
/* ------------------------ *
* CALLBACKS FROM KONAIMAGE *
* ------------------------ */
void previewImage_update_preview_from_konaImage(PreviewWidget *pv, guint propId, KonaImage *ki);
void previewImage_update_meta_from_konaImage(PreviewWidget *pv, guint propId, KonaImage *ki);
G_END_DECLS

View File

@ -103,3 +103,13 @@ KonaImage *kona_image_new()
{
return g_object_new(KONA_TYPE_IMAGE, 0);
}
kona_image_meta* kona_image_get_meta_from_konaimage(KonaImage *ki) {
kona_image_meta *meta;
GValue val = G_VALUE_INIT;
g_value_init(&val, G_TYPE_POINTER);
g_object_get_property(G_OBJECT(ki), "meta", &val);
meta = g_value_get_pointer(&val);
g_value_reset(&val);
return meta;
}

View File

@ -21,6 +21,10 @@ struct kona_image_meta_struct {
};
typedef struct kona_image_meta_struct kona_image_meta;
// Access functions for parameters (read only)
kona_image_meta* kona_image_get_meta_from_konaimage(KonaImage *ki);
G_END_DECLS
#endif // KONAIMAGE_H