Code

Use screen_status_printf() instead of screen_status_message().
authorKalle Wallin <kaw@linux.se>
Tue, 23 Mar 2004 19:17:20 +0000 (19:17 +0000)
committerKalle Wallin <kaw@linux.se>
Tue, 23 Mar 2004 19:17:20 +0000 (19:17 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@418 09075e82-0dd4-0310-85a5-a0d7c8717e4f

TODO
main.c
options.c
options.h
screen.c
screen.h
screen_file.c
screen_play.c
screen_utils.c

diff --git a/TODO b/TODO
index c76a4e54507964200078de43275437765a6c860d..d2a38c62da5ce276763e35bfbfc663fac945ee65 100644 (file)
--- a/TODO
+++ b/TODO
@@ -13,6 +13,8 @@ ncurses
 
 other
 ----------------------------------------------------------------------------
-  * find/search function in playlist (like in less '/')
+  * find/search function in playlist (like in less '/')                - done
+  * configuration file(s) - keybindings,colors...
+  * internationalization - gettext
 
 
diff --git a/main.c b/main.c
index 0a44051121436f42fab977011103f538cdb19730..7bd80c5dd24d699aa027180cb67a06ee4babdaad 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,8 +1,3 @@
-/* 
- * $Id: main.c,v 1.5 2004/03/16 14:34:49 kalle Exp $ 
- *
- */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include "command.h"
 #include "screen.h"
 
-#define BUFSIZE 256
-
 static mpd_client_t *mpc = NULL;
 
+
 void
 exit_and_cleanup(void)
 {
@@ -42,7 +36,7 @@ catch_sigint( int sig )
 }
 
 int 
-main(int argc, char *argv[])
+main(int argc, const char *argv[])
 {
   options_t *options;
   struct sigaction act;
@@ -96,6 +90,7 @@ main(int argc, char *argv[])
   if( mpc_error(mpc) )
     exit(EXIT_FAILURE);
 
+  /* initialize curses */
   screen_init();
   
   counter=0;
@@ -103,16 +98,14 @@ main(int argc, char *argv[])
   while( connected || options->reconnect )
     {
       command_t cmd;
-      char buf[BUFSIZE];
-       
+
       if( connected && counter==0  )
        {
          mpc_update(mpc);
          if( mpc_error(mpc) )
            {
              connected=0;
-             snprintf(buf, BUFSIZE, "Lost connection to %s", options->host);
-             screen_status_message(mpc, buf);
+             screen_status_printf("Lost connection to %s", options->host);
              mpd_closeConnection(mpc->connection);
              mpc->connection = NULL;
            }
@@ -133,14 +126,11 @@ main(int argc, char *argv[])
       else if( options->reconnect )
        {
          sleep(3);
-         snprintf(buf, BUFSIZE, 
-                  "Connecting to %s...  [Press Ctrl-C to abort]", 
-                  options->host);
-         screen_status_message(mpc, buf);
+         screen_status_printf("Connecting to %s...  [Press Ctrl-C to abort]", 
+                              options->host);
          if( mpc_reconnect(mpc, options->host, options->port) == 0 )
            {
-             snprintf(buf, BUFSIZE, "Connected to %s!", options->host);
-             screen_status_message(mpc, buf);
+             screen_status_printf("Connected to %s!", options->host);
              connected=1;
              counter=0;
            }
index 03fe3eea90eec3db7b33a7927dc1450724da0367..9685ce3b22cc5b4323daef204043ec1d352025b5 100644 (file)
--- a/options.c
+++ b/options.c
@@ -40,7 +40,7 @@ usage(poptContext optCon, int exitcode, char *error, char *addl)
 }
 
 options_t *
-options_parse( int argc, char **argv )
+options_parse( int argc, const char **argv)
 {
   int c;
   poptContext optCon;   /* context for parsing command-line options */
index 143be3b2df484b29bb4c33dcffa442ce6117cbe3..49af19984540c5169d62d4ead9d73fdb346563e5 100644 (file)
--- a/options.h
+++ b/options.h
@@ -13,6 +13,6 @@ typedef struct
 } options_t;
 
 void options_init(void);
-options_t *options_parse(int argc, char **argv);
+options_t *options_parse(int argc, const char **argv);
 options_t *get_options(void);
 
index 696c35f7f6811bebd0fe866244bc217b5a4f0326..3012fa31ae668494f3126b78bffd67c271f9a119 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -176,11 +176,6 @@ paint_status_window(mpd_client_t *c)
     {
       x = screen->status_window.cols - strlen(screen->buf);
 
-      if( c->status->repeat )
-       mvwaddstr(w, 0, x-3, "<R>");
-      else
-       mvwaddstr(w, 0, x-3, "   ");
-
       snprintf(screen->buf, screen->buf_size, 
               " [%i:%02i/%i:%02i] ",
               status->elapsedTime/60, status->elapsedTime%60,
@@ -188,6 +183,18 @@ paint_status_window(mpd_client_t *c)
       mvwaddstr(w, 0, x, screen->buf);
        
     }
+#if 1
+  else if( c->status->state == MPD_STATUS_STATE_STOP )
+    {
+      time_t timep;
+      x = screen->status_window.cols - strlen(screen->buf);
+      
+      time(&timep);
+      //strftime(screen->buf, screen->buf_size, "%X ",  localtime(&timep));
+      strftime(screen->buf, screen->buf_size, "%R ",  localtime(&timep));
+      mvwaddstr(w, 0, x, screen->buf);
+    }
+#endif
   
 
   wrefresh(w);
@@ -225,7 +232,7 @@ screen_resized(int sig)
 }
 
 void 
-screen_status_message(mpd_client_t *c, char *msg)
+screen_status_message(char *msg)
 {
   WINDOW *w = screen->status_window.w;
 
@@ -239,7 +246,7 @@ screen_status_message(mpd_client_t *c, char *msg)
 }
 
 void 
-screen_status_printf(mpd_client_t *c, char *format, ...)
+screen_status_printf(char *format, ...)
 {
   char buffer[STATUS_LINE_MAX_SIZE];
   va_list ap;
@@ -247,7 +254,7 @@ screen_status_printf(mpd_client_t *c, char *format, ...)
   va_start(ap,format);
   vsnprintf(buffer,sizeof(buffer),format,ap);
   va_end(ap);
-  screen_status_message(c, buffer);
+  screen_status_message(buffer);
 }
 
 int
@@ -398,7 +405,7 @@ void
 screen_cmd(mpd_client_t *c, command_t cmd)
 {
   int n;
-  char buf[256];
+  //  char buf[256];
   screen_mode_t new_mode = screen->mode;
 
   switch(screen->mode)
@@ -452,46 +459,42 @@ screen_cmd(mpd_client_t *c, command_t cmd)
     case CMD_SHUFFLE:
       mpd_sendShuffleCommand(c->connection);
       mpd_finishCommand(c->connection);
-      screen_status_message(c, "Shuffled playlist!");
+      screen_status_message("Shuffled playlist!");
       break;
     case CMD_CLEAR:
       mpd_sendClearCommand(c->connection);
       mpd_finishCommand(c->connection);
       file_clear_highlights(c);
-      screen_status_message(c, "Cleared playlist!");
+      screen_status_message("Cleared playlist!");
       break;
     case CMD_REPEAT:
       n = !c->status->repeat;
       mpd_sendRepeatCommand(c->connection, n);
       mpd_finishCommand(c->connection);
-      snprintf(buf, 256, "Repeat is %s", n ? "On" : "Off");
-      screen_status_message(c, buf);
+      screen_status_printf("Repeat is %s", n ? "On" : "Off");
       break;
     case CMD_RANDOM:
       n = !c->status->random;
       mpd_sendRandomCommand(c->connection, n);
       mpd_finishCommand(c->connection);
-      snprintf(buf, 256, "Random is %s", n ? "On" : "Off");
-      screen_status_message(c, buf);
+      screen_status_printf("Random is %s", n ? "On" : "Off");
       break;
     case CMD_VOLUME_UP:
-      //  mpd_sendSetvolCommand(c->connection, X );
-      mpd_sendVolumeCommand(c->connection, 1);
-      mpd_finishCommand(c->connection);
-      if( c->status->volume!=MPD_STATUS_NO_VOLUME )
+      if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
        {
-         snprintf(buf, 256, "Volume %d%%", c->status->volume+1); 
-         screen_status_message(c, buf);
+         c->status->volume=c->status->volume+1;
+         mpd_sendSetvolCommand(c->connection, c->status->volume  );
+         mpd_finishCommand(c->connection);
+         screen_status_printf("Volume %d%%", c->status->volume);
        }
       break;
     case CMD_VOLUME_DOWN:
-      //  mpd_sendSetvolCommand(c->connection, X );
-      mpd_sendVolumeCommand(c->connection, -1);
-      mpd_finishCommand(c->connection);
-      if( c->status->volume!=MPD_STATUS_NO_VOLUME )
+      if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
        {
-         snprintf(buf, 256, "Volume %d%%", c->status->volume-1); 
-         screen_status_message(c, buf);
+         c->status->volume=c->status->volume-1;
+         mpd_sendSetvolCommand(c->connection, c->status->volume  );
+         mpd_finishCommand(c->connection);
+         screen_status_printf("Volume %d%%", c->status->volume);
        }
       break;
     case CMD_SCREEN_PREVIOUS:
index 4681319c391d646c39e14aff07b4a832fd0337d5..70d3e121836b500eb8362e4ea40c91798acbb58e 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -64,8 +64,8 @@ typedef struct
 int screen_init(void);
 int screen_exit(void);
 void screen_resized(int sig);
-void screen_status_message(mpd_client_t *c, char *msg);
-void screen_status_printf(mpd_client_t *c, char *format, ...);
+void screen_status_message(char *msg);
+void screen_status_printf(char *format, ...);
 char *screen_error(void);
 void screen_paint(mpd_client_t *c);
 void screen_update(mpd_client_t *c);
index c09682cc629e90122dd8cac18aff35d6183c3159..d503628cbe62dc0fae02413eaef17270e1fc29b3 100644 (file)
@@ -101,10 +101,12 @@ add_directory(mpd_client_t *c, char *dir)
   mpd_InfoEntity *entity;
   GList *subdir_list = NULL;
   GList *list = NULL;
-  char buf[80];
+  char *dirname;
 
-  snprintf(buf, 80, "Adding directory %s...\n", dir);
-  screen_status_message(c, buf);
+  dirname = utf8_to_locale(dir);
+  screen_status_printf("Adding directory %s...\n", dirname);
+  free(dirname);
+  dirname = NULL;
 
   mpd_sendLsInfoCommand(c->connection, dir);
   mpd_sendCommandListBegin(c->connection);
@@ -168,16 +170,13 @@ select_entry(screen_t *screen, mpd_client_t *c)
     {
       if( entry->entity->type==MPD_INFO_ENTITY_TYPE_SONG )
        {
-         char buf[80];
          mpd_Song *song = entry->entity->info.song;
 
          mpd_sendAddCommand(c->connection, song->file);
          mpd_finishCommand(c->connection);
 
-         snprintf(buf, 80, 
-                  "Adding \'%s\' to playlist\n", 
-                  mpc_get_song_name(song));
-         screen_status_message(c, buf);
+         screen_status_printf("Adding \'%s\' to playlist\n", 
+                              mpc_get_song_name(song));
        }
     }
   else
@@ -185,7 +184,6 @@ select_entry(screen_t *screen, mpd_client_t *c)
       if( entry->entity->type==MPD_INFO_ENTITY_TYPE_SONG )
        {
          int i;
-         char buf[80];
          mpd_Song *song = entry->entity->info.song;
          
          i = mpc_playlist_get_song_index(c, song->file);
@@ -193,10 +191,9 @@ select_entry(screen_t *screen, mpd_client_t *c)
            {
              mpd_sendDeleteCommand(c->connection, i);
              mpd_finishCommand(c->connection);
-             snprintf(buf, 80, 
-                      "Removed \'%s\' from playlist\n", 
-                      mpc_get_song_name(song));
-             screen_status_message(c, buf);
+             screen_status_printf("Removed \'%s\' from playlist\n", 
+                                  mpc_get_song_name(song));
+
            }
        }
     }
@@ -352,7 +349,7 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
        }
       else
        {
-         screen_status_printf(c, "Unable to find \'%s\'", screen->findbuf);
+         screen_status_printf("Unable to find \'%s\'", screen->findbuf);
          beep();
        }
       break;
index 5ba3839c8c3862e5178816dd0ca58270a229e1c4..9d1e9e80a42a4f2e9942cf41a3f5a303fb0360a3 100644 (file)
@@ -93,8 +93,7 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
       file_clear_highlight(c, song);
       mpd_sendDeleteCommand(c->connection, screen->playlist->selected);
       mpd_finishCommand(c->connection);
-      screen_status_printf(c, 
-                          "Removed \'%s\' from playlist!",
+      screen_status_printf("Removed \'%s\' from playlist!",
                           mpc_get_song_name(song));
       break;
     case CMD_LIST_PREVIOUS:
@@ -139,7 +138,7 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
        }
       else
        {
-         screen_status_printf(c, "Unable to find \'%s\'", screen->findbuf);
+         screen_status_printf("Unable to find \'%s\'", screen->findbuf);
          beep();
        }
       break;
index d467c1a2c5a47d4ca62b8f2264454e8faf9e3f3e..8de23e16c6492d148d6d32b8b6dd7a9e51ec69a7 100644 (file)
@@ -1,8 +1,3 @@
-/* 
- * $Id: screen_utils.c,v 1.4 2004/03/16 13:57:24 kalle Exp $ 
- *
- */
-
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 
 #include "libmpdclient.h"
 #include "mpc.h"
+#include "support.h"
 #include "command.h"
 #include "screen.h"
 
-#if 0
-#include <readline/readline.h>
-#endif
-
-
 list_window_t *
 list_window_init(WINDOW *w, int width, int height)
 {