Ejemplo n.º 1
0
void gui_input_playlist(int c) {
    int j;

    switch (c) {
    case '-':
        // Move selected forward in playlist
        if (playlist->selected != playlist->head) {
            controller_playlist_move_up();
            gui_update_playlist();
        }
        break;

    case '+':
    case '=':
        // Move selected backwards in playlist
        if (playlist->selected != playlist->tail) {
            controller_playlist_move_down();
            gui_update_playlist();
        }
        break;
    case KEY_ENTER:
    case '\n':
    case '\r':
        if (playlist->playing) {
            playlist->selected = songdata_next_valid(playlist, playlist->head, KEY_HOME);
            playlist->where = 1;
            playlist->wheretop = 0;

            for (j = 0; playlist->selected->next && playlist->selected != playlist->playing; j++) {
                playlist->selected = songdata_next_valid(playlist, playlist->selected->next, KEY_DOWN);
                playlist->where++;
            }
            gui_update_playlist();
        }
        break;
    case KEY_DC:
        // remove selected from playlist
        if (playlist->selected) {
            if (playlist->playing == playlist->selected && playlist->playing->next != NULL) {
                controller_next(playlist);
            } else if (playlist->playing == playlist->selected && playlist->playing->next == NULL) {
                controller_stop();
            }
            songdata_del(playlist, playlist->selected);
            gui_update_playlist();
            gui_update_info();
        }
        break;
    default:
        window_input(playlist_window, c);
        break;
    }
}
Ejemplo n.º 2
0
void gui_input_filelist(int c) {
	int alt = 0;
	int n;
	songdata_song *ftmp;

	if (c == 27) {
		alt = 1;
		c = getch();
	}

	switch (c) {
		case KEY_ENTER:
		case '\n':
		case '\r':
			typed_letters[0] = '\0';
			if ((mp3list->selected->flags & F_DIR)) {
				if (!alt) {
					// change to another directory
					if (!strcmp("../", mp3list->selected->filename)) {
						char * filename = strdup(dirstack_filename());
						char * fullpath = strdup(dirstack_fullpath());
						dirstack_pop();
						songdata_read_mp3_list(mp3list, fullpath, L_NEW);
						while (strcmp(mp3list->selected->filename, filename))
							window_input(filelist_window, KEY_DOWN);
						free(filename);
						free(fullpath);
					} else {
						if (!(mp3list->flags & F_VIRTUAL))
							dirstack_push(mp3list->from, mp3list->selected->filename);
						songdata_read_mp3_list(mp3list, mp3list->selected->fullpath, L_NEW);
					}
					gui_update_filelist();
				} else {
					// add songs from directory
					if (previous_selected)
						free(previous_selected);
					previous_selected = strdup(mp3list->selected->fullpath);
					if ((!(mp3list->flags & F_VIRTUAL)) & (strcmp("../", mp3list->selected->fullpath))) {
						add_to_playlist_recursive(playlist, playlist->tail, mp3list->selected);
						gui_update_playlist();
					}
				}
			} else if (mp3list->selected->flags & F_PLAYLIST) {
				if (!alt) {
					dirstack_push(mp3list->from, mp3list->selected->filename);
					songdata_read_mp3_list(mp3list, mp3list->selected->fullpath, L_NEW);
					gui_update_filelist();
				} else {
					add_to_playlist_recursive(playlist, playlist->tail, mp3list->selected);
					gui_update_playlist();
				}
			} else // normal mp3
				if (strcmp(previous_selected, mp3list->selected->fullpath)) {
				if (previous_selected)
					free(previous_selected);
				previous_selected = strdup(mp3list->selected->fullpath);

				if (!alt)
					add_to_playlist(playlist, playlist->tail, mp3list->selected);
				else
					add_to_playlist(playlist, playlist->selected, mp3list->selected);
				gui_update_playlist();
				if (conf->c_flags & C_FADVANCE) {
					window_input(filelist_window, KEY_DOWN);
				}
			}
			break;
		case KEY_LEFT:
			// leave directory
			if (!dirstack_empty()) {
				char *filename = strdup(dirstack_filename());
				char *fullpath = strdup(dirstack_fullpath());
				dirstack_pop();
				songdata_read_mp3_list(mp3list, fullpath, L_NEW);
				while (strcmp(mp3list->selected->filename, filename)) {
					window_input_list(filelist_window, KEY_DOWN);
				}
				gui_update_filelist();
				gui_update_info();
				free(filename);
				free(fullpath);
			}
			break;

		case KEY_RIGHT:
			// enter directory
			if ((mp3list->selected->flags & (F_DIR | F_PLAYLIST))
					&& (strncmp(mp3list->selected->filename, "../", 3))) {
				if (!(mp3list->flags & F_VIRTUAL)) {
					dirstack_push(mp3list->from, mp3list->selected->filename);
				}
				songdata_read_mp3_list(mp3list, mp3list->selected->fullpath, L_NEW);
				if (mp3list->head) {
					window_input_list(filelist_window, KEY_DOWN);
				}
			}
			gui_update_filelist();
			gui_update_info();
			break;
		case KEY_IC:
			if (!((mp3list->selected->flags & F_DIR) | (mp3list->selected->flags & F_PLAYLIST)))
				if (strcmp(previous_selected, mp3list->selected->fullpath)) {
					// we dont want to add the last file multiple times
					if (previous_selected)
						free(previous_selected);
					previous_selected = strdup(mp3list->selected->fullpath);

					if (playlist->playing)
						add_to_playlist(playlist, playlist->playing, mp3list->selected);
					else
						add_to_playlist(playlist, playlist->selected, mp3list->selected);
					if (conf->c_flags & C_FADVANCE) {
						window_input(filelist_window, KEY_DOWN);
						gui_update_filelist();
						gui_update_info();
					}
					gui_update_playlist();
				}
			break;
		case 'a'...'z':
		case 'A'...'Z':
		case '0'...'9':
		case '.':
		case ' ':
			ftmp = mp3list->head;
			n = 0;
			
			time_t time_now = time(NULL);
			if (difftime(time_now, typed_letters_last_activity) > 10) {
				typed_letters[0] = '\0';
			}
			
			if (strlen(typed_letters) < 4) {
				// add the letter to the string and reset the timeout
				strcat(typed_letters, (char *) &c);
			}

			while (strncasecmp(ftmp->filename, typed_letters, strlen(typed_letters)) != 0) {
				if (ftmp == mp3list->tail) {
					ftmp = NULL;
					break;
				}
				ftmp = ftmp->next;
				n++;
			}

			if (ftmp) {
				// match found
				mp3list->selected = ftmp;
				mp3list->where = n;
				gui_update_filelist();
			}
			
			typed_letters_last_activity = time_now;
			break;
		case KEY_BACKSPACE:
			if (strlen(typed_letters) >= 1) {
				typed_letters[strlen(typed_letters) - 1] = '\0';
				typed_letters_last_activity = time(NULL);
			}
			break;
		default:
			window_input(filelist_window, c);
			break;
	}
}