2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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 GlFileUpdateTimer.cpp
19 * @brief This is the source file for FileUpdateTimer class.
22 #include "GlFileUpdateTimer.h"
23 #include "GlFileListPresentationModel.h"
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Base::Utility;
28 using namespace Tizen::Content;
29 using namespace Tizen::Io;
30 using namespace Tizen::System;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Controls;
33 using namespace Tizen::Ui::Scenes;
35 FileUpdateTimer::FileUpdateTimer(Tizen::Base::Collection::IList* pDelList
36 , IContentFileUpdateManager* pFDM
37 , IFileOpInvalidateListener* invalidate
38 , FileActionMode actionId
39 , RotateMode rotateMode)
40 : GlTimerBase(invalidate, actionId)
41 , __pUpdateIndexList(pDelList)
42 , __pFileUpdateManager(pFDM)
43 , __rotateMode(rotateMode)
44 , __scanDirMap(SingleObjectDeleter)
45 , __pContentManager(null)
47 __scanDirMap.Construct();
48 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
51 FileUpdateTimer::~FileUpdateTimer(void)
54 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
56 delete __pUpdateIndexList;
57 delete __pContentManager;
62 FileUpdateTimer::TimerStart(void)
65 __pContentManager = new (std::nothrow) ContentManager();
66 __pContentManager->Construct();
67 IList* pCntIdList = __pFileUpdateManager->GetContentIdListAtIndexN(*__pUpdateIndexList);
73 FileUpdateTimer::TimerExpired(const Object* contentId)
76 if (_actionId == FILE_ACTION_DELETE)
78 const ContentId* cntId = static_cast<const ContentId*>(contentId);
83 ContentInfo* cntInfo = __pContentManager->GetContentInfoN(*cntId);
86 String filePath = cntInfo->GetContentPath();
88 result r = __pFileUpdateManager->DeleteContentFile(filePath);
93 result r = filePath.LastIndexOf(DIRECTORY_SEPARATOR, filePath.GetLength() - 1, index);
94 TryReturn(r == E_SUCCESS, false, "[%s] Unable to get Dirpath", GetErrorMessage(r));
95 filePath.SubString(0, index, dirPath);
96 if(!__scanDirMap.ContainsKey(dirPath))
98 __scanDirMap.Add(new String(dirPath), new Integer(0));
110 result r = E_SUCCESS;
111 const ContentId* cntId = static_cast<const ContentId*>(contentId);
112 if (contentId != null)
114 r = __pFileUpdateManager->RotateImage(*cntId, __rotateMode);
115 if ( r == E_SUCCESS )
117 __pFileUpdateManager->RequestThumbnail(*cntId); // do not request thumbnail for video files
130 FileUpdateTimer::ScanDirectories(void)
132 AppLogDebug("ENTER");
134 result r = E_SUCCESS;
135 if (_actionId == FILE_ACTION_DELETE)
137 int scanCount = __scanDirMap.GetCount();
142 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
144 while (pMapEnum->MoveNext() == E_SUCCESS)
146 pKey = static_cast< String* > (pMapEnum->GetKey());
147 r = ContentManager::ScanDirectory(*(pKey), true, null, reqId);
149 __scanDirMap.RemoveAll();
150 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
155 AppLogDebug("EXIT, nothing to be done");
161 FileUpdateTimer::GetDirScanCount() const
163 return __scanDirMap.GetCount();
167 FileUpdateTimer::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
169 AppLogDebug("ENTER");
170 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED &&
171 _actionId == FILE_ACTION_DELETE)
173 String sdcPath = Environment::GetExternalStoragePath();
174 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
176 while (pMapEnum->MoveNext() == E_SUCCESS)
178 pKey = static_cast< String* > (pMapEnum->GetKey());
179 if (pKey->StartsWith(sdcPath, 0))
181 __scanDirMap.Remove(*pKey);
190 FileUpdateTimer::TimerCancel(int, enum FileActionCancelRes res)
192 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
195 FileUpdateTimer::TimerComplete(int, enum FileActionCompleteRes res)
197 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);