diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-12-11 09:01:05 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-12-11 09:01:05 +0800 |
commit | 19339ece3065266c8d786f052b81ef8ef1988d28 (patch) | |
tree | 5174dcdcc0aecccdd738ccaba872e74a69f114ad /composer | |
parent | 63ce54907cd9f30f046e90be07ead0346ffe7154 (diff) | |
download | gsoc2013-evolution-19339ece3065266c8d786f052b81ef8ef1988d28.tar.gz gsoc2013-evolution-19339ece3065266c8d786f052b81ef8ef1988d28.tar.zst gsoc2013-evolution-19339ece3065266c8d786f052b81ef8ef1988d28.zip |
select_file_attachments now returns a GPtrArray so handle that and loop
2001-12-10 Jeffrey Stedfast <fejj@ximian.com>
* e-msg-composer-attachment-bar.c (add_from_user):
select_file_attachments now returns a GPtrArray so handle that and
loop until we've added all the attachment files.
* e-msg-composer-select-file.c (confirm): Add an evil kludge to
get a list of filenames from the GtkFileSelection widget based on
the label in the history option menu item and the base filenames
of the selected items in the filename clist.
(create_file_selection): Setup the clist to allow multiple
selection.
(file_selection_info_destroy_notify): Destroy the GPtrArray
containing the list of xselected files.
(select_file_internal): Return a GPtrArray of files instead of a
char *.
svn path=/trunk/; revision=14968
Diffstat (limited to 'composer')
-rw-r--r-- | composer/ChangeLog | 17 | ||||
-rw-r--r-- | composer/e-msg-composer-attachment-bar.c | 14 | ||||
-rw-r--r-- | composer/e-msg-composer-select-file.c | 146 | ||||
-rw-r--r-- | composer/e-msg-composer-select-file.h | 4 |
4 files changed, 128 insertions, 53 deletions
diff --git a/composer/ChangeLog b/composer/ChangeLog index b32350552b..2ba38eab15 100644 --- a/composer/ChangeLog +++ b/composer/ChangeLog @@ -1,3 +1,20 @@ +2001-12-10 Jeffrey Stedfast <fejj@ximian.com> + + * e-msg-composer-attachment-bar.c (add_from_user): + select_file_attachments now returns a GPtrArray so handle that and + loop until we've added all the attachment files. + + * e-msg-composer-select-file.c (confirm): Add an evil kludge to + get a list of filenames from the GtkFileSelection widget based on + the label in the history option menu item and the base filenames + of the selected items in the filename clist. + (create_file_selection): Setup the clist to allow multiple + selection. + (file_selection_info_destroy_notify): Destroy the GPtrArray + containing the list of xselected files. + (select_file_internal): Return a GPtrArray of files instead of a + char *. + 2001-12-10 Jon Trowbridge <trow@ximian.com> * e-msg-composer.c (get_file_content): Only execute an executable diff --git a/composer/e-msg-composer-attachment-bar.c b/composer/e-msg-composer-attachment-bar.c index b565ea8788..16c68bf910 100644 --- a/composer/e-msg-composer-attachment-bar.c +++ b/composer/e-msg-composer-attachment-bar.c @@ -442,18 +442,22 @@ static void add_from_user (EMsgComposerAttachmentBar *bar) { EMsgComposer *composer; - char *file_name; + GPtrArray *file_list; gboolean is_inline = FALSE; + int i; composer = E_MSG_COMPOSER (gtk_widget_get_toplevel (GTK_WIDGET (bar))); - file_name = e_msg_composer_select_file_attachment (composer, &is_inline); - if (!file_name) + file_list = e_msg_composer_select_file_attachments (composer, &is_inline); + if (!file_list) return; - add_from_file (bar, file_name, is_inline ? "inline" : "attachment"); + for (i = 0; i < file_list->len; i++) { + add_from_file (bar, file_list->pdata[i], is_inline ? "inline" : "attachment"); + g_free (file_list->pdata[i]); + } - g_free (file_name); + g_ptr_array_free (file_list, TRUE); } diff --git a/composer/e-msg-composer-select-file.c b/composer/e-msg-composer-select-file.c index c3a3957892..d193a7afed 100644 --- a/composer/e-msg-composer-select-file.c +++ b/composer/e-msg-composer-select-file.c @@ -36,31 +36,58 @@ struct _FileSelectionInfo { GtkWidget *widget; GtkToggleButton *inline_checkbox; - char *selected_file; + gboolean multiple; + GPtrArray *selected_files; }; typedef struct _FileSelectionInfo FileSelectionInfo; - static void confirm (FileSelectionInfo *info) { const char *filename; - - filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (info->widget)); - info->selected_file = g_strdup (filename); - + GtkWidget *file_list; + char *path; + GList *l; + + if (info->multiple) { + /* evil kludgy hack cuz the gtk file selector fucking sucks ass */ + path = g_dirname (gtk_file_selection_get_filename (GTK_FILE_SELECTION (info->widget))); + file_list = GTK_FILE_SELECTION (info->widget)->file_list; + l = GTK_CLIST (file_list)->selection; + while (l) { + int row; + + if (!info->selected_files) + info->selected_files = g_ptr_array_new (); + + row = GPOINTER_TO_INT (l->data); + if (gtk_clist_get_text (GTK_CLIST (file_list), row, 0, (char **) &filename)) + g_ptr_array_add (info->selected_files, g_strdup_printf ("%s/%s", path, filename)); + + l = l->next; + } + + g_free (path); + } else { + filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (info->widget)); + if (filename) { + info->selected_files = g_ptr_array_new (); + g_ptr_array_add (info->selected_files, g_strdup (filename)); + } + } + gtk_widget_hide (info->widget); - + gtk_main_quit (); } static void cancel (FileSelectionInfo *info) { - g_assert (info->selected_file == NULL); - + g_assert (info->selected_files == NULL); + gtk_widget_hide (info->widget); - + gtk_main_quit (); } @@ -72,7 +99,7 @@ ok_clicked_cb (GtkWidget *widget, void *data) { FileSelectionInfo *info; - + info = (FileSelectionInfo *) data; confirm (info); } @@ -82,7 +109,7 @@ cancel_clicked_cb (GtkWidget *widget, void *data) { FileSelectionInfo *info; - + info = (FileSelectionInfo *) data; cancel (info); } @@ -93,10 +120,10 @@ delete_event_cb (GtkWidget *widget, void *data) { FileSelectionInfo *info; - + info = (FileSelectionInfo *) data; cancel (info); - + return TRUE; } @@ -104,42 +131,51 @@ delete_event_cb (GtkWidget *widget, /* Setup. */ static FileSelectionInfo * -create_file_selection (EMsgComposer *composer) +create_file_selection (EMsgComposer *composer, gboolean multiple) { FileSelectionInfo *info; GtkWidget *widget; GtkWidget *ok_button; GtkWidget *cancel_button; GtkWidget *inline_checkbox; + GtkWidget *file_list; GtkWidget *box; char *path; - + info = g_new (FileSelectionInfo, 1); - + widget = gtk_file_selection_new (NULL); path = g_strdup_printf ("%s/", g_get_home_dir ()); gtk_file_selection_set_filename (GTK_FILE_SELECTION (widget), path); g_free (path); gtk_window_set_wmclass (GTK_WINDOW (widget), "fileselection", "Evolution:composer"); + + if (multiple) { + file_list = GTK_FILE_SELECTION (widget)->file_list; + gtk_clist_set_selection_mode (GTK_CLIST (file_list), + GTK_SELECTION_MULTIPLE); + } + ok_button = GTK_FILE_SELECTION (widget)->ok_button; cancel_button = GTK_FILE_SELECTION (widget)->cancel_button; - + gtk_signal_connect (GTK_OBJECT (ok_button), "clicked", GTK_SIGNAL_FUNC (ok_clicked_cb), info); gtk_signal_connect (GTK_OBJECT (cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_clicked_cb), info); gtk_signal_connect (GTK_OBJECT (widget), "delete_event", GTK_SIGNAL_FUNC (delete_event_cb), info); - + inline_checkbox = gtk_check_button_new_with_label (_("Suggest automatic display of attachment")); box = gtk_widget_get_ancestor (GTK_FILE_SELECTION (widget)->selection_entry, GTK_TYPE_BOX); gtk_box_pack_end (GTK_BOX (box), inline_checkbox, FALSE, FALSE, 4); - + info->widget = widget; - info->selected_file = NULL; + info->multiple = multiple; + info->selected_files = NULL; info->inline_checkbox = GTK_TOGGLE_BUTTON (inline_checkbox); - + return info; } @@ -147,60 +183,69 @@ static void file_selection_info_destroy_notify (void *data) { FileSelectionInfo *info; - + int i; + info = (FileSelectionInfo *) data; - + if (info->widget != NULL) { gtk_object_unref (GTK_OBJECT (info->widget)); } - g_free (info->selected_file); + + if (info->selected_files) { + for (i = 0; i < info->selected_files->len; i++) + g_free (info->selected_files->pdata[i]); + + g_ptr_array_free (info->selected_files, TRUE); + } + g_free (info); } - -static char * + +static GPtrArray * select_file_internal (EMsgComposer *composer, const char *title, + gboolean multiple, gboolean *inline_p) { FileSelectionInfo *info; - char *retval; - + GPtrArray *files; + g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL); - + info = gtk_object_get_data (GTK_OBJECT (composer), "e-msg-composer-file-selection-info"); - + if (info == NULL) { - info = create_file_selection (composer); + info = create_file_selection (composer, multiple); gtk_object_set_data_full (GTK_OBJECT (composer), "e-msg-composer-file-selection-info", info, file_selection_info_destroy_notify); } - + if (GTK_WIDGET_VISIBLE (info->widget)) return NULL; /* Busy! */ - + gtk_window_set_title (GTK_WINDOW (info->widget), title); if (inline_p) gtk_widget_show (GTK_WIDGET (info->inline_checkbox)); else gtk_widget_hide (GTK_WIDGET (info->inline_checkbox)); gtk_widget_show (info->widget); - + GDK_THREADS_ENTER(); gtk_main (); GDK_THREADS_LEAVE(); - - retval = info->selected_file; - info->selected_file = NULL; - + + files = info->selected_files; + info->selected_files = NULL; + if (inline_p) { *inline_p = gtk_toggle_button_get_active (info->inline_checkbox); gtk_toggle_button_set_active (info->inline_checkbox, FALSE); } - - return retval; + + return files; } /** @@ -218,12 +263,21 @@ char * e_msg_composer_select_file (EMsgComposer *composer, const char *title) { - return select_file_internal (composer, title, NULL); + GPtrArray *files; + char *filename = NULL; + + files = select_file_internal (composer, title, FALSE, NULL); + if (files) { + filename = files->pdata[0]; + g_ptr_array_free (files, FALSE); + } + + return filename; } -char * -e_msg_composer_select_file_attachment (EMsgComposer *composer, - gboolean *inline_p) +GPtrArray * +e_msg_composer_select_file_attachments (EMsgComposer *composer, + gboolean *inline_p) { - return select_file_internal (composer, _("Attach a file"), inline_p); + return select_file_internal (composer, _("Attach a file"), TRUE, inline_p); } diff --git a/composer/e-msg-composer-select-file.h b/composer/e-msg-composer-select-file.h index c3e00d36f9..8216089130 100644 --- a/composer/e-msg-composer-select-file.h +++ b/composer/e-msg-composer-select-file.h @@ -29,7 +29,7 @@ char *e_msg_composer_select_file (EMsgComposer *composer, const char *title); -char *e_msg_composer_select_file_attachment (EMsgComposer *composer, - gboolean *inline_p); +GPtrArray *e_msg_composer_select_file_attachments (EMsgComposer *composer, + gboolean *inline_p); #endif /* E_MSG_COMPOSER_SELECT_FILE_H */ |