summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-05-15 23:21:33 +0200
committerPetr Mrázek <peterix@gmail.com>2016-05-15 23:27:06 +0200
commit4440f68e59fa5535e6fb3b6d49fa578beecc091f (patch)
treecb7494e338702b260d5e5d152f5ab7b886afff12 /api/logic
parent67b22c8105f872582279274593bed431b3dd6510 (diff)
downloadMultiMC-4440f68e59fa5535e6fb3b6d49fa578beecc091f.tar
MultiMC-4440f68e59fa5535e6fb3b6d49fa578beecc091f.tar.gz
MultiMC-4440f68e59fa5535e6fb3b6d49fa578beecc091f.tar.lz
MultiMC-4440f68e59fa5535e6fb3b6d49fa578beecc091f.tar.xz
MultiMC-4440f68e59fa5535e6fb3b6d49fa578beecc091f.zip
GH-575 Add back file drop support to ModList
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/minecraft/ModList.cpp70
-rw-r--r--api/logic/minecraft/ModList.h17
2 files changed, 77 insertions, 10 deletions
diff --git a/api/logic/minecraft/ModList.cpp b/api/logic/minecraft/ModList.cpp
index ca606de3..36371ee3 100644
--- a/api/logic/minecraft/ModList.cpp
+++ b/api/logic/minecraft/ModList.cpp
@@ -303,7 +303,73 @@ Qt::ItemFlags ModList::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
if (index.isValid())
- return Qt::ItemIsUserCheckable | defaultFlags;
+ return Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled |
+ defaultFlags;
else
- return defaultFlags;
+ return Qt::ItemIsDropEnabled | defaultFlags;
+}
+
+Qt::DropActions ModList::supportedDropActions() const
+{
+ // copy from outside, move from within and other mod lists
+ return Qt::CopyAction | Qt::MoveAction;
+}
+
+QStringList ModList::mimeTypes() const
+{
+ QStringList types;
+ types << "text/uri-list";
+ return types;
+}
+
+bool ModList::dropMimeData(const QMimeData* data, Qt::DropAction action, int, int, const QModelIndex&)
+{
+ if (action == Qt::IgnoreAction)
+ {
+ return true;
+ }
+
+ // check if the action is supported
+ if (!data || !(action & supportedDropActions()))
+ {
+ return false;
+ }
+
+ // files dropped from outside?
+ if (data->hasUrls())
+ {
+ bool was_watching = is_watching;
+ bool added = false;
+ if (was_watching)
+ {
+ stopWatching();
+ }
+ auto urls = data->urls();
+ for (auto url : urls)
+ {
+ // only local files may be dropped...
+ if (!url.isLocalFile())
+ {
+ continue;
+ }
+ // TODO: implement not only copy, but also move
+ if (installMod(url.toLocalFile()))
+ {
+ added = true;
+ }
+ }
+ if(added)
+ {
+ // re-sort the list
+ beginResetModel();
+ internalSort(mods);
+ endResetModel();
+ }
+ if (was_watching)
+ {
+ startWatching();
+ }
+ return true;
+ }
+ return false;
}
diff --git a/api/logic/minecraft/ModList.h b/api/logic/minecraft/ModList.h
index 5e7740bd..1a42c8f8 100644
--- a/api/logic/minecraft/ModList.h
+++ b/api/logic/minecraft/ModList.h
@@ -44,21 +44,22 @@ public:
};
ModList(const QString &dir);
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- virtual bool setData(const QModelIndex &index, const QVariant &value,
- int role = Qt::EditRole);
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
+ Qt::DropActions supportedDropActions() const override;
/// flags, mostly to support drag&drop
- virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
+ QStringList mimeTypes() const override;
+ bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) override;
- virtual int rowCount(const QModelIndex &) const
+ virtual int rowCount(const QModelIndex &) const override
{
return size();
}
;
- virtual QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
- virtual int columnCount(const QModelIndex &parent) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
+ virtual int columnCount(const QModelIndex &parent) const override;
size_t size() const
{