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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Nautilus
*
* Copyright (C) 2000, 2001 Eazel, Inc.
*
* Nautilus is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Andy Hertzfeld <andy@eazel.com>
*/
/* This is the sidebar title widget, which is the title part of the sidebar. */
#include <config.h>
#include "nautilus-sidebar-title.h"
#include "nautilus-sidebar.h"
#include "nautilus-window.h"
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-property-bag-client.h>
#include <eel/eel-background.h>
#include <eel/eel-gdk-extensions.h>
#include <eel/eel-gdk-pixbuf-extensions.h>
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
#include <eel/eel-string.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkimage.h>
#include <gtk/gtklabel.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkwidget.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-types.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus-private/nautilus-file-attributes.h>
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-icon-factory.h>
#include <libnautilus-private/nautilus-metadata.h>
#include <libnautilus-private/nautilus-search-uri.h>
#include <libnautilus-private/nautilus-theme.h>
#include <math.h>
#include <string.h>
/* maximum allowable size to be displayed as the title */
#define MAX_TITLE_SIZE 256
#define MINIMUM_INFO_WIDTH 32
#define SIDEBAR_INFO_MARGIN 4
#define MORE_INFO_FONT_SIZE 12
#define MIN_TITLE_FONT_SIZE 12
#define MAX_TITLE_FONT_SIZE 20
#define TITLE_PADDING 4
static void nautilus_sidebar_title_class_init (NautilusSidebarTitleClass *klass);
static void nautilus_sidebar_title_destroy (GtkObject *object);
static void nautilus_sidebar_title_init (NautilusSidebarTitle *pixmap);
static void nautilus_sidebar_title_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void nautilus_sidebar_title_theme_changed (gpointer user_data);
static void update_icon (NautilusSidebarTitle *sidebar_title);
static GtkWidget * sidebar_title_create_title_label (void);
static GtkWidget * sidebar_title_create_more_info_label (void);
static void update_all (NautilusSidebarTitle *sidebar_title);
static void update_title_font (NautilusSidebarTitle *sidebar_title);
static EelBackground *nautilus_sidebar_title_background (NautilusSidebarTitle *sidebar_title);
static const char *non_smooth_font_name;
struct NautilusSidebarTitleDetails {
NautilusFile *file;
guint file_changed_connection;
char *title_text;
GtkWidget *icon;
GtkWidget *title_label;
GtkWidget *more_info_label;
GtkWidget *emblem_box;
GtkWidget *notes;
int shadow_offset;
gboolean determined_icon;
};
EEL_CLASS_BOILERPLATE (NautilusSidebarTitle, nautilus_sidebar_title, gtk_vbox_get_type ())
static void
nautilus_sidebar_title_class_init (NautilusSidebarTitleClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
object_class->destroy = nautilus_sidebar_title_destroy;
widget_class->size_allocate = nautilus_sidebar_title_size_allocate;
eel_preferences_add_auto_string (NAUTILUS_PREFERENCES_DEFAULT_FONT,
&non_smooth_font_name);
}
static void
appearance_changed_callback (EelBackground *background, NautilusSidebarTitle *sidebar_title)
{
nautilus_sidebar_title_select_text_color (sidebar_title);
}
static void
realize_callback (NautilusSidebarTitle *sidebar_title)
{
EelBackground *background;
background = nautilus_sidebar_title_background (sidebar_title);
g_return_if_fail (background != NULL);
gtk_signal_connect_while_alive (GTK_OBJECT (background),
"appearance_changed",
G_CALLBACK (appearance_changed_callback),
sidebar_title,
GTK_OBJECT (sidebar_title));
}
#if GNOME2_CONVERSION_COMPLETE
static GdkFont *
get_non_smooth_font (int font_size)
{
GdkFont *result;
result = nautilus_font_factory_get_font_by_family (non_smooth_font_name, font_size);
g_assert (result != NULL);
return result;
}
static void
non_smooth_font_changed_callback (gpointer callback_data)
{
NautilusSidebarTitle *sidebar_title;
GdkFont *new_font;
g_return_if_fail (NAUTILUS_IS_SIDEBAR_TITLE (callback_data));
sidebar_title = NAUTILUS_SIDEBAR_TITLE (callback_data);
/* Update the dynamically-sized title font */
update_title_font (sidebar_title);
/* Update the fixed-size "more info" font */
new_font = get_non_smooth_font (MORE_INFO_FONT_SIZE);
eel_gtk_widget_set_font (sidebar_title->details->more_info_label,
new_font);
gdk_font_unref (new_font);
}
#endif
static void
nautilus_sidebar_title_init (NautilusSidebarTitle *sidebar_title)
{
sidebar_title->details = g_new0 (NautilusSidebarTitleDetails, 1);
/* Register to find out about icon theme changes */
gtk_signal_connect_object_while_alive (nautilus_icon_factory_get (),
"icons_changed",
G_CALLBACK (update_icon),
GTK_OBJECT (sidebar_title));
g_signal_connect (sidebar_title, "realize",
G_CALLBACK (realize_callback), NULL);
/* Create the icon */
sidebar_title->details->icon = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (sidebar_title), sidebar_title->details->icon, 0, 0, 0);
gtk_widget_show (sidebar_title->details->icon);
/* Create the title label */
sidebar_title->details->title_label = sidebar_title_create_title_label ();
gtk_box_pack_start (GTK_BOX (sidebar_title), sidebar_title->details->title_label, 0, 0, 0);
gtk_widget_show (sidebar_title->details->title_label);
/* Create the more info label */
sidebar_title->details->more_info_label = sidebar_title_create_more_info_label ();
gtk_box_pack_start (GTK_BOX (sidebar_title), sidebar_title->details->more_info_label, 0, 0, 0);
gtk_widget_show (sidebar_title->details->more_info_label);
sidebar_title->details->emblem_box = gtk_hbox_new (FALSE, 0);
gtk_widget_show (sidebar_title->details->emblem_box);
gtk_box_pack_start (GTK_BOX (sidebar_title), sidebar_title->details->emblem_box, 0, 0, 0);
sidebar_title->details->notes = GTK_WIDGET (gtk_label_new (NULL));
gtk_label_set_line_wrap (GTK_LABEL (sidebar_title->details->notes), TRUE);
gtk_widget_show (sidebar_title->details->notes);
gtk_box_pack_start (GTK_BOX (sidebar_title), sidebar_title->details->notes, 0, 0, 0);
/* Keep track of changes in graphics trade offs */
update_all (sidebar_title);
#if GNOME2_CONVERSION_COMPLETE
eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_DEFAULT_FONT,
non_smooth_font_changed_callback,
sidebar_title,
G_OBJECT (sidebar_title));
#endif
eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_THEME,
nautilus_sidebar_title_theme_changed,
sidebar_title,
G_OBJECT (sidebar_title));
/* initialize the label colors & fonts */
nautilus_sidebar_title_theme_changed (sidebar_title);
#if GNOME2_CONVERSION_COMPLETE
non_smooth_font_changed_callback (sidebar_title);
#endif
}
/* destroy by throwing away private storage */
static void
release_file (NautilusSidebarTitle *sidebar_title)
{
if (sidebar_title->details->file_changed_connection != 0) {
gtk_signal_disconnect (GTK_OBJECT (sidebar_title->details->file),
sidebar_title->details->file_changed_connection);
sidebar_title->details->file_changed_connection = 0;
}
if (sidebar_title->details->file != NULL) {
nautilus_file_monitor_remove (sidebar_title->details->file, sidebar_title);
nautilus_file_unref (sidebar_title->details->file);
sidebar_title->details->file = NULL;
}
}
static void
nautilus_sidebar_title_destroy (GtkObject *object)
{
NautilusSidebarTitle *sidebar_title;
sidebar_title = NAUTILUS_SIDEBAR_TITLE (object);
if (sidebar_title->details) {
release_file (sidebar_title);
g_free (sidebar_title->details->title_text);
g_free (sidebar_title->details);
sidebar_title->details = NULL;
}
EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
/* return a new index title object */
GtkWidget *
nautilus_sidebar_title_new (void)
{
return gtk_widget_new (nautilus_sidebar_title_get_type (), NULL);
}
static EelBackground *
nautilus_sidebar_title_background (NautilusSidebarTitle *sidebar_title)
{
GtkWidget *widget;
GtkWidget *sidebar;
EelBackground *background;
g_return_val_if_fail (NAUTILUS_IS_SIDEBAR_TITLE (sidebar_title), NULL);
widget = GTK_WIDGET (sidebar_title)->parent;
if (widget != NULL) {
sidebar = widget->parent;
g_return_val_if_fail (NAUTILUS_IS_SIDEBAR (sidebar), NULL);
background = eel_get_widget_background (sidebar);
g_return_val_if_fail (EEL_IS_BACKGROUND (background), NULL);
return background;
} else {
/* FIXME bugzilla.gnome.org 45042
* It would be preferable to assert widget != NULL and not have
* this else case. Doing this would require us to be carful when
* nautilus_sidebar_title_select_text_color is called - which would
* probably involve doing more of the sidebar_title initialization
* at realize time.
*/
return NULL;
}
}
/* utility to determine if the sidebar is using the default theme */
static gboolean
nautilus_sidebar_title_background_is_default (NautilusSidebarTitle *sidebar_title)
{
char *background_color, *background_image;
gboolean is_default;
background_color = nautilus_file_get_metadata (sidebar_title->details->file,
NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_COLOR,
NULL);
background_image = nautilus_file_get_metadata (sidebar_title->details->file,
NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_IMAGE,
NULL);
is_default = background_color == NULL && background_image == NULL;
g_free (background_color);
g_free (background_image);
return is_default;
}
/* utility that returns true if the title is over a dark background. We do this by finding the
sidebar and asking its background */
void
nautilus_sidebar_title_select_text_color (NautilusSidebarTitle *sidebar_title)
{
EelBackground *background;
char *sidebar_title_color;
char *sidebar_info_title_color;
char *sidebar_title_shadow_color;
/* if the background is set to the default, the theme can explicitly define the title colors. Check if
* the background has been customized and if the theme specified any colors
*/
sidebar_title_color = NULL;
sidebar_info_title_color = NULL;
sidebar_title_shadow_color = NULL;
background = nautilus_sidebar_title_background (sidebar_title);
if (background != NULL) {
if (nautilus_sidebar_title_background_is_default (sidebar_title)) {
sidebar_title_color = nautilus_theme_get_theme_data ("sidebar", "title_color");
sidebar_info_title_color = nautilus_theme_get_theme_data ("sidebar", "title_info_color");
sidebar_title_shadow_color = nautilus_theme_get_theme_data ("sidebar", "title_shadow_color");
}
if (sidebar_title_color == NULL) {
/* FIXME bugzilla.gnome.org 42496: for now, both the title and info colors are the same */
if (eel_background_is_dark (background)) {
sidebar_title_color = g_strdup ("#FFFFFF");
sidebar_info_title_color = g_strdup ("#FFFFFF");
sidebar_title_shadow_color = g_strdup ("#000000");
} else {
sidebar_title_color = g_strdup ("#000000");
sidebar_info_title_color = g_strdup ("#000000");
sidebar_title_shadow_color = g_strdup ("#FFFFFF");
}
} else {
if (sidebar_info_title_color == NULL) {
sidebar_info_title_color = g_strdup (sidebar_title_color);
}
if (sidebar_title_shadow_color == NULL) {
sidebar_title_shadow_color = g_strdup ("#FFFFFF");
}
}
eel_gtk_widget_set_foreground_color (sidebar_title->details->title_label,
sidebar_title_color);
eel_gtk_widget_set_foreground_color (sidebar_title->details->more_info_label,
sidebar_info_title_color);
#if GNOME2_CONVERSION_COMPLETE
eel_label_set_smooth_drop_shadow_color (EEL_LABEL (sidebar_title->details->title_label),
eel_parse_rgb_with_white_default (sidebar_title_shadow_color));
eel_label_set_smooth_drop_shadow_color (EEL_LABEL (sidebar_title->details->more_info_label),
eel_parse_rgb_with_white_default (sidebar_title_shadow_color));
eel_label_set_smooth_drop_shadow_offset (EEL_LABEL (sidebar_title->details->title_label),
sidebar_title->details->shadow_offset);
eel_label_set_smooth_drop_shadow_offset (EEL_LABEL (sidebar_title->details->more_info_label),
sidebar_title->details->shadow_offset);
#endif
g_free (sidebar_title_color);
g_free (sidebar_info_title_color);
g_free (sidebar_title_shadow_color);
}
}
/* handle theme changes by setting up the color of the labels */
static void
nautilus_sidebar_title_theme_changed (gpointer user_data)
{
char *shadow_offset_str;
NautilusSidebarTitle *sidebar_title;
sidebar_title = NAUTILUS_SIDEBAR_TITLE (user_data);
shadow_offset_str = nautilus_theme_get_theme_data ("sidebar", "shadow_offset");
if (shadow_offset_str) {
sidebar_title->details->shadow_offset = atoi (shadow_offset_str);
g_free (shadow_offset_str);
} else {
sidebar_title->details->shadow_offset = 1;
}
nautilus_sidebar_title_select_text_color (sidebar_title);
}
/* get a property from the current content view's property bag if we can */
static char*
get_property_from_component (NautilusSidebarTitle *sidebar_title, const char *property)
{
GtkWidget *window;
Bonobo_Control control;
CORBA_Environment ev;
Bonobo_PropertyBag property_bag;
char* icon_name;
window = gtk_widget_get_ancestor (GTK_WIDGET (sidebar_title), NAUTILUS_TYPE_WINDOW);
if (window == NULL || NAUTILUS_WINDOW (window)->content_view == NULL) {
return NULL;
}
control = nautilus_view_frame_get_control (NAUTILUS_VIEW_FRAME (NAUTILUS_WINDOW (window)->content_view));
if (control == NULL) {
return NULL;
}
CORBA_exception_init (&ev);
property_bag = Bonobo_Control_getProperties (control, &ev);
if (BONOBO_EX (&ev)) {
property_bag = CORBA_OBJECT_NIL;
}
CORBA_exception_free (&ev);
if (property_bag == CORBA_OBJECT_NIL) {
return NULL;
}
icon_name = bonobo_property_bag_client_get_value_string
(property_bag, property, NULL);
bonobo_object_release_unref (property_bag, NULL);
return icon_name;
}
/* set up the icon image */
static void
update_icon (NautilusSidebarTitle *sidebar_title)
{
GdkPixbuf *pixbuf;
char *uri;
char *icon_name;
gboolean leave_pixbuf_unchanged;
leave_pixbuf_unchanged = FALSE;
uri = NULL;
icon_name = NULL;
if (sidebar_title->details->file) {
uri = nautilus_file_get_uri (sidebar_title->details->file);
}
/* see if the current content view is specifying an icon */
icon_name = get_property_from_component (sidebar_title, "icon_name");
pixbuf = NULL;
if (icon_name != NULL && strlen (icon_name) > 0) {
pixbuf = nautilus_icon_factory_get_pixbuf_from_name (icon_name, NULL, NAUTILUS_ICON_SIZE_LARGE, TRUE);
} else if (nautilus_icon_factory_is_icon_ready_for_file (sidebar_title->details->file)) {
pixbuf = nautilus_icon_factory_get_pixbuf_for_file (sidebar_title->details->file,
"accept",
NAUTILUS_ICON_SIZE_LARGE,
TRUE);
} else if (sidebar_title->details->determined_icon) {
/* We used to know the icon for this file, but now the file says it isn't
* ready. This means that some file info has been invalidated, which
* doesn't necessarily mean that the previously-determined icon is
* wrong (in fact, in practice it usually doesn't mean that). Keep showing
* the one we last determined for now.
*/
leave_pixbuf_unchanged = TRUE;
}
g_free (uri);
g_free (icon_name);
if (pixbuf != NULL) {
sidebar_title->details->determined_icon = TRUE;
}
if (!leave_pixbuf_unchanged) {
gtk_image_set_from_pixbuf (GTK_IMAGE (sidebar_title->details->icon), pixbuf);
}
}
static void
update_title_font (NautilusSidebarTitle *sidebar_title)
{
int available_width;
#if GNOME2_CONVERSION_COMPLETE
GdkFont *template_font;
GdkFont *bold_template_font;
GdkFont *largest_fitting_font;
int largest_fitting_smooth_font_size;
EelScalableFont *smooth_font;
#endif
/* Make sure theres work to do */
if (eel_strlen (sidebar_title->details->title_text) < 1) {
return;
}
available_width = GTK_WIDGET (sidebar_title)->allocation.width - TITLE_PADDING;
/* No work to do */
if (available_width <= 0) {
return;
}
#if GNOME2_CONVERSION_COMPLETE
/* Update the smooth font */
smooth_font = eel_label_get_smooth_font (EEL_LABEL (sidebar_title->details->title_label));
largest_fitting_smooth_font_size = eel_scalable_font_largest_fitting_font_size
(smooth_font,
sidebar_title->details->title_text,
available_width,
MIN_TITLE_FONT_SIZE,
MAX_TITLE_FONT_SIZE);
eel_label_set_smooth_font_size (EEL_LABEL (sidebar_title->details->title_label),
largest_fitting_smooth_font_size);
g_object_unref (smooth_font);
/* Update the regular font */
template_font = get_non_smooth_font (MAX_TITLE_FONT_SIZE);
bold_template_font = eel_gdk_font_get_bold (template_font);
largest_fitting_font = eel_gdk_font_get_largest_fitting
(bold_template_font,
sidebar_title->details->title_text,
available_width,
MIN_TITLE_FONT_SIZE,
MAX_TITLE_FONT_SIZE);
if (largest_fitting_font == NULL) {
largest_fitting_font = eel_gdk_font_get_fixed ();
}
eel_gtk_widget_set_font (sidebar_title->details->title_label,
largest_fitting_font);
gdk_font_unref (largest_fitting_font);
gdk_font_unref (bold_template_font);
gdk_font_unref (template_font);
#else
eel_gtk_label_make_bold (GTK_LABEL (sidebar_title->details->title_label));
eel_gtk_label_set_scale (GTK_LABEL (sidebar_title->details->title_label), PANGO_SCALE_LARGE);
#endif
}
static void
update_title (NautilusSidebarTitle *sidebar_title)
{
GtkLabel *label;
const char *text;
label = GTK_LABEL (sidebar_title->details->title_label);
text = sidebar_title->details->title_text;
/* FIXME bugzilla.gnome.org 42500: We could defer showing the title until the icon is ready. */
if (eel_strcmp (text, gtk_label_get_text (label)) == 0) {
return;
}
gtk_label_set_text (label, text);
update_title_font (sidebar_title);
}
static void
append_and_eat (GString *string, const char *separator, char *new_string)
{
if (new_string == NULL) {
return;
}
if (separator != NULL) {
g_string_append (string, separator);
}
g_string_append (string, new_string);
g_free (new_string);
}
static gboolean
file_is_search_location (NautilusFile *file)
{
char *uri;
gboolean is_search_uri;
uri = nautilus_file_get_uri (file);
is_search_uri = nautilus_is_search_uri (uri);
g_free (uri);
return is_search_uri;
}
static int
measure_width_callback (const char *string, gpointer callback_data)
{
PangoLayout *layout;
int width;
layout = PANGO_LAYOUT (callback_data);
pango_layout_set_text (layout, string, -1);
pango_layout_get_pixel_size (layout, &width, NULL);
return width;
}
static void
update_more_info (NautilusSidebarTitle *sidebar_title)
{
NautilusFile *file;
GString *info_string;
char *type_string, *component_info;
char *search_string, *search_uri;
char *date_modified_str;
int sidebar_width;
PangoLayout *layout;
file = sidebar_title->details->file;
/* allow components to specify the info if they wish to */
component_info = get_property_from_component (sidebar_title, "summary_info");
if (component_info != NULL && strlen (component_info) > 0) {
info_string = g_string_new (component_info);
g_free (component_info);
} else {
/* FIXME bugzilla.gnome.org 42500: We could defer showing info until the icon is ready. */
/* Adding this special case for search results to
correspond to the fix for bug 2341. */
if (file != NULL && file_is_search_location (file)) {
search_uri = nautilus_file_get_uri (file);
search_string = nautilus_search_uri_to_human (search_uri);
g_free (search_uri);
info_string = g_string_new (search_string);
g_free (search_string);
append_and_eat (info_string, "\n ",
nautilus_file_get_string_attribute (file, "size"));
} else {
info_string = g_string_new (NULL);
type_string = nautilus_file_get_string_attribute (file, "type");
if (type_string != NULL) {
append_and_eat (info_string, NULL, type_string);
append_and_eat (info_string, ", ",
nautilus_file_get_string_attribute (file, "size"));
} else {
append_and_eat (info_string, NULL,
nautilus_file_get_string_attribute (file, "size"));
}
sidebar_width = GTK_WIDGET (sidebar_title)->allocation.width - 2 * SIDEBAR_INFO_MARGIN;
if (sidebar_width > MINIMUM_INFO_WIDTH) {
layout = pango_layout_copy (gtk_label_get_layout (GTK_LABEL (sidebar_title->details->more_info_label)));
pango_layout_set_width (layout, -1);
date_modified_str = nautilus_file_fit_modified_date_as_string
(file, sidebar_width, measure_width_callback, NULL, layout);
g_object_unref (layout);
append_and_eat (info_string, "\n", date_modified_str);
}
}
}
gtk_label_set_text (GTK_LABEL (sidebar_title->details->more_info_label),
info_string->str);
g_string_free (info_string, TRUE);
}
/* add a pixbuf to the emblem box */
static void
add_emblem (NautilusSidebarTitle *sidebar_title, GdkPixbuf *pixbuf)
{
GtkWidget *image_widget;
image_widget = gtk_image_new_from_pixbuf (pixbuf);
gtk_widget_show (image_widget);
gtk_container_add (GTK_CONTAINER (sidebar_title->details->emblem_box), image_widget);
}
static void
update_emblems (NautilusSidebarTitle *sidebar_title)
{
GList *icons, *p;
GdkPixbuf *pixbuf;
/* FIXME bugzilla.gnome.org 42500: We could defer showing emblems until the icon is ready. */
/* exit if we don't have the file yet */
if (sidebar_title->details->file == NULL) {
return;
}
/* First, deallocate any existing ones */
gtk_container_foreach (GTK_CONTAINER (sidebar_title->details->emblem_box),
(GtkCallback) gtk_widget_destroy,
NULL);
/* fetch the emblem icons from metadata */
icons = nautilus_icon_factory_get_emblem_icons_for_file (sidebar_title->details->file, NULL);
/* loop through the list of emblems, installing them in the box */
for (p = icons; p != NULL; p = p->next) {
pixbuf = nautilus_icon_factory_get_pixbuf_for_icon
(p->data,
NAUTILUS_ICON_SIZE_STANDARD, NAUTILUS_ICON_SIZE_STANDARD,
NAUTILUS_ICON_SIZE_STANDARD, NAUTILUS_ICON_SIZE_STANDARD,
FALSE, NULL, FALSE);
if (pixbuf != NULL) {
add_emblem (sidebar_title, pixbuf);
g_object_unref (pixbuf);
}
}
nautilus_scalable_icon_list_free (icons);
}
static void
update_notes (NautilusSidebarTitle *sidebar_title)
{
char *text;
/* FIXME bugzilla.gnome.org 42500: We could defer showing notes until the icon is ready. */
text = nautilus_file_get_metadata (sidebar_title->details->file,
NAUTILUS_METADATA_KEY_NOTES,
NULL);
gtk_label_set_text (GTK_LABEL (sidebar_title->details->notes), text);
g_free (text);
}
/* return the filename text */
char *
nautilus_sidebar_title_get_text (NautilusSidebarTitle *sidebar_title)
{
return g_strdup (sidebar_title->details->title_text);
}
/* set up the filename text */
void
nautilus_sidebar_title_set_text (NautilusSidebarTitle *sidebar_title,
const char* new_text)
{
g_free (sidebar_title->details->title_text);
/* truncate the title to a reasonable size */
if (new_text && strlen (new_text) > MAX_TITLE_SIZE) {
sidebar_title->details->title_text = g_strndup (new_text, MAX_TITLE_SIZE);
} else {
sidebar_title->details->title_text = g_strdup (new_text);
}
/* Recompute the displayed text. */
update_title (sidebar_title);
}
static void
update_all (NautilusSidebarTitle *sidebar_title)
{
update_icon (sidebar_title);
update_title (sidebar_title);
update_more_info (sidebar_title);
nautilus_sidebar_title_select_text_color (sidebar_title);
update_emblems (sidebar_title);
update_notes (sidebar_title);
}
void
nautilus_sidebar_title_set_file (NautilusSidebarTitle *sidebar_title,
NautilusFile *file,
const char *initial_text)
{
GList *attributes;
if (file != sidebar_title->details->file) {
release_file (sidebar_title);
sidebar_title->details->file = file;
sidebar_title->details->determined_icon = FALSE;
nautilus_file_ref (sidebar_title->details->file);
/* attach file */
if (file != NULL) {
sidebar_title->details->file_changed_connection =
gtk_signal_connect_object (GTK_OBJECT (sidebar_title->details->file),
"changed",
G_CALLBACK (update_all),
GTK_OBJECT (sidebar_title));
/* Monitor the things needed to get the right
* icon. Don't monitor a directory's item
* count even though the "size" attribute is
* based on that, because the main view will
* get it for us in most cases, and in other
* cases it's OK to now show the size.
*/
attributes = nautilus_icon_factory_get_required_file_attributes ();
attributes = g_list_prepend (attributes,
NAUTILUS_FILE_ATTRIBUTE_METADATA);
nautilus_file_monitor_add (sidebar_title->details->file, sidebar_title,
attributes);
g_list_free (attributes);
}
}
g_free (sidebar_title->details->title_text);
sidebar_title->details->title_text = g_strdup (initial_text);
update_all (sidebar_title);
}
static void
nautilus_sidebar_title_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
guint16 old_width;
old_width = widget->allocation.width;
EEL_CALL_PARENT (GTK_WIDGET_CLASS, size_allocate, (widget, allocation));
if (old_width != widget->allocation.width) {
/* update the title font and info format as the size changes. */
update_title_font (NAUTILUS_SIDEBAR_TITLE (widget));
update_more_info (NAUTILUS_SIDEBAR_TITLE (widget));
}
}
gboolean
nautilus_sidebar_title_hit_test_icon (NautilusSidebarTitle *sidebar_title, int x, int y)
{
g_return_val_if_fail (NAUTILUS_IS_SIDEBAR_TITLE (sidebar_title), FALSE);
return eel_point_in_widget (sidebar_title->details->icon, x, y);
}
static GtkWidget *
sidebar_title_create_title_label (void)
{
GtkWidget *title_label;
title_label = gtk_label_new ("");
eel_gtk_label_make_bold (GTK_LABEL (title_label));
gtk_label_set_line_wrap (GTK_LABEL (title_label), TRUE);
gtk_label_set_justify (GTK_LABEL (title_label), GTK_JUSTIFY_CENTER);
return title_label;
}
static GtkWidget *
sidebar_title_create_more_info_label (void)
{
GtkWidget *more_info_label;
more_info_label = gtk_label_new ("");
eel_gtk_label_set_scale (GTK_LABEL (more_info_label), PANGO_SCALE_SMALL);
gtk_label_set_justify (GTK_LABEL (more_info_label), GTK_JUSTIFY_CENTER);
return more_info_label;
}
|