Compare commits
2 Commits
5244701c7b
...
a897006a56
Author | SHA1 | Date | |
---|---|---|---|
a897006a56 | |||
bdd19cf4b8 |
53
konaclient-gtk/glade/#previewWidget.glade#
Normal file
53
konaclient-gtk/glade/#previewWidget.glade#
Normal file
@ -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 *temp;
|
||||
|
||||
KonaImage *ki;
|
||||
|
||||
builder = gtk_builder_new();
|
||||
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);
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
// CUSTOM!!!!!
|
||||
temp = PreviewWidget_new();
|
||||
ki = kona_image_new();
|
||||
|
||||
temp = PreviewWidget_new(ki);
|
||||
gtk_flow_box_insert(GTK_FLOW_BOX(previewLayout),temp,0);
|
||||
gtk_widget_show(temp);
|
||||
// -------------------
|
||||
@ -46,7 +50,8 @@ int buildWindow() {
|
||||
|
||||
/*** TESTING LIB ***/
|
||||
GValue val = G_VALUE_INIT;
|
||||
KonaImage *ki;
|
||||
GValue sval = G_VALUE_INIT;
|
||||
|
||||
kona_image_meta meta;
|
||||
ki = kona_image_new();
|
||||
g_value_init(&val, G_TYPE_POINTER);
|
||||
@ -60,7 +65,14 @@ int buildWindow() {
|
||||
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;
|
||||
|
||||
@ -70,6 +82,10 @@ int buildWindow() {
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -1,23 +1,30 @@
|
||||
#include "previewwidget.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE(PreviewWidget, PreviewWidget, GTK_TYPE_BIN)
|
||||
|
||||
|
||||
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) {
|
||||
GtkWidget *spinner;
|
||||
GtkWidget *w;
|
||||
GList *widgets;
|
||||
|
||||
widgets = gtk_container_get_children(GTK_CONTAINER(widget));
|
||||
spinner = widgets->data;
|
||||
gtk_widget_set_visible(spinner, TRUE);
|
||||
w = widgets->data; // Grab GtkImage
|
||||
|
||||
spinner = g_list_next(widgets)->data;
|
||||
gtk_widget_set_visible(spinner, FALSE);
|
||||
GdkPixbuf *p;
|
||||
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));
|
||||
}
|
||||
|
||||
GtkWidget *PreviewWidget_new()
|
||||
GtkWidget *PreviewWidget_new(KonaImage* ki)
|
||||
{
|
||||
return g_object_new (TYPE_PREVIEWWIDGET, NULL);
|
||||
}
|
||||
|
@ -2,9 +2,10 @@
|
||||
#define PREVIEWWIDGET_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "konaimage.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define TYPE_PREVIEWWIDGET (PreviewWidget_get_type ())
|
||||
@ -25,7 +26,7 @@ struct _PreviewWidgetClass {
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "konaimage.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
guint64 test;
|
||||
@ -7,18 +8,18 @@ typedef struct {
|
||||
|
||||
struct _KonaImage {
|
||||
GObject parent_instance; // struct of parent (inherit)
|
||||
guint64 id;
|
||||
GList *tags;
|
||||
GString *url;
|
||||
kona_image_meta meta;
|
||||
GString* preview_url;
|
||||
GString* full_url;
|
||||
};
|
||||
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(KonaImage, kona_image, G_TYPE_OBJECT)
|
||||
|
||||
enum {
|
||||
PROP_ID = 1,
|
||||
PROP_TAGS,
|
||||
PROP_URL,
|
||||
PROP_META=1,
|
||||
PROP_FILE_PREVIEW,
|
||||
PROP_FILE_FULL,
|
||||
PROP_COUNT
|
||||
};
|
||||
|
||||
@ -28,14 +29,15 @@ static void kona_image_get_property(GObject *object, guint prop_id, GValue *valu
|
||||
KonaImage *self = (KonaImage*)object;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ID:
|
||||
g_value_set_uint64(value, *kona_image_get_id(self));
|
||||
case PROP_FILE_PREVIEW:
|
||||
g_value_set_string(value, (const gchar*) self->preview_url);
|
||||
break;
|
||||
case PROP_TAGS:
|
||||
g_value_set_gtype(value, (GType) self->tags); // Returning the pointer itself may be dangerous... Rather copy it to the target value?
|
||||
case PROP_FILE_FULL:
|
||||
g_value_set_string(value, (const gchar*) self->full_url);
|
||||
break;
|
||||
case PROP_META:
|
||||
g_value_set_pointer(value, &self->meta);
|
||||
break;
|
||||
case PROP_URL:
|
||||
g_value_set_string(value, (const gchar*) self->url);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -45,16 +47,16 @@ static void kona_image_set_property(GObject *object, guint prop_id, const GValue
|
||||
KonaImage *self = (KonaImage*)object;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ID:
|
||||
kona_image_set_id(self, g_value_get_uint64(value));
|
||||
case PROP_FILE_FULL:
|
||||
g_free(self->full_url);
|
||||
self->full_url = (GString*) g_strdup(g_value_get_string(value));
|
||||
break;
|
||||
case PROP_TAGS:
|
||||
g_list_free(self->tags);
|
||||
self->tags = g_list_copy((GList*) g_value_get_gtype(value));
|
||||
case PROP_FILE_PREVIEW:
|
||||
g_free(self->preview_url);
|
||||
self->preview_url = (GString*) g_strdup(g_value_get_string(value));
|
||||
break;
|
||||
case PROP_URL:
|
||||
g_free(self->url);
|
||||
self->url = (GString*) g_strdup(g_value_get_string(value));
|
||||
case PROP_META:
|
||||
memcpy(&self->meta, g_value_get_pointer(value), sizeof(kona_image_meta));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -67,14 +69,14 @@ static void kona_image_class_init(KonaImageClass *klass) {
|
||||
object_class->set_property = kona_image_set_property;
|
||||
object_class->get_property = kona_image_get_property;
|
||||
|
||||
properties [PROP_ID] =
|
||||
g_param_spec_uint64("id", "id", "The ID of the image.", 0, G_MAXINT64, 22, G_PARAM_READWRITE);
|
||||
properties [PROP_META] =
|
||||
g_param_spec_pointer("meta", "meta", "Meta info struct", G_PARAM_READWRITE);
|
||||
|
||||
properties [PROP_TAGS] =
|
||||
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?
|
||||
properties [PROP_FILE_FULL] =
|
||||
g_param_spec_string("fullFile", "fullFile", "Local URL to the file", "", G_PARAM_READWRITE);
|
||||
|
||||
properties [PROP_URL] =
|
||||
g_param_spec_string("url", "url", "The URL to the full picture.", "", G_PARAM_READWRITE);
|
||||
properties [PROP_FILE_PREVIEW] =
|
||||
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);
|
||||
}
|
||||
@ -90,20 +92,12 @@ static void kona_image_dispose(KonaImage *self) {
|
||||
|
||||
static void kona_image_finalize(KonaImage *self) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -11,8 +11,15 @@ G_DECLARE_FINAL_TYPE (KonaImage, kona_image, KONA, IMAGE, GObject) // Struct nam
|
||||
|
||||
KonaImage *kona_image_new (void);
|
||||
|
||||
const guint64 *kona_image_get_id(KonaImage *self);
|
||||
void kona_image_set_id(KonaImage *self, const guint64 id);
|
||||
struct kona_image_meta_struct {
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user