VitaShell/message_dialog.c

106 lines
3.2 KiB
C
Raw Permalink Normal View History

2016-08-06 06:59:41 +00:00
/*
2017-10-13 10:42:36 +00:00
VitaShell
2017-12-30 10:43:37 +00:00
Copyright (C) 2015-2018, TheFloW
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-08-06 06:59:41 +00:00
*/
#include "main.h"
#include "message_dialog.h"
static int message_dialog_running = 0;
static int message_dialog_type = -1;
static char message_string[512];
2016-08-06 06:59:41 +00:00
2017-02-12 15:27:43 +00:00
int initMessageDialog(int type, const char *msg, ...) {
2017-10-13 10:42:36 +00:00
if (message_dialog_running)
2018-08-27 07:54:46 +00:00
return VITASHELL_ERROR_ALREADY_RUNNING;
2017-10-13 10:42:36 +00:00
va_list list;
char string[512];
va_start(list, msg);
vsprintf(string, msg, list);
va_end(list);
strcpy(message_string, string);
SceMsgDialogParam param;
sceMsgDialogParamInit(&param);
if (type == MESSAGE_DIALOG_PROGRESS_BAR) {
static SceMsgDialogProgressBarParam progress_bar_param;
memset(&progress_bar_param, 0, sizeof(SceMsgDialogProgressBarParam));
progress_bar_param.barType = SCE_MSG_DIALOG_PROGRESSBAR_TYPE_PERCENTAGE;
progress_bar_param.msg = (SceChar8 *)message_string;
param.progBarParam = &progress_bar_param;
param.mode = SCE_MSG_DIALOG_MODE_PROGRESS_BAR;
} else if (type == MESSAGE_DIALOG_QR_CODE) {
static SceMsgDialogUserMessageParam user_message_param;
memset(&user_message_param, 0, sizeof(SceMsgDialogUserMessageParam));
user_message_param.msg = (SceChar8 *)message_string;
param.userMsgParam = &user_message_param;
param.mode = MSG_DIALOG_MODE_QR_SCAN;
} else {
static SceMsgDialogUserMessageParam user_message_param;
memset(&user_message_param, 0, sizeof(SceMsgDialogUserMessageParam));
user_message_param.msg = (SceChar8 *)message_string;
user_message_param.buttonType = type;
param.userMsgParam = &user_message_param;
param.mode = SCE_MSG_DIALOG_MODE_USER_MSG;
}
int res = sceMsgDialogInit(&param);
if (res >= 0) {
message_dialog_running = 1;
message_dialog_type = type;
}
return 0;
2016-08-06 06:59:41 +00:00
}
int isMessageDialogRunning() {
2017-10-13 10:42:36 +00:00
return message_dialog_running;
2016-08-06 06:59:41 +00:00
}
int updateMessageDialog() {
2017-10-13 10:42:36 +00:00
if (!message_dialog_running)
return MESSAGE_DIALOG_RESULT_NONE;
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
SceCommonDialogStatus status = sceMsgDialogGetStatus();
if (status == MESSAGE_DIALOG_RESULT_FINISHED) {
if (message_dialog_type == SCE_MSG_DIALOG_BUTTON_TYPE_YESNO ||
2018-01-26 10:36:14 +00:00
message_dialog_type == SCE_MSG_DIALOG_BUTTON_TYPE_OK_CANCEL) {
2017-10-13 10:42:36 +00:00
SceMsgDialogResult result;
memset(&result, 0, sizeof(SceMsgDialogResult));
sceMsgDialogGetResult(&result);
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
if (result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_NO) {
status = MESSAGE_DIALOG_RESULT_NO;
} else if (result.buttonId == SCE_MSG_DIALOG_BUTTON_ID_YES) {
status = MESSAGE_DIALOG_RESULT_YES;
}
}
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
sceMsgDialogTerm();
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
message_dialog_running = 0;
}
2016-08-06 06:59:41 +00:00
2017-10-13 10:42:36 +00:00
return status;
}