#include #include #include #include "wElement.h" #include "icons.h" void Browser(); wTHEME *BlackTheme(); int main() { wInitSDL(); Browser(); SDL_Quit(); return 0; } void PrintMessage(const char *msg) { SDL_Surface *scr = SDL_GetVideoSurface(); nSDL_Font *font = nSDL_LoadFont(NSDL_FONT_TINYTYPE, 220, 220, 220); roundedBoxRGBA(scr, 160-140, 120-20, 160+140, 120+20, 3, 40,40,40,220); nSDL_DrawString(scr, font, 160-nSDL_GetStringWidth(font, msg)/2, 115, msg); SDL_Flip(scr); nSDL_FreeFont(font); } int PrintInputMsg(const char *msg) { PrintMessage(msg); int ok = -1; while (ok == -1) { wait_key_pressed(); while (K_ENTER()) ok = 1; while (K_ESC()) ok = 0; } return ok; } void Browser() { // Déclaration des variables char *elementName[512]; int nElements; char path[256] = "/documents"; char *folderName = malloc(64); strcpy(folderName, "documents"); char filePath[256]; int x; int nChilds; Widget **childs; // Chargement des images SDL_Surface *S_emptyFolder = nSDL_LoadImage(image_emptyfolder); SDL_Surface *S_folder = nSDL_LoadImage(image_folder); SDL_Surface *S_file = nSDL_LoadImage(image_file); SDL_Surface *S_tns = nSDL_LoadImage(image_tns); SDL_Surface *S_ice = nSDL_LoadImage(image_ice); SDL_Surface *S_txt = nSDL_LoadImage(image_txt); SDL_Surface *S_pdf = nSDL_LoadImage(image_pdf); SDL_Surface *S_gb = nSDL_LoadImage(image_gb); SDL_Surface *S_pic = nSDL_LoadImage(image_picture); SDL_SetColorKey(S_emptyFolder, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_folder, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_file, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_tns, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_ice, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_txt, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_pdf, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_gb, SDL_SRCCOLORKEY, RGB(255,0,0)); SDL_SetColorKey(S_pic, SDL_SRCCOLORKEY, RGB(255,0,0)); // Déclaration des widgets Widget *mainWidget = wWindow("nArchiver"); Widget *body = wBasicLayout(0); Widget *folderStatus = wElement(S_folder, folderName, -1); Widget *elementsPanel = wScrolledLayout(); wSetDynamism(folderStatus, 0); wSetBackground(elementsPanel, wBackgroundColor(RGB(80,88,103), RGB(92,103,120), BACKG_TRICOLOR)); // Fonction d'ajout des éléments à ElementsPanel void RefreshElements() { // on supprime les anciens éléments nChilds = wLayout_GetNumberOfChilds(elementsPanel); childs = wLayout_GetChildsList(elementsPanel); for (x=0; x < nChilds; x++) wRemoveWidget(childs[x]); // on rajoute les nouveaux éléments nElements = folder_GetElements(path, NULL, elementName); for (x=0; x < nElements; x++) { sprintf(filePath, "%s/%s", path, elementName[x]); if (isFile(filePath)) { // on cherche de quel type est le fichier if (strstr(elementName[x], ".txt") || strstr(elementName[x], ".cfg")) wAddWidget(elementsPanel, wElement(S_txt, elementName[x], file_GetSize(filePath))); else if (strstr(elementName[x], ".bmp") || strstr(elementName[x], ".png") || strstr(elementName[x], ".jpg") || strstr(elementName[x], ".jpeg") || strstr(elementName[x], ".gif")) wAddWidget(elementsPanel, wElement(S_pic, elementName[x], file_GetSize(filePath))); else if (strstr(elementName[x], ".gb")) wAddWidget(elementsPanel, wElement(S_gb, elementName[x], file_GetSize(filePath))); else if (strstr(elementName[x], ".pdf")) wAddWidget(elementsPanel, wElement(S_pdf, elementName[x], file_GetSize(filePath))); else if (strstr(elementName[x], ".ice")) wAddWidget(elementsPanel, wElement(S_ice, elementName[x], file_GetSize(filePath))); else { char *p = strstr(elementName[x], ".tns"); if (p && strchr(elementName[x], '.') == p) wAddWidget(elementsPanel, wElement(S_tns, elementName[x], file_GetSize(filePath))); else wAddWidget(elementsPanel, wElement(S_file, elementName[x], file_GetSize(filePath))); } } else if (isFolder(filePath)) { int n = folder_GetNumberOfElements(filePath); wAddWidget(elementsPanel, wElement(n>0? S_folder : S_emptyFolder, elementName[x], n)); } else wAddWidget(elementsPanel, wElement(S_file, elementName[x], file_GetSize(filePath))); } } // Création de l'architecture wAddWidget(mainWidget, body); wAddWidget(body, folderStatus); wAddWidget(body, elementsPanel); RefreshElements(); // Création des fonctions callback int CB_Click(Widget *w, int signal) { if (signal == SIGNAL_CLICK && K_ENTER()) { ElementArgs *args = w->args; sprintf(filePath, "%s/%s", path, args->name); if (isFile(filePath)) { if (strstr(filePath, ".ice")) { PrintMessage("Warming..."); Warm(filePath); RefreshElements(); nChilds = wLayout_GetNumberOfChilds(elementsPanel); childs = wLayout_GetChildsList(elementsPanel); for (x=0; x < nChilds; x++) wConnect(childs[x], CB_Click); return ACTION_REFRESH; } else { PrintMessage("Executing..."); nl_exec(filePath, 0, NULL); wDrawWidget(body); return ACTION_CONTINUE; } } else if (isFolder(filePath)) { if (args->size > 0) { strcpy(path, filePath); strcpy(folderName, strrchr(filePath, '/')+1); RefreshElements(); nChilds = wLayout_GetNumberOfChilds(elementsPanel); childs = wLayout_GetChildsList(elementsPanel); for (x=0; x < nChilds; x++) wConnect(childs[x], CB_Click); return ACTION_REFRESH; } else { PrintMessage("The folder is empty."); wDrawWidget(body); wait_key_pressed(); } } } return ACTION_CONTINUE; } int CB_Key(Widget *w, int signal) { if (signal == SIGNAL_KEY) { if (K_LEFT()) { if (strlen(path) > 1) { *(strrchr(path, '/')) = 0; if (strrchr(path, '/')) strcpy(folderName, strrchr(path, '/')+1); else strcpy(folderName, "/"); RefreshElements(); nChilds = wLayout_GetNumberOfChilds(elementsPanel); childs = wLayout_GetChildsList(elementsPanel); for (x=0; x < nChilds; x++) wConnect(childs[x], CB_Click); return ACTION_REFRESH; } } /*else if (K_RIGHT()) { w = wLayout_GetChildsList(elementsPanel)[wLayout_GetCurrentChild(elementsPanel)]; ElementArgs *args = w->args; sprintf(filePath, "%s/%s", path, args->name); if (isFolder(filePath)) { if (args->size > 0) { strcpy(path, filePath); strcpy(folderName, strrchr(filePath, '/')+1); RefreshElements(); nChilds = wLayout_GetNumberOfChilds(elementsPanel); childs = wLayout_GetChildsList(elementsPanel); for (x=0; x < nChilds; x++) wConnect(childs[x], CB_Click); return ACTION_REFRESH; } } }*/ else if (K_DEL()) { w = wLayout_GetChildsList(elementsPanel)[wLayout_GetCurrentChild(elementsPanel)]; ElementArgs *args = w->args; sprintf(filePath, "%s/%s", path, args->name); if (strstr(filePath, "ndless")) { } if (isFile(filePath)) { if (PrintInputMsg("Do you want to delete this file ?")) { remove(filePath); wRemoveWidget(w); return ACTION_REFRESH; } wDrawWidget(body); } else if (isFolder(filePath)) { if (PrintInputMsg("Do you want to delete this folder ?")) { folder_Remove(filePath); wRemoveWidget(w); return ACTION_REFRESH; } wDrawWidget(body); } } else if (isKeyPressed(KEY_NSPIRE_CAT)) { w = wLayout_GetChildsList(elementsPanel)[wLayout_GetCurrentChild(elementsPanel)]; ElementArgs *args = w->args; sprintf(filePath, "%s/%s", path, args->name); if (strstr(filePath, ".ice")) wShowMsg(filePath, "Ce fichier est deja archive !"); else { PrintMessage("Icing..."); Ice(filePath); RefreshElements(); nChilds = wLayout_GetNumberOfChilds(elementsPanel); childs = wLayout_GetChildsList(elementsPanel); for (x=0; x < nChilds; x++) wConnect(childs[x], CB_Click); return ACTION_REFRESH; } } } return ACTION_CONTINUE; } // Connection wConnect(body, CB_Key); nChilds = wLayout_GetNumberOfChilds(elementsPanel); childs = wLayout_GetChildsList(elementsPanel); for (x=0; x < nChilds; x++) wConnect(childs[x], CB_Click); // Exécution wExecConstruct(mainWidget, BlackTheme()); SDL_FreeSurface(S_emptyFolder); SDL_FreeSurface(S_folder); SDL_FreeSurface(S_tns); SDL_FreeSurface(S_ice); SDL_FreeSurface(S_txt); SDL_FreeSurface(S_pdf); SDL_FreeSurface(S_gb); }