Code

disable more features with --enable-mini
[ncmpc.git] / src / screen.c
index 3cfc813d9ce298061cb9f5eec3eac67fa7b07804..17641df997a2bfb5fc3efdebd16d431c30e8884c 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * (c) 2004 by Kalle Wallin <kaw@linux.se>
  *
  * This program is free software; you can redistribute it and/or modify
 #include "screen_list.h"
 #include "screen_utils.h"
 #include "config.h"
-#include "ncmpc.h"
+#include "i18n.h"
 #include "support.h"
+#include "charset.h"
 #include "mpdclient.h"
 #include "utils.h"
-#include "command.h"
 #include "options.h"
 #include "colors.h"
 #include "strfsong.h"
-#include "wreadln.h"
 
 #include <stdlib.h>
 #include <unistd.h>
 #include <time.h>
 #include <locale.h>
 
+#ifndef NCMPC_MINI
+/** welcome message time [s] */
+static const GTime SCREEN_WELCOME_TIME = 10;
+#endif
+
+/** status message time [s] */
+static const GTime SCREEN_STATUS_MESSAGE_TIME = 3;
+
+/* minumum window size */
+static const int SCREEN_MIN_COLS = 14;
+static const int SCREEN_MIN_ROWS = 5;
+
 /* screens */
 
+#ifndef NCMPC_MINI
 static gboolean welcome = TRUE;
-static struct screen screen;
+#endif
+
+struct screen screen;
 static const struct screen_functions *mode_fn = &screen_playlist;
 static int seek_id = -1;
 static int seek_target_time = 0;
@@ -67,11 +79,12 @@ screen_switch(const struct screen_functions *sf, struct mpdclient *c)
 
        /* get functions for the new mode */
        mode_fn = sf;
-       screen.painted = 0;
 
        /* open the new mode */
        if (mode_fn->open != NULL)
-               mode_fn->open(&screen, c);
+               mode_fn->open(c);
+
+       screen_paint(c);
 }
 
 static int
@@ -101,7 +114,6 @@ screen_next_mode(mpdclient_t *c, int offset)
        else if (next>=max)
                next = 0;
 
-       D("current mode: %d:%d    next:%d\n", current, max, next);
        sf = screen_lookup_name(options.screen_list[next]);
        if (sf != NULL)
                screen_switch(sf, c);
@@ -117,6 +129,7 @@ paint_top_window2(const char *header, mpdclient_t *c)
        if (header[0]) {
                colors_use(w, COLOR_TITLE_BOLD);
                mvwaddstr(w, 0, 0, header);
+#ifndef NCMPC_MINI
        } else {
                colors_use(w, COLOR_TITLE_BOLD);
                waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
@@ -147,15 +160,17 @@ paint_top_window2(const char *header, mpdclient_t *c)
                waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
                colors_use(w, COLOR_TITLE);
                waddstr(w, _(":Lyrics  "));
+#endif
 #endif
        }
+
        if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
                g_snprintf(buf, 32, _("Volume n/a "));
        } else {
                g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
        }
        colors_use(w, COLOR_TITLE);
-       mvwaddstr(w, 0, screen.top_window.cols-my_strlen(buf), buf);
+       mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
 
        flags[0] = 0;
        if (c->status != NULL) {
@@ -186,11 +201,11 @@ static void
 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
 {
        static int prev_volume = -1;
-       static size_t prev_header_len = -1;
+       static unsigned prev_header_len = -1;
        WINDOW *w = screen.top_window.w;
 
-       if (prev_header_len!=my_strlen(header)) {
-               prev_header_len = my_strlen(header);
+       if (prev_header_len != utf8_width(header)) {
+               prev_header_len = utf8_width(header);
                full_repaint = 1;
        }
 
@@ -242,7 +257,11 @@ paint_status_window(mpdclient_t *c)
        mpd_Status *status = c->status;
        mpd_Song *song = c->song;
        int elapsedTime = 0;
+#ifdef NCMPC_MINI
+       static char bitrate[1];
+#else
        char bitrate[16];
+#endif
        const char *str = NULL;
        int x = 0;
 
@@ -267,7 +286,7 @@ paint_status_window(mpdclient_t *c)
 
        if (str) {
                waddstr(w, str);
-               x += my_strlen(str)+1;
+               x += utf8_width(str) + 1;
        }
 
        /* create time string */
@@ -285,12 +304,14 @@ paint_status_window(mpdclient_t *c)
                                elapsedTime = seek_target_time;
 
                        /* display bitrate if visible-bitrate is true */
+#ifndef NCMPC_MINI
                        if (options.visible_bitrate) {
                                g_snprintf(bitrate, 16,
                                           " [%d kbps]", status->bitRate);
                        } else {
                                bitrate[0] = '\0';
                        }
+#endif
 
                        /*write out the time, using hours if time over 60 minutes*/
                        if (c->status->totalTime > 3600) {
@@ -304,37 +325,46 @@ paint_status_window(mpdclient_t *c)
                                           bitrate, elapsedTime/60, elapsedTime%60,
                                           status->totalTime/60,   status->totalTime%60 );
                        }
+#ifndef NCMPC_MINI
                } else {
                        g_snprintf(screen.buf, screen.buf_size,
                                   " [%d kbps]", status->bitRate );
+#endif
                }
+#ifndef NCMPC_MINI
        } else {
                time_t timep;
 
                time(&timep);
                strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
+#endif
        }
 
        /* display song */
        if (status != NULL && (IS_PLAYING(status->state) ||
                               IS_PAUSED(status->state))) {
                char songname[MAX_SONGNAME_LENGTH];
-               int width = COLS-x-my_strlen(screen.buf);
+#ifndef NCMPC_MINI
+               int width = COLS - x - utf8_width(screen.buf);
+#endif
 
                if (song)
-                       strfsong(songname, MAX_SONGNAME_LENGTH, STATUS_FORMAT, song);
+                       strfsong(songname, MAX_SONGNAME_LENGTH,
+                                options.status_format, song);
                else
                        songname[0] = '\0';
 
                colors_use(w, COLOR_STATUS);
                /* scroll if the song name is to long */
-               if (options.scroll && my_strlen(songname) > (size_t)width) {
+#ifndef NCMPC_MINI
+               if (options.scroll && utf8_width(songname) > (unsigned)width) {
                        static  scroll_state_t st = { 0, 0 };
                        char *tmp = strscroll(songname, options.scroll_sep, width, &st);
 
                        g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
                        g_free(tmp);
                }
+#endif
                //mvwaddnstr(w, 0, x, songname, width);
                mvwaddstr(w, 0, x, songname);
        }
@@ -363,9 +393,8 @@ screen_exit(void)
 }
 
 void
-screen_resize(void)
+screen_resize(struct mpdclient *c)
 {
-       D("Resize rows %d->%d, cols %d->%d\n",screen.rows,LINES,screen.cols,COLS);
        if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
                screen_exit();
                fprintf(stderr, _("Error: Screen to small!\n"));
@@ -408,7 +437,7 @@ screen_resize(void)
        curs_set(1);
        curs_set(0);
 
-       screen.painted = 0;
+       screen_paint(c);
 }
 
 void
@@ -451,7 +480,6 @@ screen_init(mpdclient_t *c)
        screen.buf  = g_malloc(screen.cols);
        screen.buf_size = screen.cols;
        screen.findbuf = NULL;
-       screen.painted = 0;
        screen.start_timestamp = time(NULL);
        screen.last_cmd = CMD_NONE;
 
@@ -495,6 +523,7 @@ screen_init(mpdclient_t *c)
        leaveok(screen.status_window.w, FALSE);
        keypad(screen.status_window.w, TRUE);
 
+#ifdef ENABLE_COLORS
        if (options.enable_colors) {
                /* set background attributes */
                wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
@@ -504,6 +533,7 @@ screen_init(mpdclient_t *c)
                wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
                colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
        }
+#endif
 
        refresh();
 
@@ -512,11 +542,7 @@ screen_init(mpdclient_t *c)
                         screen.main_window.cols, screen.main_window.rows);
 
        if (mode_fn->open != NULL)
-               mode_fn->open(&screen, c);
-
-       /* initialize wreadln */
-       wrln_wgetch = my_wgetch;
-       wrln_max_history_length = 16;
+               mode_fn->open(c);
 }
 
 void
@@ -527,7 +553,6 @@ screen_paint(mpdclient_t *c)
        if (mode_fn->get_title != NULL)
                title = mode_fn->get_title(screen.buf, screen.buf_size);
 
-       D("screen_paint(%s)\n", title);
        /* paint the title/header window */
        if( title )
                paint_top_window(title, c, 1);
@@ -537,11 +562,10 @@ screen_paint(mpdclient_t *c)
        /* paint the main window */
        wclear(screen.main_window.w);
        if (mode_fn->paint != NULL)
-               mode_fn->paint(c);
+               mode_fn->paint();
 
        paint_progress_window(c);
        paint_status_window(c);
-       screen.painted = 1;
        wmove(screen.main_window.w, 0, 0);
        wnoutrefresh(screen.main_window.w);
 
@@ -552,14 +576,12 @@ screen_paint(mpdclient_t *c)
 void
 screen_update(mpdclient_t *c)
 {
+#ifndef NCMPC_MINI
        static int repeat = -1;
        static int random_enabled = -1;
        static int crossfade = -1;
        static int dbupdate = -1;
 
-       if( !screen.painted )
-               screen_paint(c);
-
        /* print a message if mpd status has changed */
        if (c->status != NULL) {
                if (repeat < 0) {
@@ -598,9 +620,13 @@ screen_update(mpdclient_t *c)
            screen.last_cmd==CMD_NONE &&
            time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
                paint_top_window("", c, 0);
-       else if (mode_fn->get_title != NULL) {
+       else
+#endif
+       if (mode_fn->get_title != NULL) {
                paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
+#ifndef NCMPC_MINI
                welcome = FALSE;
+#endif
        } else
                paint_top_window("", c, 0);
 
@@ -642,7 +668,6 @@ screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
 
        /* retreive the mouse event from ncurses */
        getmouse(&event);
-       D("mouse: id=%d  y=%d,x=%d,z=%d\n",event.id,event.y,event.x,event.z);
        /* calculate the selected row in the list window */
        *row = event.y - screen.top_window.rows;
        /* copy button state bits */
@@ -758,9 +783,11 @@ void
 screen_cmd(mpdclient_t *c, command_t cmd)
 {
        screen.last_cmd = cmd;
+#ifndef NCMPC_MINI
        welcome = FALSE;
+#endif
 
-       if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
+       if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
                return;
 
        if (screen_client_cmd(c, cmd))
@@ -780,7 +807,7 @@ screen_cmd(mpdclient_t *c, command_t cmd)
                                     _("Auto center mode: Off"));
                break;
        case CMD_SCREEN_UPDATE:
-               screen.painted = 0;
+               screen_paint(c);
                break;
        case CMD_SCREEN_PREVIOUS:
                screen_next_mode(c, -1);
@@ -794,9 +821,11 @@ screen_cmd(mpdclient_t *c, command_t cmd)
        case CMD_SCREEN_FILE:
                screen_switch(&screen_browse, c);
                break;
+#ifdef ENABLE_HELP_SCREEN
        case CMD_SCREEN_HELP:
                screen_switch(&screen_help, c);
                break;
+#endif
 #ifdef ENABLE_SEARCH_SCREEN
        case CMD_SCREEN_SEARCH:
                screen_switch(&screen_search, c);