6#include <QFileSystemModel>
9#include <QRegularExpression>
44 const QModelIndex &sourceParent)
const {
45 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
60 if (sourceModel()->rowCount(index) > 0) {
61 for (
int nChild = 0; nChild < sourceModel()->rowCount(index); ++nChild) {
62 QModelIndex childIndex = sourceModel()->index(nChild, 0, index);
63 if (!childIndex.isValid())
70 QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
71 QString path = fs->filePath(useIndex);
72 path = QDir(store).relativeFilePath(path);
74 retVal = path.contains(filterRegularExpression());
86 setSourceModel(sourceModel);
88 store = std::move(passStore);
101 QVariant initial_value;
102 initial_value = QSortFilterProxyModel::data(index, role);
104 if (role == Qt::DisplayRole) {
105 QString name = initial_value.toString();
107 initial_value.setValue(name);
110 return initial_value;
118 return Qt::CopyAction | Qt::MoveAction;
126 return Qt::CopyAction | Qt::MoveAction;
135 Qt::ItemFlags defaultFlags = QSortFilterProxyModel::flags(index);
137 if (index.isValid()) {
138 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
140 return Qt::ItemIsDropEnabled | defaultFlags;
149 types <<
"application/vnd+qtpass.dragAndDropInfoPasswordStore";
161 QByteArray encodedData;
163 QModelIndex index = indexes.at(0);
164 if (index.isValid()) {
165 QModelIndex useIndex = mapToSource(index);
167 info.
isDir = fs->fileInfo(useIndex).isDir();
168 info.
isFile = fs->fileInfo(useIndex).isFile();
169 info.
path = fs->fileInfo(useIndex).absoluteFilePath();
170 QDataStream stream(&encodedData, QIODevice::WriteOnly);
175 mimeData->setData(
"application/vnd+qtpass.dragAndDropInfoPasswordStore",
191 const QModelIndex &parent)
const {
193 qDebug() << action << row;
199 QModelIndex useIndex =
200 this->index(parent.row(), parent.column(), parent.parent());
201 QByteArray encodedData =
202 data->data(
"application/vnd+qtpass.dragAndDropInfoPasswordStore");
203 QDataStream stream(&encodedData, QIODevice::ReadOnly);
206 if (!
data->hasFormat(
"application/vnd+qtpass.dragAndDropInfoPasswordStore"))
214 if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.
isDir) {
218 if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.
isFile) {
222 if (fs->fileInfo(mapToSource(useIndex)).isFile() && info.
isFile) {
239 int row,
int column,
const QModelIndex &parent) {
243 if (action == Qt::IgnoreAction) {
246 QByteArray encodedData =
247 data->data(
"application/vnd+qtpass.dragAndDropInfoPasswordStore");
249 QDataStream stream(&encodedData, QIODevice::ReadOnly);
252 QModelIndex destIndex =
253 this->index(parent.row(), parent.column(), parent.parent());
254 QFileInfo destFileinfo = fs->fileInfo(mapToSource(destIndex));
255 QFileInfo srcFileInfo = QFileInfo(info.
path);
256 QString cleanedSrc = QDir::cleanPath(srcFileInfo.absoluteFilePath());
257 QString cleanedDest = QDir::cleanPath(destFileinfo.absoluteFilePath());
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) {
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, 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);
virtual void Copy(const QString srcDir, const QString dest, const bool force=false)=0
virtual void Move(const QString srcDir, const QString dest, const bool force=false)=0
Qt::DropActions supportedDropActions() const override
StoreModel::supportedDropActions enable drop.
QStringList mimeTypes() const override
StoreModel::mimeTypes.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
StoreModel::dropMimeData.
StoreModel()
StoreModel::StoreModel SubClass of QSortFilterProxyModel via http://www.qtcentre.org/threads/46471-QT...
bool filterAcceptsRow(int, const QModelIndex &) const override
StoreModel::filterAcceptsRow should row be shown, wrapper for StoreModel::ShowThis method.
Qt::DropActions supportedDragActions() const override
StoreModel::supportedDragActions enable drag.
QMimeData * mimeData(const QModelIndexList &indexes) const override
StoreModel::mimeData.
bool ShowThis(const QModelIndex) const
StoreModel::ShowThis should a row be shown, based on our search criteria.
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
StoreModel::lessThan.
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
StoreModel::canDropMimeData.
QVariant data(const QModelIndex &index, int role) const override
StoreModel::data don't show the .gpg at the end of a file.
void setModelAndStore(QFileSystemModel *sourceModel, QString passStore)
StoreModel::setModelAndStore update the source model and store.
Qt::ItemFlags flags(const QModelIndex &index) const override
StoreModel::flags.
static const QRegularExpression & endsWithGpg()
QDataStream & operator>>(QDataStream &in, dragAndDropInfoPasswordStore &dragAndDropInfoPasswordStore)
QDataStream & operator<<(QDataStream &out, const dragAndDropInfoPasswordStore &dragAndDropInfoPasswordStore)