QBtObjectExchangeClient.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * QBtObjectExchangeClient.h
  3. *
  4. *
  5. * Author: Ftylitakis Nikolaos
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. #ifndef QBTOBJECTEXCHANGECLIENT_H_
  20. #define QBTOBJECTEXCHANGECLIENT_H_
  21. #include <QBtGlobal.h>
  22. #include <QBtTypes.h>
  23. #include <QBtServiceAdvertiser.h>
  24. #include <QtCore/QObject>
  25. QBT_NAMESPACE_BEGIN
  26. //forward declaration
  27. class QBtObjectExchangeClientPrivate;
  28. /**
  29. * Class that provides the mechanism to connect to a remote
  30. * OBEX server and send or recieve files or raw data.
  31. *
  32. * After instantiation user can call connectToServer(QBtDevice&, QBtService&)
  33. * to connect to the remote server specified by the remoteDevice argument
  34. * to its service provide by remoteService argument.
  35. *
  36. * P.S. At the remote service, one of the supported protocols must be
  37. * QBtConstants::OBEX. Suggestion, use a service whose class is equal to
  38. * QBtConstants::OBEXObjectPush or QBtConstants::OBEXFileTransfer.
  39. * Again, it is suggested to use QBtConstants::OBEXObjectPush.
  40. * Both options will work fine if the user wants to send a file to
  41. * the server, but at present further operations can be done using
  42. * QBtConstants::OBEXObjectPush.
  43. *
  44. * Signal connectedToServer() is emitted upon successfull connection to the OBEX server.
  45. *
  46. * After the successfull connection to the server, user can call putFile(const QString&)
  47. * to send to the remote server the file specified by the string passed as argument.
  48. * If successfull then objectSent() signal is emitted.
  49. *
  50. * Also user is able to send a request to get a file from the remote server specifing
  51. * the absolute path of the file to be fetched at the remote device's file system.
  52. * Also a local path must be set which is where the file will be stored after the
  53. * successfull transfer.
  54. * getFile(const QString& localPath, const QString& remoteFileNameFull)
  55. * If successfull then fileReceived(const QString) is emitted.
  56. *
  57. * getByteBuffer() and putByteBuffer() are implemented but not tested.
  58. * If successfull they emit dataReceived(const QByteArray) and objectSent() respectively.
  59. *
  60. * If connected to an OBEX FTP bluetooth service then setPath() can be called
  61. * to set the remote working directory. If successfull then remotePathSet(const QString)
  62. * will be emitted.
  63. *
  64. * User can abort any transmittion in progress by calling abort().
  65. *
  66. * User can disconnect from the server at any time or the disconnection will take place at
  67. * destruction time. Any transmittion in progress will be terminated instantly.
  68. * A successfull disconnection emits disconnectedFromServer() signal.
  69. */
  70. class DLL_EXPORT QBtObjectExchangeClient : public QObject
  71. {
  72. Q_OBJECT
  73. public:
  74. enum ErrorCode{
  75. OBEXClientConnectionError,
  76. OBEXClientSendError,
  77. OBEXClientReceiveError,
  78. OBEXClientDisconnected,
  79. OBEXClientInUse,
  80. OBEXClientInternalError,
  81. OBEXClientNoSelectedDevice,
  82. OBEXClientNoSelectedService,
  83. OBEXClientUnableToSetPath,
  84. OBEXFeatureNotSupported,
  85. OBEXClientBrowseError
  86. };
  87. public:
  88. QBtObjectExchangeClient(QObject* parent);
  89. ~QBtObjectExchangeClient();
  90. /**
  91. * connectToServer()
  92. *
  93. * Connect to a remote server defined by parameter 1 to its service
  94. * defined by parameter 2.
  95. *
  96. * P.S. At the remote service, one of the supported protocols must be
  97. * QBtConstants::OBEX. Suggestion, use a service whose class is equal to
  98. * QBtConstants::OBEXObjectPush or QBtConstants::OBEXFileTransfer.
  99. * Again, it is suggested to use QBtConstants::OBEXObjectPush.
  100. * Both options will work fine if the user wants to send a file to
  101. * the server, but at present further operations can be done using
  102. * QBtConstants::OBEXObjectPush.
  103. *
  104. * @param remoteDevice
  105. * @param remoteService
  106. */
  107. void connectToServer(const QBtDevice& remoteDevice, const QBtService& remoteService);
  108. /**
  109. * getFile()
  110. * Get a file from the remote Server
  111. *
  112. * @param localPath the path where the file will be saved
  113. * @param remoteFileNameFull the name of the file to be transfered
  114. * containing the full path of its remote location
  115. */
  116. void getFile(const QString& remoteFileAbsolutePath, const QString& destinationFolder);
  117. /**
  118. * getByteBuffer(const QString& dataName)
  119. * Request from the server to GET the data buffer defined in the argument
  120. *
  121. * @param dataName The name of the buffer.
  122. */
  123. void getByteBuffer(const QString& dataName);
  124. /**
  125. * Send a specified file from the local file system to the remote
  126. * OBEX server.
  127. *
  128. * @param fileName The file name of the file to be sent. The absolute
  129. * path of the file is required.
  130. */
  131. void putFile(const QString& fileName);
  132. /**
  133. * putByteBuffer()
  134. *
  135. * send the server a byte sequence.
  136. * @param data, the data of the buffer
  137. * @param bufferName, the name of the buffer (used for convenience on the data
  138. * processing of the server)
  139. */
  140. void putByteBuffer(const QByteArray& data, const QString& bufferName);
  141. /**
  142. * abort()
  143. *
  144. * abort any panding or running transmittion.
  145. */
  146. void abort();
  147. /**
  148. * setPath(const QString path)
  149. *
  150. * Set the current path of the remote device OBEX session.
  151. * @param path The remote folder to be set as current
  152. */
  153. void setPath(const QString & path);
  154. /**
  155. * getWorkingPath
  156. *
  157. * ONLY FOR WINDOWS
  158. *
  159. * Return as QString holding the absolute path of the current working directory
  160. */
  161. QString getWorkingPath();
  162. /**
  163. * initiateFolderBrowsing()
  164. *
  165. * ONLY FOR WINDOWS
  166. *
  167. * Browse the files of a selected folder.
  168. *
  169. * @param folder The folder path must either be absolute (e.g. \E:\Images), or it must be the name of the folder
  170. * you are going to browse as long as the folder is inside the current working directory of yours.
  171. *
  172. * @return QList<QBtRemoteFileInfo*> a list of the files/folders found and their attributes
  173. */
  174. QList<QBtRemoteFileInfo*> initiateFolderBrowsing(const QString& folderPath = "");
  175. /**
  176. * locateFiles
  177. *
  178. * ONLY FOR WINDOWS
  179. *
  180. * Locate files/folders that comply to the regex passed as arguments. For example can be used to isolate
  181. * files of specific type.
  182. *
  183. * @param regex The regex that describes the files that are needed to be selected. If this parameter is not set, the default
  184. * operation is to select all the files in the specified folder.
  185. *
  186. * @param folder The folder path must either be absolute (e.g. \E:\Images), or it must be the name of the folder
  187. * you are going to browse as long as the folder is inside the current working directory of yours. If this parameter is not set,
  188. * the default operation is to search in the current working directory.
  189. */
  190. QList<QBtRemoteFileInfo*> locateFiles(QRegExp* regex=0, QString folder="");
  191. /**
  192. * batchFileRetrieval
  193. *
  194. * ONLY FOR WINDOWS
  195. *
  196. * Convenient method to retrieve multiple files in the row.
  197. *
  198. * @param files The list of files to retrieve
  199. * @param destinationFolder The folder in the local file system where the files will be stored. The files are placed all
  200. * in that directory same directory so the structure in the remote file system is not preserved.
  201. * @param retrieveOnlyNewFiles If set true, then it first check if the file defined already exists in the
  202. * destination folder. If it does then it skips it. By default it is set to copy every file it founds.
  203. */
  204. void batchFileRetrieval(const QList<QBtRemoteFileInfo*>& files,
  205. const QString destinationFolder,
  206. bool retrieveOnlyNewFiles = false);
  207. /**
  208. * Get info about the service connected to.
  209. * @return An object containing the service info
  210. */
  211. QBtService& getTransmittingService();
  212. /**
  213. * Get info about the server connected to.
  214. * @return An object containing the remote server device info.
  215. */
  216. QBtDevice& getServerDevice();
  217. /**
  218. * Checks if the client is performing some operation.
  219. */
  220. bool isBusy() const;
  221. /**
  222. * Checks if the client got a connection (it does not check *now* if the client is still connected).
  223. */
  224. bool isConnected() const;
  225. public slots:
  226. void disconnect();
  227. signals:
  228. /**
  229. * Emitted in case of error
  230. */
  231. void error(QBtObjectExchangeClient::ErrorCode code);
  232. /**
  233. * Emitted upon successfull connection to the OBEX server.
  234. */
  235. void connectedToServer();
  236. /**
  237. * Emitted upon disconnection from the server.
  238. */
  239. void disconnectedFromServer();
  240. /**
  241. * Emitted upon successfull transmittion of an object
  242. */
  243. void objectSent();
  244. /**
  245. * Emitted when a file is received from the server
  246. */
  247. void fileReceived (const QString & fileName);
  248. /**
  249. * Emitted when a byte buffer is received from the server
  250. */
  251. void dataReceived (const QByteArray & data);
  252. /**
  253. * Emitted upon successfull set of the remote current working directory.
  254. */
  255. void remotePathSet (const QString & pathName);
  256. /**
  257. * Emitted after calling initiateFolderBrowsing function for every result
  258. * found from browsing.
  259. *
  260. * @param file The file info. See QBtRemoteFileInfo class for the info provided.
  261. */
  262. void folderBrowsingResultElement(const QBtRemoteFileInfo& file);
  263. private:
  264. friend class QBtObjectExchangeClientPrivate;
  265. QBtObjectExchangeClientPrivate* _implPtr;
  266. };
  267. QBT_NAMESPACE_END
  268. //Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtObjectExchangeClient))
  269. #endif /* QBTOBJECTEXCHANGECLIENT_H_ */