8#include <QFileSystemModel>
11#include <QRegularExpression>
47 const QModelIndex &sourceParent)
const
49 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
65 if (sourceModel()->rowCount(index) > 0) {
66 for (
int nChild = 0; nChild < sourceModel()->rowCount(index); ++nChild) {
67 QModelIndex childIndex = sourceModel()->index(nChild, 0, index);
68 if (!childIndex.isValid()) {
77 QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
78 QString path = fs->filePath(useIndex);
79 path = QDir(store).relativeFilePath(path);
80 if (path.startsWith(
".git")) {
84 retVal = path.contains(filterRegularExpression());
96 setSourceModel(sourceModel);
98 store = std::move(passStore);
108 if (!index.isValid()) {
112 QVariant initial_value;
113 initial_value = QSortFilterProxyModel::data(index, role);
115 if (role == Qt::DisplayRole) {
116 QString name = initial_value.toString();
118 initial_value.setValue(name);
121 return initial_value;
129 return Qt::CopyAction | Qt::MoveAction;
137 return Qt::CopyAction | Qt::MoveAction;
146 Qt::ItemFlags defaultFlags = QSortFilterProxyModel::flags(index);
148 if (index.isValid()) {
149 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
151 return Qt::ItemIsDropEnabled | defaultFlags;
160 types <<
"application/vnd+qtpass.dragAndDropInfoPasswordStore";
172 QByteArray encodedData;
174 QModelIndex index = indexes.at(0);
175 if (index.isValid()) {
176 QModelIndex useIndex = mapToSource(index);
178 info.
isDir = fs->fileInfo(useIndex).isDir();
179 info.
isFile = fs->fileInfo(useIndex).isFile();
180 info.
path = fs->fileInfo(useIndex).absoluteFilePath();
181 QDataStream stream(&encodedData, QIODevice::WriteOnly);
186 mimeData->setData(
"application/vnd+qtpass.dragAndDropInfoPasswordStore",
202 const QModelIndex &parent)
const ->
bool {
204 qDebug() << action << row;
210 QModelIndex useIndex =
211 this->index(parent.row(), parent.column(), parent.parent());
212 QByteArray encodedData =
213 data->data(
"application/vnd+qtpass.dragAndDropInfoPasswordStore");
214 QDataStream stream(&encodedData, QIODevice::ReadOnly);
217 if (!
data->hasFormat(
"application/vnd+qtpass.dragAndDropInfoPasswordStore")) {
226 if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.
isDir) {
230 if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.
isFile) {
234 if (fs->fileInfo(mapToSource(useIndex)).isFile() && info.
isFile) {
251 int row,
int column,
const QModelIndex &parent)
257 if (action == Qt::IgnoreAction) {
260 QByteArray encodedData =
261 data->data(
"application/vnd+qtpass.dragAndDropInfoPasswordStore");
263 QDataStream stream(&encodedData, QIODevice::ReadOnly);
266 QModelIndex destIndex =
267 this->index(parent.row(), parent.column(), parent.parent());
268 QFileInfo destFileinfo = fs->fileInfo(mapToSource(destIndex));
269 QFileInfo srcFileInfo = QFileInfo(info.
path);
270 QString cleanedSrc = QDir::cleanPath(srcFileInfo.absoluteFilePath());
271 QString cleanedDest = QDir::cleanPath(destFileinfo.absoluteFilePath());
274 if (destFileinfo.isDir()) {
275 QDir destDir = QDir(cleanedDest).filePath(srcFileInfo.fileName());
276 QString cleanedDestDir = QDir::cleanPath(destDir.absolutePath());
277 if (action == Qt::MoveAction) {
279 }
else if (action == Qt::CopyAction) {
285 if (destFileinfo.isDir()) {
286 if (action == Qt::MoveAction) {
288 }
else if (action == Qt::CopyAction) {
291 }
else if (destFileinfo.isFile()) {
293 int answer = QMessageBox::question(
294 nullptr, tr(
"force overwrite?"),
295 tr(
"overwrite %1 with %2?").arg(cleanedDest, cleanedSrc),
296 QMessageBox::Yes | QMessageBox::No);
297 bool force = answer == QMessageBox::Yes;
298 if (action == Qt::MoveAction) {
300 }
else if (action == Qt::CopyAction) {
315 const QModelIndex &source_right)
const ->
bool {
318 if (fs && (source_left.column() == 0 || source_left.column() == 1)) {
319 bool leftD = fs->isDir(source_left);
320 bool rightD = fs->isDir(source_right);
322 if (leftD ^ rightD) {
328 return QSortFilterProxyModel::lessThan(source_left, source_right);
static auto getPass() -> Pass *
Get currently active pass backend instance.
auto data(const QModelIndex &index, int role) const -> QVariant override
Get display data for index.
StoreModel()
Construct a StoreModel.
auto mimeTypes() const -> QStringList override
Get supported MIME types for drag/drop.
auto filterAcceptsRow(int, const QModelIndex &) const -> bool override
Filter whether a row should be displayed.
auto dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) -> bool override
Handle dropped MIME data.
auto mimeData(const QModelIndexList &indexes) const -> QMimeData *override
Create MIME data from indexes.
auto supportedDragActions() const -> Qt::DropActions override
Get supported drag actions.
auto showThis(const QModelIndex) const -> bool
Check if a specific index should be shown.
auto flags(const QModelIndex &index) const -> Qt::ItemFlags override
Get item flags for index.
auto canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const -> bool override
Check if drop is possible.
auto lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const -> bool override
Compare two indices for sorting.
void setModelAndStore(QFileSystemModel *sourceModel, QString passStore)
Initialize model with source model and store path.
auto supportedDropActions() const -> Qt::DropActions override
Get supported drop actions.
static auto endsWithGpg() -> const QRegularExpression &
Returns a regex to match .gpg file extensions.
auto operator>>(QDataStream &in, dragAndDropInfoPasswordStore &dragAndDropInfoPasswordStore) -> QDataStream &
auto operator<<(QDataStream &out, const dragAndDropInfoPasswordStore &dragAndDropInfoPasswordStore) -> QDataStream &
Holds information for drag and drop operations in the password store.