Changeset 14132


Ignore:
Timestamp:
Jul 20, 2013, 4:19:15 PM (9 years ago)
Author:
jordan
Message:

use consistent code indentation/whitespace in open dialog, file list, and set location dialog

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/file-list.c

    r14018 r14132  
    3232enum
    3333{
    34     /* these two fields could be any number at all so long as they're not
    35      * TR_PRI_LOW, TR_PRI_NORMAL, TR_PRI_HIGH, TRUE, or FALSE */
    36     NOT_SET = 1000,
    37     MIXED = 1001
     34  /* these two fields could be any number at all so long as they're not
     35   * TR_PRI_LOW, TR_PRI_NORMAL, TR_PRI_HIGH, TRUE, or FALSE */
     36  NOT_SET = 1000,
     37  MIXED = 1001
    3838};
    3939
    4040enum
    4141{
    42     FC_ICON,
    43     FC_LABEL,
    44     FC_LABEL_ESC,
    45     FC_PROG,
    46     FC_INDEX,
    47     FC_SIZE,
    48     FC_SIZE_STR,
    49     FC_HAVE,
    50     FC_PRIORITY,
    51     FC_ENABLED,
    52     N_FILE_COLS
     42  FC_ICON,
     43  FC_LABEL,
     44  FC_LABEL_ESC,
     45  FC_PROG,
     46  FC_INDEX,
     47  FC_SIZE,
     48  FC_SIZE_STR,
     49  FC_HAVE,
     50  FC_PRIORITY,
     51  FC_ENABLED,
     52  N_FILE_COLS
    5353};
    5454
    5555typedef struct
    5656{
    57     TrCore        * core;
    58     GtkWidget     * top;
    59     GtkWidget     * view;
    60     GtkTreeModel  * model; /* same object as store, but recast */
    61     GtkTreeStore  * store; /* same object as model, but recast */
    62     int             torrentId;
    63     guint           timeout_tag;
     57  TrCore        * core;
     58  GtkWidget     * top;
     59  GtkWidget     * view;
     60  GtkTreeModel  * model; /* same object as store, but recast */
     61  GtkTreeStore  * store; /* same object as model, but recast */
     62  int             torrentId;
     63  guint           timeout_tag;
    6464}
    6565FileData;
     
    6868clearData (FileData * data)
    6969{
    70     data->torrentId = -1;
    71 
    72     if (data->timeout_tag) {
    73         g_source_remove (data->timeout_tag);
    74         data->timeout_tag = 0;
     70  data->torrentId = -1;
     71
     72  if (data->timeout_tag)
     73    {
     74      g_source_remove (data->timeout_tag);
     75      data->timeout_tag = 0;
    7576    }
    7677}
     
    7980freeData (gpointer data)
    8081{
    81     clearData (data);
    82     g_free (data);
     82  clearData (data);
     83  g_free (data);
    8384}
    8485
     
    8990struct RefreshData
    9091{
    91     int sort_column_id;
    92     gboolean resort_needed;
    93 
    94     tr_file_stat  * refresh_file_stat;
    95     tr_torrent * tor;
    96 
    97     FileData * file_data;
     92  int sort_column_id;
     93  gboolean resort_needed;
     94
     95  tr_file_stat  * refresh_file_stat;
     96  tr_torrent * tor;
     97
     98  FileData * file_data;
    9899};
    99100
     
    104105                     gpointer       gdata)
    105106{
    106     struct RefreshData * refresh_data = gdata;
    107     FileData * data = refresh_data->file_data;
    108     unsigned int index;
    109     uint64_t size;
    110     uint64_t old_have;
    111     int old_prog;
    112     int old_priority;
    113     int old_enabled;
    114     const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
    115 
    116     gtk_tree_model_get (model, iter, FC_ENABLED, &old_enabled,
    117                                      FC_PRIORITY, &old_priority,
    118                                      FC_INDEX, &index,
    119                                      FC_HAVE, &old_have,
    120                                      FC_SIZE, &size,
    121                                      FC_PROG, &old_prog,
    122                                      -1);
    123 
    124     if (is_file)
    125     {
    126         tr_torrent * tor = refresh_data->tor;
    127         const tr_info * inf = tr_torrentInfo (tor);
    128         const int enabled = !inf->files[index].dnd;
    129         const int priority = inf->files[index].priority;
    130         const uint64_t have = refresh_data->refresh_file_stat[index].bytesCompleted;
    131         const int prog = size ? (int)((100.0*have)/size) : 1;
    132 
    133         if ((priority!=old_priority) || (enabled!=old_enabled) || (have!=old_have) || (prog!=old_prog))
     107  struct RefreshData * refresh_data = gdata;
     108  FileData * data = refresh_data->file_data;
     109  unsigned int index;
     110  uint64_t size;
     111  uint64_t old_have;
     112  int old_prog;
     113  int old_priority;
     114  int old_enabled;
     115  const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
     116
     117  gtk_tree_model_get (model, iter, FC_ENABLED, &old_enabled,
     118                                   FC_PRIORITY, &old_priority,
     119                                   FC_INDEX, &index,
     120                                   FC_HAVE, &old_have,
     121                                   FC_SIZE, &size,
     122                                   FC_PROG, &old_prog,
     123                                   -1);
     124
     125  if (is_file)
     126    {
     127      tr_torrent * tor = refresh_data->tor;
     128      const tr_info * inf = tr_torrentInfo (tor);
     129      const int enabled = !inf->files[index].dnd;
     130      const int priority = inf->files[index].priority;
     131      const uint64_t have = refresh_data->refresh_file_stat[index].bytesCompleted;
     132      const int prog = size ? (int)((100.0*have)/size) : 1;
     133
     134      if ((priority!=old_priority) || (enabled!=old_enabled) || (have!=old_have) || (prog!=old_prog))
    134135        {
    135             /* Changing a value in the sort column can trigger a resort
    136              * which breaks this foreach () call. (See #3529)
    137              * As a workaround: if that's about to happen, temporarily disable
    138              * sorting until we finish walking the tree. */
    139             if (!refresh_data->resort_needed)
     136          /* Changing a value in the sort column can trigger a resort
     137           * which breaks this foreach () call. (See #3529)
     138           * As a workaround: if that's about to happen, temporarily disable
     139           * sorting until we finish walking the tree. */
     140          if (!refresh_data->resort_needed)
    140141            {
    141                 if ((refresh_data->resort_needed =
     142              if ((refresh_data->resort_needed =
    142143                  ((refresh_data->sort_column_id==FC_PRIORITY) && (priority!=old_priority)) ||
    143144                  ((refresh_data->sort_column_id==FC_ENABLED) && (enabled!=old_enabled))))
    144145                {
    145                     refresh_data->resort_needed = TRUE;
    146                     gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->model),
    147                                                           GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
    148                                                           GTK_SORT_ASCENDING);
     146                  refresh_data->resort_needed = TRUE;
     147                  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->model),
     148                                                        GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
     149                                                        GTK_SORT_ASCENDING);
    149150                }
    150151            }
    151152
    152             gtk_tree_store_set (data->store, iter, FC_PRIORITY, priority,
    153                                                    FC_ENABLED, enabled,
    154                                                    FC_HAVE, have,
    155                                                    FC_PROG, prog,
    156                                                    -1);
     153          gtk_tree_store_set (data->store, iter, FC_PRIORITY, priority,
     154                                                 FC_ENABLED, enabled,
     155                                                 FC_HAVE, have,
     156                                                 FC_PROG, prog,
     157                                                 -1);
    157158        }
    158159    }
    159     else
    160     {
    161         GtkTreeIter child;
    162         uint64_t sub_size = 0;
    163         uint64_t have = 0;
    164         int prog;
    165         int enabled = NOT_SET;
    166         int priority = NOT_SET;
    167 
    168         /* since gtk_tree_model_foreach () is depth-first, we can
    169          * get the `sub' info by walking the immediate children */
    170 
    171         if (gtk_tree_model_iter_children (model, &child, iter)) do
     160  else
     161    {
     162      GtkTreeIter child;
     163      uint64_t sub_size = 0;
     164      uint64_t have = 0;
     165      int prog;
     166      int enabled = NOT_SET;
     167      int priority = NOT_SET;
     168
     169      /* since gtk_tree_model_foreach () is depth-first, we can
     170       * get the `sub' info by walking the immediate children */
     171
     172      if (gtk_tree_model_iter_children (model, &child, iter)) do
    172173        {
    173             int child_enabled;
    174             int child_priority;
    175             int64_t child_have, child_size;
    176 
    177             gtk_tree_model_get (model, &child, FC_SIZE, &child_size,
    178                                                FC_HAVE, &child_have,
    179                                                FC_PRIORITY, &child_priority,
    180                                                FC_ENABLED, &child_enabled,
    181                                                -1);
    182 
    183             if ((child_enabled != FALSE) && (child_enabled != NOT_SET))
     174          int child_enabled;
     175          int child_priority;
     176          int64_t child_have, child_size;
     177
     178          gtk_tree_model_get (model, &child, FC_SIZE, &child_size,
     179                                             FC_HAVE, &child_have,
     180                                             FC_PRIORITY, &child_priority,
     181                                             FC_ENABLED, &child_enabled,
     182                                             -1);
     183
     184          if ((child_enabled != FALSE) && (child_enabled != NOT_SET))
    184185            {
    185186              sub_size += child_size;
     
    187188            }
    188189
    189             if (enabled == NOT_SET)
    190                 enabled = child_enabled;
    191             else if (enabled != child_enabled)
    192                 enabled = MIXED;
    193 
    194             if (priority == NOT_SET)
    195                 priority = child_priority;
    196             else if (priority != child_priority)
    197                 priority = MIXED;
     190          if (enabled == NOT_SET)
     191            enabled = child_enabled;
     192          else if (enabled != child_enabled)
     193            enabled = MIXED;
     194
     195          if (priority == NOT_SET)
     196            priority = child_priority;
     197          else if (priority != child_priority)
     198            priority = MIXED;
    198199        }
    199         while (gtk_tree_model_iter_next (model, &child));
    200 
    201         prog = sub_size ? (int)((100.0*have)/sub_size) : 1;
    202 
    203         if ((size!=sub_size) || (have!=old_have)
     200      while (gtk_tree_model_iter_next (model, &child));
     201
     202      prog = sub_size ? (int)((100.0*have)/sub_size) : 1;
     203
     204      if ((size!=sub_size) || (have!=old_have)
    204205                             || (priority!=old_priority)
    205206                             || (enabled!=old_enabled)
    206207                             || (prog!=old_prog))
    207208        {
    208             char size_str[64];
    209             tr_strlsize (size_str, sub_size, sizeof size_str);
    210             gtk_tree_store_set (data->store, iter, FC_SIZE, sub_size,
    211                                                    FC_SIZE_STR, size_str,
    212                                                    FC_HAVE, have,
    213                                                    FC_PRIORITY, priority,
    214                                                    FC_ENABLED, enabled,
    215                                                    FC_PROG, prog,
    216                                                    -1);
     209          char size_str[64];
     210          tr_strlsize (size_str, sub_size, sizeof size_str);
     211          gtk_tree_store_set (data->store, iter, FC_SIZE, sub_size,
     212                                                 FC_SIZE_STR, size_str,
     213                                                 FC_HAVE, have,
     214                                                 FC_PRIORITY, priority,
     215                                                 FC_ENABLED, enabled,
     216                                                 FC_PROG, prog,
     217                                                 -1);
    217218        }
    218219    }
    219220
    220     return FALSE; /* keep walking */
     221  return FALSE; /* keep walking */
    221222}
    222223
     
    227228                                          gpointer                  data)
    228229{
    229     GtkTreeIter child;
    230     if (gtk_tree_model_iter_children (model, &child, parent)) do
    231         gtr_tree_model_foreach_postorder_subtree (model, &child, func, data);
    232     while (gtk_tree_model_iter_next (model, &child));
    233     if (parent)
    234         func (model, NULL, parent, data);
     230  GtkTreeIter child;
     231  if (gtk_tree_model_iter_children (model, &child, parent)) do
     232    gtr_tree_model_foreach_postorder_subtree (model, &child, func, data);
     233  while (gtk_tree_model_iter_next (model, &child));
     234  if (parent)
     235    func (model, NULL, parent, data);
    235236}
    236237
     
    240241                                  gpointer                  data)
    241242{
    242     GtkTreeIter iter;
    243     if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
    244         gtr_tree_model_foreach_postorder_subtree (model, &iter, func, data);
    245     while (gtk_tree_model_iter_next (model, &iter));
     243  GtkTreeIter iter;
     244  if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
     245    gtr_tree_model_foreach_postorder_subtree (model, &iter, func, data);
     246  while (gtk_tree_model_iter_next (model, &iter));
    246247}
    247248
     
    249250refresh (FileData * data)
    250251{
    251     tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
    252 
    253     if (tor == NULL)
    254     {
    255         gtr_file_list_clear (data->top);
    256     }
    257     else
    258     {
    259         GtkSortType order;
    260         int sort_column_id;
    261         tr_file_index_t fileCount;
    262         struct RefreshData refresh_data;
    263         GtkTreeSortable * sortable = GTK_TREE_SORTABLE (data->model);
    264         gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &order);
    265 
    266         refresh_data.sort_column_id = sort_column_id;
    267         refresh_data.resort_needed = FALSE;
    268         refresh_data.refresh_file_stat = tr_torrentFiles (tor, &fileCount);
    269         refresh_data.tor = tor;
    270         refresh_data.file_data = data;
    271 
    272         gtr_tree_model_foreach_postorder (data->model, refreshFilesForeach, &refresh_data);
    273 
    274         if (refresh_data.resort_needed)
    275             gtk_tree_sortable_set_sort_column_id (sortable, sort_column_id, order);
    276 
    277         tr_torrentFilesFree (refresh_data.refresh_file_stat, fileCount);
     252  tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
     253
     254  if (tor == NULL)
     255    {
     256      gtr_file_list_clear (data->top);
     257    }
     258  else
     259    {
     260      GtkSortType order;
     261      int sort_column_id;
     262      tr_file_index_t fileCount;
     263      struct RefreshData refresh_data;
     264      GtkTreeSortable * sortable = GTK_TREE_SORTABLE (data->model);
     265      gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &order);
     266
     267      refresh_data.sort_column_id = sort_column_id;
     268      refresh_data.resort_needed = FALSE;
     269      refresh_data.refresh_file_stat = tr_torrentFiles (tor, &fileCount);
     270      refresh_data.tor = tor;
     271      refresh_data.file_data = data;
     272
     273      gtr_tree_model_foreach_postorder (data->model, refreshFilesForeach, &refresh_data);
     274
     275      if (refresh_data.resort_needed)
     276        gtk_tree_sortable_set_sort_column_id (sortable, sort_column_id, order);
     277
     278      tr_torrentFilesFree (refresh_data.refresh_file_stat, fileCount);
    278279    }
    279280}
     
    282283refreshModel (gpointer file_data)
    283284{
    284     refresh (file_data);
    285 
    286     return G_SOURCE_CONTINUE;
     285  refresh (file_data);
     286
     287  return G_SOURCE_CONTINUE;
    287288}
    288289
     
    293294struct ActiveData
    294295{
    295     GtkTreeSelection  * sel;
    296     GArray            * array;
     296  GtkTreeSelection  * sel;
     297  GArray            * array;
    297298};
    298299
     
    303304                         gpointer       gdata)
    304305{
    305     const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
    306 
    307     if (is_file)
    308     {
    309         struct ActiveData * data = gdata;
    310 
    311         /* active means: if it's selected or any ancestor is selected */
    312 
    313         gboolean is_active = gtk_tree_selection_iter_is_selected (data->sel, iter);
    314 
    315         if (!is_active)
     306  const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
     307
     308  if (is_file)
     309    {
     310      struct ActiveData * data = gdata;
     311
     312      /* active means: if it's selected or any ancestor is selected */
     313      gboolean is_active = gtk_tree_selection_iter_is_selected (data->sel, iter);
     314
     315      if (!is_active)
    316316        {
    317             GtkTreeIter walk = *iter;
    318             GtkTreeIter parent;
    319             while (!is_active && gtk_tree_model_iter_parent (model, &parent, &walk))
     317          GtkTreeIter walk = *iter;
     318          GtkTreeIter parent;
     319          while (!is_active && gtk_tree_model_iter_parent (model, &parent, &walk))
    320320            {
    321                 is_active = gtk_tree_selection_iter_is_selected (data->sel, &parent);
    322                 walk = parent;
     321              is_active = gtk_tree_selection_iter_is_selected (data->sel, &parent);
     322              walk = parent;
    323323            }
    324324        }
    325325
    326         if (is_active)
     326      if (is_active)
    327327        {
    328             unsigned int i;
    329             gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
    330             g_array_append_val (data->array, i);
     328          unsigned int i;
     329          gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
     330          g_array_append_val (data->array, i);
    331331        }
    332332    }
    333333
    334     return FALSE; /* keep walking */
     334  return FALSE; /* keep walking */
    335335}
    336336
     
    338338getSelectedFilesAndDescendants (GtkTreeView * view)
    339339{
    340     struct ActiveData data;
    341 
    342     data.sel = gtk_tree_view_get_selection (view);
    343     data.array = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
    344     gtk_tree_model_foreach (gtk_tree_view_get_model (view),
    345                             getSelectedFilesForeach, &data);
    346     return data.array;
     340  struct ActiveData data;
     341
     342  data.sel = gtk_tree_view_get_selection (view);
     343  data.array = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
     344  gtk_tree_model_foreach (gtk_tree_view_get_model (view),
     345                          getSelectedFilesForeach, &data);
     346  return data.array;
    347347}
    348348
    349349struct SubtreeForeachData
    350350{
    351     GArray       * array;
    352     GtkTreePath  * path;
     351  GArray       * array;
     352  GtkTreePath  * path;
    353353};
    354354
     
    359359                   gpointer         gdata)
    360360{
    361     const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
    362 
    363     if (is_file)
    364     {
    365         struct SubtreeForeachData * data = gdata;
    366 
    367         if (!gtk_tree_path_compare (path, data->path) || gtk_tree_path_is_descendant (path, data->path))
     361  const gboolean is_file = !gtk_tree_model_iter_has_child (model, iter);
     362
     363  if (is_file)
     364    {
     365      struct SubtreeForeachData * data = gdata;
     366
     367      if (!gtk_tree_path_compare (path, data->path) || gtk_tree_path_is_descendant (path, data->path))
    368368        {
    369             unsigned int i;
    370             gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
    371             g_array_append_val (data->array, i);
     369          unsigned int i;
     370          gtk_tree_model_get (model, iter, FC_INDEX, &i, -1);
     371          g_array_append_val (data->array, i);
    372372        }
    373373    }
    374374
    375     return FALSE; /* keep walking */
     375  return FALSE; /* keep walking */
    376376}
    377377
     
    379379getSubtree (GtkTreeView * view, GtkTreePath * path, GArray * indices)
    380380{
    381     struct SubtreeForeachData tmp;
    382     tmp.array = indices;
    383     tmp.path = path;
    384     gtk_tree_model_foreach (gtk_tree_view_get_model (view), getSubtreeForeach, &tmp);
     381  struct SubtreeForeachData tmp;
     382  tmp.array = indices;
     383  tmp.path = path;
     384  gtk_tree_model_foreach (gtk_tree_view_get_model (view), getSubtreeForeach, &tmp);
    385385}
    386386
     
    392392getActiveFilesForPath (GtkTreeView * view, GtkTreePath * path)
    393393{
    394     GArray * indices;
    395     GtkTreeSelection * sel = gtk_tree_view_get_selection (view);
    396 
    397     if (gtk_tree_selection_path_is_selected (sel, path))
    398     {
    399         /* clicked in a selected row... use the current selection */
    400         indices = getSelectedFilesAndDescendants (view);
    401     }
    402     else
    403     {
    404         /* clicked OUTSIDE of the selected row... just use the clicked row */
    405         indices = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
    406         getSubtree (view, path, indices);
    407     }
    408 
    409     return indices;
     394  GArray * indices;
     395  GtkTreeSelection * sel = gtk_tree_view_get_selection (view);
     396
     397  if (gtk_tree_selection_path_is_selected (sel, path))
     398    {
     399      /* clicked in a selected row... use the current selection */
     400      indices = getSelectedFilesAndDescendants (view);
     401    }
     402  else
     403    {
     404      /* clicked OUTSIDE of the selected row... just use the clicked row */
     405      indices = g_array_new (FALSE, FALSE, sizeof (tr_file_index_t));
     406      getSubtree (view, path, indices);
     407    }
     408
     409  return indices;
    410410}
    411411
     
    417417gtr_file_list_clear (GtkWidget * w)
    418418{
    419     gtr_file_list_set_torrent (w, -1);
     419  gtr_file_list_set_torrent (w, -1);
    420420}
    421421
    422422struct build_data
    423423{
    424     GtkWidget    * w;
    425     tr_torrent   * tor;
    426     GtkTreeIter  * iter;
    427     GtkTreeStore * store;
     424  GtkWidget    * w;
     425  tr_torrent   * tor;
     426  GtkTreeIter  * iter;
     427  GtkTreeStore * store;
    428428};
    429429
    430430struct row_struct
    431431{
    432     uint64_t    length;
    433     char      * name;
    434     int         index;
     432  uint64_t    length;
     433  char      * name;
     434  int         index;
    435435};
    436436
     
    438438buildTree (GNode * node, gpointer gdata)
    439439{
    440     char size_str[64];
    441     GtkTreeIter child_iter;
    442     struct build_data * build = gdata;
    443     struct row_struct *child_data = node->data;
    444     const gboolean isLeaf = node->children == NULL;
    445 
    446     const char * mime_type = isLeaf ? gtr_get_mime_type_from_filename (child_data->name) : DIRECTORY_MIME_TYPE;
    447     GdkPixbuf * icon = gtr_get_mime_type_icon (mime_type, GTK_ICON_SIZE_MENU, build->w);
    448     const tr_info * inf = tr_torrentInfo (build->tor);
    449     const int priority = isLeaf ? inf->files[ child_data->index ].priority : 0;
    450     const gboolean enabled = isLeaf ? !inf->files[ child_data->index ].dnd : TRUE;
    451     char * name_esc = g_markup_escape_text (child_data->name, -1);
    452 
    453     tr_strlsize (size_str, child_data->length, sizeof size_str);
    454 
    455     gtk_tree_store_insert_with_values (build->store, &child_iter, build->iter, INT_MAX,
    456                                        FC_INDEX, child_data->index,
    457                                        FC_LABEL, child_data->name,
    458                                        FC_LABEL_ESC, name_esc,
    459                                        FC_SIZE, child_data->length,
    460                                        FC_SIZE_STR, size_str,
    461                                        FC_ICON, icon,
    462                                        FC_PRIORITY, priority,
    463                                        FC_ENABLED, enabled,
    464                                        -1);
    465 
    466     if (!isLeaf)
    467     {
    468         struct build_data b = *build;
    469         b.iter = &child_iter;
    470         g_node_children_foreach (node, G_TRAVERSE_ALL, buildTree, &b);
    471     }
    472 
    473     g_free (name_esc);
    474     g_object_unref (icon);
    475 
    476     /* we're done with this node */
    477     g_free (child_data->name);
    478     g_free (child_data);
     440  char size_str[64];
     441  GtkTreeIter child_iter;
     442  struct build_data * build = gdata;
     443  struct row_struct *child_data = node->data;
     444  const gboolean isLeaf = node->children == NULL;
     445
     446  const char * mime_type = isLeaf ? gtr_get_mime_type_from_filename (child_data->name) : DIRECTORY_MIME_TYPE;
     447  GdkPixbuf * icon = gtr_get_mime_type_icon (mime_type, GTK_ICON_SIZE_MENU, build->w);
     448  const tr_info * inf = tr_torrentInfo (build->tor);
     449  const int priority = isLeaf ? inf->files[ child_data->index ].priority : 0;
     450  const gboolean enabled = isLeaf ? !inf->files[ child_data->index ].dnd : TRUE;
     451  char * name_esc = g_markup_escape_text (child_data->name, -1);
     452
     453  tr_strlsize (size_str, child_data->length, sizeof size_str);
     454
     455  gtk_tree_store_insert_with_values (build->store, &child_iter, build->iter, INT_MAX,
     456                                     FC_INDEX, child_data->index,
     457                                     FC_LABEL, child_data->name,
     458                                     FC_LABEL_ESC, name_esc,
     459                                     FC_SIZE, child_data->length,
     460                                     FC_SIZE_STR, size_str,
     461                                     FC_ICON, icon,
     462                                     FC_PRIORITY, priority,
     463                                     FC_ENABLED, enabled,
     464                                     -1);
     465
     466  if (!isLeaf)
     467    {
     468      struct build_data b = *build;
     469      b.iter = &child_iter;
     470      g_node_children_foreach (node, G_TRAVERSE_ALL, buildTree, &b);
     471    }
     472
     473  g_free (name_esc);
     474  g_object_unref (icon);
     475
     476  /* we're done with this node */
     477  g_free (child_data->name);
     478  g_free (child_data);
    479479}
    480480
     
    482482find_child (GNode* parent, const char * name)
    483483{
    484     GNode * child = parent->children;
    485     while (child) {
    486         const struct row_struct * child_data = child->data;
    487         if ((*child_data->name == *name) && !g_strcmp0 (child_data->name, name))
    488             break;
    489         child = child->next;
    490     }
    491     return child;
     484  GNode * child = parent->children;
     485
     486  while (child)
     487    {
     488      const struct row_struct * child_data = child->data;
     489      if ((*child_data->name == *name) && !g_strcmp0 (child_data->name, name))
     490        break;
     491      child = child->next;
     492    }
     493
     494  return child;
    492495}
    493496
     
    495498gtr_file_list_set_torrent (GtkWidget * w, int torrentId)
    496499{
    497     GtkTreeStore * store;
    498     FileData * data = g_object_get_data (G_OBJECT (w), "file-data");
    499 
    500     /* unset the old fields */
    501     clearData (data);
    502 
    503     /* instantiate the model */
    504     store = gtk_tree_store_new (N_FILE_COLS,
    505                                  GDK_TYPE_PIXBUF,  /* icon */
    506                                  G_TYPE_STRING,    /* label */
    507                                  G_TYPE_STRING,    /* label esc */
    508                                  G_TYPE_INT,       /* prog [0..100] */
    509                                  G_TYPE_UINT,      /* index */
    510                                  G_TYPE_UINT64,    /* size */
    511                                  G_TYPE_STRING,    /* size str */
    512                                  G_TYPE_UINT64,    /* have */
    513                                  G_TYPE_INT,       /* priority */
    514                                  G_TYPE_INT);     /* dl enabled */
    515 
    516     data->store = store;
    517     data->model = GTK_TREE_MODEL (store);
    518     data->torrentId = torrentId;
    519 
    520     /* populate the model */
    521     if (torrentId > 0)
    522     {
    523         tr_torrent * tor = gtr_core_find_torrent (data->core, torrentId);
    524         if (tor != NULL)
     500  GtkTreeStore * store;
     501  FileData * data = g_object_get_data (G_OBJECT (w), "file-data");
     502
     503  /* unset the old fields */
     504  clearData (data);
     505
     506  /* instantiate the model */
     507  store = gtk_tree_store_new (N_FILE_COLS,
     508                              GDK_TYPE_PIXBUF,  /* icon */
     509                              G_TYPE_STRING,    /* label */
     510                              G_TYPE_STRING,    /* label esc */
     511                              G_TYPE_INT,       /* prog [0..100] */
     512                              G_TYPE_UINT,      /* index */
     513                              G_TYPE_UINT64,    /* size */
     514                              G_TYPE_STRING,    /* size str */
     515                              G_TYPE_UINT64,    /* have */
     516                              G_TYPE_INT,       /* priority */
     517                              G_TYPE_INT);     /* dl enabled */
     518
     519  data->store = store;
     520  data->model = GTK_TREE_MODEL (store);
     521  data->torrentId = torrentId;
     522
     523  /* populate the model */
     524  if (torrentId > 0)
     525    {
     526      tr_torrent * tor = gtr_core_find_torrent (data->core, torrentId);
     527      if (tor != NULL)
    525528        {
    526             tr_file_index_t i;
    527             const tr_info * inf = tr_torrentInfo (tor);
    528             struct row_struct * root_data;
    529             GNode * root;
    530             struct build_data build;
    531 
    532             /* build a GNode tree of the files */
    533             root_data = g_new0 (struct row_struct, 1);
    534             root_data->name = g_strdup (tr_torrentName (tor));
    535             root_data->index = -1;
    536             root_data->length = 0;
    537             root = g_node_new (root_data);
    538             for (i=0; i<inf->fileCount; ++i) {
    539                 int j;
    540                 GNode * parent = root;
    541                 const tr_file * file = &inf->files[i];
    542                 char ** tokens = g_strsplit (file->name, G_DIR_SEPARATOR_S, 0);
    543                 for (j=0; tokens[j]; ++j) {
    544                     const gboolean isLeaf = tokens[j+1] == NULL;
    545                     const char * name = tokens[j];
    546                     GNode * node = find_child (parent, name);
    547                     if (node == NULL) {
    548                         struct row_struct * row = g_new (struct row_struct, 1);
    549                         row->name = g_strdup (name);
    550                         row->index = isLeaf ? (int)i : -1;
    551                         row->length = isLeaf ? file->length : 0;
    552                         node = g_node_new (row);
    553                         g_node_append (parent, node);
     529          tr_file_index_t i;
     530          const tr_info * inf = tr_torrentInfo (tor);
     531          struct row_struct * root_data;
     532          GNode * root;
     533          struct build_data build;
     534
     535          /* build a GNode tree of the files */
     536          root_data = g_new0 (struct row_struct, 1);
     537          root_data->name = g_strdup (tr_torrentName (tor));
     538          root_data->index = -1;
     539          root_data->length = 0;
     540          root = g_node_new (root_data);
     541          for (i=0; i<inf->fileCount; ++i)
     542            {
     543              int j;
     544              GNode * parent = root;
     545              const tr_file * file = &inf->files[i];
     546              char ** tokens = g_strsplit (file->name, G_DIR_SEPARATOR_S, 0);
     547              for (j=0; tokens[j]; ++j)
     548                {
     549                  const gboolean isLeaf = tokens[j+1] == NULL;
     550                  const char * name = tokens[j];
     551                  GNode * node = find_child (parent, name);
     552                  if (node == NULL)
     553                    {
     554                      struct row_struct * row = g_new (struct row_struct, 1);
     555                      row->name = g_strdup (name);
     556                      row->index = isLeaf ? (int)i : -1;
     557                      row->length = isLeaf ? file->length : 0;
     558                      node = g_node_new (row);
     559                      g_node_append (parent, node);
    554560                    }
    555                     parent = node;
     561                  parent = node;
    556562                }
    557                 g_strfreev (tokens);
     563              g_strfreev (tokens);
    558564            }
    559565
    560             /* now, add them to the model */
    561             build.w = w;
    562             build.tor = tor;
    563             build.store = data->store;
    564             build.iter = NULL;
    565             g_node_children_foreach (root, G_TRAVERSE_ALL, buildTree, &build);
    566 
    567             /* cleanup */
    568             g_node_destroy (root);
    569             g_free (root_data->name);
    570             g_free (root_data);
     566          /* now, add them to the model */
     567          build.w = w;
     568          build.tor = tor;
     569          build.store = data->store;
     570          build.iter = NULL;
     571          g_node_children_foreach (root, G_TRAVERSE_ALL, buildTree, &build);
     572
     573          /* cleanup */
     574          g_node_destroy (root);
     575          g_free (root_data->name);
     576          g_free (root_data);
    571577        }
    572578
    573         refresh (data);
    574         data->timeout_tag = gdk_threads_add_timeout_seconds (SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, refreshModel, data);
    575     }
    576 
    577     gtk_tree_view_set_model (GTK_TREE_VIEW (data->view), data->model);
    578     gtk_tree_view_expand_all (GTK_TREE_VIEW (data->view));
    579     g_object_unref (data->model);
     579      refresh (data);
     580      data->timeout_tag = gdk_threads_add_timeout_seconds (SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, refreshModel, data);
     581    }
     582
     583  gtk_tree_view_set_model (GTK_TREE_VIEW (data->view), data->model);
     584  gtk_tree_view_expand_all (GTK_TREE_VIEW (data->view));
     585  g_object_unref (data->model);
    580586}
    581587
     
    591597                gpointer             data   UNUSED)
    592598{
    593     gboolean enabled;
    594     gtk_tree_model_get (model, iter, FC_ENABLED, &enabled, -1);
    595     g_object_set (renderer, "inconsistent", (enabled==MIXED),
    596                             "active", (enabled==TRUE),
    597                             NULL);
     599  gboolean enabled;
     600  gtk_tree_model_get (model, iter, FC_ENABLED, &enabled, -1);
     601  g_object_set (renderer, "inconsistent", (enabled==MIXED),
     602                          "active", (enabled==TRUE),
     603                          NULL);
    598604}
    599605
     
    605611                gpointer             data   UNUSED)
    606612{
    607     int priority;
    608     const char * text;
    609     gtk_tree_model_get (model, iter, FC_PRIORITY, &priority, -1);
    610     switch (priority) {
    611         case TR_PRI_HIGH:   text = _("High"); break;
    612         case TR_PRI_NORMAL: text = _("Normal"); break;
    613         case TR_PRI_LOW:    text = _("Low"); break;
    614         default:            text = _("Mixed"); break;
    615     }
    616     g_object_set (renderer, "text", text, NULL);
     613  int priority;
     614  const char * text;
     615  gtk_tree_model_get (model, iter, FC_PRIORITY, &priority, -1);
     616  switch (priority)
     617    {
     618      case TR_PRI_HIGH:   text = _("High"); break;
     619      case TR_PRI_NORMAL: text = _("Normal"); break;
     620      case TR_PRI_LOW:    text = _("Low"); break;
     621      default:            text = _("Mixed"); break;
     622    }
     623  g_object_set (renderer, "text", text, NULL);
    617624}
    618625
     
    622629               GtkTreePath * path, GtkTreeIter * iter)
    623630{
    624     char * ret;
    625     GtkTreeIter child;
    626     GtkTreeIter parent = *iter;
    627     int n = gtk_tree_path_get_depth (path);
    628     char ** tokens = g_new0 (char*, n + 2);
    629     tokens[0] = g_strdup (tr_torrentGetCurrentDir (tor));
    630     do {
    631         child = parent;
    632         gtk_tree_model_get (model, &child, FC_LABEL, &tokens[n--], -1);
    633     } while (gtk_tree_model_iter_parent (model, &parent, &child));
    634     ret = g_build_filenamev (tokens);
    635     g_strfreev (tokens);
    636     return ret;
     631  char * ret;
     632  GtkTreeIter child;
     633  GtkTreeIter parent = *iter;
     634  int n = gtk_tree_path_get_depth (path);
     635  char ** tokens = g_new0 (char*, n + 2);
     636  tokens[0] = g_strdup (tr_torrentGetCurrentDir (tor));
     637  do {
     638    child = parent;
     639    gtk_tree_model_get (model, &child, FC_LABEL, &tokens[n--], -1);
     640  } while (gtk_tree_model_iter_parent (model, &parent, &child));
     641  ret = g_build_filenamev (tokens);
     642  g_strfreev (tokens);
     643  return ret;
    637644}
    638645
     
    641648                GtkTreeViewColumn * col UNUSED, gpointer gdata)
    642649{
    643     gboolean handled = FALSE;
    644     FileData * data = gdata;
    645     tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
    646 
    647     if (tor != NULL)
    648     {
    649         GtkTreeIter iter;
    650         GtkTreeModel * model = gtk_tree_view_get_model (view);
    651 
    652         if (gtk_tree_model_get_iter (model, &iter, path))
     650  gboolean handled = FALSE;
     651  FileData * data = gdata;
     652  tr_torrent * tor = gtr_core_find_torrent (data->core, data->torrentId);
     653
     654  if (tor != NULL)
     655    {
     656      GtkTreeIter iter;
     657      GtkTreeModel * model = gtk_tree_view_get_model (view);
     658
     659      if (gtk_tree_model_get_iter (model, &iter, path))
    653660        {
    654             int prog;
    655             char * filename = buildFilename (tor, model, path, &iter);
    656             gtk_tree_model_get (model, &iter, FC_PROG, &prog, -1);
    657 
    658             /* if the file's not done, walk up the directory tree until we find
    659              * an ancestor that exists, and open that instead */
    660             if (filename && (prog<100 || !g_file_test (filename, G_FILE_TEST_EXISTS))) do
     661          int prog;
     662          char * filename = buildFilename (tor, model, path, &iter);
     663          gtk_tree_model_get (model, &iter, FC_PROG, &prog, -1);
     664
     665          /* if the file's not done, walk up the directory tree until we find
     666           * an ancestor that exists, and open that instead */
     667          if (filename && (prog<100 || !g_file_test (filename, G_FILE_TEST_EXISTS))) do
    661668            {
    662                 char * tmp = g_path_get_dirname (filename);
    663                 g_free (filename);
    664                 filename = tmp;
     669              char * tmp = g_path_get_dirname (filename);
     670              g_free (filename);
     671              filename = tmp;
    665672            }
    666             while (filename && *filename && !g_file_test (filename, G_FILE_TEST_EXISTS));
    667 
    668             if ((handled = filename && *filename))
    669                 gtr_open_file (filename);
     673          while (filename && *filename && !g_file_test (filename, G_FILE_TEST_EXISTS));
     674
     675          if ((handled = filename && *filename))
     676            gtr_open_file (filename);
    670677        }
    671678    }
    672679
    673     return handled;
     680  return handled;
    674681}
    675682
     
    680687                   FileData          * data)
    681688{
    682     int cid;
    683     tr_torrent * tor;
    684     gboolean handled = FALSE;
    685 
    686     if (!col || !path)
    687         return FALSE;
    688 
    689     cid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (col), TR_COLUMN_ID_KEY));
    690     tor = gtr_core_find_torrent (data->core, data->torrentId);
    691     if ((tor != NULL) && ((cid == FC_PRIORITY) || (cid == FC_ENABLED)))
    692     {
    693         GtkTreeIter iter;
    694         GArray * indices = getActiveFilesForPath (view, path);
    695         GtkTreeModel * model = data->model;
    696 
    697         gtk_tree_model_get_iter (model, &iter, path);
    698 
    699         if (cid == FC_PRIORITY)
     689  int cid;
     690  tr_torrent * tor;
     691  gboolean handled = FALSE;
     692
     693  if (!col || !path)
     694    return FALSE;
     695
     696  cid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (col), TR_COLUMN_ID_KEY));
     697  tor = gtr_core_find_torrent (data->core, data->torrentId);
     698  if ((tor != NULL) && ((cid == FC_PRIORITY) || (cid == FC_ENABLED)))
     699    {
     700      GtkTreeIter iter;
     701      GArray * indices = getActiveFilesForPath (view, path);
     702      GtkTreeModel * model = data->model;
     703
     704      gtk_tree_model_get_iter (model, &iter, path);
     705
     706      if (cid == FC_PRIORITY)
    700707        {
    701             int priority;
    702             gtk_tree_model_get (model, &iter, FC_PRIORITY, &priority, -1);
    703             switch (priority) {
    704                 case TR_PRI_NORMAL: priority = TR_PRI_HIGH; break;
    705                 case TR_PRI_HIGH:   priority = TR_PRI_LOW; break;
    706                 default:            priority = TR_PRI_NORMAL; break;
     708          int priority;
     709          gtk_tree_model_get (model, &iter, FC_PRIORITY, &priority, -1);
     710          switch (priority)
     711            {
     712              case TR_PRI_NORMAL: priority = TR_PRI_HIGH; break;
     713              case TR_PRI_HIGH:   priority = TR_PRI_LOW; break;
     714              default:            priority = TR_PRI_NORMAL; break;
    707715            }
    708             tr_torrentSetFilePriorities (tor,
     716          tr_torrentSetFilePriorities (tor,
    709717                                       (tr_file_index_t *) indices->data,
    710718                                       (tr_file_index_t) indices->len,
    711719                                         priority);
    712720        }
    713         else
     721      else
    714722        {
    715             int enabled;
    716             gtk_tree_model_get (model, &iter, FC_ENABLED, &enabled, -1);
    717             enabled = !enabled;
    718 
    719             tr_torrentSetFileDLs (tor,
     723          int enabled;
     724          gtk_tree_model_get (model, &iter, FC_ENABLED, &enabled, -1);
     725          enabled = !enabled;
     726
     727          tr_torrentSetFileDLs (tor,
    720728                                (tr_file_index_t *) indices->data,
    721729                                (tr_file_index_t) indices->len,
    722                                   enabled);
     730                                enabled);
    723731        }
    724732
    725         refresh (data);
    726         g_array_free (indices, TRUE);
    727         handled = TRUE;
    728     }
    729 
    730     return handled;
     733      refresh (data);
     734      g_array_free (indices, TRUE);
     735      handled = TRUE;
     736    }
     737
     738  return handled;
    731739}
    732740
     
    740748                       GtkTreePath       ** path)
    741749{
    742     GtkTreeSelection * sel;
    743 
    744     if (gtk_tree_view_get_path_at_pos (treeview,
    745                                        event->x, event->y,
    746                                        path, col, NULL, NULL))
    747     {
    748         sel = gtk_tree_view_get_selection (treeview);
    749         if (!gtk_tree_selection_path_is_selected (sel, *path))
     750  GtkTreeSelection * sel;
     751
     752  if (gtk_tree_view_get_path_at_pos (treeview,
     753                                     event->x, event->y,
     754                                     path, col, NULL, NULL))
     755    {
     756      sel = gtk_tree_view_get_selection (treeview);
     757      if (!gtk_tree_selection_path_is_selected (sel, *path))
    750758        {
    751             gtk_tree_selection_unselect_all (sel);
    752             gtk_tree_selection_select_path (sel, *path);
     759          gtk_tree_selection_unselect_all (sel);
     760          gtk_tree_selection_select_path (sel, *path);
    753761        }
    754         return TRUE;
    755     }
    756 
    757     return FALSE;
     762      return TRUE;
     763    }
     764
     765  return FALSE;
    758766}
    759767
     
    761769onViewButtonPressed (GtkWidget * w, GdkEventButton * event, gpointer gdata)
    762770{
    763     GtkTreeViewColumn * col;
    764     GtkTreePath * path = NULL;
    765     gboolean handled = FALSE;
    766     GtkTreeView * treeview = GTK_TREE_VIEW (w);
    767     FileData * data = gdata;
    768 
    769     if ((event->type == GDK_BUTTON_PRESS)
    770          && (event->button == 1)
    771          && ! (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
    772          && getAndSelectEventPath (treeview, event, &col, &path))
    773     {
    774         handled = onViewPathToggled (treeview, col, path, data);
    775 
    776         if (path != NULL)
    777             gtk_tree_path_free (path);
    778     }
    779 
    780     return handled;
     771  GtkTreeViewColumn * col;
     772  GtkTreePath * path = NULL;
     773  gboolean handled = FALSE;
     774  GtkTreeView * treeview = GTK_TREE_VIEW (w);
     775  FileData * data = gdata;
     776
     777  if ((event->type == GDK_BUTTON_PRESS)
     778       && (event->button == 1)
     779       && ! (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
     780       && getAndSelectEventPath (treeview, event, &col, &path))
     781    {
     782      handled = onViewPathToggled (treeview, col, path, data);
     783
     784      if (path != NULL)
     785        gtk_tree_path_free (path);
     786    }
     787
     788  return handled;
    781789}
    782790
     
    883891gtr_file_list_new (TrCore * core, int torrentId)
    884892{
    885     int size;
    886     int width;
    887     GtkWidget * ret;
    888     GtkWidget * view;
    889     GtkWidget * scroll;
    890     GtkCellRenderer * rend;
    891     GtkTreeSelection * sel;
    892     GtkTreeViewColumn * col;
    893     GtkTreeView * tree_view;
    894     const char * title;
    895     PangoLayout * pango_layout;
    896     PangoContext * pango_context;
    897     PangoFontDescription * pango_font_description;
    898     FileData * data = g_new0 (FileData, 1);
    899 
    900     data->core = core;
    901 
    902     /* create the view */
    903     view = gtk_tree_view_new ();
    904     tree_view = GTK_TREE_VIEW (view);
    905     gtk_tree_view_set_rules_hint (tree_view, TRUE);
    906     gtk_container_set_border_width (GTK_CONTAINER (view), GUI_PAD_BIG);
    907     g_signal_connect (view, "button-press-event",
    908                       G_CALLBACK (onViewButtonPressed), data);
    909     g_signal_connect (view, "row_activated",
    910                       G_CALLBACK (onRowActivated), data);
    911     g_signal_connect (view, "button-release-event",
    912                       G_CALLBACK (on_tree_view_button_released), NULL);
    913 
    914 
    915     pango_context = gtk_widget_create_pango_context (view);
    916     pango_font_description = pango_font_description_copy (pango_context_get_font_description (pango_context));
    917     size = pango_font_description_get_size (pango_font_description);
    918     pango_font_description_set_size (pango_font_description, size * 0.8);
    919     g_object_unref (G_OBJECT (pango_context));
    920 
    921     /* set up view */
    922     sel = gtk_tree_view_get_selection (tree_view);
    923     gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
    924     gtk_tree_view_expand_all (tree_view);
    925     gtk_tree_view_set_search_column (tree_view, FC_LABEL);
    926 
    927     /* add file column */
    928     col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
    929                                                 "expand", TRUE,
    930                                                 "title", _("Name"),
    931                                                 NULL));
    932     gtk_tree_view_column_set_resizable (col, TRUE);
    933     rend = gtk_cell_renderer_pixbuf_new ();
    934     gtk_tree_view_column_pack_start (col, rend, FALSE);
    935     gtk_tree_view_column_add_attribute (col, rend, "pixbuf", FC_ICON);
    936     /* add text renderer */
    937     rend = gtk_cell_renderer_text_new ();
    938     g_object_set (rend, "editable", TRUE, NULL);
    939     g_object_set (rend, "ellipsize", PANGO_ELLIPSIZE_END, "font-desc", pango_font_description, NULL);
    940     g_signal_connect (rend, "edited", (GCallback)cell_edited_callback, data);
    941     gtk_tree_view_column_pack_start (col, rend, TRUE);
    942     gtk_tree_view_column_set_attributes (col, rend, "text", FC_LABEL, NULL);
    943     gtk_tree_view_column_set_sort_column_id (col, FC_LABEL);
    944     gtk_tree_view_append_column (tree_view, col);
    945 
    946     /* add "size" column */
    947     title = _("Size");
    948     rend = gtk_cell_renderer_text_new ();
    949     g_object_set (rend, "alignment", PANGO_ALIGN_RIGHT,
    950                         "font-desc", pango_font_description,
    951                         "xpad", GUI_PAD,
    952                         "xalign", 1.0f,
    953                         "yalign", 0.5f,
    954                         NULL);
    955     col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
    956     gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
    957     gtk_tree_view_column_set_sort_column_id (col, FC_SIZE);
    958     gtk_tree_view_column_set_attributes (col, rend, "text", FC_SIZE_STR, NULL);
    959     gtk_tree_view_append_column (tree_view, col);
    960 
    961     /* add "progress" column */
    962     title = _("Have");
    963     pango_layout = gtk_widget_create_pango_layout (view, title);
    964     pango_layout_get_pixel_size (pango_layout, &width, NULL);
    965     width += 30; /* room for the sort indicator */
    966     g_object_unref (G_OBJECT (pango_layout));
    967     rend = gtk_cell_renderer_progress_new ();
    968     col = gtk_tree_view_column_new_with_attributes (title, rend, "value", FC_PROG, NULL);
    969     gtk_tree_view_column_set_fixed_width (col, width);
    970     gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
    971     gtk_tree_view_column_set_sort_column_id (col, FC_PROG);
    972     gtk_tree_view_append_column (tree_view, col);
    973 
    974     /* add "enabled" column */
    975     title = _("Download");
    976     pango_layout = gtk_widget_create_pango_layout (view, title);
    977     pango_layout_get_pixel_size (pango_layout, &width, NULL);
    978     width += 30; /* room for the sort indicator */
    979     g_object_unref (G_OBJECT (pango_layout));
    980     rend = gtk_cell_renderer_toggle_new ();
    981     col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
    982     g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
    983                        GINT_TO_POINTER (FC_ENABLED));
    984     gtk_tree_view_column_set_fixed_width (col, width);
    985     gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
    986     gtk_tree_view_column_set_cell_data_func (col, rend, renderDownload, NULL, NULL);
    987     gtk_tree_view_column_set_sort_column_id (col, FC_ENABLED);
    988     gtk_tree_view_append_column (tree_view, col);
    989 
    990     /* add priority column */
    991     title = _("Priority");
    992     pango_layout = gtk_widget_create_pango_layout (view, title);
    993     pango_layout_get_pixel_size (pango_layout, &width, NULL);
    994     width += 30; /* room for the sort indicator */
    995     g_object_unref (G_OBJECT (pango_layout));
    996     rend = gtk_cell_renderer_text_new ();
    997     g_object_set (rend, "xalign", (gfloat)0.5, "yalign", (gfloat)0.5, NULL);
    998     col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
    999     g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
    1000                        GINT_TO_POINTER (FC_PRIORITY));
    1001     gtk_tree_view_column_set_fixed_width (col, width);
    1002     gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
    1003     gtk_tree_view_column_set_sort_column_id (col, FC_PRIORITY);
    1004     gtk_tree_view_column_set_cell_data_func (col, rend, renderPriority, NULL, NULL);
    1005     gtk_tree_view_append_column (tree_view, col);
    1006 
    1007     /* add tooltip to tree */
    1008     gtk_tree_view_set_tooltip_column (tree_view, FC_LABEL_ESC);
    1009 
    1010     /* create the scrolled window and stick the view in it */
    1011     scroll = gtk_scrolled_window_new (NULL, NULL);
    1012     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
    1013                                     GTK_POLICY_AUTOMATIC,
    1014                                     GTK_POLICY_AUTOMATIC);
    1015     gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
    1016                                           GTK_SHADOW_IN);
    1017     gtk_container_add (GTK_CONTAINER (scroll), view);
    1018     gtk_widget_set_size_request (scroll, -1, 200);
    1019 
    1020     ret = scroll;
    1021     data->view = view;
    1022     data->top = scroll;
    1023     g_object_set_data_full (G_OBJECT (ret), "file-data", data, freeData);
    1024     gtr_file_list_set_torrent (ret, torrentId);
    1025 
    1026     pango_font_description_free (pango_font_description);
    1027     return ret;
    1028 }
     893  int size;
     894  int width;
     895  GtkWidget * ret;
     896  GtkWidget * view;
     897  GtkWidget * scroll;
     898  GtkCellRenderer * rend;
     899  GtkTreeSelection * sel;
     900  GtkTreeViewColumn * col;
     901  GtkTreeView * tree_view;
     902  const char * title;
     903  PangoLayout * pango_layout;
     904  PangoContext * pango_context;
     905  PangoFontDescription * pango_font_description;
     906  FileData * data = g_new0 (FileData, 1);
     907
     908  data->core = core;
     909
     910  /* create the view */
     911  view = gtk_tree_view_new ();
     912  tree_view = GTK_TREE_VIEW (view);
     913  gtk_tree_view_set_rules_hint (tree_view, TRUE);
     914  gtk_container_set_border_width (GTK_CONTAINER (view), GUI_PAD_BIG);
     915  g_signal_connect (view, "button-press-event",
     916                    G_CALLBACK (onViewButtonPressed), data);
     917  g_signal_connect (view, "row_activated",
     918                    G_CALLBACK (onRowActivated), data);
     919  g_signal_connect (view, "button-release-event",
     920                    G_CALLBACK (on_tree_view_button_released), NULL);
     921
     922
     923  pango_context = gtk_widget_create_pango_context (view);
     924  pango_font_description = pango_font_description_copy (pango_context_get_font_description (pango_context));
     925  size = pango_font_description_get_size (pango_font_description);
     926  pango_font_description_set_size (pango_font_description, size * 0.8);
     927  g_object_unref (G_OBJECT (pango_context));
     928
     929  /* set up view */
     930  sel = gtk_tree_view_get_selection (tree_view);
     931  gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
     932  gtk_tree_view_expand_all (tree_view);
     933  gtk_tree_view_set_search_column (tree_view, FC_LABEL);
     934
     935  /* add file column */
     936  col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
     937                                            "expand", TRUE,
     938                                            "title", _("Name"),
     939                                            NULL));
     940  gtk_tree_view_column_set_resizable (col, TRUE);
     941  rend = gtk_cell_renderer_pixbuf_new ();
     942  gtk_tree_view_column_pack_start (col, rend, FALSE);
     943  gtk_tree_view_column_add_attribute (col, rend, "pixbuf", FC_ICON);
     944  /* add text renderer */
     945  rend = gtk_cell_renderer_text_new ();
     946  g_object_set (rend, "editable", TRUE, NULL);
     947  g_object_set (rend, "ellipsize", PANGO_ELLIPSIZE_END, "font-desc", pango_font_description, NULL);
     948  g_signal_connect (rend, "edited", (GCallback)cell_edited_callback, data);
     949  gtk_tree_view_column_pack_start (col, rend, TRUE);
     950  gtk_tree_view_column_set_attributes (col, rend, "text", FC_LABEL, NULL);
     951  gtk_tree_view_column_set_sort_column_id (col, FC_LABEL);
     952  gtk_tree_view_append_column (tree_view, col);
     953
     954  /* add "size" column */
     955  title = _("Size");
     956  rend = gtk_cell_renderer_text_new ();
     957  g_object_set (rend, "alignment", PANGO_ALIGN_RIGHT,
     958                      "font-desc", pango_font_description,
     959                      "xpad", GUI_PAD,
     960                      "xalign", 1.0f,
     961                      "yalign", 0.5f,
     962                      NULL);
     963  col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
     964  gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
     965  gtk_tree_view_column_set_sort_column_id (col, FC_SIZE);
     966  gtk_tree_view_column_set_attributes (col, rend, "text", FC_SIZE_STR, NULL);
     967  gtk_tree_view_append_column (tree_view, col);
     968
     969  /* add "progress" column */
     970  title = _("Have");
     971  pango_layout = gtk_widget_create_pango_layout (view, title);
     972  pango_layout_get_pixel_size (pango_layout, &width, NULL);
     973  width += 30; /* room for the sort indicator */
     974  g_object_unref (G_OBJECT (pango_layout));
     975  rend = gtk_cell_renderer_progress_new ();
     976  col = gtk_tree_view_column_new_with_attributes (title, rend, "value", FC_PROG, NULL);
     977  gtk_tree_view_column_set_fixed_width (col, width);
     978  gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
     979  gtk_tree_view_column_set_sort_column_id (col, FC_PROG);
     980  gtk_tree_view_append_column (tree_view, col);
     981
     982  /* add "enabled" column */
     983  title = _("Download");
     984  pango_layout = gtk_widget_create_pango_layout (view, title);
     985  pango_layout_get_pixel_size (pango_layout, &width, NULL);
     986  width += 30; /* room for the sort indicator */
     987  g_object_unref (G_OBJECT (pango_layout));
     988  rend = gtk_cell_renderer_toggle_new ();
     989  col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
     990  g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
     991                     GINT_TO_POINTER (FC_ENABLED));
     992  gtk_tree_view_column_set_fixed_width (col, width);
     993  gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
     994  gtk_tree_view_column_set_cell_data_func (col, rend, renderDownload, NULL, NULL);
     995  gtk_tree_view_column_set_sort_column_id (col, FC_ENABLED);
     996  gtk_tree_view_append_column (tree_view, col);
     997
     998  /* add priority column */
     999  title = _("Priority");
     1000  pango_layout = gtk_widget_create_pango_layout (view, title);
     1001  pango_layout_get_pixel_size (pango_layout, &width, NULL);
     1002  width += 30; /* room for the sort indicator */
     1003  g_object_unref (G_OBJECT (pango_layout));
     1004  rend = gtk_cell_renderer_text_new ();
     1005  g_object_set (rend, "xalign", (gfloat)0.5, "yalign", (gfloat)0.5, NULL);
     1006  col = gtk_tree_view_column_new_with_attributes (title, rend, NULL);
     1007  g_object_set_data (G_OBJECT (col), TR_COLUMN_ID_KEY,
     1008                     GINT_TO_POINTER (FC_PRIORITY));
     1009  gtk_tree_view_column_set_fixed_width (col, width);
     1010  gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
     1011  gtk_tree_view_column_set_sort_column_id (col, FC_PRIORITY);
     1012  gtk_tree_view_column_set_cell_data_func (col, rend, renderPriority, NULL, NULL);
     1013  gtk_tree_view_append_column (tree_view, col);
     1014
     1015  /* add tooltip to tree */
     1016  gtk_tree_view_set_tooltip_column (tree_view, FC_LABEL_ESC);
     1017
     1018  /* create the scrolled window and stick the view in it */
     1019  scroll = gtk_scrolled_window_new (NULL, NULL);
     1020  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
     1021                                  GTK_POLICY_AUTOMATIC,
     1022                                  GTK_POLICY_AUTOMATIC);
     1023  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
     1024                                        GTK_SHADOW_IN);
     1025  gtk_container_add (GTK_CONTAINER (scroll), view);
     1026  gtk_widget_set_size_request (scroll, -1, 200);
     1027
     1028  ret = scroll;
     1029  data->view = view;
     1030  data->top = scroll;
     1031  g_object_set_data_full (G_OBJECT (ret), "file-data", data, freeData);
     1032  gtr_file_list_set_torrent (ret, torrentId);
     1033
     1034  pango_font_description_free (pango_font_description);
     1035  return ret;
     1036}
  • trunk/gtk/open-dialog.c

    r14077 r14132  
    3535get_recent_destinations (void)
    3636{
    37     int i;
    38     GSList * list = NULL;
    39 
    40     for (i=0; i<N_RECENT; ++i)
    41     {
    42         char key[64];
    43         const char * val;
    44         g_snprintf (key, sizeof (key), "recent-download-dir-%d", i+1);
    45         if ((val = gtr_pref_string_get (tr_quark_new(key,-1))))
    46             list = g_slist_append (list, (void*)val);
    47     }
    48     return list;
     37  int i;
     38  GSList * list = NULL;
     39
     40  for (i=0; i<N_RECENT; ++i)
     41    {
     42      char key[64];
     43      const char * val;
     44      g_snprintf (key, sizeof (key), "recent-download-dir-%d", i+1);
     45      if ((val = gtr_pref_string_get (tr_quark_new(key,-1))))
     46        list = g_slist_append (list, (void*)val);
     47    }
     48
     49  return list;
    4950}
    5051
     
    5253save_recent_destination (TrCore * core, const char * dir)
    5354{
    54     int i;
    55     GSList * l;
    56     GSList * list = get_recent_destinations ();
    57 
    58     if (dir == NULL)
    59         return;
    60 
    61     /* if it was already in the list, remove it */
    62     if ((l = g_slist_find_custom (list, dir, (GCompareFunc)g_strcmp0)))
    63         list = g_slist_delete_link (list, l);
    64 
    65     /* add it to the front of the list */
    66     list = g_slist_prepend (list, (void*)dir);
    67 
    68     /* make local copies of the strings that aren't
    69      * invalidated by gtr_pref_string_set () */
    70     for (l=list; l; l=l->next)
    71         l->data = g_strdup (l->data);
    72 
    73     /* save the first N_RECENT directories */
    74     for (l=list, i=0; l && (i<N_RECENT); ++i, l=l->next) {
    75         char key[64];
    76         g_snprintf (key, sizeof (key), "recent-download-dir-%d", i + 1);
    77         gtr_pref_string_set (tr_quark_new(key,-1), l->data);
    78     }
    79     gtr_pref_save (gtr_core_session (core));
    80 
    81     /* cleanup */
    82     g_slist_foreach (list, (GFunc)g_free, NULL);
    83     g_slist_free (list);
     55  int i;
     56  GSList * l;
     57  GSList * list = get_recent_destinations ();
     58
     59  if (dir == NULL)
     60    return;
     61
     62  /* if it was already in the list, remove it */
     63  if ((l = g_slist_find_custom (list, dir, (GCompareFunc)g_strcmp0)))
     64    list = g_slist_delete_link (list, l);
     65
     66  /* add it to the front of the list */
     67  list = g_slist_prepend (list, (void*)dir);
     68
     69  /* make local copies of the strings that aren't
     70   * invalidated by gtr_pref_string_set () */
     71  for (l=list; l; l=l->next)
     72    l->data = g_strdup (l->data);
     73
     74  /* save the first N_RECENT directories */
     75  for (l=list, i=0; l && (i<N_RECENT); ++i, l=l->next)
     76    {
     77      char key[64];
     78      g_snprintf (key, sizeof (key), "recent-download-dir-%d", i + 1);
     79      gtr_pref_string_set (tr_quark_new(key,-1), l->data);
     80    }
     81  gtr_pref_save (gtr_core_session (core));
     82
     83  /* cleanup */
     84  g_slist_foreach (list, (GFunc)g_free, NULL);
     85  g_slist_free (list);
    8486}
    8587
     
    9092struct OpenData
    9193{
    92     TrCore *     core;
    93     GtkWidget *  file_list;
    94     GtkWidget *  run_check;
    95     GtkWidget *  trash_check;
    96     GtkWidget *  priority_combo;
    97     GtkWidget *  freespace_label;
    98     char *       filename;
    99     char *       downloadDir;
    100     tr_torrent * tor;
    101     tr_ctor *    ctor;
     94  TrCore *     core;
     95  GtkWidget *  file_list;
     96  GtkWidget *  run_check;
     97  GtkWidget *  trash_check;
     98  GtkWidget *  priority_combo;
     99  GtkWidget *  freespace_label;
     100  char *       filename;
     101  char *       downloadDir;
     102  tr_torrent * tor;
     103  tr_ctor *    ctor;
    102104};
    103105
     
    105107removeOldTorrent (struct OpenData * o)
    106108{
    107     if (o->tor)
    108     {
    109         gtr_file_list_clear (o->file_list);
    110         tr_torrentRemove (o->tor, FALSE, NULL);
    111         o->tor = NULL;
     109  if (o->tor)
     110    {
     111      gtr_file_list_clear (o->file_list);
     112      tr_torrentRemove (o->tor, FALSE, NULL);
     113      o->tor = NULL;
    112114    }
    113115}
     
    118120               gpointer    gdata)
    119121{
    120     struct OpenData * o = gdata;
    121 
    122     if (o->tor)
    123     {
    124         if (response != GTK_RESPONSE_ACCEPT)
     122  struct OpenData * o = gdata;
     123
     124  if (o->tor)
     125    {
     126      if (response != GTK_RESPONSE_ACCEPT)
    125127        {
    126             removeOldTorrent (o);
     128          removeOldTorrent (o);
    127129        }
    128         else
     130      else
    129131        {
    130             tr_torrentSetPriority (o->tor, gtr_priority_combo_get_value (GTK_COMBO_BOX (o->priority_combo)));
    131 
    132             if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->run_check)))
    133                 tr_torrentStart (o->tor);
    134 
    135             gtr_core_add_torrent (o->core, o->tor, FALSE);
    136 
    137             if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->trash_check)))
    138                 gtr_file_trash_or_remove (o->filename);
    139 
    140             save_recent_destination (o->core, o->downloadDir);
     132          tr_torrentSetPriority (o->tor, gtr_priority_combo_get_value (GTK_COMBO_BOX (o->priority_combo)));
     133
     134          if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->run_check)))
     135            tr_torrentStart (o->tor);
     136
     137          gtr_core_add_torrent (o->core, o->tor, FALSE);
     138
     139          if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (o->trash_check)))
     140            gtr_file_trash_or_remove (o->filename);
     141
     142          save_recent_destination (o->core, o->downloadDir);
    141143        }
    142144    }
    143145
    144     tr_ctorFree (o->ctor);
    145     g_free (o->filename);
    146     g_free (o->downloadDir);
    147     g_free (o);
    148     gtk_widget_destroy (GTK_WIDGET (dialog));
     146  tr_ctorFree (o->ctor);
     147  g_free (o->filename);
     148  g_free (o->downloadDir);
     149  g_free (o);
     150  gtk_widget_destroy (GTK_WIDGET (dialog));
    149151}
    150152
     
    152154updateTorrent (struct OpenData * o)
    153155{
    154     const gboolean isLocalFile = tr_ctorGetSourceFile (o->ctor) != NULL;
    155     gtk_widget_set_sensitive (o->trash_check, isLocalFile);
    156 
    157     if (!o->tor)
    158     {
    159         gtr_file_list_clear (o->file_list);
    160         gtk_widget_set_sensitive (o->file_list, FALSE);
    161     }
    162     else
    163     {
    164         tr_torrentSetDownloadDir (o->tor, o->downloadDir);
    165         gtk_widget_set_sensitive (o->file_list, tr_torrentHasMetadata (o->tor));
    166         gtr_file_list_set_torrent (o->file_list, tr_torrentId (o->tor));
    167         tr_torrentVerify (o->tor, NULL, NULL);
     156  const gboolean isLocalFile = tr_ctorGetSourceFile (o->ctor) != NULL;
     157  gtk_widget_set_sensitive (o->trash_check, isLocalFile);
     158
     159  if (!o->tor)
     160    {
     161      gtr_file_list_clear (o->file_list);
     162      gtk_widget_set_sensitive (o->file_list, FALSE);
     163    }
     164  else
     165    {
     166      tr_torrentSetDownloadDir (o->tor, o->downloadDir);
     167      gtk_widget_set_sensitive (o->file_list, tr_torrentHasMetadata (o->tor));
     168      gtr_file_list_set_torrent (o->file_list, tr_torrentId (o->tor));
     169      tr_torrentVerify (o->tor, NULL, NULL);
    168170    }
    169171}
     
    179181sourceChanged (GtkFileChooserButton * b, gpointer gdata)
    180182{
    181     struct OpenData * o = gdata;
    182     char * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
    183 
    184     /* maybe instantiate a torrent */
    185     if (filename || !o->tor)
    186     {
    187         int err = 0;
    188         int new_file = 0;
    189         int duplicate_id = 0;
    190         tr_torrent * torrent;
    191 
    192         if (filename && (!o->filename || !tr_is_same_file (filename, o->filename)))
     183  struct OpenData * o = gdata;
     184  char * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
     185
     186  /* maybe instantiate a torrent */
     187  if (filename || !o->tor)
     188    {
     189      int err = 0;
     190      int new_file = 0;
     191      int duplicate_id = 0;
     192      tr_torrent * torrent;
     193
     194      if (filename && (!o->filename || !tr_is_same_file (filename, o->filename)))
    193195        {
    194             g_free (o->filename);
    195             o->filename = g_strdup (filename);
    196             tr_ctorSetMetainfoFromFile (o->ctor, o->filename);
    197             new_file = 1;
     196          g_free (o->filename);
     197          o->filename = g_strdup (filename);
     198          tr_ctorSetMetainfoFromFile (o->ctor, o->filename);
     199          new_file = 1;
    198200        }
    199201
    200         tr_ctorSetDownloadDir (o->ctor, TR_FORCE, o->downloadDir);
    201         tr_ctorSetPaused (o->ctor, TR_FORCE, TRUE);
    202         tr_ctorSetDeleteSource (o->ctor, FALSE);
    203 
    204         if ((torrent = tr_torrentNew (o->ctor, &err, &duplicate_id)))
     202      tr_ctorSetDownloadDir (o->ctor, TR_FORCE, o->downloadDir);
     203      tr_ctorSetPaused (o->ctor, TR_FORCE, TRUE);
     204      tr_ctorSetDeleteSource (o->ctor, FALSE);
     205
     206      if ((torrent = tr_torrentNew (o->ctor, &err, &duplicate_id)))
    205207        {
    206             removeOldTorrent (o);
    207             o->tor = torrent;
     208          removeOldTorrent (o);
     209          o->tor = torrent;
    208210        }
    209         else if (new_file)
     211      else if (new_file)
    210212        {
    211             tr_torrent * tor;
    212 
    213             if (duplicate_id)
    214               tor = gtr_core_find_torrent (o->core, duplicate_id);
    215             else
    216               tor = NULL;
    217 
    218             gtr_add_torrent_error_dialog (GTK_WIDGET (b), err, tor, o->filename);
     213          tr_torrent * tor;
     214
     215          if (duplicate_id)
     216            tor = gtr_core_find_torrent (o->core, duplicate_id);
     217          else
     218            tor = NULL;
     219
     220          gtr_add_torrent_error_dialog (GTK_WIDGET (b), err, tor, o->filename);
    219221        }
    220222
    221         updateTorrent (o);
    222     }
    223 
    224     g_free (filename);
     223      updateTorrent (o);
     224    }
     225
     226  g_free (filename);
    225227}
    226228
     
    228230downloadDirChanged (GtkFileChooserButton * b, gpointer gdata)
    229231{
    230     struct OpenData * data = gdata;
    231     char * fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
    232 
    233     if (fname && (!data->downloadDir || !tr_is_same_file (fname, data->downloadDir)))
    234     {
    235         g_free (data->downloadDir);
    236         data->downloadDir = g_strdup (fname);
    237         updateTorrent (data);
    238 
    239         gtr_freespace_label_set_dir (data->freespace_label, data->downloadDir);
    240     }
    241 
    242     g_free (fname);
     232  struct OpenData * data = gdata;
     233  char * fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (b));
     234
     235  if (fname && (!data->downloadDir || !tr_is_same_file (fname, data->downloadDir)))
     236    {
     237      g_free (data->downloadDir);
     238      data->downloadDir = g_strdup (fname);
     239      updateTorrent (data);
     240
     241      gtr_freespace_label_set_dir (data->freespace_label, data->downloadDir);
     242    }
     243
     244  g_free (fname);
    243245}
    244246
     
    246248addTorrentFilters (GtkFileChooser * chooser)
    247249{
    248     GtkFileFilter * filter;
    249 
    250     filter = gtk_file_filter_new ();
    251     gtk_file_filter_set_name (filter, _("Torrent files"));
    252     gtk_file_filter_add_pattern (filter, "*.torrent");
    253     gtk_file_chooser_add_filter (chooser, filter);
    254 
    255     filter = gtk_file_filter_new ();
    256     gtk_file_filter_set_name (filter, _("All files"));
    257     gtk_file_filter_add_pattern (filter, "*");
    258     gtk_file_chooser_add_filter (chooser, filter);
     250  GtkFileFilter * filter;
     251
     252  filter = gtk_file_filter_new ();
     253  gtk_file_filter_set_name (filter, _("Torrent files"));
     254  gtk_file_filter_add_pattern (filter, "*.torrent");
     255  gtk_file_chooser_add_filter (chooser, filter);
     256
     257  filter = gtk_file_filter_new ();
     258  gtk_file_filter_set_name (filter, _("All files"));
     259  gtk_file_filter_add_pattern (filter, "*");
     260  gtk_file_chooser_add_filter (chooser, filter);
    259261}
    260262
     
    266268gtr_torrent_options_dialog_new (GtkWindow * parent, TrCore * core, tr_ctor * ctor)
    267269{
    268     const char *     str;
    269     GtkWidget *      w;
    270     GtkWidget *      d;
    271     GtkGrid        * grid;
    272     int              row;
    273     GtkWidget *      l;
    274     GtkWidget *      source_chooser;
    275     struct OpenData * data;
    276     bool             flag;
    277     GSList *         list;
    278     GSList *         walk;
    279 
    280     /* make the dialog */
    281     d = gtk_dialog_new_with_buttons (_("Torrent Options"), parent,
    282                                      GTK_DIALOG_DESTROY_WITH_PARENT,
    283                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    284                                      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    285                                      NULL);
    286     gtk_dialog_set_default_response (GTK_DIALOG (d),
    287                                      GTK_RESPONSE_ACCEPT);
    288     gtk_dialog_set_alternative_button_order (GTK_DIALOG (d),
    289                                              GTK_RESPONSE_ACCEPT,
    290                                              GTK_RESPONSE_CANCEL,
    291                                              -1);
    292 
    293     if (tr_ctorGetDownloadDir (ctor, TR_FORCE, &str))
    294         g_assert_not_reached ();
    295     g_assert (str);
    296 
    297     data = g_new0 (struct OpenData, 1);
    298     data->core = core;
    299     data->ctor = ctor;
    300     data->filename = g_strdup (tr_ctorGetSourceFile (ctor));
    301     data->downloadDir = g_strdup (str);
    302     data->file_list = gtr_file_list_new (core, 0);
    303     str = _("Mo_ve .torrent file to the trash");
    304     data->trash_check = gtk_check_button_new_with_mnemonic (str);
    305     str = _("_Start when added");
    306     data->run_check = gtk_check_button_new_with_mnemonic (str);
    307 
    308     w = data->priority_combo = gtr_priority_combo_new ();
    309     gtr_priority_combo_set_value (GTK_COMBO_BOX (w), TR_PRI_NORMAL);
    310 
    311     g_signal_connect (G_OBJECT (d), "response",
    312                       G_CALLBACK (addResponseCB), data);
    313 
    314     row = 0;
    315     grid = GTK_GRID (gtk_grid_new ());
    316     gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_BIG);
    317     gtk_grid_set_row_spacing (grid, GUI_PAD);
    318     gtk_grid_set_column_spacing (grid, GUI_PAD_BIG);
    319 
    320     // "torrent file" row
    321     l = gtk_label_new_with_mnemonic (_("_Torrent file:"));
    322     gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
    323     gtk_grid_attach (grid, l, 0, row, 1, 1);
    324     w = gtk_file_chooser_button_new (_("Select Source File"),
    325                                      GTK_FILE_CHOOSER_ACTION_OPEN);
    326     source_chooser = w;
    327     gtk_widget_set_hexpand (w, TRUE);
    328     gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
    329     gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
    330     addTorrentFilters (GTK_FILE_CHOOSER (w));
    331     g_signal_connect (w, "selection-changed",
    332                       G_CALLBACK (sourceChanged), data);
    333 
    334     // "destination folder" row
    335     row++;
    336     l = gtk_label_new_with_mnemonic (_("_Destination folder:"));
    337     gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
    338     gtk_grid_attach (grid, l, 0, row, 1, 1);
    339     w = gtk_file_chooser_button_new (_("Select Destination Folder"),
    340                                      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
    341     if (!gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w),
    342                                               data->downloadDir))
    343         g_warning ("couldn't select '%s'", data->downloadDir);
    344     list = get_recent_destinations ();
    345     for (walk = list; walk; walk = walk->next)
    346         gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (w), walk->data, NULL);
    347     g_slist_free (list);
    348     gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
    349     gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
    350     g_signal_connect (w, "selection-changed",
    351                       G_CALLBACK (downloadDirChanged), data);
    352 
    353     row++;
    354     l = data->freespace_label = gtr_freespace_label_new (core, data->downloadDir);
    355     gtk_widget_set_margin_bottom (l, GUI_PAD_BIG);
    356     gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f);
    357     gtk_grid_attach (grid, l, 0, row, 2, 1);
    358 
    359 
    360     // file list row
    361     row++;
    362     w = data->file_list;
    363     gtk_widget_set_vexpand (w, TRUE);
    364     gtk_widget_set_size_request (w, 466u, 300u);
    365     gtk_grid_attach (grid, w, 0, row, 2, 1);
    366 
    367     // torrent priority row
    368     row++;
    369     l = gtk_label_new_with_mnemonic (_("Torrent _priority:"));
    370     gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
    371     gtk_grid_attach (grid, l, 0, row, 1, 1);
    372     w = data->priority_combo;
    373     gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
    374     gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
    375 
    376     // torrent priority row
    377     row++;
    378     w = data->run_check;
    379     if (tr_ctorGetPaused (ctor, TR_FORCE, &flag))
    380         g_assert_not_reached ();
    381     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), !flag);
    382     gtk_grid_attach (grid, w, 0, row, 2, 1);
    383 
    384     // "trash .torrent file" row
    385     row++;
    386     w = data->trash_check;
    387     if (tr_ctorGetDeleteSource (ctor, &flag))
    388         g_assert_not_reached ();
    389     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), flag);
    390     gtk_grid_attach (grid, w, 0, row, 2, 1);
    391 
    392     /* trigger sourceChanged, either directly or indirectly,
    393      * so that it creates the tor/gtor objects */
    394     w = source_chooser;
    395     if (data->filename)
    396         gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), data->filename);
    397     else
    398         sourceChanged (GTK_FILE_CHOOSER_BUTTON (w), data);
    399 
    400     gtr_dialog_set_content (GTK_DIALOG (d), GTK_WIDGET (grid));
    401     w = gtk_dialog_get_widget_for_response (GTK_DIALOG (d), GTK_RESPONSE_ACCEPT);
    402     gtk_widget_grab_focus (w);
    403     return d;
     270  const char *     str;
     271  GtkWidget *      w;
     272  GtkWidget *      d;
     273  GtkGrid        * grid;
     274  int              row;
     275  GtkWidget *      l;
     276  GtkWidget *      source_chooser;
     277  struct OpenData * data;
     278  bool             flag;
     279  GSList *         list;
     280  GSList *         walk;
     281
     282  /* make the dialog */
     283  d = gtk_dialog_new_with_buttons (_("Torrent Options"), parent,
     284                                   GTK_DIALOG_DESTROY_WITH_PARENT,
     285                                   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     286                                   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
     287                                   NULL);
     288  gtk_dialog_set_default_response (GTK_DIALOG (d),
     289                                   GTK_RESPONSE_ACCEPT);
     290  gtk_dialog_set_alternative_button_order (GTK_DIALOG (d),
     291                                           GTK_RESPONSE_ACCEPT,
     292                                           GTK_RESPONSE_CANCEL,
     293                                           -1);
     294
     295  if (tr_ctorGetDownloadDir (ctor, TR_FORCE, &str))
     296    g_assert_not_reached ();
     297  g_assert (str);
     298
     299  data = g_new0 (struct OpenData, 1);
     300  data->core = core;
     301  data->ctor = ctor;
     302  data->filename = g_strdup (tr_ctorGetSourceFile (ctor));
     303  data->downloadDir = g_strdup (str);
     304  data->file_list = gtr_file_list_new (core, 0);
     305  str = _("Mo_ve .torrent file to the trash");
     306  data->trash_check = gtk_check_button_new_with_mnemonic (str);
     307  str = _("_Start when added");
     308  data->run_check = gtk_check_button_new_with_mnemonic (str);
     309
     310  w = data->priority_combo = gtr_priority_combo_new ();
     311  gtr_priority_combo_set_value (GTK_COMBO_BOX (w), TR_PRI_NORMAL);
     312
     313  g_signal_connect (G_OBJECT (d), "response",
     314                    G_CALLBACK (addResponseCB), data);
     315
     316  row = 0;
     317  grid = GTK_GRID (gtk_grid_new ());
     318  gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_BIG);
     319  gtk_grid_set_row_spacing (grid, GUI_PAD);
     320  gtk_grid_set_column_spacing (grid, GUI_PAD_BIG);
     321
     322  /* "torrent file" row */
     323  l = gtk_label_new_with_mnemonic (_("_Torrent file:"));
     324  gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
     325  gtk_grid_attach (grid, l, 0, row, 1, 1);
     326  w = gtk_file_chooser_button_new (_("Select Source File"),
     327                                   GTK_FILE_CHOOSER_ACTION_OPEN);
     328  source_chooser = w;
     329  gtk_widget_set_hexpand (w, TRUE);
     330  gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
     331  gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
     332  addTorrentFilters (GTK_FILE_CHOOSER (w));
     333  g_signal_connect (w, "selection-changed",
     334                    G_CALLBACK (sourceChanged), data);
     335
     336  /* "destination folder" row */
     337  row++;
     338  l = gtk_label_new_with_mnemonic (_("_Destination folder:"));
     339  gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
     340  gtk_grid_attach (grid, l, 0, row, 1, 1);
     341  w = gtk_file_chooser_button_new (_("Select Destination Folder"),
     342                                   GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
     343  if (!gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w),
     344                                            data->downloadDir))
     345    g_warning ("couldn't select '%s'", data->downloadDir);
     346  list = get_recent_destinations ();
     347  for (walk = list; walk; walk = walk->next)
     348    gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (w), walk->data, NULL);
     349  g_slist_free (list);
     350  gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
     351  gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
     352  g_signal_connect (w, "selection-changed",
     353                    G_CALLBACK (downloadDirChanged), data);
     354
     355  row++;
     356  l = data->freespace_label = gtr_freespace_label_new (core, data->downloadDir);
     357  gtk_widget_set_margin_bottom (l, GUI_PAD_BIG);
     358  gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f);
     359  gtk_grid_attach (grid, l, 0, row, 2, 1);
     360
     361
     362  /* file list row */
     363  row++;
     364  w = data->file_list;
     365  gtk_widget_set_vexpand (w, TRUE);
     366  gtk_widget_set_size_request (w, 466u, 300u);
     367  gtk_grid_attach (grid, w, 0, row, 2, 1);
     368
     369  /* torrent priority row */
     370  row++;
     371  l = gtk_label_new_with_mnemonic (_("Torrent _priority:"));
     372  gtk_misc_set_alignment (GTK_MISC (l), 0.0f, 0.5f);
     373  gtk_grid_attach (grid, l, 0, row, 1, 1);
     374  w = data->priority_combo;
     375  gtk_label_set_mnemonic_widget (GTK_LABEL (l), w);
     376  gtk_grid_attach_next_to (grid, w, l, GTK_POS_RIGHT, 1, 1);
     377
     378  /* torrent priority row */
     379  row++;
     380  w = data->run_check;
     381  if (tr_ctorGetPaused (ctor, TR_FORCE, &flag))
     382    g_assert_not_reached ();
     383  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), !flag);
     384  gtk_grid_attach (grid, w, 0, row, 2, 1);
     385
     386  /* "trash .torrent file" row */
     387  row++;
     388  w = data->trash_check;
     389  if (tr_ctorGetDeleteSource (ctor, &flag))
     390    g_assert_not_reached ();
     391  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), flag);
     392  gtk_grid_attach (grid, w, 0, row, 2, 1);
     393
     394  /* trigger sourceChanged, either directly or indirectly,
     395   * so that it creates the tor/gtor objects */
     396  w = source_chooser;
     397  if (data->filename)
     398    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), data->filename);
     399  else
     400    sourceChanged (GTK_FILE_CHOOSER_BUTTON (w), data);
     401
     402  gtr_dialog_set_content (GTK_DIALOG (d), GTK_WIDGET (grid));
     403  w = gtk_dialog_get_widget_for_response (GTK_DIALOG (d), GTK_RESPONSE_ACCEPT);
     404  gtk_widget_grab_focus (w);
     405  return d;
    404406}
    405407
     
    411413onOpenDialogResponse (GtkDialog * dialog, int response, gpointer core)
    412414{
    413     char * folder;
    414 
    415     /* remember this folder the next time we use this dialog */
    416     folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
    417     gtr_pref_string_set (TR_KEY_open_dialog_dir, folder);
    418     g_free (folder);
    419 
    420     if (response == GTK_RESPONSE_ACCEPT)
    421     {
    422         GtkFileChooser  * chooser = GTK_FILE_CHOOSER (dialog);
    423         GtkWidget       * w = gtk_file_chooser_get_extra_widget (chooser);
    424         GtkToggleButton * tb = GTK_TOGGLE_BUTTON (w);
    425         const gboolean    do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
    426         const gboolean    do_prompt = gtk_toggle_button_get_active (tb);
    427         const gboolean    do_notify = FALSE;
    428         GSList * files = gtk_file_chooser_get_files (chooser);
    429 
    430         gtr_core_add_files (core, files, do_start, do_prompt, do_notify);
    431         g_slist_foreach (files, (GFunc)g_object_unref, NULL);
    432         g_slist_free (files);
    433     }
    434 
    435     gtk_widget_destroy (GTK_WIDGET (dialog));
     415  char * folder;
     416
     417  /* remember this folder the next time we use this dialog */
     418  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
     419  gtr_pref_string_set (TR_KEY_open_dialog_dir, folder);
     420  g_free (folder);
     421
     422  if (response == GTK_RESPONSE_ACCEPT)
     423    {
     424      GtkFileChooser  * chooser = GTK_FILE_CHOOSER (dialog);
     425      GtkWidget       * w = gtk_file_chooser_get_extra_widget (chooser);
     426      GtkToggleButton * tb = GTK_TOGGLE_BUTTON (w);
     427      const gboolean    do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
     428      const gboolean    do_prompt = gtk_toggle_button_get_active (tb);
     429      const gboolean    do_notify = FALSE;
     430      GSList * files = gtk_file_chooser_get_files (chooser);
     431
     432      gtr_core_add_files (core, files, do_start, do_prompt, do_notify);
     433      g_slist_foreach (files, (GFunc)g_object_unref, NULL);
     434      g_slist_free (files);
     435    }
     436
     437  gtk_widget_destroy (GTK_WIDGET (dialog));
    436438}
    437439
     
    439441gtr_torrent_open_from_file_dialog_new (GtkWindow * parent, TrCore * core)
    440442{
    441     GtkWidget *  w;
    442     GtkWidget *  c;
    443     const char * folder;
    444 
    445     w = gtk_file_chooser_dialog_new (_("Open a Torrent"), parent,
    446                                      GTK_FILE_CHOOSER_ACTION_OPEN,
    447                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    448                                      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    449                                      NULL);
    450     gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
    451                                              GTK_RESPONSE_ACCEPT,
    452                                              GTK_RESPONSE_CANCEL,
    453                                              -1);
    454     gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (w), TRUE);
    455     addTorrentFilters (GTK_FILE_CHOOSER (w));
    456     g_signal_connect (w, "response", G_CALLBACK (onOpenDialogResponse), core);
    457 
    458     if ((folder = gtr_pref_string_get (TR_KEY_open_dialog_dir)))
    459         gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), folder);
    460 
    461     c = gtk_check_button_new_with_mnemonic (_("Show _options dialog"));
    462     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (c),
    463                                  gtr_pref_flag_get (TR_KEY_show_options_window));
    464     gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (w), c);
    465     gtk_widget_show (c);
    466 
    467     return w;
     443  GtkWidget *  w;
     444  GtkWidget *  c;
     445  const char * folder;
     446
     447  w = gtk_file_chooser_dialog_new (_("Open a Torrent"), parent,
     448                                   GTK_FILE_CHOOSER_ACTION_OPEN,
     449                                   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     450                                   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
     451                                   NULL);
     452  gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
     453                                           GTK_RESPONSE_ACCEPT,
     454                                           GTK_RESPONSE_CANCEL,
     455                                           -1);
     456  gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (w), TRUE);
     457  addTorrentFilters (GTK_FILE_CHOOSER (w));
     458  g_signal_connect (w, "response", G_CALLBACK (onOpenDialogResponse), core);
     459
     460  if ((folder = gtr_pref_string_get (TR_KEY_open_dialog_dir)))
     461    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), folder);
     462
     463  c = gtk_check_button_new_with_mnemonic (_("Show _options dialog"));
     464  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (c),
     465                                gtr_pref_flag_get (TR_KEY_show_options_window));
     466  gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (w), c);
     467  gtk_widget_show (c);
     468
     469  return w;
    468470}
    469471
     
    475477onOpenURLResponse (GtkDialog * dialog, int response, gpointer user_data)
    476478{
    477     bool handled = false;
    478 
    479     if (response == GTK_RESPONSE_ACCEPT)
    480     {
    481         GtkWidget * e = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "url-entry"));
    482         char * url = g_strdup (gtk_entry_get_text (GTK_ENTRY (e)));
    483         g_strstrip (url);
    484 
    485         if (url) {
    486             handled = gtr_core_add_from_url (user_data, url);
    487             if (!handled)
    488                 gtr_unrecognized_url_dialog (GTK_WIDGET (dialog), url);
    489             g_free (url);
     479  bool handled = false;
     480
     481  if (response == GTK_RESPONSE_ACCEPT)
     482    {
     483      GtkWidget * e = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "url-entry"));
     484      char * url = g_strdup (gtk_entry_get_text (GTK_ENTRY (e)));
     485      g_strstrip (url);
     486
     487      if (url)
     488        {
     489          handled = gtr_core_add_from_url (user_data, url);
     490          if (!handled)
     491            gtr_unrecognized_url_dialog (GTK_WIDGET (dialog), url);
     492          g_free (url);
    490493        }
    491494    }
    492     else if (response == GTK_RESPONSE_CANCEL)
    493     {
    494         handled = TRUE;
    495     }
    496 
    497     if (handled)
    498         gtk_widget_destroy (GTK_WIDGET (dialog));
     495  else if (response == GTK_RESPONSE_CANCEL)
     496    {
     497      handled = TRUE;
     498    }
     499
     500  if (handled)
     501    gtk_widget_destroy (GTK_WIDGET (dialog));
    499502}
    500503
     
    502505gtr_torrent_open_from_url_dialog_new (GtkWindow * parent, TrCore * core)
    503506{
    504     guint row;
    505     GtkWidget * e;
    506     GtkWidget * t;
    507     GtkWidget * w;
    508 
    509     w = gtk_dialog_new_with_buttons (_("Open URL"), parent,
    510                                      GTK_DIALOG_DESTROY_WITH_PARENT,
    511                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    512                                      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    513                                      NULL);
    514     gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
    515                                              GTK_RESPONSE_ACCEPT,
    516                                              GTK_RESPONSE_CANCEL,
    517                                              -1);
    518     g_signal_connect (w, "response", G_CALLBACK (onOpenURLResponse), core);
    519 
    520     row = 0;
    521     t = hig_workarea_create ();
    522     hig_workarea_add_section_title (t, &row, _("Open torrent from URL"));
    523     e = gtk_entry_new ();
    524     gtk_widget_set_size_request (e, 400, -1);
    525     gtr_paste_clipboard_url_into_entry (e);
    526     g_object_set_data (G_OBJECT (w), "url-entry", e);
    527     hig_workarea_add_row (t, &row, _("_URL"), e, NULL);
    528 
    529     gtr_dialog_set_content (GTK_DIALOG (w), t);
    530 
    531     if (gtk_entry_get_text_length (GTK_ENTRY (e)) == 0)
    532         gtk_widget_grab_focus (e);
    533     else
    534         gtk_widget_grab_focus (gtk_dialog_get_widget_for_response (GTK_DIALOG (w), GTK_RESPONSE_ACCEPT));
    535 
    536     return w;
    537 }
     507  guint row;
     508  GtkWidget * e;
     509  GtkWidget * t;
     510  GtkWidget * w;
     511
     512  w = gtk_dialog_new_with_buttons (_("Open URL"), parent,
     513                                   GTK_DIALOG_DESTROY_WITH_PARENT,
     514                                   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     515                                   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
     516                                   NULL);
     517  gtk_dialog_set_alternative_button_order (GTK_DIALOG (w),
     518                                           GTK_RESPONSE_ACCEPT,
     519                                           GTK_RESPONSE_CANCEL,
     520                                           -1);
     521  g_signal_connect (w, "response", G_CALLBACK (onOpenURLResponse), core);
     522
     523  row = 0;
     524  t = hig_workarea_create ();
     525  hig_workarea_add_section_title (t, &row, _("Open torrent from URL"));
     526  e = gtk_entry_new ();
     527  gtk_widget_set_size_request (e, 400, -1);
     528  gtr_paste_clipboard_url_into_entry (e);
     529  g_object_set_data (G_OBJECT (w), "url-entry", e);
     530  hig_workarea_add_row (t, &row, _("_URL"), e, NULL);
     531
     532  gtr_dialog_set_content (GTK_DIALOG (w), t);
     533
     534  if (gtk_entry_get_text_length (GTK_ENTRY (e)) == 0)
     535    gtk_widget_grab_focus (e);
     536  else
     537    gtk_widget_grab_focus (gtk_dialog_get_widget_for_response (GTK_DIALOG (w), GTK_RESPONSE_ACCEPT));
     538
     539  return w;
     540}
  • trunk/gtk/relocate.c

    r14131 r14132  
    8888      gtk_widget_destroy (GTK_WIDGET (data->message_dialog));
    8989    }
    90     else if (done == TR_LOC_DONE)
     90  else if (done == TR_LOC_DONE)
    9191    {
    9292      if (data->torrent_ids != NULL)
Note: See TracChangeset for help on using the changeset viewer.