2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file HmHomePresentationModel.h
19 * @brief Keeps declaration of the HomePresentationModel
20 * Declares the HomePresentationModel classe, it keeps the data required to show the application icons in the home view
24 #ifndef _HM_HOME_PRESENTATION_MODEL_H_
25 #define _HM_HOME_PRESENTATION_MODEL_H_
28 #include "HmGenericDatabaseManager.h"
29 #include "HmIHomePresentationModelListener.h"
30 #include "HmIPackageInfoListListener.h"
31 #include "HmPackageInfoListRetrieveThread.h"
35 class PackageInfoListRetrieveThread;
38 * @enum HomePresentationRequestIds
39 * Request IDs to the Model Thread
41 enum HomePresentationModelRequestTypes
43 MODEL_REQUEST_INITIALIZE = 100, /** Initialization request */
47 * @class HomePresentationModel
48 * @brief Home data presenter
51 class HomePresentationModel
52 : public Tizen::Base::Object
53 , public Tizen::App::Package::IPackageInstallationEventListener
54 , public IPackageInfoListListener
57 class HomeApplicationsComparer
58 : public Tizen::Base::Collection::IComparer
61 virtual result Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp) const;
66 * The default constructor for the class
67 * The object is not fully constructed after this constructor is called.
68 * For full construction, the Construct() method must be called right after calling this constructor
70 HomePresentationModel(void);
73 * This is the destructor for this class.
75 virtual ~HomePresentationModel(void);
78 * Constructs the model, initializes the members with proper values
80 * @return result, E_SUCCESS or standard error code if failed.
82 result Construct(void);
85 * Returns the item instance to be shown in mentioned position
87 * @return HomeItemInfo*, the pointer to the actual item.
88 * @param[in] page Number, the page number to which the Item belongs
89 * @param[in] index, The index for which the item is to be retrieved
91 HomeItemInfo* GetItem(int pageNumber, int index) const;
94 * Returns the number of items in the mentioned page
96 * @return int, number of items in page.
97 * @param[in] pageNumber, the page number for which the Item count needed
99 int GetItemCount(int pageNumber) const;
102 * Returns the number of pages to be created to show all the application icons
104 * @return int, number of pages.
106 int GetPageCount(void) const;
109 * Updates the application informations etc in case of language changed
111 void LanguageChanged(void);
114 * Rearranges the items within a page, across page and moves icons .
116 * @param[in] pMovedAppInfo, The HomeItemInfo's pointer, which has to be moved
117 * @param[in] newPageNumber, New Page number, where the icon has to be placed
118 * @param[in] newIndex, The index to which the mentioned application to be placed
120 void RearrangeItems(HomeItemInfo* pMovedAppInfo, int newPageNumber, int newIndex);
123 * Sets the installation/un-installation event listener.
125 * @param[in] pListener, the listener object to be set.
127 void SetHomePackageEventListener(IHomePresentationModelEventListener* pListener);
130 * Updates the applications data into the database.
132 * @return E_SUCCESS, in case of success else system wide error code.
134 result UpdatePageData(void);
136 //from IPackageInstallationEventListener
137 virtual void OnPackageInstallationCompleted(const Tizen::App::PackageId& packageId, Tizen::App::Package::PackageInstallationResult installationResult);
138 virtual void OnPackageInstallationInProgress(const Tizen::App::PackageId& packageId, int progress) {}
139 virtual void OnPackageUninstallationCompleted(const Tizen::App::PackageId& packageId, bool uninstallationResult);
141 //from IPackageInfoListListener
143 * Called when PackageListing completes
145 * @param[in] pAppsList, list of installed packages
146 * @param[in] totalApps, total number of installed applications
147 * @param[in] totalPages, total number of pages
149 virtual void OnPackageInfoRetrievedN(Tizen::Base::Collection::HashMap* pAppsList, int totalApps, int totalPages);
153 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
155 HomePresentationModel(const HomePresentationModel&);
158 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
160 HomePresentationModel& operator =(const HomePresentationModel&);
163 * Tries to find a HomeItemInfo with the name sa provided in parameters
165 * @return HomeItemInfo*, valid pointer if found else null
166 * @param[in] packageId, the packageId to be searched for
168 HomeItemInfo* FindAppObjectInList(const Tizen::Base::String& packageIdToFind);
171 * Initializes the DataBase with initial values, create databse and tables if not already created.
173 * @return E_SUCCESS, in case of success else system wide error code.
175 result InitializeDatabase(void);
178 * Inserts page position data into the database.
180 * @return E_SUCCESS, in case of success else system wide error code.
181 * @param[in] pItemInfo, the application object to get the data from.
183 result InsertPageDataInDataBase(const HomeItemInfo* pItemInfo);
186 * Notify the ui about the package manager installation event
188 * @return result, E_SUCCESS, in case of success else system wide error code.
189 * @param[in] appId, the application id for which installation completed
191 result NotifyInstallationEvent(const Tizen::App::PackageId& packageId);
194 * this api prepares the application list, by using data in database, to retain the previous state.
196 * @return, E_SUCCESS, in case of success else system wide error code.
198 result PrepareApplicationsList(void);
201 * Sorts the pages, depending upon the position of the application icons
203 void SortPages(void);
206 * Updates the applications information into the database table.
207 * @return E_SUCCESS, in case of success else system wide error code.
208 * @param[in] pItemInfo, the application object to get the data from.
210 result UpdateDataToDatabase(HomeItemInfo* pItemInfo);
213 * Update the applications info objects within the mentioned ArrayList, with corresponding postions
214 * Gets called, after re-arrangement completes.
216 void UpdatePositions(Tizen::Base::Collection::ArrayList& pAppListToUpdate);
219 * Reads the database and updates the local copy of the applications information
221 * @return E_SUCCESS, in case of success else system wide error code.
223 result UpdateWithPositions(void);
226 GenericDatabaseManager* __pDataBaseManager; // HmDatabaseManager instance.
227 HomeApplicationsComparer __comparerObject; // IComparer derived class to be passed in Sort method
228 IHomePresentationModelEventListener* __pDataListener; // listener for various events
229 int __totalApps; //total number of applications
230 int __totalPages; //total number of pages
231 Tizen::App::Package::PackageManager* __pPackMgr; //PackageManager instance
232 Tizen::Base::Collection::HashMap* __pAppHashMap; // application informations
233 PackageInfoListRetrieveThread* __pPackageInfoRetrieveThread; // the worker thread instance to fetch packages list
236 #endif //_HM_HOME_PRESENTATION_MODEL_H_