commit be5245ef47f5e97296999b2a591a30e4359334dc parent 4dbd76de8b022a4b6b4fc35f334188e2cf2ceaae Author: Kebigon <git@kebigon.xyz> Date: Sun, 15 Nov 2009 13:22:48 +0100 Release v0.2 Diffstat:
26 files changed, 1021 insertions(+), 0 deletions(-)
diff --git a/dingui/Arial.ttf b/dingui/Arial.ttf Binary files differ. diff --git a/dingui/apps.txt b/dingui/apps.txt @@ -0,0 +1,4 @@ +smc /usr/local/snes9x +gb /usr/local/sdlgnuboy +gbc /usr/local/sdlgnuboy + diff --git a/dingui/config.txt b/dingui/config.txt @@ -0,0 +1,16 @@ +nb-icons-x=4 +nb-icons-y=3 +icon-width=48 +icon-height=48 +font-size=12 +font-family=Arial.ttf +focus-r=143 +focus-g=95 +focus-b=74 +background-image=images/background.png +foreground-image=images/foreground.png +menu-image=images/menu.png +folder-icon=images/folder.png +file-icon=images/text-x-generic.png +unknown-icon=images/text-x-preview.png + diff --git a/dingui/icons.txt b/dingui/icons.txt @@ -0,0 +1,13 @@ +dge images/application-x-executable.png +sh images/text-x-script.png +png images/image-png.png +ttf images/font-x-generic.png +cpp images/text-x-c++.png +hpp images/text-x-c++.png +nes images/nes.png +smc images/smc.png +078 images/smc.png +gb images/gb.png +gbc images/gb.png +gba images/gb.png + diff --git a/dingui/images/application-x-executable.png b/dingui/images/application-x-executable.png Binary files differ. diff --git a/dingui/images/background.png b/dingui/images/background.png Binary files differ. diff --git a/dingui/images/folder.png b/dingui/images/folder.png Binary files differ. diff --git a/dingui/images/font-x-generic.png b/dingui/images/font-x-generic.png Binary files differ. diff --git a/dingui/images/foreground.png b/dingui/images/foreground.png Binary files differ. diff --git a/dingui/images/gb.png b/dingui/images/gb.png Binary files differ. diff --git a/dingui/images/image-png.png b/dingui/images/image-png.png Binary files differ. diff --git a/dingui/images/menu.png b/dingui/images/menu.png Binary files differ. diff --git a/dingui/images/nes.png b/dingui/images/nes.png Binary files differ. diff --git a/dingui/images/smc.png b/dingui/images/smc.png Binary files differ. diff --git a/dingui/images/text-x-c++.png b/dingui/images/text-x-c++.png Binary files differ. diff --git a/dingui/images/text-x-generic.png b/dingui/images/text-x-generic.png Binary files differ. diff --git a/dingui/images/text-x-preview.png b/dingui/images/text-x-preview.png Binary files differ. diff --git a/dingui/images/text-x-script.png b/dingui/images/text-x-script.png Binary files differ. diff --git a/dingui_src/Application.cpp b/dingui_src/Application.cpp @@ -0,0 +1,243 @@ +#include "Application.hpp" +#include <cstdlib> +#include <fstream> +#include <iostream> + +Application::Application() +:sonCopier("") +,sonRepertoireCourant("/boot/") +,sesErreurs("") +{ + std::ifstream laConfiguration("config.txt"); + std::string laVariable, laValeur; + + while (laConfiguration.good() == true) + { + getline(laConfiguration, laVariable, '='); + getline(laConfiguration, laValeur, '\n'); + + if (laVariable == "" || laValeur == "" || saConfiguration.insert(std::make_pair(laVariable, laValeur)).second == false) + { + std::cerr << "Application(): " << "The config.txt file is corrupted" << std::endl; + exit(EXIT_FAILURE); + } + + } + + laConfiguration.close(); + std::ifstream lesApplications("apps.txt"); + std::string lExtension, lApplication; + + while (lesApplications.good() == true) + { + getline(lesApplications, lExtension, '\t'); + getline(lesApplications, lApplication, '\n'); + + if (lExtension == "" || lApplication == "" || sesApplications.insert(std::make_pair(lExtension, lApplication)).second == false) + { + ajouterErreur("The apps.txt file is corrupted."); + } + + } + + lesApplications.close(); + std::vector<std::vector<Element *> >::iterator leItY; + std::vector<Element *>::iterator leItX; + sonContenu.resize(1000); + + for (leItY = sonContenu.begin(); leItY != sonContenu.end(); leItY++) + { + leItY->resize(atoi(getSaValeur("nb-icons-x").c_str())); + + for (leItX = leItY->begin(); leItX != leItY->end(); leItX++) + { + *leItX = NULL; + } + + } + +} + +Application::~Application() +{ + std::vector<std::vector<Element *> >::iterator leItY; + std::vector<Element *>::iterator leItX; + + for (leItY = sonContenu.begin(); leItY != sonContenu.end(); leItY++) + { + + for (leItX = leItY->begin(); leItX != leItY->end(); leItX++) + { + delete *leItX; + } + + } + +} + +void Application::ajouterErreur(std::string uneErreur) +{ + sesErreurs += uneErreur + '\n'; + return; +} + +void Application::changerRepertoire(std::string unRepertoire) +{ + + if (unRepertoire == "..") + { + + if (sonRepertoireCourant != "/") + { + int i = sonRepertoireCourant.find_last_of('/', sonRepertoireCourant.size() - 2); + sonRepertoireCourant.erase(i + 1); + } + + } + + else + { + sonRepertoireCourant += unRepertoire + '/'; + } + + return; +} + +void Application::coller(std::string unRepertoire) const +{ + + if (sonCopier != "") + { + std::string laCommande = "cp -Rf \"" + sonCopier + "\" \"" + sonRepertoireCourant + unRepertoire + "\";"; + system(laCommande.c_str()); + } + + return; +} + +void Application::copier(std::string unFichier) +{ + sonCopier = sonRepertoireCourant + unFichier; + return; +} + +std::string Application::getSaValeur(std::string uneVariable) const +{ + std::map<std::string, std::string>::const_iterator leIt = saConfiguration.find(uneVariable); + + if (leIt == saConfiguration.end()) + { + std::cerr << "getSaValeur(): " << "The config.txt file is corrupted" << std::endl; + exit(EXIT_FAILURE); + } + + return leIt->second; +} + +std::string Application::getSesErreurs() const +{ + return sesErreurs; +} + +std::string Application::getSonApplication(std::string uneExtension) const +{ + std::string uneApplication = ""; + std::map<std::string, std::string>::const_iterator leIt = sesApplications.find(uneExtension); + + if (leIt != sesApplications.end()) + { + uneApplication = leIt->second; + } + + return uneApplication; +} + +std::vector<std::vector<Element *> > Application::getSonContenu() const +{ + return sonContenu; +} + +void Application::lireRepertoire() +{ + std::vector<std::vector<Element *> >::iterator leItY; + std::vector<Element *>::iterator leItX; + + for (leItY = sonContenu.begin(); leItY != sonContenu.end(); leItY++) + { + + for (leItX = leItY->begin(); leItX != leItY->end(); leItX++) + { + delete *leItX; + *leItX = NULL; + } + + } + + DIR * leRepertoire = opendir(sonRepertoireCourant.c_str()); + + if (leRepertoire == NULL) + { + ajouterErreur("Permission denied."); + changerRepertoire(".."); + lireRepertoire(); + } + + else + { + dirent * lEntree = NULL; + int leX = 0; + int leXMax = atoi(getSaValeur("nb-icons-x").c_str()); + int leY = 0; + bool estVide = true; + + while ((lEntree = readdir(leRepertoire)) != NULL) + { + + if (leX == leXMax) + { + leX = 0; + leY++; + } + + if (sizeof(lEntree->d_name) != 0 && lEntree->d_name[0] != '.') + { + estVide = false; + sonContenu[leY][leX] = new Element(lEntree); + leX++; + } + + } + + closedir(leRepertoire); + + if (estVide == true) + { + ajouterErreur("There are no files."); + changerRepertoire(".."); + lireRepertoire(); + } + + } + + return; +} + +void Application::redemarrer() const +{ + execlp("reboot", "reboot", NULL); + return; +} + +void Application::resetSesErreurs() +{ + sesErreurs.clear(); + return; +} + +void Application::supprimer(std::string unFichier) const +{ + std::string laCommande = "rm -Rf \"" + sonRepertoireCourant + unFichier + "\";"; + system(laCommande.c_str()); + return; +} + diff --git a/dingui_src/Application.hpp b/dingui_src/Application.hpp @@ -0,0 +1,28 @@ +#include "Element.hpp" +#include <map> +#include <vector> + +class Application +{ + std::map<std::string, std::string> saConfiguration, sesApplications; + std::string sonCopier, sonRepertoireCourant, sesErreurs; + std::vector<std::vector<Element *> > sonContenu; +public : + Application(); + ~Application(); + void ajouterErreur(std::string); + void changerRepertoire(std::string); + void coller(std::string) const; + void copier(std::string); + void eteindre() const; + std::string getSaValeur(std::string) const; + std::string getSesErreurs() const; + std::string getSonApplication(std::string) const; + std::vector<std::vector<Element *> > getSonContenu() const; + void lireRepertoire(); + void ouvrirFichier(Element *); + void redemarrer() const; + void resetSesErreurs(); + void supprimer(std::string) const; +}; + diff --git a/dingui_src/Element.cpp b/dingui_src/Element.cpp @@ -0,0 +1,43 @@ +#include "Element.hpp" + +Element::Element(dirent * uneEntree) +:sonNom(uneEntree->d_name) +,sonExtension("") +,sonType(inconnu) +{ + + switch (uneEntree->d_type) + { + case DT_DIR : + sonType = dossier; + break; + case DT_REG : + sonType = fichier; + break; + default : + sonType = inconnu; + } + + if (sonType == fichier) + { + int lePoint = sonNom.find_last_of('.'); + sonExtension = sonNom.substr(lePoint + 1); + } + +} + +std::string Element::getSonNom() const +{ + return sonNom; +} + +std::string Element::getSonExtension() const +{ + return sonExtension; +} + +type Element::getSonType() const +{ + return sonType; +} + diff --git a/dingui_src/Element.hpp b/dingui_src/Element.hpp @@ -0,0 +1,16 @@ +#include <dirent.h> +#include <string> + +enum type { dossier, fichier, inconnu }; + +class Element +{ + std::string sonNom, sonExtension; + type sonType; +public : + Element(dirent *); + std::string getSonNom() const; + std::string getSonExtension() const; + type getSonType() const; +}; + diff --git a/dingui_src/Interface.cpp b/dingui_src/Interface.cpp @@ -0,0 +1,618 @@ +#include "Interface.hpp" +#include <iostream> +#include <fstream> +#include <SDL/SDL_image.h> +#include <sstream> + +Interface::Interface() +:sonX(0) +,sonY(0) +,sonScroll(0) +,sonMenu(0) +,sonEcran(NULL) +,sonArrierePlan(NULL) +,sonFondMessage(NULL) +,sonFondMenu(NULL) +,sonIconeDossier(NULL) +,sonIconeFichier(NULL) +,sonIconeInconnu(NULL) +,saPolice(NULL) +{ + + if (SDL_Init(SDL_INIT_VIDEO) == -1) + { + std::cerr << "SDL_Init(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + sonEcran = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE); + + if (sonEcran == NULL) + { + std::cerr << "SDL_SetVideoMode(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + SDL_EnableKeyRepeat(500, 100); + SDL_ShowCursor(SDL_DISABLE); + atexit(SDL_Quit); + + if (TTF_Init() == -1) + { + std::cerr << "TTF_Init(): " << TTF_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + saPolice = TTF_OpenFont(sonExplorateur.getSaValeur("font-family").c_str(), atoi(sonExplorateur.getSaValeur("font-size").c_str())); + + if (saPolice == NULL) + { + std::cerr << "TTF_OpenFont(): " << TTF_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + sonBlanc.r = 255; + sonBlanc.g = 255; + sonBlanc.b = 255; + sonNoir.r = 0; + sonNoir.g = 0; + sonNoir.b = 0; + sonFocus.r = atoi(sonExplorateur.getSaValeur("focus-r").c_str()); + sonFocus.g = atoi(sonExplorateur.getSaValeur("focus-g").c_str()); + sonFocus.b = atoi(sonExplorateur.getSaValeur("focus-b").c_str()); + std::ifstream lesIcones("icons.txt"); + std::string lExtension, lIcone; + + while (lesIcones.good() == true) + { + getline(lesIcones, lExtension, '\t'); + getline(lesIcones, lIcone, '\n'); + + if (lExtension == "" || lIcone == "" || sesIcones.insert(std::make_pair(lExtension, chargerImage(lIcone))).second == false) + { + sonExplorateur.ajouterErreur("The icons.txt file is corrupted"); + } + + } + + lesIcones.close(); + sonArrierePlan = chargerImage(sonExplorateur.getSaValeur("background-image")); + sonFondMessage = chargerImage(sonExplorateur.getSaValeur("foreground-image")); + sonFondMenu = chargerImage(sonExplorateur.getSaValeur("menu-image")); + sonIconeDossier = chargerImage(sonExplorateur.getSaValeur("folder-icon")); + sonIconeFichier = chargerImage(sonExplorateur.getSaValeur("file-icon")); + sonIconeInconnu = chargerImage(sonExplorateur.getSaValeur("unknown-icon")); + sonExplorateur.lireRepertoire(); + afficher(); + boucler(); +} + +Interface::~Interface() +{ + TTF_CloseFont(saPolice); + TTF_Quit(); + SDL_FreeSurface(sonArrierePlan); + SDL_FreeSurface(sonFondMessage); + SDL_FreeSurface(sonFondMenu); + SDL_FreeSurface(sonIconeDossier); + SDL_FreeSurface(sonIconeFichier); + SDL_FreeSurface(sonIconeInconnu); + SDL_Quit(); +} + +void Interface::boucler() +{ + int nb_icons_x = atoi(sonExplorateur.getSaValeur("nb-icons-x").c_str()); + int nb_icons_y = atoi(sonExplorateur.getSaValeur("nb-icons-y").c_str()); + std::vector<std::vector<Element *> > leContenu = sonExplorateur.getSonContenu(); + bool b = true; + SDL_Event lEvenement; + + while (b) + { + + if (SDL_WaitEvent(&lEvenement)) + { + + if (lEvenement.type == SDL_KEYDOWN) + { + + if (sonExplorateur.getSesErreurs() != "") + { + + if (lEvenement.key.keysym.sym == SDLK_LCTRL) + { + sonExplorateur.resetSesErreurs(); + } + + } + + else + { + + if (sonMenu != 0) + { + + switch (lEvenement.key.keysym.sym) + { + case SDLK_UP : + switch (sonMenu) + { + case 9 : + sonMenu = 5; + break; + case 1 : + sonMenu = 10; + break; + default : + sonMenu--; + } + break; + case SDLK_DOWN : + switch (sonMenu) + { + case 5 : + sonMenu = 9; + break; + case 10 : + sonMenu = 1; + break; + default : + sonMenu++; + } + break; + case SDLK_LCTRL : + switch (sonMenu) + { + case 1 : + switch (leContenu[sonY][sonX]->getSonType()) + { + case dossier : + sonExplorateur.changerRepertoire(leContenu[sonY][sonX]->getSonNom()); + sonScroll = 0; + sonX = 0; + sonY = 0; + sonExplorateur.lireRepertoire(); + leContenu = sonExplorateur.getSonContenu(); + break; + case fichier : + sonExplorateur.ouvrirFichier(leContenu[sonY][sonX]); + break; + default : + sonExplorateur.ajouterErreur("Could not open the file."); + } + sonMenu = 0; + break; + case 2 : + sonExplorateur.copier(leContenu[sonY][sonX]->getSonNom()); + sonMenu = 0; + break; + case 3 : + sonExplorateur.coller(""); + sonMenu = 0; + sonExplorateur.lireRepertoire(); + leContenu = sonExplorateur.getSonContenu(); + break; + case 4 : + if (leContenu[sonY][sonX]->getSonType() == dossier) + { + sonExplorateur.coller(leContenu[sonY][sonX]->getSonNom()); + sonMenu = 0; + sonExplorateur.lireRepertoire(); + leContenu = sonExplorateur.getSonContenu(); + } + break; + case 5 : + sonExplorateur.supprimer(leContenu[sonY][sonX]->getSonNom()); + sonMenu = 0; + sonScroll = 0; + sonX = 0; + sonY = 0; + sonExplorateur.lireRepertoire(); + leContenu = sonExplorateur.getSonContenu(); + break; + case 9 : + sonExplorateur.eteindre(); + sonMenu = 0; + break; + case 10 : + sonExplorateur.redemarrer(); + sonMenu = 0; + break; + default : + sonMenu = 0; + } + break; + case SDLK_LALT : + sonMenu = 0; + break; + case SDLK_LSHIFT : + sonMenu = 0; + break; + } + + } + + else + { + + switch (lEvenement.key.keysym.sym) + { + case SDLK_UP : + if (sonY != 0) + { + sonY--; + if (sonY < sonScroll) + { + sonScroll--; + } + } + break; + case SDLK_DOWN : + if (leContenu[sonY + 1][sonX] != NULL) + { + sonY++; + if (sonY >= sonScroll + nb_icons_y) + { + sonScroll++; + } + } + break; + case SDLK_LEFT : + if (sonX != 0) + { + sonX--; + } + break; + case SDLK_RIGHT : + if (sonX + 1 < nb_icons_x && leContenu[sonY][sonX + 1] != NULL) + { + sonX++; + } + break; + case SDLK_LCTRL : + switch (leContenu[sonY][sonX]->getSonType()) + { + case dossier : + sonExplorateur.changerRepertoire(leContenu[sonY][sonX]->getSonNom()); + sonScroll = 0; + sonX = 0; + sonY = 0; + sonExplorateur.lireRepertoire(); + leContenu = sonExplorateur.getSonContenu(); + break; + case fichier : + sonExplorateur.ouvrirFichier(leContenu[sonY][sonX]); + break; + default : + sonExplorateur.ajouterErreur("Could not open the file."); + } + break; + case SDLK_LALT : + sonExplorateur.changerRepertoire(".."); + sonScroll = 0; + sonX = 0; + sonY = 0; + sonExplorateur.lireRepertoire(); + leContenu = sonExplorateur.getSonContenu(); + break; + case SDLK_LSHIFT : + sonMenu = 1; + break; + case SDLK_ESCAPE : + b = false; + break; + } + + } + + } + + afficher(); + } + + } + + } + + return; +} + +void Interface::afficher() +{ + + if (SDL_BlitSurface(sonArrierePlan, NULL, sonEcran, NULL) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + int leX = 0; + int leY = 0; + SDL_Rect laPosition; + std::string leNom; + int nb_icons_x = atoi(sonExplorateur.getSaValeur("nb-icons-x").c_str()); + int nb_icons_y = atoi(sonExplorateur.getSaValeur("nb-icons-y").c_str()); + int icon_width = atoi(sonExplorateur.getSaValeur("icon-width").c_str()); + int icon_height = atoi(sonExplorateur.getSaValeur("icon-height").c_str()); + int font_size = atoi(sonExplorateur.getSaValeur("font-size").c_str()); + unsigned int name_max_size = ((320 / nb_icons_x) / (font_size / 2 )) - 1; + std::vector<std::vector<Element *> > leContenu = sonExplorateur.getSonContenu(); + std::vector<std::vector<Element *> >::const_iterator leItY; + std::vector<Element *>::const_iterator leItX; + + for (leItY = leContenu.begin(); leItY != leContenu.end(); leItY++) + { + + for (leItX = leItY->begin(); leItX != leItY->end(); leItX++) + { + + if ((*leItX) != NULL && leY >= sonScroll && leY < sonScroll + nb_icons_y) + { + laPosition.x = leX * (320 / nb_icons_x) + (320 / nb_icons_x - icon_width) / 2; + laPosition.y = (leY - sonScroll) * (240 / nb_icons_y) + (240 / nb_icons_y - icon_height) / 2; + + switch ((*leItX)->getSonType()) + { + case dossier : + if (SDL_BlitSurface(sonIconeDossier, NULL, sonEcran, &laPosition) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + break; + case fichier : + { + SDL_Surface * lIcone = getSonIcone((*leItX)->getSonExtension()); + if (lIcone == NULL) + { + lIcone = sonIconeFichier; + } + if (SDL_BlitSurface(lIcone, NULL, sonEcran, &laPosition) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + break; + } + default : + if (SDL_BlitSurface(sonIconeInconnu, NULL, sonEcran, &laPosition) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + } + + leNom = (*leItX)->getSonNom(); + + if (leNom.size() > name_max_size) + { + leNom = leNom.substr(0, name_max_size); + } + + ecrire(leNom, laPosition.x + icon_width / 2.0 - ((leNom.size()) / 2.0) * (font_size / 2.0), laPosition.y + icon_height, leX == sonX && leY == sonY); + } + + leX++; + } + + leX = 0; + leY++; + } + + if (sonMenu != 0) + { + + if (SDL_BlitSurface(sonFondMenu, NULL, sonEcran, NULL) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + ecrire("->", 200, (2 + sonMenu) * font_size, false); + ecrire("Open", 212, 3 * font_size, false); + ecrire("Copy", 212, 4 * font_size, false); + ecrire("Paste", 212, 5 * font_size, false); + ecrire("Paste Into Folder", 212, 6 * font_size, false); + ecrire("Delete", 212, 7 * font_size, false); + ecrire("Shut Down", 212, 11 * font_size, false); + ecrire("Restart", 212, 12 * font_size, false); + } + + if (sonExplorateur.getSesErreurs() != "") + { + std::istringstream lesErreurs(sonExplorateur.getSesErreurs()); + std::string lErreur; + int i = 0; + + if (SDL_BlitSurface(sonFondMessage, NULL, sonEcran, NULL) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + while (lesErreurs.good()) + { + getline(lesErreurs, lErreur); + + if (lErreur != "") + { + ecrire(lErreur, 160.0 - lErreur.size() / 2.0 * (font_size / 2.0), (3.0 + i) * font_size, false); + i++; + } + } + + ecrire("A : OK", 200, 240 - font_size, false); + } + + if (SDL_Flip(sonEcran) == -1) + { + std::cerr << "SDL_Flip(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + return; +} + +SDL_Surface * Interface::getSonIcone(std::string uneExtension) const +{ + SDL_Surface * lIcone = NULL; + std::map<std::string, SDL_Surface *>::const_iterator leIt = sesIcones.find(uneExtension); + + if (leIt != sesIcones.end()) + { + lIcone = leIt->second; + } + + return lIcone; +} + +SDL_Surface * Interface::chargerImage(std::string unFichier) const +{ + SDL_Surface * lImage = IMG_Load(unFichier.c_str()); + + if (lImage == NULL) + { + std::cerr << "IMG_Load(): " << IMG_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + return lImage; +} + +void Interface::ecrire(std::string unTexte, int unX, int unY, bool estSelectionne) +{ + SDL_Rect laPosition; + SDL_Surface * leTexte; + + if (estSelectionne == true) + { + laPosition.x = unX; + laPosition.y = unY; + leTexte = TTF_RenderText_Shaded(saPolice, unTexte.c_str(), sonBlanc, sonFocus); + + if (leTexte == NULL) + { + std::cerr << "TTF_RenderText_Shaded(): " << TTF_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + if (SDL_BlitSurface(leTexte, NULL, sonEcran, &laPosition) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + } + + else + { + laPosition.x = unX + 1; + laPosition.y = unY + 1; + leTexte = TTF_RenderText_Blended(saPolice, unTexte.c_str(), sonNoir); + + if (leTexte == NULL) + { + std::cerr << "TTF_RenderText_Blended(): " << TTF_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + if (SDL_BlitSurface(leTexte, NULL, sonEcran, &laPosition) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + laPosition.x = unX; + laPosition.y = unY; + leTexte = TTF_RenderText_Blended(saPolice, unTexte.c_str(), sonBlanc); + + if (leTexte == NULL) + { + std::cerr << "TTF_RenderText_Blended(): " << TTF_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + if (SDL_BlitSurface(leTexte, NULL, sonEcran, &laPosition) == -1) + { + std::cerr << "SDL_BlitSurface(): " << SDL_GetError() << std::endl; + exit(EXIT_FAILURE); + } + + } + + SDL_FreeSurface(leTexte); + return; +} + +void Application::eteindre() const +{ + TTF_Quit(); + SDL_Quit(); + execlp("poweroff", "poweroff", NULL); + return; +} + +void Application::ouvrirFichier(Element * unFichier) +{ + char exe[512]; + int exe_len = readlink("/proc/self/exe", exe, sizeof(exe) - 1); + exe[exe_len] = '\0'; + std::string cwd(getcwd(NULL, 0)); + std::string leNom = unFichier->getSonNom(); + std::string lExtension = unFichier->getSonExtension(); + + if (lExtension == "dge" || lExtension == "sh") + { + std::string laCommande = "\"./" + unFichier->getSonNom() + "\"; cd \"" + cwd + "\"; exec \"" + exe + "\";"; + + if (chdir(sonRepertoireCourant.c_str()) == -1) + { + ajouterErreur("Permission denied."); + } + + else + { + TTF_Quit(); + SDL_Quit(); + execlp("/bin/sh", "/bin/sh", "-c", laCommande.c_str(), NULL); + } + + } + + else + { + std::string lApplication = getSonApplication(lExtension); + + if (lApplication.empty()) + { + ajouterErreur("Could not open the file."); + } + + else + { + int leSlash = lApplication.find_last_of('/'); + std::string leRepertoire = lApplication.substr(0, leSlash); + lApplication = lApplication.substr(leSlash + 1); + std::string laCommande = "\"./" + lApplication + "\" \"" + sonRepertoireCourant + unFichier->getSonNom() + "\"; cd \"" + cwd + "\"; exec \"" + exe + "\";"; + + if (chdir(leRepertoire.c_str()) == -1) + { + ajouterErreur("Permission denied."); + } + + else + { + TTF_Quit(); + SDL_Quit(); + execlp("/bin/sh", "/bin/sh", "-c", laCommande.c_str(), NULL); + } + + } + + } + + return; +} + diff --git a/dingui_src/Interface.hpp b/dingui_src/Interface.hpp @@ -0,0 +1,22 @@ +#include "Application.hpp" +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> + +class Interface +{ + Application sonExplorateur; + int sonX, sonY, sonScroll, sonMenu; + std::map<std::string, SDL_Surface *> sesIcones; + SDL_Color sonBlanc, sonNoir, sonFocus; + SDL_Surface * sonEcran, * sonArrierePlan, * sonFondMessage, * sonFondMenu, * sonIconeDossier, * sonIconeFichier, * sonIconeInconnu; + TTF_Font * saPolice; + void afficher(); + void boucler(); + SDL_Surface * chargerImage(std::string) const; + void ecrire(std::string, int, int, bool); + SDL_Surface * getSonIcone(std::string) const; +public : + Interface(); + ~Interface(); +}; + diff --git a/dingui_src/dingoo.sh b/dingui_src/dingoo.sh @@ -0,0 +1,10 @@ +#!/bin/bash +mipsel-linux-g++ -O3 -Wall -c Element.cpp +mipsel-linux-g++ -O3 -Wall -c Application.cpp +mipsel-linux-g++ -O3 -Wall -c Interface.cpp +mipsel-linux-g++ -O3 -Wall -c main.cpp +mipsel-linux-g++ -O3 -Wall Element.o Application.o Interface.o main.o -lSDL -lSDL_ttf -lSDL_image -o dingui +rm Element.o +rm Application.o +rm Interface.o +rm main.o diff --git a/dingui_src/main.cpp b/dingui_src/main.cpp @@ -0,0 +1,8 @@ +#include "Interface.hpp" + +int main() +{ + Interface lInterface; + return EXIT_SUCCESS; +} +