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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
diff --git a/apps/filetree.c b/apps/filetree.c
index d4681ae..87ac37c 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -552,22 +552,35 @@ 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_GOTO_WPS:
+                        play = true;
+                        break;
+                    case PLUGIN_USB_CONNECTED:
+                        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;
+                    /*
+                    case PLUGIN_ERROR:
+                    case PLUGIN_OK:
+                    */
+                    default:
+                        break;
                 }
                 break;
-
+            }
             case FILE_ATTR_CUE:
                 display_cuesheet_content(buf);
                 break;
@@ -584,8 +597,21 @@ int ft_enter(struct tree_context* c)
                 plugin = filetype_get_plugin(file);
                 if (plugin)
                 {
-                    if (plugin_load(plugin,buf) == PLUGIN_USB_CONNECTED)
-                        reload_dir = true;
+                    switch (plugin_load(plugin,buf))
+                    {
+                        case PLUGIN_USB_CONNECTED:
+                            reload_dir = true;
+                            break;
+                        case PLUGIN_GOTO_WPS:
+                            play = true;
+                            break;
+                        /*
+                        case PLUGIN_OK:
+                        case PLUGIN_ERROR:
+                        */
+                        default:
+                            break;
+                    }
                 }
                 break;
             }
diff --git a/apps/plugin.c b/apps/plugin.c
index ff80776..6792c25 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -664,6 +664,7 @@ static const struct plugin_api rockbox_api = {
 int plugin_load(const char* plugin, const void* parameter)
 {
     int rc;
+    int i;
     int oldbars;
     struct plugin_header *hdr;
 #ifdef SIMULATOR
@@ -804,8 +805,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,32 +813,27 @@ int plugin_load(const char* plugin, const void* parameter)
 #else
     lcd_remote_set_drawmode(DRMODE_SOLID);
 #endif
-    lcd_remote_clear_display();
-
-
-    lcd_remote_update();
+#endif

+    if (rc != PLUGIN_GOTO_WPS)
+    {
+        FOR_NB_SCREENS(i)
+        {
+            screens[i].clear_display();
+            screens[i].update();
+        }
+    }

-#endif
     viewportmanager_set_statusbar(oldbars);
     if (pfn_tsr_exit == NULL)
         plugin_loaded = false;

     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..d0c1fa2 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -139,6 +139,7 @@ void* plugin_get_buffer(size_t *buffer_size);
 enum plugin_status {
     PLUGIN_OK = 0,
     PLUGIN_USB_CONNECTED,
+    PLUGIN_GOTO_WPS,
     PLUGIN_ERROR = -1,
 };

diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index b3cc7e4..496e9c9 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) || CONFIG_KEYPAD == IRIVER_H10_PAD || \
@@ -2013,6 +2015,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 */

@@ -2141,6 +2147,7 @@ int settings_menu(void)
   Show the main menu
  */
 enum {
+    PF_GOTO_WPS,
 #if PF_PLAYBACK_CAPABLE
     PF_MENU_PLAYBACK_CONTROL,
 #endif
@@ -2159,12 +2166,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);
@@ -2174,10 +2184,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;

@@ -2405,6 +2413,7 @@ play:
     old_shuffle = shuffle;
 }
 #endif
+
 /**
    Draw the current album name
  */
@@ -2661,7 +2670,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 )
             {
@@ -2673,12 +2683,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
@@ -2713,7 +2723,6 @@ int main(void)
 #endif
             }
             break;
-
         default:
             if (rb->default_event_handler_ex(button, cleanup, NULL)
                 == SYS_USB_CONNECTED)
@@ -2752,9 +2761,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))
@@ -2764,7 +2770,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..2d3959a 100644
--- a/apps/plugins/random_folder_advance_config.c
+++ b/apps/plugins/random_folder_advance_config.c
@@ -535,10 +535,8 @@ int start_shuffled_play(void)
     return 1;
 }

-int main_menu(void)
+enum plugin_status main_menu(void)
 {
-    bool exit = false;
-
     MENUITEM_STRINGLIST(menu, "Main Menu", NULL,
                         "Generate Folder List",
                         "Edit Folder List",
@@ -547,69 +545,72 @@ int main_menu(void)
                         "Play Shuffled",
                         "Quit");

-    switch (rb->do_menu(&menu, NULL, NULL, false))
+    while (true)
     {
-        case 0: /* generate */
+        switch (rb->do_menu(&menu, NULL, NULL, false))
+        {
+            case 0: /* generate */
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(true);
+                rb->cpu_boost(true);
 #endif
-            generate();
+                generate();
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(false);
+                rb->cpu_boost(false);
 #endif
 #ifdef HAVE_REMOTE_LCD
-            rb->remote_backlight_on();
+                rb->remote_backlight_on();
 #endif
-            rb->backlight_on();
-            break;
-        case 1:
+                rb->backlight_on();
+                break;
+            case 1:
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(true);
+                rb->cpu_boost(true);
 #endif
-            if (edit_list() < 0)
-                exit = true;
+                if (edit_list() < 0)
+                    return PLUGIN_OK;
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(false);
+                rb->cpu_boost(false);
 #endif
 #ifdef HAVE_REMOTE_LCD
-            rb->remote_backlight_on();
+                rb->remote_backlight_on();
 #endif
-            rb->backlight_on();
-            break;
-        case 2: /* export to textfile */
+                rb->backlight_on();
+                break;
+            case 2: /* export to textfile */
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(true);
+                rb->cpu_boost(true);
 #endif
-            export_list_to_file_text();
+                export_list_to_file_text();
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(false);
+                rb->cpu_boost(false);
 #endif
 #ifdef HAVE_REMOTE_LCD
-            rb->remote_backlight_on();
+                rb->remote_backlight_on();
 #endif
-            rb->backlight_on();
-            break;
-        case 3: /* import from textfile */
+                rb->backlight_on();
+                break;
+            case 3: /* import from textfile */
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(true);
+                rb->cpu_boost(true);
 #endif
-            import_list_from_file_text();
+                import_list_from_file_text();
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
-            rb->cpu_boost(false);
+                rb->cpu_boost(false);
 #endif
 #ifdef HAVE_REMOTE_LCD
-            rb->remote_backlight_on();
+                rb->remote_backlight_on();
 #endif
-            rb->backlight_on();
-            break;
-        case 4:
-            start_shuffled_play();
-            exit=true;
-            break;
-        case 5:
-            return 1;
+                rb->backlight_on();
+                break;
+            case 4:
+                if (!start_shuffled_play())
+                    return PLUGIN_ERROR;
+                else
+                    return PLUGIN_GOTO_WPS;
+            case 5:
+                return PLUGIN_OK;
+        }
     }
-    return exit?1:0;
 }

 enum plugin_status plugin_start(const void* parameter)
@@ -618,7 +619,5 @@ enum plugin_status plugin_start(const void* parameter)

     abort = false;

-    while (!main_menu())
-        ;
-    return PLUGIN_OK;
+    return main_menu();
 }