1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
diff --git a/apps/filetree.c b/apps/filetree.c
index d4681ae..6a6a568 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -552,22 +552,31 @@ int ft_enter(struct tree_context* c)

                 /* plugin file */
             case FILE_ATTR_ROCK:
+            {
+                int ret;
                 if (global_settings.party_mode && audio_status()) {
                     splash(HZ, ID2P(LANG_PARTY_MODE));
                     break;
                 }
-
-                if (plugin_load(buf,NULL) == PLUGIN_USB_CONNECTED)
+                ret = plugin_load(buf,NULL);
+                switch (ret)
                 {
-                    if(*c->dirfilter > NUM_FILTER_MODES)
-                        /* leave sub-browsers after usb, doing
-                           otherwise might be confusing to the user */
-                        exit_func = true;
-                    else
-                        reload_dir = true;
+                    case PLUGIN_USB_CONNECTED:
+                        break;
+                    case PLUGIN_GOTO_WPS:
+                        play = true;
+                        break;
+                    default:
+                        if(*c->dirfilter > NUM_FILTER_MODES)
+                            /* leave sub-browsers after usb, doing
+                               otherwise might be confusing to the user */
+                            exit_func = true;
+                        else
+                            reload_dir = true;
+                        break;
                 }
                 break;
-
+            }
             case FILE_ATTR_CUE:
                 display_cuesheet_content(buf);
                 break;
@@ -584,8 +593,11 @@ int ft_enter(struct tree_context* c)
                 plugin = filetype_get_plugin(file);
                 if (plugin)
                 {
-                    if (plugin_load(plugin,buf) == PLUGIN_USB_CONNECTED)
+                    int ret = plugin_load(plugin,buf);
+                    if (ret == PLUGIN_USB_CONNECTED)
                         reload_dir = true;
+                    else if (ret == PLUGIN_GOTO_WPS)
+                        play = true;
                 }
                 break;
             }
diff --git a/apps/plugin.c b/apps/plugin.c
index ff80776..1a444f5 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -804,8 +804,6 @@ int plugin_load(const char* plugin, const void* parameter)
 #endif /* LCD_DEPTH */
 #endif /* HAVE_LCD_BITMAP */

-    lcd_clear_display();
-    lcd_update();

 #ifdef HAVE_REMOTE_LCD
 #if LCD_REMOTE_DEPTH > 1
@@ -814,10 +812,14 @@ int plugin_load(const char* plugin, const void* parameter)
 #else
     lcd_remote_set_drawmode(DRMODE_SOLID);
 #endif
-    lcd_remote_clear_display();

-
-    lcd_remote_update();
+    if (rc != PLUGIN_GOTO_WPS)
+    {
+        lcd_clear_display();
+        lcd_update();
+        lcd_remote_clear_display();
+        lcd_remote_update();
+    }


 #endif
@@ -827,19 +829,10 @@ int plugin_load(const char* plugin, const void* parameter)

     sim_plugin_close(pd);

-    switch (rc) {
-        case PLUGIN_OK:
-            break;
-
-        case PLUGIN_USB_CONNECTED:
-            return PLUGIN_USB_CONNECTED;
-
-        default:
-            splash(HZ*2, str(LANG_PLUGIN_ERROR));
-            break;
-    }
+    if (rc == PLUGIN_ERROR)
+        splash(HZ*2, str(LANG_PLUGIN_ERROR));

-    return PLUGIN_OK;
+    return rc;
 }

 /* Returns a pointer to the portion of the plugin buffer that is not already
diff --git a/apps/plugin.h b/apps/plugin.h
index db16800..de0791b 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -139,6 +139,8 @@ void* plugin_get_buffer(size_t *buffer_size);
 enum plugin_status {
     PLUGIN_OK = 0,
     PLUGIN_USB_CONNECTED,
+    PLUGIN_GOTO_WPS,
+    PLUGIN_MAX_RETURNS,
     PLUGIN_ERROR = -1,
 };

diff --git a/apps/plugins/lib/pluginlib_exit.h b/apps/plugins/lib/pluginlib_exit.h
index 1bad12a..0e8cb12 100644
--- a/apps/plugins/lib/pluginlib_exit.h
+++ b/apps/plugins/lib/pluginlib_exit.h
@@ -30,18 +30,21 @@
 #endif

 /* PLUGINLIB_EXIT_INIT needs to be placed as the first line in plugin_start */
-#define PLUGINLIB_EXIT_INIT switch(setjmp(__exit_env))   \
-                            {                            \
-                                case 1:                  \
-                                    return PLUGIN_OK;    \
-                                case 2:                  \
-                                    return PLUGIN_ERROR; \
-                                case 0:                  \
-                                default:                 \
-                                    break;               \
+#define PLUGINLIB_EXIT_INIT switch(setjmp(__exit_env))      \
+                            {                               \
+                                case -1:                    \
+                                    return PLUGIN_ERROR;    \
+                                case PLUGIN_OK+1:           \
+                                    return PLUGIN_OK;       \
+                                case PLUGIN_GOTO_WPS+1:     \
+                                    return PLUGIN_GOTO_WPS; \
+                                case PLUGIN_USB_CONNECTED+1:    \
+                                    return PLUGIN_USB_CONNECTED;\
+                                default:                    \
+                                    break;                  \
                             }

 extern jmp_buf __exit_env;
-#define exit(status) longjmp(__exit_env, status != 0 ? 2 : 1)
+#define exit(status) longjmp(__exit_env, (status < 0 || status >= PLUGIN_MAX_RETURNS) ? -1:status+1)

 #endif /*  __PLUGINLIB_EXIT_H__ */
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index 11822ba..c0d3325 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -54,6 +54,8 @@ PLUGIN_HEADER
 #define PF_CONTEXT ACTION_STD_CONTEXT
 #define PF_BACK ACTION_STD_CANCEL
 #define PF_MENU ACTION_STD_MENU
+#define PF_WPS ACTION_TREE_WPS
+
 #define PF_QUIT (LAST_ACTION_PLACEHOLDER + 1)

 #if !defined(HAVE_SCROLLWHEEL)
@@ -122,8 +124,6 @@ const struct button_mapping pf_context_buttons[] =
     {PF_BACK,         BUTTON_POWER|BUTTON_REL,    BUTTON_POWER},
     {ACTION_NONE,     BUTTON_POWER,               BUTTON_NONE},
 #endif
-#elif CONFIG_KEYPAD == SANSA_E200_PAD
-    {PF_QUIT,         BUTTON_POWER,               BUTTON_NONE},
 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
     {PF_QUIT,         BUTTON_EQ,                  BUTTON_NONE},
 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
@@ -2008,6 +2008,10 @@ void update_scroll_animation(void)
 void cleanup(void *parameter)
 {
     (void) parameter;
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+    rb->cpu_boost(false);
+#endif
+    end_pf_thread();
     /* Turn on backlight timeout (revert to settings) */
     backlight_use_settings(); /* backlight control in lib/helper.c */

@@ -2136,6 +2140,7 @@ int settings_menu(void)
   Show the main menu
  */
 enum {
+    PF_GOTO_WPS,
 #if PF_PLAYBACK_CAPABLE
     PF_MENU_PLAYBACK_CONTROL,
 #endif
@@ -2154,12 +2159,15 @@ int main_menu(void)
 #endif

     MENUITEM_STRINGLIST(main_menu,"PictureFlow Main Menu",NULL,
+                        "Go to WPS",
 #if PF_PLAYBACK_CAPABLE
                         "Playback Control",
 #endif
                                             "Settings", "Return", "Quit");
     while (1)  {
         switch (rb->do_menu(&main_menu,&selection, NULL, false)) {
+            case PF_GOTO_WPS: /* WPS */
+                return -2;
 #if PF_PLAYBACK_CAPABLE
             case PF_MENU_PLAYBACK_CONTROL: /* Playback Control */
                 playback_control(NULL);
@@ -2169,10 +2177,8 @@ int main_menu(void)
                 result = settings_menu();
                 if ( result != 0 ) return result;
                 break;
-
             case PF_MENU_RETURN:
                 return 0;
-
             case PF_MENU_QUIT:
                 return -1;

@@ -2400,6 +2406,7 @@ play:
     old_shuffle = shuffle;
 }
 #endif
+
 /**
    Draw the current album name
  */
@@ -2656,7 +2663,8 @@ int main(void)
         switch (button) {
         case PF_QUIT:
             return PLUGIN_OK;
-
+        case PF_WPS:
+            return PLUGIN_GOTO_WPS;
         case PF_BACK:
             if ( pf_state == pf_show_tracks )
             {
@@ -2668,12 +2676,12 @@ int main(void)
             if (pf_state == pf_idle || pf_state == pf_scrolling)
                 return PLUGIN_OK;
             break;
-
         case PF_MENU:
 #ifdef USEGSLIB
             grey_show(false);
 #endif
             ret = main_menu();
+            if ( ret == -2 ) return PLUGIN_GOTO_WPS;
             if ( ret == -1 ) return PLUGIN_OK;
             if ( ret != 0 ) return ret;
 #ifdef USEGSLIB
@@ -2708,7 +2716,6 @@ int main(void)
 #endif
             }
             break;
-
         default:
             if (rb->default_event_handler_ex(button, cleanup, NULL)
                 == SYS_USB_CONNECTED)
@@ -2747,9 +2754,6 @@ enum plugin_status plugin_start(const void *parameter)
 #endif
 #endif
     ret = main();
-#ifdef HAVE_ADJUSTABLE_CPU_FREQ
-    rb->cpu_boost(false);
-#endif
     if ( ret == PLUGIN_OK ) {
         if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS,
                             CONFIG_VERSION))
@@ -2759,7 +2763,6 @@ enum plugin_status plugin_start(const void *parameter)
         }
     }

-    end_pf_thread();
     cleanup(NULL);
     return ret;
 }
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c
index 3c74b79..d31f1f6 100644
--- a/apps/plugins/random_folder_advance_config.c
+++ b/apps/plugins/random_folder_advance_config.c
@@ -20,6 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"
 #include "file.h"
+#include "lib/pluginlib_exit.h"

 PLUGIN_HEADER

@@ -287,7 +288,7 @@ int save_list(void)
 int edit_list(void)
 {
     struct gui_synclist lists;
-    bool exit = false;
+    bool quit = false;
     int button,i;
     int selection, ret = 0;

@@ -306,7 +307,7 @@ int edit_list(void)
     rb->gui_synclist_limit_scroll(&lists,true);
     rb->gui_synclist_select_item(&lists, 0);

-    while (!exit)
+    while (!quit)
     {
         rb->gui_synclist_draw(&lists);
         button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
@@ -359,7 +360,7 @@ int edit_list(void)
                     case 0:
                         save_list();
                     case 1:
-                        exit = true;
+                        quit = true;
                         ret = -2;
                 }
             }
@@ -537,7 +538,7 @@ int start_shuffled_play(void)

 int main_menu(void)
 {
-    bool exit = false;
+    bool quit = false;

     MENUITEM_STRINGLIST(menu, "Main Menu", NULL,
                         "Generate Folder List",
@@ -567,7 +568,7 @@ int main_menu(void)
             rb->cpu_boost(true);
 #endif
             if (edit_list() < 0)
-                exit = true;
+                quit = true;
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
             rb->cpu_boost(false);
 #endif
@@ -603,21 +604,26 @@ int main_menu(void)
             rb->backlight_on();
             break;
         case 4:
-            start_shuffled_play();
-            exit=true;
+        {
+            int ret = start_shuffled_play();
+            if (!ret)
+                exit(PLUGIN_ERROR);
+            else
+                exit(PLUGIN_GOTO_WPS);
             break;
+        }
         case 5:
             return 1;
     }
-    return exit?1:0;
+    return quit?1:0;
 }

 enum plugin_status plugin_start(const void* parameter)
 {
+    PLUGINLIB_EXIT_INIT;
     (void)parameter;

     abort = false;
-    
     while (!main_menu())
         ;
     return PLUGIN_OK;