~ruther/CTU-FEE-B0B35APO-Semestral-project

5c0263445f4fac557d28f9305bf8f9d43ab8032b — František Boháček 4 years ago 1d2b188
feat: add controls text file open
M file-browser/include/file_open.h => file-browser/include/file_open.h +3 -0
@@ 26,4 26,7 @@ typedef struct {
opened_file_state_t file_open(file_t *file, exec_options_t *options,
                                 fileaccess_state_t state);

opened_file_state_t file_open_mime_raw(char *file, exec_options_t *options,
                                       char *mime);

#endif // __FILE_OPEN_H__

M file-browser/src/file_open.c => file-browser/src/file_open.c +21 -16
@@ 62,12 62,6 @@ static opened_file_state_t file_open_mime(file_t *file, exec_options_t *options,
      return opened;
    }
  }

  char *program = exec_options_get_program(options, mime);
  if (program == NULL) {
    return opened;
  }

  char local_path[PATH_MAX];
  opened.error =
      fileaccess_file_get_local_path(state, file, local_path);


@@ 76,16 70,7 @@ static opened_file_state_t file_open_mime(file_t *file, exec_options_t *options,
    return opened;
  }

  file_prepare_before_open();
  executing_file_error_t executing_or_error =
      executing_file_execute(program, local_path);

  if (executing_or_error.error != FILOPER_SUCCESS) {
    opened.error = executing_or_error.error;
    return opened;
  }

  return file_execute(&executing_or_error.file, base_mime != NULL ? OPENED_TEXT : OPENED_MIME);
  return file_open_mime_raw(local_path, options, mime);
}

static opened_file_state_t file_open_text(file_t *file, exec_options_t *options,


@@ 131,3 116,23 @@ opened_file_state_t file_open(file_t *file, exec_options_t *options, fileaccess_
  // 3. text mime
  return file_open_text(file, options, state);
}

opened_file_state_t file_open_mime_raw(char *file, exec_options_t *options,
                                       char *mime) {
  opened_file_state_t opened = opened_file_create();
  char *program = exec_options_get_program(options, mime);
  if (program == NULL) {
    return opened;
  }

  file_prepare_before_open();
  executing_file_error_t executing_or_error =
      executing_file_execute(program, file);

  if (executing_or_error.error != FILOPER_SUCCESS) {
    opened.error = executing_or_error.error;
    return opened;
  }

  return file_execute(&executing_or_error.file, OPENED_MIME);
}

M file-browser/src/window_initial.c => file-browser/src/window_initial.c +25 -13
@@ 1,8 1,11 @@
#include "window_initial.h"
#include "SDL_video.h"
#include "display_utils.h"
#include "file_open.h"
#include "font.h"
#include "gui.h"

#include "file_browser_utils.h"
#include "gui_window_info.h"
#include "gui_container_info.h"
#include "gui_list_commands.h"


@@ 14,10 17,15 @@
#include <stdbool.h>

#define INITIAL_WINDOW_LOCAL_INDEX 0
#define INITIAL_WINDOW_MOUNT_INDEX 1
#define INITIAL_WINDOW_OPTIONS_INDEX 2
#define INITIAL_WINDOW_CONTROLS_ENG_INDEX 1
#define INITIAL_WINDOW_CONTROLS_CZE_INDEX 2
#define INITIAL_WINDOW_EXIT_INDEX 3

#define INITIAL_WINDOW_ENTRIES 4

#define CONTROLS_PATH "./controls.txt"
#define CONTROLS_CZ_PATH "./controls_cz.txt"

typedef struct {
  bool running;
  gui_t *gui;


@@ 79,13 87,13 @@ static bool initial_window_list_render_item(void *state, uint32_t index,
  char *data;
  switch (index) {
  case INITIAL_WINDOW_LOCAL_INDEX:
    data = "ROOT FILESYSTEM";
    data = "SHOW ROOT FILESYSTEM";
    break;
  case INITIAL_WINDOW_MOUNT_INDEX:
    data = "MOUNTABLE DEVICES";
  case INITIAL_WINDOW_CONTROLS_ENG_INDEX:
    data = "SHOW CONTROLS (ENG) - J down, V confirm";
    break;
  case INITIAL_WINDOW_OPTIONS_INDEX:
    data = "OPTIONS";
  case INITIAL_WINDOW_CONTROLS_CZE_INDEX:
    data = "SHOW CONTROLS (CZE) - J dolů, V potvrzení";
    break;
  case INITIAL_WINDOW_EXIT_INDEX:
    data = "EXIT";


@@ 122,7 130,7 @@ static void *initial_window_construct(window_t *window, void *state) {
  istate->click_state.window = window;

  // containers init
  gui_container_info_init(istate->list_container, istate, 4, 5, 5);
  gui_container_info_init(istate->list_container, istate, INITIAL_WINDOW_ENTRIES, 5, 5);
  istate->list_container->width = istate->gui->size.x - 20;
  istate->list_container->height = istate->gui->size.y - 20;



@@ 163,13 171,17 @@ static void initial_window_item_clicked(container_t *container, void *state,
                "Clicked local root filesystem");
    window_browser_open_local(istate->gui, &istate->font);
    break;
  case INITIAL_WINDOW_MOUNT_INDEX:
    logger_info(logger, __FILE__, __FUNCTION__, __LINE__,
                "Clicked mount");
    break;
  case INITIAL_WINDOW_OPTIONS_INDEX:
  case INITIAL_WINDOW_CONTROLS_ENG_INDEX:
    logger_info(logger, __FILE__, __FUNCTION__, __LINE__,
                "Clicked options");
    opened_file_state_t opened_eng = file_open_mime_raw(CONTROLS_PATH, browser_exec_options, "text");
    file_browser_handle_opened_file(opened_eng, istate->gui, &istate->font);
    break;
  case INITIAL_WINDOW_CONTROLS_CZE_INDEX:
    logger_info(logger, __FILE__, __FUNCTION__, __LINE__, "Clicked options");
    opened_file_state_t opened_cze =
        file_open_mime_raw(CONTROLS_CZ_PATH, browser_exec_options, "text");
    file_browser_handle_opened_file(opened_cze, istate->gui, &istate->font);
    break;
  case INITIAL_WINDOW_EXIT_INDEX:
    logger_info(logger, __FILE__, __FUNCTION__, __LINE__,