Code

added type argument to gcmp_list_from_path()
authorKalle Wallin <kaw@linux.se>
Sat, 19 Jun 2004 19:33:46 +0000 (19:33 +0000)
committerKalle Wallin <kaw@linux.se>
Sat, 19 Jun 2004 19:33:46 +0000 (19:33 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1567 09075e82-0dd4-0310-85a5-a0d7c8717e4f

ChangeLog
src/screen_play.c
src/utils.c
src/utils.h

index 75d9fd09ee5d4982f560dac34a4c6b3c75a788da..6bacbc91d24ba9ced2e0ec50992385b5c8f02413 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2004-06-17 Kalle Wallin <kaw@linux.se>
+       * screen_utils.c: fixed the display of completion lists
+       * wreadln.c: try to complete even if the line is empty
+       * utils.c: added type argument to gcmp_list_from_path()
+       * screen_play.c: added completion support to handle_save_playlist()
+       * command.[c|h]: check_key_bindings() can now write an error messages 
+                        to a buffer instead of stderr
+       * main.c: display errors without exiting when key bindings are broken
+
+2004-06-17 Kalle Wallin <kaw@linux.se>
+       * Added a add command, used to add urls or files to the playlist, with
+         file completion.
+
+
+2004-06-16 Kalle Wallin <kaw@linux.se>
+       * mpdclient.c: enabled plchanges, make shure the playlist length is 
+         updated when removing songs
+
 2004-06-16 Kalle Wallin <kaw@linux.se>
        * libmpdclient updated (r1507)
        * mpdclient: add path to mpdclient_cmd_db_update() 
@@ -8,7 +26,7 @@
        * conf.c: Added support for cusomized format strings with 
                  list-format and status-format
        * options.c: Added status_format, list_format fields
-       * mpdclient.c: Sort playlist if needed after plchanges, 
+       * mpdclient.c: disable plchanges (needs more work),
          update the song position fields in mpdclient_cmd_move, 
          use song id's by default (define ENABLE_SONG_ID), disable plchanges
        * screen_play.c: Offer to overwrite when saving playlists
index 3bb16ee638d49fa20e3a7102960468c25d981dce..fc130b9861cc61845dd33cd8e4b5e04eac170f82 100644 (file)
@@ -117,12 +117,46 @@ handle_save_playlist(screen_t *screen, mpdclient_t *c, char *name)
 {
   gchar *filename;
   gint error;
+  GCompletion *gcmp;
+  GList *list = NULL;
+
+  void pre_completion_cb(GCompletion *gcmp, gchar *line)
+    {
+      if( list == NULL )
+       {
+         /* create completion list */
+         list = gcmp_list_from_path(c, "", NULL, GCMP_TYPE_PLAYLIST);
+         g_completion_add_items(gcmp, list);
+       }
+    }
+
+  void post_completion_cb(GCompletion *gcmp, gchar *line, GList *items)
+    {
+      if( g_list_length(items)>=1 )
+       screen_display_completion_list(screen, items);
+    }
 
   if( name==NULL )
     {
+      /* initialize completion support */
+      gcmp = g_completion_new(NULL);
+      g_completion_set_compare(gcmp, strncmp);
+      wrln_pre_completion_callback = pre_completion_cb;
+      wrln_post_completion_callback = post_completion_cb;
+
       /* query the user for a filename */
-      filename=screen_getstr(screen->status_window.w, _("Save playlist as: "));
+      filename = screen_readln(screen->status_window.w,
+                              _("Save playlist as: "),
+                              NULL,
+                              NULL,
+                              gcmp);                                  
       filename=trim(filename);
+
+      /* destroy completion support */
+      wrln_pre_completion_callback = NULL;
+      wrln_post_completion_callback = NULL;
+      g_completion_free(gcmp);
+      list = string_list_free(list);
     }
   else
     {
@@ -181,17 +215,18 @@ handle_add_to_playlist(screen_t *screen, mpdclient_t *c)
     {
       g_completion_remove_items(gcmp, list);
       list = string_list_remove(list, dir);
-      list = gcmp_list_from_path(c, dir, list);
+      list = gcmp_list_from_path(c, dir, list, GCMP_TYPE_RFILE);
       g_completion_add_items(gcmp, list);
       dir_list = g_list_append(dir_list, g_strdup(dir));
     }
 
   void pre_completion_cb(GCompletion *gcmp, gchar *line)       
     {
+      D("pre_completion()...\n");
       if( list == NULL )
        {
          /* create initial list */
-         list = gcmp_list_from_path(c, "", NULL);
+         list = gcmp_list_from_path(c, "", NULL, GCMP_TYPE_RFILE);
          g_completion_add_items(gcmp, list);
        }
       else if( line && line[0] && line[strlen(line)-1]=='/' &&
@@ -204,6 +239,7 @@ handle_add_to_playlist(screen_t *screen, mpdclient_t *c)
 
   void post_completion_cb(GCompletion *gcmp, gchar *line, GList *items)
     {
+      D("post_completion()...\n");
       if( g_list_length(items)>1 )
        screen_display_completion_list(screen, items);
 
@@ -215,28 +251,32 @@ handle_add_to_playlist(screen_t *screen, mpdclient_t *c)
        }
     }
     
-
+  /* initialize completion support */
   gcmp = g_completion_new(NULL);
   g_completion_set_compare(gcmp, strncmp);
-
   wrln_pre_completion_callback = pre_completion_cb;
   wrln_post_completion_callback = post_completion_cb;
+  /* get path */
   path = screen_readln(screen->status_window.w, 
                       _("Add: "),
                       NULL, 
                       NULL, 
                       gcmp);
+
+  /* destroy completion data */
   wrln_pre_completion_callback = NULL;
   wrln_post_completion_callback = NULL;
-  
   g_completion_free(gcmp);
-
   string_list_free(list);
   string_list_free(dir_list);
 
+  /* add the path to the playlist */
   if( path && path[0] )
     mpdclient_cmd_add_path(c, path);
 
+  lw->clear = 1;
+  lw->repaint = 1;
+
   return 0;
 }
 
index 49841a350c1baffd57aee9d208492f0860d1eb3f..58340c42ece27d90c977dc9f9a8172e722e46d2b 100644 (file)
@@ -81,7 +81,7 @@ string_list_remove(GList *string_list, gchar *str)
 
 /* create a list suiteble for GCompletion from path */
 GList *
-gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list)
+gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list, gint types)
 {
   GList *flist = NULL;
   mpdclient_filelist_t *filelist;
@@ -96,7 +96,8 @@ gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list)
       mpd_InfoEntity *entity = entry ? entry->entity : NULL;
       char *name = NULL;
       
-      if( entity && entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY ) 
+      if( entity && entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY && 
+         types & GCMP_TYPE_DIR) 
        {
          mpd_Directory *dir = entity->info.directory;
          gchar *tmp = utf8_to_locale(dir->path);
@@ -106,11 +107,19 @@ gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list)
          strcat(name, "/");
          g_free(tmp);
        }
-      else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG )
+      else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG &&
+              types & GCMP_TYPE_FILE )
        {
          mpd_Song *song = entity->info.song;
          name = utf8_to_locale(song->file);
        }
+      else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE &&
+              types & GCMP_TYPE_PLAYLIST )
+       {
+         mpd_PlaylistFile *plf = entity->info.playlistFile;
+         name = utf8_to_locale(plf->path);
+       }
+
       if( name )
        list = g_list_append(list, name);
 
index 998a0decead8893abd24834b8a1f4be640d6495d..4446d1cd705fa28c69dbc292c899af4b071a03c1 100644 (file)
@@ -1,12 +1,22 @@
 #ifndef UTILS_H
 #define UTILS_H
 
+
 /* functions for lists containing strings */
 GList *string_list_free(GList *string_list);
 GList *string_list_find(GList *string_list, gchar *str);
 GList *string_list_remove(GList *string_list, gchar *str);
 
 /* create a string list from path - used for completion */
-GList *gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list);
+#define GCMP_TYPE_DIR       (0x01 << 0)
+#define GCMP_TYPE_FILE      (0x01 << 1)
+#define GCMP_TYPE_PLAYLIST  (0x01 << 2)
+#define GCMP_TYPE_RFILE     (GCMP_TYPE_DIR | GCMP_TYPE_FILE)
+#define GCMP_TYPE_RPLAYLIST (GCMP_TYPE_DIR | GCMP_TYPE_PLAYLIST)
+
+GList *gcmp_list_from_path(mpdclient_t *c, 
+                          gchar *path, 
+                          GList *list,
+                          gint types);
 
 #endif