Tizen 2.1 base
[apps/osp/Home.git] / inc / HmHomePresentationModel.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
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
21  */
22
23
24 #ifndef _HM_HOME_PRESENTATION_MODEL_H_
25 #define _HM_HOME_PRESENTATION_MODEL_H_
26
27 #include <FBase.h>
28 #include "HmGenericDatabaseManager.h"
29 #include "HmIHomePresentationModelListener.h"
30 #include "HmIPackageInfoListListener.h"
31 #include "HmPackageInfoListRetrieveThread.h"
32 #include "HmTypes.h"
33
34 class HomeItemInfo;
35 class PackageInfoListRetrieveThread;
36
37 /**
38  * @enum HomePresentationRequestIds
39  * Request IDs to the Model Thread
40  */
41 enum HomePresentationModelRequestTypes
42 {
43         MODEL_REQUEST_INITIALIZE = 100, /** Initialization request */
44 };
45
46 /**
47  * @class   HomePresentationModel
48  * @brief   Home data presenter
49  */
50
51 class HomePresentationModel
52         : public Tizen::Base::Object
53         , public Tizen::App::Package::IPackageInstallationEventListener
54         , public IPackageInfoListListener
55 {
56
57         class HomeApplicationsComparer
58                 : public Tizen::Base::Collection::IComparer
59         {
60         public:
61                 virtual result Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp) const;
62         };
63
64 public:
65         /**
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
69          */
70         HomePresentationModel(void);
71
72         /**
73          * This is the destructor for this class.
74          */
75         virtual ~HomePresentationModel(void);
76
77         /**
78          * Constructs the model, initializes the members with proper values
79          *
80          * @return      result, E_SUCCESS or standard error code if failed.
81          */
82         result Construct(void);
83
84         /**
85          * Returns the item instance to be shown in mentioned position
86          *
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
90          */
91         HomeItemInfo* GetItem(int pageNumber, int index) const;
92
93         /**
94          * Returns the number of items in the mentioned page
95          *
96          * @return              int, number of items in page.
97          * @param[in]   pageNumber, the page number for which the Item count needed
98          */
99         int GetItemCount(int pageNumber) const;
100
101         /**
102          * Returns the number of pages to be created to show all the application icons
103          *
104          * @return      int, number of pages.
105          */
106         int GetPageCount(void) const;
107
108         /**
109          * Updates the application informations etc in case of language changed
110          */
111         void LanguageChanged(void);
112
113         /**
114          * Rearranges the items within a page, across page and moves icons .
115          *
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
119          */
120         void RearrangeItems(HomeItemInfo* pMovedAppInfo, int newPageNumber, int newIndex);
121
122         /**
123          * Sets the installation/un-installation event listener.
124          *
125          * @param[in]   pListener, the listener object to be set.
126          */
127         void SetHomePackageEventListener(IHomePresentationModelEventListener* pListener);
128
129         /**
130          * Updates the applications data into the database.
131          *
132          * @return      E_SUCCESS, in case of success else system wide error code.
133          */
134         result UpdatePageData(void);
135
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);
140
141         //from IPackageInfoListListener
142         /**
143          * Called when PackageListing completes
144          *
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
148          */
149         virtual void OnPackageInfoRetrievedN(Tizen::Base::Collection::HashMap* pAppsList, int totalApps, int totalPages);
150
151 private:
152         /**
153          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
154          */
155         HomePresentationModel(const HomePresentationModel&);
156
157         /**
158          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
159          */
160         HomePresentationModel& operator =(const HomePresentationModel&);
161
162         /**
163          * Tries to find a HomeItemInfo with the name sa provided in parameters
164          *
165          * @return              HomeItemInfo*, valid pointer if found else null
166          * @param[in]   packageId, the packageId to be searched for
167          */
168         HomeItemInfo* FindAppObjectInList(const Tizen::Base::String& packageIdToFind);
169
170         /**
171          * Initializes the DataBase with initial values, create databse and tables if not already created.
172          *
173          * @return      E_SUCCESS, in case of success else system wide error code.
174          */
175         result InitializeDatabase(void);
176
177         /**
178          * Inserts page position data into the database.
179          *
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.
182          */
183         result InsertPageDataInDataBase(const HomeItemInfo* pItemInfo);
184
185         /**
186          * Notify the ui about the package manager installation event
187          *
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
190          */
191         result NotifyInstallationEvent(const Tizen::App::PackageId& packageId);
192
193         /**
194          * this api prepares the application list, by using data in database, to retain the previous state.
195          *
196          * @return, E_SUCCESS, in case of success else system wide error code.
197          */
198         result PrepareApplicationsList(void);
199
200         /**
201          * Sorts the pages, depending upon the position of the application icons
202          */
203         void SortPages(void);
204
205         /**
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.
209          */
210         result UpdateDataToDatabase(HomeItemInfo* pItemInfo);
211
212         /**
213          * Update the applications info objects within the mentioned ArrayList, with corresponding postions
214          * Gets called, after re-arrangement completes.
215          */
216         void UpdatePositions(Tizen::Base::Collection::ArrayList& pAppListToUpdate);
217
218         /**
219          * Reads the database and updates the local copy of the applications information
220          *
221          * @return      E_SUCCESS, in case of success else system wide error code.
222          */
223         result UpdateWithPositions(void);
224
225 private:
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
234 };
235
236 #endif //_HM_HOME_PRESENTATION_MODEL_H_