1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
#include <string.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkexpander.h>
#include <gtk/gtksizegroup.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkscrolledwindow.h>
#include "config.h"
#include "support/thread.h"
#include "stpui_widgets/dimension.h"
#include "imagesource/imagesource_util.h"
#include "pp_imageinfo.h"
#include "gettext.h"
#define _(x) gettext(x)
enum {
CHANGED_SIGNAL,
LAST_SIGNAL
};
static guint pp_imageinfo_signals[LAST_SIGNAL] = { 0 };
static void pp_imageinfo_class_init (pp_ImageInfoClass *klass);
static void pp_imageinfo_init (pp_ImageInfo *stpuicombo);
void pp_imageinfo_refresh(pp_ImageInfo *ob)
{
}
static void killshadow(GtkWidget *wid,gpointer data)
{
gtk_viewport_set_shadow_type(GTK_VIEWPORT(wid),GTK_SHADOW_NONE);
}
GtkWidget*
pp_imageinfo_new ()
{
pp_ImageInfo *ob=PP_IMAGEINFO(g_object_new (pp_imageinfo_get_type (), NULL));
// gtk_box_set_spacing(GTK_BOX(ob),5);
GtkWidget *label;
// GtkWidget *frame;
// Layout frame
gtk_expander_set_label(GTK_EXPANDER(ob),_("Image Info"));
gtk_expander_set_spacing(GTK_EXPANDER(ob),5);
gtk_expander_set_expanded(GTK_EXPANDER(ob),true);
// gtk_box_pack_start(GTK_BOX(ob),frame,FALSE,FALSE,0);
// gtk_widget_show(frame);
ob->scrollwin=gtk_scrolled_window_new(NULL,NULL);
gtk_widget_show(ob->scrollwin);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ob->scrollwin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
gtk_container_add(GTK_CONTAINER(ob),ob->scrollwin);
ob->table=gtk_table_new(2,3,false);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (ob->scrollwin), ob->table);
gtk_container_foreach(GTK_CONTAINER(ob->scrollwin),killshadow,NULL);
gtk_table_set_col_spacings(GTK_TABLE(ob->table),8);
gtk_table_set_row_spacings(GTK_TABLE(ob->table),4);
label=gtk_label_new(_("Filename:"));
gtk_misc_set_alignment(GTK_MISC(label),1.0,0.5);
gtk_table_attach(GTK_TABLE(ob->table),GTK_WIDGET(label),0,1,0,1,
GtkAttachOptions(GTK_SHRINK|GTK_FILL),GtkAttachOptions(GTK_SHRINK|GTK_FILL),0,0);
gtk_widget_show(label);
ob->filename=gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(ob->filename),0.0,0.5);
gtk_widget_show(ob->filename);
gtk_table_attach_defaults(GTK_TABLE(ob->table),GTK_WIDGET(ob->filename),1,2,0,1);
label=gtk_label_new(_("Dimensions:"));
gtk_misc_set_alignment(GTK_MISC(label),1.0,0.5);
gtk_table_attach(GTK_TABLE(ob->table),GTK_WIDGET(label),0,1,1,2,
GtkAttachOptions(GTK_SHRINK|GTK_FILL),GtkAttachOptions(GTK_SHRINK|GTK_FILL),0,0);
gtk_widget_show(label);
ob->dimensions=gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(ob->dimensions),0.0,0.5);
gtk_widget_show(ob->dimensions);
gtk_table_attach_defaults(GTK_TABLE(ob->table),GTK_WIDGET(ob->dimensions),1,2,1,2);
label=gtk_label_new(_("Profile:"));
gtk_misc_set_alignment(GTK_MISC(label),1.0,0.5);
gtk_table_attach(GTK_TABLE(ob->table),GTK_WIDGET(label),0,1,2,3,
GtkAttachOptions(GTK_SHRINK|GTK_FILL),GtkAttachOptions(GTK_SHRINK|GTK_FILL),0,0);
gtk_widget_show(label);
ob->profile=gtk_label_new("");
gtk_label_set_line_wrap(GTK_LABEL(ob->profile),true);
gtk_misc_set_alignment(GTK_MISC(ob->profile),0.0,0.5);
gtk_widget_show(ob->profile);
gtk_table_attach_defaults(GTK_TABLE(ob->table),GTK_WIDGET(ob->profile),1,2,2,3);
gtk_widget_show(ob->table);
pp_imageinfo_set_image(ob,NULL);
return(GTK_WIDGET(ob));
}
GType
pp_imageinfo_get_type (void)
{
static GType stpuic_type = 0;
if (!stpuic_type)
{
static const GTypeInfo pp_imageinfo_info =
{
sizeof (pp_ImageInfoClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) pp_imageinfo_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (pp_ImageInfo),
0,
(GInstanceInitFunc) pp_imageinfo_init,
};
stpuic_type = g_type_register_static (GTK_TYPE_EXPANDER, "pp_ImageInfo", &pp_imageinfo_info, (GTypeFlags)0);
}
return stpuic_type;
}
static void
pp_imageinfo_class_init (pp_ImageInfoClass *klass)
{
pp_imageinfo_signals[CHANGED_SIGNAL] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (klass),
GSignalFlags(G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (pp_ImageInfoClass, changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}
static void
pp_imageinfo_init (pp_ImageInfo *ob)
{
ob->table=NULL;
ob->filename=NULL;
ob->dimensions=NULL;
ob->profile=NULL;
ob->scrollwin=NULL;
ob->thread=NULL;
}
class ii_payload
{
public:
ii_payload(const char *fn,pp_ImageInfo *ob,Layout_ImageInfo *ii)
: filename(NULL), dimensions(NULL), proffilename(NULL), profname(NULL), imageinfo(NULL)
{
filename=strdup(fn);
imageinfo=ob;
const char *tmp;
if((tmp=ii->GetAssignedProfile()))
proffilename=strdup(tmp);
}
~ii_payload()
{
if(filename)
free(filename);
if(proffilename)
free(proffilename);
if(profname)
free(profname);
if(dimensions)
g_free(dimensions);
}
void GetInfo()
{
}
static int ThreadFunc(Thread *t,void *ud)
{
t->SendSync();
ii_payload *p=(ii_payload *)ud;
ImageSource *is=ISLoadImage(p->filename);
if(is)
{
p->dimensions=g_strdup_printf("%d x %d %s",is->width,is->height,_("pixels"));
// Embedded/Assigned Profile
CMSProfile *prof=NULL;
if(p->proffilename)
prof=new CMSProfile(p->proffilename);
if(!prof)
prof=is->GetEmbeddedProfile();
if(prof)
{
const char *desc=prof->GetDescription();
p->profname=strdup(desc);
if(p->proffilename) // Only delete the profile if we created it from a filename
delete prof;
}
delete is;
}
g_idle_add(ii_payload::IdleFunc,p);
return(0);
}
static gboolean IdleFunc(gpointer ud)
{
ii_payload *p=(ii_payload *)ud;
pp_ImageInfo *ii=p->imageinfo;
if(p->dimensions)
gtk_label_set_label(GTK_LABEL(ii->dimensions),p->dimensions);
if(p->profname)
gtk_label_set_text(GTK_LABEL(ii->profile),p->profname);
else
gtk_label_set_text(GTK_LABEL(ii->profile),_("Default"));
delete p;
return(FALSE);
}
protected:
char *filename;
char *dimensions;
char *proffilename;
char *profname;
pp_ImageInfo *imageinfo;
};
void pp_imageinfo_set_image(pp_ImageInfo *ob,Layout_ImageInfo *ii)
{
if(ii)
{
// Remove path leaving just the file part of the filename,
// and convert to UTF8 for display.
const char *fn=ii->GetFilename();
gchar *fnb=g_path_get_basename(fn);
gsize bread=0,bwritten=0;
GError *err;
gchar *fnu=g_filename_to_utf8(fnb,-1,&bread,&bwritten,&err);
if(fnu)
gtk_label_set_label(GTK_LABEL(ob->filename),fnu);
if(fnu)
g_free(fnu);
g_free(fnb);
if(ob->thread) // Deleting the old thread has the added bonus of ensuring that
delete ob->thread; // any previous iteration has completed.
ii_payload *p=new ii_payload(fn,ob,ii);
ob->thread=new Thread(ii_payload::ThreadFunc,p);
ob->thread->Start();
ob->thread->WaitSync();
#if 0
// Dimensions
ImageSource *is=ISLoadImage(fn);
if(is)
{
gchar *dim=g_strdup_printf("%d x %d %s",is->width,is->height,_("pixels"));
gtk_label_set_label(GTK_LABEL(ob->dimensions),dim);
g_free(dim);
// Embedded/Assigned Profile
CMSProfile *prof=NULL;
fn=ii->GetAssignedProfile();
if(fn)
prof=new CMSProfile(fn);
if(!prof)
prof=is->GetEmbeddedProfile();
if(prof)
{
const char *desc=prof->GetDescription();
gtk_label_set_text(GTK_LABEL(ob->profile),desc);
if(fn) // Only delete the profile if we created it from a filename
delete prof;
}
else
gtk_label_set_text(GTK_LABEL(ob->profile),"Default");
delete is;
}
#endif
gtk_widget_set_sensitive(GTK_WIDGET(ob->scrollwin),true);
}
else
{
gtk_label_set_text(GTK_LABEL(ob->filename),"");
gtk_label_set_text(GTK_LABEL(ob->dimensions),"");
gtk_label_set_text(GTK_LABEL(ob->profile),"");
gtk_widget_set_sensitive(GTK_WIDGET(ob->scrollwin),false);
}
}
|