Show
Ignore:
Timestamp:
03/16/08 09:55:40 (4 years ago)
Author:
rakshasa
Message:

* Changed view_filter to use boolean commands instead of custom
functors.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/rtorrent/src/core/view.cc

    r992 r1042  
    4040#include <functional> 
    4141#include <rak/functional.h> 
     42#include <rpc/parse_commands.h> 
    4243#include <sigc++/adaptors/bind.h> 
    4344#include <torrent/download.h> 
     
    129130 
    130131struct view_downloads_filter : std::unary_function<Download*, bool> { 
    131   view_downloads_filter(const View::filter_list& s) : m_filter(s) {} 
     132  view_downloads_filter(const std::string& cmd) : m_command(cmd) {} 
    132133 
    133134  bool operator () (Download* d1) const { 
    134     for (View::filter_list::const_iterator itr = m_filter.begin(), last = m_filter.end(); itr != last; ++itr) 
    135       if (!(**itr)(d1)) 
    136         return false; 
    137  
    138     // The default filter action is to return true, to not filter the 
    139     // download out. 
    140     return true; 
     135    try { 
     136      torrent::Object result = rpc::parse_command_single(rpc::make_target(d1), m_command); 
     137 
     138      switch (result.type()) { 
     139      case torrent::Object::TYPE_NONE:   return false; 
     140      case torrent::Object::TYPE_VALUE:  return result.as_value(); 
     141      case torrent::Object::TYPE_STRING: return !result.as_string().empty(); 
     142      case torrent::Object::TYPE_LIST:   return !result.as_list().empty(); 
     143      case torrent::Object::TYPE_MAP:    return !result.as_map().empty(); 
     144      } 
     145 
     146      // The default filter action is to return true, to not filter 
     147      // the download out. 
     148      return true; 
     149 
     150    } catch (torrent::input_error& e) { 
     151      return false; 
     152    } 
    141153  } 
    142154 
    143   const View::filter_list& m_filter; 
     155  const std::string&       m_command; 
    144156}; 
    145157 
     
    233245      // Erase even if it is in visible so that the download is 
    234246      // re-sorted. 
     247      // 
     248      // Do we really want to do this? 
    235249      erase(itr); 
    236250      insert_visible(download);