Skip to content

Commit

Permalink
Issue 6: Tap into invocation framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ragaeeb committed Aug 1, 2013
1 parent 76bafc7 commit f42f1f3
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 57 deletions.
41 changes: 41 additions & 0 deletions assets/InvokedPage.qml
Original file line number Diff line number Diff line change
@@ -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();
}
}
]
}
13 changes: 12 additions & 1 deletion bar-descriptor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,15 @@
<permission>access_shared</permission>
<env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>
<env var="CASCADES_THEME" value="bright"/>
</qnx>

<invoke-target id="com.canadainc.Exporter">
<invoke-target-type>card.composer</invoke-target-type>
<invoke-target-name>Exporter</invoke-target-name>
<icon><image>icon.png</image></icon>

<filter>
<action>bb.action.SHARE</action>
<mime-type>text/plain</mime-type>
</filter>
</invoke-target>
</qnx>
12 changes: 3 additions & 9 deletions precompiled.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
#include <QFile>
#include <QSettings>
#include <QThreadPool>

#include <bb/cascades/AbstractPane>
#include <bb/cascades/Application>
#include <bb/cascades/Control>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/SceneCover>

#include <bb/pim/contacts/ContactService>

#include <bb/cascades/pickers/FilePicker>

#include <bb/pim/account/AccountService>
#include <bb/pim/contacts/ContactService>

#include <bb/pim/message/MessageFilter>
#include <bb/pim/message/MessageService>

#include <bb/system/Clipboard>
#include <bb/system/SystemProgressDialog>
#include <bb/system/SystemToast>
#include <bb/system/CardDoneMessage>
48 changes: 45 additions & 3 deletions src/ApplicationUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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<bb::cascades::pickers::FilePicker>("CustomComponent", 1, 0, "FilePicker");
qmlRegisterUncreatableType<bb::cascades::pickers::FileType>("CustomComponent", 1, 0, "FileType", "Can't instantiate");
qmlRegisterUncreatableType<bb::cascades::pickers::FilePickerMode>("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<AbstractPane>();
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() );
}


Expand Down Expand Up @@ -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();
Expand Down
28 changes: 3 additions & 25 deletions src/ExportSMS.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "precompiled.h"

#include "ExportSMS.h"
#include "IOUtils.h"
#include "Logger.h"

namespace exportui {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/applicationui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "LazySceneCover.h"
#include "Persistance.h"

#include <bb/system/InvokeManager>

class QRunnable;

namespace bb {
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
};

}
Expand Down
49 changes: 31 additions & 18 deletions translations/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,48 @@ This app makes it really easy to select which conversations you want to share an
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>InvokedPage</name>
<message>
<location filename="../assets/InvokedPage.qml" line="21"/>
<source>Enter Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/InvokedPage.qml" line="31"/>
<source>Successfully saved file: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/InvokedPage.qml" line="31"/>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<location filename="../src/ExportSMS.cpp" line="61"/>
<location filename="../src/ExportSMS.cpp" line="62"/>
<source>%1 %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="64"/>
<location filename="../src/ExportSMS.cpp" line="65"/>
<source>%1

</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="79"/>
<location filename="../src/ExportSMS.cpp" line="80"/>
<source>%1: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="81"/>
<location filename="../src/ExportSMS.cpp" line="82"/>
<source>%1 - %2: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="111"/>
<source>%1/%2.txt</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SettingsPage</name>
Expand Down Expand Up @@ -259,50 +272,50 @@ Tap the first message, then tap the last message and all of the ones in between
<context>
<name>exportui::ApplicationUI</name>
<message>
<location filename="../src/ApplicationUI.cpp" line="41"/>
<location filename="../src/ApplicationUI.cpp" line="83"/>
<source>You</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="58"/>
<location filename="../src/ApplicationUI.cpp" line="100"/>
<source>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.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="61"/>
<location filename="../src/ApplicationUI.cpp" line="103"/>
<source>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.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="64"/>
<location filename="../src/ApplicationUI.cpp" line="106"/>
<source>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.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="99"/>
<location filename="../src/ApplicationUI.cpp" line="141"/>
<source>Export complete</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>exportui::ExportSMS</name>
<message>
<location filename="../src/ExportSMS.cpp" line="19"/>
<location filename="../src/ExportSMS.cpp" line="20"/>
<source>0% complete...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="26"/>
<location filename="../src/ExportSMS.cpp" line="27"/>
<source>MMM d/yy, hh:mm:ss</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="31"/>
<location filename="../src/ExportSMS.cpp" line="32"/>
<source>hh:mm:ss</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="132"/>
<location filename="../src/ExportSMS.cpp" line="110"/>
<source>%1% complete...</source>
<translation type="unfinished"></translation>
</message>
Expand Down

0 comments on commit f42f1f3

Please sign in to comment.