Home | History | Annotate | Download | only in home
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "athena/home/app_list_view_delegate.h"
      6 
      7 #include <string>
      8 
      9 #include "athena/home/public/app_model_builder.h"
     10 #include "base/basictypes.h"
     11 #include "base/bind.h"
     12 #include "base/callback.h"
     13 #include "base/files/file_path.h"
     14 #include "base/strings/utf_string_conversions.h"
     15 #include "third_party/skia/include/core/SkBitmap.h"
     16 #include "ui/app_list/app_list_model.h"
     17 #include "ui/app_list/search_box_model.h"
     18 #include "ui/app_list/search_provider.h"
     19 #include "ui/app_list/search_result.h"
     20 #include "ui/app_list/speech_ui_model.h"
     21 #include "ui/gfx/image/image_skia.h"
     22 
     23 namespace athena {
     24 
     25 AppListViewDelegate::AppListViewDelegate(AppModelBuilder* model_builder)
     26     : model_(new app_list::AppListModel),
     27       speech_ui_(new app_list::SpeechUIModel(
     28           app_list::SPEECH_RECOGNITION_OFF)) {
     29   model_builder->PopulateApps(model_.get());
     30   // TODO(mukai): get the text from the resources.
     31   model_->search_box()->SetHintText(base::ASCIIToUTF16("Search"));
     32 }
     33 
     34 AppListViewDelegate::~AppListViewDelegate() {
     35   for (size_t i = 0; i < search_providers_.size(); ++i)
     36     search_providers_[i]->set_result_changed_callback(base::Closure());
     37 }
     38 
     39 void AppListViewDelegate::RegisterSearchProvider(
     40     app_list::SearchProvider* search_provider) {
     41   // Right now we allow only one provider.
     42   // TODO(mukai): port app-list's mixer and remove this restriction.
     43   DCHECK(search_providers_.empty());
     44   search_provider->set_result_changed_callback(base::Bind(
     45       &AppListViewDelegate::SearchResultChanged, base::Unretained(this)));
     46   search_providers_.push_back(search_provider);
     47 }
     48 
     49 void AppListViewDelegate::SearchResultChanged() {
     50   // TODO(mukai): port app-list's Mixer to reorder the results properly.
     51   app_list::SearchProvider* search_provider = search_providers_[0];
     52   std::vector<app_list::SearchResult*> results;
     53   search_provider->ReleaseResult(&results);
     54   model_->results()->DeleteAll();
     55   for (size_t i = 0; i < results.size(); ++i)
     56     model_->results()->Add(results[i]);
     57 }
     58 
     59 bool AppListViewDelegate::ForceNativeDesktop() const {
     60   return false;
     61 }
     62 
     63 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) {
     64   // Nothing needs to be done.
     65 }
     66 
     67 app_list::AppListModel* AppListViewDelegate::GetModel() {
     68   return model_.get();
     69 }
     70 
     71 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() {
     72   return speech_ui_.get();
     73 }
     74 
     75 void AppListViewDelegate::GetShortcutPathForApp(
     76     const std::string& app_id,
     77     const base::Callback<void(const base::FilePath&)>& callback) {
     78   // Windows only, nothing is necessary.
     79 }
     80 
     81 void AppListViewDelegate::StartSearch() {
     82   for (size_t i = 0; i < search_providers_.size(); ++i)
     83     search_providers_[i]->Start(model_->search_box()->text());
     84 }
     85 
     86 void AppListViewDelegate::StopSearch() {
     87   for (size_t i = 0; i < search_providers_.size(); ++i)
     88     search_providers_[i]->Stop();
     89 }
     90 
     91 void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result,
     92                                            bool auto_launch,
     93                                            int event_flags) {
     94   result->Open(event_flags);
     95 }
     96 
     97 void AppListViewDelegate::InvokeSearchResultAction(
     98     app_list::SearchResult* result,
     99     int action_index,
    100     int event_flags) {
    101   // TODO(mukai): implement this.
    102 }
    103 
    104 base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() {
    105   // Used by voice search, nothing needs to be done for now.
    106   return base::TimeDelta();
    107 }
    108 
    109 void AppListViewDelegate::AutoLaunchCanceled() {
    110   // Used by voice search, nothing needs to be done for now.
    111 }
    112 
    113 void AppListViewDelegate::ViewInitialized() {
    114   // Nothing needs to be done.
    115 }
    116 
    117 void AppListViewDelegate::Dismiss() {
    118   // Nothing needs to be done.
    119 }
    120 
    121 void AppListViewDelegate::ViewClosing() {
    122   // Nothing needs to be done.
    123 }
    124 
    125 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
    126   return gfx::ImageSkia();
    127 }
    128 
    129 void AppListViewDelegate::OpenSettings() {
    130   // Nothing needs to be done for now.
    131   // TODO(mukai): should invoke the settings app.
    132 }
    133 
    134 void AppListViewDelegate::OpenHelp() {
    135   // Nothing needs to be done for now.
    136   // TODO(mukai): should invoke the help app.
    137 }
    138 
    139 void AppListViewDelegate::OpenFeedback() {
    140   // Nothing needs to be done for now.
    141   // TODO(mukai): should invoke the feedback app.
    142 }
    143 
    144 void AppListViewDelegate::ToggleSpeechRecognition() {
    145   // Nothing needs to be done.
    146 }
    147 
    148 void AppListViewDelegate::ShowForProfileByPath(
    149     const base::FilePath& profile_path) {
    150   // Nothing needs to be done.
    151 }
    152 
    153 views::View* AppListViewDelegate::CreateStartPageWebView(
    154     const gfx::Size& size) {
    155   return NULL;
    156 }
    157 
    158 bool AppListViewDelegate::IsSpeechRecognitionEnabled() {
    159   return false;
    160 }
    161 
    162 const app_list::AppListViewDelegate::Users&
    163 AppListViewDelegate::GetUsers() const {
    164   return users_;
    165 }
    166 
    167 bool AppListViewDelegate::ShouldCenterWindow() const {
    168   return true;
    169 }
    170 
    171 }  // namespace athena
    172