N_SE-36744 N_SE-36750 N_SE-36754 N_SE-36743
[apps/osp/MyFiles.git] / inc / MfFolderEntryPresentationModel.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: MfFolderEntryPresentationModel.h
19  * @brief: This model is responsible for getting the details of any Directory/File entries in the
20  * file system. Constructs the structure which contains basic information of these entries.
21  * Acts as Content browser for any given file path or directory path.
22  */
23
24 #ifndef _MF_FOLDER_ENTRY_PRESENTATION_MODEL_H_
25 #define _MF_FOLDER_ENTRY_PRESENTATION_MODEL_H_
26
27 #include <FApp.h>
28 #include <FBase.h>
29 #include <FIo.h>
30 #include <FSysEnvironment.h>
31 #include <FSystem.h>
32 #include <FUi.h>
33
34 #include "MfBasePresentationModel.h"
35 #include "MfCacheManager.h"
36 #include "MfDirectoryEntry.h"
37 #include "MfIFileEventNotification.h"
38 #include "MfIListViewStateChangeListener.h"
39 #include "MfThumbnailManager.h"
40 #include "MfTypes.h"
41
42 class FolderEntryPresentationModel;
43
44 class IFolderEntryProviderListener
45 {
46 public:
47         virtual ~IFolderEntryProviderListener(void);
48
49         //! IFolderEntryProviderListener
50         /*! A public virtual member function of IFolderEntryProviderListener returning a pointer to the FolderEntryPresentationModel.
51          * @fn  GetFolderEntryPresentationModel(void)
52          * @brief Used to get the pointer to the FileListPresentationModel Class.
53          * @param No parameters taken.
54          * @return [FolderEntryPresentationModel*] A pointer to the FolderEntryPresentationModel model.
55          */
56         virtual FolderEntryPresentationModel* GetFolderEntryPresentationModel(void) = 0;
57 };
58
59 class FolderEntryPresentationModel
60         : public BasePresentationModel
61 {
62 public:
63         //!This is the constructor for the class
64         /*!
65          * @fn FileListPresentationModel()
66          * @param Takes no parameters
67          * @return No value returned
68          */
69         FolderEntryPresentationModel(void);
70
71         //!This is the Destructor for the class
72         /*!@fn ~FileListPresentationModel()
73          * @param Takes no parameters
74          * @return No value returned
75          */
76         virtual ~FolderEntryPresentationModel(void);
77
78         //!This is the Construct method for the class in which memory will be allocated for member variables
79         /*!@fn ~Construct()
80          * @param Takes no parameters
81          * @return result value
82          */
83         result Construct(void);
84
85         /*!@fn UpdateEntryCount()
86          * @params [string, int, int] filepath for which structure is constructed,
87          * currentDirectoryCount which will be updated with number of directories present in the given filepath
88          * currentFileCount which will be updated with number of files present in the given filepath
89          * Returns no parameters
90          */
91         void GetFolderEntryCount(const Tizen::Base::String& filePath, int& currentDirectoryCount, int& currentFileCount);
92
93         void GetSortFolderEntryCount(int& currentDirectoryCount, int& currentFileCount);
94         /*!@fn GetDirectoryEntryList()
95          * @param Takes no parameters
96          * @return[ArrayList] Returns an arraylist containing the directory entries
97          */
98         Tizen::Base::Collection::ArrayList* GetFolderEntryList(void);
99
100         /*!@fnGetSourceForm(void)
101          * @brief Used to get the parent form which invoked FolderEntryPesentationModel.
102          * @params No Parameters taken
103          * @return [CreateItemSource], source form which invoked FolderEntryPesentationModel
104          */
105         CreateItemSource GetSourceForm(void);
106
107         /*!@fn InitThumbnailManager
108          * This function is a public member of this model and called by views for generating thumbnails
109          * @param taken integer value index as a parameter for of the list view item for which it is suppose to genetrate thumbnail.
110          * Returns result
111          */
112         result InitThumbnailManager(void);
113         //result InitThumbnailManager(int iItemIndex);
114
115
116         /*!@fn void setFileEventListener(IFileEventNotification *pIFileEventNotification,Tizen::Base::String& currentFilePath)
117          * used to set listeners for the respective view if some file addition or delete activity take place
118          * @param Takes filenotification listener and path
119          * Returns no parameters
120          */
121         void SetFileEventListener(IFolderEntryEventListener* pIFileEventNotification);
122
123         /*!@fn SetFolderEntryPath()
124          * @param Takes a string as a parameter. This is the filepath from which structure is constructed.
125          * Returns no parameters
126          */
127         void SetFolderEntryPath(const Tizen::Base::String& filePath);
128
129         /*!@fn AddFolderEntryList()
130          * @param string filepath: new path that has to be added to the directory entry list
131          * @param int index: index where the list has to be added
132          * Returns no parameters
133          */
134         void AddFolderEntryList(const Tizen::Base::String& filePath, int index);
135
136         int GetDirectoryTreeIndex(const Tizen::Base::String& filePath, int index);
137
138         /*!@fn RemoveFolderEntryList()
139          * @param string filepath: path of directories that has to be removed from the directory entry list
140          * @param int index: index where the list has to be added
141          * Returns no parameters
142          */
143         void RemoveFolderEntryList(int index);
144
145         /*!@fn void SetType(FileType currentType)
146          * used to set the type of file
147          * @param FileType enum
148          * Returns no parameters
149          */
150         void SetFolderEntryType(FileType currentType);
151
152         void SetViewType(AppControlView currentView);
153
154         /*
155          * @fn SetSortEnabled
156          * @brief: This method determines whether the directory entries have to be sorted or not
157          * @param [bool]
158          * @return No Return Value
159          */
160         void SetSortEnabled(bool enableFlag);
161
162         /*!@fn SetSourceForm(CreateItemSource currentSource)
163          * @brief Used to set the parent for which the FolderEntryPesentationModel is invoked.
164          * @params[CreateItemSource], source form which invoked FolderEntryPesentationModel
165          * @return No Return Value
166          */
167         void SetSourceForm(CreateItemSource currentSource);
168
169         /*!@fn SortBy()
170          * used to sort all the entries which are present in __pFileEntries arraylist
171          * @param Takes no parameters
172          * Returns no parameters
173          */
174         void SortFolderEntries(void);
175
176         /*@fn StartThumbnailRequest
177          * This function requests thumbnailmanager to get the thumbnail for a file.
178          *Takes index as an argument, this is the index of the file in the data-stucture maintained by the presentation model.
179          * Returns result value. Result of the StartThumbnailRequest function call
180          */
181         result StartThumbnailRequest(int iReqIndex = -1);
182
183         result SetListUpdateEventListener(IListViewStateChangeListener* pListener);
184
185         /*@fn StopThumbnailManager
186          * This function send request to thumbnailmanager to stops processing further thumbnail request.
187          * Takes no argument
188          * Returns result value
189          */
190         result  StopThumbnailManager(bool       bForceStop=false);
191
192         void RefreshFolderEntries(void);
193
194         /*
195          * It executes when some fileEvent Occured
196          * param long event, string refernce and event id
197          * @return No Return values
198          */
199         virtual void OnFileEventOccured(unsigned long events, const Tizen::Base::String& path, unsigned int eventId);
200
201         /*@fn OnThumbnailResponseReceived
202          * This function receives thumbnail image received from thumbnailmanager.
203          * Takes pointer to the bitmap and index of the item for which bitmap is received as argument
204          * Returns result value
205          */
206         result OnThumbnailResponseReceived(Tizen::Graphics::Bitmap* pThumb, int Index);
207
208         /*@fn OnThumbnailResponseFailed
209          * This function is  the callback of the thumbnail loading failed
210          * Takes index of the item for which bitmap is generation failed as an argument
211          * Returns result value
212          */
213         result OnThumbnailResponseFailed(int Index = -1);
214         void SetCurrentReqId(int currentRequestId);
215         int GetCurrentReqId(void);
216
217         void CreateStack(void);
218         void CreateTraversalTree(void);
219         int GetDeviceListCount(void);
220 private:
221         /*@fn FileListPresentationModel()
222          * Copy Constructor for the FileListPresentationModel class
223          * Takes FileListPresentationModel as a  parameter
224          * Returns no parameters
225          */
226         FolderEntryPresentationModel(const FolderEntryPresentationModel& content);
227
228         /*!@fn operator =()
229          *  Overloaded assignment operator for FileListPresentationModel class
230          * Takes FileListPresentationModel as a  parameter
231          * Returns FileListPresentationModel as a  return value
232          */
233         FolderEntryPresentationModel& operator =(const FolderEntryPresentationModel& source);
234
235         /*
236          * Responsible for creating the entries in __pFileEntries.
237          */
238         void CreateFolderEntryList(const Tizen::Base::String& directoryName, int index = 0);
239
240         /*
241          *This method is used to get the next available position in the arraylist of the directory entry during Swap operation.
242          * \param pList an arraylist which contains all the DirectoryStructure entries of the given path
243          * @return Returns the next available position where swapping can be done
244          */
245         int GetSwapIndex(void);
246
247         /*
248          * Responsible for constructing all the entries in the given path
249          */
250         result MakeFolderEntryList(const Tizen::Base::String& directoryName, int index = 0);
251
252         /*
253          * This method is used to swap two DirectoryStructure entries. This will be useful while sorting the elements of any file entry list.
254          * \param source a DirectoryStructure variable which contains the first object.
255          * \param destination a DirectoryStructure variable which contains the second object.
256          * @return No Return values
257          */
258         void SwapFolderEntries(DirectoryEntry& source, DirectoryEntry& destination);
259
260         /*
261          * It Updates the folder enteries on occuring of file event
262          * param long events and one string refernce
263          * @return No Return values
264          */
265         void UpdateFileListEnteries(unsigned long events, const Tizen::Base::String& path);
266         void GetDeviceList(Tizen::Base::Collection::ArrayList* pDeviceList);
267
268 private:
269         int __requestId;
270         int __currentRequestId;
271
272         bool __forceStop;
273         bool __enableSort;
274         bool __ThumbnailRequestInProgress;
275
276         AppControlView __currentViewType;
277         CreateItemSource __sourceForm;
278         FileType __entryType;
279
280         Tizen::Base::Collection::ArrayList* __pFolderEntries;
281         Tizen::Base::String __currentFilePath;
282         Tizen::Io::FileEventManager* __pFileEventManager;
283
284         static IFolderEntryEventListener* __pFolderEntryEventListener;
285         ThumbnailManager* __pThumbnailManager;
286         Tizen::Base::Collection::Stack* __pFolderEntryStack;
287         CacheManager* __pCacheManager;
288         int __deviceListCount;
289 };
290
291 #endif // _MF_FOLDER_ENTRY_PRESENTATION_MODEL_H_