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