Changeset 8635


Ignore:
Timestamp:
Jun 6, 2009, 2:09:43 PM (13 years ago)
Author:
charles
Message:

(trunk gtk) a little more file-list cleanup

Location:
trunk/gtk
Files:
2 edited

Legend:

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

    r8634 r8635  
    5555typedef struct
    5656{
     57    TrCore        * core;
     58    tr_torrent    * tor;
     59    GtkWidget     * top;
     60    GtkWidget     * view;
     61    GtkTreeModel  * model; /* same object as store, but recast */
     62    GtkTreeStore  * store; /* same object as model, but recast */
     63    tr_file_stat  * refresh_file_stat;
    5764    int             torrentId;
    58     TrCore *        core;
    59     tr_torrent    * tor;
    60     GtkWidget *     top;
    61     GtkWidget *     view;
    62     GtkTreeModel *  model; /* same object as store, but recast */
    63     GtkTreeStore *  store; /* same object as model, but recast */
    64     tr_file_stat *  refresh_file_stat;
    6565    guint           timeout_tag;
    6666}
     
    7979
    8080static void
    81 freeData( gpointer gdata )
    82 {
    83     FileData * data = gdata;
    84 
     81freeData( gpointer data )
     82{
    8583    clearData( data );
    8684    g_free( data );
     
    120118                                     FC_PROG, &old_prog,
    121119                                     -1  );
    122 //g_message ( "is_file {%d} index {%d} name {%s}", (int)is_file, (int)index, name );
     120
    123121    if( is_file )
    124122    {
     
    167165                                               FC_SUB_HAVE, &child_have,
    168166                                               FC_SUB_STATE, &child_state,
    169                                                 -1 );
     167                                               -1 );
    170168            size += child_size;
    171169            have += child_have;
     
    226224    {
    227225        tr_file_index_t fileCount;
    228 
    229         /* initialize the temporary variables */
    230226        data->tor = tr_torrentFindFromId( tr_core_session( data->core ), data->torrentId );
    231227        data->refresh_file_stat = tr_torrentFiles( tor, &fileCount );
    232228
    233229        gtr_tree_model_foreach_postorder( data->model, refreshFilesForeach, data );
    234         //gtk_tree_model_foreach( data->model, refreshFilesForeach, data );
    235         //gtk_tree_model_foreach( data->model, addSubForeach, data );
    236 
    237         /* clean up the temporary variables */
     230
    238231        tr_torrentFilesFree( data->refresh_file_stat, fileCount );
    239232        data->refresh_file_stat = NULL;
     
    255248struct ActiveData
    256249{
    257     GtkTreeSelection * sel;
    258     GArray *            array;
     250    GtkTreeSelection  * sel;
     251    GArray            * array;
    259252};
    260253
    261254static gboolean
    262 getSelectedFilesForeach( GtkTreeModel *       model,
    263                          GtkTreePath   * path UNUSED,
    264                          GtkTreeIter *        iter,
    265                          gpointer             gdata )
     255getSelectedFilesForeach( GtkTreeModel * model,
     256                         GtkTreePath  * path UNUSED,
     257                         GtkTreeIter  * iter,
     258                         gpointer       gdata )
    266259{
    267260    struct ActiveData * data = gdata;
     
    271264
    272265    /* active == if it's selected, or any ancestor is selected */
    273     gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file, FC_INDEX, &i, -1 );
     266    gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file,
     267                                     FC_INDEX, &i,
     268                                     -1 );
    274269    if( is_file )
    275270    {
     
    279274            GtkTreeIter walk = *iter;
    280275            GtkTreeIter parent;
    281             while( !is_active
    282                  && gtk_tree_model_iter_parent( model, &parent, &walk ) )
     276            while( !is_active && gtk_tree_model_iter_parent( model, &parent, &walk ) )
    283277            {
    284                 is_active = gtk_tree_selection_iter_is_selected( data->sel,
    285                                                                  &parent );
     278                is_active = gtk_tree_selection_iter_is_selected( data->sel, &parent );
    286279                walk = parent;
    287280            }
     
    296289
    297290static void
    298 getSelectedFilesAndDescendants( GtkTreeView * view,
    299                                 GArray *      indices )
     291getSelectedFilesAndDescendants( GtkTreeView * view, GArray * indices )
    300292{
    301293    struct ActiveData data;
     
    309301struct SubtreeForeachData
    310302{
    311     GArray * array;
    312     GtkTreePath * path;
     303    GArray       * array;
     304    GtkTreePath  * path;
    313305};
    314306
     
    323315    gboolean is_file = FALSE;
    324316
    325     gtk_tree_model_get( model, iter,
    326                         FC_IS_FILE, &is_file,
    327                         FC_INDEX, &i, -1 );
     317    gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file,
     318                                     FC_INDEX, &i,
     319                                    -1 );
    328320    if( is_file )
    329321        if( !gtk_tree_path_compare( path, data->path ) || gtk_tree_path_is_descendant( path, data->path ) )
     
    347339 */
    348340static GArray*
    349 getActiveFilesForPath( GtkTreeView * view,
    350                        GtkTreePath * path )
     341getActiveFilesForPath( GtkTreeView * view, GtkTreePath * path )
    351342{
    352343    GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
     
    379370struct build_data
    380371{
    381     GtkWidget * w;
    382     tr_torrent * tor;
    383     GtkTreeIter * iter;
     372    GtkWidget    * w;
     373    tr_torrent   * tor;
     374    GtkTreeIter  * iter;
    384375    GtkTreeStore * store;
    385376};
     
    387378struct row_struct
    388379{
    389     char * name;
    390     int index;
    391     uint64_t length;
     380    uint64_t    length;
     381    char      * name;
     382    int         index;
    392383};
    393384
     
    540531    }
    541532
    542     gtk_tree_view_set_model( GTK_TREE_VIEW( data->view ), GTK_TREE_MODEL( store ) );
     533    gtk_tree_view_set_model( GTK_TREE_VIEW( data->view ), data->model );
    543534    gtk_tree_view_expand_all( GTK_TREE_VIEW( data->view ) );
    544535}
     
    553544                GtkTreeModel       * model,
    554545                GtkTreeIter        * iter,
    555                 gpointer             data   UNUSED )
     546                gpointer             data UNUSED )
    556547{
    557548    char *   filename;
     
    577568                gpointer             data   UNUSED )
    578569{
    579     int      sub_state;
     570    int sub_state;
    580571    gboolean enabled;
    581572    gboolean active = FALSE;
     
    587578                                     FC_SUB_STATE, &sub_state,
    588579                                     -1 );
     580
    589581    if( is_file && enabled )
    590582        active = TRUE;
    591583    else if( is_file )
    592584        active = FALSE;
    593     else switch( sub_state & SUB_STATE_DOWNLOAD_MASK )
    594         {
    595             case SUB_STATE_DOWNLOAD:
    596                 active = TRUE; break;
    597 
    598             case SUB_STATE_IGNORE:
    599                 active = FALSE; break;
    600 
    601             default:
    602                 inconsistent = TRUE; break;
    603         }
     585    else switch( sub_state & SUB_STATE_DOWNLOAD_MASK ) {
     586        case SUB_STATE_DOWNLOAD: active = TRUE; break;
     587        case SUB_STATE_IGNORE: active = FALSE; break;
     588        default: inconsistent = TRUE; break;
     589    }
    604590
    605591    g_object_set( renderer, "inconsistent", inconsistent,
    606                   "active", active,
    607                   NULL );
     592                            "active", active,
     593                            NULL );
    608594}
    609595
     
    624610                                     FC_SUB_STATE, &sub_state,
    625611                                     -1 );
     612
    626613    if( !is_file ) {
    627614        switch( sub_state & SUB_STATE_PRIORITY_MASK ) {
     
    647634
    648635static gboolean
    649 onViewButtonPressed( GtkWidget      * w,
    650                      GdkEventButton * event,
    651                      gpointer         gdata )
     636onViewButtonPressed( GtkWidget * w, GdkEventButton * event, gpointer gdata )
    652637{
    653638    FileData * data = gdata;
     
    674659            if( downloadColumn || priorityColumn )
    675660            {
    676                 GArray *           a = getActiveFilesForPath( view, path );
     661                GArray * a = getActiveFilesForPath( view, path );
    677662                GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
    678                 const gboolean     isSelected =
    679                     gtk_tree_selection_path_is_selected( sel, path );
    680                 GtkTreeModel *     model = gtk_tree_view_get_model( view );
    681                 GtkTreeIter        iter;
     663                const gboolean isSelected = gtk_tree_selection_path_is_selected( sel, path );
     664                GtkTreeModel * model = data->model;
     665                GtkTreeIter iter;
    682666
    683667                gtk_tree_model_get_iter( model, &iter, path );
     
    696680
    697681                    /* twiddle it to the next state */
    698                     if( !is_file ) switch( sub_state & SUB_STATE_PRIORITY_MASK )
    699                         {
    700                             case SUB_STATE_NORMAL:
    701                                 priority = TR_PRI_HIGH; break;
    702 
    703                             case SUB_STATE_HIGH:
    704                                 priority = TR_PRI_LOW; break;
    705 
    706                             default:
    707                                 priority = TR_PRI_NORMAL; break;
    708                         }
    709                     else switch( priority )
    710                         {
    711                             case TR_PRI_LOW:
    712                                 priority = TR_PRI_NORMAL; break;
    713 
    714                             case TR_PRI_NORMAL:
    715                                 priority = TR_PRI_HIGH; break;
    716 
    717                             case TR_PRI_HIGH:
    718                                 priority = TR_PRI_LOW; break;
    719                         }
     682                    if( !is_file ) switch( sub_state & SUB_STATE_PRIORITY_MASK ) {
     683                        case SUB_STATE_NORMAL: priority = TR_PRI_HIGH; break;
     684                        case SUB_STATE_HIGH: priority = TR_PRI_LOW; break;
     685                        default: priority = TR_PRI_NORMAL; break;
     686                    } else switch( priority ) {
     687                        case TR_PRI_LOW: priority = TR_PRI_NORMAL; break;
     688                        case TR_PRI_NORMAL: priority = TR_PRI_HIGH; break;
     689                        case TR_PRI_HIGH: priority = TR_PRI_LOW; break;
     690                    }
    720691
    721692                    /* apply that new state to the active files */
     
    770741file_list_new( TrCore * core, int torrentId )
    771742{
     743    int width;
     744    GtkWidget * ret;
     745    GtkWidget * view;
     746    GtkWidget * scroll;
     747    GtkCellRenderer * rend;
     748    GtkTreeSelection * sel;
     749    GtkTreeViewColumn * col;
     750    GtkTreeView * tree_view;
    772751    const char * title;
    773     PangoLayout  * pango_layout;
    774     int width;
    775     GtkWidget *         ret;
    776     GtkWidget *         view, * scroll;
    777     GtkCellRenderer *   rend;
    778     GtkTreeViewColumn * col;
    779     GtkTreeSelection *  sel;
    780     FileData *          data = g_new0( FileData, 1 );
     752    PangoLayout * pango_layout;
     753    FileData * data = g_new0( FileData, 1 );
    781754
    782755    data->core = core;
     
    784757    /* create the view */
    785758    view = gtk_tree_view_new( );
    786     gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW( view ), TRUE );
    787     gtk_tree_view_set_rules_hint( GTK_TREE_VIEW( view ), TRUE );
     759    tree_view = GTK_TREE_VIEW( view );
     760    gtk_tree_view_set_fixed_height_mode( tree_view, TRUE );
     761    gtk_tree_view_set_rules_hint( tree_view, TRUE );
    788762    gtk_container_set_border_width( GTK_CONTAINER( view ), GUI_PAD_BIG );
    789763    g_signal_connect( view, "button-press-event",
     
    794768
    795769    /* set up view */
    796     sel = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
     770    sel = gtk_tree_view_get_selection( tree_view );
    797771    gtk_tree_selection_set_mode( sel, GTK_SELECTION_MULTIPLE );
    798     gtk_tree_view_expand_all( GTK_TREE_VIEW( view ) );
    799     gtk_tree_view_set_search_column( GTK_TREE_VIEW( view ), FC_LABEL );
     772    gtk_tree_view_expand_all( tree_view );
     773    gtk_tree_view_set_search_column( tree_view, FC_LABEL );
    800774
    801775    /* add file column */
     
    814788    gtk_tree_view_column_pack_start( col, rend, TRUE );
    815789    gtk_tree_view_column_set_cell_data_func( col, rend, renderFilename, NULL, NULL );
    816     gtk_tree_view_append_column( GTK_TREE_VIEW( view ), col );
     790    gtk_tree_view_append_column( tree_view, col );
    817791
    818792    /* add "progress" column */
     
    827801    gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_FIXED );
    828802    //gtk_tree_view_column_set_cell_data_func( col, rend, renderProgress, NULL, NULL );
    829     gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col );
     803    gtk_tree_view_append_column ( tree_view, col );
    830804
    831805    /* add "enabled" column */
     
    840814    gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_FIXED );
    841815    gtk_tree_view_column_set_cell_data_func( col, rend, renderDownload, NULL, NULL );
    842     gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col );
     816    gtk_tree_view_append_column ( tree_view, col );
    843817
    844818    /* add priority column */
     
    853827    gtk_tree_view_column_set_sizing( col, GTK_TREE_VIEW_COLUMN_FIXED );
    854828    gtk_tree_view_column_set_cell_data_func( col, rend, renderPriority, NULL, NULL );
    855     gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col );
     829    gtk_tree_view_append_column ( tree_view, col );
    856830
    857831    /* create the scrolled window and stick the view in it */
  • trunk/gtk/file-list.h

    r8279 r8635  
    1 /******************************************************************************
     1/*
     2 * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
     3 *
     4 * This file is licensed by the GPL version 2.  Works owned by the
     5 * Transmission project are granted a special exemption to clause 2(b)
     6 * so that the bulk of its code can remain under the MIT license.
     7 * This exemption does not extend to derived works not owned by
     8 * the Transmission project.
     9 *
    210 * $Id$
    3  *
    4  * Copyright (c) 2005-2008 Transmission authors and contributors
    5  *
    6  * Permission is hereby granted, free of charge, to any person obtaining a
    7  * copy of this software and associated documentation files (the "Software"),
    8  * to deal in the Software without restriction, including without limitation
    9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    10  * and/or sell copies of the Software, and to permit persons to whom the
    11  * Software is furnished to do so, subject to the following conditions:
    12  *
    13  * The above copyright notice and this permission notice shall be included in
    14  * all copies or substantial portions of the Software.
    15  *
    16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    22  * DEALINGS IN THE SOFTWARE.
    23  *****************************************************************************/
     11 */
    2412
    2513#ifndef GTK_TORRENT_FILE_LIST_H
Note: See TracChangeset for help on using the changeset viewer.