From dab98acdccb42509898bab0fff8702a8f09e541e Mon Sep 17 00:00:00 2001
From: Vitor Vieira <155513369+VitorVieiraZ@users.noreply.github.com>
Date: Mon, 8 Apr 2024 07:04:11 -0300
Subject: [PATCH 01/27] Android PDF file viewer and openLink function working
(#3268)
---
app/android/res/xml/file_paths.xml | 3 ++
.../uk/co/lutraconsulting/InputActivity.java | 43 +++++++++++++++++++
app/androidutils.cpp | 9 ++++
app/androidutils.h | 1 +
app/inpututils.cpp | 36 +++++++++++++++-
app/inpututils.h | 7 +++
.../editors/MMFormTextMultilineEditor.qml | 2 +-
7 files changed, 99 insertions(+), 2 deletions(-)
diff --git a/app/android/res/xml/file_paths.xml b/app/android/res/xml/file_paths.xml
index 7829eff2e..b4950a8d7 100644
--- a/app/android/res/xml/file_paths.xml
+++ b/app/android/res/xml/file_paths.xml
@@ -1,4 +1,7 @@
+
diff --git a/app/android/src/uk/co/lutraconsulting/InputActivity.java b/app/android/src/uk/co/lutraconsulting/InputActivity.java
index fa5781037..934197e9d 100644
--- a/app/android/src/uk/co/lutraconsulting/InputActivity.java
+++ b/app/android/src/uk/co/lutraconsulting/InputActivity.java
@@ -28,6 +28,13 @@
import android.graphics.Insets;
import android.graphics.Color;
+import android.content.Intent;
+import android.net.Uri;
+import android.content.ActivityNotFoundException;
+import java.io.File;
+import androidx.core.content.FileProvider;
+import android.widget.Toast;
+
import androidx.core.view.WindowCompat;
import androidx.core.splashscreen.SplashScreen;
@@ -123,6 +130,42 @@ public void hideSplashScreen()
keepSplashScreenVisible = false;
}
+ public void openFile( String filePath ) {
+ Log.d( TAG, "Expected file path: " + filePath );
+
+ File file = new File( filePath );
+
+ if ( !file.exists() ) {
+ Log.d( TAG, "File does not exist: " + filePath );
+ runOnUiThread( () -> Toast.makeText( getApplicationContext(), "File not available", Toast.LENGTH_SHORT ).show() );
+ return;
+ } else {
+ Log.d( TAG, "File exists: " + filePath );
+ }
+
+ Intent showFileIntent = new Intent( Intent.ACTION_VIEW );
+
+ try {
+ Uri fileUri = FileProvider.getUriForFile( this, "uk.co.lutraconsulting.fileprovider", file );
+ Log.d( TAG, "File URI: " + fileUri.toString() );
+
+ showFileIntent.setData( fileUri );
+
+ // FLAG_GRANT_READ_URI_PERMISSION grants temporary read permission to the content URI.
+ // FLAG_ACTIVITY_NEW_TASK is used when starting an Activity from a non-Activity context.
+ showFileIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION );
+ } catch ( IllegalArgumentException e ) {
+ Log.d( TAG, "FileProvider URI issue", e );
+ return;
+ }
+
+ if ( showFileIntent.resolveActivity( getPackageManager() ) != null ) {
+ startActivity( showFileIntent );
+ } else {
+ runOnUiThread( () -> Toast.makeText( getApplicationContext(), "No application for opening this file", Toast.LENGTH_SHORT ).show() );
+ }
+ }
+
public void quitGracefully()
{
String man = android.os.Build.MANUFACTURER.toUpperCase();
diff --git a/app/androidutils.cpp b/app/androidutils.cpp
index 1869a38cd..d92ead21a 100644
--- a/app/androidutils.cpp
+++ b/app/androidutils.cpp
@@ -227,6 +227,15 @@ void AndroidUtils::hideSplashScreen()
#endif
}
+void AndroidUtils::openFile( const QString &filePath )
+{
+#ifdef ANDROID
+ auto activity = QJniObject( QNativeInterface::QAndroidApplication::context() );
+ QJniObject jFilePath = QJniObject::fromString( filePath );
+ activity.callMethod( "openFile", "(Ljava/lang/String;)V", jFilePath.object() );
+#endif
+}
+
bool AndroidUtils::requestStoragePermission()
{
#ifdef ANDROID
diff --git a/app/androidutils.h b/app/androidutils.h
index 8d7f6ec21..937437c49 100644
--- a/app/androidutils.h
+++ b/app/androidutils.h
@@ -69,6 +69,7 @@ class AndroidUtils: public QObject
*/
Q_INVOKABLE void callImagePicker( const QString &code = "" );
Q_INVOKABLE void callCamera( const QString &targetPath, const QString &code = "" );
+ Q_INVOKABLE void openFile( const QString &filePath );
#ifdef ANDROID
const static int MEDIA_CODE = 101;
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 5a30f88d6..fb015d3b6 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -58,7 +58,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -2156,6 +2156,7 @@ QList InputUtils::parsePositionUpdates( const QString &data )
return parsedUpdates;
}
+<<<<<<< HEAD
QString InputUtils::getManufacturer()
{
#ifdef Q_OS_ANDROID
@@ -2175,3 +2176,36 @@ QString InputUtils::getDeviceModel()
#endif
return QStringLiteral( "N/A" );
}
+
+void InputUtils::openLink( const QString &homePath, const QString &link )
+{
+ qDebug() << "LINK" << link;
+ qDebug() << "HOMEPATH" << homePath;
+
+ QString cleanedLink = link.trimmed();
+ static QRegularExpression re( "^\\?|\\?$" );
+ cleanedLink.remove( re );
+
+ qDebug() << "cleanedLink" << cleanedLink;
+
+ if ( cleanedLink.startsWith( "project://" ) )
+ {
+ QString relativePath = cleanedLink.mid( QString( "project://" ).length() );
+ QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+
+ qDebug() << "relativePath" << relativePath;
+ qDebug() << "absoluteLinkPath" << absoluteLinkPath;
+
+#ifdef Q_OS_ANDROID
+ qDebug() << "openLink android";
+ mAndroidUtils->openFile( absoluteLinkPath );
+#elif defined(Q_OS_IOS)
+ qDebug() << "openLink ios";
+#endif
+ }
+ else
+ {
+ cleanedLink.chop( 1 ); //remove \ from cleanedLink
+ QDesktopServices::openUrl( QUrl( cleanedLink ) );
+ }
+}
diff --git a/app/inpututils.h b/app/inpututils.h
index f2606ab92..6f7bb713a 100644
--- a/app/inpututils.h
+++ b/app/inpututils.h
@@ -174,6 +174,13 @@ class InputUtils: public QObject
*/
Q_INVOKABLE static QString bytesToHumanSize( double bytes );
+ /**
+ * Opens the specified link in an appropriate application. For "project://" links, it converts them to
+ * absolute paths and opens with default file handlers. Other links are opened in the default web browser.
+ * @param link The link to open, either a "project://" link or a standard URL.
+ */
+ Q_INVOKABLE void openLink( const QString &homePath, const QString &link );
+
Q_INVOKABLE bool acquireCameraPermission();
Q_INVOKABLE bool isBluetoothTurnedOn();
diff --git a/app/qml/form/editors/MMFormTextMultilineEditor.qml b/app/qml/form/editors/MMFormTextMultilineEditor.qml
index 985fdf9ec..00ea32f52 100644
--- a/app/qml/form/editors/MMFormTextMultilineEditor.qml
+++ b/app/qml/form/editors/MMFormTextMultilineEditor.qml
@@ -117,7 +117,7 @@ MMPrivateComponents.MMBaseInput {
radius: __style.radius12
}
- onLinkActivated: ( link ) => Qt.openUrlExternally( link )
+ onLinkActivated: ( link ) => __inputUtils.openLink( root._fieldHomePath, link.toString() )
onTextChanged: root.editorValueChanged( textArea.text, textArea.text === "" )
}
From 44d58768a0120e076aa07dc1e8a63435f72ab25d Mon Sep 17 00:00:00 2001
From: Vitor Vieira <155513369+VitorVieiraZ@users.noreply.github.com>
Date: Mon, 8 Apr 2024 07:13:58 -0300
Subject: [PATCH 02/27] Desktop file viewer - part one (#3281)
---
app/inpututils.cpp | 52 +++++++++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 21 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index fb015d3b6..17e4adda9 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -59,6 +59,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -2179,33 +2180,42 @@ QString InputUtils::getDeviceModel()
void InputUtils::openLink( const QString &homePath, const QString &link )
{
- qDebug() << "LINK" << link;
- qDebug() << "HOMEPATH" << homePath;
+ qDebug() << "LINK" << link;
+ qDebug() << "HOMEPATH" << homePath;
- QString cleanedLink = link.trimmed();
- static QRegularExpression re( "^\\?|\\?$" );
- cleanedLink.remove( re );
+ QString cleanedLink = link.trimmed();
+ static QRegularExpression re( "^\\?|\\?$" );
+ cleanedLink.remove( re );
+ cleanedLink.chop( 1 ); //remove \ from cleanedLink
- qDebug() << "cleanedLink" << cleanedLink;
+ qDebug() << "cleanedLink" << cleanedLink;
- if ( cleanedLink.startsWith( "project://" ) )
- {
- QString relativePath = cleanedLink.mid( QString( "project://" ).length() );
- QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+ if ( cleanedLink.startsWith( "project://" ) )
+ {
+ QString relativePath = cleanedLink.mid( QString( "project://" ).length() );
+ QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
- qDebug() << "relativePath" << relativePath;
- qDebug() << "absoluteLinkPath" << absoluteLinkPath;
+ QString testPath = "/Users/vmstar/Documents/Lutra/MM/mobile/app/android/assets/qgis-data/projects/PDF Viewing Project/dummy.pdf";
+ qDebug() << "relativePath" << relativePath;
+ qDebug() << "absoluteLinkPath" << absoluteLinkPath;
#ifdef Q_OS_ANDROID
- qDebug() << "openLink android";
- mAndroidUtils->openFile( absoluteLinkPath );
+ qDebug() << "openLink android";
+ mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
- qDebug() << "openLink ios";
+ qDebug() << "openLink ios";
+ //IosUtils::openFile( )
+#else
+ // Desktop environments
+ QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
+ if ( !QDesktopServices::openUrl( fileUrl ) )
+ {
+ qDebug() << "Failed to open the file:" << absoluteLinkPath;
+ }
#endif
- }
- else
- {
- cleanedLink.chop( 1 ); //remove \ from cleanedLink
- QDesktopServices::openUrl( QUrl( cleanedLink ) );
- }
+ }
+ else
+ {
+ QDesktopServices::openUrl( QUrl( cleanedLink ) );
+ }
}
From bd7a49080440e54c34b56430438b8fd4a4b9eae1 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Mon, 8 Apr 2024 13:48:22 +0200
Subject: [PATCH 03/27] code cleaning
---
app/inpututils.cpp | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 17e4adda9..2fdee4ed8 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2180,19 +2180,9 @@ QString InputUtils::getDeviceModel()
void InputUtils::openLink( const QString &homePath, const QString &link )
{
- qDebug() << "LINK" << link;
- qDebug() << "HOMEPATH" << homePath;
-
- QString cleanedLink = link.trimmed();
- static QRegularExpression re( "^\\?|\\?$" );
- cleanedLink.remove( re );
- cleanedLink.chop( 1 ); //remove \ from cleanedLink
-
- qDebug() << "cleanedLink" << cleanedLink;
-
- if ( cleanedLink.startsWith( "project://" ) )
+ if ( link.startsWith( "project://" ) )
{
- QString relativePath = cleanedLink.mid( QString( "project://" ).length() );
+ QString relativePath = link.mid( QString( "project://" ).length() );
QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
QString testPath = "/Users/vmstar/Documents/Lutra/MM/mobile/app/android/assets/qgis-data/projects/PDF Viewing Project/dummy.pdf";
@@ -2200,22 +2190,21 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
qDebug() << "absoluteLinkPath" << absoluteLinkPath;
#ifdef Q_OS_ANDROID
- qDebug() << "openLink android";
mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
qDebug() << "openLink ios";
- //IosUtils::openFile( )
#else
// Desktop environments
QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
if ( !QDesktopServices::openUrl( fileUrl ) )
{
- qDebug() << "Failed to open the file:" << absoluteLinkPath;
+ QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
+ CoreUtils::log( "File error", errorMessage );
}
#endif
}
else
{
- QDesktopServices::openUrl( QUrl( cleanedLink ) );
+ QDesktopServices::openUrl( QUrl( link ) );
}
}
From 14177572c340075fba756e217ccd3e07e0685094 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Mon, 8 Apr 2024 14:17:33 +0200
Subject: [PATCH 04/27] git layout adjusts
---
app/inpututils.cpp | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 2fdee4ed8..59c4c3205 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2180,31 +2180,31 @@ QString InputUtils::getDeviceModel()
void InputUtils::openLink( const QString &homePath, const QString &link )
{
- if ( link.startsWith( "project://" ) )
- {
- QString relativePath = link.mid( QString( "project://" ).length() );
- QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+ if ( link.startsWith( "project://" ) )
+ {
+ QString relativePath = link.mid( QString( "project://" ).length() );
+ QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
- QString testPath = "/Users/vmstar/Documents/Lutra/MM/mobile/app/android/assets/qgis-data/projects/PDF Viewing Project/dummy.pdf";
- qDebug() << "relativePath" << relativePath;
- qDebug() << "absoluteLinkPath" << absoluteLinkPath;
+ QString testPath = "/Users/vmstar/Documents/Lutra/MM/mobile/app/android/assets/qgis-data/projects/PDF Viewing Project/dummy.pdf";
+ qDebug() << "relativePath" << relativePath;
+ qDebug() << "absoluteLinkPath" << absoluteLinkPath;
#ifdef Q_OS_ANDROID
- mAndroidUtils->openFile( absoluteLinkPath );
+ mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
- qDebug() << "openLink ios";
+ qDebug() << "openLink ios";
#else
- // Desktop environments
- QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
- if ( !QDesktopServices::openUrl( fileUrl ) )
- {
- QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
- CoreUtils::log( "File error", errorMessage );
- }
-#endif
- }
- else
+ // Desktop environments
+ QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
+ if ( !QDesktopServices::openUrl( fileUrl ) )
{
- QDesktopServices::openUrl( QUrl( link ) );
+ QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
+ CoreUtils::log( "File error", errorMessage );
}
+#endif
+ }
+ else
+ {
+ QDesktopServices::openUrl( QUrl( link ) );
+ }
}
From 235ba85dfd14b9ce8f344a8938f5833ea6293771 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Mon, 8 Apr 2024 14:19:09 +0200
Subject: [PATCH 05/27] last adjustments
---
app/inpututils.cpp | 5 -----
1 file changed, 5 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 59c4c3205..e42316a8f 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2184,11 +2184,6 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
{
QString relativePath = link.mid( QString( "project://" ).length() );
QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
-
- QString testPath = "/Users/vmstar/Documents/Lutra/MM/mobile/app/android/assets/qgis-data/projects/PDF Viewing Project/dummy.pdf";
- qDebug() << "relativePath" << relativePath;
- qDebug() << "absoluteLinkPath" << absoluteLinkPath;
-
#ifdef Q_OS_ANDROID
mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
From 9c3962af18f2e2ac5fc7e9e324f7c91bdca6bab7 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Tue, 23 Apr 2024 05:08:45 -0300
Subject: [PATCH 06/27] ios pdf viewing
---
app/inpututils.cpp | 40 +++++++++++++++++++++++-----------------
app/ios/iosutils.cpp | 7 +++++++
app/ios/iosutils.h | 7 +++++++
app/ios/iosutils.mm | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 17 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index e42316a8f..c165f8c05 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2180,26 +2180,32 @@ QString InputUtils::getDeviceModel()
void InputUtils::openLink( const QString &homePath, const QString &link )
{
- if ( link.startsWith( "project://" ) )
- {
- QString relativePath = link.mid( QString( "project://" ).length() );
- QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+ if ( link.startsWith( "project://" ) )
+ {
+ QString relativePath = link.mid( QString( "project://" ).length() );
+ QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
#ifdef Q_OS_ANDROID
- mAndroidUtils->openFile( absoluteLinkPath );
+ mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
- qDebug() << "openLink ios";
+ qWarning() << "IOS HERE";
+ //QUrl fileUrl = QUrl::fromLocalFile(absoluteLinkPath);
+
+ // Open the file with the default application
+ //QDesktopServices::openUrl(fileUrl);
+ IosUtils::openFile( absoluteLinkPath );
+ qDebug() << "openLink ios";
#else
- // Desktop environments
- QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
- if ( !QDesktopServices::openUrl( fileUrl ) )
+ // Desktop environments
+ QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
+ if ( !QDesktopServices::openUrl( fileUrl ) )
+ {
+ QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
+ CoreUtils::log( "File error", errorMessage );
+ }
+#endif
+ }
+ else
{
- QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
- CoreUtils::log( "File error", errorMessage );
+ QDesktopServices::openUrl( QUrl( link ) );
}
-#endif
- }
- else
- {
- QDesktopServices::openUrl( QUrl( link ) );
- }
}
diff --git a/app/ios/iosutils.cpp b/app/ios/iosutils.cpp
index 37c3e107f..49d05162b 100644
--- a/app/ios/iosutils.cpp
+++ b/app/ios/iosutils.cpp
@@ -67,6 +67,7 @@ QVector IosUtils::getSafeArea()
return QVector();
}
+<<<<<<< HEAD
QString IosUtils::getManufacturer()
{
#ifdef Q_OS_IOS
@@ -81,4 +82,10 @@ QString IosUtils::getDeviceModel()
return getDeviceModelImpl();
#endif
return "";
+=======
+void IosUtils::openFile( const QString &filePath )
+{
+ //qWarning() << "test";
+ openFileImpl( filePath ); //
+>>>>>>> 05801f46 (ios pdf viewing)
}
diff --git a/app/ios/iosutils.h b/app/ios/iosutils.h
index b0386b943..b4aa0b8ee 100644
--- a/app/ios/iosutils.h
+++ b/app/ios/iosutils.h
@@ -42,6 +42,8 @@ class IosUtils: public QObject
static QString readExif( const QString &filepath, const QString &tag );
Q_INVOKABLE QVector getSafeArea();
+
+ Q_INVOKABLE static void openFile(const QString &filePath);
static Q_INVOKABLE QString getManufacturer();
static Q_INVOKABLE QString getDeviceModel();
@@ -64,9 +66,14 @@ class IosUtils: public QObject
void setIdleTimerDisabled();
QVector getSafeAreaImpl();
+<<<<<<< HEAD
static QString getManufacturerImpl();
static QString getDeviceModelImpl();
+=======
+
+ static void openFileImpl(const QString &filePath); //tesrtsasssaa
+>>>>>>> 05801f46 (ios pdf viewing)
};
#endif // IOSUTILS_H
diff --git a/app/ios/iosutils.mm b/app/ios/iosutils.mm
index ea91001ae..38c9a296b 100644
--- a/app/ios/iosutils.mm
+++ b/app/ios/iosutils.mm
@@ -14,8 +14,15 @@
***************************************************************************/
#include
+<<<<<<< HEAD
#include
+=======
+#import
+#import
+#include
+>>>>>>> 05801f46 (ios pdf viewing)
#include "iosutils.h"
+#include "coreutils.h"
void IosUtils::setIdleTimerDisabled()
{
@@ -54,3 +61,32 @@
QString deviceModel = QString::fromUtf8( systemInfo.machine );
return deviceModel.toUpper();
}
+
+@interface FileOpener : UIViewController
+@end
+
+@implementation FileOpener
+
+- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)ctrl {
+ return self;
+}
+
+@end
+
+void IosUtils::openFileImpl(const QString &filePath)
+{
+ static FileOpener *viewer = nil;
+ NSURL *resourceURL = [NSURL fileURLWithPath:filePath.toNSString()];
+ CoreUtils::log("PDF file encountered: ", [resourceURL path].UTF8String);
+
+ UIDocumentInteractionController *interactionCtrl = [UIDocumentInteractionController interactionControllerWithURL:resourceURL];
+ UIViewController *rootViewController = [[[[UIApplication sharedApplication] windows] firstObject] rootViewController];
+
+ viewer = [[FileOpener alloc] init];
+ [rootViewController addChildViewController: viewer];
+ interactionCtrl.delegate = (id)viewer;
+
+ if (![interactionCtrl presentPreviewAnimated:NO]){
+ [interactionCtrl presentOptionsMenuFromRect:CGRectZero inView:viewer.view animated:NO];
+ }
+}
From 8f41edfb5d589319ecb69aacf0e349b03dd8c0e6 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Tue, 23 Apr 2024 07:29:02 -0300
Subject: [PATCH 07/27] form rich text opening pdfs enabled
---
app/inpututils.cpp | 6 ------
app/ios/iosutils.cpp | 14 ++++++++------
app/qml/form/editors/MMFormRichTextViewer.qml | 6 +++---
app/qml/form/editors/MMFormTextMultilineEditor.qml | 1 +
4 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index c165f8c05..0524c610a 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2187,13 +2187,7 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
#ifdef Q_OS_ANDROID
mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
- qWarning() << "IOS HERE";
- //QUrl fileUrl = QUrl::fromLocalFile(absoluteLinkPath);
-
- // Open the file with the default application
- //QDesktopServices::openUrl(fileUrl);
IosUtils::openFile( absoluteLinkPath );
- qDebug() << "openLink ios";
#else
// Desktop environments
QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
diff --git a/app/ios/iosutils.cpp b/app/ios/iosutils.cpp
index 49d05162b..2612d5224 100644
--- a/app/ios/iosutils.cpp
+++ b/app/ios/iosutils.cpp
@@ -67,7 +67,6 @@ QVector IosUtils::getSafeArea()
return QVector();
}
-<<<<<<< HEAD
QString IosUtils::getManufacturer()
{
#ifdef Q_OS_IOS
@@ -82,10 +81,13 @@ QString IosUtils::getDeviceModel()
return getDeviceModelImpl();
#endif
return "";
-=======
-void IosUtils::openFile( const QString &filePath )
+}
+
+bool IosUtils::openFile( const QString &filePath )
{
- //qWarning() << "test";
- openFileImpl( filePath ); //
->>>>>>> 05801f46 (ios pdf viewing)
+#ifdef Q_OS_IOS
+ return openFileImpl( filePath );
+#else
+ return false;
+#endif
}
diff --git a/app/qml/form/editors/MMFormRichTextViewer.qml b/app/qml/form/editors/MMFormRichTextViewer.qml
index ec226d191..67b619a8c 100644
--- a/app/qml/form/editors/MMFormRichTextViewer.qml
+++ b/app/qml/form/editors/MMFormRichTextViewer.qml
@@ -20,6 +20,7 @@ MMPrivateComponents.MMBaseInput {
property bool _fieldShouldShowTitle: parent.fieldShouldShowTitle
property string _fieldTitle: parent.fieldTitle
+ property string _fieldHomePath: parent.fieldHomePath
title: _fieldShouldShowTitle ? _fieldTitle : ""
@@ -47,9 +48,8 @@ MMPrivateComponents.MMBaseInput {
leftPadding: __style.margin20
rightPadding: __style.margin20
- onLinkActivated: function( link ) {
- Qt.openUrlExternally( link )
- }
+ //HERE
+ onLinkActivated: ( link ) => __inputUtils.openLink( root._fieldHomePath, link.toString() )
}
}
}
diff --git a/app/qml/form/editors/MMFormTextMultilineEditor.qml b/app/qml/form/editors/MMFormTextMultilineEditor.qml
index 00ea32f52..bac481296 100644
--- a/app/qml/form/editors/MMFormTextMultilineEditor.qml
+++ b/app/qml/form/editors/MMFormTextMultilineEditor.qml
@@ -36,6 +36,7 @@ MMPrivateComponents.MMBaseInput {
property string _fieldTitle: parent.fieldTitle
property string _fieldErrorMessage: parent.fieldErrorMessage
property string _fieldWarningMessage: parent.fieldWarningMessage
+ property string _fieldHomePath: parent.fieldHomePath
property bool _fieldRememberValueSupported: parent.fieldRememberValueSupported
property bool _fieldRememberValueState: parent.fieldRememberValueState
From f42a6241f1b4eec9cf83422454072ff23e8ac4ef Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Tue, 23 Apr 2024 07:35:57 -0300
Subject: [PATCH 08/27] new code adjustments
---
app/ios/iosutils.h | 8 ++------
app/ios/iosutils.mm | 2 --
2 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/app/ios/iosutils.h b/app/ios/iosutils.h
index b4aa0b8ee..b2bb6e34a 100644
--- a/app/ios/iosutils.h
+++ b/app/ios/iosutils.h
@@ -66,14 +66,10 @@ class IosUtils: public QObject
void setIdleTimerDisabled();
QVector getSafeAreaImpl();
-<<<<<<< HEAD
+
static QString getManufacturerImpl();
static QString getDeviceModelImpl();
-
-=======
-
- static void openFileImpl(const QString &filePath); //tesrtsasssaa
->>>>>>> 05801f46 (ios pdf viewing)
+ static void openFileImpl(const QString &filePath);
};
#endif // IOSUTILS_H
diff --git a/app/ios/iosutils.mm b/app/ios/iosutils.mm
index 38c9a296b..e297488d5 100644
--- a/app/ios/iosutils.mm
+++ b/app/ios/iosutils.mm
@@ -22,7 +22,6 @@
#include
>>>>>>> 05801f46 (ios pdf viewing)
#include "iosutils.h"
-#include "coreutils.h"
void IosUtils::setIdleTimerDisabled()
{
@@ -77,7 +76,6 @@ - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UID
{
static FileOpener *viewer = nil;
NSURL *resourceURL = [NSURL fileURLWithPath:filePath.toNSString()];
- CoreUtils::log("PDF file encountered: ", [resourceURL path].UTF8String);
UIDocumentInteractionController *interactionCtrl = [UIDocumentInteractionController interactionControllerWithURL:resourceURL];
UIViewController *rootViewController = [[[[UIApplication sharedApplication] windows] firstObject] rootViewController];
From 0a5f114cc447403d5e8b0d6d02194fd8ed730da0 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Tue, 23 Apr 2024 07:38:39 -0300
Subject: [PATCH 09/27] code cleanup
---
app/qml/form/editors/MMFormRichTextViewer.qml | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/qml/form/editors/MMFormRichTextViewer.qml b/app/qml/form/editors/MMFormRichTextViewer.qml
index 67b619a8c..647c59f77 100644
--- a/app/qml/form/editors/MMFormRichTextViewer.qml
+++ b/app/qml/form/editors/MMFormRichTextViewer.qml
@@ -48,7 +48,6 @@ MMPrivateComponents.MMBaseInput {
leftPadding: __style.margin20
rightPadding: __style.margin20
- //HERE
onLinkActivated: ( link ) => __inputUtils.openLink( root._fieldHomePath, link.toString() )
}
}
From 6702130db7d5fe2cb42b4305aec9edb2fe8ab099 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Tue, 23 Apr 2024 11:46:19 -0300
Subject: [PATCH 10/27] dealing with no-existent file
---
app/inpututils.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 0524c610a..634fcc455 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -53,10 +53,12 @@
#include "imageutils.h"
#include "variablesmanager.h"
+#include "notificationmodel.h"
#include
#include
#include
+#include
#include
#include
#include
@@ -2184,6 +2186,11 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
{
QString relativePath = link.mid( QString( "project://" ).length() );
QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+ if (!fileExists(absoluteLinkPath)){
+ QString errorMessage = tr("The specified file does not exist: %1").arg(relativePath);
+ QMessageBox::warning(nullptr, "File Not Found", errorMessage);
+ return;
+ }
#ifdef Q_OS_ANDROID
mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
From 2c67b6b1bede41935a39c271ca27446668a48305 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Wed, 24 Apr 2024 04:53:58 -0300
Subject: [PATCH 11/27] adjustments
---
app/inpututils.cpp | 44 ++++++++++++++++++++++----------------------
app/ios/iosutils.h | 4 ++--
app/ios/iosutils.mm | 10 ++++++----
3 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 634fcc455..4a982d3cc 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -53,7 +53,6 @@
#include "imageutils.h"
#include "variablesmanager.h"
-#include "notificationmodel.h"
#include
#include
@@ -2182,31 +2181,32 @@ QString InputUtils::getDeviceModel()
void InputUtils::openLink( const QString &homePath, const QString &link )
{
- if ( link.startsWith( "project://" ) )
+ if ( link.startsWith( "project://" ) )
+ {
+ QString relativePath = link.mid( QString( "project://" ).length() );
+ QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+ if ( !fileExists( absoluteLinkPath ) )
{
- QString relativePath = link.mid( QString( "project://" ).length() );
- QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
- if (!fileExists(absoluteLinkPath)){
- QString errorMessage = tr("The specified file does not exist: %1").arg(relativePath);
- QMessageBox::warning(nullptr, "File Not Found", errorMessage);
- return;
- }
+ QString errorMessage = tr( "The specified file does not exist: %1" ).arg( relativePath );
+ QMessageBox::warning( nullptr, "File Not Found", errorMessage );
+ return;
+ }
#ifdef Q_OS_ANDROID
- mAndroidUtils->openFile( absoluteLinkPath );
+ mAndroidUtils->openFile( absoluteLinkPath );
#elif defined(Q_OS_IOS)
- IosUtils::openFile( absoluteLinkPath );
+ IosUtils::openFile( absoluteLinkPath );
#else
- // Desktop environments
- QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
- if ( !QDesktopServices::openUrl( fileUrl ) )
- {
- QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
- CoreUtils::log( "File error", errorMessage );
- }
-#endif
- }
- else
+ // Desktop environments
+ QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
+ if ( !QDesktopServices::openUrl( fileUrl ) )
{
- QDesktopServices::openUrl( QUrl( link ) );
+ QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
+ CoreUtils::log( "File error", errorMessage );
}
+#endif
+ }
+ else
+ {
+ QDesktopServices::openUrl( QUrl( link ) );
+ }
}
diff --git a/app/ios/iosutils.h b/app/ios/iosutils.h
index b2bb6e34a..e7b69acaf 100644
--- a/app/ios/iosutils.h
+++ b/app/ios/iosutils.h
@@ -42,8 +42,8 @@ class IosUtils: public QObject
static QString readExif( const QString &filepath, const QString &tag );
Q_INVOKABLE QVector getSafeArea();
-
- Q_INVOKABLE static void openFile(const QString &filePath);
+
+ Q_INVOKABLE static void openFile( const QString &filePath );
static Q_INVOKABLE QString getManufacturer();
static Q_INVOKABLE QString getDeviceModel();
diff --git a/app/ios/iosutils.mm b/app/ios/iosutils.mm
index e297488d5..6061fc5ad 100644
--- a/app/ios/iosutils.mm
+++ b/app/ios/iosutils.mm
@@ -66,13 +66,14 @@ @interface FileOpener : UIViewController )viewer;
+ interactionCtrl.delegate = ( id )viewer;
- if (![interactionCtrl presentPreviewAnimated:NO]){
+ if ( ![interactionCtrl presentPreviewAnimated:NO] )
+ {
[interactionCtrl presentOptionsMenuFromRect:CGRectZero inView:viewer.view animated:NO];
}
}
From 6872f3c91fef17a3450bb12c72dd15d5015dc80a Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Thu, 25 Apr 2024 09:07:50 -0300
Subject: [PATCH 12/27] first part of post review changes
---
.../uk/co/lutraconsulting/InputActivity.java | 18 +++++----------
app/androidutils.cpp | 7 ++++--
app/androidutils.h | 2 +-
app/inpututils.cpp | 23 +++++++++++++------
app/inpututils.h | 2 +-
app/ios/iosutils.cpp | 7 ++++++
app/ios/iosutils.h | 4 ++--
app/ios/iosutils.mm | 9 ++++++--
app/qml/form/editors/MMFormRichTextViewer.qml | 7 +++++-
.../editors/MMFormTextMultilineEditor.qml | 8 ++++++-
10 files changed, 58 insertions(+), 29 deletions(-)
diff --git a/app/android/src/uk/co/lutraconsulting/InputActivity.java b/app/android/src/uk/co/lutraconsulting/InputActivity.java
index 934197e9d..c77aa3035 100644
--- a/app/android/src/uk/co/lutraconsulting/InputActivity.java
+++ b/app/android/src/uk/co/lutraconsulting/InputActivity.java
@@ -130,24 +130,17 @@ public void hideSplashScreen()
keepSplashScreenVisible = false;
}
- public void openFile( String filePath ) {
- Log.d( TAG, "Expected file path: " + filePath );
-
+ public bool openFile( String filePath ) {
File file = new File( filePath );
if ( !file.exists() ) {
- Log.d( TAG, "File does not exist: " + filePath );
- runOnUiThread( () -> Toast.makeText( getApplicationContext(), "File not available", Toast.LENGTH_SHORT ).show() );
- return;
- } else {
- Log.d( TAG, "File exists: " + filePath );
+ return false;
}
Intent showFileIntent = new Intent( Intent.ACTION_VIEW );
try {
Uri fileUri = FileProvider.getUriForFile( this, "uk.co.lutraconsulting.fileprovider", file );
- Log.d( TAG, "File URI: " + fileUri.toString() );
showFileIntent.setData( fileUri );
@@ -155,15 +148,16 @@ public void openFile( String filePath ) {
// FLAG_ACTIVITY_NEW_TASK is used when starting an Activity from a non-Activity context.
showFileIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION );
} catch ( IllegalArgumentException e ) {
- Log.d( TAG, "FileProvider URI issue", e );
- return;
+ return false;
}
if ( showFileIntent.resolveActivity( getPackageManager() ) != null ) {
startActivity( showFileIntent );
} else {
- runOnUiThread( () -> Toast.makeText( getApplicationContext(), "No application for opening this file", Toast.LENGTH_SHORT ).show() );
+ return false;
}
+
+ return true;
}
public void quitGracefully()
diff --git a/app/androidutils.cpp b/app/androidutils.cpp
index d92ead21a..d550fb6d1 100644
--- a/app/androidutils.cpp
+++ b/app/androidutils.cpp
@@ -227,13 +227,16 @@ void AndroidUtils::hideSplashScreen()
#endif
}
-void AndroidUtils::openFile( const QString &filePath )
+bool AndroidUtils::openFile( const QString &filePath )
{
+ bool result = false;
#ifdef ANDROID
auto activity = QJniObject( QNativeInterface::QAndroidApplication::context() );
QJniObject jFilePath = QJniObject::fromString( filePath );
- activity.callMethod( "openFile", "(Ljava/lang/String;)V", jFilePath.object() );
+ // Ensure the method signature includes 'Z' to indicate a boolean return type.
+ result = activity.callMethod( "openFile", "(Ljava/lang/String;)Z", jFilePath.object() );
#endif
+ return result;
}
bool AndroidUtils::requestStoragePermission()
diff --git a/app/androidutils.h b/app/androidutils.h
index 937437c49..a0fe50126 100644
--- a/app/androidutils.h
+++ b/app/androidutils.h
@@ -69,7 +69,7 @@ class AndroidUtils: public QObject
*/
Q_INVOKABLE void callImagePicker( const QString &code = "" );
Q_INVOKABLE void callCamera( const QString &targetPath, const QString &code = "" );
- Q_INVOKABLE void openFile( const QString &filePath );
+ Q_INVOKABLE bool openFile( const QString &filePath );
#ifdef ANDROID
const static int MEDIA_CODE = 101;
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 4a982d3cc..e88641058 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2158,6 +2158,7 @@ QList InputUtils::parsePositionUpdates( const QString &data )
return parsedUpdates;
}
+<<<<<<< HEAD
<<<<<<< HEAD
QString InputUtils::getManufacturer()
{
@@ -2180,6 +2181,9 @@ QString InputUtils::getDeviceModel()
}
void InputUtils::openLink( const QString &homePath, const QString &link )
+=======
+bool InputUtils::openLink( const QString &homePath, const QString &link )
+>>>>>>> 247d842d (first part of post review changes)
{
if ( link.startsWith( "project://" ) )
{
@@ -2187,21 +2191,24 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
if ( !fileExists( absoluteLinkPath ) )
{
- QString errorMessage = tr( "The specified file does not exist: %1" ).arg( relativePath );
- QMessageBox::warning( nullptr, "File Not Found", errorMessage );
- return;
+ return false;
}
#ifdef Q_OS_ANDROID
- mAndroidUtils->openFile( absoluteLinkPath );
+ if ( !mAndroidUtils->openFile( absoluteLinkPath ) )
+ {
+ return false;
+ }
#elif defined(Q_OS_IOS)
- IosUtils::openFile( absoluteLinkPath );
+ if ( ! IosUtils::openFile( absoluteLinkPath ) )
+ {
+ return false;
+ }
#else
// Desktop environments
QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
if ( !QDesktopServices::openUrl( fileUrl ) )
{
- QString errorMessage = "Failed to open the file:" + absoluteLinkPath;
- CoreUtils::log( "File error", errorMessage );
+ return false;
}
#endif
}
@@ -2209,4 +2216,6 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
{
QDesktopServices::openUrl( QUrl( link ) );
}
+
+ return true;
}
diff --git a/app/inpututils.h b/app/inpututils.h
index 6f7bb713a..22792c86c 100644
--- a/app/inpututils.h
+++ b/app/inpututils.h
@@ -179,7 +179,7 @@ class InputUtils: public QObject
* absolute paths and opens with default file handlers. Other links are opened in the default web browser.
* @param link The link to open, either a "project://" link or a standard URL.
*/
- Q_INVOKABLE void openLink( const QString &homePath, const QString &link );
+ Q_INVOKABLE bool openLink( const QString &homePath, const QString &link );
Q_INVOKABLE bool acquireCameraPermission();
diff --git a/app/ios/iosutils.cpp b/app/ios/iosutils.cpp
index 2612d5224..193ad30ea 100644
--- a/app/ios/iosutils.cpp
+++ b/app/ios/iosutils.cpp
@@ -67,6 +67,7 @@ QVector IosUtils::getSafeArea()
return QVector();
}
+<<<<<<< HEAD
QString IosUtils::getManufacturer()
{
#ifdef Q_OS_IOS
@@ -89,5 +90,11 @@ bool IosUtils::openFile( const QString &filePath )
return openFileImpl( filePath );
#else
return false;
+=======
+bool IosUtils::openFile( const QString &filePath )
+{
+#ifdef Q_OS_IOS
+ return openFileImpl( filePath );
+>>>>>>> 247d842d (first part of post review changes)
#endif
}
diff --git a/app/ios/iosutils.h b/app/ios/iosutils.h
index e7b69acaf..64c911273 100644
--- a/app/ios/iosutils.h
+++ b/app/ios/iosutils.h
@@ -43,7 +43,7 @@ class IosUtils: public QObject
Q_INVOKABLE QVector getSafeArea();
- Q_INVOKABLE static void openFile( const QString &filePath );
+ Q_INVOKABLE static bool openFile( const QString &filePath );
static Q_INVOKABLE QString getManufacturer();
static Q_INVOKABLE QString getDeviceModel();
@@ -69,7 +69,7 @@ class IosUtils: public QObject
static QString getManufacturerImpl();
static QString getDeviceModelImpl();
- static void openFileImpl(const QString &filePath);
+ static bool openFileImpl( const QString &filePath );
};
#endif // IOSUTILS_H
diff --git a/app/ios/iosutils.mm b/app/ios/iosutils.mm
index 6061fc5ad..76fcf27f1 100644
--- a/app/ios/iosutils.mm
+++ b/app/ios/iosutils.mm
@@ -73,7 +73,7 @@ - ( UIViewController * )documentInteractionControllerViewControllerForPreview:(
@end
-void IosUtils::openFileImpl( const QString &filePath )
+bool IosUtils::openFileImpl( const QString &filePath )
{
static FileOpener *viewer = nil;
NSURL *resourceURL = [NSURL fileURLWithPath:filePath.toNSString()];
@@ -87,6 +87,11 @@ - ( UIViewController * )documentInteractionControllerViewControllerForPreview:(
if ( ![interactionCtrl presentPreviewAnimated:NO] )
{
- [interactionCtrl presentOptionsMenuFromRect:CGRectZero inView:viewer.view animated:NO];
+ if ( ![interactionCtrl presentOptionsMenuFromRect:CGRectZero inView:viewer.view animated:NO] )
+ {
+ return false;
+ }
}
+
+ return true;
}
diff --git a/app/qml/form/editors/MMFormRichTextViewer.qml b/app/qml/form/editors/MMFormRichTextViewer.qml
index 647c59f77..2b2c5ea3a 100644
--- a/app/qml/form/editors/MMFormRichTextViewer.qml
+++ b/app/qml/form/editors/MMFormRichTextViewer.qml
@@ -48,7 +48,12 @@ MMPrivateComponents.MMBaseInput {
leftPadding: __style.margin20
rightPadding: __style.margin20
- onLinkActivated: ( link ) => __inputUtils.openLink( root._fieldHomePath, link.toString() )
+ onLinkActivated: function ( link ) {
+ if ( !__inputUtils.openLink( root._fieldHomePath, link.toString( ) ) )
+ {
+ __notificationModel.addError( "Could not open the file. It may not exist, could be invalid, or there might be no application available to open it." )
+ }
+ }
}
}
}
diff --git a/app/qml/form/editors/MMFormTextMultilineEditor.qml b/app/qml/form/editors/MMFormTextMultilineEditor.qml
index bac481296..04942d380 100644
--- a/app/qml/form/editors/MMFormTextMultilineEditor.qml
+++ b/app/qml/form/editors/MMFormTextMultilineEditor.qml
@@ -118,7 +118,13 @@ MMPrivateComponents.MMBaseInput {
radius: __style.radius12
}
- onLinkActivated: ( link ) => __inputUtils.openLink( root._fieldHomePath, link.toString() )
+ onLinkActivated: function ( link ) {
+ if ( !__inputUtils.openLink( root._fieldHomePath, link.toString( ) ) )
+ {
+ __notificationModel.addError( "Could not open the file. It may not exist, could be invalid, or there might be no application available to open it." )
+ }
+ }
+
onTextChanged: root.editorValueChanged( textArea.text, textArea.text === "" )
}
From 21023ece0d522a33513ed6dd0b10cb261bfe1f3c Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Thu, 25 Apr 2024 09:12:48 -0300
Subject: [PATCH 13/27] second part of post review changes
---
app/androidutils.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/androidutils.cpp b/app/androidutils.cpp
index d550fb6d1..bf352074c 100644
--- a/app/androidutils.cpp
+++ b/app/androidutils.cpp
@@ -233,7 +233,6 @@ bool AndroidUtils::openFile( const QString &filePath )
#ifdef ANDROID
auto activity = QJniObject( QNativeInterface::QAndroidApplication::context() );
QJniObject jFilePath = QJniObject::fromString( filePath );
- // Ensure the method signature includes 'Z' to indicate a boolean return type.
result = activity.callMethod( "openFile", "(Ljava/lang/String;)Z", jFilePath.object() );
#endif
return result;
From af25a7554c3657590cad7a54b3245c0fa812bf76 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Thu, 25 Apr 2024 09:16:44 -0300
Subject: [PATCH 14/27] third part of post review changes
---
app/inpututils.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index e88641058..25326efdd 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2185,9 +2185,11 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
bool InputUtils::openLink( const QString &homePath, const QString &link )
>>>>>>> 247d842d (first part of post review changes)
{
- if ( link.startsWith( "project://" ) )
+ QString LOCAL_FILE_PREFIX = "project://";
+
+ if ( link.startsWith( LOCAL_FILE_PREFIX ) )
{
- QString relativePath = link.mid( QString( "project://" ).length() );
+ QString relativePath = link.mid( QString( LOCAL_FILE_PREFIX ).length() );
QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
if ( !fileExists( absoluteLinkPath ) )
{
From 61c01f6a18b6d4f18043653fa9b8a944746a7198 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Thu, 2 May 2024 12:03:43 -0300
Subject: [PATCH 15/27] java fix
---
app/android/src/uk/co/lutraconsulting/InputActivity.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/android/src/uk/co/lutraconsulting/InputActivity.java b/app/android/src/uk/co/lutraconsulting/InputActivity.java
index c77aa3035..a8607eba6 100644
--- a/app/android/src/uk/co/lutraconsulting/InputActivity.java
+++ b/app/android/src/uk/co/lutraconsulting/InputActivity.java
@@ -130,7 +130,7 @@ public void hideSplashScreen()
keepSplashScreenVisible = false;
}
- public bool openFile( String filePath ) {
+ public boolean openFile( String filePath ) {
File file = new File( filePath );
if ( !file.exists() ) {
From 901f502db7bc701d9780544eba72e1eb3a91c99f Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Fri, 3 May 2024 09:13:30 -0300
Subject: [PATCH 16/27] fixing windows build
---
app/ios/iosutils.cpp | 7 -------
1 file changed, 7 deletions(-)
diff --git a/app/ios/iosutils.cpp b/app/ios/iosutils.cpp
index 193ad30ea..2612d5224 100644
--- a/app/ios/iosutils.cpp
+++ b/app/ios/iosutils.cpp
@@ -67,7 +67,6 @@ QVector IosUtils::getSafeArea()
return QVector();
}
-<<<<<<< HEAD
QString IosUtils::getManufacturer()
{
#ifdef Q_OS_IOS
@@ -90,11 +89,5 @@ bool IosUtils::openFile( const QString &filePath )
return openFileImpl( filePath );
#else
return false;
-=======
-bool IosUtils::openFile( const QString &filePath )
-{
-#ifdef Q_OS_IOS
- return openFileImpl( filePath );
->>>>>>> 247d842d (first part of post review changes)
#endif
}
From 8ca2f99f29a7d3ff959e5bb04d5d203139f218d5 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Fri, 3 May 2024 09:17:52 -0300
Subject: [PATCH 17/27] layout fix
---
app/ios/iosutils.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/ios/iosutils.cpp b/app/ios/iosutils.cpp
index 2612d5224..e2144d503 100644
--- a/app/ios/iosutils.cpp
+++ b/app/ios/iosutils.cpp
@@ -88,6 +88,6 @@ bool IosUtils::openFile( const QString &filePath )
#ifdef Q_OS_IOS
return openFileImpl( filePath );
#else
- return false;
+ return false;
#endif
}
From c438009d3d20c043f2e6505bf809b33664113884 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Tue, 7 May 2024 09:22:01 -0300
Subject: [PATCH 18/27] local_file_prefix to header file
---
app/inpututils.cpp | 2 --
app/inpututils.h | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index 25326efdd..dfd5d64dd 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2185,8 +2185,6 @@ void InputUtils::openLink( const QString &homePath, const QString &link )
bool InputUtils::openLink( const QString &homePath, const QString &link )
>>>>>>> 247d842d (first part of post review changes)
{
- QString LOCAL_FILE_PREFIX = "project://";
-
if ( link.startsWith( LOCAL_FILE_PREFIX ) )
{
QString relativePath = link.mid( QString( LOCAL_FILE_PREFIX ).length() );
diff --git a/app/inpututils.h b/app/inpututils.h
index 22792c86c..bc2c8deb0 100644
--- a/app/inpututils.h
+++ b/app/inpututils.h
@@ -610,6 +610,8 @@ class InputUtils: public QObject
static QUrl iconFromGeometry( const Qgis::GeometryType &geometry );
AndroidUtils *mAndroidUtils = nullptr; // not owned
+
+ const QString LOCAL_FILE_PREFIX = QStringLiteral( "project://" );
};
#endif // INPUTUTILS_H
From bf1bcb3c14bdac284dc7d1b86725d15deb709976 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Wed, 15 May 2024 07:16:20 -0300
Subject: [PATCH 19/27] adjustments for newer android versions
---
.../uk/co/lutraconsulting/InputActivity.java | 26 ++++++++++++-------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/app/android/src/uk/co/lutraconsulting/InputActivity.java b/app/android/src/uk/co/lutraconsulting/InputActivity.java
index a8607eba6..d762d3a50 100644
--- a/app/android/src/uk/co/lutraconsulting/InputActivity.java
+++ b/app/android/src/uk/co/lutraconsulting/InputActivity.java
@@ -28,6 +28,7 @@
import android.graphics.Insets;
import android.graphics.Color;
+import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.content.ActivityNotFoundException;
@@ -41,6 +42,7 @@
public class InputActivity extends QtActivity
{
private static final String TAG = "Mergin Maps Input Activity";
+ private static final int OPEN_FILE_REQUEST_CODE = 1;
private boolean keepSplashScreenVisible = true;
@Override
@@ -133,13 +135,15 @@ public void hideSplashScreen()
public boolean openFile( String filePath ) {
File file = new File( filePath );
- if ( !file.exists() ) {
+ if ( !file.exists() )
+ {
return false;
}
Intent showFileIntent = new Intent( Intent.ACTION_VIEW );
- try {
+ try
+ {
Uri fileUri = FileProvider.getUriForFile( this, "uk.co.lutraconsulting.fileprovider", file );
showFileIntent.setData( fileUri );
@@ -147,17 +151,21 @@ public boolean openFile( String filePath ) {
// FLAG_GRANT_READ_URI_PERMISSION grants temporary read permission to the content URI.
// FLAG_ACTIVITY_NEW_TASK is used when starting an Activity from a non-Activity context.
showFileIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION );
- } catch ( IllegalArgumentException e ) {
+ }
+ catch ( IllegalArgumentException e )
+ {
return false;
}
- if ( showFileIntent.resolveActivity( getPackageManager() ) != null ) {
- startActivity( showFileIntent );
- } else {
- return false;
+ try
+ {
+ startActivityForResult( showFileIntent, OPEN_FILE_REQUEST_CODE );
+ return true;
+ }
+ catch ( ActivityNotFoundException ex )
+ {
+ return false;
}
-
- return true;
}
public void quitGracefully()
From a356ed6fc7c985e00609944e63158278c370ff9d Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Wed, 15 May 2024 07:25:13 -0300
Subject: [PATCH 20/27] inputactivity code layout adjust
---
app/android/src/uk/co/lutraconsulting/InputActivity.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/android/src/uk/co/lutraconsulting/InputActivity.java b/app/android/src/uk/co/lutraconsulting/InputActivity.java
index d762d3a50..a6ea234fc 100644
--- a/app/android/src/uk/co/lutraconsulting/InputActivity.java
+++ b/app/android/src/uk/co/lutraconsulting/InputActivity.java
@@ -159,12 +159,12 @@ public boolean openFile( String filePath ) {
try
{
- startActivityForResult( showFileIntent, OPEN_FILE_REQUEST_CODE );
- return true;
+ startActivityForResult( showFileIntent, OPEN_FILE_REQUEST_CODE );
+ return true;
}
catch ( ActivityNotFoundException ex )
{
- return false;
+ return false;
}
}
From 7d5fef66bee66bfc0071a0aee52f8be4c4e96f5d Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Wed, 15 May 2024 07:39:50 -0300
Subject: [PATCH 21/27] post rebase adjusts
---
app/inpututils.cpp | 57 +++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 31 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index dfd5d64dd..feabb1349 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2158,8 +2158,6 @@ QList InputUtils::parsePositionUpdates( const QString &data )
return parsedUpdates;
}
-<<<<<<< HEAD
-<<<<<<< HEAD
QString InputUtils::getManufacturer()
{
#ifdef Q_OS_ANDROID
@@ -2180,42 +2178,39 @@ QString InputUtils::getDeviceModel()
return QStringLiteral( "N/A" );
}
-void InputUtils::openLink( const QString &homePath, const QString &link )
-=======
bool InputUtils::openLink( const QString &homePath, const QString &link )
->>>>>>> 247d842d (first part of post review changes)
{
- if ( link.startsWith( LOCAL_FILE_PREFIX ) )
- {
- QString relativePath = link.mid( QString( LOCAL_FILE_PREFIX ).length() );
- QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
- if ( !fileExists( absoluteLinkPath ) )
+ if ( link.startsWith( LOCAL_FILE_PREFIX ) )
{
- return false;
- }
+ QString relativePath = link.mid( QString( LOCAL_FILE_PREFIX ).length() );
+ QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+ if ( !fileExists( absoluteLinkPath ) )
+ {
+ return false;
+ }
#ifdef Q_OS_ANDROID
- if ( !mAndroidUtils->openFile( absoluteLinkPath ) )
- {
- return false;
- }
+ if ( !mAndroidUtils->openFile( absoluteLinkPath ) )
+ {
+ return false;
+ }
#elif defined(Q_OS_IOS)
- if ( ! IosUtils::openFile( absoluteLinkPath ) )
- {
- return false;
- }
+ if ( ! IosUtils::openFile( absoluteLinkPath ) )
+ {
+ return false;
+ }
#else
- // Desktop environments
- QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
- if ( !QDesktopServices::openUrl( fileUrl ) )
+ // Desktop environments
+ QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
+ if ( !QDesktopServices::openUrl( fileUrl ) )
+ {
+ return false;
+ }
+#endif
+ }
+ else
{
- return false;
+ QDesktopServices::openUrl( QUrl( link ) );
}
-#endif
- }
- else
- {
- QDesktopServices::openUrl( QUrl( link ) );
- }
- return true;
+ return true;
}
From e116979ad5fb933623ea56da9cb9101630e927d6 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Wed, 15 May 2024 07:49:07 -0300
Subject: [PATCH 22/27] android manifest update and code layout fix
---
app/inpututils.cpp | 52 +++++++++++++-------------
app/ios/iosutils.cpp | 2 +-
app/ios/iosutils.mm | 8 ++--
cmake_templates/AndroidManifest.xml.in | 11 ++++--
4 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/app/inpututils.cpp b/app/inpututils.cpp
index feabb1349..aad2eacbe 100644
--- a/app/inpututils.cpp
+++ b/app/inpututils.cpp
@@ -2180,37 +2180,37 @@ QString InputUtils::getDeviceModel()
bool InputUtils::openLink( const QString &homePath, const QString &link )
{
- if ( link.startsWith( LOCAL_FILE_PREFIX ) )
+ if ( link.startsWith( LOCAL_FILE_PREFIX ) )
+ {
+ QString relativePath = link.mid( QString( LOCAL_FILE_PREFIX ).length() );
+ QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
+ if ( !fileExists( absoluteLinkPath ) )
{
- QString relativePath = link.mid( QString( LOCAL_FILE_PREFIX ).length() );
- QString absoluteLinkPath = homePath + QDir::separator() + relativePath;
- if ( !fileExists( absoluteLinkPath ) )
- {
- return false;
- }
+ return false;
+ }
#ifdef Q_OS_ANDROID
- if ( !mAndroidUtils->openFile( absoluteLinkPath ) )
- {
- return false;
- }
+ if ( !mAndroidUtils->openFile( absoluteLinkPath ) )
+ {
+ return false;
+ }
#elif defined(Q_OS_IOS)
- if ( ! IosUtils::openFile( absoluteLinkPath ) )
- {
- return false;
- }
-#else
- // Desktop environments
- QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
- if ( !QDesktopServices::openUrl( fileUrl ) )
- {
- return false;
- }
-#endif
+ if ( ! IosUtils::openFile( absoluteLinkPath ) )
+ {
+ return false;
}
- else
+#else
+ // Desktop environments
+ QUrl fileUrl = QUrl::fromLocalFile( absoluteLinkPath );
+ if ( !QDesktopServices::openUrl( fileUrl ) )
{
- QDesktopServices::openUrl( QUrl( link ) );
+ return false;
}
+#endif
+ }
+ else
+ {
+ QDesktopServices::openUrl( QUrl( link ) );
+ }
- return true;
+ return true;
}
diff --git a/app/ios/iosutils.cpp b/app/ios/iosutils.cpp
index e2144d503..e261ac7c6 100644
--- a/app/ios/iosutils.cpp
+++ b/app/ios/iosutils.cpp
@@ -86,7 +86,7 @@ QString IosUtils::getDeviceModel()
bool IosUtils::openFile( const QString &filePath )
{
#ifdef Q_OS_IOS
- return openFileImpl( filePath );
+ return openFileImpl( filePath );
#else
return false;
#endif
diff --git a/app/ios/iosutils.mm b/app/ios/iosutils.mm
index 76fcf27f1..f3b62d89c 100644
--- a/app/ios/iosutils.mm
+++ b/app/ios/iosutils.mm
@@ -14,16 +14,16 @@
***************************************************************************/
#include
-<<<<<<< HEAD
+<<< <<< < HEAD
#include
-=======
+== == == =
#import
#import
#include
->>>>>>> 05801f46 (ios pdf viewing)
+ >>> >>> > 05801f46( ios pdf viewing )
#include "iosutils.h"
-void IosUtils::setIdleTimerDisabled()
+ void IosUtils::setIdleTimerDisabled()
{
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
diff --git a/cmake_templates/AndroidManifest.xml.in b/cmake_templates/AndroidManifest.xml.in
index 68ccd01cd..0a5c6ded4 100644
--- a/cmake_templates/AndroidManifest.xml.in
+++ b/cmake_templates/AndroidManifest.xml.in
@@ -100,10 +100,15 @@
-
+
-
+
-
+
+
+
+
+
+
From 8524155e1ed3843ba98a7de2872055c3371dde61 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Wed, 15 May 2024 07:53:53 -0300
Subject: [PATCH 23/27] iosutils.mm fix
---
app/ios/iosutils.mm | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/app/ios/iosutils.mm b/app/ios/iosutils.mm
index f3b62d89c..28c0b7fb8 100644
--- a/app/ios/iosutils.mm
+++ b/app/ios/iosutils.mm
@@ -14,16 +14,13 @@
***************************************************************************/
#include
-<<< <<< < HEAD
#include
-== == == =
#import
#import
#include
- >>> >>> > 05801f46( ios pdf viewing )
#include "iosutils.h"
- void IosUtils::setIdleTimerDisabled()
+void IosUtils::setIdleTimerDisabled()
{
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
From bfb8e443fd8bd89975e4ea42a3423cf8547305f6 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Wed, 15 May 2024 09:10:46 -0300
Subject: [PATCH 24/27] start activity in openFile method
---
.../src/uk/co/lutraconsulting/InputActivity.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/app/android/src/uk/co/lutraconsulting/InputActivity.java b/app/android/src/uk/co/lutraconsulting/InputActivity.java
index a6ea234fc..ac6523204 100644
--- a/app/android/src/uk/co/lutraconsulting/InputActivity.java
+++ b/app/android/src/uk/co/lutraconsulting/InputActivity.java
@@ -42,7 +42,6 @@
public class InputActivity extends QtActivity
{
private static final String TAG = "Mergin Maps Input Activity";
- private static final int OPEN_FILE_REQUEST_CODE = 1;
private boolean keepSplashScreenVisible = true;
@Override
@@ -157,15 +156,16 @@ public boolean openFile( String filePath ) {
return false;
}
- try
+ if ( showFileIntent.resolveActivity( getPackageManager() ) != null )
{
- startActivityForResult( showFileIntent, OPEN_FILE_REQUEST_CODE );
- return true;
+ startActivity( showFileIntent );
}
- catch ( ActivityNotFoundException ex )
+ else
{
return false;
}
+
+ return true;
}
public void quitGracefully()
From 8eaff6feb74d1095b6b4217f52211d5104fc3175 Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Mon, 20 May 2024 00:36:43 -0300
Subject: [PATCH 25/27] manifest update
---
cmake_templates/AndroidManifest.xml.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/cmake_templates/AndroidManifest.xml.in b/cmake_templates/AndroidManifest.xml.in
index 0a5c6ded4..246f91f7f 100644
--- a/cmake_templates/AndroidManifest.xml.in
+++ b/cmake_templates/AndroidManifest.xml.in
@@ -107,6 +107,7 @@
+
From d3293dbe25074d9b0f19d6f3796bdb13e5f4ef5a Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Mon, 20 May 2024 08:50:34 -0300
Subject: [PATCH 26/27] manifest update
---
cmake_templates/AndroidManifest.xml.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/cmake_templates/AndroidManifest.xml.in b/cmake_templates/AndroidManifest.xml.in
index 246f91f7f..fc7d213c7 100644
--- a/cmake_templates/AndroidManifest.xml.in
+++ b/cmake_templates/AndroidManifest.xml.in
@@ -108,6 +108,7 @@
+
From e909344b444dec08fb576cf20725374b9ff7e45c Mon Sep 17 00:00:00 2001
From: VitorVieiraZ
Date: Thu, 23 May 2024 08:50:50 -0300
Subject: [PATCH 27/27] manifest adjustment
---
cmake_templates/AndroidManifest.xml.in | 2 --
1 file changed, 2 deletions(-)
diff --git a/cmake_templates/AndroidManifest.xml.in b/cmake_templates/AndroidManifest.xml.in
index fc7d213c7..0a5c6ded4 100644
--- a/cmake_templates/AndroidManifest.xml.in
+++ b/cmake_templates/AndroidManifest.xml.in
@@ -107,8 +107,6 @@
-
-