mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
mod manager drag'n'drop
This commit is contained in:
parent
03e3e28b65
commit
c2570adad6
@ -34,3 +34,8 @@ QString CLauncherDirs::modsPath()
|
|||||||
{
|
{
|
||||||
return pathToQString(VCMIDirs::get().userDataPath() / "Mods");
|
return pathToQString(VCMIDirs::get().userDataPath() / "Mods");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CLauncherDirs::mapsPath()
|
||||||
|
{
|
||||||
|
return pathToQString(VCMIDirs::get().userDataPath() / "Maps");
|
||||||
|
}
|
||||||
|
@ -19,4 +19,5 @@ public:
|
|||||||
|
|
||||||
QString downloadsPath();
|
QString downloadsPath();
|
||||||
QString modsPath();
|
QString modsPath();
|
||||||
|
QString mapsPath();
|
||||||
};
|
};
|
||||||
|
@ -48,6 +48,46 @@ void CModListView::changeEvent(QEvent *event)
|
|||||||
QWidget::changeEvent(event);
|
QWidget::changeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModListView::dragEnterEvent(QDragEnterEvent* event)
|
||||||
|
{
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CModListView::dragMoveEvent(QDragMoveEvent* event)
|
||||||
|
{
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CModListView::dragLeaveEvent(QDragLeaveEvent* event)
|
||||||
|
{
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CModListView::dropEvent(QDropEvent* event)
|
||||||
|
{
|
||||||
|
const QMimeData* mimeData = event->mimeData();
|
||||||
|
|
||||||
|
if(mimeData->hasUrls())
|
||||||
|
{
|
||||||
|
QStringList pathList;
|
||||||
|
QList<QUrl> urlList = mimeData->urls();
|
||||||
|
|
||||||
|
for (int i = 0; i < urlList.size(); i++)
|
||||||
|
{
|
||||||
|
QString url = urlList.at(i).toString();
|
||||||
|
if(url.endsWith(".zip", Qt::CaseInsensitive))
|
||||||
|
downloadFile(url.split("/").last().toLower()
|
||||||
|
// mod name currently comes from zip file -> remove suffixes from github zip download
|
||||||
|
.replace(QRegularExpression("-[0-9a-f]{40}"), "")
|
||||||
|
.replace(QRegularExpression("-vcmi-.*\\.zip"), ".zip")
|
||||||
|
.replace(QRegularExpression("-main.zip"), ".zip")
|
||||||
|
, url, "mods", 0);
|
||||||
|
else
|
||||||
|
downloadFile(url.split("/").last(), url, "mods", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CModListView::setupFilterModel()
|
void CModListView::setupFilterModel()
|
||||||
{
|
{
|
||||||
filterModel = new CModFilterModel(modModel, this);
|
filterModel = new CModFilterModel(modModel, this);
|
||||||
@ -100,6 +140,8 @@ CModListView::CModListView(QWidget * parent)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
setAcceptDrops(true);
|
||||||
|
|
||||||
setupModModel();
|
setupModModel();
|
||||||
setupFilterModel();
|
setupFilterModel();
|
||||||
setupModsView();
|
setupModsView();
|
||||||
@ -677,6 +719,7 @@ void CModListView::hideProgressBar()
|
|||||||
void CModListView::installFiles(QStringList files)
|
void CModListView::installFiles(QStringList files)
|
||||||
{
|
{
|
||||||
QStringList mods;
|
QStringList mods;
|
||||||
|
QStringList maps;
|
||||||
QStringList images;
|
QStringList images;
|
||||||
QVector<QVariantMap> repositories;
|
QVector<QVariantMap> repositories;
|
||||||
|
|
||||||
@ -685,6 +728,8 @@ void CModListView::installFiles(QStringList files)
|
|||||||
{
|
{
|
||||||
if(filename.endsWith(".zip"))
|
if(filename.endsWith(".zip"))
|
||||||
mods.push_back(filename);
|
mods.push_back(filename);
|
||||||
|
if(filename.endsWith(".h3m") || filename.endsWith(".h3c") || filename.endsWith(".vmap") || filename.endsWith(".vcmp"))
|
||||||
|
maps.push_back(filename);
|
||||||
if(filename.endsWith(".json"))
|
if(filename.endsWith(".json"))
|
||||||
{
|
{
|
||||||
//download and merge additional files
|
//download and merge additional files
|
||||||
@ -718,6 +763,9 @@ void CModListView::installFiles(QStringList files)
|
|||||||
if(!mods.empty())
|
if(!mods.empty())
|
||||||
installMods(mods);
|
installMods(mods);
|
||||||
|
|
||||||
|
if(!maps.empty())
|
||||||
|
installMaps(maps);
|
||||||
|
|
||||||
if(!images.empty())
|
if(!images.empty())
|
||||||
loadScreenshots();
|
loadScreenshots();
|
||||||
}
|
}
|
||||||
@ -794,6 +842,16 @@ void CModListView::installMods(QStringList archives)
|
|||||||
QFile::remove(archive);
|
QFile::remove(archive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModListView::installMaps(QStringList archives)
|
||||||
|
{
|
||||||
|
QString destDir = CLauncherDirs::get().mapsPath() + "/";
|
||||||
|
|
||||||
|
for(QString archive : archives)
|
||||||
|
{
|
||||||
|
QFile(archive).rename(destDir + archive.section('/', -1, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CModListView::on_refreshButton_clicked()
|
void CModListView::on_refreshButton_clicked()
|
||||||
{
|
{
|
||||||
loadRepositories();
|
loadRepositories();
|
||||||
|
@ -54,12 +54,17 @@ class CModListView : public QWidget
|
|||||||
void downloadFile(QString file, QString url, QString description, qint64 size = 0);
|
void downloadFile(QString file, QString url, QString description, qint64 size = 0);
|
||||||
|
|
||||||
void installMods(QStringList archives);
|
void installMods(QStringList archives);
|
||||||
|
void installMaps(QStringList archives);
|
||||||
void installFiles(QStringList mods);
|
void installFiles(QStringList mods);
|
||||||
|
|
||||||
QString genChangelogText(CModEntry & mod);
|
QString genChangelogText(CModEntry & mod);
|
||||||
QString genModInfoText(CModEntry & mod);
|
QString genModInfoText(CModEntry & mod);
|
||||||
|
|
||||||
void changeEvent(QEvent *event) override;
|
void changeEvent(QEvent *event) override;
|
||||||
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
|
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||||
|
void dragLeaveEvent(QDragLeaveEvent* event) override;
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
signals:
|
signals:
|
||||||
void modsChanged();
|
void modsChanged();
|
||||||
|
|
||||||
|
@ -161,9 +161,6 @@ bool CModManager::canInstallMod(QString modname)
|
|||||||
|
|
||||||
if(mod.isInstalled())
|
if(mod.isInstalled())
|
||||||
return addError(modname, "Mod is already installed");
|
return addError(modname, "Mod is already installed");
|
||||||
|
|
||||||
if(!mod.isAvailable())
|
|
||||||
return addError(modname, "Mod is not available");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user