- add sources.
[platform/framework/web/crosswalk.git] / src / ui / app_list / app_list_menu.cc
1 // Copyright 2013 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_menu.h"
6
7 #include "grit/ui_resources.h"
8 #include "grit/ui_strings.h"
9 #include "ui/app_list/app_list_view_delegate.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/models/menu_separator_types.h"
12 #include "ui/base/resource/resource_bundle.h"
13
14 namespace app_list {
15
16 AppListMenu::AppListMenu(AppListViewDelegate* delegate,
17                          const AppListModel::Users& users)
18     : menu_model_(this),
19       delegate_(delegate),
20       users_(users) {
21   InitMenu();
22 }
23
24 AppListMenu::~AppListMenu() {}
25
26 void AppListMenu::InitMenu() {
27   // User selector menu section. We don't show the user selector if there is
28   // only 1 user.
29   if (users_.size() > 1) {
30     for (size_t i = 0; i < users_.size(); ++i) {
31 #if defined(OS_MACOSX)
32       menu_model_.AddRadioItem(SELECT_PROFILE + i,
33                                users_[i].email.empty() ? users_[i].name
34                                                        : users_[i].email,
35                                0 /* group_id */);
36 #elif defined(OS_WIN)
37       menu_model_.AddItem(SELECT_PROFILE + i, users_[i].name);
38       int menu_index = menu_model_.GetIndexOfCommandId(SELECT_PROFILE + i);
39       menu_model_.SetSublabel(menu_index, users_[i].email);
40       // Use custom check mark.
41       if (users_[i].active) {
42         ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
43         menu_model_.SetIcon(menu_index, gfx::Image(*rb.GetImageSkiaNamed(
44             IDR_APP_LIST_USER_INDICATOR)));
45       }
46 #endif
47     }
48     menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
49   }
50
51   menu_model_.AddItem(SHOW_SETTINGS, l10n_util::GetStringUTF16(
52       IDS_APP_LIST_OPEN_SETTINGS));
53
54   menu_model_.AddItem(SHOW_HELP, l10n_util::GetStringUTF16(
55       IDS_APP_LIST_HELP));
56
57   menu_model_.AddItem(SHOW_FEEDBACK, l10n_util::GetStringUTF16(
58       IDS_APP_LIST_OPEN_FEEDBACK));
59 }
60
61 bool AppListMenu::IsCommandIdChecked(int command_id) const {
62 #if defined(OS_MACOSX)
63   DCHECK_LT(static_cast<unsigned>(command_id) - SELECT_PROFILE, users_.size());
64   return users_[command_id - SELECT_PROFILE].active;
65 #else
66   return false;
67 #endif
68 }
69
70 bool AppListMenu::IsCommandIdEnabled(int command_id) const {
71   return true;
72 }
73
74 bool AppListMenu::GetAcceleratorForCommandId(int command_id,
75                                              ui::Accelerator* accelerator) {
76   return false;
77 }
78
79 void AppListMenu::ExecuteCommand(int command_id, int event_flags) {
80   if (command_id >= SELECT_PROFILE) {
81     delegate_->ShowForProfileByPath(
82         users_[command_id - SELECT_PROFILE].profile_path);
83     return;
84   }
85   switch (command_id) {
86     case SHOW_SETTINGS:
87       delegate_->OpenSettings();
88       break;
89     case SHOW_HELP:
90       delegate_->OpenHelp();
91       break;
92     case SHOW_FEEDBACK:
93       delegate_->OpenFeedback();
94       break;
95     default:
96       NOTREACHED();
97   }
98 }
99
100 }  // namespace app_list