diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-10-08 17:12:05 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-10-08 17:12:05 +0000 |
commit | f930813dd818ddbd88374f89394d68d485b4d1e7 (patch) | |
tree | 3ee6a9803b509a542d6a1653fb47dbfe2860c032 /src | |
parent | 579d63656354be1e92e0625136c46d24192d826a (diff) |
move {tpeer,tfile},{c,h} into torrent.{c,h}
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/tfile.c | 49 | ||||
-rw-r--r-- | src/tfile.h | 31 | ||||
-rw-r--r-- | src/torrent.c | 108 | ||||
-rw-r--r-- | src/torrent.h | 26 | ||||
-rw-r--r-- | src/tpeer.c | 98 | ||||
-rw-r--r-- | src/tpeer.h | 44 | ||||
-rw-r--r-- | src/trg-files-model.c | 1 | ||||
-rw-r--r-- | src/trg-peers-model.c | 1 | ||||
-rw-r--r-- | src/trg-torrent-model.c | 1 |
10 files changed, 133 insertions, 228 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 6b3f3c8..476bab0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,8 +29,6 @@ transmission_remote_gtk_SOURCES = main.c \ util.c \ trg-about-window.c \ torrent.c \ - tpeer.c \ - tfile.c \ session-get.c \ trg-client.c \ trg-preferences-dialog.c \ diff --git a/src/tfile.c b/src/tfile.c deleted file mode 100644 index cc92c34..0000000 --- a/src/tfile.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * transmission-remote-gtk - A GTK RPC client to Transmission - * Copyright (C) 2011 Alan Fitton - - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <json-glib/json-glib.h> - -#include "protocol-constants.h" -#include "tfile.h" - -gdouble file_get_progress(JsonObject * f) -{ - gint64 length = file_get_length(f); - if (length > 0) { - return ((gdouble) file_get_bytes_completed(f) / - (gdouble) length) * 100.0; - } else { - return 0.0; - } -} - -gint64 file_get_length(JsonObject * f) -{ - return json_object_get_int_member(f, TFILE_LENGTH); -} - -gint64 file_get_bytes_completed(JsonObject * f) -{ - return json_object_get_int_member(f, TFILE_BYTES_COMPLETED); -} - -const gchar *file_get_name(JsonObject * f) -{ - return json_object_get_string_member(f, TFILE_NAME); -} diff --git a/src/tfile.h b/src/tfile.h deleted file mode 100644 index ad5c57b..0000000 --- a/src/tfile.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * transmission-remote-gtk - A GTK RPC client to Transmission - * Copyright (C) 2011 Alan Fitton - - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef TFILE_H_ -#define TFILE_H_ - -#include <glib-object.h> -#include <json-glib/json-glib.h> - -gint64 file_get_length(JsonObject * f); -gint64 file_get_bytes_completed(JsonObject * f); -const gchar *file_get_name(JsonObject * f); -gdouble file_get_progress(JsonObject * f); - -#endif /* TFILE_H_ */ diff --git a/src/torrent.c b/src/torrent.c index 4510f64..879573e 100644 --- a/src/torrent.c +++ b/src/torrent.c @@ -68,7 +68,11 @@ const gchar *torrent_get_download_dir(JsonObject * t) gdouble torrent_get_metadata_percent_complete(JsonObject *t) { - return json_double_to_progress(json_object_get_member(t, FIELD_METADATAPERCENTCOMPLETE)); + JsonNode *node = json_object_get_member(t, FIELD_METADATAPERCENTCOMPLETE); + if (node) + return json_double_to_progress(node); + else + return 100.0; } const gchar *torrent_get_name(JsonObject * t) @@ -503,3 +507,105 @@ gchar *torrent_get_full_dir(JsonObject * obj) { return containing_path; } +/* peers */ + +const gchar *peer_get_address(JsonObject * p) { + return json_object_get_string_member(p, TPEER_ADDRESS); +} + +const gchar *peer_get_flagstr(JsonObject * p) { + return json_object_get_string_member(p, TPEER_FLAGSTR); +} + +const gchar *peer_get_client_name(JsonObject * p) { + return json_object_get_string_member(p, TPEER_CLIENT_NAME); +} + +gboolean peer_get_is_encrypted(JsonObject * p) { + return json_object_get_boolean_member(p, TPEER_IS_ENCRYPTED); +} + +gboolean peer_get_is_uploading_to(JsonObject * p) { + return json_object_get_boolean_member(p, TPEER_IS_UPLOADING_TO); +} + +gboolean peer_get_is_downloading_from(JsonObject * p) { + return json_object_get_boolean_member(p, TPEER_IS_DOWNLOADING_FROM); +} + +gdouble peer_get_progress(JsonObject * p) { + return json_double_to_progress(json_object_get_member(p, TPEER_PROGRESS)); +} + +gint64 peer_get_rate_to_client(JsonObject * p) { + return json_object_get_int_member(p, TPEER_RATE_TO_CLIENT); +} + +gint64 peer_get_rate_to_peer(JsonObject * p) { + return json_object_get_int_member(p, TPEER_RATE_TO_PEER); +} + +gint64 peerfrom_get_pex(JsonObject *pf) +{ + return json_object_get_int_member(pf, TPEERFROM_FROMPEX); +} + +gint64 peerfrom_get_dht(JsonObject *pf) +{ + return json_object_get_int_member(pf, TPEERFROM_FROMDHT); +} + +gint64 peerfrom_get_trackers(JsonObject *pf) +{ + return json_object_get_int_member(pf, TPEERFROM_FROMTRACKERS); +} + +gint64 peerfrom_get_ltep(JsonObject *pf) +{ + return json_object_get_int_member(pf, TPEERFROM_FROMLTEP); +} + +gint64 peerfrom_get_resume(JsonObject *pf) +{ + return json_object_get_int_member(pf, TPEERFROM_FROMRESUME); +} + +gint64 peerfrom_get_incoming(JsonObject *pf) +{ + return json_object_get_int_member(pf, TPEERFROM_FROMINCOMING); +} + + +gint64 peerfrom_get_lpd(JsonObject *pf) +{ + return json_object_has_member(pf, TPEERFROM_FROMLPD) ? + json_object_get_int_member(pf, TPEERFROM_FROMLPD) : -1; +} + +/* files */ + +gdouble file_get_progress(JsonObject * f) +{ + gint64 length = file_get_length(f); + if (length > 0) { + return ((gdouble) file_get_bytes_completed(f) / + (gdouble) length) * 100.0; + } else { + return 0.0; + } +} + +gint64 file_get_length(JsonObject * f) +{ + return json_object_get_int_member(f, TFILE_LENGTH); +} + +gint64 file_get_bytes_completed(JsonObject * f) +{ + return json_object_get_int_member(f, TFILE_BYTES_COMPLETED); +} + +const gchar *file_get_name(JsonObject * f) +{ + return json_object_get_string_member(f, TFILE_NAME); +} diff --git a/src/torrent.h b/src/torrent.h index 01ebda9..fd6cc19 100644 --- a/src/torrent.h +++ b/src/torrent.h @@ -111,4 +111,30 @@ gint64 tracker_stats_get_download_count(JsonObject *t); const gchar *tracker_stats_get_announce_result(JsonObject *t); const gchar *tracker_stats_get_host(JsonObject *t); +/* files */ + +gint64 file_get_length(JsonObject * f); +gint64 file_get_bytes_completed(JsonObject * f); +const gchar *file_get_name(JsonObject * f); +gdouble file_get_progress(JsonObject * f); + +/* peers */ + +const gchar *peer_get_address(JsonObject * p); +const gchar *peer_get_client_name(JsonObject * p); +gboolean peer_get_is_encrypted(JsonObject * p); +gdouble peer_get_progress(JsonObject * p); +const gchar *peer_get_flagstr(JsonObject * p); +gint64 peer_get_rate_to_client(JsonObject * p); +gint64 peer_get_rate_to_peer(JsonObject * p); +gboolean peer_get_is_uploading_to(JsonObject * p); +gboolean peer_get_is_downloading_from(JsonObject * p); + +gint64 peerfrom_get_pex(JsonObject *pf); +gint64 peerfrom_get_dht(JsonObject *pf); +gint64 peerfrom_get_trackers(JsonObject *pf); +gint64 peerfrom_get_ltep(JsonObject *pf); +gint64 peerfrom_get_resume(JsonObject *pf); +gint64 peerfrom_get_incoming(JsonObject *pf); +gint64 peerfrom_get_lpd(JsonObject *pf); #endif /* TORRENT_H_ */ diff --git a/src/tpeer.c b/src/tpeer.c deleted file mode 100644 index 53cb0ce..0000000 --- a/src/tpeer.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * transmission-remote-gtk - A GTK RPC client to Transmission - * Copyright (C) 2011 Alan Fitton - - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <glib-object.h> -#include <json-glib/json-glib.h> - -#include "tpeer.h" -#include "protocol-constants.h" -#include "util.h" - -const gchar *peer_get_address(JsonObject * p) { - return json_object_get_string_member(p, TPEER_ADDRESS); -} - -const gchar *peer_get_flagstr(JsonObject * p) { - return json_object_get_string_member(p, TPEER_FLAGSTR); -} - -const gchar *peer_get_client_name(JsonObject * p) { - return json_object_get_string_member(p, TPEER_CLIENT_NAME); -} - -gboolean peer_get_is_encrypted(JsonObject * p) { - return json_object_get_boolean_member(p, TPEER_IS_ENCRYPTED); -} - -gboolean peer_get_is_uploading_to(JsonObject * p) { - return json_object_get_boolean_member(p, TPEER_IS_UPLOADING_TO); -} - -gboolean peer_get_is_downloading_from(JsonObject * p) { - return json_object_get_boolean_member(p, TPEER_IS_DOWNLOADING_FROM); -} - -gdouble peer_get_progress(JsonObject * p) { - return json_double_to_progress(json_object_get_member(p, TPEER_PROGRESS)); -} - -gint64 peer_get_rate_to_client(JsonObject * p) { - return json_object_get_int_member(p, TPEER_RATE_TO_CLIENT); -} - -gint64 peer_get_rate_to_peer(JsonObject * p) { - return json_object_get_int_member(p, TPEER_RATE_TO_PEER); -} - -gint64 peerfrom_get_pex(JsonObject *pf) -{ - return json_object_get_int_member(pf, TPEERFROM_FROMPEX); -} - -gint64 peerfrom_get_dht(JsonObject *pf) -{ - return json_object_get_int_member(pf, TPEERFROM_FROMDHT); -} - -gint64 peerfrom_get_trackers(JsonObject *pf) -{ - return json_object_get_int_member(pf, TPEERFROM_FROMTRACKERS); -} - -gint64 peerfrom_get_ltep(JsonObject *pf) -{ - return json_object_get_int_member(pf, TPEERFROM_FROMLTEP); -} - -gint64 peerfrom_get_resume(JsonObject *pf) -{ - return json_object_get_int_member(pf, TPEERFROM_FROMRESUME); -} - -gint64 peerfrom_get_incoming(JsonObject *pf) -{ - return json_object_get_int_member(pf, TPEERFROM_FROMINCOMING); -} - - -gint64 peerfrom_get_lpd(JsonObject *pf) -{ - return json_object_has_member(pf, TPEERFROM_FROMLPD) ? - json_object_get_int_member(pf, TPEERFROM_FROMLPD) : -1; -} diff --git a/src/tpeer.h b/src/tpeer.h deleted file mode 100644 index 6886655..0000000 --- a/src/tpeer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * transmission-remote-gtk - A GTK RPC client to Transmission - * Copyright (C) 2011 Alan Fitton - - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef TPEER_H_ -#define TPEER_H_ - -#include <glib-object.h> -#include <json-glib/json-glib.h> - -const gchar *peer_get_address(JsonObject * p); -const gchar *peer_get_client_name(JsonObject * p); -gboolean peer_get_is_encrypted(JsonObject * p); -gdouble peer_get_progress(JsonObject * p); -const gchar *peer_get_flagstr(JsonObject * p); -gint64 peer_get_rate_to_client(JsonObject * p); -gint64 peer_get_rate_to_peer(JsonObject * p); -gboolean peer_get_is_uploading_to(JsonObject * p); -gboolean peer_get_is_downloading_from(JsonObject * p); - -gint64 peerfrom_get_pex(JsonObject *pf); -gint64 peerfrom_get_dht(JsonObject *pf); -gint64 peerfrom_get_trackers(JsonObject *pf); -gint64 peerfrom_get_ltep(JsonObject *pf); -gint64 peerfrom_get_resume(JsonObject *pf); -gint64 peerfrom_get_incoming(JsonObject *pf); -gint64 peerfrom_get_lpd(JsonObject *pf); - -#endif /* TPEER_H_ */ diff --git a/src/trg-files-model.c b/src/trg-files-model.c index 0c8d348..13d117b 100644 --- a/src/trg-files-model.c +++ b/src/trg-files-model.c @@ -23,7 +23,6 @@ #include "trg-files-model.h" #include "trg-client.h" #include "torrent.h" -#include "tfile.h" #include "util.h" #include "trg-files-model.h" diff --git a/src/trg-peers-model.c b/src/trg-peers-model.c index 4305d8c..6ba7d09 100644 --- a/src/trg-peers-model.c +++ b/src/trg-peers-model.c @@ -33,7 +33,6 @@ #include "trg-tree-view.h" #include "torrent.h" #include "trg-client.h" -#include "tpeer.h" #include "trg-peers-model.h" #include "trg-model.h" #include "util.h" diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c index bd7b545..54a2f0f 100644 --- a/src/trg-torrent-model.c +++ b/src/trg-torrent-model.c @@ -24,7 +24,6 @@ #include "config.h" #include "torrent.h" -#include "tpeer.h" #include "json.h" #include "trg-torrent-model.h" #include "protocol-constants.h" |