Skip to content

Commit

Permalink
BB10: Add TAOT to share targets for selected text
Browse files Browse the repository at this point in the history
It's now possible to select a text in any app, press "Share" icon and
select TAO Translator from the list of targets. The text will then be
translated in TAO Translator.
  • Loading branch information
leppa committed Oct 31, 2014
1 parent bffac11 commit d9c7d11
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bar-descriptor.xml
Expand Up @@ -25,4 +25,13 @@
<asset path="%SRC_DIR%/taot480.png">icon.png</asset>
<asset path="%SRC_DIR%/qml/about.js">assets/about.js</asset>
<asset path="%SRC_DIR%/qml/bb10">assets</asset>
<invoke-target id="name.oleksii.taot.translate">
<invoke-target-type>application</invoke-target-type>
<invoke-target-name>TAO Translator</invoke-target-name>
<filter>
<action>bb.action.SHARE</action>
<mime-type>text/plain</mime-type>
<property var="uris" value="data://local" />
</filter>
</invoke-target>
</qnx>
6 changes: 6 additions & 0 deletions qml/bb10/MainPage.qml
Expand Up @@ -234,6 +234,8 @@ Page {

translation.editor.selectionStartChanged.connect(selectionChanged);
translation.editor.selectionEndChanged.connect(selectionChanged);

translator.sourceTextChanged.connect(sourceTextChanged);
}

function updateSourceLanguages()
Expand Down Expand Up @@ -266,4 +268,8 @@ Page {
{
targetLanguagesDropDown.selectedIndex = translator.targetLanguage.index;
}
function sourceTextChanged()
{
source.text = translator.sourceText;
}
}
20 changes: 20 additions & 0 deletions src/translationinterface.cpp
Expand Up @@ -26,6 +26,7 @@
#include "translationservicesmodel.h"
#include "languagelistmodel.h"
#ifdef Q_OS_BLACKBERRY
# include <bb/system/InvokeManager>
# include "bb10/dictionarymodel.h"
#else
# include "dictionarymodel.h"
Expand Down Expand Up @@ -81,6 +82,14 @@ TranslationInterface::TranslationInterface(QObject *parent)
if (m_settings->contains("displayNokiaStoreNotice"))
m_settings->remove("displayNokiaStoreNotice");
#endif

#ifdef Q_OS_BLACKBERRY
// No need to store this pointer - it will be
// deleted by TranslationInterface as its child.
bb::system::InvokeManager *manager = new bb::system::InvokeManager(this);
QObject::connect(manager, SIGNAL(invoked(bb::system::InvokeRequest)),
this, SLOT(onInvoked(bb::system::InvokeRequest)));
#endif
}

QString TranslationInterface::version()
Expand Down Expand Up @@ -407,3 +416,14 @@ void TranslationInterface::retranslate()

translate();
}

#ifdef Q_OS_BLACKBERRY
void TranslationInterface::onInvoked(const bb::system::InvokeRequest &request)
{
if (request.mimeType() != "text/plain")
return;

setSourceText(QString::fromUtf8(request.data()));
retranslate();
}
#endif
8 changes: 8 additions & 0 deletions src/translationinterface.h
Expand Up @@ -35,6 +35,10 @@
#include <QNetworkReply>
#include <QSettings>

#ifdef Q_OS_BLACKBERRY
# include <bb/system/InvokeRequest>
#endif

class TranslationServicesModel;
class TranslationServiceItem;
class LanguageListModel;
Expand Down Expand Up @@ -162,6 +166,10 @@ public slots:
private slots:
void onTranslationFinished();
void retranslate();

#ifdef Q_OS_BLACKBERRY
void onInvoked(const bb::system::InvokeRequest &request);
#endif
};

#endif // TRANSLATIONINTERFACE_H

0 comments on commit d9c7d11

Please sign in to comment.