Files
th/interactions.c

103 lines
2.7 KiB
C

#include <curses.h>
#include <pthread.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "defines.h"
#include "config.h"
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;
}
void move_down(){
pthread_mutex_lock(&mutex_selection);
/*capping the maximum file is done inside thread_mid */
selected_file_current++;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}
void move_up(){
pthread_mutex_lock(&mutex_selection);
if (selected_file_current != 0) {
selected_file_current--;
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}
void move_right(){
chdir("..");
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void move_left(){
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(){
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void jump_bottom(){
pthread_mutex_lock(&mutex_selection);
selected_file_current = 0 - 1;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}
void jump_top(){
pthread_mutex_lock(&mutex_selection);
selected_file_current = 0;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}