Plan app dialog factories
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "app_core/about_menu.h"
|
||||
#include "app_core/app_dialog.h"
|
||||
#include "app_core/app_preferences.h"
|
||||
#include "app_core/app_frame.h"
|
||||
#include "app_core/app_input.h"
|
||||
@@ -249,6 +250,16 @@ struct PlanAppPreferencesArgs {
|
||||
int cursor_mode = 0;
|
||||
};
|
||||
|
||||
struct PlanAppDialogArgs {
|
||||
pp::app::AppDialogKind kind = pp::app::AppDialogKind::progress;
|
||||
std::string title = "Saving";
|
||||
std::string message = "Done";
|
||||
std::string field_name = "Name";
|
||||
std::string ok_caption = "Ok";
|
||||
int total = 0;
|
||||
bool cancel = false;
|
||||
};
|
||||
|
||||
struct PlanAppStartupArgs {
|
||||
int run_counter = 0;
|
||||
bool auto_timelapse_enabled = true;
|
||||
@@ -1931,6 +1942,20 @@ const char* cloud_transfer_action_name(pp::app::CloudTransferAction action) noex
|
||||
return "reject-missing-source";
|
||||
}
|
||||
|
||||
const char* app_dialog_kind_name(pp::app::AppDialogKind kind) noexcept
|
||||
{
|
||||
switch (kind) {
|
||||
case pp::app::AppDialogKind::progress:
|
||||
return "progress";
|
||||
case pp::app::AppDialogKind::message:
|
||||
return "message";
|
||||
case pp::app::AppDialogKind::input:
|
||||
return "input";
|
||||
}
|
||||
|
||||
return "progress";
|
||||
}
|
||||
|
||||
const char* recording_start_action_name(pp::app::RecordingStartAction action) noexcept
|
||||
{
|
||||
switch (action) {
|
||||
@@ -2147,6 +2172,7 @@ void print_help()
|
||||
<< " plan-cloud-browse [--no-canvas] [--selected-file FILE]\n"
|
||||
<< " plan-cloud-upload-all [--file-count N] [--no-progress-ui]\n"
|
||||
<< " plan-cloud-transfer [--direction download|upload] [--source TEXT] [--destination FILE] [--progress] [--disable-tls-verification] [--progress-total N] [--progress-current N]\n"
|
||||
<< " plan-app-dialog --kind progress|message|input [--title TEXT] [--message TEXT] [--field-name TEXT] [--ok-caption TEXT] [--total N] [--cancel]\n"
|
||||
<< " plan-recording-session [--running] [--frame-count N] [--platform-deletes-recorded-files] [--no-encoder] [--no-canvas]\n"
|
||||
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
||||
<< " plan-app-startup [--run-counter N] [--auto-timelapse-disabled] [--vr-controllers-disabled] [--license-invalid]\n"
|
||||
@@ -3675,6 +3701,121 @@ int plan_cloud_transfer(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_app_dialog_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanAppDialogArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--kind") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const std::string_view value(argv[++i]);
|
||||
if (value == "progress") {
|
||||
args.kind = pp::app::AppDialogKind::progress;
|
||||
} else if (value == "message") {
|
||||
args.kind = pp::app::AppDialogKind::message;
|
||||
} else if (value == "input") {
|
||||
args.kind = pp::app::AppDialogKind::input;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown app dialog kind");
|
||||
}
|
||||
} else if (key == "--title") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.title = argv[++i];
|
||||
} else if (key == "--message") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.message = argv[++i];
|
||||
} else if (key == "--field-name") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.field_name = argv[++i];
|
||||
} else if (key == "--ok-caption") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.ok_caption = argv[++i];
|
||||
} else if (key == "--total") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = parse_i32_arg(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
args.total = value.value();
|
||||
} else if (key == "--cancel") {
|
||||
args.cancel = true;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_app_dialog(int argc, char** argv)
|
||||
{
|
||||
PlanAppDialogArgs args;
|
||||
const auto status = parse_plan_app_dialog_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-app-dialog", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
switch (args.kind) {
|
||||
case pp::app::AppDialogKind::progress:
|
||||
{
|
||||
const auto plan = pp::app::plan_app_progress_dialog(args.title, args.total);
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-app-dialog\""
|
||||
<< ",\"kind\":\"" << app_dialog_kind_name(args.kind)
|
||||
<< "\",\"plan\":{\"title\":\"" << json_escape(plan.title)
|
||||
<< "\",\"total\":" << plan.total
|
||||
<< ",\"count\":" << plan.count
|
||||
<< ",\"progressFraction\":" << plan.progress_fraction
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
case pp::app::AppDialogKind::message:
|
||||
{
|
||||
const auto plan = pp::app::plan_app_message_dialog(args.title, args.message, args.cancel);
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-app-dialog\""
|
||||
<< ",\"kind\":\"" << app_dialog_kind_name(args.kind)
|
||||
<< "\",\"plan\":{\"title\":\"" << json_escape(plan.title)
|
||||
<< "\",\"message\":\"" << json_escape(plan.message)
|
||||
<< "\",\"okCaption\":\"" << json_escape(plan.ok_caption)
|
||||
<< "\",\"showCancel\":" << json_bool(plan.show_cancel)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
case pp::app::AppDialogKind::input:
|
||||
{
|
||||
const auto plan = pp::app::plan_app_input_dialog(args.title, args.field_name, args.ok_caption);
|
||||
if (!plan) {
|
||||
print_error("plan-app-dialog", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-app-dialog\""
|
||||
<< ",\"kind\":\"" << app_dialog_kind_name(args.kind)
|
||||
<< "\",\"plan\":{\"title\":\"" << json_escape(plan.value().title)
|
||||
<< "\",\"fieldName\":\"" << json_escape(plan.value().field_name)
|
||||
<< "\",\"okCaption\":\"" << json_escape(plan.value().ok_caption)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
print_error("plan-app-dialog", "unknown app dialog kind");
|
||||
return 2;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_recording_session_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -10879,6 +11020,10 @@ int main(int argc, char** argv)
|
||||
return plan_cloud_transfer(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-app-dialog") {
|
||||
return plan_app_dialog(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-recording-session") {
|
||||
return plan_recording_session(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user