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