Как правильно открыть URL из области видимости в c ++?
Это то, что я пробовал (эта функция вызывается из ActivationResponse.):
static void open_url(std::string const& uri) {
// url_dispatch_send(uri.c_str(), NULL, NULL);
/*
* I found this in the libertine-scope, but I wasn't able to import
* the right libraries
*/
// Qt.openUrlExternally(uri.c_str());
/*
* I found this at https://developer.ubuntu.com/en/phone/platform/guides/url-dispatcher-guide/
* and https://developer.ubuntu.com/en/phone/apps/qml/tutorials/register-your-app-url-dispatcher/
* but it is actually meant to be used in QML, so it isn't recognized.
* I hoped it would work by using QtQuick or QtQml
*/
// QDesktopServices::openUrl(QUrl(QString(uri), QUrl::TolerantMode));
// QDesktopServices::openUrl(QUrl("http://www.google.com", QUrl::TolerantMode));
/*
* I found this at https://developer.ubuntu.com/en/phone/platform/guides/url-dispatcher-guide/
* and http://doc.qt.io/qt-5/qdesktopservices.html#openUrl
* this compiles, but the scope crashes on execution.
*
*/
}
edit: Если быть более точным, три функции, которые я прокомментировал, - это три различных варианта Я нашел и попробовал. Ни один из них не будет работать. В комментарии к функциям я попытался объяснить, что не сработало.
Функция open_url вызывается из ActivationResponse следующим образом:
Action::Action(unity::scopes::Result const& result,
unity::scopes::ActionMetadata const& metadata,
Action::OpenUriAction open_uri)
: sc::ActivationQueryBase(result, metadata)
, open_uri_(open_uri)
{
}
sc::ActivationResponse
Action::activate()
{
open_uri_(result().uri());
return sc::ActivationResponse(sc::ActivationResponse::Status::NotHandled);
}
Как я подозревал, существует хороший способ сделать это.
1: в классе объема необходимо переопределить активировать-метод
unity::scopes::ActivationQueryBase::UPtr NewsScope::activate(const sc::Result &result,
const unity::scopes::ActionMetadata &metadata) {
return unity::scopes::ActivationQueryBase::UPtr(new NewsAction(result, metadata));
}
2: В единице:: объемы:: класс ActivationQueryBase (здесь NewsAction) Вы определяете активировать-метод, например, как это:
sc::ActivationResponse NewsAction::activate()
{
initScope();
if (openWithoutPreview) {
return sc::ActivationResponse(sc::ActivationResponse::Status::NotHandled);
}
return sc::ActivationResponse(sc::ActivationResponse::Status::ShowPreview);
}
(следят за ответом активации: NotHandled говорит объему отправлять его внешнему диспетчеру.)
3: Наконец, если создают карты (CategorisedResult) в searchquery-классе, необходимо сказать им прерывать активацию. (Результат set_intercept_activation ()), Например, как это:
for (const Result &result : results) {
sc::CategorisedResult card(category);
fillCard(card, result);
card.set_intercept_activation();
// Push the result
if (!reply->push(card)) {
// If we fail to push, it means the query has been cancelled.
// So don't continue;
return;
}
}
я нашел решение (скрытым) в этом руководстве: https://developer.ubuntu.com/api/scopes/cpp/development/index /