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