| | 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 |
| | 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; |