diff options
Diffstat (limited to 'src/plugins/fs/helper.c')
-rw-r--r-- | src/plugins/fs/helper.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/plugins/fs/helper.c b/src/plugins/fs/helper.c index 60f4af9c..9f6eaed9 100644 --- a/src/plugins/fs/helper.c +++ b/src/plugins/fs/helper.c | |||
@@ -92,3 +92,116 @@ int parseTime(const char * t, | |||
92 | return OK; | 92 | return OK; |
93 | } | 93 | } |
94 | 94 | ||
95 | /** | ||
96 | * FIXME: convert this into a glade widget! | ||
97 | */ | ||
98 | GtkWidget * | ||
99 | buildSearchTabLabel(GtkWidget *searchPage, | ||
100 | const char *title) { | ||
101 | GtkWidget *hbox; | ||
102 | GtkWidget *label_hbox; | ||
103 | GtkWidget *label_ebox; | ||
104 | GtkWidget *label; | ||
105 | GtkWidget *dummy_label; | ||
106 | GtkWidget *close_button; | ||
107 | GtkRcStyle *rcstyle; | ||
108 | GtkRequisition size; | ||
109 | GtkWidget *image; | ||
110 | char *short_title; | ||
111 | char *orig_title; | ||
112 | char *final_title; | ||
113 | char *short_title_end; | ||
114 | char *tip_title; | ||
115 | int short_title_len; | ||
116 | static GtkTooltips *searchTabLabelTooltip = NULL; | ||
117 | unsigned int *file_count; | ||
118 | |||
119 | if(!searchTabLabelTooltip) | ||
120 | searchTabLabelTooltip = gtk_tooltips_new(); | ||
121 | |||
122 | hbox = gtk_hbox_new (FALSE, 2); | ||
123 | |||
124 | label_ebox = gtk_event_box_new (); | ||
125 | gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE); | ||
126 | gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0); | ||
127 | |||
128 | label_hbox = gtk_hbox_new (FALSE, 2); | ||
129 | gtk_container_add (GTK_CONTAINER (label_ebox), label_hbox); | ||
130 | |||
131 | /* setup close button */ | ||
132 | close_button = gtk_button_new (); | ||
133 | gtk_button_set_relief (GTK_BUTTON (close_button), | ||
134 | GTK_RELIEF_NONE); | ||
135 | /* don't allow focus on the close button */ | ||
136 | gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE); | ||
137 | |||
138 | /* make it as small as possible */ | ||
139 | rcstyle = gtk_rc_style_new (); | ||
140 | rcstyle->xthickness = 0; | ||
141 | rcstyle->ythickness = 0; | ||
142 | gtk_widget_modify_style (close_button, rcstyle); | ||
143 | gtk_rc_style_unref (rcstyle), | ||
144 | |||
145 | image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, | ||
146 | GTK_ICON_SIZE_MENU); | ||
147 | gtk_widget_size_request (image, &size); | ||
148 | gtk_widget_set_size_request (close_button, size.width, size.height); | ||
149 | gtk_container_add (GTK_CONTAINER (close_button), image); | ||
150 | gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0); | ||
151 | |||
152 | g_signal_connect_swapped(close_button, | ||
153 | "clicked", | ||
154 | G_CALLBACK (on_closeSearchButton_clicked_fs), | ||
155 | searchPage); | ||
156 | |||
157 | /* truncate the description if needed */ | ||
158 | if(g_utf8_strlen(title, 16) > 15) { | ||
159 | short_title_end = g_utf8_offset_to_pointer (title, 15); | ||
160 | short_title_len = short_title_end - title; | ||
161 | short_title = g_strndup(title, short_title_len); | ||
162 | orig_title = g_strconcat(short_title, "...", NULL); | ||
163 | FREE(short_title); | ||
164 | } else { | ||
165 | orig_title = STRDUP(title); | ||
166 | } | ||
167 | |||
168 | /* setup label */ | ||
169 | final_title = g_strconcat(orig_title, " (0)", NULL); | ||
170 | label = gtk_label_new (final_title); | ||
171 | FREE(final_title); | ||
172 | |||
173 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); | ||
174 | gtk_misc_set_padding (GTK_MISC (label), 0, 0); | ||
175 | gtk_box_pack_start (GTK_BOX (label_hbox), label, FALSE, FALSE, 0); | ||
176 | |||
177 | /* add a forced space before the button */ | ||
178 | dummy_label = gtk_label_new (""); | ||
179 | gtk_box_pack_start (GTK_BOX (label_hbox), dummy_label, TRUE, TRUE, 0); | ||
180 | |||
181 | /* tooltips */ | ||
182 | gtk_tooltips_set_tip(searchTabLabelTooltip, close_button, | ||
183 | _("Close this search"), NULL); | ||
184 | tip_title = g_strconcat (_("Search: "), title, NULL); | ||
185 | gtk_tooltips_set_tip(searchTabLabelTooltip, label_ebox, | ||
186 | tip_title, NULL); | ||
187 | |||
188 | /* store some references to access count & title later */ | ||
189 | file_count = malloc(sizeof(unsigned int)); | ||
190 | *file_count = 0; | ||
191 | g_object_set_data(G_OBJECT(searchPage), | ||
192 | "file_count", (gpointer) file_count); | ||
193 | g_object_set_data(G_OBJECT(searchPage), | ||
194 | "label", (gpointer) label); | ||
195 | g_object_set_data(G_OBJECT(searchPage), | ||
196 | "title", (gpointer) orig_title); | ||
197 | |||
198 | gtk_widget_show (hbox); | ||
199 | gtk_widget_show (label_ebox); | ||
200 | gtk_widget_show (label_hbox); | ||
201 | gtk_widget_show (label); | ||
202 | gtk_widget_show (dummy_label); | ||
203 | gtk_widget_show (image); | ||
204 | gtk_widget_show (close_button); | ||
205 | |||
206 | return hbox; | ||
207 | } | ||