Index: main.c =================================================================== --- main.c (revision 20847) +++ main.c (working copy) @@ -116,7 +116,7 @@ #include "system-sdl.h" #endif -/*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */ +#define AUTOROCK /* define this to check for "autostart.rock" on boot */ const char appsversion[]=APPSVERSION; @@ -583,7 +583,7 @@ #ifdef AUTOROCK { - static const char filename[] = PLUGIN_APPS_DIR "/autostart.rock"; + static const char filename[] = PLUGIN_APPS_DIR "/RockLock.rock"; if(file_exists(filename)) /* no complaint if it doesn't exist */ { Index: plugins/RockLock.c =================================================================== --- plugins/RockLock.c (revision 0) +++ plugins/RockLock.c (revision 0) @@ -0,0 +1,470 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: RockLock.c 19846 2009-01-24 22:41:55Z lowlight $ + * + * Copyright (C) 2009 Mattitiah Curtis (motionman95) + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "plugin.h" +#include "lib/playback_control.h" + +PLUGIN_HEADER + +/* Keypad/Macros */ + +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) + +#define QUIT BUTTON_OFF +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + +#define RC_QUIT BUTTON_RC_STOP + + +#elif CONFIG_KEYPAD == ONDIO_PAD + +#define QUIT BUTTON_OFF +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_MENU +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + + +#elif CONFIG_KEYPAD == RECORDER_PAD + +#define QUIT BUTTON_OFF +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_PLAY +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + + +#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD + +#define QUIT BUTTON_OFF +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + + +#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ + (CONFIG_KEYPAD == IPOD_3G_PAD) || \ + (CONFIG_KEYPAD == IPOD_1G2G_PAD) + +#define QUIT BUTTON_MENU +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_SCROLL_BACK +#define DOWN BUTTON_SCROLL_FWD + +#define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD) +#define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK) + + +#elif (CONFIG_KEYPAD == GIGABEAT_PAD) + +#define QUIT BUTTON_POWER +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + + +#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD + +#define QUIT BUTTON_POWER +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_PLAY +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + + +#elif (CONFIG_KEYPAD == SANSA_E200_PAD) + +#define QUIT BUTTON_POWER +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_SCROLL_BACK +#define DOWN BUTTON_SCROLL_FWD + +#define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD) +#define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK) + + +#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD) + +#define QUIT (BUTTON_HOME|BUTTON_REPEAT) +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_SCROLL_BACK +#define DOWN BUTTON_SCROLL_FWD + +#define SCROLL_FWD(x) ((x) & BUTTON_SCROLL_FWD) +#define SCROLL_BACK(x) ((x) & BUTTON_SCROLL_BACK) + + +#elif CONFIG_KEYPAD == SANSA_C200_PAD || \ +CONFIG_KEYPAD == SANSA_CLIP_PAD || \ +CONFIG_KEYPAD == SANSA_M200_PAD + +#define QUIT BUTTON_POWER +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + + +#elif CONFIG_KEYPAD == IRIVER_H10_PAD + +#define QUIT BUTTON_POWER +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_PLAY +#define UP BUTTON_SCROLL_UP +#define DOWN BUTTON_SCROLL_DOWN + +#elif CONFIG_KEYPAD == GIGABEAT_S_PAD + +#define QUIT BUTTON_BACK +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + +#elif (CONFIG_KEYPAD == MROBE100_PAD) + +#define QUIT BUTTON_POWER +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + +#elif CONFIG_KEYPAD == IAUDIO_M3_PAD + +#define QUIT BUTTON_RC_REC +#define RIGHT BUTTON_RC_FF +#define SELECT BUTTON_RC_PLAY +#define UP BUTTON_RC_VOL_UP +#define DOWN BUTTON_RC_VOL_DOWN + +#elif CONFIG_KEYPAD == CREATIVEZVM_PAD + +#define QUIT BUTTON_BACK +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + +#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD + +#define QUIT BUTTON_POWER +#define RIGHT BUTTON_RIGHT +#define SELECT BUTTON_SELECT +#define UP BUTTON_UP +#define DOWN BUTTON_DOWN + +#define SAVE_FILE PLUGIN_APPS_DIR "/.RockLock" + +/* Booleans */ + +bool leave = false; +bool unlocked = false; + +/* Strings */ + +char codeString[20]; +char correctCode[] = "0000"; +char aboutText[] = "RockLock, Version 1.1"; + +/* Numbers */ + +int curNum = 0; +int curNums = 0; + +/* Functions */ + +static void loadCode(void) +{ + /* Load code from file.. */ + int len, i, fd; + char temp[20], temp2[20]; + + fd = rb->open(SAVE_FILE, O_RDONLY); + + if(fd < 0) + { + return; + } + + rb->read(fd, temp, sizeof(temp)); + rb->close(fd); + + len = rb->strlen(temp); + + for (i = 0; istrcpy(correctCode, temp2); +} + +static void displayAbout(void) +{ + rb->lcd_clear_display(); + rb->splash(1, aboutText); + switch(rb->button_get(true)) + { + default: + break; + } +} + +static void makeCodeString(void) +{ + char buff[20]; + rb->snprintf(buff, sizeof(buff), "%d", curNum); + rb->strcat(codeString, buff); +} + +static void showNum(void) +{ + if(unlocked){ + switch(curNums) + { + case 0: + rb->splashf(1, "Enter new 4-digit code: [%d]000", curNum); + break; + + case 1: + rb->splashf(1, "Enter new 4-digit code: %s[%d]00", codeString, curNum); + break; + + case 2: + rb->splashf(1, "Enter new 4-digit code: %s[%d]0", codeString, curNum); + break; + + case 3: + rb->splashf(1, "Enter new 4-digit code: %s[%d]", codeString, curNum); + break; + } + } else { + switch(curNums) + { + case 0: + rb->splashf(1, "Enter 4-digit code: [%d]000", curNum); + break; + + case 1: + rb->splashf(1, "Enter 4-digit code: %s[%d]00", codeString, curNum); + break; + + case 2: + rb->splashf(1, "Enter 4-digit code: %s[%d]0", codeString, curNum); + break; + + case 3: + rb->splashf(1, "Enter 4-digit code: %s[%d]", codeString, curNum); + break; + } + } +} + +static void decreaseNum(void) +{ + if(curNum == 0){ + curNum = 9; + } else if (curNum > 8 || curNum > 0){ + curNum--; + } +} + +static void increaseNum(void) +{ + if(curNum >= 0 && curNum < 9){ + curNum++; + } else if (curNum > 8){ + curNum = 0; + } +} + +static void saveCode(void) +{ + /* Recode code to use letters */ + + int i, fd, len = rb->strlen(codeString); + char copy[len+1]; + + for (i = 0; iopen(SAVE_FILE, O_WRONLY|O_CREAT); + rb->write(fd, copy, sizeof(copy)); + rb->close(fd); + + rb->strcpy(correctCode, codeString); +} + +static void enterCode(void) +{ + /* Booleans */ + + bool abort = false; + + rb->lcd_clear_display(); + showNum(); + + while(!abort){ + switch(rb->button_get(true)) + { + case UP: + /* Up key pressed, increment current number */ + increaseNum(); + showNum(); + break; + + case DOWN: + /* Down key pressed, deincrement current number */ + decreaseNum(); + showNum(); + break; + + case SELECT: + case RIGHT: + /* Select key pressed, next number! */ + if(curNums == 3) + { + curNums++; + makeCodeString(); + abort = true; + } else { + makeCodeString(); + curNums++; + curNum = 0; + showNum(); + } + break; + + case QUIT: + abort = true; + break; + } + } + + if(!unlocked) + { + if((curNums == 4) & (!rb->strcmp(codeString, correctCode))) + { + rb->splash(HZ*2, "Correct code entered. Access granted."); + unlocked = true; + } else if (curNums == 4) + { + rb->splash(HZ*2, "Incorrect code entered. Access denied."); + } + } else if(curNums == 4) { + rb->splash(1, "Saving code..."); + + saveCode(); + + rb->splash(HZ*2, "Code saved!"); + } + + codeString[0] = '\0'; + curNum = 0; + curNums = 0; +} + +static void changeCode(void) +{ + /* Redirect to enterCode() */ + enterCode(); +} + +/* Plugin entry point */ + +enum plugin_status plugin_start(const void* parameter) +{ + (void)parameter; + + /* Locked Menu */ + MENUITEM_STRINGLIST(menu_locked, "RockLock - Locked", NULL, "Unlock", "About"); + + /* Unlocked Menu */ + MENUITEM_STRINGLIST(menu_unlocked, "RockLock - Unlocked", NULL, "Quit", "Lock", "Change Password", "About"); + + rb->audio_pause(); + loadCode(); + + while(!leave) + { + if(!unlocked) + { + switch (rb->do_menu(&menu_locked, NULL, NULL, false)) + { + case 0: + /* "Unlock" was selected */ + enterCode(); + break; + + case 1: + /* "About" was selected */ + displayAbout(); + break; + } + } else { + switch (rb->do_menu(&menu_unlocked, NULL, NULL, false)) + { + case 0: + /* "Quit" was selected */ + leave = true; + break; + + case 1: + /* "Lock" was selected */ + unlocked = false; + break; + + case 2: + /* "Change Password" was selected */ + changeCode(); + break; + + case 3: + /* "About" was selected */ + displayAbout(); + break; + + default: + leave = true; + break; + } + } + } + + rb->audio_resume(); + return PLUGIN_OK; +} Index: plugins/CATEGORIES =================================================================== --- plugins/CATEGORIES (revision 20847) +++ plugins/CATEGORIES (working copy) @@ -3,6 +3,8 @@ battery_bench,apps blackjack,games bounce,demos +RockLock,apps brickmania,games bubbles,games calculator,apps Index: plugins/SOURCES =================================================================== --- plugins/SOURCES (revision 20847) +++ plugins/SOURCES (working copy) @@ -8,6 +8,7 @@ logo.c mosaique.c properties.c +RockLock.c random_folder_advance_config.c rockblox.c search.c