Mercurial > pidgin.yaz
annotate finch/gntft.c @ 21731:ea32d04d87dd
Fix a few assertion failures:
* Don't cal gtk_entry_get_text(GTK_ENTRY(gtkconv->u.chat->topic_text))
if gtkconv->u.chat->topic_text is NULL, which happens for AIM group
chats
* Don't allow double-clicking on the tab for an AIM group chat to set
the topic because AIM doesn't support chat room topics
* Don't call gtk_entry_set_text(GTK_ENTRY(entry), text) when
initializing the entry and text is NULL
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 02 Dec 2007 21:46:32 +0000 |
parents | 6bf32c9e15a7 |
children | c38d72677c8a 60f5abc6cf0c |
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; | |
68 | |
15823 | 69 } PurpleGntXferUiData; |
15818 | 70 |
71 enum | |
72 { | |
73 COLUMN_PROGRESS = 0, | |
74 COLUMN_FILENAME, | |
75 COLUMN_SIZE, | |
76 COLUMN_SPEED, | |
77 COLUMN_REMAINING, | |
78 COLUMN_STATUS, | |
79 NUM_COLUMNS | |
80 }; | |
81 | |
82 | |
83 /************************************************************************** | |
84 * Utility Functions | |
85 **************************************************************************/ | |
86 | |
87 static void | |
88 update_title_progress() | |
89 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
16677
diff
changeset
|
90 GList *list; |
15818 | 91 int num_active_xfers = 0; |
92 guint64 total_bytes_xferred = 0; | |
93 guint64 total_file_size = 0; | |
94 | |
95 if (xfer_dialog == NULL || xfer_dialog->window == NULL) | |
96 return; | |
97 | |
98 /* Find all active transfers */ | |
99 for (list = gnt_tree_get_rows(GNT_TREE(xfer_dialog->tree)); list; list = list->next) { | |
15823 | 100 PurpleXfer *xfer = (PurpleXfer *)list->data; |
15818 | 101 |
15823 | 102 if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_STARTED) { |
15818 | 103 num_active_xfers++; |
15823 | 104 total_bytes_xferred += purple_xfer_get_bytes_sent(xfer); |
105 total_file_size += purple_xfer_get_size(xfer); | |
15818 | 106 } |
107 } | |
108 | |
109 /* Update the title */ | |
110 if (num_active_xfers > 0) { | |
111 gchar *title; | |
112 int total_pct = 0; | |
113 | |
114 if (total_file_size > 0) { | |
115 total_pct = 100 * total_bytes_xferred / total_file_size; | |
116 } | |
117 | |
118 title = g_strdup_printf(_("File Transfers - %d%% of %d files"), | |
119 total_pct, num_active_xfers); | |
120 gnt_screen_rename_widget((xfer_dialog->window), title); | |
121 g_free(title); | |
122 } else { | |
123 gnt_screen_rename_widget((xfer_dialog->window), _("File Transfers")); | |
124 } | |
125 } | |
126 | |
127 | |
128 /************************************************************************** | |
129 * Callbacks | |
130 **************************************************************************/ | |
131 static void | |
132 toggle_keep_open_cb(GntWidget *w) | |
133 { | |
134 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
|
135 purple_prefs_set_bool("/finch/filetransfer/keep_open", |
15818 | 136 xfer_dialog->keep_open); |
137 } | |
138 | |
139 static void | |
140 toggle_clear_finished_cb(GntWidget *w) | |
141 { | |
142 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
|
143 purple_prefs_set_bool("/finch/filetransfer/clear_finished", |
15818 | 144 xfer_dialog->auto_clear); |
145 } | |
146 | |
147 static void | |
148 remove_button_cb(GntButton *button) | |
149 { | |
15823 | 150 PurpleXfer *selected_xfer = gnt_tree_get_selection_data(GNT_TREE(xfer_dialog->tree)); |
151 if (selected_xfer && (selected_xfer->status == PURPLE_XFER_STATUS_CANCEL_LOCAL || | |
152 selected_xfer->status == PURPLE_XFER_STATUS_CANCEL_REMOTE || | |
153 selected_xfer->status == PURPLE_XFER_STATUS_DONE)) { | |
15818 | 154 finch_xfer_dialog_remove_xfer(selected_xfer); |
155 } | |
156 } | |
157 | |
158 static void | |
159 stop_button_cb(GntButton *button) | |
160 { | |
15823 | 161 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
|
162 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
|
163 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
|
164 selected_xfer->status != PURPLE_XFER_STATUS_DONE) |
15823 | 165 purple_xfer_cancel_local(selected_xfer); |
15818 | 166 } |
167 | |
168 /************************************************************************** | |
169 * Dialog Building Functions | |
170 **************************************************************************/ | |
171 | |
172 | |
173 void | |
174 finch_xfer_dialog_new(void) | |
175 { | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
16677
diff
changeset
|
176 GList *iter; |
15818 | 177 GntWidget *window; |
178 GntWidget *bbox; | |
179 GntWidget *button; | |
180 GntWidget *checkbox; | |
181 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
|
182 int widths[] = {8, 12, 8, 8, 8, 8, -1}; |
15818 | 183 |
184 if (!xfer_dialog) | |
15823 | 185 xfer_dialog = g_new0(PurpleGntXferDialog, 1); |
15818 | 186 |
187 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
|
188 purple_prefs_get_bool("/finch/filetransfer/keep_open"); |
15818 | 189 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
|
190 purple_prefs_get_bool("/finch/filetransfer/clear_finished"); |
15818 | 191 |
192 /* Create the window. */ | |
193 xfer_dialog->window = window = gnt_vbox_new(FALSE); | |
194 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(finch_xfer_dialog_destroy), NULL); | |
195 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
196 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
|
197 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
|
198 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); |
15818 | 199 |
200 xfer_dialog->tree = tree = gnt_tree_new_with_columns(NUM_COLUMNS); | |
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 gnt_widget_set_size(tree, 70, -1); |
15818 | 208 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); |
209 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
|
210 |
15818 | 211 checkbox = gnt_check_box_new( _("Close this window when all transfers finish")); |
212 gnt_check_box_set_checked(GNT_CHECK_BOX(checkbox), | |
213 !xfer_dialog->keep_open); | |
214 g_signal_connect(G_OBJECT(checkbox), "toggled", | |
215 G_CALLBACK(toggle_keep_open_cb), NULL); | |
216 gnt_box_add_widget(GNT_BOX(window), checkbox); | |
217 | |
218 checkbox = gnt_check_box_new(_("Clear finished transfers")); | |
219 gnt_check_box_set_checked(GNT_CHECK_BOX(checkbox), | |
220 xfer_dialog->auto_clear); | |
221 g_signal_connect(G_OBJECT(checkbox), "toggled", | |
222 G_CALLBACK(toggle_clear_finished_cb), NULL); | |
223 gnt_box_add_widget(GNT_BOX(window), checkbox); | |
224 | |
19374
d65ce3df5be2
Make some of the dialogs look and behave more like each other.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
225 bbox = gnt_hbox_new(FALSE); |
15818 | 226 |
227 xfer_dialog->remove_button = button = gnt_button_new(_("Remove")); | |
228 g_signal_connect(G_OBJECT(button), "activate", | |
229 G_CALLBACK(remove_button_cb), NULL); | |
230 gnt_box_add_widget(GNT_BOX(bbox), button); | |
231 | |
232 xfer_dialog->stop_button = button = gnt_button_new(_("Stop")); | |
233 g_signal_connect(G_OBJECT(button), "activate", | |
234 G_CALLBACK(stop_button_cb), NULL); | |
235 gnt_box_add_widget(GNT_BOX(bbox), button); | |
236 | |
237 xfer_dialog->close_button = button = gnt_button_new(_("Close")); | |
238 g_signal_connect(G_OBJECT(button), "activate", | |
239 G_CALLBACK(finch_xfer_dialog_destroy), NULL); | |
240 gnt_box_add_widget(GNT_BOX(bbox), button); | |
241 | |
242 gnt_box_add_widget(GNT_BOX(window), bbox); | |
243 | |
15823 | 244 for (iter = purple_xfers_get_all(); iter; iter = iter->next) { |
245 PurpleXfer *xfer = (PurpleXfer *)iter->data; | |
246 PurpleGntXferUiData *data = FINCHXFER(xfer); | |
15818 | 247 if (data->in_list) { |
248 finch_xfer_dialog_add_xfer(xfer); | |
249 finch_xfer_dialog_update_xfer(xfer); | |
250 gnt_tree_set_selected(GNT_TREE(tree), xfer); | |
251 } | |
252 } | |
253 gnt_widget_show(xfer_dialog->window); | |
254 } | |
255 | |
256 void | |
257 finch_xfer_dialog_destroy() | |
258 { | |
259 gnt_widget_destroy(xfer_dialog->window); | |
260 g_free(xfer_dialog); | |
261 xfer_dialog = NULL; | |
262 } | |
263 | |
264 void | |
265 finch_xfer_dialog_show() | |
266 { | |
267 if (xfer_dialog == NULL) | |
268 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
|
269 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
|
270 gnt_window_present(xfer_dialog->window); |
15818 | 271 } |
272 | |
273 void | |
15823 | 274 finch_xfer_dialog_add_xfer(PurpleXfer *xfer) |
15818 | 275 { |
15823 | 276 PurpleGntXferUiData *data; |
277 PurpleXferType type; | |
15818 | 278 char *size_str, *remaining_str; |
279 char *lfilename, *utf8; | |
280 | |
281 g_return_if_fail(xfer_dialog != NULL); | |
282 g_return_if_fail(xfer != NULL); | |
283 | |
15823 | 284 purple_xfer_ref(xfer); |
15818 | 285 |
15823 | 286 data = FINCHXFER(xfer); |
15818 | 287 data->in_list = TRUE; |
288 | |
289 finch_xfer_dialog_show(); | |
290 | |
291 data->last_updated_time = 0; | |
292 | |
15823 | 293 type = purple_xfer_get_type(xfer); |
15818 | 294 |
15823 | 295 size_str = purple_str_size_to_units(purple_xfer_get_size(xfer)); |
296 remaining_str = purple_str_size_to_units(purple_xfer_get_bytes_remaining(xfer)); | |
15818 | 297 |
15823 | 298 lfilename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); |
15818 | 299 utf8 = g_filename_to_utf8(lfilename, -1, NULL, NULL, NULL); |
300 g_free(lfilename); | |
301 lfilename = utf8; | |
302 gnt_tree_add_row_last(GNT_TREE(xfer_dialog->tree), xfer, | |
303 gnt_tree_create_row(GNT_TREE(xfer_dialog->tree), | |
15823 | 304 "0.0", (type == PURPLE_XFER_RECEIVE) ? purple_xfer_get_filename(xfer) : lfilename, |
15818 | 305 size_str, "0.0", "",_("Waiting for transfer to begin")), NULL); |
306 g_free(lfilename); | |
307 | |
308 g_free(size_str); | |
309 g_free(remaining_str); | |
310 | |
311 xfer_dialog->num_transfers++; | |
312 | |
313 update_title_progress(); | |
314 } | |
315 | |
316 void | |
15823 | 317 finch_xfer_dialog_remove_xfer(PurpleXfer *xfer) |
15818 | 318 { |
15823 | 319 PurpleGntXferUiData *data; |
15818 | 320 |
321 g_return_if_fail(xfer_dialog != NULL); | |
322 g_return_if_fail(xfer != NULL); | |
323 | |
15823 | 324 data = FINCHXFER(xfer); |
15818 | 325 |
326 if (data == NULL) | |
327 return; | |
328 | |
329 if (!data->in_list) | |
330 return; | |
331 | |
332 data->in_list = FALSE; | |
333 | |
334 gnt_tree_remove(GNT_TREE(xfer_dialog->tree), xfer); | |
335 | |
336 xfer_dialog->num_transfers--; | |
337 | |
338 if (xfer_dialog->num_transfers == 0 && !xfer_dialog->keep_open) | |
339 finch_xfer_dialog_destroy(); | |
340 else | |
341 update_title_progress(); | |
15823 | 342 purple_xfer_unref(xfer); |
15818 | 343 } |
344 | |
345 void | |
15823 | 346 finch_xfer_dialog_cancel_xfer(PurpleXfer *xfer) |
15818 | 347 { |
15823 | 348 PurpleGntXferUiData *data; |
15818 | 349 const gchar *status; |
350 | |
351 g_return_if_fail(xfer_dialog != NULL); | |
352 g_return_if_fail(xfer != NULL); | |
353 | |
15823 | 354 data = FINCHXFER(xfer); |
15818 | 355 |
356 if (data == NULL) | |
357 return; | |
358 | |
359 if (!data->in_list) | |
360 return; | |
361 | |
15823 | 362 if ((purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) && (xfer_dialog->auto_clear)) { |
15818 | 363 finch_xfer_dialog_remove_xfer(xfer); |
364 return; | |
365 } | |
366 | |
15823 | 367 data = FINCHXFER(xfer); |
15818 | 368 |
369 update_title_progress(); | |
370 | |
15823 | 371 if (purple_xfer_is_canceled(xfer)) |
15818 | 372 status = _("Canceled"); |
373 else | |
374 status = _("Failed"); | |
375 | |
376 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, status); | |
377 } | |
378 | |
379 void | |
15823 | 380 finch_xfer_dialog_update_xfer(PurpleXfer *xfer) |
15818 | 381 { |
15823 | 382 PurpleGntXferUiData *data; |
15818 | 383 char *size_str, *remaining_str; |
384 time_t current_time; | |
385 char prog_str[5]; | |
386 double kb_sent, kb_rem; | |
387 double kbps = 0.0; | |
388 time_t elapsed, now; | |
389 char *kbsec; | |
390 | |
391 if (xfer->end_time != 0) | |
392 now = xfer->end_time; | |
393 else | |
394 now = time(NULL); | |
395 | |
15823 | 396 kb_sent = purple_xfer_get_bytes_sent(xfer) / 1024.0; |
397 kb_rem = purple_xfer_get_bytes_remaining(xfer) / 1024.0; | |
15818 | 398 elapsed = (xfer->start_time > 0 ? now - xfer->start_time : 0); |
399 kbps = (elapsed > 0 ? (kb_sent / elapsed) : 0); | |
400 | |
401 g_return_if_fail(xfer_dialog != NULL); | |
402 g_return_if_fail(xfer != NULL); | |
403 | |
15823 | 404 if ((data = FINCHXFER(xfer)) == NULL) |
15818 | 405 return; |
406 | |
407 if (data->in_list == FALSE) | |
408 return; | |
409 | |
410 current_time = time(NULL); | |
411 if (((current_time - data->last_updated_time) == 0) && | |
15823 | 412 (!purple_xfer_is_completed(xfer))) { |
15818 | 413 /* Don't update the window more than once per second */ |
414 return; | |
415 } | |
416 data->last_updated_time = current_time; | |
417 | |
15823 | 418 size_str = purple_str_size_to_units(purple_xfer_get_size(xfer)); |
419 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
|
420 kbsec = g_strdup_printf(_("%.2f KiB/s"), kbps); |
15818 | 421 |
422 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_PROGRESS, | |
15823 | 423 g_ascii_dtostr(prog_str, sizeof(prog_str), purple_xfer_get_progress(xfer) * 100.)); |
15818 | 424 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SIZE, size_str); |
425 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_REMAINING, remaining_str); | |
426 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SPEED, kbsec); | |
427 g_free(size_str); | |
428 g_free(remaining_str); | |
15964 | 429 g_free(kbsec); |
15823 | 430 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
|
431 char *msg = g_strdup_printf(_("The file was saved as %s."), purple_xfer_get_local_filename(xfer)); |
15818 | 432 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
|
433 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
|
434 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
|
435 g_free(msg); |
15818 | 436 } else { |
437 gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, _("Transferring")); | |
438 } | |
439 | |
440 update_title_progress(); | |
441 | |
15823 | 442 if (purple_xfer_is_completed(xfer) && xfer_dialog->auto_clear) |
15818 | 443 finch_xfer_dialog_remove_xfer(xfer); |
444 } | |
445 | |
446 /************************************************************************** | |
447 * File Transfer UI Ops | |
448 **************************************************************************/ | |
449 static void | |
15823 | 450 finch_xfer_new_xfer(PurpleXfer *xfer) |
15818 | 451 { |
15823 | 452 PurpleGntXferUiData *data; |
15818 | 453 |
454 /* This is where we're setting xfer->ui_data for the first time. */ | |
15823 | 455 data = g_new0(PurpleGntXferUiData, 1); |
15818 | 456 xfer->ui_data = data; |
457 } | |
458 | |
459 static void | |
15823 | 460 finch_xfer_destroy(PurpleXfer *xfer) |
15818 | 461 { |
15823 | 462 PurpleGntXferUiData *data; |
15818 | 463 |
15823 | 464 data = FINCHXFER(xfer); |
15818 | 465 if (data) { |
466 g_free(data->name); | |
467 g_free(data); | |
468 xfer->ui_data = NULL; | |
469 } | |
470 } | |
471 | |
472 static void | |
15823 | 473 finch_xfer_add_xfer(PurpleXfer *xfer) |
15818 | 474 { |
475 if (!xfer_dialog) | |
476 finch_xfer_dialog_new(); | |
477 | |
478 finch_xfer_dialog_add_xfer(xfer); | |
479 gnt_tree_set_selected(GNT_TREE(xfer_dialog->tree), xfer); | |
480 } | |
481 | |
482 static void | |
15823 | 483 finch_xfer_update_progress(PurpleXfer *xfer, double percent) |
15818 | 484 { |
485 if (xfer_dialog) | |
486 finch_xfer_dialog_update_xfer(xfer); | |
487 } | |
488 | |
489 static void | |
15823 | 490 finch_xfer_cancel_local(PurpleXfer *xfer) |
15818 | 491 { |
492 if (xfer_dialog) | |
493 finch_xfer_dialog_cancel_xfer(xfer); | |
494 } | |
495 | |
496 static void | |
15823 | 497 finch_xfer_cancel_remote(PurpleXfer *xfer) |
15818 | 498 { |
499 if (xfer_dialog) | |
500 finch_xfer_dialog_cancel_xfer(xfer); | |
501 } | |
502 | |
15823 | 503 static PurpleXferUiOps ops = |
15818 | 504 { |
505 finch_xfer_new_xfer, | |
506 finch_xfer_destroy, | |
507 finch_xfer_add_xfer, | |
508 finch_xfer_update_progress, | |
509 finch_xfer_cancel_local, | |
16677
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
510 finch_xfer_cancel_remote, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
511 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
512 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
513 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
514 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
515 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16427
diff
changeset
|
516 NULL |
15818 | 517 }; |
518 | |
519 /************************************************************************** | |
520 * GNT File Transfer API | |
521 **************************************************************************/ | |
522 void | |
523 finch_xfers_init(void) | |
524 { | |
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
|
525 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
|
526 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
|
527 purple_prefs_add_bool("/finch/filetransfer/keep_open", FALSE); |
15818 | 528 } |
529 | |
530 void | |
531 finch_xfers_uninit(void) | |
532 { | |
533 if (xfer_dialog != NULL) | |
534 finch_xfer_dialog_destroy(); | |
535 } | |
536 | |
15823 | 537 PurpleXferUiOps * |
15818 | 538 finch_xfers_get_ui_ops(void) |
539 { | |
540 return &ops; | |
541 } |