summaryrefslogtreecommitdiffstats
path: root/logic/minecraft/WorldList.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-09-13 04:21:26 +0200
committerPetr Mrázek <peterix@gmail.com>2015-09-13 04:21:26 +0200
commit8ef07ec6346a4f9c078184c9497e7c12f5b8c33d (patch)
treeddb81e3591825bd1cd5e080e1fcc4aede553d911 /logic/minecraft/WorldList.cpp
parent2315f463a8e7713fc62027bb9540a22b240a0f78 (diff)
downloadMultiMC-8ef07ec6346a4f9c078184c9497e7c12f5b8c33d.tar
MultiMC-8ef07ec6346a4f9c078184c9497e7c12f5b8c33d.tar.gz
MultiMC-8ef07ec6346a4f9c078184c9497e7c12f5b8c33d.tar.lz
MultiMC-8ef07ec6346a4f9c078184c9497e7c12f5b8c33d.tar.xz
MultiMC-8ef07ec6346a4f9c078184c9497e7c12f5b8c33d.zip
GH-1227 allow structured world zip import and drag and drop out of MultiMC
Diffstat (limited to 'logic/minecraft/WorldList.cpp')
-rw-r--r--logic/minecraft/WorldList.cpp85
1 files changed, 52 insertions, 33 deletions
diff --git a/logic/minecraft/WorldList.cpp b/logic/minecraft/WorldList.cpp
index 1c25f3b1..e58ca064 100644
--- a/logic/minecraft/WorldList.cpp
+++ b/logic/minecraft/WorldList.cpp
@@ -219,25 +219,64 @@ QVariant WorldList::headerData(int section, Qt::Orientation orientation, int rol
QStringList WorldList::mimeTypes() const
{
QStringList types;
- types << "text/plain";
types << "text/uri-list";
return types;
}
-QMimeData *WorldList::mimeData(const QModelIndexList &indexes) const
+class WorldMimeData : public QMimeData
{
- QMimeData *data = new QMimeData();
+Q_OBJECT
- if (indexes.size() == 0)
- return data;
+public:
+ WorldMimeData(QList<World> worlds)
+ {
+ m_worlds = worlds;
- auto idx = indexes[0];
- int row = idx.row();
- if (row < 0 || row >= worlds.size())
- return data;
+ }
+ QStringList formats() const
+ {
+ return QMimeData::formats() << "text/uri-list";
+ }
+
+protected:
+ QVariant retrieveData(const QString &mimetype, QVariant::Type type) const
+ {
+ QList<QUrl> urls;
+ for(auto &world: m_worlds)
+ {
+ if(!world.isValid() || !world.isOnFS())
+ continue;
+ QString worldPath = world.container().absoluteFilePath();
+ qDebug() << worldPath;
+ urls.append(QUrl::fromLocalFile(worldPath));
+ }
+ const_cast<WorldMimeData*>(this)->setUrls(urls);
+ return QMimeData::retrieveData(mimetype, type);
+ }
+private:
+ QList<World> m_worlds;
+};
+
+QMimeData *WorldList::mimeData(const QModelIndexList &indexes) const
+{
+ if (indexes.size() == 0)
+ return new QMimeData();
- data->setText(QString::number(row));
- return data;
+ QList<World> worlds;
+ for(auto idx : indexes)
+ {
+ if(idx.column() != 0)
+ continue;
+ int row = idx.row();
+ if (row < 0 || row >= this->worlds.size())
+ continue;
+ worlds.append(this->worlds[row]);
+ }
+ if(!worlds.size())
+ {
+ return new QMimeData();
+ }
+ return new WorldMimeData(worlds);
}
Qt::ItemFlags WorldList::flags(const QModelIndex &index) const
@@ -302,27 +341,7 @@ bool WorldList::dropMimeData(const QMimeData *data, Qt::DropAction action, int r
startWatching();
return true;
}
- /*
- else if (data->hasText())
- {
- QString sourcestr = data->text();
- auto list = sourcestr.split('|');
- if (list.size() != 2)
- return false;
- QString remoteId = list[0];
- int remoteIndex = list[1].toInt();
- qDebug() << "move: " << sourcestr;
- // no moving of things between two lists
- if (remoteId != m_list_id)
- return false;
- // no point moving to the same place...
- if (row == remoteIndex)
- return false;
- // otherwise, move the mod :D
- moveModTo(remoteIndex, row);
- return true;
- }
- */
return false;
-
}
+
+#include "WorldList.moc"