1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 02:51:53 +02:00

Use an enum instead of hardcoded values for the user-injected codes

This commit is contained in:
Paul Cercueil 2013-07-21 23:52:35 -04:00
parent a0515ad356
commit b0fa6db97d
4 changed files with 31 additions and 11 deletions

View File

@ -178,18 +178,29 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
break; break;
#endif #endif
case SDL_USEREVENT: case SDL_USEREVENT:
if (!event.user.code) switch ((enum EventCode) event.user.code) {
menu->removePackageLink((const char *) event.user.data1); case REMOVE_LINKS:
else if (event.user.code == 1) menu->removePackageLink((const char *) event.user.data1);
menu->openPackage((const char *) event.user.data1); break;
else if (event.user.code == 2) case OPEN_PACKAGE:
menu->openPackagesFromDir( menu->openPackage((const char *) event.user.data1);
((string) (const char *) event.user.data1 break;
+ "/apps").c_str()); case OPEN_PACKAGES_FROM_DIR:
free(event.user.data1); menu->openPackagesFromDir(
((string) (const char *) event.user.data1
+ "/apps").c_str());
break;
case REPAINT_MENU:
default:
break;
}
if (event.user.data1)
free(event.user.data1);
bevent->state = PRESSED; bevent->state = PRESSED;
bevent->button = REPAINT; bevent->button = REPAINT;
return true; return true;
default: default:
return false; return false;
} }

View File

@ -26,6 +26,13 @@
class Menu; class Menu;
enum EventCode {
REMOVE_LINKS,
OPEN_PACKAGE,
OPEN_PACKAGES_FROM_DIR,
REPAINT_MENU,
};
class InputManager { class InputManager {
public: public:
enum Button { enum Button {

View File

@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include "debug.h" #include "debug.h"
#include "inputmanager.h"
#include "mediamonitor.h" #include "mediamonitor.h"
MediaMonitor::MediaMonitor(std::string dir) : MediaMonitor::MediaMonitor(std::string dir) :
@ -21,7 +22,7 @@ void MediaMonitor::inject_event(bool is_add, const char *path)
{ {
SDL_UserEvent e = { SDL_UserEvent e = {
.type = SDL_USEREVENT, .type = SDL_USEREVENT,
.code = is_add ? 2 : 0, .code = is_add ? OPEN_PACKAGES_FROM_DIR : REMOVE_LINKS,
.data1 = strdup(path), .data1 = strdup(path),
.data2 = NULL, .data2 = NULL,
}; };

View File

@ -8,13 +8,14 @@
#include <sys/inotify.h> #include <sys/inotify.h>
#include <unistd.h> #include <unistd.h>
#include "inputmanager.h"
#include "monitor.h" #include "monitor.h"
void Monitor::inject_event(bool is_add, const char *path) void Monitor::inject_event(bool is_add, const char *path)
{ {
SDL_UserEvent e = { SDL_UserEvent e = {
.type = SDL_USEREVENT, .type = SDL_USEREVENT,
.code = (int) is_add, .code = is_add ? OPEN_PACKAGE : REMOVE_LINKS,
.data1 = strdup(path), .data1 = strdup(path),
.data2 = NULL, .data2 = NULL,
}; };