5 #include <QRegularExpression>
42 const QModelIndex &sourceParent)
const {
43 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
58 if (sourceModel()->rowCount(index) > 0) {
59 for (
int nChild = 0; nChild < sourceModel()->rowCount(index); ++nChild) {
60 QModelIndex childIndex = sourceModel()->index(nChild, 0, index);
61 if (!childIndex.isValid())
68 QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
69 QString path = fs->filePath(useIndex);
70 path = QDir(store).relativeFilePath(path);
71 path.replace(QRegularExpression(
"\\.gpg$"),
"");
72 retVal = path.contains(filterRegularExpression());
84 setSourceModel(sourceModel);
86 store = std::move(passStore);
99 QVariant initial_value;
100 initial_value = QSortFilterProxyModel::data(index, role);
102 if (role == Qt::DisplayRole) {
103 QString name = initial_value.toString();
104 name.replace(QRegularExpression(
"\\.gpg$"),
"");
105 initial_value.setValue(name);
108 return initial_value;
116 return Qt::CopyAction | Qt::MoveAction;
124 return Qt::CopyAction | Qt::MoveAction;
133 Qt::ItemFlags defaultFlags = QSortFilterProxyModel::flags(index);
135 if (index.isValid()) {
136 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
138 return Qt::ItemIsDropEnabled | defaultFlags;
147 types <<
"application/vnd+qtpass.dragAndDropInfoPasswordStore";
159 QByteArray encodedData;
161 QModelIndex index = indexes.at(0);
162 if (index.isValid()) {
163 QModelIndex useIndex = mapToSource(index);
165 info.
isDir = fs->fileInfo(useIndex).isDir();
166 info.
isFile = fs->fileInfo(useIndex).isFile();
167 info.
path = fs->fileInfo(useIndex).absoluteFilePath();
168 QDataStream stream(&encodedData, QIODevice::WriteOnly);
173 mimeData->setData(
"application/vnd+qtpass.dragAndDropInfoPasswordStore",
189 const QModelIndex &parent)
const {
191 qDebug() << action << row;
197 QModelIndex useIndex =
198 this->index(parent.row(), parent.column(), parent.parent());
199 QByteArray encodedData =
200 data->data(
"application/vnd+qtpass.dragAndDropInfoPasswordStore");
201 QDataStream stream(&encodedData, QIODevice::ReadOnly);
204 if (!
data->hasFormat(
"application/vnd+qtpass.dragAndDropInfoPasswordStore"))
212 if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.isDir) {
216 if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.isFile) {
220 if (fs->fileInfo(mapToSource(useIndex)).isFile() && info.isFile) {
237 int row,
int column,
const QModelIndex &parent) {
241 if (action == Qt::IgnoreAction) {
244 QByteArray encodedData =
245 data->data(
"application/vnd+qtpass.dragAndDropInfoPasswordStore");
247 QDataStream stream(&encodedData, QIODevice::ReadOnly);
250 QModelIndex destIndex =
251 this->index(parent.row(), parent.column(), parent.parent());
252 QFileInfo destFileinfo = fs->fileInfo(mapToSource(destIndex));
253 QFileInfo srcFileInfo = QFileInfo(info.path);
255 QString cleanedSrc = QDir::cleanPath(srcFileInfo.absoluteFilePath());
256 QString cleanedDest = QDir::cleanPath(destFileinfo.absoluteFilePath());
258 QDir srcDir = QDir(info.path);
260 if (destFileinfo.isDir()) {
261 QDir destDir = QDir(cleanedDest).filePath(srcFileInfo.fileName());
262 QString cleanedDestDir = QDir::cleanPath(destDir.absolutePath());
263 if (action == Qt::MoveAction) {
265 }
else if (action == Qt::CopyAction) {
269 }
else if (info.isFile) {
271 if (destFileinfo.isDir()) {
272 if (action == Qt::MoveAction) {
274 }
else if (action == Qt::CopyAction) {
277 }
else if (destFileinfo.isFile()) {
279 int answer = QMessageBox::question(
280 nullptr, tr(
"force overwrite?"),
281 tr(
"overwrite %1 with %2?").arg(cleanedDest).arg(cleanedSrc),
282 QMessageBox::Yes | QMessageBox::No);
283 bool force = answer == QMessageBox::Yes;
284 if (action == Qt::MoveAction) {
286 }
else if (action == Qt::CopyAction) {
301 const QModelIndex &source_right)
const {
304 if (fs && (source_left.column() == 0 || source_left.column() == 1)) {
305 bool leftD = fs->isDir(source_left);
306 bool rightD = fs->isDir(source_right);
313 return QSortFilterProxyModel::lessThan(source_left, source_right);