Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Jul 8, 2015
1 parent 78851fa commit ac249cb
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 77 deletions.
3 changes: 1 addition & 2 deletions src/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ file_list *selected;
struct conf config;
struct vars ps[MAX_TABS];
struct search_vars sv;
WINDOW *info_win;
int active, cont, quit;
int active, cont, quit, num_of_jobs;
pthread_mutex_t lock;
struct thread_mesg thread_m;
2 changes: 1 addition & 1 deletion src/fm_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ void create_archive(void)
if (((archive_write_add_filter_gzip(archive) == ARCHIVE_FATAL) || (archive_write_set_format_pax_restricted(archive) == ARCHIVE_FATAL)) ||
(archive_write_open_filename(archive, thread_h->full_path) == ARCHIVE_FATAL)) {
thread_m.str = strerror(archive_errno(archive));
thread_m.line = ERR_LINE;
thread_m.line = ERR_LINE;
archive_write_free(archive);
archive = NULL;
} else {
Expand Down
81 changes: 14 additions & 67 deletions src/helper_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#include "helper_functions.h"

static void free_running_h(void);
static thread_job_list *add_thread(thread_job_list *h, int type, const char *path, void (*f)(void));
static void init_thread_helper(const char *temp, const char *str);
static void copy_selected_files(void);
static void *execute_thread(void *x);
static void free_thread_job_list(thread_job_list *h);
static void quit_thread_func(void);

static int num_of_jobs = 0;
static pthread_t th;
static thread_job_list *current_th; // current_th: ptr to latest elem in thread_l list

Expand All @@ -55,61 +55,6 @@ int is_archive(const char *filename)
return 0;
}

/*
* Given a str, a char input[dim], and a char c (that is default value if enter is pressed, if dim == 1),
* asks the user "str" and saves in input the user response.
*/
void ask_user(const char *str, char *input, int dim, char c)
{
echo();
print_info(str, INFO_LINE);
if (dim == 1) {
*input = wgetch(info_win);
if ((*input >= 'A') && (*input <= 'Z')) {
*input = tolower(*input);
} else if (*input == 10) {
*input = c;
}
} else {
wgetstr(info_win, input);
}
noecho();
print_info(NULL, INFO_LINE);
}

/*
* Given a string str, and a line i, prints str on the I line of INFO_WIN.
* Plus, it searches for running th, and if found, prints running_h message(depends on its type) at the end of INFO_LINE
* It searches for selected_files too, and prints a message at the end of INFO_LINE - (strlen(running_h mesg) if there's.
* Finally, if a search is running, prints a message at the end of ERR_LINE;
*/
void print_info(const char *str, int i)
{
int k;
char st[PATH_MAX];

for (k = INFO_LINE; k != ERR_LINE + 1; k++) {
wmove(info_win, k, strlen("I:") + 1);
wclrtoeol(info_win);
}
k = 0;
if (thread_h && thread_h->type) {
sprintf(st, "[%d/%d] %s", thread_h->num, num_of_jobs, thread_job_mesg[thread_h->type - 1]);
k = strlen(st) + 1;
mvwprintw(info_win, INFO_LINE, COLS - strlen(st), st);
}
if (selected) {
mvwprintw(info_win, INFO_LINE, COLS - k - strlen(selected_mess), selected_mess);
}
if ((sv.searching == 1) || (sv.searching == 2)) {
mvwprintw(info_win, ERR_LINE, COLS - strlen(searching_mess[sv.searching - 1]), searching_mess[sv.searching - 1]);
}
if (str) {
mvwprintw(info_win, i, strlen("I: ") + 1, str);
}
wrefresh(info_win);
}

void *safe_malloc(ssize_t size, const char *str)
{
void *ptr = NULL;
Expand Down Expand Up @@ -158,19 +103,22 @@ int get_mimetype(const char *path, const char *test)
* Adds a job to the thread_job_list (thread_job_list list).
* current_th will always point to the newly created job (ie the last job to be executed).
*/
thread_job_list *add_thread(thread_job_list *h)
static thread_job_list *add_thread(thread_job_list *h, int type, const char *path, void (*f)(void))
{
if (h) {
h->next = add_thread(h->next);
h->next = add_thread(h->next, type, path, f);
} else {
if (!(h = safe_malloc(sizeof(struct thread_list), generic_mem_error))) {
return NULL;
}
num_of_jobs++;
h->selected_files = NULL;
h->next = NULL;
h->f = NULL;
h->f = f;
strcpy(h->full_path, path);
h->type = type;
h->num = num_of_jobs;
current_th = h;
num_of_jobs++;
}
return h;
}
Expand Down Expand Up @@ -212,12 +160,8 @@ void init_thread(int type, void (*f)(void), const char *str)
return;
}
}
thread_h = add_thread(thread_h);
strcpy(current_th->full_path, str);
current_th->num = num_of_jobs;
current_th->type = type;
thread_h = add_thread(thread_h, type, str, f);
init_thread_helper(temp, str);
current_th->f = f;
if (num_of_jobs > 1) {
print_info(thread_running, INFO_LINE);
} else {
Expand Down Expand Up @@ -357,8 +301,11 @@ void quit_thread_func(void)
if (thread_h) {
ask_user(quit_with_running_thread, &c, 1, 'y');
if (c == 'y') {
free_thread_job_list(thread_h->next);
thread_h->next = NULL;
ask_user(quit_waiting_only_current, &c, 1, 'y');
if (c == 'n') {
free_thread_job_list(thread_h->next);
thread_h->next = NULL;
}
pthread_join(th, NULL);
} else {
free_thread_job_list(thread_h);
Expand Down
1 change: 0 additions & 1 deletion src/helper_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ void print_info(const char *str, int i);
void *safe_malloc(ssize_t size, const char *str);
void free_str(char *str[PATH_MAX]);
int get_mimetype(const char *path, const char *test);
thread_job_list *add_thread(thread_job_list *h);
void init_thread(int type, void (*f)(void), const char *str);
void free_copied_list(file_list *h);
int remove_from_list(const char *name);
Expand Down
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ static void read_config_file(void)
{
config_t cfg;
const char *config_file_name = "/etc/default/ncursesFM.conf";
// const char *config_file_name = "/home/federico/ncursesFM/ncursesFM.conf"; // local test entry
const char *str_editor, *str_starting_dir;
int start_with_2_tabs;

Expand Down
5 changes: 3 additions & 2 deletions src/string_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const char *sure = "Are you serious? y/N:> ";

const char *already_searching = "There's already a search in progress. Wait for it.";
const char *search_mem_fail = "Stopping search as no more memory can be allocated.";
const char *search_insert_name = "Insert filename to be found, at least 5 chars:> ";
const char *search_insert_name = "Insert filename to be found, at least 5 chars, max 20 chars.:> ";
const char *search_archives = "Do you want to search in archives too? Search can result slower and has higher memory usage. y/N:> ";
const char *searched_string_minimum = "At least 5 chars...";
const char *too_many_found = "Too many files found; try with a larger string.";
Expand Down Expand Up @@ -52,7 +52,8 @@ const char *selected_mess = "There are selected files.";

const char *file_used_by_thread = "There's a thread working on this file/dir. Please wait.";
const char *thread_running = "There's already a thread working. This thread will be queued.";
const char *quit_with_running_thread = "A job is still running. Do you want to wait for it?(You should!) It only waits for current job, other queued job will be lost. Y/n:> ";
const char *quit_with_running_thread = "A job is still running. Do you want to wait for it?(You should!) :> ";
const char *quit_waiting_only_current = "Wait for all the jobs (Y) or only current job (n)?";

const char *helper_string[] = { "n and r to create/remove a file.",
"Enter to surf between folders or to open files with either xdg-open (if in a X session) or (text only) $editor var.",
Expand Down
1 change: 1 addition & 0 deletions src/string_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ const char *selected_mess;
const char *file_used_by_thread;
const char *thread_running;
const char *quit_with_running_thread;
const char *quit_waiting_only_current;

const char *helper_string[HELPER_HEIGHT - 2];
59 changes: 57 additions & 2 deletions src/ui_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void create_helper_win(void);
static void remove_helper_win(void);
static void change_unit(float size, char *str);

WINDOW *helper_win = NULL;
static WINDOW *helper_win = NULL, *info_win = NULL;
static int dim, width[MAX_TABS];

/*
Expand Down Expand Up @@ -120,7 +120,7 @@ void generate_list(int win)
* else it indicates how many strings the function has to print (starting from files[old_dim])
* If stat_active == 1 for 'win', and 'win' is not in search mode, it prints stats about size and permissions for every file.
*/
void list_everything(int win, int old_dim, int end, char **files)
void list_everything(int win, int old_dim, int end, char *files[])
{
int i;

Expand Down Expand Up @@ -417,4 +417,59 @@ void erase_stat(void)
wclrtoeol(ps[active].fm);
}
print_border_and_title(active);
}

/*
* Given a string str, and a line i, prints str on the I line of INFO_WIN.
* Plus, it searches for running th, and if found, prints running_h message(depends on its type) at the end of INFO_LINE
* It searches for selected_files too, and prints a message at the end of INFO_LINE - (strlen(running_h mesg) if there's.
* Finally, if a search is running, prints a message at the end of ERR_LINE;
*/
void print_info(const char *str, int i)
{
int k;
char st[PATH_MAX];

for (k = INFO_LINE; k != ERR_LINE + 1; k++) {
wmove(info_win, k, strlen("I:") + 1);
wclrtoeol(info_win);
}
k = 0;
if (thread_h && thread_h->type) {
sprintf(st, "[%d/%d] %s", thread_h->num, num_of_jobs, thread_job_mesg[thread_h->type - 1]);
k = strlen(st) + 1;
mvwprintw(info_win, INFO_LINE, COLS - strlen(st), st);
}
if (selected) {
mvwprintw(info_win, INFO_LINE, COLS - k - strlen(selected_mess), selected_mess);
}
if ((sv.searching == 1) || (sv.searching == 2)) {
mvwprintw(info_win, ERR_LINE, COLS - strlen(searching_mess[sv.searching - 1]), searching_mess[sv.searching - 1]);
}
if (str) {
mvwprintw(info_win, i, strlen("I: ") + 1, str);
}
wrefresh(info_win);
}

/*
* Given a str, a char input[dim], and a char c (that is default value if enter is pressed, if dim == 1),
* asks the user "str" and saves in input the user response.
*/
void ask_user(const char *str, char *input, int dim, char c)
{
echo();
print_info(str, INFO_LINE);
if (dim == 1) {
*input = wgetch(info_win);
if ((*input >= 'A') && (*input <= 'Z')) {
*input = tolower(*input);
} else if (*input == 10) {
*input = c;
}
} else {
wgetstr(info_win, input);
}
noecho();
print_info(NULL, INFO_LINE);
}
2 changes: 1 addition & 1 deletion src/ui_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
void screen_init(void);
void screen_end(void);
void generate_list(int win);
void list_everything(int win, int old_dim, int end, char **files);
void list_everything(int win, int old_dim, int end, char *files[]);
void new_tab(void);
void delete_tab(void);
void scroll_down(char **str);
Expand Down

0 comments on commit ac249cb

Please sign in to comment.