Skip to content

Commit

Permalink
Issue 11: [Paid feature]: Add support for export multimedia MMS messages
Browse files Browse the repository at this point in the history
Issue 25:	Export sort order incorrect
  • Loading branch information
ragaeeb committed May 16, 2014
1 parent d551a4b commit 1e4cd1d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 86 deletions.
6 changes: 3 additions & 3 deletions assets/ConversationView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ Page
tb.title = qsTr("No messages found") + Retranslate.onLanguageChanged
}

if ( persist.tutorial("tutorialRange"), qsTr("You can select only the messages that you want to export by tapping on them so they are highlighted (the dimmed ones will be skipped). You can also use the 'Select Range' feature from the menu to pick start and end points. Once you have your selection you can choose 'Share' and pick Exporter from the Share menu."), "asset:///images/menu/ic_range.png" ) {}
else if ( persist.tutorial("tutorialSaveAll"), qsTr("To the Save All action at the bottom to save all the messages in one shot!"), "asset:///images/menu/ic_save.png" ) {}
else if ( persist.tutorial("tutorialCopy"), qsTr("You can easily copy only certain converastions and messages and share them with your contacts! Simply select the appropriate bubbles by tapping on them, and then either choose 'Share' to share socially, or choose the 'Copy' action from the menu to copy it to your clipboard so you can paste it."), "asset:///images/menu/ic_copy.png" ) {}
if ( persist.tutorial("tutorialRange", qsTr("You can select only the messages that you want to export by tapping on them so they are highlighted (the dimmed ones will be skipped). You can also use the 'Select Range' feature from the menu to pick start and end points. Once you have your selection you can choose 'Share' and pick Exporter from the Share menu."), "asset:///images/menu/ic_range.png" ) ) {}
else if ( persist.tutorial("tutorialSaveAll", qsTr("To the Save All action at the bottom to save all the messages in one shot!"), "asset:///images/menu/ic_save.png" ) ) {}
else if ( persist.tutorial("tutorialCopy", qsTr("You can easily copy only certain converastions and messages and share them with your contacts! Simply select the appropriate bubbles by tapping on them, and then either choose 'Share' to share socially, or choose the 'Copy' action from the menu to copy it to your clipboard so you can paste it."), "asset:///images/menu/ic_copy.png" ) ) {}
}

onCreationCompleted: {
Expand Down
8 changes: 4 additions & 4 deletions assets/ExportPane.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ NavigationPane
persist.showToast( qsTr("No accounts found. Are you sure you gave the app the permissions it needs?"), qsTr("OK"), "asset:///images/dropdown/ic_account.png" );
}

else if ( persist.tutorial("tutorialExportTxt"), qsTr("These are a list of all the conversations, press-and-hold on one and from the menu choose 'Select More' and then 'Export TXT' to save it. You can also tap on the conversation itself and save only parts of it if you wish."), "asset:///images/menu/ic_export.png" ) {}
else if ( persist.tutorial("tutorialSelectAll"), qsTr("You can tap the Select All button at the bottom of the screen to quickly export all your conversations!"), "asset:///images/menu/selectAll.png" ) {}
else if ( persist.tutorial("tutorialDropDown"), qsTr("Use the dropdown at the top to switch between your mailboxes."), "asset:///images/dropdown/ic_account.png" ) {}
else if ( persist.tutorial("tutorialSettings"), qsTr("There are many customizations you can make to the way the messages are exported. You can do this from the Settings. To access the app settings, swipe-down from the top-bezel and choose 'Settings' from the application menu."), "file:///usr/share/icons/bb_action_install.png" ) {}
else if ( persist.tutorial("tutorialExportTxt", qsTr("These are a list of all the conversations, press-and-hold on one and from the menu choose 'Select More' and then 'Export TXT' to save it. You can also tap on the conversation itself and save only parts of it if you wish."), "asset:///images/menu/ic_export.png" ) ) {}
else if ( persist.tutorial("tutorialSelectAll", qsTr("You can tap the Select All button at the bottom of the screen to quickly export all your conversations!"), "asset:///images/menu/selectAll.png" ) ) {}
else if ( persist.tutorial("tutorialDropDown", qsTr("Use the dropdown at the top to switch between your mailboxes."), "asset:///images/dropdown/ic_account.png" ) ) {}
else if ( persist.tutorial("tutorialSettings", qsTr("There are many customizations you can make to the way the messages are exported. You can do this from the Settings. To access the app settings, swipe-down from the top-bezel and choose 'Settings' from the application menu."), "file:///usr/share/icons/bb_action_install.png" ) ) {}
}

onSelectedValueChanged: {
Expand Down
2 changes: 1 addition & 1 deletion assets/PurchasePane.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ NavigationPane
if (key == "exporter_csv" || key == "exporter_mms")
{
adm.clear();
adm.append({'title': qsTr("CSV Exporting"), 'description': "Support for comma-separated-value format", 'imageSource': "images/ic_export_csv.png", 'sku': "exporter_csv", 'purchased': persist.contains("exporter_csv")});
adm.append({'title': qsTr("CSV Exporting"), 'description': "Support for comma-separated-value format", 'imageSource': "images/menu/ic_export_csv.png", 'sku': "exporter_csv", 'purchased': persist.contains("exporter_csv")});
adm.append({'title': qsTr("MMS Support"), 'description': "Save multimedia content (videos, images, etc.)", 'imageSource': "images/ic_mms.png", 'sku': "exporter_mms", 'purchased': persist.contains("exporter_mms")});
}
}
Expand Down
21 changes: 3 additions & 18 deletions src/ApplicationUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,7 @@ void ApplicationUI::invoked(bb::system::InvokeRequest const& request)
QString name = m.sender().displayableName().trimmed();
root->setProperty( "defaultName", QString("%1.txt").arg(name) );

QString timeFormat = tr("MMM d/yy, hh:mm:ss");

switch ( m_persistance.getValueFor("timeFormat").toInt() )
{
case 1:
timeFormat = tr("hh:mm:ss");
break;

case 2:
timeFormat = "";
break;

default:
break;
}

QString timeFormat = ExportSMS::getTimeFormat( m_persistance.getValueFor("timeFormat").toInt() );
QDateTime t = m_persistance.getValueFor("serverTimestamp").toInt() == 1 ? m.serverTimestamp() : m.deviceTimestamp();

text = tr("%1\r\n\r\n%2: %3").arg( m.sender().address() ).arg( timeFormat.isEmpty() ? "" : t.toString(timeFormat) ).arg( PimUtil::extractText(m) );
Expand Down Expand Up @@ -141,7 +126,7 @@ void ApplicationUI::init()

m_persistance.saveValueFor("output", sdDirectory, false);
}

/*
bool permissionOK = PimUtil::validateEmailSMSAccess( tr("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.") );
if (permissionOK)
Expand All @@ -151,7 +136,7 @@ void ApplicationUI::init()
if (permissionOK) {
PimUtil::validateContactsAccess( tr("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.") );
}
}
} */
}


Expand Down
69 changes: 46 additions & 23 deletions src/ExportSMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,26 @@
#include "PimUtil.h"
#include "TextUtils.h"

namespace {
using namespace bb::pim::message;

QString getTimeFormat(int tf)
{
QString timeFormat = QObject::tr("MMM d/yy hh:mm:ss");
namespace {

switch (tf)
{
case 1:
timeFormat = QObject::tr("hh:mm:ss");
break;
bool latestFirst = true;
bool deviceTime = false;

case 2:
timeFormat = "";
break;

default:
break;
bool messageComparator(Message const& c1, Message const& c2)
{
if (deviceTime) {
return !latestFirst ? c1.deviceTimestamp() < c2.deviceTimestamp() : c1.deviceTimestamp() > c2.deviceTimestamp();
} else {
return !latestFirst ? c1.serverTimestamp() < c2.serverTimestamp() : c1.serverTimestamp() > c2.serverTimestamp();
}

return timeFormat;
}

}

namespace exportui {

using namespace bb::pim::message;
using namespace canadainc;

ExportSMS::ExportSMS(QStringList const& keys, qint64 const& accountId) :
Expand All @@ -46,7 +38,8 @@ QList<FormattedConversation> ExportSMS::formatConversations()
{
QList<FormattedConversation> result;

bool useServerTime = m_settings.value("serverTimestamp").toInt() == 1;
deviceTime = m_settings.value("serverTimestamp").toInt() != 1;
latestFirst = m_settings.value("latestFirst").toInt() == 1;
QString userName = m_settings.value("userName").toString();
QString timeFormat = getTimeFormat( m_settings.value("timeFormat").toInt() );
bool supportMMS = m_settings.contains("exporter_mms");
Expand All @@ -68,6 +61,7 @@ QList<FormattedConversation> ExportSMS::formatConversations()
if ( !conversation.participants().isEmpty() && conversation.messageCount() > 0 )
{
QList<Message> messages = ms.messagesInConversation( m_accountId, m_keys[i], MessageFilter() );
qSort( messages.begin(), messages.end(), messageComparator );
MessageContact c = conversation.participants()[0];

LOGGER("Total messages fetched" << messages.size());
Expand Down Expand Up @@ -95,16 +89,24 @@ QList<FormattedConversation> ExportSMS::formatConversations()
{
FormattedMessage fm;

QDateTime t = useServerTime ? m.serverTimestamp() : m.deviceTimestamp();
QDateTime t = deviceTime ? m.deviceTimestamp() : m.serverTimestamp();
fm.timestamp = timeFormat.isEmpty() ? "" : t.toString(timeFormat);
fm.sender = m.isInbound() ? m.sender().displayableName() : userName;

QStringList totalBody;

if (isEmail) {
totalBody << m.body(MessageBody::PlainText).data();
QString body = m.body(MessageBody::PlainText).plainText();

if ( body.isEmpty() ) {
body = m.body(MessageBody::Html).plainText();
}

totalBody << body;
}

LOGGER("total" << isEmail << totalBody);

for (int k = m.attachmentCount()-1; k >= 0; k--)
{
Attachment a = m.attachmentAt(k);
Expand Down Expand Up @@ -146,7 +148,6 @@ void ExportSMS::run()

QString result;
QList<FormattedConversation> conversations = formatConversations();
bool latestFirst = m_settings.value("latestFirst").toInt() == 1;
QString outputPath = m_settings.value("output").toString();
bool replace = m_settings.value("duplicateAction").toInt() == 1;
QString extension = m_format == OutputFormat::CSV ? "csv" : "txt";
Expand All @@ -169,7 +170,7 @@ void ExportSMS::run()
LOGGER("Total messages" << messages.size());
QStringList total;

for (int i = latestFirst ? messages.length()-1 : 0; latestFirst ? i >= 0 : i < messages.length(); latestFirst ? i-- : i++)
for (int i = 0; i < messages.length(); i++)
{
FormattedMessage fm = messages[i];
QList<FormattedAttachment> attachments = fm.attachments;
Expand Down Expand Up @@ -214,6 +215,28 @@ void ExportSMS::run()
}


QString ExportSMS::getTimeFormat(int tf)
{
QString timeFormat = QObject::tr("MMM d/yy hh:mm:ss");

switch (tf)
{
case 1:
timeFormat = QObject::tr("hh:mm:ss");
break;

case 2:
timeFormat = "";
break;

default:
break;
}

return timeFormat;
}


void ExportSMS::setFormat(OutputFormat::Type format) {
m_format = format;
}
Expand Down
1 change: 1 addition & 0 deletions src/ExportSMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ExportSMS : public QObject, public QRunnable
void setFormat(OutputFormat::Type format);
void run();
Q_SLOT void cancel();
static QString getTimeFormat(int tf);
};

} /* namespace exportui */
Expand Down
4 changes: 3 additions & 1 deletion src/PaymentHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ PaymentHelper::PaymentHelper(Persistance* persist, QObject* parent) :
PaymentManager* PaymentHelper::getPaymentManager()
{
if (!m_payment) {
LOGGER("Instantiating for first time!");
m_payment = new PaymentManager(this);

connect( m_payment, SIGNAL( existingPurchasesFinished(bb::platform::ExistingPurchasesReply*) ), this, SLOT( existingPurchasesFinished(bb::platform::ExistingPurchasesReply*) ) );
connect( m_payment, SIGNAL( purchaseFinished(bb::platform::PurchaseReply*) ), this, SLOT( purchaseFinished(bb::platform::PurchaseReply*) ) );
#if !defined(QT_NO_DEBUG)
m_payment->setConnectionMode(PaymentConnectionMode::Test);
#endif
Expand Down
6 changes: 4 additions & 2 deletions src/PaymentHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ class PaymentHelper : public QObject
PaymentManager* m_payment;
PaymentManager* getPaymentManager();

private slots:
void existingPurchasesFinished(bb::platform::ExistingPurchasesReply* reply);
void purchaseFinished(bb::platform::PurchaseReply* reply);

signals:
void initialize();

public:
PaymentHelper(Persistance* persist, QObject* parent=NULL);
virtual ~PaymentHelper();

void existingPurchasesFinished(bb::platform::ExistingPurchasesReply* reply);
void purchaseFinished(bb::platform::PurchaseReply* reply);
Q_SLOT void refreshPurchases();
Q_SLOT void requestPurchase(QString const& sku, QString const& name);
};
Expand Down
43 changes: 9 additions & 34 deletions translations/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ The great thing is that the app gives you access to nearly all your accounts to
<context>
<name>QObject</name>
<message>
<location filename="../src/ExportSMS.cpp" line="13"/>
<location filename="../src/ExportSMS.cpp" line="220"/>
<source>MMM d/yy hh:mm:ss</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="18"/>
<location filename="../src/ExportSMS.cpp" line="225"/>
<source>hh:mm:ss</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -416,62 +416,37 @@ 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="90"/>
<source>MMM d/yy, hh:mm:ss</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="95"/>
<source>hh:mm:ss</source>
<location filename="../src/ApplicationUI.cpp" line="112"/>
<source>You</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="108"/>
<location filename="../src/ApplicationUI.cpp" line="93"/>
<source>%1

%2: %3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="127"/>
<source>You</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="145"/>
<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="149"/>
<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="152"/>
<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="192"/>
<location filename="../src/ApplicationUI.cpp" line="177"/>
<source>Loading...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ApplicationUI.cpp" line="197"/>
<location filename="../src/ApplicationUI.cpp" line="182"/>
<source>Export complete</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>exportui::ExportSMS</name>
<message>
<location filename="../src/ExportSMS.cpp" line="53"/>
<location filename="../src/ExportSMS.cpp" line="46"/>
<source>Preparing...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/ExportSMS.cpp" line="157"/>
<location filename="../src/ExportSMS.cpp" line="158"/>
<source>Writing...</source>
<translation type="unfinished"></translation>
</message>
Expand Down

0 comments on commit 1e4cd1d

Please sign in to comment.