Code

conf: Added new "jump-prefix-only" option.
authorPatrick Hallen <patrick.hallen@rwth-aachen.de>
Sat, 28 Mar 2009 18:03:51 +0000 (19:03 +0100)
committerPatrick Hallen <patrick.hallen@rwth-aachen.de>
Sat, 28 Mar 2009 18:03:51 +0000 (19:03 +0100)
Commit b36fbc3ed8b9ceed41 broke the usecase of jumping
directly to the first entry which begins with a certain letter.
This patch adds a new option, which enables the old behaviour,
which searches for the beginning of a string and not for the first
occurence.

src/conf.c
src/list_window.c
src/match.c
src/match.h
src/options.c
src/options.h

index 478d468c4823f3d82692ccffdba60e9c12e15595..09fa45fe19d57b638ea3031cbba874471038b196 100644 (file)
@@ -74,6 +74,7 @@
 #define CONF_VISIBLE_BITRATE "visible-bitrate"
 #define CONF_WELCOME_SCREEN_LIST "welcome-screen-list"
 #define CONF_DISPLAY_TIME "display-time"
+#define CONF_JUMP_PREFIX_ONLY "jump-prefix-only"
 
 static bool
 str2bool(char *str)
@@ -502,6 +503,12 @@ parse_line(char *line)
                {}
 #else
                options.display_time = str2bool(value);
+#endif
+       else if (!strcasecmp(CONF_JUMP_PREFIX_ONLY, name))
+#ifdef NCMPC_MINI
+               {}
+#else
+               options.jump_prefix_only = str2bool(value);
 #endif
        else
                match_found = false;
index 40f2e14250196106735632d483ce1c2633d87580..347c54b4d440fc0f3b704e3ba730d472c37e5b4e 100644 (file)
@@ -414,25 +414,23 @@ list_window_jump(struct list_window *lw,
        const char *label;
 
        while ((label = callback(i,&h,callback_data))) {
-               if (label && label[0] != '[')
+               if (label && label[0] == '[')
+                       label++;
+#ifndef NCMPC_MINI
+               if (str && label &&
+                               ((options.jump_prefix_only && g_ascii_strncasecmp(label, str, strlen(str)) == 0) ||
+                                (!options.jump_prefix_only && match_line(label, str))) )
+#else
+               if (str && label && g_ascii_strncasecmp(label, str, strlen(str)) == 0)
+#endif
                {
-                       if (str && label && find_occurence(label, str, strlen(str)) == 0) {
-                               lw->selected = i;
-                               if(!lw->range_selection || i > lw->selected_end)
-                                         lw->selected_end = i;
-                               if(!lw->range_selection || i < lw->selected_start)
-                                         lw->selected_start = i;
-                               return true;
-                       }
+                       lw->selected = i;
+                       if(!lw->range_selection || i > lw->selected_end)
+                               lw->selected_end = i;
+                       if(!lw->range_selection || i < lw->selected_start)
+                               lw->selected_start = i;
+                       return true;
                }
-               else if (str && label && find_occurence(label+1, str, strlen(str)) == 0) {
-                               lw->selected = i;
-                               if(!lw->range_selection || i > lw->selected_end)
-                                         lw->selected_end = i;
-                               if(!lw->range_selection || i < lw->selected_start)
-                                         lw->selected_start = i;
-                               return true;
-                       }
                i++;
        }
        return false;
index 313c76e686dde0c563c71b0ad762b6980027d2fc..bd5250373348943e376a96e551663ce9862dca41 100644 (file)
@@ -50,29 +50,3 @@ match_line(const char *line, const char *needle)
 
        return ret;
 }
-
-int
-find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len)
-{
-       const int str_orig_len = strlen (str_orig);
-       int i, j;
-
-       if (str_occur_len > str_orig_len)
-       return -1;
-
-       for (i = 0; i < str_orig_len; i++) {
-               if ((i + str_occur_len) > str_orig_len)
-                       return -1;
-
-               for (j = 0; j < str_occur_len; j++) {
-                       if (tolower (str_occur[j])  != tolower (str_orig[i+j]))
-                               break;
-
-                       if (j == str_occur_len - 1)
-                               return 0;
-               }
-       }
-
-       return -1;
-}
-
index 4362cce8a22769c5489156a20310f7ff35e362d3..fed7207ecb99ca9747cebe5474a4b4338ffa94b1 100644 (file)
@@ -33,13 +33,6 @@ match_line(const char *line, const char *needle)
 {
        return strstr(line, needle) != NULL;
 }
-
-static inline int
-find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len)
-{
-       return g_ascii_strncasecmp(str_orig, str_occur, str_occur_len);
-}
-
 #else
 
 /**
@@ -49,9 +42,6 @@ find_occurence(const char *str_orig, const char *str_occur, const int str_occur_
 bool
 match_line(const char *line, const char *needle);
 
-int
-find_occurence(const char *str_orig, const char *str_occur, const int str_occur_len);
-
 #endif
 
 #endif
index dd7ba532c68aa1346141dc4f44bf9a944180fdf8..44840548eb1c734521d5d1a1b3d8a0426b24d1a6 100644 (file)
@@ -64,6 +64,7 @@ options_t options = {
        .scroll = DEFAULT_SCROLL,
        .welcome_screen_list = true,
        .display_time = true,
+       .jump_prefix_only = true,
 #endif
 };
 
index dbd5a43ce93a1199be5765034b7eefa22f9c3150..bccd0b22b4fab2217cf1c37bb6c0bf35beaf80b7 100644 (file)
@@ -73,6 +73,7 @@ typedef struct {
        bool visible_bitrate;
        bool welcome_screen_list;
        bool display_time;
+       bool jump_prefix_only;
 #endif
 } options_t;