TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

storedtransferjob.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright (C) 2004 David Faure <faure@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef STOREDTRANSFERJOB_H
  17. #define STOREDTRANSFERJOB_H
  18. #include <tdeio/job.h>
  19. // To be moved to TDEIO?
  20. namespace TDEIOext {
  21. /**
  22. * StoredTransferJob is a TransferJob (for downloading or uploading data) that
  23. * also stores a TQByteArray with the data, making it simpler to use than the
  24. * standard TransferJob.
  25. *
  26. * For TDEIO::get it puts the data into the member TQByteArray, so the user
  27. * of this class can get hold of the whole data at once by calling data()
  28. * when the result signal is emitted.
  29. * You should only use StoredTransferJob to download data if you cannot
  30. * process the data by chunks while it's being downloaded, since storing
  31. * everything in a TQByteArray can potentially require a lot of memory.
  32. *
  33. * For TDEIO::put the user of this class simply provides the bytearray from
  34. * the start, and the job takes care of uploading it.
  35. * You should only use StoredTransferJob to upload data if you cannot
  36. * provide the in chunks while it's being uploaded, since storing
  37. * everything in a TQByteArray can potentially require a lot of memory.
  38. *
  39. */
  40. class StoredTransferJob : public TDEIO::TransferJob {
  41. Q_OBJECT
  42. public:
  43. /**
  44. * Do not create a StoredTransferJob. Use storedGet() or storedPut()
  45. * instead.
  46. * @param url the url to get or put
  47. * @param command the command to issue
  48. * @param packedArgs the arguments
  49. * @param _staticData additional data to transmit (e.g. in a HTTP Post)
  50. * @param showProgressInfo true to show progress information to the user
  51. */
  52. StoredTransferJob(const KURL& url, int command,
  53. const TQByteArray &packedArgs,
  54. const TQByteArray &_staticData,
  55. bool showProgressInfo);
  56. /**
  57. * Set data to be uploaded. This is for put jobs.
  58. * Automatically called by TDEIOext::put(const TQByteArray &, ...), do not call this yourself.
  59. */
  60. void setData( const TQByteArray& arr );
  61. /**
  62. * Get hold of the downloaded data. This is for get jobs.
  63. * You're supposed to call this only from the slot connected to the result() signal.
  64. */
  65. TQByteArray data() const { return m_data; }
  66. private slots:
  67. void slotData( TDEIO::Job *job, const TQByteArray &data );
  68. void slotDataReq( TDEIO::Job *job, TQByteArray &data );
  69. private:
  70. TQByteArray m_data;
  71. int m_uploadOffset;
  72. };
  73. /**
  74. * Get (a.k.a. read), into a single TQByteArray.
  75. * @see StoredTransferJob
  76. *
  77. * @param url the URL of the file
  78. * @param reload true to reload the file, false if it can be taken from the cache
  79. * @param showProgressInfo true to show progress information
  80. * @return the job handling the operation.
  81. */
  82. StoredTransferJob *storedGet( const KURL& url, bool reload=false, bool showProgressInfo = true );
  83. /**
  84. * Put (a.k.a. write) data from a single TQByteArray.
  85. * @see StoredTransferJob
  86. *
  87. * @param url Where to write data.
  88. * @param permissions May be -1. In this case no special permission mode is set.
  89. * @param overwrite If true, any existing file will be overwritten.
  90. * @param resume true to resume, false otherwise
  91. * @param showProgressInfo true to show progress information
  92. * @return the job handling the operation.
  93. * @see multi_get()
  94. */
  95. StoredTransferJob *put( const TQByteArray& arr, const KURL& url, int permissions,
  96. bool overwrite, bool resume, bool showProgressInfo = true );
  97. } // namespace
  98. #endif