conf: merge two translatable strings
[ncmpc.git] / src / screen_init.c
blob2f3b3238c7ebe22bd631de9a8bbda45edc6f95b2
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2017 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "screen.h"
21 #include "screen_interface.h"
22 #include "screen_list.h"
23 #include "config.h"
24 #include "i18n.h"
25 #include "utils.h"
26 #include "options.h"
27 #include "colors.h"
29 #include <stdlib.h>
31 #ifndef NCMPC_MINI
32 /** welcome message time [s] */
33 static const GTime SCREEN_WELCOME_TIME = 10;
34 #endif
36 /* minimum window size */
37 static const unsigned SCREEN_MIN_COLS = 14;
38 static const unsigned SCREEN_MIN_ROWS = 5;
40 void
41 screen_exit(void)
43 if (screen.current_page->close != NULL)
44 screen.current_page->close();
46 screen_list_exit();
48 string_list_free(screen.find_history);
49 g_free(screen.buf);
50 g_free(screen.findbuf);
52 title_bar_deinit(&screen.title_bar);
53 delwin(screen.main_window.w);
54 progress_bar_deinit(&screen.progress_bar);
55 status_bar_deinit(&screen.status_bar);
57 #ifndef NCMPC_MINI
58 if (screen.welcome_source_id != 0)
59 g_source_remove(screen.welcome_source_id);
60 #endif
63 void
64 screen_resize(struct mpdclient *c)
66 const unsigned cols = COLS, rows = LINES;
67 if (cols < SCREEN_MIN_COLS || rows < SCREEN_MIN_ROWS) {
68 screen_exit();
69 fprintf(stderr, "%s\n", _("Error: Screen too small"));
70 exit(EXIT_FAILURE);
73 #ifdef PDCURSES
74 resize_term(rows, cols);
75 #else
76 resizeterm(rows, cols);
77 #endif
79 title_bar_resize(&screen.title_bar, cols);
81 /* main window */
82 screen.main_window.cols = cols;
83 screen.main_window.rows = rows - 4;
84 wresize(screen.main_window.w, screen.main_window.rows, cols);
86 /* progress window */
87 progress_bar_resize(&screen.progress_bar, cols, rows - 2, 0);
89 /* status window */
90 status_bar_resize(&screen.status_bar, cols, rows - 1, 0);
92 screen.buf_size = cols;
93 g_free(screen.buf);
94 screen.buf = g_malloc(cols);
96 /* resize all screens */
97 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
99 /* ? - without this the cursor becomes visible with aterm & Eterm */
100 curs_set(1);
101 curs_set(0);
103 screen_paint(c, true);
106 #ifndef NCMPC_MINI
107 static gboolean
108 welcome_timer_callback(gpointer data)
110 struct mpdclient *c = data;
112 screen.welcome_source_id = 0;
114 paint_top_window(c);
115 doupdate();
117 return false;
119 #endif
121 void
122 screen_init(struct mpdclient *c)
124 const unsigned cols = COLS, rows = LINES;
125 if (cols < SCREEN_MIN_COLS || rows < SCREEN_MIN_ROWS) {
126 fprintf(stderr, "%s\n", _("Error: Screen too small"));
127 exit(EXIT_FAILURE);
130 screen.buf = g_malloc(cols);
131 screen.buf_size = cols;
132 screen.findbuf = NULL;
134 #ifndef NCMPC_MINI
135 if (options.welcome_screen_list)
136 screen.welcome_source_id =
137 g_timeout_add_seconds(SCREEN_WELCOME_TIME,
138 welcome_timer_callback, c);
139 #endif
141 /* create top window */
142 title_bar_init(&screen.title_bar, cols, 0, 0);
144 /* create main window */
145 window_init(&screen.main_window, rows - 4, cols, 2, 0);
147 if (!options.hardware_cursor)
148 leaveok(screen.main_window.w, TRUE);
150 keypad(screen.main_window.w, TRUE);
152 /* create progress window */
153 progress_bar_init(&screen.progress_bar, cols, rows - 2, 0);
155 /* create status window */
156 status_bar_init(&screen.status_bar, cols, rows - 1, 0);
158 #ifdef ENABLE_COLORS
159 if (options.enable_colors) {
160 /* set background attributes */
161 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
162 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
163 wbkgd(screen.title_bar.window.w, COLOR_PAIR(COLOR_TITLE));
164 wbkgd(screen.progress_bar.window.w,
165 COLOR_PAIR(COLOR_PROGRESSBAR));
166 wbkgd(screen.status_bar.window.w, COLOR_PAIR(COLOR_STATUS));
167 colors_use(screen.progress_bar.window.w, COLOR_PROGRESSBAR);
169 #endif
171 /* initialize screens */
172 screen_list_init(screen.main_window.w,
173 screen.main_window.cols, screen.main_window.rows);
175 if (screen.current_page->open != NULL)
176 screen.current_page->open(c);