File indexing completed on 2024-12-15 04:01:00

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #include "telegram_intent.hpp"
0008 
0009 #ifdef Q_OS_ANDROID
0010 
0011 #include <QAndroidIntent>
0012 #include <QtAndroid>
0013 #include <QAndroidJniEnvironment>
0014 
0015 #include <QApplication>
0016 
0017 #include <KLocalizedString>
0018 
0019 
0020 glaxnimate::android::TelegramIntent::Result glaxnimate::android::TelegramIntent::send_stickers(const QStringList& filenames, const QStringList& emoji)
0021 {
0022     QAndroidJniObject generator_name = QAndroidJniObject::fromString(qApp->applicationName());
0023     QAndroidJniObject messenger(
0024         "org/mattbas/glaxnimate/jnimessenger/JniMessenger",
0025         "(Ljava/lang/String;)V",
0026         generator_name.object<jstring>()
0027     );
0028 
0029     for ( int i = 0; i < filenames.size(); i++ )
0030     {
0031         QAndroidJniObject sticker_file = QAndroidJniObject::fromString(filenames[i]);
0032         QAndroidJniObject sticker_emoji = QAndroidJniObject::fromString(emoji[i]);
0033         messenger.callMethod<void>("add_sticker", "(Ljava/lang/String;Ljava/lang/String;)V", sticker_file.object<jstring>(), sticker_emoji.object<jstring>());
0034     }
0035 
0036 
0037     QAndroidJniObject intent = messenger.callObjectMethod("import_stickers", "()Landroid/content/Intent;");
0038     QAndroidJniObject activity = QtAndroid::androidActivity();
0039     {
0040         QAndroidJniEnvironment env;
0041         activity.callMethod<void>("startActivity", "(Landroid/content/Intent;)V", intent.object<jobject>());
0042 
0043         if (env->ExceptionCheck())
0044         {
0045             env->ExceptionDescribe();
0046             env->ExceptionClear();
0047             return i18n("Could not start activity, is Telegram installed?");
0048         }
0049     }
0050     return {};
0051 }
0052 
0053 #else
0054 glaxnimate::android::TelegramIntent::Result glaxnimate::android::TelegramIntent::send_stickers(const QStringList& filenames, const QStringList& emoji)
0055 {
0056     Q_UNUSED(filenames)
0057     Q_UNUSED(emoji)
0058     return {};
0059 }
0060 #endif