| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_APP_LIST_APP_LIST_MODEL_H_ | 5 #ifndef UI_APP_LIST_APP_LIST_MODEL_H_ |
| 6 #define UI_APP_LIST_APP_LIST_MODEL_H_ | 6 #define UI_APP_LIST_APP_LIST_MODEL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "ui/app_list/app_list_export.h" | 11 #include "ui/app_list/app_list_export.h" |
| 12 #include "ui/app_list/app_list_item_list.h" | 12 #include "ui/app_list/app_list_item_list.h" |
| 13 #include "ui/app_list/app_list_item_list_observer.h" |
| 13 #include "ui/base/models/list_model.h" | 14 #include "ui/base/models/list_model.h" |
| 14 | 15 |
| 15 namespace app_list { | 16 namespace app_list { |
| 16 | 17 |
| 18 class AppListFolderItem; |
| 17 class AppListItem; | 19 class AppListItem; |
| 18 class AppListItemList; | 20 class AppListItemList; |
| 19 class AppListModelObserver; | 21 class AppListModelObserver; |
| 20 class SearchBoxModel; | 22 class SearchBoxModel; |
| 21 class SearchResult; | 23 class SearchResult; |
| 22 | 24 |
| 23 // Master model of app list that consists of three sub models: AppListItemList, | 25 // Master model of app list that consists of three sub models: AppListItemList, |
| 24 // SearchBoxModel and SearchResults. The AppListItemList sub model owns a list | 26 // SearchBoxModel and SearchResults. The AppListItemList sub model owns a list |
| 25 // of AppListItems and is displayed in the grid view. SearchBoxModel is | 27 // of AppListItems and is displayed in the grid view. SearchBoxModel is |
| 26 // the model for SearchBoxView. SearchResults owns a list of SearchResult. | 28 // the model for SearchBoxView. SearchResults owns a list of SearchResult. |
| 27 class APP_LIST_EXPORT AppListModel { | 29 // NOTE: Currently this class observes |item_list_|. The View code may |
| 30 // move entries in the item list directly (but can not add or remove them) and |
| 31 // the model needs to notify its observers when this occurs. |
| 32 |
| 33 class APP_LIST_EXPORT AppListModel : public AppListItemListObserver { |
| 28 public: | 34 public: |
| 29 enum Status { | 35 enum Status { |
| 30 STATUS_NORMAL, | 36 STATUS_NORMAL, |
| 31 STATUS_SYNCING, // Syncing apps or installing synced apps. | 37 STATUS_SYNCING, // Syncing apps or installing synced apps. |
| 32 }; | 38 }; |
| 33 | 39 |
| 34 typedef ui::ListModel<SearchResult> SearchResults; | 40 typedef ui::ListModel<SearchResult> SearchResults; |
| 35 | 41 |
| 36 AppListModel(); | 42 AppListModel(); |
| 37 ~AppListModel(); | 43 virtual ~AppListModel(); |
| 38 | 44 |
| 39 void AddObserver(AppListModelObserver* observer); | 45 void AddObserver(AppListModelObserver* observer); |
| 40 void RemoveObserver(AppListModelObserver* observer); | 46 void RemoveObserver(AppListModelObserver* observer); |
| 41 | 47 |
| 42 void SetStatus(Status status); | 48 void SetStatus(Status status); |
| 43 | 49 |
| 50 // Finds the item matching |id|. |
| 51 AppListItem* FindItem(const std::string& id); |
| 52 |
| 53 // Adds |item| to the model. The model takes ownership of the item. |
| 54 void AddItem(AppListItem* item); |
| 55 |
| 56 // Merges two items. If the target item is a folder, the source item is added |
| 57 // to that folder, otherwise a new folder is created in the same position as |
| 58 // the target item. Returns the id of the target folder. |
| 59 const std::string& MergeItems(const std::string& target_item_id, |
| 60 const std::string& source_item_id); |
| 61 |
| 62 // Sets the position of |item| in |item_list_|. |
| 63 void SetItemPosition(AppListItem* item, |
| 64 const syncer::StringOrdinal& new_position); |
| 65 |
| 66 // Deletes the item matching |id| from |item_list_|. |
| 67 void DeleteItem(const std::string& id); |
| 68 |
| 44 AppListItemList* item_list() { return item_list_.get(); } | 69 AppListItemList* item_list() { return item_list_.get(); } |
| 45 SearchBoxModel* search_box() { return search_box_.get(); } | 70 SearchBoxModel* search_box() { return search_box_.get(); } |
| 46 SearchResults* results() { return results_.get(); } | 71 SearchResults* results() { return results_.get(); } |
| 47 Status status() const { return status_; } | 72 Status status() const { return status_; } |
| 48 | 73 |
| 49 private: | 74 private: |
| 75 // AppListItemListObserver |
| 76 virtual void OnListItemMoved(size_t from_index, |
| 77 size_t to_index, |
| 78 AppListItem* item) OVERRIDE; |
| 79 |
| 80 // Returns the position of the last item in |item_list_| or an initial one. |
| 81 syncer::StringOrdinal GetLastItemPosition(); |
| 82 |
| 83 // Adds |item| to |item_list_| and notifies observers. |
| 84 void AddItemToItemList(AppListItem* item); |
| 85 |
| 86 // Adds |item| to |folder|. |
| 87 void AddItemToFolder(AppListFolderItem* folder, AppListItem* item); |
| 88 |
| 50 scoped_ptr<AppListItemList> item_list_; | 89 scoped_ptr<AppListItemList> item_list_; |
| 51 scoped_ptr<SearchBoxModel> search_box_; | 90 scoped_ptr<SearchBoxModel> search_box_; |
| 52 scoped_ptr<SearchResults> results_; | 91 scoped_ptr<SearchResults> results_; |
| 53 | 92 |
| 54 Status status_; | 93 Status status_; |
| 55 ObserverList<AppListModelObserver> observers_; | 94 ObserverList<AppListModelObserver> observers_; |
| 56 | 95 |
| 57 DISALLOW_COPY_AND_ASSIGN(AppListModel); | 96 DISALLOW_COPY_AND_ASSIGN(AppListModel); |
| 58 }; | 97 }; |
| 59 | 98 |
| 60 } // namespace app_list | 99 } // namespace app_list |
| 61 | 100 |
| 62 #endif // UI_APP_LIST_APP_LIST_MODEL_H_ | 101 #endif // UI_APP_LIST_APP_LIST_MODEL_H_ |
| OLD | NEW |