From f42f1f3fde7a0401a045d5d9c029eaab2dc0e2ad Mon Sep 17 00:00:00 2001 From: Ragaeeb Haq <7464039+ragaeeb@users.noreply.github.com> Date: Thu, 1 Aug 2013 18:34:33 -0400 Subject: [PATCH] Issue 6: Tap into invocation framework --- assets/InvokedPage.qml | 41 +++++++++++++++++++++++++++++++++ bar-descriptor.xml | 13 ++++++++++- precompiled.h | 12 +++------- src/ApplicationUI.cpp | 48 ++++++++++++++++++++++++++++++++++++--- src/ExportSMS.cpp | 28 +++-------------------- src/applicationui.hpp | 8 ++++++- translations/Exporter.ts | 49 +++++++++++++++++++++++++--------------- 7 files changed, 142 insertions(+), 57 deletions(-) create mode 100644 assets/InvokedPage.qml diff --git a/assets/InvokedPage.qml b/assets/InvokedPage.qml new file mode 100644 index 0000000..bd7526c --- /dev/null +++ b/assets/InvokedPage.qml @@ -0,0 +1,41 @@ +import bb.cascades 1.0 +import CustomComponent 1.0 + +BasePage +{ + signal finished(); + property string data + + onDataChanged: { + var tokens = data.split("\n"); + filePicker.defaultSaveFileNames = [ tokens[0].substr(0, 40) + ".txt", "Document.txt" ]; + + filePicker.open(); + } + + attachedObjects: [ + FilePicker + { + id: filePicker + mode: FilePickerMode.Saver + title : qsTr("Enter Name") + Retranslate.onLanguageChanged + defaultType: FileType.Document + allowOverwrite: true + filter: ["*.txt"] + directories: persist.getValueFor("output") + + onFileSelected : { + var result = selectedFiles[0]; + app.saveTextData(result, data); + + persist.showBlockingToast( qsTr("Successfully saved file: %1").arg(result), qsTr("OK") ); + + finished(); + } + + onCanceled: { + finished(); + } + } + ] +} diff --git a/bar-descriptor.xml b/bar-descriptor.xml index 0e9fa24..c1b3909 100755 --- a/bar-descriptor.xml +++ b/bar-descriptor.xml @@ -103,4 +103,15 @@ access_shared - + + + card.composer + Exporter + icon.png + + + bb.action.SHARE + text/plain + + + \ No newline at end of file diff --git a/precompiled.h b/precompiled.h index 9bcfe8a..8b6ed3c 100755 --- a/precompiled.h +++ b/precompiled.h @@ -1,21 +1,15 @@ -#include -#include -#include - #include #include #include #include #include -#include - #include -#include +#include + #include #include -#include #include -#include +#include diff --git a/src/ApplicationUI.cpp b/src/ApplicationUI.cpp index b99a10d..6fdc2c8 100755 --- a/src/ApplicationUI.cpp +++ b/src/ApplicationUI.cpp @@ -5,8 +5,8 @@ #include "ContactUtil.h" #include "ExportSMS.h" #include "ImportSMS.h" -#include "IOUtils.h" #include "InvocationUtils.h" +#include "IOUtils.h" #include "Logger.h" #include "MessageImporter.h" @@ -18,21 +18,58 @@ using namespace bb::pim::message; using namespace canadainc; ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app), m_cover("Cover.qml") +{ + switch ( m_invokeManager.startupMode() ) + { + case ApplicationStartupMode::LaunchApplication: + initRoot(); + break; + + case ApplicationStartupMode::InvokeCard: + connect( &m_invokeManager, SIGNAL( invoked(bb::system::InvokeRequest const&) ), this, SLOT( invoked(bb::system::InvokeRequest const&) ) ); + break; + + default: + exit(0); + break; + } +} + + +QObject* ApplicationUI::initRoot(QString const& qmlSource) { qmlRegisterType("CustomComponent", 1, 0, "FilePicker"); qmlRegisterUncreatableType("CustomComponent", 1, 0, "FileType", "Can't instantiate"); qmlRegisterUncreatableType("CustomComponent", 1, 0, "FilePickerMode", "Can't instantiate"); - QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); + QmlDocument *qml = QmlDocument::create( QString("asset:///%1").arg(qmlSource) ).parent(this); qml->setContextProperty("app", this); qml->setContextProperty("persist", &m_persistance); AbstractPane* root = qml->createRootObject(); - app->setScene(root); + Application::instance()->setScene(root); connect( this, SIGNAL( initialize() ), this, SLOT( init() ), Qt::QueuedConnection ); // async startup emit initialize(); + + return root; +} + + +void ApplicationUI::invoked(bb::system::InvokeRequest const& request) +{ + QObject* root = initRoot("InvokedPage.qml"); + + QString text = QString::fromUtf8( request.data().data() ); + root->setProperty("data", text); + + connect( root, SIGNAL( finished() ), this, SLOT( cardFinished() ) ); +} + + +void ApplicationUI::cardFinished() { + m_invokeManager.sendCardDone( CardDoneMessage() ); } @@ -109,6 +146,11 @@ void ApplicationUI::exportSMS(QStringList const& conversationIds, qint64 account } +void ApplicationUI::saveTextData(QString const& file, QString const& data) { + IOUtils::writeTextFile(file, data); +} + + void ApplicationUI::loadAccounts() { AccountImporter* ai = new AccountImporter(); diff --git a/src/ExportSMS.cpp b/src/ExportSMS.cpp index ec18391..7bd770d 100644 --- a/src/ExportSMS.cpp +++ b/src/ExportSMS.cpp @@ -1,6 +1,7 @@ #include "precompiled.h" #include "ExportSMS.h" +#include "IOUtils.h" #include "Logger.h" namespace exportui { @@ -96,36 +97,13 @@ void ExportSMS::run() QStringList keys = map.keys(); QString outputPath = settings.value("output").toString(); - QIODevice::OpenMode om = QIODevice::WriteOnly | QIODevice::Append; - - int duplicateAction = settings.value("duplicateAction").toInt(); - if (duplicateAction == 1) { - om = QIODevice::WriteOnly; - } - + bool replace = settings.value("duplicateAction").toInt() == 1; int total = keys.size(); for (int i = 0; i < total; i++) { QString key = keys[i]; - QFile outputFile( QObject::tr("%1/%2.txt").arg(outputPath).arg(key) ); - - bool alreadyExists = outputFile.exists() && duplicateAction != 1; - outputFile.open(om); - - if ( outputFile.isOpen() ) - { - QTextStream stream(&outputFile); - - if (alreadyExists) { - stream << "\r\n\r\n"; - } - - stream << map[key]; - outputFile.close(); - } else { - LOGGER("Could not open " << key << "for writing!"); - } + canadainc::IOUtils::writeTextFile( QString("%1/%2.txt").arg(outputPath).arg(key), map[key], replace ); int progress = (double)i/total * 100; m_progress.setProgress(progress); diff --git a/src/applicationui.hpp b/src/applicationui.hpp index 1fb65df..707ede6 100755 --- a/src/applicationui.hpp +++ b/src/applicationui.hpp @@ -4,6 +4,8 @@ #include "LazySceneCover.h" #include "Persistance.h" +#include + class QRunnable; namespace bb { @@ -22,11 +24,12 @@ class ApplicationUI : public QObject { Q_OBJECT + bb::system::InvokeManager m_invokeManager; Persistance m_persistance; LazySceneCover m_cover; ApplicationUI(bb::cascades::Application *app); - void startThread(QRunnable* qr); + QObject* initRoot(QString const& qml="main.qml"); Q_SIGNALS: void initialize(); @@ -39,6 +42,8 @@ class ApplicationUI : public QObject private slots: void onExportCompleted(); void init(); + void invoked(bb::system::InvokeRequest const& request); + void cardFinished(); public: static void create(bb::cascades::Application *app); @@ -48,6 +53,7 @@ private slots: Q_INVOKABLE void getMessagesFor(QString const& conversationKey, qint64 accountId); Q_INVOKABLE void getConversationsFor(qint64 accountId); Q_INVOKABLE void exportSMS(QStringList const& conversationIds, qint64 accountId); + Q_INVOKABLE void saveTextData(QString const& file, QString const& data); }; } diff --git a/translations/Exporter.ts b/translations/Exporter.ts index 575b8c3..81b2a81 100755 --- a/translations/Exporter.ts +++ b/translations/Exporter.ts @@ -83,35 +83,48 @@ This app makes it really easy to select which conversations you want to share an + + InvokedPage + + + Enter Name + + + + + Successfully saved file: %1 + + + + + OK + + + QObject - + %1 %2 - + %1 - + %1: %2 - + %1 - %2: %3 - - - %1/%2.txt - - SettingsPage @@ -259,27 +272,27 @@ Tap the first message, then tap the last message and all of the ones in between exportui::ApplicationUI - + You - + Warning: It seems like the app does not have access to your Email/SMS messages Folder. This permission is needed for the app to access the SMS and email services it needs to render and process them so they can be saved. If you leave this permission off, some features may not work properly. Select OK to launch the Application Permissions screen where you can turn these settings on. - + Warning: It seems like the app does not have access to your Shared Folder. This permission is needed for the app to access the file system so that it can save the text messages as files. If you leave this permission off, some features may not work properly. - + Warning: It seems like the app does not have access to your contacts. This permission is needed for the app to access your address book so we can properly display the names of the contacts in the output files. If you leave this permission off, some features may not work properly. Select OK to launch the Application Permissions screen where you can turn these settings on. - + Export complete @@ -287,22 +300,22 @@ Tap the first message, then tap the last message and all of the ones in between exportui::ExportSMS - + 0% complete... - + MMM d/yy, hh:mm:ss - + hh:mm:ss - + %1% complete...