-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.h
195 lines (157 loc) · 5.22 KB
/
ui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* This file is part of clapl.
*
* clapl is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 or later
* <http://gnu.org/license/gpl.html>
*
* clapl is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY, without even the implied warranty of
* MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License of more details.
*/
/**
* @file ui.h
* @author Torsten Lehmann
* @date 2018-05-06
* @brief file containing definitions of the user interface used by clapl
*/
#ifndef _UI_H_
#define _UI_H_
#include <curses.h>
#include <locale.h>
#include <string.h>
#include <sqlite3.h>
#include "enums.h"
#include "logger.h"
#include "cache.h"
#include "configparser.h"
#include "playback.h"
#define ARTISTWIN_POS 0, LINES / 10
#define ARTISTWIN_WIDTH COLS / 6
#define ARTISTWIN_HEIGHT LINES / 2 - 1
#define ALBUMWIN_POS 0, (6 * LINES / 10)
#define ALBUMWIN_WIDTH COLS / 6
#define ALBUMWIN_HEIGHT LINES - 6 * LINES / 10 - 1 - 1
#define TRACKWIN_POS (COLS / 6), LINES / 10
#define TRACKWIN_WIDTH COLS - 2 * COLS / 3 //COLS / 3
#define TRACKWIN_HEIGHT LINES - LINES / 10 - 1 - 1
#define LYRICWIN_POS COLS / 2, 0
#define LYRICWIN_WIDTH COLS - COLS / 2
#define LYRICWIN_HEIGHT LINES - 1 - 1
#define INFOWIN_POS 0, 0
#define INFOWIN_WIDTH COLS / 2
#define INFOWIN_HEIGHT LINES / 10
#define DEFAULT_OFFSET 2
/*
* Positions of the Windows
* ----------------------------------------------
* | INFO | |
* |--------------------| LYRICS |
* |ARTIST |TITLE | |
* | | | |
* | | | |
* |---------| | |
* |ALBUM | | |
* | | | |
* ----------------------------------------------
*/
/**
* @brief definition of the userinterface struct used by clapl
* This struct sums up some neccessary components as well as some options
* for the user interface
*/
typedef struct userinterface
{
WINDOW *artistWin;
WINDOW *albumWin;
WINDOW *trackWin;
WINDOW *lyricWin;
WINDOW *infoWin;
WINDOW *selectedWin;
cache *c;
char color;
} userinterface;
/**
* @brief initialize the user interface; is calling initializing functions defined by ncurses
*/
void ui_init (void);
/**
* @brief redraws the entire user interface (ui have to be created using ui_create)
* @param ui pointer to the userinterface (have to be created using ui_create)
*/
void ui_redraw (userinterface *ui);
/**
* @brief creates a single window used in the ui
* @param x the x coordinate of the window
* @param y the y coordinate of the window
* @param width the width of the window
* @param height the height of the window
*/
WINDOW *win_create (const int x, const int y, const int width, const int height);
/**
* @brif clears a given window and rewrites the title given by string.
* @param ui pointer to the user interface
* @param win pointer to the window to be cleaned
* @param string title of the window to be displayed in the top left corner of the window
*/
void ui_clear_window (userinterface *ui, WINDOW *win, const char *string);
/**
* @brief creates the windows of the user interface
* @param ui pointer to the userinterface
*/
void ui_createWindows (userinterface *ui);
/**
* @brief creates the user interface
* @param db pointer to the sqlite3-database (have to be opened before)
* @param cp pointer to the configparser (have to be loaded before)
* @return returns the user interface or NULL on failure
*/
userinterface *ui_create (sqlite3 *db, configparser *cp);
/**
* @brief refreshes the user interface
* @param ui pointer to the userinterface
*/
void ui_refresh (userinterface *ui);
/**
* @brief prints a string to a window
* @param win pointer to the window the string should be written to
* @param width the maximum width of the window
* @param line the vertical position of the string
* @param string pointer to the string
*/
void ui_print_to_window (WINDOW *win, const int width, const int line, const char *string);
/**
* @brief prints the artists
* @param ui pointer to the user interface
*/
void ui_print_artist (userinterface *ui);
/**
* @brief prints the album
* @param ui pointer to the user interface
*/
void ui_print_album (userinterface *ui);
/**
* @brief prints the tracks
* @param ui pointer to the user interface
*/
void ui_print_track (userinterface *ui);
/**
* @brief reads a single line of text from a file
* @param file pointer to the file (have to be opened before)
* @param buffer_size size of the buffer
* @return pointer to the read line
*/
char *ui_read_line (FILE *file, const int buffer_size);
/**
* @brief prints the lyrics to the user interface
* @param ui pointer to the user interface
*/
void ui_print_lyrics (userinterface *ui);
/**
* @brief prints some info about the current played track
* @param ui pointer to the user interface
* @param a pointer to the audio struct of the current played track
*/
void ui_print_info (userinterface *ui, audio *a);
#endif