Assistant: Keep the set of providers in a Vector for easy iteration

This commit is contained in:
Andreas Kling 2021-07-03 20:46:33 +02:00
parent ee991fa4e0
commit e4199beccc
Notes: sideshowbarker 2024-07-18 10:33:01 +09:00
3 changed files with 19 additions and 26 deletions

View file

@ -120,6 +120,11 @@ Gfx::Bitmap const* FileResult::bitmap() const
return GUI::FileIconProvider::icon_for_path(title()).bitmap_for_size(16);
}
FileProvider::FileProvider()
{
build_filesystem_cache();
}
void FileProvider::query(const String& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
{
build_filesystem_cache();

View file

@ -145,6 +145,8 @@ public:
class FileProvider : public Provider {
public:
FileProvider();
void query(String const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete) override;
void build_filesystem_cache();

View file

@ -120,36 +120,26 @@ public:
explicit Database(AppState& state)
: m_state(state)
{
m_file_provider.build_filesystem_cache();
m_providers.append(make<AppProvider>());
m_providers.append(make<CalculatorProvider>());
m_providers.append(make<FileProvider>());
m_providers.append(make<TerminalProvider>());
m_providers.append(make<URLProvider>());
}
Function<void(NonnullRefPtrVector<Result>)> on_new_results;
void search(String const& query)
{
m_file_provider.query(query, [=, this](auto results) {
recv_results(query, results);
});
m_app_provider.query(query, [=, this](auto results) {
recv_results(query, results);
});
m_calculator_provider.query(query, [=, this](auto results) {
recv_results(query, results);
});
m_terminal_provider.query(query, [=, this](auto results) {
recv_results(query, results);
});
m_url_provider.query(query, [=, this](auto results) {
recv_results(query, results);
});
for (auto& provider : m_providers) {
provider.query(query, [=, this](auto results) {
did_receive_results(query, results);
});
}
}
private:
void recv_results(String const& query, NonnullRefPtrVector<Result> const& results)
void did_receive_results(String const& query, NonnullRefPtrVector<Result> const& results)
{
{
Threading::Locker db_locker(m_lock);
@ -188,11 +178,7 @@ private:
AppState& m_state;
AppProvider m_app_provider;
CalculatorProvider m_calculator_provider;
FileProvider m_file_provider;
TerminalProvider m_terminal_provider;
URLProvider m_url_provider;
NonnullOwnPtrVector<Provider> m_providers;
Threading::Lock m_lock;
HashMap<String, NonnullRefPtrVector<Result>> m_result_cache;