A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 165 lines 5.6 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2010 Jonathan Gordon 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21#include "config.h" 22 23#if (CONFIG_PLATFORM&PLATFORM_ANDROID) 24#include <jni.h> 25#include <stdbool.h> 26#include <stdio.h> 27#include "yesno.h" 28#include "settings.h" 29#include "lang.h" 30#include "kernel.h" 31#include "splash.h" 32 33extern JNIEnv *env_ptr; 34static jobject RockboxYesno_instance = NULL; 35static jmethodID yesno_func; 36static struct semaphore yesno_done; 37static bool ret; 38 39JNIEXPORT void JNICALL 40Java_org_rockbox_RockboxYesno_put_1result(JNIEnv *env, jobject this, jboolean result) 41{ 42 (void)env; 43 (void)this; 44 ret = (bool)result; 45 semaphore_release(&yesno_done); 46} 47 48static void yesno_init(void) 49{ 50 JNIEnv e = *env_ptr; 51 static jmethodID yesno_is_usable; 52 if (RockboxYesno_instance == NULL) 53 { 54 semaphore_init(&yesno_done, 1, 0); 55 /* get the class and its constructor */ 56 jclass RockboxYesno_class = e->FindClass(env_ptr, 57 "org/rockbox/RockboxYesno"); 58 jmethodID constructor = e->GetMethodID(env_ptr, 59 RockboxYesno_class, 60 "<init>", "()V"); 61 RockboxYesno_instance = e->NewObject(env_ptr, 62 RockboxYesno_class, 63 constructor); 64 yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class, 65 "yesno_display", 66 "(Ljava/lang/String;" 67 "Ljava/lang/String;" 68 "Ljava/lang/String;)V"); 69 yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class, 70 "is_usable", "()Z"); 71 } 72 /* need to get it every time incase the activity died/restarted */ 73 while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance, 74 yesno_is_usable)) 75 sleep(HZ/10); 76} 77 78jstring build_message(const struct text_message *message) 79{ 80 char msg[1024] = ""; 81 JNIEnv e = *env_ptr; 82 int i; 83 for(i=0; i<message->nb_lines; i++) 84 { 85 char* text = P2STR((unsigned char *)message->message_lines[i]); 86 if (i>0) 87 strlcat(msg, "\n", 1024); 88 strlcat(msg, text, 1024); 89 } 90 /* make sure the questions end in a ?, for some reason they dont! */ 91 if (!strrchr(msg, '?')) 92 strlcat(msg, "?", 1024); 93 return e->NewStringUTF(env_ptr, msg); 94} 95 96enum yesno_res gui_syncyesno_run(const struct text_message * main_message, 97 const struct text_message * yes_message, 98 const struct text_message * no_message) 99{ 100 (void)yes_message; 101 (void)no_message; 102 yesno_init(); 103 104 JNIEnv e = *env_ptr; 105 jstring message = build_message(main_message); 106 jstring yes = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_YES)); 107 jstring no = (*env_ptr)->NewStringUTF(env_ptr, str(LANG_SET_BOOL_NO)); 108 109 e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, 110 message, yes, no); 111 112 semaphore_wait(&yesno_done, TIMEOUT_BLOCK); 113 114 e->DeleteLocalRef(env_ptr, message); 115 e->DeleteLocalRef(env_ptr, yes); 116 e->DeleteLocalRef(env_ptr, no); 117 118 return ret ? YESNO_YES : YESNO_NO; 119} 120 121enum yesno_res gui_syncyesno_run_w_tmo(int ticks, enum yesno_res tmo_default_res, 122 const struct text_message * main_message, 123 const struct text_message * yes_message, 124 const struct text_message * no_message) 125{ 126 /* FIXME: create a prompt with timeout for android */ 127 (void)ticks; 128 (void)tmo_default_res; 129 return gui_syncyesno_run(main_message, yes_message, no_message); 130} 131 132#endif 133 134static bool yesno_pop_lines(const char *lines[], int line_cnt) 135{ 136 const struct text_message message={lines, line_cnt}; 137 bool ret = (gui_syncyesno_run(&message,NULL,NULL)== YESNO_YES); 138 FOR_NB_SCREENS(i) 139 screens[i].clear_viewport(); 140 return ret; 141} 142 143/* YES/NO dialog, uses text parameter as prompt */ 144bool yesno_pop(const char* text) 145{ 146 const char *lines[]= {text}; 147 return yesno_pop_lines(lines, 1); 148} 149 150/* YES/NO dialog, asks "Are you sure?", displays 151 text parameter on second line. 152 153 Says "Cancelled" if answered negatively. 154*/ 155bool yesno_pop_confirm(const char* text) 156{ 157 bool confirmed; 158 const char *lines[] = {ID2P(LANG_ARE_YOU_SURE), text}; 159 confirmed = yesno_pop_lines(lines, 2); 160 161 if (!confirmed) 162 splash(HZ, ID2P(LANG_CANCEL)); 163 164 return confirmed; 165}