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