comparison src/bar.c @ 1484:9c16a93a0fdf

improved sidebar configuration
author nadvornik
date Sun, 29 Mar 2009 14:20:44 +0000
parents 65a5c27823c2
children 7216f4a45698
comparison
equal deleted inserted replaced
1483:7cb24fdf07c0 1484:9c16a93a0fdf
34 struct _KnownPanes 34 struct _KnownPanes
35 { 35 {
36 PaneType type; 36 PaneType type;
37 gchar *id; 37 gchar *id;
38 gchar *title; 38 gchar *title;
39 const gchar *config;
39 }; 40 };
41
42 static const gchar default_config_histogram[] =
43 "<gq>"
44 " <layout id = '_current_'>"
45 " <bar>"
46 " <pane_histogram id = 'histogram' expanded = 'true' histogram_channel = '4' histogram_mode = '0' />"
47 " </bar>"
48 " </layout>"
49 "</gq>";
50
51 static const gchar default_config_title[] =
52 "<gq>"
53 " <layout id = '_current_'>"
54 " <bar>"
55 " <pane_comment id = 'title' expanded = 'true' key = 'Xmp.dc.title' height = '40' />"
56 " </bar>"
57 " </layout>"
58 "</gq>";
59
60 static const gchar default_config_keywords[] =
61 "<gq>"
62 " <layout id = '_current_'>"
63 " <bar>"
64 " <pane_keywords id = 'keywords' expanded = 'true' key = '" KEYWORD_KEY "' />"
65 " </bar>"
66 " </layout>"
67 "</gq>";
68
69 static const gchar default_config_comment[] =
70 "<gq>"
71 " <layout id = '_current_'>"
72 " <bar>"
73 " <pane_comment id = 'comment' expanded = 'true' key = '" COMMENT_KEY "' height = '150' />"
74 " </bar>"
75 " </layout>"
76 "</gq>";
77
78 static const gchar default_config_exif[] =
79 "<gq>"
80 " <layout id = '_current_'>"
81 " <bar>"
82 " <pane_exif id = 'exif' expanded = 'true' >"
83 " <entry key = 'formatted.Camera' if_set = 'true' editable = 'false' />"
84 " <entry key = 'formatted.DateTime' if_set = 'true' editable = 'false' />"
85 " <entry key = 'formatted.ShutterSpeed' if_set = 'true' editable = 'false' />"
86 " <entry key = 'formatted.Aperture' if_set = 'true' editable = 'false' />"
87 " <entry key = 'formatted.ExposureBias' if_set = 'true' editable = 'false' />"
88 " <entry key = 'formatted.ISOSpeedRating' if_set = 'true' editable = 'false' />"
89 " <entry key = 'formatted.FocalLength' if_set = 'true' editable = 'false' />"
90 " <entry key = 'formatted.FocalLength35mmFilm' if_set = 'true' editable = 'false' />"
91 " <entry key = 'formatted.Flash' if_set = 'true' editable = 'false' />"
92 " <entry key = 'Exif.Photo.ExposureProgram' if_set = 'true' editable = 'false' />"
93 " <entry key = 'Exif.Photo.MeteringMode' if_set = 'true' editable = 'false' />"
94 " <entry key = 'Exif.Photo.LightSource' if_set = 'true' editable = 'false' />"
95 " <entry key = 'formatted.ColorProfile' if_set = 'true' editable = 'false' />"
96 " <entry key = 'formatted.SubjectDistance' if_set = 'true' editable = 'false' />"
97 " <entry key = 'formatted.Resolution' if_set = 'true' editable = 'false' />"
98 " <entry key = 'Exif.Image.Orientation' if_set = 'true' editable = 'false' />"
99 " </pane_exif>"
100 " </bar>"
101 " </layout>"
102 "</gq>";
103
104 static const gchar default_config_file_info[] =
105 "<gq>"
106 " <layout id = '_current_'>"
107 " <bar>"
108 " <pane_exif id = 'file_info' expanded = 'true' >"
109 " <entry key = 'file.mode' if_set = 'false' editable = 'false' />"
110 " <entry key = 'file.date' if_set = 'false' editable = 'false' />"
111 " <entry key = 'file.size' if_set = 'false' editable = 'false' />"
112 " </pane_exif>"
113 " </bar>"
114 " </layout>"
115 "</gq>";
116
117 static const gchar default_config_location[] =
118 "<gq>"
119 " <layout id = '_current_'>"
120 " <bar>"
121 " <pane_exif id = 'location' expanded = 'true' >"
122 " <entry key = 'formatted.GPSPosition' if_set = 'true' editable = 'false' />"
123 " <entry key = 'formatted.GPSAltitude' if_set = 'true' editable = 'false' />"
124 " <entry key = 'Xmp.photoshop.Country' if_set = 'false' editable = 'true' />"
125 " <entry key = 'Xmp.iptc.CountryCode' if_set = 'false' editable = 'true' />"
126 " <entry key = 'Xmp.photoshop.State' if_set = 'false' editable = 'true' />"
127 " <entry key = 'Xmp.photoshop.City' if_set = 'false' editable = 'true' />"
128 " <entry key = 'Xmp.iptc.Location' if_set = 'false' editable = 'true' />"
129 " </pane_exif>"
130 " </bar>"
131 " </layout>"
132 "</gq>";
133
134 static const gchar default_config_copyright[] =
135 "<gq>"
136 " <layout id = '_current_'>"
137 " <bar>"
138 " <pane_exif id = 'copyright' expanded = 'true' >"
139 " <entry key = 'Xmp.dc.creator' if_set = 'true' editable = 'false' />"
140 " <entry key = 'Xmp.dc.contributor' if_set = 'true' editable = 'false' />"
141 " <entry key = 'Xmp.dc.rights' if_set = 'false' editable = 'false' />"
142 " </pane_exif>"
143 " </bar>"
144 " </layout>"
145 "</gq>";
40 146
41 static const KnownPanes known_panes[] = { 147 static const KnownPanes known_panes[] = {
42 /* default sidebar */ 148 /* default sidebar */
43 {PANE_HISTOGRAM, "histogram", N_("Histogram")}, 149 {PANE_HISTOGRAM, "histogram", N_("Histogram"), default_config_histogram},
44 {PANE_COMMENT, "title", N_("Title")}, 150 {PANE_COMMENT, "title", N_("Title"), default_config_title},
45 {PANE_KEYWORDS, "keywords", N_("Keywords")}, 151 {PANE_KEYWORDS, "keywords", N_("Keywords"), default_config_keywords},
46 {PANE_COMMENT, "comment", N_("Comment")}, 152 {PANE_COMMENT, "comment", N_("Comment"), default_config_comment},
47 {PANE_EXIF, "exif", N_("Exif")}, 153 {PANE_EXIF, "exif", N_("Exif"), default_config_exif},
48 154 /* other pre-configured panes */
49 {PANE_UNDEF, NULL, NULL} 155 {PANE_EXIF, "file_info", N_("File info"), default_config_file_info},
156 {PANE_EXIF, "location", N_("Location"), default_config_location},
157 {PANE_EXIF, "copyright", N_("Copyright"), default_config_copyright},
158
159 {PANE_UNDEF, NULL, NULL, NULL}
50 }; 160 };
51 161
52 typedef struct _BarData BarData; 162 typedef struct _BarData BarData;
53 struct _BarData 163 struct _BarData
54 { 164 {
59 169
60 LayoutWindow *lw; 170 LayoutWindow *lw;
61 gint width; 171 gint width;
62 }; 172 };
63 173
64 static void bar_expander_move(GtkWidget *widget, gpointer data, gboolean up) 174 static void bar_expander_move(GtkWidget *widget, gpointer data, gboolean up, gboolean single_step)
65 { 175 {
66 GtkWidget *expander = data; 176 GtkWidget *expander = data;
67 GtkWidget *box; 177 GtkWidget *box;
68 gint pos; 178 gint pos;
69 179
71 box = gtk_widget_get_ancestor(expander, GTK_TYPE_BOX); 181 box = gtk_widget_get_ancestor(expander, GTK_TYPE_BOX);
72 if (!box) return; 182 if (!box) return;
73 183
74 gtk_container_child_get(GTK_CONTAINER(box), expander, "position", &pos, NULL); 184 gtk_container_child_get(GTK_CONTAINER(box), expander, "position", &pos, NULL);
75 185
76 pos = up ? (pos - 1) : (pos + 1); 186 if (single_step)
77 if (pos < 0) pos = 0; 187 {
188 pos = up ? (pos - 1) : (pos + 1);
189 if (pos < 0) pos = 0;
190 }
191 else
192 {
193 pos = up ? 0 : -1;
194 }
78 195
79 gtk_box_reorder_child(GTK_BOX(box), expander, pos); 196 gtk_box_reorder_child(GTK_BOX(box), expander, pos);
80 } 197 }
81 198
82 199
83 static void bar_expander_move_up_cb(GtkWidget *widget, gpointer data) 200 static void bar_expander_move_up_cb(GtkWidget *widget, gpointer data)
84 { 201 {
85 bar_expander_move(widget, data, TRUE); 202 bar_expander_move(widget, data, TRUE, TRUE);
86 } 203 }
87 204
88 static void bar_expander_move_down_cb(GtkWidget *widget, gpointer data) 205 static void bar_expander_move_down_cb(GtkWidget *widget, gpointer data)
89 { 206 {
90 bar_expander_move(widget, data, FALSE); 207 bar_expander_move(widget, data, FALSE, TRUE);
91 } 208 }
92 209
93 210 static void bar_expander_move_top_cb(GtkWidget *widget, gpointer data)
94 static void bar_expander_menu_popup(GtkWidget *data) 211 {
212 bar_expander_move(widget, data, TRUE, FALSE);
213 }
214
215 static void bar_expander_move_bottom_cb(GtkWidget *widget, gpointer data)
216 {
217 bar_expander_move(widget, data, FALSE, FALSE);
218 }
219
220 static void bar_expander_delete_cb(GtkWidget *widget, gpointer data)
221 {
222 GtkWidget *expander = data;
223 gtk_widget_destroy(expander);
224 }
225
226 static void bar_expander_add_cb(GtkWidget *widget, gpointer data)
227 {
228 //GtkWidget *bar = data;
229 const KnownPanes *pane = known_panes;
230 const gchar *id = g_object_get_data(G_OBJECT(widget), "pane_add_id");
231 const gchar *config;
232
233 if (!id) return;
234
235 while (pane->id)
236 {
237 if (strcmp(pane->id, id) == 0) break;
238 pane++;
239 }
240 if (!pane->id) return;
241
242 config = bar_pane_get_default_config(id);
243 if (config) load_config_from_buf(config, strlen(config), FALSE);
244
245 }
246
247
248 static void bar_menu_popup(GtkWidget *widget)
95 { 249 {
96 GtkWidget *menu; 250 GtkWidget *menu;
97 251 GtkWidget *bar;
252 GtkWidget *expander;
253 const KnownPanes *pane = known_panes;
254 BarData *bd;
255
256 bd = g_object_get_data(G_OBJECT(widget), "bar_data");
257 if (bd)
258 {
259 expander = NULL;
260 bar = widget;
261 }
262 else
263 {
264 expander = widget;
265 bar = widget->parent;
266 while (bar && !g_object_get_data(G_OBJECT(bar), "bar_data"))
267 bar = bar->parent;
268 if (!bar) return;
269 }
270
98 menu = popup_menu_short_lived(); 271 menu = popup_menu_short_lived();
99 272
100 menu_item_add_stock(menu, _("Move _up"), GTK_STOCK_GO_UP, G_CALLBACK(bar_expander_move_up_cb), data); 273 if (expander)
101 menu_item_add_stock(menu, _("Move _down"), GTK_STOCK_GO_DOWN, G_CALLBACK(bar_expander_move_down_cb), data); 274 {
102 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, data, 0, GDK_CURRENT_TIME); 275 menu_item_add_stock(menu, _("Move to _top"), GTK_STOCK_GOTO_TOP, G_CALLBACK(bar_expander_move_top_cb), expander);
103 } 276 menu_item_add_stock(menu, _("Move _up"), GTK_STOCK_GO_UP, G_CALLBACK(bar_expander_move_up_cb), expander);
104 277 menu_item_add_stock(menu, _("Move _down"), GTK_STOCK_GO_DOWN, G_CALLBACK(bar_expander_move_down_cb), expander);
105 278 menu_item_add_stock(menu, _("Move to _bottom"), GTK_STOCK_GOTO_BOTTOM, G_CALLBACK(bar_expander_move_bottom_cb), expander);
106 static gboolean bar_expander_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) 279 menu_item_add_divider(menu);
280 menu_item_add_stock(menu, _("Delete"), GTK_STOCK_DELETE, G_CALLBACK(bar_expander_delete_cb), expander);
281 menu_item_add_divider(menu);
282 }
283
284 while (pane->id)
285 {
286 GtkWidget *item;
287 item = menu_item_add_stock(menu, _(pane->title), GTK_STOCK_ADD, G_CALLBACK(bar_expander_add_cb), bar);
288 g_object_set_data(G_OBJECT(item), "pane_add_id", pane->id);
289 pane++;
290 }
291
292 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, bar, 0, GDK_CURRENT_TIME);
293 }
294
295
296 static gboolean bar_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
107 { 297 {
108 if (bevent->button == MOUSE_BUTTON_RIGHT) 298 if (bevent->button == MOUSE_BUTTON_RIGHT)
109 { 299 {
110 bar_expander_menu_popup(widget); 300 bar_menu_popup(widget);
111 return TRUE; 301 return TRUE;
112 } 302 }
113 return FALSE; 303 return FALSE;
114 } 304 }
115 305
286 gtk_widget_show(pd->title); 476 gtk_widget_show(pd->title);
287 } 477 }
288 478
289 gtk_box_pack_start(GTK_BOX(bd->vbox), expander, FALSE, TRUE, 0); 479 gtk_box_pack_start(GTK_BOX(bd->vbox), expander, FALSE, TRUE, 0);
290 480
291 g_signal_connect(expander, "button_press_event", G_CALLBACK(bar_expander_menu_cb), bd); 481 g_signal_connect(expander, "button_press_event", G_CALLBACK(bar_menu_cb), bd);
292 482
293 gtk_container_add(GTK_CONTAINER(expander), pane); 483 gtk_container_add(GTK_CONTAINER(expander), pane);
294 484
295 gtk_expander_set_expanded(GTK_EXPANDER(expander), pd->expanded); 485 gtk_expander_set_expanded(GTK_EXPANDER(expander), pd->expanded);
296 486
298 488
299 if (bd->fd && pd && pd->pane_set_fd) pd->pane_set_fd(pane, bd->fd); 489 if (bd->fd && pd && pd->pane_set_fd) pd->pane_set_fd(pane, bd->fd);
300 490
301 } 491 }
302 492
303 static void bar_populate_default(GtkWidget *bar) 493 void bar_populate_default(GtkWidget *bar)
304 { 494 {
305 GtkWidget *widget; 495 const gchar *populate_id[] = {"histogram", "title", "keywords", "comment", "exif", NULL};
306 496 const gchar **id = populate_id;
307 widget = bar_pane_histogram_new("histogram", _("Histogram"), 80, TRUE, HCHAN_RGB, 0); 497
308 bar_add(bar, widget); 498 while (*id)
309 499 {
310 widget = bar_pane_comment_new("title", _("Title"), "Xmp.dc.title", TRUE, 40); 500 const gchar *config = bar_pane_get_default_config(*id);
311 bar_add(bar, widget); 501 if (config) load_config_from_buf(config, strlen(config), FALSE);
312 502 id++;
313 widget = bar_pane_keywords_new("keywords", _("Keywords"), KEYWORD_KEY, TRUE); 503 }
314 bar_add(bar, widget);
315
316 widget = bar_pane_comment_new("comment", _("Comment"), "Xmp.dc.description", TRUE, 150);
317 bar_add(bar, widget);
318
319 widget = bar_pane_exif_new("exif", _("Exif"), TRUE, TRUE);
320 bar_add(bar, widget);
321 } 504 }
322 505
323 static void bar_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer data) 506 static void bar_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
324 { 507 {
325 BarData *bd = data; 508 BarData *bd = data;
370 g_signal_connect(G_OBJECT(bd->widget), "destroy", 553 g_signal_connect(G_OBJECT(bd->widget), "destroy",
371 G_CALLBACK(bar_destroy), bd); 554 G_CALLBACK(bar_destroy), bd);
372 555
373 g_signal_connect(G_OBJECT(bd->widget), "size-allocate", 556 g_signal_connect(G_OBJECT(bd->widget), "size-allocate",
374 G_CALLBACK(bar_size_allocate), bd); 557 G_CALLBACK(bar_size_allocate), bd);
558
559 g_signal_connect(G_OBJECT(bd->widget), "button_press_event", G_CALLBACK(bar_menu_cb), bd);
375 560
376 bd->width = SIDEBAR_DEFAULT_WIDTH; 561 bd->width = SIDEBAR_DEFAULT_WIDTH;
377 gtk_widget_set_size_request(bd->widget, bd->width, -1); 562 gtk_widget_set_size_request(bd->widget, bd->width, -1);
378 563
379 box = gtk_hbox_new(FALSE, 0); 564 box = gtk_hbox_new(FALSE, 0);
402 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_NONE); 587 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_NONE);
403 gtk_widget_show(bd->vbox); 588 gtk_widget_show(bd->vbox);
404 return bd->widget; 589 return bd->widget;
405 } 590 }
406 591
407 GtkWidget *bar_new_default(LayoutWindow *lw)
408 {
409 GtkWidget *bar = bar_new(lw);
410
411 bar_populate_default(bar);
412
413 gtk_widget_show(bar);
414
415 return bar;
416 }
417 592
418 GtkWidget *bar_update_from_config(GtkWidget *bar, const gchar **attribute_names, const gchar **attribute_values) 593 GtkWidget *bar_update_from_config(GtkWidget *bar, const gchar **attribute_names, const gchar **attribute_values)
419 { 594 {
420 gboolean enabled = TRUE; 595 gboolean enabled = TRUE;
421 gint width = SIDEBAR_DEFAULT_WIDTH; 596 gint width = SIDEBAR_DEFAULT_WIDTH;
476 651
477 g_free(*title); 652 g_free(*title);
478 *title = g_strdup(_(pane->title)); 653 *title = g_strdup(_(pane->title));
479 return TRUE; 654 return TRUE;
480 } 655 }
656
657 const gchar *bar_pane_get_default_config(const gchar *id)
658 {
659 const KnownPanes *pane = known_panes;
660
661 while (pane->id)
662 {
663 if (strcmp(pane->id, id) == 0) break;
664 pane++;
665 }
666 if (!pane->id) return NULL;
667 return pane->config;
668 }
481 669
482 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ 670 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */