Arrange code
[apps/osp/Gallery.git] / src / GlBaseForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
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                GlBaseForm.cpp
19  * @brief               This is the implementation file for GlBaseForm class.
20  */
21
22 #include "GlFileListPresentationModel.h"
23 #include "GlBaseForm.h"
24
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Ui::Controls;
28 using namespace Tizen::Base::Utility;
29
30 IList*
31 BaseForm::GetMoveFileIndexList(String& moveDir, IList* pMoveIndexList, FileListPresentationModel* pPresentationModel)
32 {
33         if (&moveDir == null || moveDir.IsEmpty())
34         {
35                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
36                 return null;
37         }
38
39         if (pMoveIndexList == null || pMoveIndexList->GetCount() <= 0)
40         {
41                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
42                 return null;
43         }
44
45         IList* pCollisionList = pPresentationModel->GetCollisionIndexListN(*pMoveIndexList, moveDir);
46
47         if (pCollisionList != null)
48         {
49                 int loopCount = pCollisionList->GetCount();
50                 int collisionCount = 0;
51                 for (int i = 0; i < loopCount; ++i)
52                 {
53                         String* pCollisionString = const_cast<String*>(static_cast<const String*>(pCollisionList->GetAt(i)));
54                         String tmpString;
55
56                         if (pCollisionString != null)
57                         {
58                                 tmpString = (*pCollisionString);
59                         }
60
61                         String delim(MULTI_ITEM_SEPARATOR);
62                         StringTokenizer st(tmpString, delim);
63                         String token;
64
65                         int collisionIndex;
66                         String fileName;
67
68                         if (st.HasMoreTokens() == true)
69                         {
70                                 st.GetNextToken(token);
71                                 Integer::Parse(token, collisionIndex);
72
73                                 if (st.HasMoreTokens() == true)
74                                 {
75                                         st.GetNextToken(fileName);
76                                 }
77
78                                 int innerLoopCount = pMoveIndexList->GetCount();
79                                 for (int j = 0; j < innerLoopCount; ++j)
80                                 {
81                                         if (collisionIndex == (const_cast<Integer*>(static_cast<const Integer*>
82                                         (pMoveIndexList->GetAt(j))))->ToInt())
83                                         {
84                                                 pMoveIndexList->RemoveAt(j, true);
85                                                 --j;
86                                                 --innerLoopCount;
87                                                 ++collisionCount;
88                                         }
89                                 }
90                         }
91                 }
92
93                 pCollisionList->RemoveAll(true);
94                 delete pCollisionList;
95
96                 if (collisionCount > 0)
97                 {
98                         MessageBox messageBox;
99                         messageBox.Construct(L"", L"Unable to move some files. Same files exists",
100                                         MSGBOX_STYLE_NONE, 3000);
101                         int modalResult;
102                         messageBox.ShowAndWait(modalResult);
103                 }
104         }
105         return pMoveIndexList;
106 }