Skip to content

Commit

Permalink
Merge pull request #84 from KnowikiApps/sharing-experimental
Browse files Browse the repository at this point in the history
PR - Sharing experimental
  • Loading branch information
KnowikiApps authored Mar 11, 2024
2 parents a20d61e + fd0f61c commit 8d05221
Show file tree
Hide file tree
Showing 18 changed files with 668 additions and 5 deletions.
12 changes: 12 additions & 0 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@

<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:extractNativeLibs="true" android:icon="@drawable/icon">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.knowikiapps.SCaLE.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>

<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down Expand Up @@ -72,4 +82,6 @@
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
</application>



</manifest>
60 changes: 60 additions & 0 deletions android/androidshareutils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//=============================================================================
// Copyright (c) 2014 Nicolas Froment

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//=============================================================================
#include "androidshareutils.h"

#include <QtAndroidExtras/QAndroidJniObject>

#include "contactexporter.h"


AndroidShareUtils::AndroidShareUtils(QQuickItem* parent) : PlatformShareUtils(parent)
{

}

void AndroidShareUtils::share(const QString &text, const QUrl &url)
{
QAndroidJniObject jsText = QAndroidJniObject::fromString(text);
QAndroidJniObject jsUrl = QAndroidJniObject::fromString(url.toString());
QAndroidJniObject::callStaticMethod<void>("com/lasconic/QShareUtils",
"share",
"(Ljava/lang/String;Ljava/lang/String;)V",
jsText.object<jstring>(), jsUrl.object<jstring>());
}

void AndroidShareUtils::shareJustText(const QString &text)
{
QAndroidJniObject jsText = QAndroidJniObject::fromString(text);
QAndroidJniObject::callStaticMethod<void>("com/lasconic/QShareUtils",
"shareJustText",
"(Ljava/lang/String;)V",
jsText.object<jstring>());
}

void AndroidShareUtils::shareTextAsFile(const QString &vals) {
writeStringToFile(vals);
QAndroidJniObject jsText = QAndroidJniObject::fromString(getFilePath());
QAndroidJniObject::callStaticMethod<void>("com/lasconic/QShareUtils",
"shareFile",
"(Ljava/lang/String;)V",
jsText.object<jstring>());
}
39 changes: 39 additions & 0 deletions android/androidshareutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//=============================================================================
// Copyright (c) 2014 Nicolas Froment

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//=============================================================================

#ifndef ANDROIDSHAREUTILS_H
#define ANDROIDSHAREUTILS_H

#include "shareutils.h"

class AndroidShareUtils : public PlatformShareUtils
{
public:
AndroidShareUtils(QQuickItem* parent = 0);
void share(const QString &text, const QUrl &url) override;
void shareJustText(const QString &text) override;
void shareTextAsFile(const QString &vals) override;


};

#endif // ANDROIDSHAREUTILS_H
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ apply plugin: 'com.android.application'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'androidx.appcompat:appcompat:1.1.0'

}

android {
Expand Down
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ org.gradle.jvmargs=-Xmx2048m
# build with the same inputs. However, over time, the cache size will
# grow. Uncomment the following line to enable it.
#org.gradle.caching=true

android.useAndroidX=true
android.enableJetifier=true
3 changes: 3 additions & 0 deletions android/res/xml/filepaths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<paths>
<files-path path="csv/" name="sharable" />
</paths>
87 changes: 87 additions & 0 deletions android/src/com/lasconic/QShareUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//=============================================================================
// Copyright (c) 2014 Nicolas Froment

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//=============================================================================

package com.lasconic;

import org.qtproject.qt5.android.QtNative;

import java.lang.String;
import android.content.Intent;
import android.util.Log;



import androidx.core.content.FileProvider;
import android.content.Context;
import java.io.File;
import android.net.Uri;

public class QShareUtils
{
protected QShareUtils()
{
//Log.d("lasconic", "QShareUtils()");
}

public static void share(String text, String url) {
if (QtNative.activity() == null)
return;
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text + " " + url);
sendIntent.setType("text/plain");
QtNative.activity().startActivity(sendIntent);
}

public static void shareJustText(String text) {
if (QtNative.activity() == null)
return;
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.setType("text/plain");
QtNative.activity().startActivity(sendIntent);
}

public static void shareFile(String filepath)
{
if(QtNative.activity() == null)
return;

File newFile = new File(filepath);


if(!newFile.exists())
return;


Uri contentUri = FileProvider.getUriForFile(QtNative.activity(), "com.knowikiapps.SCaLE.fileprovider", newFile);


Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
intent.setType("text/csv");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
QtNative.activity().startActivity(intent);
}
}
44 changes: 44 additions & 0 deletions contactexporter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "contactexporter.h"

#include <QFile>
#include <QTextStream>
#include <QStandardPaths>
#include <QDebug>
#include <QDir>

void writeStringToFile(const QString &vals) {

auto path {QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/csv/"};

auto fileName{"contacts.csv"};

QDir temp{path};

if (!temp.exists()) {
qDebug() << "Warning, shareable folder does not exist: " << path << "\n";
QDir("").mkdir(path);
}

QFile file(path + fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
qDebug() << "Something broke while trying to write the file\n";
qDebug() << "You tried writing: " << fileName << "\n";
return;
}

QTextStream out(&file);
out << vals;
qDebug() << "Wrote data";
file.close();

}

QString getFilePath() {

auto path {QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/csv/"};

auto fileName{"contacts.csv"};

return path + fileName;

}
11 changes: 11 additions & 0 deletions contactexporter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef CONTACTEXPORTER_H
#define CONTACTEXPORTER_H

#include <QString>


QString getFilePath(); // returns the file path

void writeStringToFile(const QString &vals);

#endif // CONTACTEXPORTER_H
7 changes: 7 additions & 0 deletions cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "shareutils.h"
#include <QZXing.h>
#include <QDebug>
#include <QtWebView/QtWebView>



int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);

qmlRegisterType<ShareUtils> ("com.lasconic", 1, 0, "ShareUtils");


QtWebView::initialize();

QZXing::registerQMLTypes();


QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));

Expand Down
37 changes: 37 additions & 0 deletions ios/iosshareutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//=============================================================================
// Copyright (c) 2014 Nicolas Froment

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//=============================================================================

#ifndef __IOSSHAREUTILS_H__
#define __IOSSHAREUTILS_H__

#include "shareutils.h"

class IosShareUtils : public PlatformShareUtils
{
Q_OBJECT

public:
explicit IosShareUtils(QQuickItem *parent = 0);
Q_INVOKABLE void share(const QString &text, const QUrl &url);
};

#endif
Loading

0 comments on commit 8d05221

Please sign in to comment.