1
0
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:
Laserlicht 2023-12-25 18:53:02 +01:00 committed by GitHub
parent 03e3e28b65
commit c2570adad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 3 deletions

View File

@ -34,3 +34,8 @@ QString CLauncherDirs::modsPath()
{
return pathToQString(VCMIDirs::get().userDataPath() / "Mods");
}
QString CLauncherDirs::mapsPath()
{
return pathToQString(VCMIDirs::get().userDataPath() / "Maps");
}

View File

@ -19,4 +19,5 @@ public:
QString downloadsPath();
QString modsPath();
QString mapsPath();
};

View File

@ -48,6 +48,46 @@ void CModListView::changeEvent(QEvent *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()
{
filterModel = new CModFilterModel(modModel, this);
@ -100,6 +140,8 @@ CModListView::CModListView(QWidget * parent)
{
ui->setupUi(this);
setAcceptDrops(true);
setupModModel();
setupFilterModel();
setupModsView();
@ -677,6 +719,7 @@ void CModListView::hideProgressBar()
void CModListView::installFiles(QStringList files)
{
QStringList mods;
QStringList maps;
QStringList images;
QVector<QVariantMap> repositories;
@ -685,6 +728,8 @@ void CModListView::installFiles(QStringList files)
{
if(filename.endsWith(".zip"))
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"))
{
//download and merge additional files
@ -718,6 +763,9 @@ void CModListView::installFiles(QStringList files)
if(!mods.empty())
installMods(mods);
if(!maps.empty())
installMaps(maps);
if(!images.empty())
loadScreenshots();
}
@ -794,6 +842,16 @@ void CModListView::installMods(QStringList archives)
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()
{
loadRepositories();

View File

@ -54,12 +54,17 @@ class CModListView : public QWidget
void downloadFile(QString file, QString url, QString description, qint64 size = 0);
void installMods(QStringList archives);
void installMaps(QStringList archives);
void installFiles(QStringList mods);
QString genChangelogText(CModEntry & mod);
QString genModInfoText(CModEntry & mod);
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:
void modsChanged();

View File

@ -161,9 +161,6 @@ bool CModManager::canInstallMod(QString modname)
if(mod.isInstalled())
return addError(modname, "Mod is already installed");
if(!mod.isAvailable())
return addError(modname, "Mod is not available");
return true;
}