Skip to content

Commit

Permalink
ios pdf viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ committed Apr 23, 2024
1 parent 9431e8f commit b656714
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
42 changes: 25 additions & 17 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <QCoreApplication>
#include <QPermissions>

#include "ios/iosutils.h"

#include "qgsruntimeprofiler.h"
#include "qcoreapplication.h"
#include "qgsgeometrycollection.h"
Expand Down Expand Up @@ -2145,26 +2147,32 @@ QList<QgsPoint> InputUtils::parsePositionUpdates( const QString &data )

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 ) );
}
}
6 changes: 6 additions & 0 deletions app/ios/iosutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ QVector<int> IosUtils::getSafeArea()
#endif
return QVector<int>();
}

void IosUtils::openFile( const QString &filePath )
{
//qWarning() << "test";
openFileImpl( filePath ); //
}
4 changes: 4 additions & 0 deletions app/ios/iosutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class IosUtils: public QObject
static QString readExif( const QString &filepath, const QString &tag );

Q_INVOKABLE QVector<int> getSafeArea();

Q_INVOKABLE static void openFile(const QString &filePath);

signals:
void imageSelected( const QString &imagePath, const QString &code );
Expand All @@ -61,6 +63,8 @@ class IosUtils: public QObject
void setIdleTimerDisabled();

QVector<int> getSafeAreaImpl();

static void openFileImpl(const QString &filePath); //tesrtsasssaa
};

#endif // IOSUTILS_H
35 changes: 35 additions & 0 deletions app/ios/iosutils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
***************************************************************************/

#include <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include <QString>
#include "iosutils.h"
#include "coreutils.h"

void IosUtils::setIdleTimerDisabled()
{
Expand All @@ -40,3 +44,34 @@

return ret;
}

@interface FileOpener : UIViewController <UIDocumentInteractionControllerDelegate>
@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<UIDocumentInteractionControllerDelegate>)viewer;

if (![interactionCtrl presentPreviewAnimated:NO]){
[interactionCtrl presentOptionsMenuFromRect:CGRectZero inView:viewer.view animated:NO];
}
}


2 changes: 1 addition & 1 deletion app/qml/form/editors/MMFormTextMultilineEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ MMBaseInput {
wrapMode: Text.WordWrap

onLinkActivated: function( link ) {
__inputUtils.openLink( root._fieldHomePath, link )
__inputUtils.openLink( root._fieldHomePath, link.toString() )
}

onTextChanged: root.editorValueChanged( text, text === "" )
Expand Down

0 comments on commit b656714

Please sign in to comment.