Changeset 13991


Ignore:
Timestamp:
Feb 9, 2013, 4:05:03 AM (8 years ago)
Author:
jordan
Message:

(trunk) first draft of changing the FreeSpace? API to behave as https://trac.transmissionbt.com/ticket/4076#comment:25 -- libT, rpc, qt, and gtk implementations.

Location:
trunk
Files:
2 added
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r13887 r13991  
    15241524      if (tr_variantDictFindStr (args,  TR_KEY_download_dir, &str, NULL))
    15251525        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));
    15281526      if (tr_variantDictFindInt (args, TR_KEY_peer_port, &i))
    15291527        printf ("  Listenport: %" PRId64 "\n", i);
  • trunk/extras/rpc-spec.txt

    r13844 r13991  
    458458   "config-dir"                     | string     | location of transmission's configuration directory
    459459   "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 calculated
    461460   "download-queue-size"            | number     | max number of torrents to download at once (see download-queue-enabled)
    462461   "download-queue-enabled"         | boolean    | if true, limit how many torrents can be downloaded at once
     
    517516   Method name: "session-set"
    518517   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"
    521520   Response arguments: none
    522521
     
    598597
    599598   Response arguments: none
     599
     6004.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
    600620
    6016215.0.  Protocol Versions
     
    739759         |         | yes       |                      | new method "torrent-start-now"
    740760   ------+---------+-----------+--------------------------+-------------------------------
    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"
    742763         |         | yes       | torrent-rename-path  | new method
    743 
     764         |         | yes       | free-space           | new method
     765
  • trunk/gtk/open-dialog.c

    r13913 r13991  
    9595    GtkWidget *  trash_check;
    9696    GtkWidget *  priority_combo;
     97    GtkWidget *  freespace_label;
    9798    char *       filename;
    9899    char *       downloadDir;
     
    227228        data->downloadDir = g_strdup (fname);
    228229        updateTorrent (data);
     230
     231        gtr_freespace_label_set_dir (data->freespace_label, data->downloadDir);
    229232    }
    230233
     
    340343                      G_CALLBACK (downloadDirChanged), data);
    341344
     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
    342352    // file list row
    343353    row++;
  • trunk/gtk/tr-prefs.c

    r13955 r13991  
    3030**/
    3131
     32struct 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
    3249#define PREF_KEY "pref-key"
    3350
     
    257274
    258275static GtkWidget*
    259 downloadingPage (GObject * core)
     276downloadingPage (GObject * core, struct prefs_dialog_data * data)
    260277{
    261278  GtkWidget * t;
     
    289306    w = new_path_chooser_button (TR_KEY_download_dir, core);
    290307    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);
    291312
    292313  hig_workarea_add_section_divider (t, &row);
     
    12431264****/
    12441265
     1266static void
     1267on_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
     1277static void
     1278on_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
    12451297GtkWidget *
    12461298gtr_prefs_dialog_new (GtkWindow * parent, GObject * core)
    12471299{
     1300  size_t i;
    12481301  GtkWidget * d;
    12491302  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);
    12501309
    12511310  d = gtk_dialog_new_with_buttons (_("Transmission Preferences"),
     
    12551314                                   GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
    12561315                                   NULL);
     1316  g_object_weak_ref (G_OBJECT(d), on_prefs_dialog_destroyed, data);
    12571317  gtk_window_set_role (GTK_WINDOW (d), "transmission-preferences-dialog");
    12581318  gtk_container_set_border_width (GTK_CONTAINER (d), GUI_PAD);
     
    12631323  gtk_notebook_append_page (GTK_NOTEBOOK (n), speedPage (core),
    12641324                            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),
    12661326                            gtk_label_new (C_("Gerund", "Downloading")));
    12671327  gtk_notebook_append_page (GTK_NOTEBOOK (n), seedingPage (core),
     
    12761336                            gtk_label_new (_("Remote")));
    12771337
     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
    12781342  g_signal_connect (d, "response", G_CALLBACK (response_cb), core);
    12791343  gtr_dialog_set_content (GTK_DIALOG (d), n);
  • trunk/gtk/tr-window.c

    r13983 r13991  
    5555    GtkLabel           * dl_lb;
    5656    GtkLabel           * stats_lb;
    57     GtkLabel           * freespace_lb;
    58     GtkWidget          * freespace_icon;
    5957    GtkWidget          * alt_speed_image;
    6058    GtkWidget          * alt_speed_button;
     
    716714  sibling = w;
    717715
    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 
    737716  /* download */
    738717  w = dl_lb = gtk_label_new (NULL);
     
    813792  gtr_window_refresh (GTK_WINDOW(self));
    814793  return self;
    815 }
    816 
    817 static void
    818 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);
    854794}
    855795
     
    959899      updateSpeeds (p);
    960900      updateStats (p);
    961       updateFreeSpace (p);
    962901    }
    963902}
  • trunk/gtk/util.c

    r13970 r13991  
    2727#include "conf.h"
    2828#include "hig.h"
     29#include "tr-core.h"
    2930#include "tr-prefs.h"
    3031#include "util.h"
     
    632633    gtk_label_set_text (lb, newstr);
    633634}
     635
     636/***
     637****
     638***/
     639
     640struct freespace_label_data
     641{
     642  guint timer_id;
     643  TrCore * core;
     644  GtkLabel * label;
     645  char * dir;
     646};
     647
     648static void on_freespace_label_core_destroyed (gpointer gdata, GObject * dead_core);
     649static void on_freespace_label_destroyed      (gpointer gdata, GObject * dead_label);
     650
     651static void
     652freespace_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
     667static GQuark
     668freespace_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
     678static void
     679on_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
     686static void
     687on_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
     694static gboolean
     695on_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
     723GtkWidget *
     724gtr_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
     743void
     744gtr_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  
    110110***/
    111111
     112struct _TrCore;
     113
     114GtkWidget * gtr_freespace_label_new (struct _TrCore * core, const char * dir);
     115
     116void gtr_freespace_label_set_dir (GtkWidget * label, const char * dir);
     117
     118/***
     119****
     120***/
     121
    112122void gtr_unrecognized_url_dialog (GtkWidget * parent, const char * url);
    113123
  • trunk/libtransmission/platform.c

    r13975 r13991  
    5757
    5858#include <assert.h>
     59#include <errno.h>
    5960#include <stdio.h>
    6061#include <stdlib.h>
     
    8182 #include <xfs/xqm.h>
    8283#endif
     84
     85#include <event2/util.h> /* evutil_ascii_strcasecmp () */
    8386
    8487#include "transmission.h"
     
    733736
    734737#ifndef WIN32
    735 static char *
     738static const char *
    736739getdev (const char * path)
    737740{
     
    784787}
    785788
    786 static char *
     789static const char *
    787790getfstype (const char * device)
    788791{
     
    834837}
    835838
    836 static char *
     839static const char *
    837840getblkdev (const char * path)
    838841{
    839842  char * c;
    840843  char * dir;
    841   char * device;
     844  const char * device;
    842845
    843846  dir = tr_strdup(path);
     
    861864
    862865static int64_t
    863 getquota (char * device)
     866getquota (const char * device)
    864867{
    865868  struct dqblk dq;
     
    961964
    962965static int64_t
    963 tr_getQuotaFreeSpace (const char * path, char * device, char * fstype)
    964 {
    965   int64_t ret=-1;
     966tr_getQuotaFreeSpace (const struct tr_device_info * info)
     967{
     968  int64_t ret = -1;
    966969
    967970#ifndef WIN32
    968971
    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"))
    987973    {
    988974#ifdef HAVE_XQM
    989       ret = getxfsquota(device);
     975      ret = getxfsquota (info->device);
    990976#endif
    991977    }
    992978  else
    993979    {
    994       ret = getquota(device);
    995     }
    996 
     980      ret = getquota (info->device);
     981    }
    997982#endif /* WIN32 */
     983
    998984  return ret;
    999985}
     
    10221008}
    10231009
     1010struct tr_device_info *
     1011tr_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
     1023void
     1024tr_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
    10241035int64_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;
     1036tr_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;
    10331054}
    10341055
  • trunk/libtransmission/platform.h

    r13698 r13991  
    4343const char * tr_getWebClientDir (const tr_session *);
    4444
     45struct tr_device_info
     46{
     47  char * path;
     48  char * device;
     49  char * fstype;
     50};
     51
     52struct tr_device_info * tr_device_info_create (const char * path);
     53
    4554/** If the disk quota is enabled and readable, this returns how much is available in the quota.
    4655    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);
     56int64_t tr_device_info_get_free_space (const struct tr_device_info * info);
     57
     58void tr_device_info_free (struct tr_device_info * info);
    4859
    4960
  • trunk/libtransmission/quark.c

    r13946 r13991  
    7979  { "doneDate", 8 },
    8080  { "download-dir", 12 },
    81   { "download-dir-free-space", 23 },
    8281  { "download-queue-enabled", 22 },
    8382  { "download-queue-size", 19 },
  • trunk/libtransmission/quark.h

    r13933 r13991  
    8989  TR_KEY_doneDate,
    9090  TR_KEY_download_dir,
    91   TR_KEY_download_dir_free_space,
    9291  TR_KEY_download_queue_enabled,
    9392  TR_KEY_download_queue_size,
  • trunk/libtransmission/rpc-test.c

    r13916 r13991  
    107107  check (tr_variantDictFind (args, TR_KEY_dht_enabled) != NULL);
    108108  check (tr_variantDictFind (args, TR_KEY_download_dir) != NULL);
    109   check (tr_variantDictFind (args, TR_KEY_download_dir_free_space) != NULL);
    110109  check (tr_variantDictFind (args, TR_KEY_download_queue_enabled) != NULL);
    111110  check (tr_variantDictFind (args, TR_KEY_download_queue_size) != NULL);
  • trunk/libtransmission/rpcimpl.c

    r13970 r13991  
    17271727static const char*
    17281728sessionSet (tr_session               * session,
    1729             tr_variant                  * args_in,
    1730             tr_variant                  * args_out UNUSED,
     1729            tr_variant               * args_in,
     1730            tr_variant               * args_out UNUSED,
    17311731            struct tr_rpc_idle_data  * idle_data UNUSED)
    17321732{
     
    19061906    tr_variantDictAddBool (d, TR_KEY_download_queue_enabled, tr_sessionGetQueueEnabled (s, TR_DOWN));
    19071907    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));
    19091908    tr_variantDictAddInt  (d, TR_KEY_peer_limit_global, tr_sessionGetPeerLimit (s));
    19101909    tr_variantDictAddInt  (d, TR_KEY_peer_limit_per_torrent, tr_sessionGetPeerLimitPerTorrent (s));
     
    19491948}
    19501949
     1950static const char*
     1951freeSpace (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
    19511977/***
    19521978****
     
    19792005    { "port-test",             false, portTest            },
    19802006    { "blocklist-update",      false, blocklistUpdate     },
     2007    { "free-space",            true,  freeSpace           },
    19812008    { "session-close",         true,  sessionClose        },
    19822009    { "session-get",           true,  sessionGet          },
  • trunk/libtransmission/session.c

    r13969 r13991  
    387387  tr_variantDictAddBool (d, TR_KEY_utp_enabled,                  s->isUTPEnabled);
    388388  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));
    390390  tr_variantDictAddInt  (d, TR_KEY_download_queue_size,          tr_sessionGetQueueSize (s, TR_DOWN));
    391391  tr_variantDictAddBool (d, TR_KEY_download_queue_enabled,       tr_sessionGetQueueEnabled (s, TR_DOWN));
     
    954954tr_sessionSetDownloadDir (tr_session * session, const char * dir)
    955955{
    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;
    965964}
    966965
     
    968967tr_sessionGetDownloadDir (const tr_session * session)
    969968{
    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;
    973977}
    974978
    975979int64_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);
     980tr_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;
    983990}
    984991
     
    18841891        tr_free (session->metainfoLookup);
    18851892    }
     1893    tr_device_info_free (session->downloadDir);
    18861894    tr_free (session->torrentDoneScript);
    18871895    tr_free (session->tag);
     
    18891897    tr_free (session->resumeDir);
    18901898    tr_free (session->torrentDir);
    1891     tr_free (session->downloadDir);
    18921899    tr_free (session->incompleteDir);
    18931900    tr_free (session->blocklist_url);
  • trunk/libtransmission/session.h

    r13933 r13991  
    5757struct tr_cache;
    5858struct tr_fdInfo;
     59struct tr_device_info;
    5960
    6061typedef void (tr_web_config_func)(tr_session * session, void * curl_pointer, const char * url, void * user_data);
     
    184185    char *                       tag;
    185186    char *                       configDir;
    186     char *                       downloadDir;
    187     char                         downloadDirBlkDev[TR_PATH_MAX + 1];
    188     char                         downloadDirFsType[TR_PATH_MAX + 1];
    189187    char *                       resumeDir;
    190188    char *                       torrentDir;
     
    192190
    193191    char *                       blocklist_url;
     192
     193    struct tr_device_info *      downloadDir;
    194194
    195195    struct tr_list *             blocklists;
  • trunk/libtransmission/torrent-ctor.c

    r13683 r13991  
    453453        tr_ctorSetPaused (ctor, TR_FALLBACK, tr_sessionGetPaused (session));
    454454        tr_ctorSetPeerLimit (ctor, TR_FALLBACK, session->peerLimitPerTorrent);
    455         tr_ctorSetDownloadDir (ctor, TR_FALLBACK, session->downloadDir);
     455        tr_ctorSetDownloadDir (ctor, TR_FALLBACK, tr_sessionGetDownloadDir(session));
    456456    }
    457457    tr_ctorSetSave (ctor, true);
  • trunk/libtransmission/torrent.c

    r13980 r13991  
    8383tr_torrentId (const tr_torrent * tor)
    8484{
    85     return tor->uniqueId;
     85    return tor ? tor->uniqueId : -1;
    8686}
    8787
  • trunk/libtransmission/transmission.h

    r13913 r13991  
    292292
    293293/**
    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.
    295295 * @return zero or positive integer on success, -1 in case of error.
    296296 */
    297 int64_t tr_sessionGetDownloadDirFreeSpace (tr_session * session);
     297int64_t tr_sessionGetDirFreeSpace (tr_session * session, const char * dir);
    298298
    299299/**
  • trunk/libtransmission/utils.c

    r13970 r13991  
    421421}
    422422
     423int64_t
     424tr_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
    423444/****
    424445*****
  • trunk/libtransmission/utils.h

    r13969 r13991  
    140140
    141141bool 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 */
     147int64_t tr_getDirFreeSpace (const char * path);
    142148
    143149
  • trunk/qt/mainwin.cc

    r13982 r13991  
    282282  connect (&mySession, SIGNAL (sourceChanged ()), this, SLOT (onSessionSourceChanged ()));
    283283  connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (refreshStatusBar ()));
    284   connect (&mySession, SIGNAL (sessionUpdated ()), this, SLOT (refreshFreeSpace ()));
    285284  connect (&mySession, SIGNAL (dataReadProgress ()), this, SLOT (dataReadProgress ()));
    286285  connect (&mySession, SIGNAL (dataSendProgress ()), this, SLOT (dataSendProgress ()));
     
    304303  refreshTrayIconSoon ();
    305304  refreshStatusBar ();
    306   refreshFreeSpace ();
    307305  refreshTitle ();
    308306}
     
    388386
    389387    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);
    400388    h->addWidget (l);
    401389
     
    714702
    715703void
    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 void
    738704TrMainWindow :: refreshTrayIconSoon ()
    739705{
  • trunk/qt/mainwin.h

    r13927 r13991  
    105105    void showSessionRatio ();
    106106    void showSessionTransfer ();
    107     void refreshFreeSpace ();
    108107    void refreshTitle ();
    109108    void refreshStatusBar ();
     
    159158    QLabel * myDownloadSpeedLabel;
    160159    QLabel * myUploadSpeedLabel;
    161     QLabel * myFreeSpaceTextLabel;
    162     QLabel * myFreeSpaceIconLabel;
    163160    QLabel * myNetworkLabel;
    164161
  • trunk/qt/options.cc

    r13893 r13991  
    3737#include "add-data.h"
    3838#include "file-tree.h"
     39#include "freespace-label.h"
    3940#include "hig.h"
    4041#include "options.h"
     
    119120    l = new QLabel( tr( "&Destination folder:" ) );
    120121    layout->addWidget( l, ++row, 0, Qt::AlignLeft );
     122    const QString downloadDir (prefs.getString (Prefs::DOWNLOAD_DIR));
    121123
    122124    if( session.isLocal( ) )
    123125    {
    124         myDestination.setPath( prefs.getString( Prefs :: DOWNLOAD_DIR ) );
     126        myDestination.setPath (downloadDir);
    125127        p = myDestinationButton = new QPushButton;
    126128        p->setIcon( folderPixmap );
     
    134136    {
    135137        QLineEdit * e = myDestinationEdit = new QLineEdit;
    136         e->setText( prefs.getString( Prefs :: DOWNLOAD_DIR ) );
     138        e->setText (downloadDir);
    137139        layout->addWidget( e, row, 1 );
    138140        l->setBuddy( e );
    139141    }
     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);
    140146
    141147    myTree = new FileTreeView (0, false);
     
    175181    layout->addWidget( b, ++row, 0, 1, 2 );
    176182
    177     layout->setRowStretch( 2, 2 );
     183    layout->setRowStretch( 3, 2 );
    178184    layout->setColumnStretch( 1, 2 );
    179185    layout->setSpacing( HIG :: PAD );
     
    449455
    450456void
    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( );
     457Options :: 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 ();
    458465    }
    459466}
  • trunk/qt/options.h

    r13667 r13991  
    2222#include <QVector>
    2323#include <QMap>
    24 #include <QPushButton>
    2524#include <QString>
    2625#include <QStringList>
     
    3332#include "file-tree.h" // FileList
    3433
    35 class FileTreeView;
    36 class Prefs;
    3734class QCheckBox;
    3835class QComboBox;
     36class QPushButton;
     37
     38class FileTreeView;
     39class FreespaceLabel;
     40class Prefs;
    3941class Session;
    4042
     
    7981        tr_info myInfo;
    8082        FileTreeView * myTree;
     83        FreespaceLabel * myFreespaceLabel;
    8184        QCheckBox * myStartCheck;
    8285        QCheckBox * myTrashCheck;
  • trunk/qt/prefs-dialog.cc

    r13813 r13991  
    3737#include <QVBoxLayout>
    3838
     39#include "freespace-label.h"
    3940#include "formatter.h"
    4041#include "hig.h"
     
    589590        hig->addRow( tr( "Save to &Location:" ), b );
    590591
     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
    591599    hig->addSectionDivider( );
    592600    hig->addSectionTitle( tr( "Download Queue" ) );
     
    747755
    748756        case Prefs :: DOWNLOAD_DIR: {
    749             QString path( myPrefs.getString( key ) );
     757            const QString path( myPrefs.getString( key ) );
    750758            myDestinationButton->setText( QFileInfo(path).fileName() );
     759            myFreespaceLabel->setPath (path);
    751760            break;
    752761        }
  • trunk/qt/prefs-dialog.h

    r13796 r13991  
    3333class QHttp;
    3434
     35class FreespaceLabel;
    3536class Prefs;
    3637class Session;
     
    109110        QWidgetList myBlockWidgets;
    110111        QWidgetList myUnsupportedWhenRemote;
     112        FreespaceLabel * myFreespaceLabel;
    111113
    112114        int myBlocklistHttpTag;
  • trunk/qt/qtr.pro

    r13680 r13991  
    5353           filterbar.cc \
    5454           filters.cc \
     55           freespace-label.cc \
    5556           formatter.cc \
    5657           hig.cc \
  • trunk/qt/session.cc

    r13981 r13991  
    259259  mySession (0),
    260260  myConfigDir (QString::fromUtf8 (configDir)),
    261   myNAM (0),
    262   myDownloadDirFreeSpace (-1)
     261  myNAM (0)
    263262{
    264263  myStats.ratio = TR_RATIO_NA;
     
    10091008    mySessionVersion = str;
    10101009
    1011   if (tr_variantDictFindInt (d, TR_KEY_download_dir_free_space, &i) && (myDownloadDirFreeSpace != i))
    1012     myDownloadDirFreeSpace = i;
    1013 
    10141010  //std::cerr << "Session :: updateInfo end" << std::endl;
    10151011  connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int)));
  • trunk/qt/session.h

    r13944 r13991  
    5858    const struct tr_session_stats& getCumulativeStats () const { return myCumulativeStats; }
    5959    const QString& sessionVersion () const { return mySessionVersion; }
    60     int64_t downloadDirFreeSpace () const { return myDownloadDirFreeSpace; }
    6160
    6261  public:
     
    161160    struct tr_session_stats myCumulativeStats;
    162161    QString mySessionVersion;
    163     int64_t myDownloadDirFreeSpace;
    164162};
    165163
Note: See TracChangeset for help on using the changeset viewer.