2005-08-20 19:56:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Jonas Haggqvist
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-08-20 19:56:01 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
2012-02-09 13:18:46 +00:00
|
|
|
#include "lib/pluginlib_actions.h"
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
|
2010-12-28 14:42:30 +00:00
|
|
|
static int files, dirs, audiofiles, m3ufiles, imagefiles, videofiles, largestdir;
|
2005-08-20 19:56:01 +00:00
|
|
|
static int lasttick;
|
2010-05-06 21:04:40 +00:00
|
|
|
static bool cancel;
|
2005-08-20 19:56:01 +00:00
|
|
|
|
2008-10-07 16:38:28 +00:00
|
|
|
|
2012-02-09 13:18:46 +00:00
|
|
|
/* we use PLA */
|
|
|
|
#define STATS_STOP PLA_EXIT
|
plugins: Improve usability of iPod keymaps
- Reduce need to press multiple buttons at
the same time to quit a plugin
- Have "Menu" be default way to quit plugins or
to access plugin menu
- Fall back to (Long) "Select" or Long "Menu"
in cases where Menu button isn't available
(e.g. in ImageViewer and many games)
out of scope:
boomshine, lua_scripts, Rockpaint,
Doom, Duke3D, Pacbox, Quake,
Sgt-Puzzles, Wolf3D, XWorld,
Minesweeper, Pixel Painter, Spacerocks
Change-Id: I6d4dc7174695fe4b8ee9cbaccb21bdbfe6af5c48
2022-12-18 20:13:15 +00:00
|
|
|
|
|
|
|
#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IPOD_3G_PAD) \
|
|
|
|
|| (CONFIG_KEYPAD == IPOD_4G_PAD)
|
|
|
|
#define STATS_STOP2 PLA_UP
|
|
|
|
#else
|
2012-02-09 13:18:46 +00:00
|
|
|
#define STATS_STOP2 PLA_CANCEL
|
plugins: Improve usability of iPod keymaps
- Reduce need to press multiple buttons at
the same time to quit a plugin
- Have "Menu" be default way to quit plugins or
to access plugin menu
- Fall back to (Long) "Select" or Long "Menu"
in cases where Menu button isn't available
(e.g. in ImageViewer and many games)
out of scope:
boomshine, lua_scripts, Rockpaint,
Doom, Duke3D, Pacbox, Quake,
Sgt-Puzzles, Wolf3D, XWorld,
Minesweeper, Pixel Painter, Spacerocks
Change-Id: I6d4dc7174695fe4b8ee9cbaccb21bdbfe6af5c48
2022-12-18 20:13:15 +00:00
|
|
|
#endif
|
|
|
|
|
2012-02-09 13:18:46 +00:00
|
|
|
/* this set the context to use with PLA */
|
|
|
|
static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
|
2006-04-02 20:47:42 +00:00
|
|
|
|
2010-12-28 14:42:30 +00:00
|
|
|
/* we don't have yet a filetype attribute for image files */
|
2011-09-17 17:20:27 +00:00
|
|
|
static const char *image_exts[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
|
2010-12-28 14:42:30 +00:00
|
|
|
|
|
|
|
/* neither for video ones */
|
2011-09-17 17:20:27 +00:00
|
|
|
static const char *video_exts[] = {"mpg","mpeg","mpv","m2v"};
|
2010-12-28 14:42:30 +00:00
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void prn(const char *str, int y)
|
2006-04-02 20:47:42 +00:00
|
|
|
{
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_puts(0,y,str);
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_remote_puts(0,y,str);
|
2006-04-02 20:47:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-08-20 19:56:01 +00:00
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void update_screen(void)
|
2005-08-20 19:56:01 +00:00
|
|
|
{
|
2007-07-31 12:57:22 +00:00
|
|
|
char buf[32];
|
2007-04-06 22:55:00 +00:00
|
|
|
|
2005-08-20 19:56:01 +00:00
|
|
|
rb->lcd_clear_display();
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_clear_display();
|
|
|
|
#endif
|
2007-04-06 22:55:00 +00:00
|
|
|
|
2010-12-28 14:42:30 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Total Files: %d", files);
|
2006-04-02 20:47:42 +00:00
|
|
|
prn(buf,0);
|
2010-12-28 14:42:30 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Audio: %d", audiofiles);
|
2007-04-06 22:55:00 +00:00
|
|
|
prn(buf,1);
|
2010-12-28 14:42:30 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Playlists: %d", m3ufiles);
|
2007-04-06 22:55:00 +00:00
|
|
|
prn(buf,2);
|
2010-12-28 14:42:30 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Images: %d", imagefiles);
|
2007-07-31 12:57:22 +00:00
|
|
|
prn(buf,3);
|
2010-12-28 14:42:30 +00:00
|
|
|
rb->snprintf(buf, sizeof(buf), "Videos: %d", videofiles);
|
|
|
|
prn(buf,4);
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Directories: %d", dirs);
|
|
|
|
prn(buf,5);
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d", largestdir);
|
|
|
|
prn(buf,6);
|
2007-04-06 22:55:00 +00:00
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_update();
|
|
|
|
#endif
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
|
|
|
|
2011-09-17 17:20:27 +00:00
|
|
|
static void traversedir(char* location, char* name)
|
2005-08-20 19:56:01 +00:00
|
|
|
{
|
|
|
|
int button;
|
|
|
|
struct dirent *entry;
|
|
|
|
DIR* dir;
|
|
|
|
char fullpath[MAX_PATH];
|
2007-07-31 12:57:22 +00:00
|
|
|
int files_in_dir = 0;
|
2005-08-20 19:56:01 +00:00
|
|
|
|
|
|
|
rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
|
|
|
|
dir = rb->opendir(fullpath);
|
|
|
|
if (dir) {
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
while (entry) {
|
2010-05-06 21:04:40 +00:00
|
|
|
if (cancel)
|
2005-08-20 19:56:01 +00:00
|
|
|
break;
|
|
|
|
/* Skip .. and . */
|
|
|
|
if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
|
|
|
|
{
|
2010-09-01 21:29:34 +00:00
|
|
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
|
|
|
if (info.attribute & ATTR_DIRECTORY) {
|
2005-08-20 19:56:01 +00:00
|
|
|
traversedir(fullpath, entry->d_name);
|
2006-04-02 20:47:42 +00:00
|
|
|
dirs++;
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
2006-04-02 20:47:42 +00:00
|
|
|
else {
|
2010-12-28 14:42:30 +00:00
|
|
|
files_in_dir++; files++;
|
|
|
|
|
|
|
|
/* get the filetype from the filename */
|
2010-12-28 14:34:38 +00:00
|
|
|
int attr = rb->filetype_get_attr(entry->d_name);
|
2010-12-28 14:42:30 +00:00
|
|
|
switch (attr & FILE_ATTR_MASK)
|
|
|
|
{
|
|
|
|
case FILE_ATTR_AUDIO:
|
|
|
|
audiofiles++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FILE_ATTR_M3U:
|
|
|
|
m3ufiles++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-12-28 14:34:38 +00:00
|
|
|
{
|
2010-12-28 14:42:30 +00:00
|
|
|
/* use hardcoded filetype_exts to count
|
|
|
|
* image and video files until we get
|
|
|
|
* new attributes added to filetypes.h */
|
|
|
|
char *ptr = rb->strrchr(entry->d_name,'.');
|
|
|
|
if(ptr) {
|
|
|
|
unsigned i;
|
|
|
|
ptr++;
|
|
|
|
for(i=0;i<ARRAYLEN(image_exts);i++) {
|
|
|
|
if(!rb->strcasecmp(ptr,image_exts[i])) {
|
|
|
|
imagefiles++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= ARRAYLEN(image_exts)) {
|
|
|
|
/* not found above - try video files */
|
|
|
|
for(i=0;i<ARRAYLEN(video_exts);i++) {
|
|
|
|
if(!rb->strcasecmp(ptr,video_exts[i])) {
|
|
|
|
videofiles++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* default: */
|
|
|
|
} /* switch */
|
2006-04-02 20:47:42 +00:00
|
|
|
}
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
2010-12-28 14:42:30 +00:00
|
|
|
|
2005-08-20 19:56:01 +00:00
|
|
|
if (*rb->current_tick - lasttick > (HZ/2)) {
|
|
|
|
update_screen();
|
|
|
|
lasttick = *rb->current_tick;
|
2012-02-09 13:18:46 +00:00
|
|
|
button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts,
|
|
|
|
ARRAYLEN(plugin_contexts));
|
plugins: Improve usability of iPod keymaps
- Reduce need to press multiple buttons at
the same time to quit a plugin
- Have "Menu" be default way to quit plugins or
to access plugin menu
- Fall back to (Long) "Select" or Long "Menu"
in cases where Menu button isn't available
(e.g. in ImageViewer and many games)
out of scope:
boomshine, lua_scripts, Rockpaint,
Doom, Duke3D, Pacbox, Quake,
Sgt-Puzzles, Wolf3D, XWorld,
Minesweeper, Pixel Painter, Spacerocks
Change-Id: I6d4dc7174695fe4b8ee9cbaccb21bdbfe6af5c48
2022-12-18 20:13:15 +00:00
|
|
|
if (button == STATS_STOP || button == STATS_STOP2) {
|
2010-05-06 21:04:40 +00:00
|
|
|
cancel = true;
|
2005-08-20 19:56:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
}
|
|
|
|
rb->closedir(dir);
|
|
|
|
}
|
2007-07-31 12:57:22 +00:00
|
|
|
if (largestdir < files_in_dir)
|
|
|
|
largestdir = files_in_dir;
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|
|
|
|
|
2010-12-28 14:34:38 +00:00
|
|
|
/* this is the plugin entry point */
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2005-08-20 19:56:01 +00:00
|
|
|
{
|
|
|
|
int button;
|
|
|
|
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
files = 0;
|
|
|
|
dirs = 0;
|
2010-12-28 14:42:30 +00:00
|
|
|
audiofiles = 0;
|
|
|
|
m3ufiles = 0;
|
|
|
|
imagefiles = 0;
|
|
|
|
videofiles = 0;
|
2007-07-31 12:57:22 +00:00
|
|
|
largestdir = 0;
|
2010-05-06 21:04:40 +00:00
|
|
|
cancel = false;
|
2005-08-20 19:56:01 +00:00
|
|
|
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Counting...");
|
2005-08-20 19:56:01 +00:00
|
|
|
update_screen();
|
|
|
|
lasttick = *rb->current_tick;
|
|
|
|
|
|
|
|
traversedir("", "");
|
2010-05-06 21:04:40 +00:00
|
|
|
if (cancel) {
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Aborted");
|
2005-08-20 19:56:01 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
2005-09-02 22:25:25 +00:00
|
|
|
update_screen();
|
2020-07-24 23:20:15 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2006-04-02 20:47:42 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->remote_backlight_on();
|
|
|
|
#endif
|
|
|
|
rb->backlight_on();
|
2020-07-24 23:20:15 +00:00
|
|
|
#endif
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Done");
|
2005-08-20 19:56:01 +00:00
|
|
|
update_screen();
|
|
|
|
while (1) {
|
2012-02-09 13:18:46 +00:00
|
|
|
|
|
|
|
button = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts,
|
|
|
|
ARRAYLEN(plugin_contexts));
|
2005-08-20 19:56:01 +00:00
|
|
|
switch (button) {
|
|
|
|
case STATS_STOP:
|
2012-02-09 13:18:46 +00:00
|
|
|
case STATS_STOP2:
|
2005-08-20 19:56:01 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 06:48:07 +00:00
|
|
|
return PLUGIN_OK;
|
2005-08-20 19:56:01 +00:00
|
|
|
}
|