FlippyPass/project/ui/scenes/import.c

127 lines
No EOL
3 KiB
C

// Header
#include "import.h"
// Others
#include "../../backend/archive.h"
// Functions
void FP_Scene_Callback_Import(DialogExResult result, void* context){
// Setting context
FP_App* app = context;
// Sending it to the scene manager
scene_manager_handle_custom_event(app->scene_manager, result);
}
void FP_Scene_Enter_Import(void* context){
// Setting context
FP_App* app = context;
// Setting selection
app->selection = 0;
// Resetting scene
dialog_ex_reset(app->dialog);
// Setting dialog content
dialog_ex_set_header(
app->dialog,
"Import Archive",
0, 0,
AlignLeft, AlignTop
);
dialog_ex_set_text(
app->dialog,
"Are you sure you want to import: /ext/apps_data/fpass/archive.txt?",
5, 15,
AlignLeft, AlignTop
);
dialog_ex_set_center_button_text(
app->dialog,
"Yes"
);
dialog_ex_set_left_button_text(
app->dialog,
"No"
);
// Setting callback
dialog_ex_set_result_callback(
app->dialog,
FP_Scene_Callback_Import
);
dialog_ex_set_context(
app->dialog,
app
);
// Sending view to Flipper
view_dispatcher_switch_to_view(app->view_dispatcher, FP_View_Dialog);
}
void FP_Scene_Exit_Import(void* context){
// Setting context
FP_App* app = context;
// Reset menu
submenu_reset(app->submenu);
}
bool FP_Scene_Event_Import(void* context, SceneManagerEvent event){
// Setting context
FP_App* app = context;
bool consumed = false;
// Switching based on event
if (event.type == SceneManagerEventTypeCustom) {
// We consumed it
consumed = true;
// Are we already good?
if (app->selection >= 1) {
scene_manager_previous_scene(
app->scene_manager
);
}
// What should we do?
switch (event.event) {
case DialogExResultCenter: // Yes
// Importing the passwords
bool success = archive_import(app->manager);
// Telling the user it worked!
if (success) {
dialog_ex_set_text(
app->dialog,
"Imported Successfully.",
5, 15,
AlignLeft, AlignTop
);
} else {
dialog_ex_set_text(
app->dialog,
"Failed to import passwords",
5, 15,
AlignLeft, AlignTop
);
}
dialog_ex_set_center_button_text(
app->dialog,
"Okay"
);
dialog_ex_set_left_button_text(
app->dialog,
NULL
);
app->selection++;
break;
case DialogExResultLeft: // No
scene_manager_previous_scene(app->scene_manager);
break;
}
} else {
consumed = false;
}
// Return result
return consumed;
}