diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index ac1e8df5..49defa07 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -136,3 +136,41 @@ void Util::qSleep(int ms) { nanosleep(&ts, NULL); #endif } + +/** + * @brief Util::getDir get selectd folder path + * @param index + * @param forPass short or full path + * @param model the filesystem model to operate on + * @param storeModel our storemodel to operate on + * @return path + */ +QString Util::getDir(const QModelIndex &index, bool forPass, const QFileSystemModel &model, const StoreModel &storeModel) { + QString abspath = QDir(QtPassSettings::getPassStore()).absolutePath() + '/'; + if (!index.isValid()) + return forPass ? "" : abspath; + QFileInfo info = model.fileInfo(storeModel.mapToSource(index)); + QString filePath = + (info.isFile() ? info.absolutePath() : info.absoluteFilePath()); + if (forPass) { + filePath = QDir(abspath).relativeFilePath(filePath); + } + filePath += '/'; + return filePath; +} + +void Util::copyDir(const QString src, const QString dest) +{ + QDir srcDir(src); + if (srcDir.exists() == false){ + return; + } + srcDir.mkpath(dest); + foreach (QString dir, srcDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { + copyDir(src + QDir::separator() + dir, dest + QDir::separator() + dir); + } + + foreach (QString file, srcDir.entryList(QDir::Files)) { + QFile::copy(src + QDir::separator() + file, dest + QDir::separator() + file); + } +} |