Changeset 1042
- Timestamp:
- 03/16/08 09:55:40 (4 years ago)
- Location:
- trunk/rtorrent/src
- Files:
-
- 9 modified
-
command_ui.cc (modified) (5 diffs)
-
core/view.cc (modified) (3 diffs)
-
core/view.h (modified) (5 diffs)
-
core/view_manager.cc (modified) (4 diffs)
-
core/view_manager.h (modified) (2 diffs)
-
main.cc (modified) (6 diffs)
-
rpc/command.h (modified) (3 diffs)
-
rpc/command_map.h (modified) (3 diffs)
-
rpc/parse_commands.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/rtorrent/src/command_ui.cc
r1039 r1042 54 54 55 55 typedef void (core::ViewManager::*view_filter_slot)(const std::string&, const core::ViewManager::sort_args&); 56 typedef void (core::ViewManager::*view_cfilter_slot)(const std::string&, const std::string&); 56 57 57 58 torrent::Object … … 78 79 79 80 torrent::Object 81 apply_view_cfilter(view_cfilter_slot viewFilterSlot, const torrent::Object& rawArgs) { 82 const torrent::Object::list_type& args = rawArgs.as_list(); 83 84 if (args.size() != 2) 85 throw torrent::input_error("Too few arguments."); 86 87 const std::string& name = args.front().as_string(); 88 89 if (name.empty()) 90 throw torrent::input_error("First argument must be a string."); 91 92 (control->view_manager()->*viewFilterSlot)(name, args.back().as_string()); 93 94 return torrent::Object(); 95 } 96 97 torrent::Object 80 98 apply_view_sort(const torrent::Object& rawArgs) { 81 99 const torrent::Object::list_type& args = rawArgs.as_list(); … … 143 161 rpc::print_object_std(&result, &rawArgs, 0); 144 162 return result; 163 } 164 165 bool 166 as_boolean(const torrent::Object& rawArgs) { 167 switch (rawArgs.type()) { 168 case torrent::Object::TYPE_VALUE: return rawArgs.as_value(); 169 case torrent::Object::TYPE_STRING: return !rawArgs.as_string().empty(); 170 case torrent::Object::TYPE_LIST: return !rawArgs.as_list().empty(); 171 case torrent::Object::TYPE_MAP: return !rawArgs.as_map().empty(); 172 default: return false; 173 } 174 } 175 176 torrent::Object 177 apply_not(rpc::target_type target, const torrent::Object& rawArgs) { 178 return (int64_t)as_boolean(rawArgs); 179 } 180 181 torrent::Object 182 apply_and(rpc::target_type target, const torrent::Object& rawArgs) { 183 if (rawArgs.type() != torrent::Object::TYPE_LIST) 184 return as_boolean(rawArgs); 185 186 for (torrent::Object::list_const_iterator itr = rawArgs.as_list().begin(), last = rawArgs.as_list().end(); itr != last; itr++) 187 if (!as_boolean(rpc::parse_command_single(target, itr->as_string()))) 188 return (int64_t)false; 189 190 return (int64_t)true; 191 } 192 193 torrent::Object 194 apply_or(rpc::target_type target, const torrent::Object& rawArgs) { 195 if (rawArgs.type() != torrent::Object::TYPE_LIST) 196 return as_boolean(rawArgs); 197 198 for (torrent::Object::list_const_iterator itr = rawArgs.as_list().begin(), last = rawArgs.as_list().end(); itr != last; itr++) 199 if (as_boolean(rpc::parse_command_single(target, itr->as_string()))) 200 return (int64_t)true; 201 202 return (int64_t)false; 145 203 } 146 204 … … 288 346 ADD_COMMAND_NONE_L("view_set", rak::ptr_fn(&apply_view_set)); 289 347 290 ADD_COMMAND_LIST("view_filter", rak::bind_ptr_fn(&apply_view_ filter, &core::ViewManager::set_filter));348 ADD_COMMAND_LIST("view_filter", rak::bind_ptr_fn(&apply_view_cfilter, &core::ViewManager::set_filter)); 291 349 ADD_COMMAND_LIST("view_filter_on", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_filter_on)); 292 350 … … 302 360 ADD_ANY_NONE("cat", rak::ptr_fn(&apply_cat)); 303 361 ADD_ANY_NONE("if", rak::bind_ptr_fn(&apply_if, 0)); 362 ADD_ANY_NONE("not", rak::ptr_fn(&apply_not)); 363 ADD_ANY_NONE("and", rak::ptr_fn(&apply_and)); 364 ADD_ANY_NONE("or", rak::ptr_fn(&apply_or)); 304 365 305 366 // A temporary command for handling stuff until we get proper -
trunk/rtorrent/src/core/view.cc
r992 r1042 40 40 #include <functional> 41 41 #include <rak/functional.h> 42 #include <rpc/parse_commands.h> 42 43 #include <sigc++/adaptors/bind.h> 43 44 #include <torrent/download.h> … … 129 130 130 131 struct 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) {} 132 133 133 134 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 } 141 153 } 142 154 143 const View::filter_list& m_filter;155 const std::string& m_command; 144 156 }; 145 157 … … 233 245 // Erase even if it is in visible so that the download is 234 246 // re-sorted. 247 // 248 // Do we really want to do this? 235 249 erase(itr); 236 250 insert_visible(download); -
trunk/rtorrent/src/core/view.h
r1041 r1042 63 63 class DownloadList; 64 64 class ViewSort; 65 class ViewFilter;66 65 67 66 class View : private std::vector<Download*> { … … 70 69 typedef sigc::signal0<void> signal_type; 71 70 typedef std::vector<const ViewSort*> sort_list; 72 typedef std::vector<const ViewFilter*> filter_list;73 71 74 72 using base_type::iterator; … … 118 116 void filter(); 119 117 120 void set_filter(const filter_list& s) { m_filter = s; }118 void set_filter(const std::string& s) { m_filter = s; } 121 119 void set_filter_on(int event); 122 120 123 void set_cfilter(const std::string& s) { m_cfilter = s; }124 121 125 122 void clear_filter_on(); … … 163 160 sort_list m_sortCurrent; 164 161 165 filter_list m_filter; 166 167 std::string m_cfilter; 162 // This should be replaced by a faster non-string command type. 163 std::string m_filter; 168 164 169 165 rak::timer m_lastChanged; … … 178 174 }; 179 175 180 class ViewFilter {181 public:182 virtual ~ViewFilter() {}183 184 virtual bool operator () (Download* d1) const = 0;185 };186 187 176 } 188 177 -
trunk/rtorrent/src/core/view_manager.cc
r966 r1042 112 112 }; 113 113 114 class ViewFilterVariableValue : public ViewFilter {115 public:116 ViewFilterVariableValue(const char* name, torrent::Object::value_type v, bool inverse = false) :117 m_name(name), m_value(v), m_inverse(inverse) {}118 119 virtual bool operator () (Download* d1) const {120 return (rpc::call_command_value(m_name, rpc::make_target(d1)) == m_value) != m_inverse;121 }122 123 private:124 const char* m_name;125 torrent::Object::value_type m_value;126 bool m_inverse;127 };128 129 114 // Really need to implement a factory and allow options in the sort 130 115 // statements. … … 144 129 m_sort["state_changed"] = new ViewSortVariableValue("d.get_state_changed"); 145 130 m_sort["state_changed_reverse"] = new ViewSortVariableValue("d.get_state_changed", true); 146 147 m_filter["started"] = new ViewFilterVariableValue("d.get_state", 1);148 m_filter["stopped"] = new ViewFilterVariableValue("d.get_state", 0);149 m_filter["complete"] = new ViewFilterVariableValue("d.get_complete", 0, true);150 m_filter["incomplete"] = new ViewFilterVariableValue("d.get_complete", 0);151 m_filter["hashing"] = new ViewFilterVariableValue("d.get_hashing", 0, true);152 131 } 153 132 … … 156 135 std::for_each(begin(), end(), rak::call_delete<View>()); 157 136 std::for_each(m_sort.begin(), m_sort.end(), rak::on(rak::mem_ref(&sort_map::value_type::second), rak::call_delete<ViewSort>())); 158 std::for_each(m_filter.begin(), m_filter.end(), rak::on(rak::mem_ref(&filter_map::value_type::second), rak::call_delete<ViewFilter>()));159 137 160 138 base_type::clear(); … … 231 209 } 232 210 233 inline ViewManager::filter_list 234 ViewManager::build_filter_list(const filter_args& args) { 235 View::filter_list filterList; 236 filterList.reserve(args.size()); 237 238 for (filter_args::const_iterator itr = args.begin(), last = args.end(); itr != last; ++itr) { 239 filter_map::const_iterator filterItr = m_filter.find(itr->c_str()); 240 241 if (filterItr == m_filter.end()) 242 throw torrent::input_error("Invalid filtering identifier."); 243 244 filterList.push_back(filterItr->second); 245 } 246 247 return filterList; 248 } 249 250 void 251 ViewManager::set_filter(const std::string& name, const filter_args& args) { 252 iterator viewItr = find_throw(name); 253 254 (*viewItr)->set_filter(build_filter_list(args)); 211 void 212 ViewManager::set_filter(const std::string& name, const std::string& cmd) { 213 iterator viewItr = find_throw(name); 214 215 (*viewItr)->set_filter(cmd); 255 216 (*viewItr)->filter(); 256 217 } -
trunk/rtorrent/src/core/view_manager.h
r938 r1042 61 61 typedef std::list<std::string> sort_args; 62 62 63 typedef std::map<const char*, ViewFilter*, view_manager_comp> filter_map;64 typedef View::filter_list filter_list;65 63 typedef std::list<std::string> filter_args; 66 64 … … 106 104 void set_sort_current(const std::string& name, const sort_args& sort); 107 105 108 void set_filter(const std::string& name, const filter_args& args);106 void set_filter(const std::string& name, const std::string& cmd); 109 107 void set_filter_on(const std::string& name, const filter_args& args); 110 108 111 109 private: 112 110 inline sort_list build_sort_list(const sort_args& args); 113 inline filter_list build_filter_list(const sort_args& args);114 111 115 112 DownloadList* m_list; 116 113 117 114 sort_map m_sort; 118 filter_map m_filter;119 115 }; 120 116 -
trunk/rtorrent/src/main.cc
r1025 r1042 185 185 186 186 "view_add = started\n" 187 "view_filter = started, started\n"187 "view_filter = started,d.get_state=\n" 188 188 "view_filter_on = started,start,stop\n" 189 189 "view_sort_new = started,name\n" … … 191 191 192 192 "view_add = stopped\n" 193 "view_filter = stopped, stopped\n"193 "view_filter = stopped,not=$d.get_state=\n" 194 194 "view_filter_on = stopped,start,stop\n" 195 195 "view_sort_new = stopped,name\n" … … 197 197 198 198 "view_add = complete\n" 199 "view_filter = complete, complete\n"199 "view_filter = complete,d.get_complete=\n" 200 200 "view_filter_on = complete,hash_done,finished\n" 201 201 "view_sort_new = complete,state_changed\n" … … 203 203 204 204 "view_add = incomplete\n" 205 "view_filter = incomplete, incomplete\n"205 "view_filter = incomplete,not=$d.get_complete=\n" 206 206 "view_filter_on = incomplete,hash_done,finished\n" 207 207 "view_sort_new = incomplete,state_changed\n" … … 210 210 // The hashing view does not include stopped torrents. 211 211 "view_add = hashing\n" 212 "view_filter = hashing, hashing\n"212 "view_filter = hashing,d.get_hashing=\n" 213 213 "view_filter_on = hashing,hash_queued,hash_removed,hash_done\n" 214 214 "view_sort_new = hashing,state_changed\n" … … 216 216 217 217 "view_add = seeding\n" 218 "view_filter = seeding, started,complete\n"218 "view_filter = seeding,\"and=d.get_state=,d.get_complete=\"\n" 219 219 "view_filter_on = seeding,start,stop\n" 220 220 "view_sort_new = seeding,state_changed\n" -
trunk/rtorrent/src/rpc/command.h
r1041 r1042 103 103 typedef const torrent::Object (*tracker_slot) (Command*, torrent::Tracker*, const torrent::Object&); 104 104 105 typedef const torrent::Object (*download_pair_slot) (Command*, core::Download*, core::Download*, const torrent::Object&); 106 105 107 static const int target_generic = 0; 106 108 static const int target_any = 1; … … 110 112 static const int target_file = 5; 111 113 static const int target_file_itr = 6; 114 115 static const int target_download_pair = 7; 112 116 113 117 Command() {} … … 119 123 }; 120 124 121 template <typename T >125 template <typename T1 = void, typename T2 = void> 122 126 struct target_type_id { 123 127 // Nothing here, so we cause an error. 124 128 }; 125 129 126 template <> struct target_type_id<Command::generic_slot> { static const int value = Command::target_generic; }; 127 template <> struct target_type_id<Command::any_slot> { static const int value = Command::target_any; }; 128 template <> struct target_type_id<Command::download_slot> { static const int value = Command::target_download; }; 129 template <> struct target_type_id<Command::peer_slot> { static const int value = Command::target_peer; }; 130 template <> struct target_type_id<Command::tracker_slot> { static const int value = Command::target_tracker; }; 131 template <> struct target_type_id<Command::file_slot> { static const int value = Command::target_file; }; 132 template <> struct target_type_id<Command::file_itr_slot> { static const int value = Command::target_file_itr; }; 130 template <> struct target_type_id<Command::generic_slot> { static const int value = Command::target_generic; }; 131 template <> struct target_type_id<Command::any_slot> { static const int value = Command::target_any; }; 132 template <> struct target_type_id<Command::download_slot> { static const int value = Command::target_download; }; 133 template <> struct target_type_id<Command::peer_slot> { static const int value = Command::target_peer; }; 134 template <> struct target_type_id<Command::tracker_slot> { static const int value = Command::target_tracker; }; 135 template <> struct target_type_id<Command::file_slot> { static const int value = Command::target_file; }; 136 template <> struct target_type_id<Command::file_itr_slot> { static const int value = Command::target_file_itr; }; 137 138 template <> struct target_type_id<Command::download_pair_slot> { static const int value = Command::target_download_pair; }; 139 140 template <> struct target_type_id<> { static const int value = Command::target_generic; }; 141 template <> struct target_type_id<target_type> { static const int value = Command::target_any; }; 142 template <> struct target_type_id<core::Download*> { static const int value = Command::target_download; }; 143 template <> struct target_type_id<torrent::Peer*> { static const int value = Command::target_peer; }; 144 template <> struct target_type_id<torrent::Tracker*> { static const int value = Command::target_tracker; }; 145 template <> struct target_type_id<torrent::File*> { static const int value = Command::target_file; }; 146 template <> struct target_type_id<torrent::FileListIterator*> { static const int value = Command::target_file_itr; }; 147 148 template <> struct target_type_id<core::Download*, core::Download*> { static const int value = Command::target_download_pair; }; 133 149 134 150 } -
trunk/rtorrent/src/rpc/command_map.h
r1041 r1042 73 73 Command::peer_slot m_peerSlot; 74 74 Command::tracker_slot m_trackerSlot; 75 76 Command::download_slot m_downloadPairSlot; 75 77 }; 76 78 … … 109 111 iterator insert(key_type key, Command* variable, int flags, const char* parm, const char* doc); 110 112 113 // Make this a wrapper call to insert without extra fluff. 111 114 template <typename T> 112 115 void insert_type(key_type key, Command* variable, T targetSlot, int flags, const char* parm, const char* doc) { … … 133 136 134 137 inline target_type make_target() { return target_type((int)Command::target_generic, NULL); } 135 inline target_type make_target(core::Download* target) { return target_type((int)Command::target_download, target); }136 inline target_type make_target(torrent::Peer* target) { return target_type((int)Command::target_peer, target); }137 inline target_type make_target(torrent::Tracker* target) { return target_type((int)Command::target_tracker, target); }138 inline target_type make_target(torrent::File* target) { return target_type((int)Command::target_file, target); }139 inline target_type make_target(torrent::FileListIterator* target) { return target_type((int)Command::target_file_itr, target); }140 138 inline target_type make_target(int type, void* target) { return target_type(type, target); } 139 inline target_type make_target(int type, void* target1, void* target2) { return target_type(type, target1, target2); } 140 141 template <typename T> 142 inline target_type make_target(T target) { 143 return target_type((int)target_type_id<T>::value, target); 144 } 141 145 142 146 } -
trunk/rtorrent/src/rpc/parse_commands.h
r1026 r1042 72 72 const char* parse_command_name(const char* first, const char* last, std::string* dest); 73 73 74 inline torrent::Object 75 parse_command_single(target_type target, const std::string& cmd) { 76 return parse_command(target, cmd.c_str(), cmd.c_str() + cmd.size()).first; 77 } 78 74 79 inline void 75 80 parse_command_single_std(const std::string& cmd) {
