Compare commits
2 Commits
5244701c7b
...
a897006a56
Author | SHA1 | Date |
---|---|---|
Markus Koch | a897006a56 | |
Markus Koch | bdd19cf4b8 |
|
@ -0,0 +1,53 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.20.0 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.12"/>
|
||||||
|
<object class="GtkBox" id="previewWidget">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<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="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>
|
||||||
|
</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>
|
||||||
|
<signal name="clicked" handler="kona_download_image" object="previewWidget" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
|
@ -14,6 +14,8 @@ int buildWindow() {
|
||||||
GtkWidget *previewContainer;
|
GtkWidget *previewContainer;
|
||||||
GtkWidget *temp;
|
GtkWidget *temp;
|
||||||
|
|
||||||
|
KonaImage *ki;
|
||||||
|
|
||||||
builder = gtk_builder_new();
|
builder = gtk_builder_new();
|
||||||
gtk_builder_add_from_file(builder, "glade/mainWindow.glade", NULL);
|
gtk_builder_add_from_file(builder, "glade/mainWindow.glade", NULL);
|
||||||
|
|
||||||
|
@ -26,7 +28,9 @@ int buildWindow() {
|
||||||
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(previewLayout), 200);
|
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(previewLayout), 200);
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
// CUSTOM!!!!!
|
// CUSTOM!!!!!
|
||||||
temp = PreviewWidget_new();
|
ki = kona_image_new();
|
||||||
|
|
||||||
|
temp = PreviewWidget_new(ki);
|
||||||
gtk_flow_box_insert(GTK_FLOW_BOX(previewLayout),temp,0);
|
gtk_flow_box_insert(GTK_FLOW_BOX(previewLayout),temp,0);
|
||||||
gtk_widget_show(temp);
|
gtk_widget_show(temp);
|
||||||
// -------------------
|
// -------------------
|
||||||
|
@ -46,7 +50,8 @@ int buildWindow() {
|
||||||
|
|
||||||
/*** TESTING LIB ***/
|
/*** TESTING LIB ***/
|
||||||
GValue val = G_VALUE_INIT;
|
GValue val = G_VALUE_INIT;
|
||||||
KonaImage *ki;
|
GValue sval = G_VALUE_INIT;
|
||||||
|
|
||||||
kona_image_meta meta;
|
kona_image_meta meta;
|
||||||
ki = kona_image_new();
|
ki = kona_image_new();
|
||||||
g_value_init(&val, G_TYPE_POINTER);
|
g_value_init(&val, G_TYPE_POINTER);
|
||||||
|
@ -60,7 +65,14 @@ int buildWindow() {
|
||||||
g_object_set_property((GObject*) ki, "meta", &val);
|
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(&val);
|
||||||
|
g_value_reset(&sval);
|
||||||
|
|
||||||
meta.height = 0;
|
meta.height = 0;
|
||||||
meta.width = 1;
|
meta.width = 1;
|
||||||
|
|
||||||
|
@ -70,6 +82,10 @@ int buildWindow() {
|
||||||
metret = g_value_get_pointer(&val);
|
metret = g_value_get_pointer(&val);
|
||||||
printf("WIDTH=%i\n", metret->width);
|
printf("WIDTH=%i\n", metret->width);
|
||||||
printf("HEIGHT=%i\n", metret->height);
|
printf("HEIGHT=%i\n", metret->height);
|
||||||
|
|
||||||
|
g_object_get_property((GObject*) ki, "fullFile", &sval);
|
||||||
|
printf("STRING=%s\n", g_value_get_string(&sval));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
|
@ -1,23 +1,30 @@
|
||||||
#include "previewwidget.h"
|
#include "previewwidget.h"
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE(PreviewWidget, PreviewWidget, GTK_TYPE_BIN)
|
G_DEFINE_TYPE(PreviewWidget, PreviewWidget, GTK_TYPE_BIN)
|
||||||
|
|
||||||
|
|
||||||
void kona_download_image( GtkWidget *widget, gpointer data )
|
void kona_download_image( GtkWidget *widget, gpointer data )
|
||||||
{
|
{
|
||||||
PreviewWidget_set_image(data, ""); // DEBUG ONLY!
|
PreviewWidget_set_image(data, "/home/kurisu/Pictures/a.xpm"); // DEBUG ONLY!
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
|
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
|
||||||
GtkWidget *spinner;
|
GtkWidget *w;
|
||||||
GList *widgets;
|
GList *widgets;
|
||||||
|
|
||||||
widgets = gtk_container_get_children(GTK_CONTAINER(widget));
|
widgets = gtk_container_get_children(GTK_CONTAINER(widget));
|
||||||
spinner = widgets->data;
|
w = widgets->data; // Grab GtkImage
|
||||||
gtk_widget_set_visible(spinner, TRUE);
|
|
||||||
|
|
||||||
spinner = g_list_next(widgets)->data;
|
GdkPixbuf *p;
|
||||||
gtk_widget_set_visible(spinner, FALSE);
|
p = gdk_pixbuf_new_from_file(url, NULL);
|
||||||
|
p = gdk_pixbuf_scale_simple(p, 200, 150, GDK_INTERP_BILINEAR);
|
||||||
|
gtk_image_set_from_pixbuf(GTK_IMAGE(w), p);
|
||||||
|
|
||||||
|
gtk_widget_set_visible(w, TRUE);
|
||||||
|
|
||||||
|
w = g_list_next(widgets)->data; // Grab Spinner
|
||||||
|
gtk_widget_set_visible(w, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +54,7 @@ void PreviewWidget_init(PreviewWidget *klass)
|
||||||
g_object_unref(G_OBJECT(builder));
|
g_object_unref(G_OBJECT(builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *PreviewWidget_new()
|
GtkWidget *PreviewWidget_new(KonaImage* ki)
|
||||||
{
|
{
|
||||||
return g_object_new (TYPE_PREVIEWWIDGET, NULL);
|
return g_object_new (TYPE_PREVIEWWIDGET, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
#define PREVIEWWIDGET_H
|
#define PREVIEWWIDGET_H
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "konaimage.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define TYPE_PREVIEWWIDGET (PreviewWidget_get_type ())
|
#define TYPE_PREVIEWWIDGET (PreviewWidget_get_type ())
|
||||||
|
@ -25,7 +26,7 @@ struct _PreviewWidgetClass {
|
||||||
};
|
};
|
||||||
|
|
||||||
GType PreviewWidget_get_type (void) G_GNUC_CONST;
|
GType PreviewWidget_get_type (void) G_GNUC_CONST;
|
||||||
GtkWidget* PreviewWidget_new (void);
|
GtkWidget* PreviewWidget_new (KonaImage* ki);
|
||||||
|
|
||||||
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url);
|
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "konaimage.h"
|
#include "konaimage.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
guint64 test;
|
guint64 test;
|
||||||
|
@ -7,18 +8,18 @@ typedef struct {
|
||||||
|
|
||||||
struct _KonaImage {
|
struct _KonaImage {
|
||||||
GObject parent_instance; // struct of parent (inherit)
|
GObject parent_instance; // struct of parent (inherit)
|
||||||
guint64 id;
|
kona_image_meta meta;
|
||||||
GList *tags;
|
GString* preview_url;
|
||||||
GString *url;
|
GString* full_url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE(KonaImage, kona_image, G_TYPE_OBJECT)
|
G_DEFINE_TYPE_WITH_PRIVATE(KonaImage, kona_image, G_TYPE_OBJECT)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_ID = 1,
|
PROP_META=1,
|
||||||
PROP_TAGS,
|
PROP_FILE_PREVIEW,
|
||||||
PROP_URL,
|
PROP_FILE_FULL,
|
||||||
PROP_COUNT
|
PROP_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,14 +29,15 @@ static void kona_image_get_property(GObject *object, guint prop_id, GValue *valu
|
||||||
KonaImage *self = (KonaImage*)object;
|
KonaImage *self = (KonaImage*)object;
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_ID:
|
case PROP_FILE_PREVIEW:
|
||||||
g_value_set_uint64(value, *kona_image_get_id(self));
|
g_value_set_string(value, (const gchar*) self->preview_url);
|
||||||
break;
|
break;
|
||||||
case PROP_TAGS:
|
case PROP_FILE_FULL:
|
||||||
g_value_set_gtype(value, (GType) self->tags); // Returning the pointer itself may be dangerous... Rather copy it to the target value?
|
g_value_set_string(value, (const gchar*) self->full_url);
|
||||||
|
break;
|
||||||
|
case PROP_META:
|
||||||
|
g_value_set_pointer(value, &self->meta);
|
||||||
break;
|
break;
|
||||||
case PROP_URL:
|
|
||||||
g_value_set_string(value, (const gchar*) self->url);
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -45,16 +47,16 @@ static void kona_image_set_property(GObject *object, guint prop_id, const GValue
|
||||||
KonaImage *self = (KonaImage*)object;
|
KonaImage *self = (KonaImage*)object;
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_ID:
|
case PROP_FILE_FULL:
|
||||||
kona_image_set_id(self, g_value_get_uint64(value));
|
g_free(self->full_url);
|
||||||
|
self->full_url = (GString*) g_strdup(g_value_get_string(value));
|
||||||
break;
|
break;
|
||||||
case PROP_TAGS:
|
case PROP_FILE_PREVIEW:
|
||||||
g_list_free(self->tags);
|
g_free(self->preview_url);
|
||||||
self->tags = g_list_copy((GList*) g_value_get_gtype(value));
|
self->preview_url = (GString*) g_strdup(g_value_get_string(value));
|
||||||
break;
|
break;
|
||||||
case PROP_URL:
|
case PROP_META:
|
||||||
g_free(self->url);
|
memcpy(&self->meta, g_value_get_pointer(value), sizeof(kona_image_meta));
|
||||||
self->url = (GString*) g_strdup(g_value_get_string(value));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -67,14 +69,14 @@ static void kona_image_class_init(KonaImageClass *klass) {
|
||||||
object_class->set_property = kona_image_set_property;
|
object_class->set_property = kona_image_set_property;
|
||||||
object_class->get_property = kona_image_get_property;
|
object_class->get_property = kona_image_get_property;
|
||||||
|
|
||||||
properties [PROP_ID] =
|
properties [PROP_META] =
|
||||||
g_param_spec_uint64("id", "id", "The ID of the image.", 0, G_MAXINT64, 22, G_PARAM_READWRITE);
|
g_param_spec_pointer("meta", "meta", "Meta info struct", G_PARAM_READWRITE);
|
||||||
|
|
||||||
properties [PROP_TAGS] =
|
properties [PROP_FILE_FULL] =
|
||||||
g_param_spec_gtype("tags", "tags", "A list of tags.", G_TYPE_NONE, G_PARAM_READWRITE); // TODO: G_TYPE_NONE for a GList(GString) a parameter?
|
g_param_spec_string("fullFile", "fullFile", "Local URL to the file", "", G_PARAM_READWRITE);
|
||||||
|
|
||||||
properties [PROP_URL] =
|
properties [PROP_FILE_PREVIEW] =
|
||||||
g_param_spec_string("url", "url", "The URL to the full picture.", "", G_PARAM_READWRITE);
|
g_param_spec_string("previewFile", "previewFile", "Local URL to the preview file", "", G_PARAM_READWRITE);
|
||||||
|
|
||||||
g_object_class_install_properties(object_class, PROP_COUNT, properties);
|
g_object_class_install_properties(object_class, PROP_COUNT, properties);
|
||||||
}
|
}
|
||||||
|
@ -90,20 +92,12 @@ static void kona_image_dispose(KonaImage *self) {
|
||||||
|
|
||||||
static void kona_image_finalize(KonaImage *self) {
|
static void kona_image_finalize(KonaImage *self) {
|
||||||
// Clear public vars here
|
// Clear public vars here
|
||||||
g_free(self->tags);
|
g_free(self->meta.image_url);
|
||||||
|
g_free(self->meta.preview_url);
|
||||||
|
g_free(self->meta.tags);
|
||||||
G_OBJECT_CLASS (kona_image_parent_class)->finalize ((GObject*) self);
|
G_OBJECT_CLASS (kona_image_parent_class)->finalize ((GObject*) self);
|
||||||
}
|
}
|
||||||
|
|
||||||
const guint64 *kona_image_get_id(KonaImage *self)
|
|
||||||
{
|
|
||||||
return &(self->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void kona_image_set_id(KonaImage *self, const guint64 id)
|
|
||||||
{
|
|
||||||
self->id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KonaImage *kona_image_new()
|
KonaImage *kona_image_new()
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,8 +11,15 @@ G_DECLARE_FINAL_TYPE (KonaImage, kona_image, KONA, IMAGE, GObject) // Struct nam
|
||||||
|
|
||||||
KonaImage *kona_image_new (void);
|
KonaImage *kona_image_new (void);
|
||||||
|
|
||||||
const guint64 *kona_image_get_id(KonaImage *self);
|
struct kona_image_meta_struct {
|
||||||
void kona_image_set_id(KonaImage *self, const guint64 id);
|
int id;
|
||||||
|
GList *tags;
|
||||||
|
char* preview_url;
|
||||||
|
char* image_url;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
typedef struct kona_image_meta_struct kona_image_meta;
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue