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 (!purple_strequal(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
= pidgin_pixbuf_new_from_file_at_scale(filename
, 64, 64, FALSE
);
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
;
696 if ((error_message
!= NULL
) || (len
== 0)) {
700 f
= purple_mkstemp(&path
, TRUE
);
701 wc
= fwrite(smileydata
, len
, 1, f
);
703 purple_debug_warning("smiley_got_url", "Unable to write smiley data.\n");
711 image
= pidgin_pixbuf_new_from_file(path
);
717 ps
= pidgin_smiley_edit(dialog
->window
, NULL
);
718 pidgin_smiley_editor_set_image(ps
, image
);
719 pidgin_smiley_editor_set_data(ps
, g_memdup(smileydata
, len
), len
);
723 smiley_dnd_recv(GtkWidget
*widget
, GdkDragContext
*dc
, guint x
, guint y
,
724 GtkSelectionData
*sd
, guint info
, guint t
, gpointer user_data
)
726 SmileyManager
*dialog
= user_data
;
727 gchar
*name
= g_strchomp((gchar
*)sd
->data
);
729 if ((sd
->length
>= 0) && (sd
->format
== 8)) {
730 /* Well, it looks like the drag event was cool.
731 * Let's do something with it */
733 if (!g_ascii_strncasecmp(name
, "file://", 7)) {
734 GError
*converr
= NULL
;
737 /* It looks like we're dealing with a local file. Let's
738 * just try and read it */
739 if(!(tmp
= g_filename_from_uri(name
, NULL
, &converr
))) {
740 purple_debug_error("smiley dnd", "%s\n",
741 (converr
? converr
->message
:
742 "g_filename_from_uri error"));
745 ps
= pidgin_smiley_edit(dialog
->window
, NULL
);
746 do_add_file_cb(tmp
, ps
);
747 if (gtk_image_get_pixbuf(GTK_IMAGE(ps
->smiley_image
)) == NULL
)
748 gtk_dialog_response(GTK_DIALOG(ps
->parent
), GTK_RESPONSE_CANCEL
);
750 } else if (!g_ascii_strncasecmp(name
, "http://", 7)) {
751 /* Oo, a web drag and drop. This is where things
752 * will start to get interesting */
753 purple_util_fetch_url(name
, TRUE
, NULL
, FALSE
, smiley_got_url
, dialog
);
754 } else if (!g_ascii_strncasecmp(name
, "https://", 8)) {
755 /* purple_util_fetch_url() doesn't support HTTPS */
756 char *tmp
= g_strdup(name
+ 1);
762 purple_util_fetch_url(tmp
, TRUE
, NULL
, FALSE
, smiley_got_url
, dialog
);
766 gtk_drag_finish(dc
, TRUE
, FALSE
, t
);
769 gtk_drag_finish(dc
, FALSE
, FALSE
, t
);
772 static GtkWidget
*smiley_list_create(SmileyManager
*dialog
)
775 GtkTreeSelection
*sel
;
776 GtkTargetEntry te
[3] = {
777 {"text/plain", 0, 0},
778 {"text/uri-list", 0, 1},
782 /* Create the list model */
783 dialog
->model
= gtk_list_store_new(N_COL
,
784 GDK_TYPE_PIXBUF
, /* ICON */
785 G_TYPE_STRING
, /* SHORTCUT */
786 G_TYPE_OBJECT
/* SMILEY */
789 /* the actual treeview */
790 treeview
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog
->model
));
791 dialog
->treeview
= treeview
;
792 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview
), TRUE
);
793 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(dialog
->model
), SHORTCUT
, GTK_SORT_ASCENDING
);
794 g_object_unref(G_OBJECT(dialog
->model
));
796 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
797 gtk_tree_selection_set_mode(sel
, GTK_SELECTION_MULTIPLE
);
799 g_signal_connect(G_OBJECT(sel
), "changed", G_CALLBACK(smile_selected_cb
), dialog
);
800 g_signal_connect(G_OBJECT(treeview
), "row_activated", G_CALLBACK(smiley_edit_cb
), dialog
);
802 gtk_drag_dest_set(treeview
,
803 GTK_DEST_DEFAULT_MOTION
| GTK_DEST_DEFAULT_HIGHLIGHT
| GTK_DEST_DEFAULT_DROP
,
804 te
, G_N_ELEMENTS(te
), GDK_ACTION_COPY
| GDK_ACTION_MOVE
);
805 g_signal_connect(G_OBJECT(treeview
), "drag_data_received", G_CALLBACK(smiley_dnd_recv
), dialog
);
807 gtk_widget_show(treeview
);
809 add_columns(treeview
, dialog
);
810 populate_smiley_list(dialog
);
812 return pidgin_make_scrollable(treeview
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
, GTK_SHADOW_IN
, -1, -1);
815 static void refresh_list()
817 populate_smiley_list(smiley_manager
);
820 static void smiley_manager_select_cb(GtkWidget
*widget
, gint resp
, SmileyManager
*dialog
)
822 GtkTreeSelection
*selection
= NULL
;
825 case GTK_RESPONSE_YES
:
826 pidgin_smiley_edit(dialog
->window
, NULL
);
828 case GTK_RESPONSE_NO
:
829 smiley_delete(dialog
);
831 case GTK_RESPONSE_DELETE_EVENT
:
832 case GTK_RESPONSE_CLOSE
:
833 gtk_widget_destroy(dialog
->window
);
834 g_free(smiley_manager
);
835 smiley_manager
= NULL
;
837 case PIDGIN_RESPONSE_MODIFY
:
838 /* Find smiley of selection... */
839 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog
->treeview
));
840 gtk_tree_selection_selected_foreach(selection
, edit_selected_cb
, dialog
);
843 purple_debug_info("gtksmiley", "No valid selection\n");
848 void pidgin_smiley_manager_show(void)
850 SmileyManager
*dialog
;
855 if (smiley_manager
) {
856 gtk_window_present(GTK_WINDOW(smiley_manager
->window
));
860 dialog
= g_new0(SmileyManager
, 1);
861 smiley_manager
= dialog
;
863 dialog
->window
= win
= gtk_dialog_new_with_buttons(
864 _("Custom Smiley Manager"),
866 GTK_DIALOG_DESTROY_WITH_PARENT
,
867 PIDGIN_STOCK_ADD
, GTK_RESPONSE_YES
,
868 PIDGIN_STOCK_MODIFY
, PIDGIN_RESPONSE_MODIFY
,
869 GTK_STOCK_DELETE
, GTK_RESPONSE_NO
,
870 GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
,
873 gtk_window_set_default_size(GTK_WINDOW(win
), 50, 400);
874 gtk_window_set_role(GTK_WINDOW(win
), "custom_smiley_manager");
875 gtk_container_set_border_width(GTK_CONTAINER(win
),PIDGIN_HIG_BORDER
);
876 gtk_dialog_set_response_sensitive(GTK_DIALOG(win
), GTK_RESPONSE_NO
, FALSE
);
877 gtk_dialog_set_response_sensitive(GTK_DIALOG(win
),
878 PIDGIN_RESPONSE_MODIFY
, FALSE
);
880 g_signal_connect(win
, "response", G_CALLBACK(smiley_manager_select_cb
),
884 vbox
= gtk_vbox_new(FALSE
, PIDGIN_HIG_BORDER
);
885 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win
)->vbox
), vbox
);
886 gtk_widget_show(vbox
);
888 /* get the scrolled window with all stuff */
889 sw
= smiley_list_create(dialog
);
890 gtk_box_pack_start(GTK_BOX(vbox
), sw
, TRUE
, TRUE
, 0);
893 gtk_widget_show(win
);