1 /* gtk-exif-entry-generic.c
2  *
3  * Copyright © 2001 Lutz Müller <lutz@users.sourceforge.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #include "config.h"
22 #include "gtk-exif-entry-generic.h"
23 #include "gtk-exif-util.h"
24 
25 #include <string.h>
26 #include <gtk/gtk.h>
27 
28 #ifdef ENABLE_NLS
29 #  include <libintl.h>
30 #  undef _
31 #  define _(String) dgettext (GETTEXT_PACKAGE, String)
32 #  ifdef gettext_noop
33 #    define N_(String) gettext_noop (String)
34 #  else
35 #    define N_(String) (String)
36 #  endif
37 #else
38 #  define textdomain(String) (String)
39 #  define gettext(String) (String)
40 #  define dgettext(Domain,Message) (Message)
41 #  define dcgettext(Domain,Message,Type) (Message)
42 #  define bindtextdomain(Domain,Directory) (Domain)
43 #  define _(String) (String)
44 #  define N_(String) (String)
45 #endif
46 
47 struct _GtkExifEntryGenericPrivate {
48 	ExifEntry *entry;
49 
50 	GtkToggleButton *c;
51 	GtkToggleButton *r1, *r2, *r3;
52 };
53 
54 #define PARENT_TYPE GTK_EXIF_TYPE_ENTRY
55 static GtkExifEntryClass *parent_class;
56 
57 static void
58 #if GTK_CHECK_VERSION(3,0,0)
gtk_exif_entry_generic_destroy(GtkWidget * widget)59 gtk_exif_entry_generic_destroy (GtkWidget *widget)
60 #else
61 gtk_exif_entry_generic_destroy (GtkObject *object)
62 #endif
63 {
64 #if GTK_CHECK_VERSION(3,0,0)
65 	GtkExifEntryGeneric *entry = GTK_EXIF_ENTRY_GENERIC (widget);
66 #else
67 	GtkExifEntryGeneric *entry = GTK_EXIF_ENTRY_GENERIC (object);
68 #endif
69 
70 	if (entry->priv->entry) {
71 		exif_entry_unref (entry->priv->entry);
72 		entry->priv->entry = NULL;
73 	}
74 
75 #if GTK_CHECK_VERSION(3,0,0)
76 	GTK_WIDGET_CLASS (parent_class)->destroy (widget);
77 #else
78 	GTK_OBJECT_CLASS (parent_class)->destroy (object);
79 #endif
80 }
81 
GTK_EXIF_FINALIZE(entry_generic,EntryGeneric)82 GTK_EXIF_FINALIZE (entry_generic, EntryGeneric)
83 
84 static void
85 gtk_exif_entry_generic_class_init (gpointer g_class, gpointer class_data G_GNUC_UNUSED)
86 {
87 #if GTK_CHECK_VERSION(3,0,0)
88 	GtkWidgetClass *widget_class;
89 	GObjectClass *gobject_class;
90 
91 	widget_class = GTK_WIDGET_CLASS (g_class);
92 	widget_class->destroy = gtk_exif_entry_generic_destroy;
93 #else
94 	GtkObjectClass *object_class;
95 	GObjectClass *gobject_class;
96 
97 	object_class = GTK_OBJECT_CLASS (g_class);
98 	object_class->destroy  = gtk_exif_entry_generic_destroy;
99 #endif
100 
101 	gobject_class = G_OBJECT_CLASS (g_class);
102 	gobject_class->finalize = gtk_exif_entry_generic_finalize;
103 
104 	parent_class = g_type_class_peek_parent (g_class);
105 }
106 
107 static void
gtk_exif_entry_generic_init(GTypeInstance * instance,gpointer g_class G_GNUC_UNUSED)108 gtk_exif_entry_generic_init (GTypeInstance *instance, gpointer g_class G_GNUC_UNUSED)
109 {
110 	GtkExifEntryGeneric *entry = GTK_EXIF_ENTRY_GENERIC (instance);
111 
112 	entry->priv = g_new0 (GtkExifEntryGenericPrivate, 1);
113 }
114 
115 GTK_EXIF_CLASS (entry_generic, EntryGeneric, "EntryGeneric")
116 
117 GtkWidget *
gtk_exif_entry_generic_new(ExifEntry * e)118 gtk_exif_entry_generic_new (ExifEntry *e)
119 {
120 	GtkExifEntryGeneric *entry;
121 	GtkWidget *table, *label;
122 	gchar *txt, s[1024];
123 
124 	g_return_val_if_fail (e != NULL, NULL);
125 
126 	entry = g_object_new (GTK_EXIF_TYPE_ENTRY_GENERIC, NULL);
127 	entry->priv->entry = e;
128 	exif_entry_ref (e);
129 	gtk_exif_entry_construct (GTK_EXIF_ENTRY (entry),
130 		exif_tag_get_title_in_ifd (e->tag, exif_content_get_ifd(e->parent)),
131 		exif_tag_get_description_in_ifd (e->tag, exif_content_get_ifd(e->parent)));
132 
133 	table = gtk_table_new (2, 4, FALSE);
134 	gtk_widget_show (table);
135 	gtk_box_pack_start (GTK_BOX (entry), table, TRUE, TRUE, 0);
136 	gtk_table_set_col_spacings (GTK_TABLE (table), 5);
137 	gtk_table_set_row_spacings (GTK_TABLE (table), 5);
138 
139 	label = gtk_label_new (_("Format:"));
140 	gtk_widget_show (label);
141 	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, 0, 0, 0, 0);
142 	txt = g_strdup_printf ("%i ('%s')", e->format,
143 			       exif_format_get_name (e->format));
144 	label = gtk_label_new (txt);
145 	g_free (txt);
146 	gtk_widget_show (label);
147 	gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, 0, 0, 0, 0);
148 
149 	label = gtk_label_new (_("Components:"));
150 	gtk_widget_show (label);
151 	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, 0, 0, 0, 0);
152 	txt = g_strdup_printf ("%i", (int) e->components);
153 	label = gtk_label_new (txt);
154 	g_free (txt);
155 	gtk_widget_show (label);
156 	gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, 0, 0, 0, 0);
157 
158 	label = gtk_label_new (_("Size:"));
159 	gtk_widget_show (label);
160 	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, 0, 0, 0, 0);
161 	txt = g_strdup_printf ("%i", e->size);
162 	label = gtk_label_new (txt);
163 	g_free (txt);
164 	gtk_widget_show (label);
165 	gtk_table_attach (GTK_TABLE (table), label, 1, 2, 2, 3, 0, 0, 0, 0);
166 
167 	label = gtk_label_new (_("Value:"));
168 	gtk_widget_show (label);
169 	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, 0, 0, 0, 0);
170 	label = gtk_label_new (exif_entry_get_value (e, s, sizeof (s)));
171 	gtk_widget_show (label);
172 	gtk_table_attach (GTK_TABLE (table), label, 1, 2, 3, 4, 0, 0, 0, 0);
173 
174 	return (GTK_WIDGET (entry));
175 }
176