Skip to content

Commit

Permalink
small cleanup of Import All
Browse files Browse the repository at this point in the history
  • Loading branch information
rdefeo committed Sep 8, 2024
1 parent 75fd1a4 commit 6f79e18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
12 changes: 8 additions & 4 deletions quac.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "views/action_menu.h"
#include "item.h"

#define QUAC_NAME "Quac!"
#define QUAC_NAME "Quac!"
#define QUAC_VERSION "v0.6.3"
#define QUAC_ABOUT \
"Quick Action remote control\n" QUAC_VERSION "\n" \
Expand All @@ -25,9 +25,12 @@

// Location of our actions and folders
#define QUAC_SETTINGS_FILENAME ".quac.conf"
#define QUAC_SETTINGS_PATH APP_DATA_PATH(QUAC_SETTINGS_FILENAME)
#define QUAC_SETTINGS_PATH APP_DATA_PATH(QUAC_SETTINGS_FILENAME)

typedef enum { QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE } QuacAppLayout;
typedef enum {
QUAC_APP_PORTRAIT,
QUAC_APP_LANDSCAPE
} QuacAppLayout;

typedef struct App {
SceneManager* scene_manager;
Expand All @@ -49,6 +52,7 @@ typedef struct App {

FuriString* temp_str; // used for renames/etc
char temp_cstr[MAX_NAME_LEN]; // used for renames/etc
uint32_t temp_u32;

struct {
QuacAppLayout layout; // Defaults to Portrait
Expand All @@ -65,4 +69,4 @@ typedef struct App {
} App;

App* app_alloc();
void app_free(App* app);
void app_free(App* app);
28 changes: 18 additions & 10 deletions scenes/scene_action_ir_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

#include <flipper_format/flipper_format.h>

// ehhhh
uint32_t num_ir_commands;

void scene_action_ir_list_callback(void* context, uint32_t index) {
App* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
Expand Down Expand Up @@ -46,10 +43,11 @@ void scene_action_ir_list_on_enter(void* context) {
index++;
}
}
num_ir_commands = index - 1;

if(index == 1) { // '1' to account for 'IMPORT ALL'
FURI_LOG_E(TAG, "Failed to get commands from %s", furi_string_get_cstr(app->temp_str));
// Number of IR Commands in file
app->temp_u32 = index - 1;
if(app->temp_u32 == 0) {
FURI_LOG_E(TAG, "Failed to get ANY commands from %s", furi_string_get_cstr(app->temp_str));
submenu_change_item_label(menu, 0, "No IR cmds!");
}

Expand All @@ -75,11 +73,12 @@ bool scene_action_ir_list_on_event(void* context, SceneManagerEvent event) {
FuriString* file_name = furi_string_alloc(); // new IR file name

do {
uint32_t num_imported = 0;
uint32_t start = index - 1;
uint32_t end = index;
if(index == 0) {
start = 0;
end = num_ir_commands;
end = app->temp_u32; // Number of IR Commands in file
}
for(uint32_t ir_index = start; ir_index < end; ir_index++) {
if(!flipper_format_file_open_existing(
Expand Down Expand Up @@ -116,12 +115,21 @@ bool scene_action_ir_list_on_event(void* context, SceneManagerEvent event) {
}
flipper_format_file_close(fff_data_file);
FURI_LOG_I(TAG, "Imported %s", furi_string_get_cstr(name));
num_imported++;
}

if(num_imported == (end - start)) {
// Import successful!
notification_message(app->notifications, &sequence_success);
} else {
FURI_LOG_E(
TAG,
"Error importing IR command(s) from %s",
furi_string_get_cstr(app->temp_str));
notification_message(app->notifications, &sequence_error);
}
// Import successful!
// Leave the user on this scene, in case they want to import
// more commands from this IR file
notification_message(app->notifications, &sequence_success);

} while(false);

// cleanup
Expand Down

0 comments on commit 6f79e18

Please sign in to comment.