2 * @file gtksmiley.c GTK+ Smiley Manager API
9 * Pidgin is the legal property of its developers, whose names are too numerous
10 * to list here. Please refer to the COPYRIGHT file distributed with this
11 * source distribution.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
35 #include "gtkimhtml.h"
36 #include "gtksmiley.h"
38 #include "pidginstock.h"
40 #define PIDGIN_RESPONSE_MODIFY 1000
47 GtkWidget
*smiley_image
;
49 GdkPixbuf
*custom_pixbuf
;
50 gpointer data
; /** @since 2.6.0 */
51 gsize datasize
; /** @since 2.6.0 */
52 gint entry_len
; /** @since 2.6.0 */
71 static SmileyManager
*smiley_manager
= NULL
;
72 static GSList
*gtk_smileys
= NULL
;
75 pidgin_smiley_destroy(PidginSmiley
*smiley
)
78 g_object_set_data(G_OBJECT(smiley
->smiley
), "edit-dialog", NULL
);
79 gtk_widget_destroy(smiley
->parent
);
80 g_free(smiley
->filename
);
81 if (smiley
->custom_pixbuf
)
82 g_object_unref(G_OBJECT(smiley
->custom_pixbuf
));
86 /******************************************************************************
87 * GtkIMHtmlSmileys stuff
88 *****************************************************************************/
89 /* Perhaps these should be in gtkimhtml.c instead. -- sadrul */
90 static void add_gtkimhtml_to_list(GtkIMHtmlSmiley
*gtksmiley
)
92 gtk_smileys
= g_slist_prepend(gtk_smileys
, gtksmiley
);
94 purple_debug_info("gtksmiley", "adding %s to gtk_smileys\n", gtksmiley
->smile
);
98 shortcut_changed_cb(PurpleSmiley
*smiley
, gpointer dontcare
, GtkIMHtmlSmiley
*gtksmiley
)
100 g_free(gtksmiley
->smile
);
101 gtksmiley
->smile
= g_strdup(purple_smiley_get_shortcut(smiley
));
105 image_changed_cb(PurpleSmiley
*smiley
, gpointer dontcare
, GtkIMHtmlSmiley
*gtksmiley
)
109 g_free(gtksmiley
->file
);
111 file
= purple_imgstore_get_filename(purple_smiley_get_stored_image(smiley
));
112 gtksmiley
->file
= g_build_filename(purple_smileys_get_storing_dir(), file
, NULL
);
113 gtk_imhtml_smiley_reload(gtksmiley
);
116 static GtkIMHtmlSmiley
*smiley_purple_to_gtkimhtml(PurpleSmiley
*smiley
)
118 GtkIMHtmlSmiley
*gtksmiley
;
122 file
= purple_imgstore_get_filename(purple_smiley_get_stored_image(smiley
));
124 filename
= g_build_filename(purple_smileys_get_storing_dir(), file
, NULL
);
126 gtksmiley
= gtk_imhtml_smiley_create(filename
, purple_smiley_get_shortcut(smiley
),
127 FALSE
, GTK_IMHTML_SMILEY_CUSTOM
);
130 /* Make sure the shortcut for the GtkIMHtmlSmiley is updated with the PurpleSmiley */
131 g_signal_connect(G_OBJECT(smiley
), "notify::shortcut",
132 G_CALLBACK(shortcut_changed_cb
), gtksmiley
);
134 /* And update the pixbuf too when the image is changed */
135 g_signal_connect(G_OBJECT(smiley
), "notify::image",
136 G_CALLBACK(image_changed_cb
), gtksmiley
);
141 void pidgin_smiley_del_from_list(PurpleSmiley
*smiley
)
144 GtkIMHtmlSmiley
*gtksmiley
;
146 if (gtk_smileys
== NULL
)
151 for (; list
; list
= list
->next
) {
152 gtksmiley
= (GtkIMHtmlSmiley
*)list
->data
;
154 if (strcmp(gtksmiley
->smile
, purple_smiley_get_shortcut(smiley
)))
157 gtk_imhtml_smiley_destroy(gtksmiley
);
158 g_signal_handlers_disconnect_matched(G_OBJECT(smiley
), G_SIGNAL_MATCH_DATA
,
159 0, 0, NULL
, NULL
, gtksmiley
);
164 gtk_smileys
= g_slist_delete_link(gtk_smileys
, list
);
167 void pidgin_smiley_add_to_list(PurpleSmiley
*smiley
)
169 GtkIMHtmlSmiley
*gtksmiley
;
171 gtksmiley
= smiley_purple_to_gtkimhtml(smiley
);
172 add_gtkimhtml_to_list(gtksmiley
);
173 g_signal_connect(G_OBJECT(smiley
), "destroy", G_CALLBACK(pidgin_smiley_del_from_list
), NULL
);
176 void pidgin_smileys_init(void)
179 PurpleSmiley
*smiley
;
181 if (gtk_smileys
!= NULL
)
184 smileys
= purple_smileys_get_all();
186 for (; smileys
; smileys
= g_list_delete_link(smileys
, smileys
)) {
187 smiley
= (PurpleSmiley
*)smileys
->data
;
189 pidgin_smiley_add_to_list(smiley
);
193 void pidgin_smileys_uninit(void)
196 GtkIMHtmlSmiley
*gtksmiley
;
203 for (; list
; list
= g_slist_delete_link(list
, list
)) {
204 gtksmiley
= (GtkIMHtmlSmiley
*)list
->data
;
205 gtk_imhtml_smiley_destroy(gtksmiley
);
211 GSList
*pidgin_smileys_get_all(void)
216 /******************************************************************************
218 *****************************************************************************/
220 static void refresh_list(void);
222 /******************************************************************************
224 ******************************************************************************/
226 static void do_add(GtkWidget
*widget
, PidginSmiley
*s
)
229 PurpleSmiley
*emoticon
;
231 entry
= gtk_entry_get_text(GTK_ENTRY(s
->smile
));
233 emoticon
= purple_smileys_find_by_shortcut(entry
);
234 if (emoticon
&& emoticon
!= s
->smiley
) {
236 msg
= g_strdup_printf(_("A custom smiley for '%s' already exists. "
237 "Please use a different shortcut."), entry
);
238 purple_notify_error(s
->parent
, _("Custom Smiley"),
239 _("Duplicate Shortcut"), msg
);
250 if (!g_file_get_contents(s
->filename
, &data
, &len
, &err
)) {
251 purple_debug_error("gtksmiley", "Error reading %s: %s\n",
252 s
->filename
, err
->message
);
257 purple_smiley_set_data(s
->smiley
, (guchar
*)data
, len
);
259 purple_smiley_set_shortcut(s
->smiley
, entry
);
261 purple_debug_info("gtksmiley", "adding a new smiley\n");
263 if (s
->filename
== NULL
) {
264 gchar
*buffer
= NULL
;
267 const gchar
*dirname
= purple_smileys_get_storing_dir();
269 /* since this may be called before purple_smiley_new_* has ever been
270 called, we create the storing dir, if it doesn't exist yet, to be
271 able to save the pixbuf before adding the smiley */
272 if (!g_file_test(dirname
, G_FILE_TEST_IS_DIR
)) {
273 purple_debug_info("gtksmiley", "Creating smileys directory.\n");
275 if (g_mkdir(dirname
, S_IRUSR
| S_IWUSR
| S_IXUSR
) < 0) {
276 purple_debug_error("gtksmiley",
277 "Unable to create directory %s: %s\n",
278 dirname
, g_strerror(errno
));
282 if (s
->data
&& s
->datasize
) {
283 /* Cached data & size in memory */
288 /* Get the smiley from the custom pixbuf */
289 gdk_pixbuf_save_to_buffer(s
->custom_pixbuf
, &buffer
, &size
,
290 "png", NULL
, "compression", "9", NULL
, NULL
);
292 filename
= purple_util_get_image_filename(buffer
, size
);
293 s
->filename
= g_build_filename(dirname
, filename
, NULL
);
294 purple_util_write_data_to_file_absolute(s
->filename
, buffer
, size
);
298 emoticon
= purple_smiley_new_from_file(entry
, s
->filename
);
300 pidgin_smiley_add_to_list(emoticon
);
303 if (smiley_manager
!= NULL
)
306 gtk_widget_destroy(s
->parent
);
309 static void do_add_select_cb(GtkWidget
*widget
, gint resp
, PidginSmiley
*s
)
312 case GTK_RESPONSE_ACCEPT
:
315 case GTK_RESPONSE_DELETE_EVENT
:
316 case GTK_RESPONSE_CANCEL
:
317 gtk_widget_destroy(s
->parent
);
320 purple_debug_error("gtksmiley", "no valid response\n");
325 static void do_add_file_cb(const char *filename
, gpointer data
)
327 PidginSmiley
*s
= data
;
334 s
->filename
= g_strdup(filename
);
335 pixbuf
= gdk_pixbuf_new_from_file_at_scale(filename
, 64, 64, FALSE
, NULL
);
336 gtk_image_set_from_pixbuf(GTK_IMAGE(s
->smiley_image
), pixbuf
);
338 g_object_unref(G_OBJECT(pixbuf
));
339 gtk_widget_grab_focus(s
->smile
);
341 if (s
->entry_len
> 0)
342 gtk_dialog_set_response_sensitive(GTK_DIALOG(s
->parent
), GTK_RESPONSE_ACCEPT
, TRUE
);
346 open_image_selector(GtkWidget
*widget
, PidginSmiley
*psmiley
)
348 GtkWidget
*file_chooser
;
349 file_chooser
= pidgin_buddy_icon_chooser_new(GTK_WINDOW(gtk_widget_get_toplevel(widget
)),
350 do_add_file_cb
, psmiley
);
351 gtk_window_set_title(GTK_WINDOW(file_chooser
), _("Custom Smiley"));
352 gtk_window_set_role(GTK_WINDOW(file_chooser
), "file-selector-custom-smiley");
353 gtk_widget_show_all(file_chooser
);
357 smiley_name_insert_cb(GtkEditable
*editable
,
359 gint new_text_length
,
363 PidginSmiley
*s
= user_data
;
364 if (new_text_length
!= -1)
365 s
->entry_len
+= new_text_length
;
367 s
->entry_len
+= strlen(new_text
);
369 if (s
->filename
!= NULL
|| s
->custom_pixbuf
!= NULL
|| s
->smiley
!= NULL
)
370 gtk_dialog_set_response_sensitive(GTK_DIALOG(s
->parent
), GTK_RESPONSE_ACCEPT
, TRUE
);
374 smiley_name_delete_cb(GtkEditable
*editable
,
379 PidginSmiley
*s
= user_data
;
380 s
->entry_len
-= end_pos
- start_pos
;
382 if (s
->entry_len
<= 0)
383 gtk_dialog_set_response_sensitive(GTK_DIALOG(s
->parent
), GTK_RESPONSE_ACCEPT
, FALSE
);
387 pidgin_smiley_edit(GtkWidget
*widget
, PurpleSmiley
*smiley
)
394 GdkPixbuf
*pixbuf
= NULL
;
395 PurpleStoredImage
*stored_img
;
397 PidginSmiley
*s
= g_new0(PidginSmiley
, 1);
400 window
= gtk_dialog_new_with_buttons(smiley
? _("Edit Smiley") : _("Add Smiley"),
401 widget
? GTK_WINDOW(widget
) : NULL
,
402 GTK_DIALOG_DESTROY_WITH_PARENT
| GTK_DIALOG_NO_SEPARATOR
,
403 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
404 smiley
? GTK_STOCK_SAVE
: GTK_STOCK_ADD
, GTK_RESPONSE_ACCEPT
,
408 g_object_set_data(G_OBJECT(smiley
), "edit-dialog", window
);
410 gtk_container_set_border_width(GTK_CONTAINER(window
), PIDGIN_HIG_BORDER
);
412 gtk_dialog_set_default_response(GTK_DIALOG(window
), GTK_RESPONSE_ACCEPT
);
413 g_signal_connect(window
, "response", G_CALLBACK(do_add_select_cb
), s
);
416 vbox
= gtk_vbox_new(FALSE
, PIDGIN_HIG_BORDER
);
417 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(window
)->vbox
), vbox
);
418 gtk_widget_show(vbox
);
421 hbox
= gtk_hbox_new(FALSE
, PIDGIN_HIG_BORDER
);
422 gtk_container_add(GTK_CONTAINER(GTK_VBOX(vbox
)), hbox
);
424 label
= gtk_label_new_with_mnemonic(_("_Image:"));
425 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
426 gtk_widget_show(label
);
428 filech
= gtk_button_new();
429 gtk_box_pack_end(GTK_BOX(hbox
), filech
, FALSE
, FALSE
, 0);
430 pidgin_set_accessible_label(filech
, label
);
432 s
->smiley_image
= gtk_image_new();
433 gtk_container_add(GTK_CONTAINER(filech
), s
->smiley_image
);
434 if (smiley
&& (stored_img
= purple_smiley_get_stored_image(smiley
))) {
435 pixbuf
= pidgin_pixbuf_from_imgstore(stored_img
);
436 purple_imgstore_unref(stored_img
);
438 GtkIconSize icon_size
= gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_SMALL
);
439 pixbuf
= gtk_widget_render_icon(window
, PIDGIN_STOCK_TOOLBAR_SELECT_AVATAR
,
440 icon_size
, "PidginSmiley");
443 gtk_image_set_from_pixbuf(GTK_IMAGE(s
->smiley_image
), pixbuf
);
445 g_object_unref(G_OBJECT(pixbuf
));
446 g_signal_connect(G_OBJECT(filech
), "clicked", G_CALLBACK(open_image_selector
), s
);
448 gtk_widget_show_all(hbox
);
451 hbox
= gtk_hbox_new(FALSE
, PIDGIN_HIG_BORDER
);
452 gtk_container_add(GTK_CONTAINER(GTK_VBOX(vbox
)),hbox
);
455 label
= gtk_label_new_with_mnemonic(_("S_hortcut text:"));
456 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
457 gtk_widget_show(label
);
459 s
->smile
= gtk_entry_new();
460 gtk_entry_set_activates_default(GTK_ENTRY(s
->smile
), TRUE
);
461 pidgin_set_accessible_label(s
->smile
, label
);
463 const char *shortcut
= purple_smiley_get_shortcut(smiley
);
464 gtk_entry_set_text(GTK_ENTRY(s
->smile
), shortcut
);
465 s
->entry_len
= strlen(shortcut
);
468 gtk_dialog_set_response_sensitive(GTK_DIALOG(window
), GTK_RESPONSE_ACCEPT
, FALSE
);
470 /* gtk_entry_get_text_length is 2.14+, so we'll just keep track ourselves */
471 g_signal_connect(G_OBJECT(s
->smile
), "insert-text", G_CALLBACK(smiley_name_insert_cb
), s
);
472 g_signal_connect(G_OBJECT(s
->smile
), "delete-text", G_CALLBACK(smiley_name_delete_cb
), s
);
474 gtk_box_pack_end(GTK_BOX(hbox
), s
->smile
, FALSE
, FALSE
, 0);
475 gtk_widget_show(s
->smile
);
477 gtk_widget_show(hbox
);
479 gtk_widget_show(GTK_WIDGET(window
));
480 g_signal_connect_swapped(G_OBJECT(window
), "destroy", G_CALLBACK(pidgin_smiley_destroy
), s
);
481 g_signal_connect(G_OBJECT(window
), "destroy", G_CALLBACK(purple_notify_close_with_handle
), s
);
487 pidgin_smiley_editor_set_shortcut(PidginSmiley
*editor
, const gchar
*shortcut
)
489 gtk_entry_set_text(GTK_ENTRY(editor
->smile
), shortcut
? shortcut
: "");
493 pidgin_smiley_editor_set_image(PidginSmiley
*editor
, GdkPixbuf
*image
)
495 if (editor
->custom_pixbuf
)
496 g_object_unref(G_OBJECT(editor
->custom_pixbuf
));
497 editor
->custom_pixbuf
= image
? g_object_ref(G_OBJECT(image
)) : NULL
;
499 gtk_image_set_from_pixbuf(GTK_IMAGE(editor
->smiley_image
), image
);
500 if (editor
->entry_len
> 0)
501 gtk_dialog_set_response_sensitive(GTK_DIALOG(editor
->parent
),
502 GTK_RESPONSE_ACCEPT
, TRUE
);
505 gtk_dialog_set_response_sensitive(GTK_DIALOG(editor
->parent
),
506 GTK_RESPONSE_ACCEPT
, FALSE
);
510 pidgin_smiley_editor_set_data(PidginSmiley
*editor
, gpointer data
, gsize datasize
)
513 editor
->datasize
= datasize
;
516 /******************************************************************************
518 *****************************************************************************/
519 static void delete_foreach(GtkTreeModel
*model
, GtkTreePath
*path
,
520 GtkTreeIter
*iter
, gpointer data
)
522 PurpleSmiley
*smiley
= NULL
;
524 gtk_tree_model_get(model
, iter
,
529 g_object_unref(G_OBJECT(smiley
));
530 pidgin_smiley_del_from_list(smiley
);
531 purple_smiley_delete(smiley
);
535 static void append_to_list(GtkTreeModel
*model
, GtkTreePath
*path
,
536 GtkTreeIter
*iter
, gpointer data
)
539 *list
= g_list_prepend(*list
, gtk_tree_path_copy(path
));
542 static void smiley_delete(SmileyManager
*dialog
)
544 GtkTreeSelection
*selection
;
547 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog
->treeview
));
548 gtk_tree_selection_selected_foreach(selection
, delete_foreach
, dialog
);
549 gtk_tree_selection_selected_foreach(selection
, append_to_list
, &list
);
553 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog
->model
), &iter
, list
->data
))
554 gtk_list_store_remove(GTK_LIST_STORE(dialog
->model
), &iter
);
555 gtk_tree_path_free(list
->data
);
556 list
= g_list_delete_link(list
, list
);
559 /******************************************************************************
561 *****************************************************************************/
562 static void add_columns(GtkWidget
*treeview
, SmileyManager
*dialog
)
564 GtkCellRenderer
*rend
;
565 GtkTreeViewColumn
*column
;
568 column
= gtk_tree_view_column_new();
569 gtk_tree_view_column_set_title(column
, _("Smiley"));
570 gtk_tree_view_column_set_resizable(column
, TRUE
);
571 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview
), column
);
573 rend
= gtk_cell_renderer_pixbuf_new();
574 gtk_tree_view_column_pack_start(column
, rend
, FALSE
);
575 gtk_tree_view_column_add_attribute(column
, rend
, "pixbuf", ICON
);
578 column
= gtk_tree_view_column_new();
579 gtk_tree_view_column_set_title(column
, _("Shortcut Text"));
580 gtk_tree_view_column_set_resizable(column
, TRUE
);
581 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview
), column
);
583 rend
= gtk_cell_renderer_text_new();
584 gtk_tree_view_column_pack_start(column
, rend
, TRUE
);
585 gtk_tree_view_column_add_attribute(column
, rend
, "text", SHORTCUT
);
588 static void store_smiley_add(PurpleSmiley
*smiley
)
591 PurpleStoredImage
*img
;
592 GdkPixbuf
*sized_smiley
= NULL
;
594 if (smiley_manager
== NULL
)
597 img
= purple_smiley_get_stored_image(smiley
);
600 GdkPixbuf
*smiley_image
= pidgin_pixbuf_from_imgstore(img
);
601 purple_imgstore_unref(img
);
603 if (smiley_image
!= NULL
) {
604 if (gdk_pixbuf_get_width(smiley_image
) > 22 ||
605 gdk_pixbuf_get_height(smiley_image
) > 22) {
606 sized_smiley
= gdk_pixbuf_scale_simple(smiley_image
,
607 22, 22, GDK_INTERP_HYPER
);
608 g_object_unref(G_OBJECT(smiley_image
));
610 /* don't scale up smaller smileys, avoid blurryness */
611 sized_smiley
= smiley_image
;
617 gtk_list_store_append(smiley_manager
->model
, &iter
);
619 gtk_list_store_set(smiley_manager
->model
, &iter
,
621 SHORTCUT
, purple_smiley_get_shortcut(smiley
),
625 if (sized_smiley
!= NULL
)
626 g_object_unref(G_OBJECT(sized_smiley
));
629 static void populate_smiley_list(SmileyManager
*dialog
)
632 PurpleSmiley
*emoticon
;
634 gtk_list_store_clear(dialog
->model
);
636 for(list
= purple_smileys_get_all(); list
!= NULL
;
637 list
= g_list_delete_link(list
, list
)) {
638 emoticon
= (PurpleSmiley
*)list
->data
;
640 store_smiley_add(emoticon
);
644 static void smile_selected_cb(GtkTreeSelection
*sel
, SmileyManager
*dialog
)
648 selected
= gtk_tree_selection_count_selected_rows(sel
);
650 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog
->window
),
651 GTK_RESPONSE_NO
, selected
> 0);
653 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog
->window
),
654 PIDGIN_RESPONSE_MODIFY
, selected
> 0);
658 smiley_edit_iter(SmileyManager
*dialog
, GtkTreeIter
*iter
)
660 PurpleSmiley
*smiley
= NULL
;
661 GtkWidget
*window
= NULL
;
662 gtk_tree_model_get(GTK_TREE_MODEL(dialog
->model
), iter
, SMILEY
, &smiley
, -1);
663 if ((window
= g_object_get_data(G_OBJECT(smiley
), "edit-dialog")) != NULL
)
664 gtk_window_present(GTK_WINDOW(window
));
666 pidgin_smiley_edit(gtk_widget_get_toplevel(GTK_WIDGET(dialog
->treeview
)), smiley
);
667 g_object_unref(G_OBJECT(smiley
));
670 static void smiley_edit_cb(GtkTreeView
*treeview
, GtkTreePath
*path
, GtkTreeViewColumn
*col
, gpointer data
)
673 SmileyManager
*dialog
= data
;
675 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog
->model
), &iter
, path
);
676 smiley_edit_iter(dialog
, &iter
);
680 edit_selected_cb(GtkTreeModel
*model
, GtkTreePath
*path
, GtkTreeIter
*iter
, gpointer data
)
682 smiley_edit_iter(data
, iter
);
686 smiley_got_url(PurpleUtilFetchUrlData
*url_data
, gpointer user_data
,
687 const gchar
*smileydata
, size_t len
, const gchar
*error_message
)
689 SmileyManager
*dialog
= user_data
;
697 if ((error_message
!= NULL
) || (len
== 0)) {
701 f
= purple_mkstemp(&path
, TRUE
);
702 wc
= fwrite(smileydata
, len
, 1, f
);
704 purple_debug_warning("smiley_got_url", "Unable to write smiley data.\n");
712 image
= gdk_pixbuf_new_from_file(path
, &err
);
720 ps
= pidgin_smiley_edit(dialog
->window
, NULL
);
721 pidgin_smiley_editor_set_image(ps
, image
);
722 pidgin_smiley_editor_set_data(ps
, g_memdup(smileydata
, len
), len
);
726 smiley_dnd_recv(GtkWidget
*widget
, GdkDragContext
*dc
, guint x
, guint y
,
727 GtkSelectionData
*sd
, guint info
, guint t
, gpointer user_data
)
729 SmileyManager
*dialog
= user_data
;
730 gchar
*name
= g_strchomp((gchar
*)sd
->data
);
732 if ((sd
->length
>= 0) && (sd
->format
== 8)) {
733 /* Well, it looks like the drag event was cool.
734 * Let's do something with it */
736 if (!g_ascii_strncasecmp(name
, "file://", 7)) {
737 GError
*converr
= NULL
;
740 /* It looks like we're dealing with a local file. Let's
741 * just try and read it */
742 if(!(tmp
= g_filename_from_uri(name
, NULL
, &converr
))) {
743 purple_debug_error("smiley dnd", "%s\n",
744 (converr
? converr
->message
:
745 "g_filename_from_uri error"));
748 ps
= pidgin_smiley_edit(dialog
->window
, NULL
);
749 do_add_file_cb(tmp
, ps
);
750 if (gtk_image_get_pixbuf(GTK_IMAGE(ps
->smiley_image
)) == NULL
)
751 gtk_dialog_response(GTK_DIALOG(ps
->parent
), GTK_RESPONSE_CANCEL
);
753 } else if (!g_ascii_strncasecmp(name
, "http://", 7)) {
754 /* Oo, a web drag and drop. This is where things
755 * will start to get interesting */
756 purple_util_fetch_url(name
, TRUE
, NULL
, FALSE
, smiley_got_url
, dialog
);
757 } else if (!g_ascii_strncasecmp(name
, "https://", 8)) {
758 /* purple_util_fetch_url() doesn't support HTTPS */
759 char *tmp
= g_strdup(name
+ 1);
765 purple_util_fetch_url(tmp
, TRUE
, NULL
, FALSE
, smiley_got_url
, dialog
);
769 gtk_drag_finish(dc
, TRUE
, FALSE
, t
);
772 gtk_drag_finish(dc
, FALSE
, FALSE
, t
);
775 static GtkWidget
*smiley_list_create(SmileyManager
*dialog
)
779 GtkTreeSelection
*sel
;
780 GtkTargetEntry te
[3] = {
781 {"text/plain", 0, 0},
782 {"text/uri-list", 0, 1},
786 sw
= gtk_scrolled_window_new(NULL
, NULL
);
787 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw
),
788 GTK_POLICY_AUTOMATIC
,
789 GTK_POLICY_AUTOMATIC
);
790 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw
),
794 /* Create the list model */
795 dialog
->model
= gtk_list_store_new(N_COL
,
796 GDK_TYPE_PIXBUF
, /* ICON */
797 G_TYPE_STRING
, /* SHORTCUT */
798 G_TYPE_OBJECT
/* SMILEY */
801 /* the actual treeview */
802 treeview
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog
->model
));
803 dialog
->treeview
= treeview
;
804 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview
), TRUE
);
805 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog
->model
), SHORTCUT
, GTK_SORT_ASCENDING
);
806 g_object_unref(G_OBJECT(dialog
->model
));
808 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
809 gtk_tree_selection_set_mode(sel
, GTK_SELECTION_MULTIPLE
);
810 gtk_container_add(GTK_CONTAINER(sw
), treeview
);
812 g_signal_connect(G_OBJECT(sel
), "changed", G_CALLBACK(smile_selected_cb
), dialog
);
813 g_signal_connect(G_OBJECT(treeview
), "row_activated", G_CALLBACK(smiley_edit_cb
), dialog
);
815 gtk_drag_dest_set(treeview
,
816 GTK_DEST_DEFAULT_MOTION
| GTK_DEST_DEFAULT_HIGHLIGHT
| GTK_DEST_DEFAULT_DROP
,
817 te
, G_N_ELEMENTS(te
), GDK_ACTION_COPY
| GDK_ACTION_MOVE
);
818 g_signal_connect(G_OBJECT(treeview
), "drag_data_received", G_CALLBACK(smiley_dnd_recv
), dialog
);
820 gtk_widget_show(treeview
);
822 add_columns(treeview
, dialog
);
823 populate_smiley_list(dialog
);
828 static void refresh_list()
830 populate_smiley_list(smiley_manager
);
833 static void smiley_manager_select_cb(GtkWidget
*widget
, gint resp
, SmileyManager
*dialog
)
835 GtkTreeSelection
*selection
= NULL
;
838 case GTK_RESPONSE_YES
:
839 pidgin_smiley_edit(dialog
->window
, NULL
);
841 case GTK_RESPONSE_NO
:
842 smiley_delete(dialog
);
844 case GTK_RESPONSE_DELETE_EVENT
:
845 case GTK_RESPONSE_CLOSE
:
846 gtk_widget_destroy(dialog
->window
);
847 g_free(smiley_manager
);
848 smiley_manager
= NULL
;
850 case PIDGIN_RESPONSE_MODIFY
:
851 /* Find smiley of selection... */
852 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog
->treeview
));
853 gtk_tree_selection_selected_foreach(selection
, edit_selected_cb
, dialog
);
856 purple_debug_info("gtksmiley", "No valid selection\n");
861 void pidgin_smiley_manager_show(void)
863 SmileyManager
*dialog
;
868 if (smiley_manager
) {
869 gtk_window_present(GTK_WINDOW(smiley_manager
->window
));
873 dialog
= g_new0(SmileyManager
, 1);
874 smiley_manager
= dialog
;
876 dialog
->window
= win
= gtk_dialog_new_with_buttons(
877 _("Custom Smiley Manager"),
879 GTK_DIALOG_DESTROY_WITH_PARENT
,
880 PIDGIN_STOCK_ADD
, GTK_RESPONSE_YES
,
881 PIDGIN_STOCK_MODIFY
, PIDGIN_RESPONSE_MODIFY
,
882 GTK_STOCK_DELETE
, GTK_RESPONSE_NO
,
883 GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
,
886 gtk_window_set_default_size(GTK_WINDOW(win
), 50, 400);
887 gtk_window_set_role(GTK_WINDOW(win
), "custom_smiley_manager");
888 gtk_container_set_border_width(GTK_CONTAINER(win
),PIDGIN_HIG_BORDER
);
889 gtk_dialog_set_response_sensitive(GTK_DIALOG(win
), GTK_RESPONSE_NO
, FALSE
);
890 gtk_dialog_set_response_sensitive(GTK_DIALOG(win
),
891 PIDGIN_RESPONSE_MODIFY
, FALSE
);
893 g_signal_connect(win
, "response", G_CALLBACK(smiley_manager_select_cb
),
897 vbox
= gtk_vbox_new(FALSE
, PIDGIN_HIG_BORDER
);
898 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win
)->vbox
), vbox
);
899 gtk_widget_show(vbox
);
901 /* get the scrolled window with all stuff */
902 sw
= smiley_list_create(dialog
);
903 gtk_box_pack_start(GTK_BOX(vbox
), sw
, TRUE
, TRUE
, 0);
906 gtk_widget_show(win
);