Merge "[content] Change codes fabout content path not including extension" into tizen_2.2
[platform/framework/native/content.git] / inc / FCntContentTransfer.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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  * @if OSPDEPREC
18  * @file                FCntContentTransfer.h
19  * @brief               This is the header file for the %ContentTransfer class.
20  *
21  * This header file contains the declarations of the %ContentTransfer class.
22  * @endif
23  */
24
25 #ifndef _FCNT_CONTENT_TRANSFER_H_
26 #define _FCNT_CONTENT_TRANSFER_H_
27
28 #include <FBaseObject.h>
29
30 namespace Tizen { namespace Base { namespace Collection
31 {
32 class IList;
33 }}}
34
35 namespace Tizen { namespace Base { namespace Utility
36 {
37 class Uri;
38 }}}
39
40 namespace Tizen { namespace Content
41 {
42
43 class _ContentTransferImpl;
44 class IContentTransferListener;
45
46 /**
47  * @if OSPDEPREC
48  * @class       ContentTransfer
49  * @brief       <i> [Deprecated] </i> This class provides methods to download the content.
50  *
51  * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
52  * @since       2.0
53  *
54  * The %ContentTransfer class provides the following features:
55  * - Downloading the content from the servers that support HTTP access.
56  * - Cancelling a download operation.
57  *
58  * HTTP download (ContentTransfer::Download()) is a standard HTTP transaction using the HTTP GET request and response methods.
59  *
60  * The following example demonstrates how to use the %ContentTransfer class.
61  *
62  *      @code
63  *      class  MyClass
64  *              :public Tizen::Content::IContentTransferListener
65  *      {
66  *      public:
67  *              MyClass(void);
68  *              virtual ~MyClass(void);
69  *
70  *      public:
71  *              void OnContentTransferInProgress(RequestId requestID, int totalReceivedSize);
72  *              void OnContentDownloadCompleted(RequestId requestID, ContentId contentID, result res, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage);
73  *              void OnContentDownloadToBufferCompleted(RequestId reqId, Tizen::Base::ByteBuffer* pBuffer, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage);
74  *              void OnContentTransferCanceled(RequestId reqId, result res, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage);
75  *      };
76  *
77  *      // Implementation for the listener function and Implementation of other listener function is
78  *      void MyClass::OnContentDownloadCompleted(RequestId requestID, ContentId contentID, result res, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMessage)
79  *      {
80  *              result r = E_SUCCESS;
81  *              ContentManager contentManager;
82  *              ContentInfo* pContentInfo = null;
83  *
84  *              // Error check
85  *              TryCatch(!IsFailed(res), r, "Download Error [%s]", GetErrorMessage(res));
86  *
87  *              // Do something
88  *              r = contentManager.Construct();
89  *              TryCatch(!IsFailed(r), r, "Construct failed.");
90  *
91  *              // Get ContentInfo
92  *              pContentInfo = contentManager.GetContentInfoN(contentID);
93  *      CATCH:
94  *              if (pContentInfo)
95  *                      delete pContentInfo;
96  *      }
97  *
98  *      result
99  *      MyClass::RequestDownload(void)
100  *      {
101  *              ContentTransfer contentTransfer;
102  *              RequestId requestId;
103  *              Tizen::Base::Utility::Uri contentUri;
104  *              int contentSize;
105  *              Tizen::Base::String downloadPath;
106  *
107  *              result r = contentTransfer.Construct(*this);
108  *              TryReturn(!IsFailed(r), r, ("Construct is failed.\n"));
109  *
110  *              // TODO: set uri and download path
111  *
112  *              r = contentTransfer.Download(contentUri, downloadPath, requestId, false);
113  *              TryReturn(!IsFailed(r), r, ("Download Request is failed.\n"));
114  *      }
115  *      @endcode
116  *      @endif
117  */
118 class _OSP_EXPORT_ ContentTransfer
119         : virtual public Tizen::Base::Object
120 {
121 public:
122         /**
123          * The object is not fully constructed after this constructor is called. @n
124          * For full construction, the Construct(IContentTransferListener&) method must be called right after calling this constructor.
125          *
126          * @brief       <i> [Deprecated] </i>
127          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
128          * @since               2.0
129          *
130          * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
131          */
132         ContentTransfer(void);
133
134         /**
135          * This destructor overrides Tizen::Base::Object::~Object().
136          *
137          * @brief       <i> [Deprecated] </i>
138          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
139          *
140          * @since               2.0
141          */
142         virtual ~ContentTransfer(void);
143
144         /**
145          * Initializes this instance of %ContentTransfer with the specified parameter. @n
146          * The %Construct() method should be called after every instance of %ContentTransfer is constructed.
147          *
148          * @brief       <i> [Deprecated] </i>
149          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
150          * @since               2.0
151          *
152          * @return              An error code
153          * @param[in]   listener                A reference to IContentTransferListener
154          * @exception   E_SUCCESS               The method is successful.
155          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
156          * @exception   E_SYSTEM                A system error has occurred.
157          */
158         result Construct(IContentTransferListener& listener);
159
160         /**
161         * Downloads a content file from the content provider's server. @n
162         * The @c filesize parameter is used to check the limitation of the local volume. If this parameter is set to @c 0, the %Download() method will not check the volume. @n
163         * An application should set the full destination path for the downloaded contents. When the content is downloaded to one of the following paths, this method internally registers the content using ContentManager.
164         * - /Media/
165         * - /Storagecard/Media/ @n
166         *
167         * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadCompleted() method. @n
168         * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
169         *
170         * @brief        <i> [Deprecated] </i>
171         * @deprecated This method is deprecated due to the operation policy of the Tizen Server.
172         * When downloading the contents from a third party server, it is recommended to use the Download(const Tizen::Base::Utility::Uri&, const Tizen::Base::String&, RequestId&, bool, int, int) method.
173         * @since                                 2.0
174         * @privlevel    public
175         * @privilege    %http://tizen.org/privilege/download
176         *
177         * @return       An error code
178         * @param[in]    uri                                     The content URL
179         * @param[in]    fileSize                        The content file size in bytes @n
180         *                                                                       If set to @c 0, the method does not check the storage limitation.
181         * @param[in]    destFilePath            The full destination path
182         * @param[in]    replace                         The replace option of the destination file @n
183         *                                                                       Set to @c true to replace the file, @n
184         *                                                                       else @c false.
185         * @param[out]   reqId                           The request ID
186         * @param[in]    pListener                       A pointer to the IContentTransferListener instance
187         * @param[in]    sec                                     The timeout period in seconds
188         * @exception    E_SUCCESS                               The method is successful.
189         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
190         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
191         * @exception    E_ILLEGAL_ACCESS                Access is denied due to insufficient permission.
192         * @exception    E_FILE_ALREADY_EXIST    The specified file already exists.
193         * @exception    E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
194         * @exception    E_IN_PROGRESS                   A previous request is in progress.
195         * @exception    E_OUT_OF_MEMORY The memory is insufficient.
196         * @exception    E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
197         * @see  IContentTransferListener::OnContentDownloadCompleted()
198         * @see  IContentTransferListener::OnContentTransferInProgress()
199         */
200         result Download(const Tizen::Base::Utility::Uri& uri, int fileSize, const Tizen::Base::String& destFilePath, bool replace, RequestId& reqId, IContentTransferListener* pListener = null, int sec = 0);
201
202         /**
203          * Downloads a content file from the content provider's server. @n
204          * An application should set the destination path for the downloaded contents.
205          * The path of the downloaded file should use Tizen::System::Environment::GetMediaPath() or Tizen::System::Environment::GetExternalStoragePath().
206          *
207          * When the content is downloaded to the path using Tizen::System::Environment::GetMediaPath() or Tizen::System::Environment::GetExternalStoragePath(), the %Download() method internally registers the content in the content database. @n
208          * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadCompleted() method. @n
209          * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
210          *
211          * @brief       <i> [Deprecated] </i>
212          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
213          * @if OSPCOMPAT
214          * @brief <i> [Compatibility] </i>
215          * @endif
216          * @since                       2.0
217          * @if OSPCOMPAT
218          * @compatibility This method has compatibility issues with OSP compatible applications. @n
219          *                       For more information, see @ref CompContentTransferDownloadPage3 "here".
220          * @endif
221          * @privlevel           public
222          * @privilege           %http://tizen.org/privilege/download
223          *
224          * @return                      An error code
225          * @param[in]   uri                                             The content URL
226          * @param[in]   filePath                                The destination file path @n
227          *                                                      Use Tizen::System::Environment::GetMediaPath(), Tizen::System::Environment::GetExternalStoragePath() and Tizen::App::App::GetInstance()->GetAppRootPath().
228          * @param[out]  reqId                   The request ID
229          * @param[in]   replace                 The replace option of the destination file @n
230          *                                       Set to @c true to replace the file, @n
231          *                                                                              else @c false.
232          * @param[in]   timeout                 The timeout period in seconds
233          * @param[in]   progressInterval        The progress period interval as a percentage value
234          * @exception   E_SUCCESS                               The method is successful.
235          * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
236          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
237          * @exception   E_INVALID_STATE         This method is invalid for the current state of this instance.
238          * @exception   E_ILLEGAL_ACCESS                Access is denied due to insufficient permission.
239          * @exception   E_FILE_ALREADY_EXIST    The specified file already exists.
240          * @exception   E_IN_PROGRESS                   A previous request is in progress.
241          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
242          * @exception   E_SYSTEM                                A system error has occurred.
243          * @exception   E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
244          * @remarks
245          *                              - The @c progressInterval is the interval of the progress for each download request. If the value of the @c progressInterval is @c 0, the @c progressInterval uses the value set by the ContentTransfer::SetProgressIntervalByPercent(int). The @c progressInterval is a percentage value between @c 0 and @c 100.
246          *                              - The @c timeout is the value of the response timeout for each download request. If the value of the @c timeout is @c 0, the value for the @c timeout uses the value set by the ContentTransfer::SetDefaultTimeout(int).
247          * @see  IContentTransferListener::OnContentDownloadCompleted()
248          * @see  IContentTransferListener::OnContentTransferInProgress()
249          */
250         result Download(const Tizen::Base::Utility::Uri& uri, const Tizen::Base::String& filePath, RequestId& reqId, bool replace = false, int timeout = 0, int progressInterval = 0);
251
252         /**
253          * @if OSPCOMPAT
254          * @page                CompContentTransferDownloadPage3 Compatibility for the file path.
255          * @section     CompContentTransferDownloadPageIssueSection Issues
256          *                 The content path argument of this method in OSP compatible applications has the following issues: @n
257          *                 -# The content path should be a path that begins with an allowed path prefix. @n
258          *                    For example, L"/Media/Images/flower.jpg", "/Storagecard/Media/Images/flower.jpg".
259          *
260          * @section     CompImageContentInfoConstructPageSolutionSection Resolutions
261          *                 This issue has been resolved in Tizen. @n
262          *                 -# The content path can be a path without a specific allowed path prefix. @n
263          *                 Application do not need to know the specific allowed path prefixes. @n
264          *                 To get the directory path, use the following methods: @n
265          *                 - For accessing the media directory, use Tizen::System::Environment::GetMediaPath().
266          *                 - For accessing the external storage, use Tizen::System::Environment::GetExternalStoragePath().
267          *
268          * @endif
269          */
270
271         /**
272         * Downloads a content file to a buffer from the content provider's servers. @n
273         * The %DownloadToBuffer() method does not register the content. @n
274         * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadToBufferCompleted() method. @n
275         * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
276         *
277         * @brief        <i> [Deprecated] </i>
278         * @deprecated This method is deprecated due to the operation policy of the Tizen Server.
279         * When downloading the contents to a buffer from a third party server, it is recommended to use the DownloadToBuffer(const Tizen::Base::Utility::Uri&, RequestId&, int, int) method.
280         * @since                                 2.0
281         * @privlevel    public
282         * @privilege    %http://tizen.org/privilege/download
283         *
284         * @return       An error code
285         * @param[in]    uri                                     The content URL
286         * @param[in]    fileSize                        The content file size in bytes @n
287         *                                                                       If set to @c 0, the method does not check the storage limitation.
288         * @param[out]   reqId                           The request ID
289         * @param[in]    pListener                       A pointer to the IContentTransferListener instance
290         * @param[in]    sec                                     The timeout period in seconds
291         * @exception    E_SUCCESS                               The method is successful.
292         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
293         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
294         * @exception    E_OUT_OF_MEMORY         The memory is insufficient.
295         * @exception    E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
296         * @exception    E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
297         * @see  IContentTransferListener::OnContentDownloadToBufferCompleted()
298         * @see  IContentTransferListener::OnContentTransferInProgress()
299         */
300         result DownloadToBuffer(const Tizen::Base::Utility::Uri& uri, int fileSize, RequestId& reqId, IContentTransferListener* pListener = null, int sec = 0);
301
302         /**
303          * Downloads a content file to a buffer from the content provider's servers. @n
304          * The %DownloadToBuffer() method does not register the content. @n
305          * When the download is completed, the application is notified using the IContentTransferListener::OnContentDownloadToBufferCompleted() method. @n
306          * When the data is being downloaded, the application is notified of the progress using the IContentTransferListener::OnContentTransferInProgress() method.
307          *
308          * @brief       <i> [Deprecated] </i>
309          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
310          * @since                       2.0
311          * @privlevel           public
312          * @privilege           %http://tizen.org/privilege/download
313          *
314          * @return                      An error code
315          * @param[in]   uri                                             The content URL
316          * @param[out]  reqId                                   The request ID
317          * @param[in]   timeout                                 The timeout period in seconds
318          * @param[in]   progressInterval        The progress period interval as a percentage value
319          * @exception   E_SUCCESS                               The method is successful.
320          * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
321          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
322          * @exception   E_INVALID_STATE         This method is invalid for the current state of this instance.
323          * @exception   E_ILLEGAL_ACCESS                Access is denied due to insufficient permission.
324          * @exception   E_IN_PROGRESS                   A previous request is in progress.
325          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
326          * @exception   E_USER_NOT_CONSENTED    The user blocks an application from calling this method. @b Since: @b 2.1
327          * @remarks
328          *                              - The @c progressInterval is the interval of the progress for each download request. If the value of the @c progressInterval is @c 0, the @c progressInterval uses the value set by the ContentTransfer::SetProgressIntervalByPercent(int). The @c progressInterval is a percentage value between @c 0 and @c 100.
329          *                              - The @c timeout is the value of the response timeout for each download request. If the value of the @c timeout is @c 0, the value for the @c timeout uses the value set by the ContentTransfer::SetDefaultTimeout(int).
330          * @see  IContentTransferListener::OnContentDownloadToBufferCompleted()
331          * @see  IContentTransferListener::OnContentTransferInProgress()
332          */
333         result DownloadToBuffer(const Tizen::Base::Utility::Uri& uri, RequestId& reqId, int timeout = 0, int progressInterval = 0);
334
335         /**
336          * Sets the default timeout period. @n
337          * If the server does not respond during the timeout period, the network connection is closed.
338          * @c 0 or minus second means unlimited period.
339          *
340          * @brief       <i> [Deprecated] </i>
341          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
342          * @since               2.0
343          *
344          * @param[in]   sec                     The default timeout period in seconds @n
345          *                          The default value is @c 0.
346          */
347         void SetDefaultTimeout(int sec);
348
349         /**
350          * Gets the default timeout period.
351          *
352          * @brief       <i> [Deprecated] </i>
353          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
354          * @since               2.0
355          *
356          * @return              The default timeout period
357          */
358         int GetDefaultTimeout(void) const;
359
360         /**
361          * Removes a transfer operation. @n
362          * This operation removes a request for multiple downloads.
363          * A download operation in progress is not removed by this operation.
364          *
365          * @brief       <i> [Deprecated] </i>
366          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
367          * @since               2.0
368          *
369          * @return              An error code
370          * @param[in]   reqId The request ID
371          * @exception   E_SUCCESS                       The method is successful.
372          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
373          * @exception   E_OBJ_NOT_FOUND The specified @c reqId is not found.
374          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
375          * @remarks     To stop an on-going transfer, use the Cancel() method.
376          */
377         result Remove(RequestId reqId);
378
379         /**
380          * Removes all the transfer operations. @n
381          * This operation removes all the requests for multiple downloads.
382          * The download operations in progress are not removed by this operation.
383          *
384          * @brief       <i> [Deprecated] </i>
385          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
386          * @since               2.0
387          *
388          * @return              An error code
389          * @exception   E_SUCCESS                       The method is successful.
390          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
391          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
392          * @remarks     To stop an on-going transfer, use the Cancel() method.
393          */
394         result RemoveAll(void);
395
396         /**
397          * Cancels a transfer operation. @n
398          * The downloaded file is deleted from the file system. @n
399          * When a transfer download operation is canceled, the application is notified via the IContentTransferListener::OnContentTransferCanceled() method.
400          *
401          * @brief       <i> [Deprecated] </i>
402          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
403          * @since               2.0
404          *
405          * @return              An error code
406          * @param[in]   reqId                   The request ID
407          * @exception   E_SUCCESS                       The method is successful.
408          * @exception   E_OBJ_NOT_FOUND         The specified @c reqId is not found.
409          * @exception   E_INVALID_ARG           The specified input parameter is invalid.
410          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
411          * @see IContentTransferListener::OnContentTransferCanceled()
412          */
413         result Cancel(RequestId reqId);
414
415         /**
416          * Cancels all the operations in progress.
417          *
418          * @brief       <i> [Deprecated] </i>
419          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
420          * @since               2.0
421          *
422          * @return              An error code
423          * @exception   E_SUCCESS                       The method is successful.
424          * @exception   E_OUT_OF_MEMORY The memory is insufficient.
425          * @exception   E_INVALID_STATE This method is invalid for the current state of this instance.
426          */
427         result CancelAll(void);
428
429         /**
430          * Gets the content transfer information list.
431          *
432          * @brief       <i> [Deprecated] </i>
433          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
434          * @since               2.0
435          *
436          * @return              A pointer to a list containing the ContentTransferInfo instances, @n
437          *                              else an empty list if there is no result and no error
438          */
439         Tizen::Base::Collection::IList* GetContentTransferInfoListN(void) const;
440
441         /**
442          * Gets the list of transfers that are in progress.
443          *
444          * @brief       <i> [Deprecated] </i>
445          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
446          * @since               2.0
447          *
448          * @return              A pointer to a list containing the ContentTransferInfo instances, @n
449          *                              else an empty list if there is no result and no error
450          */
451         Tizen::Base::Collection::IList* GetContentTransferInfoListInProgressN(void) const;
452
453         /**
454          * Sets the interval of the progress. @n
455          * The input is a percentage value between @c 0 and @c 100. The default value is @c 0.
456          * @c 0 means the application would not receive progress events.
457          *
458          * @brief       <i> [Deprecated] </i>
459          * @deprecated  This class is deprecated. Instead of using this class, use DownloadManager class.
460          * @since               2.0
461          *
462          * @param[in]   percent         The progress period interval as a percentage value
463          * @remarks     If a server does not provide the information about the content size, then the content module cannot verify the information. @n
464          *              In that case, progress event will occur randomly.
465          */
466         void SetProgressIntervalByPercent(int percent);
467
468 private:
469         /**
470          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
471          */
472         ContentTransfer(const ContentTransfer& rhs);
473
474         /**
475          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
476          */
477         ContentTransfer& operator =(const ContentTransfer& rhs);
478
479 private:
480         friend class _ContentTransferImpl;
481         _ContentTransferImpl* __pImpl;
482
483 };  // class ContentTransfer
484
485 }}  // Tizen::Content
486
487 #endif  // _FCNT_CONTENT_TRANSFER_H_