Changeset 3737

Show
Ignore:
Timestamp:
08/22/08 08:11:15 (5 months ago)
Author:
andar
Message:

Sorting # column will place downloaders above seeds

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r3688 r3737  
    88  * Add peer progress to the peers tab 
    99  * Add 'edit' to edit trackers dialog 
     10  * Sorting # column will place downloaders above seeds 
  • trunk/deluge/ui/gtkui/listview.py

    r3722 r3737  
    120120            # show up in any menu listing;  it cannot be shown ever. 
    121121            self.hidden = False 
     122            # If this is set, it is used to sort the model 
     123            self.sort_func = None 
     124            self.sort_id = None 
    122125                 
    123126    def __init__(self, treeview_widget=None, state_file=None): 
     
    169172            self.columns["filter"].column_indices[0]) 
    170173        self.model_filter = gtk.TreeModelSort(model_filter) 
     174        self.set_sort_functions()                 
    171175        self.treeview.set_model(self.model_filter) 
    172176        if sort_column and sort_column != (None, None): 
    173177            self.model_filter.set_sort_column_id(*sort_column) 
    174      
     178 
     179    def set_sort_functions(self): 
     180        for column in self.columns.values(): 
     181            if column.sort_func: 
     182                log.debug("sort_func: %s sort_id: %s", column.sort_func, column.sort_id) 
     183                self.model_filter.set_sort_func( 
     184                    column.sort_id, 
     185                    column.sort_func, 
     186                    column.sort_id) 
     187             
    175188    def save_state(self, filename): 
    176189        """Saves the listview state (column positions and visibility) to 
     
    355368    def add_column(self, header, render, col_types, hidden, position,  
    356369            status_field, sortid, text=0, value=0, pixbuf=0, function=None, 
    357             column_type=None): 
     370            column_type=None, sort_func=None): 
    358371        """Adds a column to the ListView""" 
    359372        # Add the column types to liststore_columns 
     
    377390            
    378391        self.columns[header].status_field = status_field 
     392        self.columns[header].sort_func = sort_func 
     393        self.columns[header].sort_id = column_indices[sortid] 
    379394         
    380395        # Create a new list with the added column 
     
    458473                                            status_field=None, 
    459474                                            sortid=0, 
    460                                             column_type="text"): 
     475                                            column_type="text", 
     476                                            sort_func=None): 
    461477        """Add a text column to the listview.  Only the header name is required. 
    462478        """ 
    463479        render = gtk.CellRendererText() 
    464480        self.add_column(header, render, col_type, hidden, position, 
    465                     status_field, sortid, column_type=column_type) 
     481                    status_field, sortid, column_type=column_type, sort_func=sort_func) 
    466482        
    467483        return True 
     
    480496    def add_func_column(self, header, function, col_types, sortid=0,  
    481497                                hidden=False, position=None, status_field=None, 
    482                                 column_type="func"): 
     498                                column_type="func", sort_func=None): 
    483499        """Add a function column to the listview.  Need a header name, the 
    484500        function and the column types.""" 
     
    487503        self.add_column(header, render, col_types, hidden, position, 
    488504                            status_field, sortid, column_type=column_type,  
    489                             function=function) 
     505                            function=function, sort_func=sort_func) 
    490506 
    491507        return True 
  • trunk/deluge/ui/gtkui/torrentview.py

    r3733 r3737  
    101101        cell.set_property("text", value + 1) 
    102102 
     103def queue_column_sort(model, iter1, iter2, data): 
     104    v1 = model[iter1][data] 
     105    v2 = model[iter2][data] 
     106    if v1 == v2: 
     107        return 0 
     108    if v2 < 0: 
     109        return -1 
     110    if v1 < 0: 
     111        return 1 
     112    if v1 > v2: 
     113        return 1 
     114    if v2 > v1: 
     115        return -1 
     116         
    103117class TorrentView(listview.ListView, component.Component): 
    104118    """TorrentView handles the listing of torrents.""" 
     
    123137        self.add_text_column("torrent_id", hidden=True) 
    124138        self.add_bool_column("dirty", hidden=True) 
    125         self.add_func_column("#", cell_data_queue, [int], status_field=["queue"]) 
     139        self.add_func_column("#", cell_data_queue, [int], status_field=["queue"], sort_func=queue_column_sort) 
    126140        self.add_texticon_column(_("Name"), status_field=["state", "name"], 
    127141                                            function=cell_data_statusicon) 
     
    180194 
    181195        self.treeview.connect("drag-drop", self.on_drag_drop) 
    182  
     196         
    183197    def start(self): 
    184198        """Start the torrentview""" 
     
    188202 
    189203    def _on_session_state(self, state): 
     204        self.treeview.freeze_child_notify() 
     205        model = self.treeview.get_model() 
    190206        for torrent_id in state: 
    191207            self.add_row(torrent_id, update=False) 
    192208            self.mark_dirty(torrent_id) 
     209        self.treeview.set_model(model) 
     210        self.treeview.thaw_child_notify() 
    193211        self.update() 
    194212 
     
    254272        """ 
    255273        filter_column = self.columns["filter"].column_indices[0] 
    256  
    257274        # Update the torrent view model with data we've received 
    258275        status = self.status 
     276        (sort_id, sort_type) = self.treeview.get_model().get_sort_column_id() 
     277        self.treeview.get_model().set_sort_column_id(-1, gtk.SORT_ASCENDING) 
    259278        for row in self.liststore: 
    260279            torrent_id = row[self.columns["torrent_id"].column_indices[0]] 
     
    272291                        try: 
    273292                            # Only update if different 
    274                             if row[column_index] != \ 
    275                                 status[torrent_id][self.columns[column].status_field[0]]: 
    276                                 row[column_index] = status[torrent_id][ 
    277                                         self.columns[column].status_field[0]] 
     293                            row_value = status[torrent_id][self.columns[column].status_field[0]] 
     294                            if row[column_index] != row_value: 
     295                                row[column_index] = row_value 
    278296                        except (TypeError, KeyError), e: 
    279297                            log.warning("Unable to update column %s: %s", 
     
    285303                            try: 
    286304                                # Only update if different 
    287                                 if row[index] != \ 
    288                                     status[torrent_id][ 
    289                                         self.columns[column].status_field[ 
    290                                             column_index.index(index)]]: 
    291  
    292                                     row[index] = \ 
    293                                         status[torrent_id][ 
    294                                             self.columns[column].status_field[ 
    295                                                 column_index.index(index)]] 
     305                                row_value = status[torrent_id][self.columns[column].status_field[column_index.index(index)]] 
     306                                if row[index] != row_value: 
     307                                    row[index] = row_value 
    296308                            except: 
    297309                                pass 
     310        self.treeview.get_model().set_sort_column_id(sort_id, sort_type) 
    298311        # Update the toolbar buttons just in case some state has changed 
    299312        component.get("ToolBar").update_buttons() 
     
    416429    def on_drag_drop(self, widget, drag_context, x, y, timestamp): 
    417430        widget.stop_emission("drag-drop") 
    418