-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from KnowikiApps/sharing-experimental
PR - Sharing experimental
- Loading branch information
Showing
18 changed files
with
668 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<paths> | ||
<files-path path="csv/" name="sharable" /> | ||
</paths> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.