1 /****************************************************************************** 2 3 This source file is part of the MoleQueue project. 4 5 Copyright 2012 Kitware, Inc. 6 7 This source code is released under the New BSD License, (the "License"). 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 15 ******************************************************************************/ 16 17 #ifndef UITDIRDOWNLOADER_H_ 18 #define UITDIRDOWNLOADER_H_ 19 20 #include "filesystemoperation.h" 21 22 #include <QtCore/QObject> 23 #include <QtNetwork/QNetworkReply> 24 #include <QtCore/QQueue> 25 #include <QtCore/QFileInfo> 26 27 namespace MoleQueue { 28 namespace Uit { 29 30 class Session; 31 32 /** 33 * @brief File system operation to download a directory from a remote UIT system. 34 */ 35 class DirectoryDownload : public FileSystemOperation 36 { 37 Q_OBJECT 38 public: 39 /** 40 * @param session The UIT session. 41 * @param parentObject The parent object. 42 */ 43 DirectoryDownload(Session *session, QObject *parentObject); 44 45 /** 46 * @return The remote path being downloaded. 47 */ remotePath()48 QString remotePath() const 49 { 50 return m_remotePath; 51 } 52 53 /** 54 * @param path The remote path to be downloaded. 55 */ setRemotePath(const QString & path)56 void setRemotePath(const QString& path) 57 { 58 m_remotePath = path; 59 } 60 61 /** 62 * @return The local path to download the directory to. 63 */ localPath()64 QString localPath() const 65 { 66 return m_localPath; 67 } 68 69 /** 70 * @param path The local path to download the directory to. 71 */ setLocalPath(const QString & path)72 void setLocalPath(const QString& path) 73 { 74 m_localPath = path; 75 } 76 77 /** 78 * @return The download URL. 79 */ url()80 QString url() const 81 { 82 return m_url; 83 } 84 85 /** 86 * @param The download URL to use. 87 */ setUrl(const QString & u)88 void setUrl(const QString& u) 89 { 90 m_url = u; 91 } 92 93 void start(); 94 95 private slots: 96 void download(const QString &dir); 97 void downloadInternal(); 98 void downloadNext(); 99 /** 100 * Slot to process a directory listing. 101 */ 102 void processDirectoryListing(); 103 /** 104 * Slot called when the current download request is complete. 105 * 106 * @param reply The reply used to read the file contents. 107 */ 108 void finished(QNetworkReply *reply); 109 110 private: 111 QString m_remotePath; 112 QString m_localPath; 113 QNetworkAccessManager *m_networkAccess; 114 QString m_url; 115 // Queue of directories to download. 116 QQueue<QString> m_directories; 117 // Queue of files to download. 118 QQueue<QString> m_files; 119 // The current local file path to write data to. 120 QString m_currentFilePath; 121 }; 122 123 } /* namespace Uit */ 124 } /* namespace MoleQueue */ 125 #endif /* UITDIRDOWNLOADER_H_ */ 126