Changeset 13991
- Timestamp:
- Feb 9, 2013, 4:05:03 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/remote.c
r13887 r13991 1524 1524 if (tr_variantDictFindStr (args, TR_KEY_download_dir, &str, NULL)) 1525 1525 printf (" Download directory: %s\n", str); 1526 if (tr_variantDictFindInt (args, TR_KEY_download_dir_free_space, &i))1527 printf (" Download directory free space: %s\n", strlsize (buf, i, sizeof buf));1528 1526 if (tr_variantDictFindInt (args, TR_KEY_peer_port, &i)) 1529 1527 printf (" Listenport: %" PRId64 "\n", i); -
trunk/extras/rpc-spec.txt
r13844 r13991 458 458 "config-dir" | string | location of transmission's configuration directory 459 459 "download-dir" | string | default path to download torrents 460 "download-dir-free-space" | number | number of free bytes available in download-dir, or -1 if it can't be calculated461 460 "download-queue-size" | number | max number of torrents to download at once (see download-queue-enabled) 462 461 "download-queue-enabled" | boolean | if true, limit how many torrents can be downloaded at once … … 517 516 Method name: "session-set" 518 517 Request arguments: one or more of 4.1's arguments, except: "blocklist-size", 519 "config-dir", " download-dir-free-space", "rpc-version",520 " rpc-version-minimum", and "version"518 "config-dir", "rpc-version", "rpc-version-minimum", and 519 "version" 521 520 Response arguments: none 522 521 … … 598 597 599 598 Response arguments: none 599 600 4.7. Free Space 601 602 This method tests how much free space is available in a 603 client-specified folder. 604 605 Method name: "free-space" 606 607 Request arguments: 608 609 string | value type & description 610 ------------+---------------------------------------------------------- 611 "path" | string the directory to query 612 613 Response arguments: 614 615 string | value type & description 616 ------------+---------------------------------------------------------- 617 "path" | string same as the Request argument 618 "size-bytes"| number the size, in bytes, of the free space in that directory 619 600 620 601 621 5.0. Protocol Versions … … 739 759 | | yes | | new method "torrent-start-now" 740 760 ------+---------+-----------+--------------------------+------------------------------- 741 15 | 2.80 | yes | torrent-get | new arg "etaIdle" 761 15 | 2.80 | NO | session-get | removed arg "download-dir-free-space" 762 | | yes | torrent-get | new arg "etaIdle" 742 763 | | yes | torrent-rename-path | new method 743 764 | | yes | free-space | new method 765 -
trunk/gtk/open-dialog.c
r13913 r13991 95 95 GtkWidget * trash_check; 96 96 GtkWidget * priority_combo; 97 GtkWidget * freespace_label; 97 98 char * filename; 98 99 char * downloadDir; … … 227 228 data->downloadDir = g_strdup (fname); 228 229 updateTorrent (data); 230 231 gtr_freespace_label_set_dir (data->freespace_label, data->downloadDir); 229 232 } 230 233 … … 340 343 G_CALLBACK (downloadDirChanged), data); 341 344 345 row++; 346 l = data->freespace_label = gtr_freespace_label_new (core, data->downloadDir); 347 gtk_widget_set_margin_bottom (l, GUI_PAD_BIG); 348 gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f); 349 gtk_grid_attach (grid, l, 0, row, 2, 1); 350 351 342 352 // file list row 343 353 row++; -
trunk/gtk/tr-prefs.c
r13955 r13991 30 30 **/ 31 31 32 struct prefs_dialog_data 33 { 34 TrCore * core; 35 gulong core_prefs_tag; 36 37 GtkWidget * freespace_label; 38 39 GtkWidget * port_label; 40 GtkWidget * port_button; 41 GtkWidget * port_spin; 42 }; 43 44 45 /** 46 *** 47 **/ 48 32 49 #define PREF_KEY "pref-key" 33 50 … … 257 274 258 275 static GtkWidget* 259 downloadingPage (GObject * core )276 downloadingPage (GObject * core, struct prefs_dialog_data * data) 260 277 { 261 278 GtkWidget * t; … … 289 306 w = new_path_chooser_button (TR_KEY_download_dir, core); 290 307 hig_workarea_add_row (t, &row, _("Save to _Location:"), w, NULL); 308 309 l = data->freespace_label = gtr_freespace_label_new (TR_CORE(core), NULL); 310 gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f); 311 hig_workarea_add_wide_control (t, &row, l); 291 312 292 313 hig_workarea_add_section_divider (t, &row); … … 1243 1264 ****/ 1244 1265 1266 static void 1267 on_prefs_dialog_destroyed (gpointer gdata, GObject * dead_dialog G_GNUC_UNUSED) 1268 { 1269 struct prefs_dialog_data * data = gdata; 1270 1271 if (data->core_prefs_tag > 0) 1272 g_signal_handler_disconnect (data->core, data->core_prefs_tag); 1273 1274 g_free (data); 1275 } 1276 1277 static void 1278 on_core_prefs_changed (TrCore * core, const tr_quark key, gpointer gdata) 1279 { 1280 struct prefs_dialog_data * data = gdata; 1281 1282 #if 0 1283 if (key == TR_KEY_peer_port) 1284 { 1285 gtr_label_set_text (GTK_LABEL (data->port_label), _("Status unknown")); 1286 gtk_widget_set_sensitive (data->port_button, TRUE); 1287 gtk_widget_set_sensitive (data->port_spin, TRUE); 1288 } 1289 #endif 1290 if (key == TR_KEY_download_dir) 1291 { 1292 const char * downloadDir = tr_sessionGetDownloadDir (gtr_core_session (core)); 1293 gtr_freespace_label_set_dir (data->freespace_label, downloadDir); 1294 } 1295 } 1296 1245 1297 GtkWidget * 1246 1298 gtr_prefs_dialog_new (GtkWindow * parent, GObject * core) 1247 1299 { 1300 size_t i; 1248 1301 GtkWidget * d; 1249 1302 GtkWidget * n; 1303 struct prefs_dialog_data * data; 1304 const tr_quark prefs_quarks[] = { TR_KEY_peer_port, TR_KEY_download_dir }; 1305 1306 data = g_new0 (struct prefs_dialog_data, 1); 1307 data->core = TR_CORE (core); 1308 data->core_prefs_tag = g_signal_connect (TR_CORE (core), "prefs-changed", G_CALLBACK (on_core_prefs_changed), data); 1250 1309 1251 1310 d = gtk_dialog_new_with_buttons (_("Transmission Preferences"), … … 1255 1314 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, 1256 1315 NULL); 1316 g_object_weak_ref (G_OBJECT(d), on_prefs_dialog_destroyed, data); 1257 1317 gtk_window_set_role (GTK_WINDOW (d), "transmission-preferences-dialog"); 1258 1318 gtk_container_set_border_width (GTK_CONTAINER (d), GUI_PAD); … … 1263 1323 gtk_notebook_append_page (GTK_NOTEBOOK (n), speedPage (core), 1264 1324 gtk_label_new (_("Speed"))); 1265 gtk_notebook_append_page (GTK_NOTEBOOK (n), downloadingPage (core ),1325 gtk_notebook_append_page (GTK_NOTEBOOK (n), downloadingPage (core, data), 1266 1326 gtk_label_new (C_("Gerund", "Downloading"))); 1267 1327 gtk_notebook_append_page (GTK_NOTEBOOK (n), seedingPage (core), … … 1276 1336 gtk_label_new (_("Remote"))); 1277 1337 1338 /* init from prefs keys */ 1339 for (i=0; i<sizeof(prefs_quarks)/sizeof(prefs_quarks[0]); ++i) 1340 on_core_prefs_changed (TR_CORE(core), prefs_quarks[i], data); 1341 1278 1342 g_signal_connect (d, "response", G_CALLBACK (response_cb), core); 1279 1343 gtr_dialog_set_content (GTK_DIALOG (d), n); -
trunk/gtk/tr-window.c
r13983 r13991 55 55 GtkLabel * dl_lb; 56 56 GtkLabel * stats_lb; 57 GtkLabel * freespace_lb;58 GtkWidget * freespace_icon;59 57 GtkWidget * alt_speed_image; 60 58 GtkWidget * alt_speed_button; … … 716 714 sibling = w; 717 715 718 /* freespace */719 w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU);720 p->freespace_icon = w;721 g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);722 gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);723 sibling = w;724 w = gtk_label_new (NULL);725 g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL);726 p->freespace_lb = GTK_LABEL (w);727 gtk_label_set_single_line_mode (p->freespace_lb, TRUE);728 gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);729 sibling = w;730 731 /* spacer */732 w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);733 gtk_widget_set_hexpand (w, TRUE);734 gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);735 sibling = w;736 737 716 /* download */ 738 717 w = dl_lb = gtk_label_new (NULL); … … 813 792 gtr_window_refresh (GTK_WINDOW(self)); 814 793 return self; 815 }816 817 static void818 updateFreeSpace (PrivateData * p)819 {820 GtkWidget * w;821 bool visible = false;822 823 g_return_if_fail (p != NULL);824 825 w = GTK_WIDGET (p->freespace_lb);826 827 if (p->core != NULL)828 {829 tr_session * session = gtr_core_session (p->core);830 const int64_t n = tr_sessionGetDownloadDirFreeSpace (session);831 const char * downloadDir = tr_sessionGetDownloadDir (session);832 833 visible = n >= 0;834 835 if (visible)836 {837 char * str;838 char sizeStr[32];839 840 tr_strlsize (sizeStr, n, sizeof(sizeStr));841 842 str = g_strdup_printf (_("%s Free"), sizeStr);843 gtk_label_set_text (p->freespace_lb, str);844 g_free (str);845 846 str = g_strdup_printf (_("Download folder \"%1$s\" has %2$s free"), downloadDir, sizeStr);847 gtk_widget_set_tooltip_text (w, str);848 g_free (str);849 }850 }851 852 gtk_widget_set_visible (w, visible);853 gtk_widget_set_visible (p->freespace_icon, visible);854 794 } 855 795 … … 959 899 updateSpeeds (p); 960 900 updateStats (p); 961 updateFreeSpace (p);962 901 } 963 902 } -
trunk/gtk/util.c
r13970 r13991 27 27 #include "conf.h" 28 28 #include "hig.h" 29 #include "tr-core.h" 29 30 #include "tr-prefs.h" 30 31 #include "util.h" … … 632 633 gtk_label_set_text (lb, newstr); 633 634 } 635 636 /*** 637 **** 638 ***/ 639 640 struct freespace_label_data 641 { 642 guint timer_id; 643 TrCore * core; 644 GtkLabel * label; 645 char * dir; 646 }; 647 648 static void on_freespace_label_core_destroyed (gpointer gdata, GObject * dead_core); 649 static void on_freespace_label_destroyed (gpointer gdata, GObject * dead_label); 650 651 static void 652 freespace_label_data_free (gpointer gdata) 653 { 654 struct freespace_label_data * data = gdata; 655 656 if (data->core != NULL) 657 g_object_weak_unref (G_OBJECT(data->core), on_freespace_label_core_destroyed, data); 658 659 if (data->label != NULL) 660 g_object_weak_ref (G_OBJECT(data->label), on_freespace_label_destroyed, data); 661 662 g_source_remove (data->timer_id); 663 g_free (data->dir); 664 g_free (data); 665 } 666 667 static GQuark 668 freespace_label_data_quark (void) 669 { 670 static GQuark q = 0; 671 672 if (G_UNLIKELY(!q)) 673 q = g_quark_from_static_string ("data"); 674 675 return q; 676 } 677 678 static void 679 on_freespace_label_core_destroyed (gpointer gdata, GObject * dead_core G_GNUC_UNUSED) 680 { 681 struct freespace_label_data * data = gdata; 682 data->core = NULL; 683 freespace_label_data_free (data); 684 } 685 686 static void 687 on_freespace_label_destroyed (gpointer gdata, GObject * dead_label G_GNUC_UNUSED) 688 { 689 struct freespace_label_data * data = gdata; 690 data->label = NULL; 691 freespace_label_data_free (data); 692 } 693 694 static gboolean 695 on_freespace_timer (gpointer gdata) 696 { 697 char text[128]; 698 char markup[128]; 699 int64_t bytes; 700 tr_session * session; 701 struct freespace_label_data * data = gdata; 702 703 session = gtr_core_session (data->core); 704 bytes = tr_sessionGetDirFreeSpace (session, data->dir); 705 706 if (bytes < 0) 707 { 708 g_snprintf (text, sizeof(text), _("Error")); 709 } 710 else 711 { 712 char size[128]; 713 tr_strlsize (size, bytes, sizeof(size)); 714 g_snprintf (text, sizeof(text), _("%s free"), size); 715 } 716 717 g_snprintf (markup, sizeof(markup), "<i>%s</i>", text); 718 gtk_label_set_markup (data->label, markup); 719 720 return G_SOURCE_CONTINUE; 721 } 722 723 GtkWidget * 724 gtr_freespace_label_new (struct _TrCore * core, const char * dir) 725 { 726 struct freespace_label_data * data; 727 728 data = g_new0 (struct freespace_label_data, 1); 729 data->timer_id = g_timeout_add_seconds (3, on_freespace_timer, data); 730 data->core = core; 731 data->label = GTK_LABEL (gtk_label_new (NULL)); 732 data->dir = g_strdup (dir); 733 734 /* when either the core or the label is destroyed, stop updating */ 735 g_object_weak_ref (G_OBJECT(core), on_freespace_label_core_destroyed, data); 736 g_object_weak_ref (G_OBJECT(data->label), on_freespace_label_destroyed, data); 737 738 g_object_set_qdata (G_OBJECT(data->label), freespace_label_data_quark (), data); 739 on_freespace_timer (data); 740 return GTK_WIDGET (data->label); 741 } 742 743 void 744 gtr_freespace_label_set_dir (GtkWidget * label, const char * dir) 745 { 746 struct freespace_label_data * data; 747 748 data = g_object_get_qdata (G_OBJECT(label), freespace_label_data_quark ()); 749 750 tr_free (data->dir); 751 data->dir = g_strdup (dir); 752 on_freespace_timer (data); 753 } -
trunk/gtk/util.h
r13625 r13991 110 110 ***/ 111 111 112 struct _TrCore; 113 114 GtkWidget * gtr_freespace_label_new (struct _TrCore * core, const char * dir); 115 116 void gtr_freespace_label_set_dir (GtkWidget * label, const char * dir); 117 118 /*** 119 **** 120 ***/ 121 112 122 void gtr_unrecognized_url_dialog (GtkWidget * parent, const char * url); 113 123 -
trunk/libtransmission/platform.c
r13975 r13991 57 57 58 58 #include <assert.h> 59 #include <errno.h> 59 60 #include <stdio.h> 60 61 #include <stdlib.h> … … 81 82 #include <xfs/xqm.h> 82 83 #endif 84 85 #include <event2/util.h> /* evutil_ascii_strcasecmp () */ 83 86 84 87 #include "transmission.h" … … 733 736 734 737 #ifndef WIN32 735 static c har *738 static const char * 736 739 getdev (const char * path) 737 740 { … … 784 787 } 785 788 786 static c har *789 static const char * 787 790 getfstype (const char * device) 788 791 { … … 834 837 } 835 838 836 static c har *839 static const char * 837 840 getblkdev (const char * path) 838 841 { 839 842 char * c; 840 843 char * dir; 841 c har * device;844 const char * device; 842 845 843 846 dir = tr_strdup(path); … … 861 864 862 865 static int64_t 863 getquota (c har * device)866 getquota (const char * device) 864 867 { 865 868 struct dqblk dq; … … 961 964 962 965 static int64_t 963 tr_getQuotaFreeSpace (const char * path, char * device, char * fstype)964 { 965 int64_t ret =-1;966 tr_getQuotaFreeSpace (const struct tr_device_info * info) 967 { 968 int64_t ret = -1; 966 969 967 970 #ifndef WIN32 968 971 969 /* save device for future use */ 970 if (!*device) 971 { 972 char * d = getblkdev (path); 973 if (d == NULL) 974 return ret; 975 tr_strlcpy (device, d, PATH_MAX + 1); 976 } 977 978 /* save FS type for future use */ 979 if (!*fstype) 980 { 981 char * fs = getfstype (device); 982 if (fs != NULL) 983 tr_strlcpy (fstype, fs, PATH_MAX + 1); 984 } 985 986 if (strcasecmp(fstype, "xfs") == 0) 972 if (info->fstype && !evutil_ascii_strcasecmp(info->fstype, "xfs")) 987 973 { 988 974 #ifdef HAVE_XQM 989 ret = getxfsquota (device);975 ret = getxfsquota (info->device); 990 976 #endif 991 977 } 992 978 else 993 979 { 994 ret = getquota(device); 995 } 996 980 ret = getquota (info->device); 981 } 997 982 #endif /* WIN32 */ 983 998 984 return ret; 999 985 } … … 1022 1008 } 1023 1009 1010 struct tr_device_info * 1011 tr_device_info_create (const char * path) 1012 { 1013 struct tr_device_info * info; 1014 1015 info = tr_new0 (struct tr_device_info, 1); 1016 info->path = tr_strdup (path); 1017 info->device = tr_strdup (getblkdev (path)); 1018 info->fstype = tr_strdup (getfstype (path)); 1019 1020 return info; 1021 } 1022 1023 void 1024 tr_device_info_free (struct tr_device_info * info) 1025 { 1026 if (info != NULL) 1027 { 1028 tr_free (info->fstype); 1029 tr_free (info->device); 1030 tr_free (info->path); 1031 tr_free (info); 1032 } 1033 } 1034 1024 1035 int64_t 1025 tr_getFreeSpace (const char * path, char * device, char * fstype) 1026 { 1027 int64_t i = tr_getQuotaFreeSpace (path, device, fstype); 1028 1029 if (i < 0) 1030 i = tr_getDiskFreeSpace (path); 1031 1032 return i; 1036 tr_device_info_get_free_space (const struct tr_device_info * info) 1037 { 1038 int64_t free_space; 1039 1040 if ((info == NULL) || (info->path == NULL)) 1041 { 1042 errno = EINVAL; 1043 free_space = -1; 1044 } 1045 else 1046 { 1047 free_space = tr_getQuotaFreeSpace (info); 1048 1049 if (free_space < 0) 1050 free_space = tr_getDiskFreeSpace (info->path); 1051 } 1052 1053 return free_space; 1033 1054 } 1034 1055 -
trunk/libtransmission/platform.h
r13698 r13991 43 43 const char * tr_getWebClientDir (const tr_session *); 44 44 45 struct tr_device_info 46 { 47 char * path; 48 char * device; 49 char * fstype; 50 }; 51 52 struct tr_device_info * tr_device_info_create (const char * path); 53 45 54 /** If the disk quota is enabled and readable, this returns how much is available in the quota. 46 55 Otherwise, it returns how much is available on the disk, or -1 on error. */ 47 int64_t tr_getFreeSpace (const char * path, char * device, char * fstype); 56 int64_t tr_device_info_get_free_space (const struct tr_device_info * info); 57 58 void tr_device_info_free (struct tr_device_info * info); 48 59 49 60 -
trunk/libtransmission/quark.c
r13946 r13991 79 79 { "doneDate", 8 }, 80 80 { "download-dir", 12 }, 81 { "download-dir-free-space", 23 },82 81 { "download-queue-enabled", 22 }, 83 82 { "download-queue-size", 19 }, -
trunk/libtransmission/quark.h
r13933 r13991 89 89 TR_KEY_doneDate, 90 90 TR_KEY_download_dir, 91 TR_KEY_download_dir_free_space,92 91 TR_KEY_download_queue_enabled, 93 92 TR_KEY_download_queue_size, -
trunk/libtransmission/rpc-test.c
r13916 r13991 107 107 check (tr_variantDictFind (args, TR_KEY_dht_enabled) != NULL); 108 108 check (tr_variantDictFind (args, TR_KEY_download_dir) != NULL); 109 check (tr_variantDictFind (args, TR_KEY_download_dir_free_space) != NULL);110 109 check (tr_variantDictFind (args, TR_KEY_download_queue_enabled) != NULL); 111 110 check (tr_variantDictFind (args, TR_KEY_download_queue_size) != NULL); -
trunk/libtransmission/rpcimpl.c
r13970 r13991 1727 1727 static const char* 1728 1728 sessionSet (tr_session * session, 1729 tr_variant 1730 tr_variant 1729 tr_variant * args_in, 1730 tr_variant * args_out UNUSED, 1731 1731 struct tr_rpc_idle_data * idle_data UNUSED) 1732 1732 { … … 1906 1906 tr_variantDictAddBool (d, TR_KEY_download_queue_enabled, tr_sessionGetQueueEnabled (s, TR_DOWN)); 1907 1907 tr_variantDictAddInt (d, TR_KEY_download_queue_size, tr_sessionGetQueueSize (s, TR_DOWN)); 1908 tr_variantDictAddInt (d, TR_KEY_download_dir_free_space, tr_sessionGetDownloadDirFreeSpace (s));1909 1908 tr_variantDictAddInt (d, TR_KEY_peer_limit_global, tr_sessionGetPeerLimit (s)); 1910 1909 tr_variantDictAddInt (d, TR_KEY_peer_limit_per_torrent, tr_sessionGetPeerLimitPerTorrent (s)); … … 1949 1948 } 1950 1949 1950 static const char* 1951 freeSpace (tr_session * session, 1952 tr_variant * args_in, 1953 tr_variant * args_out, 1954 struct tr_rpc_idle_data * idle_data UNUSED) 1955 { 1956 int tmperr; 1957 const char * path = NULL; 1958 const char * err = NULL; 1959 int64_t free_space = -1; 1960 1961 /* get the free space */ 1962 tr_variantDictFindStr (args_in, TR_KEY_path, &path, NULL); 1963 tmperr = errno; 1964 errno = 0; 1965 free_space = tr_sessionGetDirFreeSpace (session, path); 1966 if (free_space < 0) 1967 err = tr_strerror (errno); 1968 errno = tmperr; 1969 1970 /* response */ 1971 if (path != NULL) 1972 tr_variantDictAddStr (args_out, TR_KEY_path, path); 1973 tr_variantDictAddInt (args_out, TR_KEY_size_bytes, free_space); 1974 return err; 1975 } 1976 1951 1977 /*** 1952 1978 **** … … 1979 2005 { "port-test", false, portTest }, 1980 2006 { "blocklist-update", false, blocklistUpdate }, 2007 { "free-space", true, freeSpace }, 1981 2008 { "session-close", true, sessionClose }, 1982 2009 { "session-get", true, sessionGet }, -
trunk/libtransmission/session.c
r13969 r13991 387 387 tr_variantDictAddBool (d, TR_KEY_utp_enabled, s->isUTPEnabled); 388 388 tr_variantDictAddBool (d, TR_KEY_lpd_enabled, s->isLPDEnabled); 389 tr_variantDictAddStr (d, TR_KEY_download_dir, s->downloadDir);389 tr_variantDictAddStr (d, TR_KEY_download_dir, tr_sessionGetDownloadDir (s)); 390 390 tr_variantDictAddInt (d, TR_KEY_download_queue_size, tr_sessionGetQueueSize (s, TR_DOWN)); 391 391 tr_variantDictAddBool (d, TR_KEY_download_queue_enabled, tr_sessionGetQueueEnabled (s, TR_DOWN)); … … 954 954 tr_sessionSetDownloadDir (tr_session * session, const char * dir) 955 955 { 956 assert (tr_isSession (session)); 957 958 if (session->downloadDir != dir) 959 { 960 tr_free (session->downloadDir); 961 session->downloadDir = tr_strdup (dir); 962 memset (session->downloadDirBlkDev, 0, sizeof(session->downloadDirBlkDev)); 963 memset (session->downloadDirFsType, 0, sizeof(session->downloadDirFsType)); 964 } 956 struct tr_device_info * info = NULL; 957 958 assert (tr_isSession (session)); 959 960 if (dir != NULL) 961 info = tr_device_info_create (dir); 962 tr_device_info_free (session->downloadDir); 963 session->downloadDir = info; 965 964 } 966 965 … … 968 967 tr_sessionGetDownloadDir (const tr_session * session) 969 968 { 970 assert (tr_isSession (session)); 971 972 return session->downloadDir; 969 const char * dir = NULL; 970 971 assert (tr_isSession (session)); 972 973 if ((session != NULL) && (session->downloadDir != NULL)) 974 dir = session->downloadDir->path; 975 976 return dir; 973 977 } 974 978 975 979 int64_t 976 tr_sessionGetDownloadDirFreeSpace (tr_session * session) 977 { 978 assert (tr_isSession (session)); 979 980 return tr_getFreeSpace (session->downloadDir, 981 session->downloadDirBlkDev, 982 session->downloadDirFsType); 980 tr_sessionGetDirFreeSpace (tr_session * session, const char * dir) 981 { 982 int64_t free_space; 983 984 if (!tr_strcmp0 (dir, tr_sessionGetDownloadDir (session))) 985 free_space = tr_device_info_get_free_space (session->downloadDir); 986 else 987 free_space = tr_getDirFreeSpace (dir); 988 989 return free_space; 983 990 } 984 991 … … 1884 1891 tr_free (session->metainfoLookup); 1885 1892 } 1893 tr_device_info_free (session->downloadDir); 1886 1894 tr_free (session->torrentDoneScript); 1887 1895 tr_free (session->tag); … … 1889 1897 tr_free (session->resumeDir); 1890 1898 tr_free (session->torrentDir); 1891 tr_free (session->downloadDir);1892 1899 tr_free (session->incompleteDir); 1893 1900 tr_free (session->blocklist_url); -
trunk/libtransmission/session.h
r13933 r13991 57 57 struct tr_cache; 58 58 struct tr_fdInfo; 59 struct tr_device_info; 59 60 60 61 typedef void (tr_web_config_func)(tr_session * session, void * curl_pointer, const char * url, void * user_data); … … 184 185 char * tag; 185 186 char * configDir; 186 char * downloadDir;187 char downloadDirBlkDev[TR_PATH_MAX + 1];188 char downloadDirFsType[TR_PATH_MAX + 1];189 187 char * resumeDir; 190 188 char * torrentDir; … … 192 190 193 191 char * blocklist_url; 192 193 struct tr_device_info * downloadDir; 194 194 195 195 struct tr_list * blocklists; -
trunk/libtransmission/torrent-ctor.c
r13683 r13991 453 453 tr_ctorSetPaused (ctor, TR_FALLBACK, tr_sessionGetPaused (session)); 454 454 tr_ctorSetPeerLimit (ctor, TR_FALLBACK, session->peerLimitPerTorrent); 455 tr_ctorSetDownloadDir (ctor, TR_FALLBACK, session->downloadDir);455 tr_ctorSetDownloadDir (ctor, TR_FALLBACK, tr_sessionGetDownloadDir(session)); 456 456 } 457 457 tr_ctorSetSave (ctor, true); -
trunk/libtransmission/torrent.c
r13980 r13991 83 83 tr_torrentId (const tr_torrent * tor) 84 84 { 85 return tor ->uniqueId;85 return tor ? tor->uniqueId : -1; 86 86 } 87 87 -
trunk/libtransmission/transmission.h
r13913 r13991 292 292 293 293 /** 294 * @brief Get available disk space (in bytes) for the default download folder.294 * @brief Get available disk space (in bytes) for the specified directory. 295 295 * @return zero or positive integer on success, -1 in case of error. 296 296 */ 297 int64_t tr_sessionGetD ownloadDirFreeSpace (tr_session * session);297 int64_t tr_sessionGetDirFreeSpace (tr_session * session, const char * dir); 298 298 299 299 /** -
trunk/libtransmission/utils.c
r13970 r13991 421 421 } 422 422 423 int64_t 424 tr_getDirFreeSpace (const char * dir) 425 { 426 int64_t free_space; 427 428 if (!dir || !*dir) 429 { 430 errno = EINVAL; 431 free_space = -1; 432 } 433 else 434 { 435 struct tr_device_info * info; 436 info = tr_device_info_create (dir); 437 free_space = tr_device_info_get_free_space (info); 438 tr_device_info_free (info); 439 } 440 441 return free_space; 442 } 443 423 444 /**** 424 445 ***** -
trunk/libtransmission/utils.h
r13969 r13991 140 140 141 141 bool tr_fileExists (const char * filename, time_t * mtime); 142 143 /** 144 * @brief Get available disk space (in bytes) for the specified folder. 145 * @return zero or positive integer on success, -1 in case of error. 146 */ 147 int64_t tr_getDirFreeSpace (const char * path); 142 148 143 149 -
trunk/qt/mainwin.cc
r13982 r13991 282 282 connect (&mySession, SIGNAL (sourceChanged ()), this, SLOT (onSessionSourceChanged ())); 283 283 connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (refreshStatusBar ())); 284 connect (&mySession, SIGNAL (sessionUpdated ()), this, SLOT (refreshFreeSpace ()));285 284 connect (&mySession, SIGNAL (dataReadProgress ()), this, SLOT (dataReadProgress ())); 286 285 connect (&mySession, SIGNAL (dataSendProgress ()), this, SLOT (dataSendProgress ())); … … 304 303 refreshTrayIconSoon (); 305 304 refreshStatusBar (); 306 refreshFreeSpace ();307 305 refreshTitle (); 308 306 } … … 388 386 389 387 l = myNetworkLabel = new QLabel; 390 h->addWidget (l);391 392 h->addStretch (1);393 394 l = myFreeSpaceIconLabel = new QLabel (this);395 l->setPixmap (getStockIcon ("drive-harddisk", QStyle::SP_DriveHDIcon).pixmap (smallIconSize));396 h->addWidget (l);397 l = myFreeSpaceTextLabel = new QLabel (this);398 const int minimumFreeSpaceWidth = l->fontMetrics ().width (Formatter::sizeToString (1024 * 1024));399 l->setMinimumWidth (minimumFreeSpaceWidth);400 388 h->addWidget (l); 401 389 … … 714 702 715 703 void 716 TrMainWindow :: refreshFreeSpace ()717 {718 const int64_t bytes (mySession.downloadDirFreeSpace ());719 720 if (bytes >= 0)721 {722 const QString sizeStr = Formatter::sizeToString (bytes);723 724 const QString tip = tr ("Download folder \"%1\" has %2 free")725 .arg (myPrefs.getString (Prefs::DOWNLOAD_DIR))726 .arg (sizeStr);727 728 myFreeSpaceTextLabel->setText (tr("%1 Free").arg(sizeStr));729 myFreeSpaceTextLabel->setToolTip (tip);730 myFreeSpaceIconLabel->setToolTip (tip);731 }732 733 myFreeSpaceTextLabel->setVisible (bytes >= 0);734 myFreeSpaceIconLabel->setVisible (bytes >= 0);735 }736 737 void738 704 TrMainWindow :: refreshTrayIconSoon () 739 705 { -
trunk/qt/mainwin.h
r13927 r13991 105 105 void showSessionRatio (); 106 106 void showSessionTransfer (); 107 void refreshFreeSpace ();108 107 void refreshTitle (); 109 108 void refreshStatusBar (); … … 159 158 QLabel * myDownloadSpeedLabel; 160 159 QLabel * myUploadSpeedLabel; 161 QLabel * myFreeSpaceTextLabel;162 QLabel * myFreeSpaceIconLabel;163 160 QLabel * myNetworkLabel; 164 161 -
trunk/qt/options.cc
r13893 r13991 37 37 #include "add-data.h" 38 38 #include "file-tree.h" 39 #include "freespace-label.h" 39 40 #include "hig.h" 40 41 #include "options.h" … … 119 120 l = new QLabel( tr( "&Destination folder:" ) ); 120 121 layout->addWidget( l, ++row, 0, Qt::AlignLeft ); 122 const QString downloadDir (prefs.getString (Prefs::DOWNLOAD_DIR)); 121 123 122 124 if( session.isLocal( ) ) 123 125 { 124 myDestination.setPath ( prefs.getString( Prefs :: DOWNLOAD_DIR ));126 myDestination.setPath (downloadDir); 125 127 p = myDestinationButton = new QPushButton; 126 128 p->setIcon( folderPixmap ); … … 134 136 { 135 137 QLineEdit * e = myDestinationEdit = new QLineEdit; 136 e->setText ( prefs.getString( Prefs :: DOWNLOAD_DIR ));138 e->setText (downloadDir); 137 139 layout->addWidget( e, row, 1 ); 138 140 l->setBuddy( e ); 139 141 } 142 143 l = myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this); 144 layout->addWidget (l, ++row, 0, 1, 2, Qt::Alignment (Qt::AlignRight | Qt::AlignTop)); 145 layout->setRowMinimumHeight (row, l->height() + HIG::PAD); 140 146 141 147 myTree = new FileTreeView (0, false); … … 175 181 layout->addWidget( b, ++row, 0, 1, 2 ); 176 182 177 layout->setRowStretch( 2, 2 );183 layout->setRowStretch( 3, 2 ); 178 184 layout->setColumnStretch( 1, 2 ); 179 185 layout->setSpacing( HIG :: PAD ); … … 449 455 450 456 void 451 Options :: onDestinationsSelected( const QStringList& destinations ) 452 { 453 if( destinations.size() == 1 ) 454 { 455 const QString& destination( destinations.first( ) ); 456 myDestination.setPath( destination ); 457 refreshDestinationButton( ); 457 Options :: onDestinationsSelected (const QStringList& destinations) 458 { 459 if (destinations.size() == 1) 460 { 461 const QString& destination (destinations.first ()); 462 myFreespaceLabel->setPath (destination); 463 myDestination.setPath (destination); 464 refreshDestinationButton (); 458 465 } 459 466 } -
trunk/qt/options.h
r13667 r13991 22 22 #include <QVector> 23 23 #include <QMap> 24 #include <QPushButton>25 24 #include <QString> 26 25 #include <QStringList> … … 33 32 #include "file-tree.h" // FileList 34 33 35 class FileTreeView;36 class Prefs;37 34 class QCheckBox; 38 35 class QComboBox; 36 class QPushButton; 37 38 class FileTreeView; 39 class FreespaceLabel; 40 class Prefs; 39 41 class Session; 40 42 … … 79 81 tr_info myInfo; 80 82 FileTreeView * myTree; 83 FreespaceLabel * myFreespaceLabel; 81 84 QCheckBox * myStartCheck; 82 85 QCheckBox * myTrashCheck; -
trunk/qt/prefs-dialog.cc
r13813 r13991 37 37 #include <QVBoxLayout> 38 38 39 #include "freespace-label.h" 39 40 #include "formatter.h" 40 41 #include "hig.h" … … 589 590 hig->addRow( tr( "Save to &Location:" ), b ); 590 591 592 const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR)); 593 l = myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this); 594 QHBoxLayout * h = new QHBoxLayout (); 595 h->addStretch (1); 596 h->addWidget (l); 597 hig->addWideControl (h); 598 591 599 hig->addSectionDivider( ); 592 600 hig->addSectionTitle( tr( "Download Queue" ) ); … … 747 755 748 756 case Prefs :: DOWNLOAD_DIR: { 749 QString path( myPrefs.getString( key ) );757 const QString path( myPrefs.getString( key ) ); 750 758 myDestinationButton->setText( QFileInfo(path).fileName() ); 759 myFreespaceLabel->setPath (path); 751 760 break; 752 761 } -
trunk/qt/prefs-dialog.h
r13796 r13991 33 33 class QHttp; 34 34 35 class FreespaceLabel; 35 36 class Prefs; 36 37 class Session; … … 109 110 QWidgetList myBlockWidgets; 110 111 QWidgetList myUnsupportedWhenRemote; 112 FreespaceLabel * myFreespaceLabel; 111 113 112 114 int myBlocklistHttpTag; -
trunk/qt/qtr.pro
r13680 r13991 53 53 filterbar.cc \ 54 54 filters.cc \ 55 freespace-label.cc \ 55 56 formatter.cc \ 56 57 hig.cc \ -
trunk/qt/session.cc
r13981 r13991 259 259 mySession (0), 260 260 myConfigDir (QString::fromUtf8 (configDir)), 261 myNAM (0), 262 myDownloadDirFreeSpace (-1) 261 myNAM (0) 263 262 { 264 263 myStats.ratio = TR_RATIO_NA; … … 1009 1008 mySessionVersion = str; 1010 1009 1011 if (tr_variantDictFindInt (d, TR_KEY_download_dir_free_space, &i) && (myDownloadDirFreeSpace != i))1012 myDownloadDirFreeSpace = i;1013 1014 1010 //std::cerr << "Session :: updateInfo end" << std::endl; 1015 1011 connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int))); -
trunk/qt/session.h
r13944 r13991 58 58 const struct tr_session_stats& getCumulativeStats () const { return myCumulativeStats; } 59 59 const QString& sessionVersion () const { return mySessionVersion; } 60 int64_t downloadDirFreeSpace () const { return myDownloadDirFreeSpace; }61 60 62 61 public: … … 161 160 struct tr_session_stats myCumulativeStats; 162 161 QString mySessionVersion; 163 int64_t myDownloadDirFreeSpace;164 162 }; 165 163
Note: See TracChangeset
for help on using the changeset viewer.