* @brief Copies a directory and it's contents from src to dest */
| 103 | * @brief Copies a directory and it's contents from src to dest |
| 104 | */ |
| 105 | class copy : public QObject { |
| 106 | Q_OBJECT |
| 107 | public: |
| 108 | copy(const QString& src, const QString& dst, QObject* parent = nullptr) : QObject(parent) |
| 109 | { |
| 110 | m_src.setPath(src); |
| 111 | m_dst.setPath(dst); |
| 112 | } |
| 113 | copy& followSymlinks(const bool follow) |
| 114 | { |
| 115 | m_followSymlinks = follow; |
| 116 | return *this; |
| 117 | } |
| 118 | copy& matcher(const IPathMatcher* filter) |
| 119 | { |
| 120 | m_matcher = filter; |
| 121 | return *this; |
| 122 | } |
| 123 | copy& whitelist(bool whitelist) |
| 124 | { |
| 125 | m_whitelist = whitelist; |
| 126 | return *this; |
| 127 | } |
| 128 | copy& overwrite(const bool overwrite) |
| 129 | { |
| 130 | m_overwrite = overwrite; |
| 131 | return *this; |
| 132 | } |
| 133 | |
| 134 | bool operator()(bool dryRun = false) { return operator()(QString(), dryRun); } |
| 135 | |
| 136 | qsizetype totalCopied() { return m_copied; } |
| 137 | qsizetype totalFailed() { return m_failedPaths.length(); } |
| 138 | QStringList failed() { return m_failedPaths; } |
| 139 | |
| 140 | signals: |
| 141 | void fileCopied(const QString& relativeName); |
| 142 | void copyFailed(const QString& relativeName); |
| 143 | // TODO: maybe add a "shouldCopy" signal in the future? |
| 144 | |
| 145 | private: |
| 146 | bool operator()(const QString& offset, bool dryRun = false); |
| 147 | |
| 148 | private: |
| 149 | bool m_followSymlinks = true; |
| 150 | const IPathMatcher* m_matcher = nullptr; |
| 151 | bool m_whitelist = false; |
| 152 | bool m_overwrite = false; |
| 153 | QDir m_src; |
| 154 | QDir m_dst; |
| 155 | qsizetype m_copied; |
| 156 | QStringList m_failedPaths; |
| 157 | }; |
| 158 | |
| 159 | struct LinkPair { |
| 160 | QString src; |
no test coverage detected