1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-21 17:17:06 +02:00

[launcher][iOS] reveal game directories in Files app

This commit is contained in:
Andrey Filipenkov 2024-06-13 03:53:43 +03:00
parent 6d251de00d
commit b76bc4c0f8
5 changed files with 66 additions and 10 deletions

View File

@ -26,6 +26,8 @@ set(launcher_SRCS
if(APPLE_IOS)
list(APPEND launcher_SRCS
ios/launchGame.m
ios/revealdirectoryinfiles.h
ios/revealdirectoryinfiles.mm
ios/selectdirectory.h
ios/selectdirectory.mm
)

View File

@ -16,6 +16,24 @@
#include "../../lib/GameConstants.h"
#include "../../lib/VCMIDirs.h"
#ifdef VCMI_IOS
#include "ios/revealdirectoryinfiles.h"
#endif
namespace
{
void revealDirectoryInFileBrowser(QLineEdit * dirLineEdit)
{
const auto dirUrl = QUrl::fromLocalFile(QFileInfo{dirLineEdit->text()}.absoluteFilePath());
#ifdef VCMI_IOS
iOS_utils::revealDirectoryInFiles(dirUrl);
#else
QDesktopServices::openUrl(dirUrl);
#endif
}
}
void AboutProjectView::hideAndStretchWidget(QGridLayout * layout, QWidget * toHide, QWidget * toStretch)
{
toHide->hide();
@ -47,10 +65,12 @@ AboutProjectView::AboutProjectView(QWidget * parent)
// On mobile platforms these directories are generally not accessible from phone itself, only via USB connection from PC
// Remove "Open" buttons and stretch line with text into now-empty space
hideAndStretchWidget(ui->gridLayout, ui->openGameDataDir, ui->lineEditGameDir);
#ifdef VCMI_ANDROID
hideAndStretchWidget(ui->gridLayout, ui->openUserDataDir, ui->lineEditUserDataDir);
hideAndStretchWidget(ui->gridLayout, ui->openTempDir, ui->lineEditTempDir);
hideAndStretchWidget(ui->gridLayout, ui->openConfigDir, ui->lineEditConfigDir);
#endif
#endif
}
void AboutProjectView::changeEvent(QEvent *event)
@ -68,22 +88,22 @@ void AboutProjectView::on_updatesButton_clicked()
void AboutProjectView::on_openGameDataDir_clicked()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditGameDir->text()).absoluteFilePath()));
revealDirectoryInFileBrowser(ui->lineEditGameDir);
}
void AboutProjectView::on_openUserDataDir_clicked()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditUserDataDir->text()).absoluteFilePath()));
revealDirectoryInFileBrowser(ui->lineEditUserDataDir);
}
void AboutProjectView::on_openTempDir_clicked()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditTempDir->text()).absoluteFilePath()));
revealDirectoryInFileBrowser(ui->lineEditTempDir);
}
void AboutProjectView::on_openConfigDir_clicked()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditConfigDir->text()).absoluteFilePath()));
revealDirectoryInFileBrowser(ui->lineEditConfigDir);
}
void AboutProjectView::on_pushButtonDiscord_clicked()
@ -106,7 +126,6 @@ void AboutProjectView::on_pushButtonHomepage_clicked()
QDesktopServices::openUrl(QUrl("https://vcmi.eu/"));
}
void AboutProjectView::on_pushButtonBugreport_clicked()
{
QDesktopServices::openUrl(QUrl("https://github.com/vcmi/vcmi/issues"));

View File

@ -25,14 +25,11 @@ class AboutProjectView : public QWidget
/// Hides a widget and expands second widgets to take place of first widget in layout
void hideAndStretchWidget(QGridLayout * layout, QWidget * toHide, QWidget * toStretch);
public:
explicit AboutProjectView(QWidget * parent = nullptr);
public slots:
private slots:
void on_updatesButton_clicked();
void on_openGameDataDir_clicked();
@ -55,5 +52,4 @@ private slots:
private:
Ui::AboutProjectView * ui;
};

View File

@ -0,0 +1,17 @@
/*
* revealdirectoryinfiles.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include <QUrl>
namespace iOS_utils
{
void revealDirectoryInFiles(QUrl dirUrl);
}

View File

@ -0,0 +1,22 @@
/*
* revealdirectoryinfiles.mm, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "revealdirectoryinfiles.h"
#import <UIKit/UIKit.h>
namespace iOS_utils
{
void revealDirectoryInFiles(QUrl dirUrl)
{
auto urlComponents = [NSURLComponents componentsWithURL:dirUrl.toNSURL() resolvingAgainstBaseURL:NO];
urlComponents.scheme = @"shareddocuments";
[UIApplication.sharedApplication openURL:urlComponents.URL options:@{} completionHandler:nil];
}
}