SCTC
the soundcloud.com terminal client
Macros | Functions | Variables
command.c File Reference

Implementation of all the commands supported by SCTC. More...

#include "_hard_config.h"
#include "command.h"
#include <ncurses.h>
#include "config.h"
#include "helper.h"
#include "jspf.h"
#include "log.h"
#include "network/network.h"
#include "network/tls.h"
#include "sound.h"
#include "soundcloud.h"
#include "state.h"
#include "track.h"
#include "tui.h"
Include dependency graph for command.c:

Macros

#define _GNU_SOURCE
 
#define NONE   (~0)
 
#define TIME_BUFFER_SIZE   64
 
#define MIN(x, y)   (x < y ? x : y)
 
#define LOGO_PART
 
#define DESCRIPTION_PART   "SCTC is a curses based client for soundcloud.com.\nIts primary target is streaming - the most social media - like features are and will not (be) supported."
 
#define LICENSE_PART   "SCTC is Free Software released under the GPL v3 or later license.\nFor details see LICENSE or visit https://www.gnu.org/copyleft/gpl.html"
 
#define ALPHA_PART   "This version is NOT a stable release - expect bugs!"
 
#define FEATURE_PART   "Implemented / functional features:\n - TUI (resizing, updating)\n - playback\n - caching\n - bookmarks"
 
#define NONFEATURE_PART   "Planned features not yet implemented:\n - playlist management\n - logging in to soundcloud.com (OAuth)\n - reading playlists from soundcloud.com"
 
#define KNOWN_BUGS_PART   "Known bugs:\n - track in bookmarks is not marked as 'currently playing'"
 
#define PARAGRAPH_PART   "\n \n"
 

Functions

static void handle_textbox ()
 Handle input for a textbox. More...
 
static bool handle_command (char *buffer, size_t buffer_size)
 Handle input for a command. More...
 
static int command_dispatcher (char *command)
 
static void cmd_download (char *unused)
 
static void cmd_open_user (char *_user)
 
static void cmd_add (char *_list)
 
static void cmd_del (char *unused)
 
static void cmd_list_new (char *_name)
 
static void cmd_write_playlist (char *_file)
 
static void cmd_goto (char *hint)
 
void switch_to_list (unsigned int id)
 Switch to playlist with id More...
 
static void cmd_list (char *list)
 Switch to playlist specified in string list More...
 
static void cmd_seek (char *time)
 
static void cmd_exit (char *unused)
 Exit SCTC. More...
 
static void search_direction (bool down)
 
static bool handle_search (char *buffer, size_t buffer_size)
 
static void cmd_search_next (char *unused)
 
static void cmd_search_prev (char *unused)
 
static void cmd_search_start (char *unused)
 
static void cmd_command_input (char *unused)
 Initiate a command input. More...
 
static void cmd_help (char *unused)
 Display 'Help' Dialog. More...
 
static void cmd_repeat_none (char *unused)
 Set repeat to 'none'. More...
 
static void cmd_repeat_one (char *unused)
 Set repeat to 'one' (repeat single track) More...
 
static void cmd_repeat_all (char *unused)
 Set repeat to 'all' (repeat whole track_list) More...
 
static void cmd_repeat_toggle (char *unused)
 
static void cmd_yank (char *unused)
 
static void cmd_details (char *unused)
 
static void stop_playback (bool reset)
 Stop playback of currently playing track. More...
 
static void cmd_play (char *unused)
 
static void cmd_pause (char *unused)
 
static void cmd_stop (char *unused)
 
static void cmd_redraw (char *unused)
 Issue a redraw of the whole screen. More...
 
static size_t submit_updated_suggestion_list (struct command *buffer, char *filter)
 Generate a new list of commands using the filter filter. More...
 

Variables

const struct command commands []
 Array of all commands supported by SCTC. More...
 
const size_t command_count = sizeof(commands) / sizeof(struct command) - 1
 

Detailed Description

Implementation of all the commands supported by SCTC.

This file contains the actual implementation of the all cmd_* functions. These function contain the actual behaviour in case of user input. Any command may be mapped to a key via configfile.

See also
config.c

Macro Definition Documentation

#define _GNU_SOURCE
#define ALPHA_PART   "This version is NOT a stable release - expect bugs!"
#define DESCRIPTION_PART   "SCTC is a curses based client for soundcloud.com.\nIts primary target is streaming - the most social media - like features are and will not (be) supported."
#define FEATURE_PART   "Implemented / functional features:\n - TUI (resizing, updating)\n - playback\n - caching\n - bookmarks"
#define KNOWN_BUGS_PART   "Known bugs:\n - track in bookmarks is not marked as 'currently playing'"
#define LICENSE_PART   "SCTC is Free Software released under the GPL v3 or later license.\nFor details see LICENSE or visit https://www.gnu.org/copyleft/gpl.html"
#define LOGO_PART
Value:
" ____________________\n"\
" / __/ ___/_ __/ ___/\n"\
" _\\ \\/ /__ / / / /__ \n"\
"/___/\\___/ /_/ \\___/ \n"\
" - the soundcloud.com terminal client"
#define MIN (   x,
 
)    (x < y ? x : y)
#define NONE   (~0)
#define NONFEATURE_PART   "Planned features not yet implemented:\n - playlist management\n - logging in to soundcloud.com (OAuth)\n - reading playlists from soundcloud.com"
#define PARAGRAPH_PART   "\n \n"
#define TIME_BUFFER_SIZE   64

Function Documentation

static void cmd_add ( char *  _list)
static

Here is the call graph for this function:

static void cmd_command_input ( char *  unused)
static

Initiate a command input.

Parameters
unusedUnused parameter, required due to interface of cmd_* functions

Here is the call graph for this function:

static void cmd_del ( char *  unused)
static

Here is the call graph for this function:

static void cmd_details ( char *  unused)
static

Here is the call graph for this function:

static void cmd_download ( char *  unused)
static
Todo:
a) does not belong here
b) does not work
static void cmd_exit ( char *  unused)
static

Exit SCTC.

Writes the list of bookmarks to file and shuts down SCTC.

Parameters
unusedUnused parameter, required due to interface of cmd_* functions
Returns
does not return

Here is the call graph for this function:

static void cmd_goto ( char *  hint)
static

Here is the call graph for this function:

static void cmd_help ( char *  unused)
static

Display 'Help' Dialog.

Parameters
unusedUnused parameter, required due to interface of cmd_* functions

Here is the call graph for this function:

static void cmd_list ( char *  list)
static

Switch to playlist specified in string list

Parameters
listThe id of the playlist to switch to
Returns
true on success, otherwise false

Here is the call graph for this function:

static void cmd_list_new ( char *  _name)
static

Here is the call graph for this function:

static void cmd_open_user ( char *  _user)
static

Here is the call graph for this function:

static void cmd_pause ( char *  unused)
static

Here is the call graph for this function:

static void cmd_play ( char *  unused)
static

Here is the call graph for this function:

static void cmd_redraw ( char *  unused)
static

Issue a redraw of the whole screen.

Returns
true

Here is the call graph for this function:

static void cmd_repeat_all ( char *  unused)
static

Set repeat to 'all' (repeat whole track_list)

Parameters
unusedUnused parameter, required due to interface of cmd_* functions

Here is the call graph for this function:

Here is the caller graph for this function:

static void cmd_repeat_none ( char *  unused)
static

Set repeat to 'none'.

Parameters
unusedUnused parameter, required due to interface of cmd_* functions

Here is the call graph for this function:

Here is the caller graph for this function:

static void cmd_repeat_one ( char *  unused)
static

Set repeat to 'one' (repeat single track)

Parameters
unusedUnused parameter, required due to interface of cmd_* functions

Here is the call graph for this function:

Here is the caller graph for this function:

static void cmd_repeat_toggle ( char *  unused)
static

Here is the call graph for this function:

static void cmd_search_next ( char *  unused)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void cmd_search_prev ( char *  unused)
static

Here is the call graph for this function:

static void cmd_search_start ( char *  unused)
static

Here is the call graph for this function:

static void cmd_seek ( char *  time)
static

Here is the call graph for this function:

static void cmd_stop ( char *  unused)
static

Here is the call graph for this function:

static void cmd_write_playlist ( char *  _file)
static

Here is the call graph for this function:

static void cmd_yank ( char *  unused)
static

Here is the call graph for this function:

static int command_dispatcher ( char *  command)
static

These functions represent the individual commands action.
For instance executing a redraw will result in calling the function cmd_redraw().

Todo:
Commands are, at this point, only usefull for the main interface (the list). As soon as we open any other window everything is hardcoded again!

Here is the call graph for this function:

Here is the caller graph for this function:

static bool handle_command ( char *  buffer,
size_t  buffer_size 
)
static

Handle input for a command.

Note that buffer is modified even if handle_command() returns false.

Parameters
[out]bufferPointer to a buffer receiving the user's input
buffer_sizeSize of buffer (in Bytes)
Returns
true if a command is in buffer, false otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

static bool handle_search ( char *  buffer,
size_t  buffer_size 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void handle_textbox ( )
static

Handle input for a textbox.

Handles user's input for a textbox, such as scroll up, scroll down and close textbox.

Here is the call graph for this function:

Here is the caller graph for this function:

static void search_direction ( bool  down)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void stop_playback ( bool  reset)
static

Stop playback of currently playing track.

Nothing happens in case no track is currently playing. If reset is set to true the position of the currently plaing track is reset to 0, if set to false the position will not be modified. The position can be used lateron to continue playing.

Parameters
resetReset the current position of playback to 0

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t submit_updated_suggestion_list ( struct command buffer,
char *  filter 
)
static

Generate a new list of commands using the filter filter.

Filtering equals to matching the first strlen(filter) chars against the individual commands' names. Matching is done case-insensitive.

Parameters
[out]bufferA pointer to a buffer holding the commands (is expected to be of size command_count + 1) * sizeof(struct command))
filterThe filter to use for filtering the list of commands
Returns
The number of elements matching the filter

Here is the call graph for this function:

Here is the caller graph for this function:

void switch_to_list ( unsigned int  id)

Switch to playlist with id

Parameters
idThe id of the playlist to switch to
Returns
true on success, otherwise false

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const size_t command_count = sizeof(commands) / sizeof(struct command) - 1
const struct command commands[]
Initial value:
= {
{"add", cmd_add, "<ID of list>", "Add currently selected track to playlist with provided ID"},
{"command-input", cmd_command_input, "<none/ignored>", "Open command input field"},
{"del", cmd_del, "<none/ignored>", "Delete currently selected track from current playlist"},
{"details", cmd_details, "<none/ignored>", "Show details for currently selected track"},
{"download", cmd_download, "<none/ignored>", "Download the currently selected entry to file"},
{"exit", cmd_exit, "<none/ignored>", "Terminate SCTC"},
{"goto", cmd_goto, "<relative or absolute offset>", "Set selection to specific entry"},
{"help", cmd_help, "<none/ignored>", "Show help"},
{"list", cmd_list, "<number of list>", "Switch to specified playlist"},
{"list-new", cmd_list_new, "<name of list>", "Create a new playlist with specified name"},
{"open", cmd_open_user, "<name of user>", "Open a specific user's stream"},
{"pause", cmd_pause, "<none/ignored>", "Pause playback of current track"},
{"play", cmd_play, "<none/ignored>", "Start playback of currently selected track"},
{"redraw", cmd_redraw, "<none/ignored>", "Redraw the screen"},
{"repeat-none", cmd_repeat_none, "<none/ignored>", "Set repeat to 'none'"},
{"repeat-one", cmd_repeat_one, "<none/ignored>", "Set repeat to 'one'"},
{"repeat-all", cmd_repeat_all, "<none/ignored>", "Set repeat to 'all'"},
{"repeat-toggle", cmd_repeat_toggle, "<none/ignored>", "Toggle repeat (none -> one -> all -> none)"},
{"search-start", cmd_search_start, "<none/ignored>", "Start searching (open input field)"},
{"search-next", cmd_search_next, "<none/ignored>", "Continue search downwards"},
{"search-prev", cmd_search_prev, "<none/ignored>", "Continue search upwards"},
{"seek", cmd_seek, "<time to seek to>", "Seek to specified time in current track"},
{"stop", cmd_stop, "<none/ignored>", "Stop playback of current track"},
{"write", cmd_write_playlist, "<filename>", "Write current playlist to file (.jspf)", },
{"yank", cmd_yank, "<none/ignored>", "Copy URL of currently selected track to clipboard"},
{NULL, NULL, NULL}
}
static void cmd_redraw(char *unused)
Issue a redraw of the whole screen.
Definition: command.c:588
static void cmd_repeat_one(char *unused)
Set repeat to 'one' (repeat single track)
Definition: command.c:488
static void cmd_help(char *unused)
Display 'Help' Dialog.
Definition: command.c:468
static void cmd_seek(char *time)
Definition: command.c:318
static void cmd_goto(char *hint)
Definition: command.c:247
static void cmd_list(char *list)
Switch to playlist specified in string list
Definition: command.c:308
static void cmd_repeat_none(char *unused)
Set repeat to 'none'.
Definition: command.c:479
static void cmd_search_start(char *unused)
Definition: command.c:436
static void cmd_exit(char *unused)
Exit SCTC.
Definition: command.c:352
static void cmd_search_next(char *unused)
Definition: command.c:433
static void cmd_pause(char *unused)
Definition: command.c:581
static void cmd_stop(char *unused)
Definition: command.c:582
static void cmd_repeat_toggle(char *unused)
Definition: command.c:502
static void cmd_list_new(char *_name)
Definition: command.c:222
static void cmd_play(char *unused)
Definition: command.c:561
static void cmd_repeat_all(char *unused)
Set repeat to 'all' (repeat whole track_list)
Definition: command.c:497
static void cmd_command_input(char *unused)
Initiate a command input.
Definition: command.c:447
static void cmd_details(char *unused)
Definition: command.c:518
static void cmd_add(char *_list)
Definition: command.c:175
static void cmd_yank(char *unused)
Definition: command.c:510
static void cmd_download(char *unused)
Definition: command.c:111
static void cmd_write_playlist(char *_file)
Definition: command.c:237
static void cmd_open_user(char *_user)
Definition: command.c:158
static void cmd_search_prev(char *unused)
Definition: command.c:434
static void cmd_del(char *unused)
Definition: command.c:203

Array of all commands supported by SCTC.

Includes a description, which is, for instance, shown in the commandwindow, and the function to call in order to execute the command.

Todo:
Step by step, 'everything' should be moved here.
At some point in time we want to be able to bind keys via configfile.