opening files using mimetypes defined in config.h

This commit is contained in:
nova
2025-06-18 04:08:02 +02:00
parent 1485d69cad
commit f99035629a
10 changed files with 106 additions and 41 deletions

View File

@ -1,7 +1,9 @@
#include <curses.h>
#include <pthread.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "defines.h"
#include "config.h"
@ -10,12 +12,28 @@ extern unsigned int file_modifiers;
unsigned long selected_file_current;
unsigned long selected_file_last;
extern pthread_mutex_t mutex_selection;
extern pthread_mutex_t mutex_rgt;
extern pthread_mutex_t mutex_mid;
extern file *mid_content;
extern file *lft_content;
extern file *rgt_content;
extern file file_current;
extern char *rgt_buffer;
extern char *btm_buffer;
extern unsigned int status;
void user_interactions(char *input) {
void (*func_ptr)();
unsigned long i = 0;
for (i = 0; i < binding_count; i++) {
if (*input == key_binding[i].key) {
func_ptr = key_binding[i].func;
func_ptr();
}
}
}
void quit_program(){
status = STATUS_QUIT_PROGRAM;
}
@ -39,7 +57,30 @@ void move_right(){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void move_left(){
chdir(mid_content[selected_file_current].file_name);
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
chdir(file_current.file_name);
} else {
unsigned long i = 0;
char *mime = get_mimetype(file_current.file_name);
for (i = 0; i < mimetype_default_count; i++) {
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
char *cmd = concat(mimetype_default_cmd[i].command, " ./\"");
cmd = concat(cmd, file_current.file_name);
cmd = concat(cmd, "\"");
btm_buffer = malloc(strlen(cmd));
strcpy(btm_buffer, cmd);
system(cmd);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break;
}
}
free(mime);
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void toggle_hidden_files(){
@ -59,15 +100,3 @@ void jump_top(){
pthread_mutex_unlock(&mutex_selection);
}
void user_interactions(char *input) {
void (*func_ptr)();
unsigned long i = 0;
for (i = 0; i < binding_count; i++) {
if (*input == key_binding[i].key) {
func_ptr = key_binding[i].func;
func_ptr();
}
}
}