Mercurial > pidgin.yaz
annotate finch/gntft.c @ 22144:c85ee90ed861
merge of '43413f6662ecd55ea083fbbacb3f16c01843e655'
and 'a00c23cb7c851de1701db02d50c4f35bdf540595'
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 17 Jan 2008 08:10:50 +0000 |
parents | 3f7e58ae1305 |
children | b99d6d21cd79 |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntft.c GNT File Transfer UI | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
15964
diff
changeset
|
3 * @ingroup finch |
20074
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
4 */ |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
5 |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19680
diff
changeset
|
6 /* finch |
15818 | 7 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
8 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 9 * to list here. Please refer to the COPYRIGHT file distributed with this |
10 * source distribution. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2 of the License, or | |
15 * (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19374
diff
changeset
|
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15818 | 25 */ |
26 #include <gnt.h> | |
27 #include <gntbox.h> | |
28 #include <gntbutton.h> | |
29 #include <gntcheckbox.h> | |
30 #include <gntlabel.h> | |
31 #include <gnttree.h> | |
32 #include "internal.h" | |
33 | |
34 #include "debug.h" | |
35 #include "notify.h" | |
36 #include "ft.h" | |
37 #include "prpl.h" | |
38 #include "util.h" | |
39 | |
40 #include "gntft.h" | |
41 #include "prefs.h" | |
42 | |
15823 | 43 #define FINCHXFER(xfer) \ |
44 (PurpleGntXferUiData *)(xfer)->ui_data | |
15818 | 45 |
46 typedef struct | |
47 { | |
48 gboolean keep_open; | |
49 gboolean auto_clear; | |
50 gint num_transfers; | |
51 | |
52 GntWidget *window; | |
53 GntWidget *tree; | |
54 | |
55 GntWidget *remove_button; | |
56 GntWidget *stop_button; | |
57 GntWidget *close_button; | |
15823 | 58 } PurpleGntXferDialog; |
15818 | 59 |
15823 | 60 static PurpleGntXferDialog *xfer_dialog = NULL; |
15818 | 61 |
62 typedef struct | |
63 { | |
64 time_t last_updated_time; | |
65 gboolean in_list; | |
66 | |
67 char *name; | |
22049
3f7e58ae1305
Don't print 'file transfer complete' message more than once for the same xfer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22048
diff
changeset
|
68 gboolean notified; /* Has the completion of the transfer been notified? */ |
15818 | 69 |
15823 | 70 } PurpleGntXferUiData; |
15818 | 71 |
72 enum | |
73 { | |
74 COLUMN_PROGRESS = 0, | |
75 COLUMN_FILENAME, | |
76 COLUMN_SIZE, | |
77 COLUMN_SPEED, | |
78 COLUMN_REMAINING, | |
79 COLUMN_STATUS, | |
80 NUM_COLUMNS | |
81 }; | |
82 | |
83 | |
84 /************************************************************************** | |
85 * Utility Functions | |
86 **************************************************************************/ | |
87 | |
88 static void | |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
20074
diff
changeset
|
89 update_title_progress(void) |
15818 | 90 { |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
16677
diff
changeset
|
91 GList *list; |
15818 | 92 int num_active_xfers = 0; |
93 guint64 total_bytes_xferred = 0; | |
94 guint64 total_file_size = 0; | |
95 | |
96 if (xfer_dialog == NULL || xfer_dialog->window == NULL) | |
97 return; | |
98 | |
99 /* Find all active transfers */ | |
100 for (list = gnt_tree_get_rows(GNT_TREE(xfer_dialog->tree)); list; list = list->next) { | |
15823 | 101 PurpleXfer *xfer = (PurpleXfer *)list->data; |
15818 | 102 |
15823 | 103 if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_STARTED) { |
15818 | 104 num_active_xfers++; |
15823 | 105 total_bytes_xferred += purple_xfer_get_bytes_sent(xfer); |
106 total_file_size += purple_xfer_get_size(xfer); | |
15818 | 107 } |
108 } | |
109 | |
110 /* Update the title */ | |
111 if (num_active_xfers > 0) { | |
112 gchar *title; | |
113 int total_pct = 0; | |
114 | |
115 if (total_file_size > 0) { | |
116 total_pct = 100 * total_bytes_xferred / total_file_size; | |
117 } | |
118 | |
119 title = g_strdup_printf(_("File Transfers - %d%% of %d files"), | |
120 total_pct, num_active_xfers); | |
121 gnt_screen_rename_widget((xfer_dialog->window), title); | |
122 g_free(title); | |
123 } else { | |
124 gnt_screen_rename_widget((xfer_dialog->window), _("File Transfers")); | |
125 } | |
126 } | |
127 | |
128 | |
129 /************************************************************************** | |
130 * Callbacks | |
131 **************************************************************************/ | |
132 static void | |
133 toggle_keep_open_cb(GntWidget *w) | |
134 { | |
135 xfer_dialog->keep_open = !xfer_dialog->keep_open; | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
136 purple_prefs_set_bool("/finch/filetransfer/keep_open", |
15818 | 137 xfer_dialog->keep_open); |
138 } | |
139 | |
140 static void | |
141 toggle_clear_finished_cb(GntWidget *w) | |
142 { | |
143 xfer_dialog->auto_clear = !xfer_dialog->auto_clear; | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
144 purple_prefs_set_bool("/finch/filetransfer/clear_finished", |
15818 | 145 xfer_dialog->auto_clear); |
22048
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
146 if (xfer_dialog->auto_clear) { |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
147 GList *iter = purple_xfers_get_all(); |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
148 while (iter) { |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
149 PurpleXfer *xfer = iter->data; |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
150 iter = iter->next; |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
151 if (purple_xfer_is_completed(xfer) || purple_xfer_is_canceled(xfer)) |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
152 finch_xfer_dialog_remove_xfer(xfer); |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
153 } |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
154 } |
15818 | 155 } |
156 | |
157 static void | |
158 remove_button_cb(GntButton *button) | |
159 { | |
15823 | 160 PurpleXfer *selected_xfer = gnt_tree_get_selection_data(GNT_TREE(xfer_dialog->tree)); |
22048
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
161 if (selected_xfer && (purple_xfer_is_completed(selected_xfer) || |
6704629dc478
Remove the completed/cancelled xfers when 'Clear finished transfers' is selected. (Did anyone notice our 'purple_xfer_is_canceled' is typoed?)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
162 purple_xfer_is_canceled(selected_xfer))) { |
15818 | 163 finch_xfer_dialog_remove_xfer(selected_xfer); |
164 } | |
165 } | |
166 | |
167 static void | |
168 stop_button_cb(GntButton *button) | |
169 { | |
15823 | 170 PurpleXfer *selected_xfer = gnt_tree_get_selection_data(GNT_TREE(xfer_dialog->tree)); |
15942
ee397e53d9ce
allow cancellation of transfers waiting to be accepted
Richard Nelson <wabz@pidgin.im>
parents:
15871
diff
changeset
|
171 if (selected_xfer && selected_xfer->status != PURPLE_XFER_STATUS_CANCEL_LOCAL && |
ee397e53d9ce
allow cancellation of transfers waiting to be accepted
Richard Nelson <wabz@pidgin.im>
parents:
15871
diff
changeset
|
172 selected_xfer->status != PURPLE_XFER_STATUS_CANCEL_REMOTE && |
ee397e53d9ce
allow cancellation of transfers waiting to be accepted
Richard Nelson <wabz@pidgin.im>
parents:
15871
diff
changeset
|
173 selected_xfer->status != PURPLE_XFER_STATUS_DONE) |
15823 | 174 purple_xfer_cancel_local(selected_xfer); |
15818 | 175 } |
176 | |
177 /************************************************************************** | |
178 * Dialog Building Functions | |
179 **************************************************************************/ | |
180 | |
181 | |
182 void | |
183 finch_xfer_dialog_new(void) | |
184 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
16677
diff
changeset
|
185 GList *iter; |
15818 | 186 GntWidget *window; |
187 GntWidget *bbox; | |
188 GntWidget *button; | |
189 GntWidget *checkbox; | |
190 GntWidget *tree; | |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
191 int widths[] = {8, 12, 8, 8, 8, 8, -1}; |
15818 | 192 |
193 if (!xfer_dialog) | |
15823 | 194 xfer_dialog = g_new0(PurpleGntXferDialog, 1); |
15818 | 195 |
196 xfer_dialog->keep_open = | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
197 purple_prefs_get_bool("/finch/filetransfer/keep_open"); |
15818 | 198 xfer_dialog->auto_clear = |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
199 purple_prefs_get_bool("/finch/filetransfer/clear_finished"); |
15818 | 200 |
201 /* Create the window. */ | |
202 xfer_dialog->window = window = gnt_vbox_new(FALSE); | |
203 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(finch_xfer_dialog_destroy), NULL); | |
204 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
205 gnt_box_set_title(GNT_BOX(window), _("File Transfers")); | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
206 gnt_box_set_fill(GNT_BOX(window), TRUE); |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
207 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); |
15818 | 208 |
209 xfer_dialog->tree = tree = gnt_tree_new_with_columns(NUM_COLUMNS); | |
210 gnt_tree_set_column_titles(GNT_TREE(tree), _("Progress"), _("Filename"), _("Size"), _("Speed"), _("Remaining"), _("Status")); | |
18404
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
211 gnt_tree_set_column_width_ratio(GNT_TREE(tree), widths); |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
212 gnt_tree_set_column_resizable(GNT_TREE(tree), COLUMN_PROGRESS, FALSE); |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
213 gnt_tree_set_column_resizable(GNT_TREE(tree), COLUMN_SIZE, FALSE); |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
214 gnt_tree_set_column_resizable(GNT_TREE(tree), COLUMN_SPEED, FALSE); |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
215 gnt_tree_set_column_resizable(GNT_TREE(tree), COLUMN_REMAINING, FALSE); |
9a0f99ea664d
Resize tree-columns nicely when the tree is resized. We can tell it to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
216 gnt_widget_set_size(tree, 70, -1); |
15818 | 217 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); |
218 gnt_box_add_widget(GNT_BOX(window), tree); | |
15942
ee397e53d9ce
allow cancellation of transfers waiting to be accepted
Richard Nelson <wabz@pidgin.im>
parents:
15871
diff
changeset
|
219 |
15818 | 220 checkbox = gnt_check_box_new( _("Close this window when all transfers finish")); |
221 gnt_check_box_set_checked(GNT_CHECK_BOX(checkbox), | |
222 !xfer_dialog->keep_open); | |
223 g_signal_connect(G_OBJECT(checkbox), "toggled", | |
224 G_CALLBACK(toggle_keep_open_cb), NULL); | |
225 gnt_box_add_widget(GNT_BOX(window), checkbox); | |
226 | |
227 checkbox = gnt_check_box_new(_("Clear finished transfers")); | |
228 gnt_check_box_set_checked(GNT_CHECK_BOX(checkbox), | |
229 xfer_dialog->auto_clear); | |
230 g_signal_connect(G_OBJECT(checkbox), "toggled", | |
231 G_CALLBACK(toggle_clear_finished_cb), NULL); | |
232 gnt_box_add_widget(GNT_BOX(window), checkbox); | |
233 | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
234 bbox = gnt_hbox_new(FALSE); |
15818 | 235 |
236 xfer_dialog->remove_button = button = gnt_button_new(_("Remove")); | |
237 g_signal_connect(G_OBJECT(button), "activate", | |
238 G_CALLBACK(remove_button_cb), NULL); | |
239 gnt_box_add_widget(GNT_BOX(bbox), button); | |
240 | |
241 xfer_dialog->stop_button = button = gnt_button_new(_("Stop")); | |
242 g_signal_connect(G_OBJECT(button), "activate", | |
243 G_CALLBACK(stop_button_cb), NULL); | |
244 gnt_box_add_widget(GNT_BOX(bbox), button); | |
245 | |
246 xfer_dialog->close_button = button = gnt_button_new(_("Close")); | |
247 g_signal_connect(G_OBJECT(button), "activate", | |
248 G_CALLBACK(finch_xfer_dialog_destroy), NULL); | |
249 gnt_box_add_widget(GNT_BOX(bbox), button); | |
250 | |
251 gnt_box_add_widget(GNT_BOX(window), bbox); | |
252 | |
15823 | 253 for (iter = purple_xfers_get_all(); iter; iter = iter->next) { |
254 PurpleXfer *xfer = (PurpleXfer *)iter->data; | |
255 PurpleGntXferUiData *data = FINCHXFER(xfer); | |
15818 | 256 if (data->in_list) { |
257 finch_xfer_dialog_add_xfer(xfer); | |
258 finch_xfer_dialog_update_xfer(xfer); | |
259 gnt_tree_set_selected(GNT_TREE(tree), xfer); | |
260 } | |
261 } | |
262 gnt_widget_show(xfer_dialog->window); | |
263 } | |
264 | |
265 void | |
266 finch_xfer_dialog_destroy() | |
267 { | |
268 gnt_widget_destroy(xfer_dialog->window); | |
269 g_free(xfer_dialog); | |
270 xfer_dialog = NULL; | |
271 } | |
272 | |
273 void | |
274 finch_xfer_dialog_show() | |
275 { | |
276 if (xfer_dialog == NULL) | |
277 finch_xfer_dialog_new(); | |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18129
diff
changeset
|
278 else |
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18129
diff
changeset
|
279 gnt_window_present(xfer_dialog->window); |
15818 | 280 } |
281 | |
282 void | |
15823 | 283 finch_xfer_dialog_add_xfer(PurpleXfer *xfer) |
15818 | 284 { |
15823 | 285 PurpleGntXferUiData *data; |
286 PurpleXferType type; | |
15818 | 287 char *size_str, *remaining_str; |
288 char *lfilename, *utf8; | |
289 | |
290 g_return_if_fail(xfer_dialog != NULL); | |
291 g_return_if_fail(xfer != NULL); | |
292 | |
15823 | 293 purple_xfer_ref(xfer); |
15818 | 294 |
15823 | 295 data = FINCHXFER(xfer); |
15818 | 296 data->in_list = TRUE; |
297 | |
298 finch_xfer_dialog_show(); | |
299 | |
300 data->last_updated_time = 0; | |
301 | |
15823 | 302 type = purple_xfer_get_type(xfer); |
15818 | 303 |
15823 | 304 size_str = purple_str_size_to_units(purple_xfer_get_size(xfer)); |
305 remaining_str = purple_str_size_to_units(purple_xfer_get_bytes_remaining(xfer)); | |
15818 | 306 |
15823 | 307 lfilename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); |
15818 | 308 utf8 = g_filename_to_utf8(lfilename, -1, NULL, NULL, NULL); |
309 g_free(lfilename); | |
310 lfilename = utf8; | |
311 gnt_tree_add_row_last(GNT_TREE(xfer_dialog->tree), xfer, | |
312 gnt_tree_create_row(GNT_TREE(xfer_dialog->tree), | |
15823 | 313 "0.0", (type == PURPLE_XFER_RECEIVE) ? purple_xfer_get_filename(xfer) : lfilename, |
15818 | 314 size_str, "0.0", "",_("Waiting for transfer to begin")), NULL); |
315 g_free(lfilename); | |
316 | |
317 g_free(size_str); | |
318 g_free(remaining_str); | |
319 | |
320 xfer_dialog->num_transfers++; | |
321 | |
322 update_title_progress(); | |
323 } | |
324 | |
325 void | |
15823 | 326 finch_xfer_dialog_remove_xfer(PurpleXfer *xfer) |
15818 | 327 { |
15823 | 328 PurpleGntXferUiData *data; |
15818 | 329 |
330 g_return_if_fail(xfer_dialog != NULL); | |
331 g_return_if_fail(xfer != NULL); | |
332 | |
15823 | 333 data = FINCHXFER(xfer); |
15818 | 334 |
335 if (data == NULL) | |
336 return; | |
337 | |
338 if (!data->in_list) | |
339 return; | |
340 | |
341 data->in_list = FALSE; | |
342 | |
343 gnt_tree_remove(GNT_TREE(xfer_dialog->tree), xfer); | |
344 | |
345 xfer_dialog->num_transfers--; | |
346 | |
347 if (xfer_dialog->num_transfers == 0 && !xfer_dialog->keep_open) | |
348 finch_xfer_dialog_destroy(); | |
349 else | |
350 update_title_progress(); | |
15823 | 351 purple_xfer_unref(xfer); |
15818 | 352 } |
353 | |
354 void | |
15823 | 355 finch_xfer_dialog_cancel_xfer(PurpleXfer *xfer) |
15818 | 356 { |
15823 | 357 PurpleGntXferUiData *data; |
15818 | 358 const gchar *status; |
359 | |
360 g_return_if_fail(xfer_dialog != NULL); | |
361 g_return_if_fail(xfer != NULL); | |
362 | |
15823 | 363 data = FINCHXFER(xfer); |
15818 | 364 |
365 if (data == NULL) | |
366 return; | |
367 | |
368 if (!data->in_list) | |
369 return; | |
370 | |
15823 | 371 if ((purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) && (xfer_dialog->auto_clear)) { |
15818 | 372 finch_xfer_dialog_remove_xfer(xfer); |
373 return; | |
374 } | |
375 | |
15823 | 376 data = FINCHXFER(xfer); |
15818 | 377 |
378 update_title_progress(); | |
379 | |
15823 | 380 if (purple_xfer_is_canceled(xfer)) |
15818 | 381 status = _("Canceled"); |
382 else | |
383 status = _("Failed"); | |
384 | |
385 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, status); | |
386 } | |
387 | |
388 void | |
15823 | 389 finch_xfer_dialog_update_xfer(PurpleXfer *xfer) |
15818 | 390 { |
15823 | 391 PurpleGntXferUiData *data; |
15818 | 392 char *size_str, *remaining_str; |
393 time_t current_time; | |
394 char prog_str[5]; | |
395 double kb_sent, kb_rem; | |
396 double kbps = 0.0; | |
397 time_t elapsed, now; | |
398 char *kbsec; | |
399 | |
400 if (xfer->end_time != 0) | |
401 now = xfer->end_time; | |
402 else | |
403 now = time(NULL); | |
404 | |
15823 | 405 kb_sent = purple_xfer_get_bytes_sent(xfer) / 1024.0; |
406 kb_rem = purple_xfer_get_bytes_remaining(xfer) / 1024.0; | |
15818 | 407 elapsed = (xfer->start_time > 0 ? now - xfer->start_time : 0); |
408 kbps = (elapsed > 0 ? (kb_sent / elapsed) : 0); | |
409 | |
410 g_return_if_fail(xfer_dialog != NULL); | |
411 g_return_if_fail(xfer != NULL); | |
412 | |
15823 | 413 if ((data = FINCHXFER(xfer)) == NULL) |
15818 | 414 return; |
415 | |
22049
3f7e58ae1305
Don't print 'file transfer complete' message more than once for the same xfer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22048
diff
changeset
|
416 if (data->in_list == FALSE || data->notified) |
15818 | 417 return; |
418 | |
419 current_time = time(NULL); | |
420 if (((current_time - data->last_updated_time) == 0) && | |
15823 | 421 (!purple_xfer_is_completed(xfer))) { |
15818 | 422 /* Don't update the window more than once per second */ |
423 return; | |
424 } | |
425 data->last_updated_time = current_time; | |
426 | |
15823 | 427 size_str = purple_str_size_to_units(purple_xfer_get_size(xfer)); |
428 remaining_str = purple_str_size_to_units(purple_xfer_get_bytes_remaining(xfer)); | |
18129
16f3919b78f5
Use the IEC binary units to match our math.
Richard Laager <rlaager@wiktel.com>
parents:
18118
diff
changeset
|
429 kbsec = g_strdup_printf(_("%.2f KiB/s"), kbps); |
15818 | 430 |
431 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_PROGRESS, | |
15823 | 432 g_ascii_dtostr(prog_str, sizeof(prog_str), purple_xfer_get_progress(xfer) * 100.)); |
15818 | 433 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SIZE, size_str); |
434 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_REMAINING, remaining_str); | |
435 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SPEED, kbsec); | |
436 g_free(size_str); | |
437 g_free(remaining_str); | |
15964 | 438 g_free(kbsec); |
15823 | 439 if (purple_xfer_is_completed(xfer)) { |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
440 char *msg = g_strdup_printf(_("The file was saved as %s."), purple_xfer_get_local_filename(xfer)); |
15818 | 441 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, _("Finished")); |
15942
ee397e53d9ce
allow cancellation of transfers waiting to be accepted
Richard Nelson <wabz@pidgin.im>
parents:
15871
diff
changeset
|
442 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_REMAINING, _("Finished")); |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
443 purple_xfer_conversation_write(xfer, msg, FALSE); |
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
444 g_free(msg); |
22049
3f7e58ae1305
Don't print 'file transfer complete' message more than once for the same xfer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22048
diff
changeset
|
445 data->notified = TRUE; |
15818 | 446 } else { |
447 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, _("Transferring")); | |
448 } | |
449 | |
450 update_title_progress(); | |
451 | |
15823 | 452 if (purple_xfer_is_completed(xfer) && xfer_dialog->auto_clear) |
15818 | 453 finch_xfer_dialog_remove_xfer(xfer); |
454 } | |
455 | |
456 /************************************************************************** | |
457 * File Transfer UI Ops | |
458 **************************************************************************/ | |
459 static void | |
15823 | 460 finch_xfer_new_xfer(PurpleXfer *xfer) |
15818 | 461 { |
15823 | 462 PurpleGntXferUiData *data; |
15818 | 463 |
464 /* This is where we're setting xfer->ui_data for the first time. */ | |
15823 | 465 data = g_new0(PurpleGntXferUiData, 1); |
15818 | 466 xfer->ui_data = data; |
467 } | |
468 | |
469 static void | |
15823 | 470 finch_xfer_destroy(PurpleXfer *xfer) |
15818 | 471 { |
15823 | 472 PurpleGntXferUiData *data; |
15818 | 473 |
15823 | 474 data = FINCHXFER(xfer); |
15818 | 475 if (data) { |
476 g_free(data->name); | |
477 g_free(data); | |
478 xfer->ui_data = NULL; | |
479 } | |
480 } | |
481 | |
482 static void | |
15823 | 483 finch_xfer_add_xfer(PurpleXfer *xfer) |
15818 | 484 { |
485 if (!xfer_dialog) | |
486 finch_xfer_dialog_new(); | |
487 | |
488 finch_xfer_dialog_add_xfer(xfer); | |
489 gnt_tree_set_selected(GNT_TREE(xfer_dialog->tree), xfer); | |
490 } | |
491 | |
492 static void | |
15823 | 493 finch_xfer_update_progress(PurpleXfer *xfer, double percent) |
15818 | 494 { |
495 if (xfer_dialog) | |
496 finch_xfer_dialog_update_xfer(xfer); | |
497 } | |
498 | |
499 static void | |
15823 | 500 finch_xfer_cancel_local(PurpleXfer *xfer) |
15818 | 501 { |
502 if (xfer_dialog) | |
503 finch_xfer_dialog_cancel_xfer(xfer); | |
504 } | |
505 | |
506 static void | |
15823 | 507 finch_xfer_cancel_remote(PurpleXfer *xfer) |
15818 | 508 { |
509 if (xfer_dialog) | |
510 finch_xfer_dialog_cancel_xfer(xfer); | |
511 } | |
512 | |
15823 | 513 static PurpleXferUiOps ops = |
15818 | 514 { |
515 finch_xfer_new_xfer, | |
516 finch_xfer_destroy, | |
517 finch_xfer_add_xfer, | |
518 finch_xfer_update_progress, | |
519 finch_xfer_cancel_local, | |
16677
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
520 finch_xfer_cancel_remote, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
521 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
522 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
523 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
524 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
525 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
526 NULL |
15818 | 527 }; |
528 | |
529 /************************************************************************** | |
530 * GNT File Transfer API | |
531 **************************************************************************/ | |
532 void | |
533 finch_xfers_init(void) | |
534 { | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
535 purple_prefs_add_none("/finch/filetransfer"); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
536 purple_prefs_add_bool("/finch/filetransfer/clear_finished", TRUE); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
537 purple_prefs_add_bool("/finch/filetransfer/keep_open", FALSE); |
15818 | 538 } |
539 | |
540 void | |
541 finch_xfers_uninit(void) | |
542 { | |
543 if (xfer_dialog != NULL) | |
544 finch_xfer_dialog_destroy(); | |
545 } | |
546 | |
15823 | 547 PurpleXferUiOps * |
15818 | 548 finch_xfers_get_ui_ops(void) |
549 { | |
550 return &ops; | |
551 } |