| 33 | |
| 34 | |
| 35 | QueryEngine::QueryEngine(ExtensionRegistry ®istry) |
| 36 | : registry_(registry) |
| 37 | , usage_scoring_(0,0,{}) // Null scoring, just to not have to implement constructors |
| 38 | { |
| 39 | auto s = App::settings(); |
| 40 | |
| 41 | auto decay = s->value(CFG_MEMORY_DECAY, DEF_MEMORY_DECAY).toDouble(); |
| 42 | auto prioritize_perfect_match = s->value(CFG_PRIO_PERFECT, DEF_PRIO_PERFECT).toBool(); |
| 43 | usage_scoring_ = UsageScoring(prioritize_perfect_match, decay, |
| 44 | make_shared<unordered_map<ItemKey, double>> |
| 45 | (UsageDatabase::instance().itemUsageScores(decay))); |
| 46 | |
| 47 | loadFallbackOrder(); |
| 48 | |
| 49 | connect(®istry, &ExtensionRegistry::added, this, [this](Extension *e) |
| 50 | { |
| 51 | const auto id = e->id(); |
| 52 | auto settings = App::instance().settings(); |
| 53 | settings->beginGroup(id); |
| 54 | |
| 55 | if (auto *h = dynamic_cast<albert::QueryHandler*>(e)) |
| 56 | { |
| 57 | auto t = settings->value(CFG_TRIGGER, h->defaultTrigger()).toString(); |
| 58 | auto f = settings->value(CFG_FUZZY, false).toBool(); |
| 59 | |
| 60 | h->setTrigger(t); |
| 61 | h->setFuzzyMatching(f); |
| 62 | trigger_handlers_.emplace(piecewise_construct, |
| 63 | forward_as_tuple(id), |
| 64 | forward_as_tuple(h, t, f)); |
| 65 | emit queryHandlerAdded(h); |
| 66 | |
| 67 | updateActiveTriggers(); |
| 68 | } |
| 69 | |
| 70 | if (auto *h = dynamic_cast<albert::GlobalQueryHandler*>(e)) |
| 71 | { |
| 72 | global_handlers_.emplace(id, h); |
| 73 | if (settings->value(CFG_GLOBAL_HANDLER_ENABLED, true).toBool()) |
| 74 | global_query_.global_query_handlers.emplace(id, h); |
| 75 | |
| 76 | emit globalQueryHandlerAdded(h); |
| 77 | } |
| 78 | |
| 79 | if (auto *h = dynamic_cast<albert::FallbackHandler*>(e)) |
| 80 | { |
| 81 | fallback_handlers_.emplace(id, h); |
| 82 | emit fallbackHandlerAdded(h); |
| 83 | } |
| 84 | }); |
| 85 | |
| 86 | connect(®istry, &ExtensionRegistry::removed, this, [this](Extension *e) |
| 87 | { |
| 88 | const auto id = e->id(); |
| 89 | |
| 90 | if (const auto it = trigger_handlers_.find(id); it != trigger_handlers_.end()) |
| 91 | { |
| 92 | auto h = it->second.handler; |
nothing calls this directly
no test coverage detected