share file for iOS
This commit is contained in:
parent
9ed16b81e8
commit
9601506270
6 changed files with 94 additions and 17 deletions
|
@ -38,6 +38,7 @@ HEADERS += \
|
|||
debug.h \
|
||||
defines.h \
|
||||
managementserver.h \
|
||||
platforms/ios/MobileUtils.h \
|
||||
platforms/linux/leakdetector.h \
|
||||
protocols/protocols_defs.h \
|
||||
settings.h \
|
||||
|
@ -95,6 +96,7 @@ SOURCES += \
|
|||
debug.cpp \
|
||||
main.cpp \
|
||||
managementserver.cpp \
|
||||
platforms/ios/MobileUtils.cpp \
|
||||
platforms/linux/leakdetector.cpp \
|
||||
protocols/protocols_defs.cpp \
|
||||
settings.cpp \
|
||||
|
@ -305,7 +307,8 @@ ios {
|
|||
platforms/ios/QtAppDelegate-C-Interface.h
|
||||
|
||||
SOURCES -= \
|
||||
platforms/ios/QRCodeReader.cpp
|
||||
platforms/ios/QRCodeReader.cpp \
|
||||
platforms/ios/MobileUtils.cpp
|
||||
|
||||
SOURCES += \
|
||||
protocols/ios_vpnprotocol.mm \
|
||||
|
@ -315,7 +318,8 @@ ios {
|
|||
platforms/ios/ipaddress.cpp \
|
||||
platforms/ios/ipaddressrange.cpp \
|
||||
platforms/ios/QRCodeReader.mm \
|
||||
platforms/ios/QtAppDelegate.mm
|
||||
platforms/ios/QtAppDelegate.mm \
|
||||
platforms/ios/MobileUtils.mm
|
||||
|
||||
Q_ENABLE_BITCODE.value = NO
|
||||
Q_ENABLE_BITCODE.name = ENABLE_BITCODE
|
||||
|
|
10
client/platforms/ios/MobileUtils.cpp
Normal file
10
client/platforms/ios/MobileUtils.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "MobileUtils.h"
|
||||
|
||||
MobileUtils::MobileUtils()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MobileUtils::shareText(const QStringList& filesToSend) {
|
||||
|
||||
}
|
17
client/platforms/ios/MobileUtils.h
Normal file
17
client/platforms/ios/MobileUtils.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef MOBILEUTILS_H
|
||||
#define MOBILEUTILS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class MobileUtils : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MobileUtils() = delete;
|
||||
|
||||
public slots:
|
||||
static void shareText(const QStringList& filesToSend);
|
||||
};
|
||||
|
||||
#endif // MOBILEUTILS_H
|
33
client/platforms/ios/MobileUtils.mm
Normal file
33
client/platforms/ios/MobileUtils.mm
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "MobileUtils.h"
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
static UIViewController* getViewController() {
|
||||
NSArray *windows = [[UIApplication sharedApplication]windows];
|
||||
for (UIWindow *window in windows) {
|
||||
if (window.isKeyWindow) {
|
||||
return window.rootViewController;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
void MobileUtils::shareText(const QStringList& filesToSend) {
|
||||
NSMutableArray *sharingItems = [NSMutableArray new];
|
||||
|
||||
for (int i = 0; i < filesToSend.size(); i++) {
|
||||
NSURL *logFileUrl = [[NSURL alloc] initFileURLWithPath:filesToSend[i].toNSString()];
|
||||
[sharingItems addObject:logFileUrl];
|
||||
}
|
||||
|
||||
UIViewController *qtController = getViewController();
|
||||
if (!qtController) return;
|
||||
|
||||
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
|
||||
|
||||
[qtController presentViewController:activityController animated:YES completion:nil];
|
||||
UIPopoverPresentationController *popController = activityController.popoverPresentationController;
|
||||
if (popController) {
|
||||
popController.sourceView = qtController.view;
|
||||
}
|
||||
}
|
|
@ -48,6 +48,8 @@
|
|||
#include "platforms/android/android_controller.h"
|
||||
#endif
|
||||
|
||||
#include "platforms/ios/MobileUtils.h"
|
||||
|
||||
#include "pages_logic/AppSettingsLogic.h"
|
||||
#include "pages_logic/GeneralSettingsLogic.h"
|
||||
#include "pages_logic/NetworkSettingsLogic.h"
|
||||
|
@ -612,21 +614,10 @@ PageEnumNS::Page UiLogic::currentPage()
|
|||
|
||||
void UiLogic::saveTextFile(const QString& desc, const QString& suggestedName, QString ext, const QString& data)
|
||||
{
|
||||
// ext.replace("*", "");
|
||||
// QString fileName = QFileDialog::getSaveFileName(nullptr, desc,
|
||||
// QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*" + ext);
|
||||
|
||||
// if (fileName.isEmpty()) return;
|
||||
// if (!fileName.endsWith(ext)) fileName.append(ext);
|
||||
|
||||
// QFile save(fileName);
|
||||
// save.open(QIODevice::WriteOnly);
|
||||
// save.write(data.toUtf8());
|
||||
// save.close();
|
||||
|
||||
// QFileInfo fi(fileName);
|
||||
// QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
shareTempFile(suggestedName, ext, data);
|
||||
return;
|
||||
#endif
|
||||
|
||||
ext.replace("*", "");
|
||||
QString docDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
||||
|
@ -681,3 +672,23 @@ void UiLogic::copyToClipboard(const QString &text)
|
|||
{
|
||||
qApp->clipboard()->setText(text);
|
||||
}
|
||||
|
||||
void UiLogic::shareTempFile(const QString &suggestedName, QString ext, const QString& data) {
|
||||
ext.replace("*", "");
|
||||
QString fileName = QDir::tempPath() + "/" + suggestedName;
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
if (!fileName.endsWith(ext)) fileName.append(ext);
|
||||
|
||||
QFile::remove(fileName);
|
||||
qDebug() << "UiLogic::shareTempFile" << fileName;
|
||||
|
||||
QFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(data.toUtf8());
|
||||
save.close();
|
||||
|
||||
QStringList filesToSend;
|
||||
filesToSend.append(fileName);
|
||||
MobileUtils::shareText(filesToSend);
|
||||
}
|
||||
|
|
|
@ -104,6 +104,8 @@ public:
|
|||
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
|
||||
Q_INVOKABLE void copyToClipboard(const QString& text);
|
||||
|
||||
void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
|
||||
|
||||
QString getDialogConnectErrorText() const;
|
||||
void setDialogConnectErrorText(const QString &dialogConnectErrorText);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue