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
23namespace athena {
24
25AppListViewDelegate::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
34AppListViewDelegate::~AppListViewDelegate() {
35  for (size_t i = 0; i < search_providers_.size(); ++i)
36    search_providers_[i]->set_result_changed_callback(base::Closure());
37}
38
39void 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
49void 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
59bool AppListViewDelegate::ForceNativeDesktop() const {
60  return false;
61}
62
63void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) {
64  // Nothing needs to be done.
65}
66
67app_list::AppListModel* AppListViewDelegate::GetModel() {
68  return model_.get();
69}
70
71app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() {
72  return speech_ui_.get();
73}
74
75void 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
81void AppListViewDelegate::StartSearch() {
82  for (size_t i = 0; i < search_providers_.size(); ++i)
83    search_providers_[i]->Start(model_->search_box()->text());
84}
85
86void AppListViewDelegate::StopSearch() {
87  for (size_t i = 0; i < search_providers_.size(); ++i)
88    search_providers_[i]->Stop();
89}
90
91void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result,
92                                           bool auto_launch,
93                                           int event_flags) {
94  result->Open(event_flags);
95}
96
97void AppListViewDelegate::InvokeSearchResultAction(
98    app_list::SearchResult* result,
99    int action_index,
100    int event_flags) {
101  // TODO(mukai): implement this.
102}
103
104base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() {
105  // Used by voice search, nothing needs to be done for now.
106  return base::TimeDelta();
107}
108
109void AppListViewDelegate::AutoLaunchCanceled() {
110  // Used by voice search, nothing needs to be done for now.
111}
112
113void AppListViewDelegate::ViewInitialized() {
114  // Nothing needs to be done.
115}
116
117void AppListViewDelegate::Dismiss() {
118  // Nothing needs to be done.
119}
120
121void AppListViewDelegate::ViewClosing() {
122  // Nothing needs to be done.
123}
124
125gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
126  return gfx::ImageSkia();
127}
128
129void AppListViewDelegate::OpenSettings() {
130  // Nothing needs to be done for now.
131  // TODO(mukai): should invoke the settings app.
132}
133
134void AppListViewDelegate::OpenHelp() {
135  // Nothing needs to be done for now.
136  // TODO(mukai): should invoke the help app.
137}
138
139void AppListViewDelegate::OpenFeedback() {
140  // Nothing needs to be done for now.
141  // TODO(mukai): should invoke the feedback app.
142}
143
144void AppListViewDelegate::ToggleSpeechRecognition() {
145  // Nothing needs to be done.
146}
147
148void AppListViewDelegate::ShowForProfileByPath(
149    const base::FilePath& profile_path) {
150  // Nothing needs to be done.
151}
152
153views::View* AppListViewDelegate::CreateStartPageWebView(
154    const gfx::Size& size) {
155  return NULL;
156}
157
158bool AppListViewDelegate::IsSpeechRecognitionEnabled() {
159  return false;
160}
161
162const app_list::AppListViewDelegate::Users&
163AppListViewDelegate::GetUsers() const {
164  return users_;
165}
166
167bool AppListViewDelegate::ShouldCenterWindow() const {
168  return true;
169}
170
171}  // namespace athena
172