1// Copyright (c) 2012 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 "ui/app_list/app_list_item_model.h"
6
7#include "base/logging.h"
8#include "ui/app_list/app_list_item_model_observer.h"
9
10namespace app_list {
11
12AppListItemModel::AppListItemModel(const std::string& id)
13    : id_(id),
14      highlighted_(false),
15      is_installing_(false),
16      percent_downloaded_(-1) {
17}
18
19AppListItemModel::~AppListItemModel() {
20}
21
22void AppListItemModel::SetIcon(const gfx::ImageSkia& icon, bool has_shadow) {
23  icon_ = icon;
24  has_shadow_ = has_shadow;
25  FOR_EACH_OBSERVER(AppListItemModelObserver, observers_, ItemIconChanged());
26}
27
28void AppListItemModel::SetTitleAndFullName(const std::string& title,
29                                           const std::string& full_name) {
30  if (title_ == title && full_name_ == full_name)
31    return;
32
33  title_ = title;
34  full_name_ = full_name;
35  FOR_EACH_OBSERVER(AppListItemModelObserver, observers_, ItemTitleChanged());
36}
37
38void AppListItemModel::SetHighlighted(bool highlighted) {
39  if (highlighted_ == highlighted)
40    return;
41
42  highlighted_ = highlighted;
43  FOR_EACH_OBSERVER(AppListItemModelObserver,
44                    observers_,
45                    ItemHighlightedChanged());
46}
47
48void AppListItemModel::SetIsInstalling(bool is_installing) {
49  if (is_installing_ == is_installing)
50    return;
51
52  is_installing_ = is_installing;
53  FOR_EACH_OBSERVER(AppListItemModelObserver,
54                    observers_,
55                    ItemIsInstallingChanged());
56}
57
58void AppListItemModel::SetPercentDownloaded(int percent_downloaded) {
59  if (percent_downloaded_ == percent_downloaded)
60    return;
61
62  percent_downloaded_ = percent_downloaded;
63  FOR_EACH_OBSERVER(AppListItemModelObserver,
64                    observers_,
65                    ItemPercentDownloadedChanged());
66}
67
68void AppListItemModel::AddObserver(AppListItemModelObserver* observer) {
69  observers_.AddObserver(observer);
70}
71
72void AppListItemModel::RemoveObserver(AppListItemModelObserver* observer) {
73  observers_.RemoveObserver(observer);
74}
75
76void AppListItemModel::Activate(int event_flags) {
77}
78
79const char* AppListItemModel::GetAppType() const {
80  static const char* app_type = "";
81  return app_type;
82}
83
84ui::MenuModel* AppListItemModel::GetContextMenuModel() {
85  return NULL;
86}
87
88bool AppListItemModel::CompareForTest(const AppListItemModel* other) const {
89  return id_ == other->id_ &&
90      title_ == other->title_ &&
91      position_.Equals(other->position_);
92}
93
94std::string AppListItemModel::ToDebugString() const {
95  return id_.substr(0, 8) + " '" + title_ + "'"
96      + " [" + position_.ToDebugString() + "]";
97}
98
99}  // namespace app_list
100