830c8ca7fe1995ce6e3b28ca8ebabfc49559e185
[framework/web/wrt-plugins-common.git] / src / modules / API / Messaging / Attachments.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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  * @file       Attachments.h
18  * @author     Pawel Misiak (p.misiak@samsung.com)
19  * @version    0.1
20  * @brief
21  */
22 #ifndef ATTACHMENTS_H
23 #define ATTACHMENTS_H
24
25 #include <vector>
26 #include <string>
27 #include <dpl/shared_ptr.h>
28 #include "IMessagingTypes.h"
29 #include "IAttachment.h"
30
31 namespace WrtDeviceApis {
32 namespace Messaging{
33 namespace Api {
34 //--------------------------------------------------------------------------
35
36 class Attachments
37 {
38     std::vector<IAttachmentPtr> m_attachments;
39
40   public: // fields
41
42   private:
43
44     bool m_validAttachments;
45
46   public: // methods
47
48     Attachments();
49
50     virtual ~Attachments();
51
52     /**
53      * method for append attachment into list
54      * @param[in] fullPath - path for attachment
55      * @return AttachmentPtr - if file exist create attachment object
56      *                         it is possible to modify name, etc.
57      * @throw InvalidArgumentException - if file not exist
58      */
59     IAttachmentPtr appendAttachment(const std::string& fullPath,
60             bool isVirtualPath);
61
62     /**
63      * method for append attachment into list
64      * @param[in] attachment - attachment to be added
65      */
66     void appendAttachment(const IAttachmentPtr& attachment);
67
68     /**
69      * method for append attachments list
70      * @param[in] attachments - attachment list
71      */
72     void appendAttachments(const std::vector<IAttachmentPtr>& attachments);
73
74     /**
75      * get attachment count
76      * @return attachment count
77      */
78     size_t getAttachmentsCount() const;
79
80     /**
81      * get attachment object at index
82      * @param[in] index - index of attachment to get
83      * @return attachment object
84      * @throw OutOfRangeException if index is out of range
85      */
86     IAttachmentPtr getAttachment(const size_t index) const;
87
88     /**
89      * remove attachment at the index
90      * @param[in] index - index of attachment to get
91      * @return void
92      * @throw OutOfRangeException if index is out of range
93      */
94     void removeAttachment(const size_t index);
95
96     /**
97      * remove attachment at the index
98      * @param[in] attachment - AttachmentPtr object
99      * @return void
100      * @throw OutOfRangeException if index is out of range
101      */
102     void removeAttachment(const IAttachmentPtr& attachment);
103
104     /**
105      * get all attachments vector
106      * @return attachment vector
107      */
108     std::vector<IAttachmentPtr> getAttachments() const;
109
110     /**
111      * get all attachments full path vector
112      * @return attachment path vector
113      */
114     std::vector<std::string> getAttachmentsFullPaths() const;
115
116     /**
117      * get all attachments names vector
118      * @return attachment names vector
119      */
120     std::vector<std::string> getAttachmentsShortNames() const;
121
122     /**
123      * get all attachments vector reference
124      * @return attachment vector
125      */
126     const std::vector<IAttachmentPtr>& getAttachmentsRef() const;
127
128     /**
129      * set attachments
130      * @param[in] attachments - vector of and attachments full path
131      * @throw InvalidArgumentException - if file not exist
132      */
133     void setAttachments(const std::vector<std::string>& attachments,
134             bool isVirtualPath);
135
136     /**
137      * set attachmentsPtr
138      * @param[in] attachments - vector of AttachmentPtr
139      */
140     void setAttachments(const std::vector<IAttachmentPtr>& attachments);
141
142     /**
143      * check if attachments are modified and need update in platform
144      * @return bool
145      */
146     bool isAttachmentsValid() const;
147
148     /**
149      * setting validity after update
150      * @param[in] state - state for validity to set
151      */
152     void setAttachmentsValidity(bool state);
153
154     /**
155      * saving attachment file to selected destination file
156      * @param[in] destFileName - destination file to save attachment
157      * @param[in] attachment - attachment to be saved
158      */
159     void saveAttachment(const std::string& destFileName,
160             const IAttachmentPtr& attachment);
161
162     /**
163      * sets attachment at given position and expands array if needed
164      * @param[in] index - position
165      * @param[in] fullPath - path for attachment
166      * @throw InvalidArgumentException - if file not exist
167      */
168     void setAttachmentWithExpand(const size_t index,
169             const std::string& fullPath,
170             bool isVirtualPath);
171
172     /**
173      * The reverse() method reverses the order of the elements in an array
174      * (makes the last element first, and the first element last).
175      */
176     void reverse();
177
178     /**
179      * Creates new attachment and inserts it at given position
180      * @param[in] index position
181      * @param[in] fullPath - path for attachment
182      * @param[in] isVirtualPath - true if path is virtual
183      * @throw InvalidArgumentException - if file not exist
184      */
185     void insertAttachment(const size_t index,
186             const std::string& fullPath,
187             bool isVirtualPath);
188
189     /**
190      * Creates new attachment and inserts it at given position and expands array if needed
191      * @param[in] index position
192      * @param[in] fullPath - path for attachment
193      * @param[in] isVirtualPath - true if path is virtual
194      * @throw InvalidArgumentException - if file not exist
195      */
196     void insertAttachmentWithExpand(const size_t index,
197             const std::string& fullPath,
198             bool isVirtualPath);
199 };
200
201 typedef DPL::SharedPtr<Attachments> AttachmentsPtr;
202
203 }
204 }
205 }
206
207 #endif