diff --git a/src/Makefile.am b/src/Makefile.am index 203fabb..a896f34 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,7 @@ gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \ textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \ utilities.cpp wallpaperdialog.cpp \ browsedialog.cpp buttonbox.cpp dialog.cpp \ - imageio.cpp powersaver.cpp monitor.cpp + imageio.cpp powersaver.cpp monitor.cpp mediamonitor.cpp noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \ filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.h \ @@ -25,7 +25,7 @@ noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \ surfacecollection.h surface.h textdialog.h textmanualdialog.h \ touchscreen.h translator.h utilities.h wallpaperdialog.h \ browsedialog.h buttonbox.h dialog.h \ - imageio.h powersaver.h monitor.h + imageio.h powersaver.h monitor.h mediamonitor.h AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@ diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 04e109c..0b5b436 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -29,6 +29,7 @@ #include "iconbutton.h" #include "inputdialog.h" #include "linkapp.h" +#include "mediamonitor.h" #include "menu.h" #include "menusettingbool.h" #include "menusettingdir.h" @@ -226,6 +227,8 @@ GMenu2X::GMenu2X() setSkin(confStr["skin"], !fileExists(confStr["wallpaper"])); initMenu(); + monitor = new MediaMonitor(CARD_ROOT); + if (!fileExists(confStr["wallpaper"])) { DEBUG("No wallpaper defined; we will take the default one.\n"); confStr["wallpaper"] = DEFAULT_WALLPAPER_PATH; @@ -266,6 +269,7 @@ GMenu2X::~GMenu2X() { delete menu; delete font; + delete monitor; } void GMenu2X::quit() { diff --git a/src/gmenu2x.h b/src/gmenu2x.h index 0b50f88..611680f 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -35,6 +35,7 @@ class ASFont; class Button; +class MediaMonitor; class Menu; class Surface; @@ -65,6 +66,7 @@ class GMenu2X { private: Touchscreen ts; Menu *menu; + MediaMonitor *monitor; /*! Retrieves the free disk space on the sd diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 503aa81..2c0471b 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -180,8 +180,12 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) { case SDL_USEREVENT: if (!event.user.code) menu->removePackageLink((const char *) event.user.data1); - else + else if (event.user.code == 1) menu->openPackage((const char *) event.user.data1); + else if (event.user.code == 2) + menu->openPackagesFromDir( + ((string) (const char *) event.user.data1 + + "/apps").c_str()); free(event.user.data1); bevent->state = PRESSED; bevent->button = REPAINT; diff --git a/src/mediamonitor.cpp b/src/mediamonitor.cpp new file mode 100644 index 0000000..90bc1a1 --- /dev/null +++ b/src/mediamonitor.cpp @@ -0,0 +1,40 @@ +#ifdef ENABLE_INOTIFY +#include +#include +#include + +#include "debug.h" +#include "mediamonitor.h" + +MediaMonitor::MediaMonitor(std::string dir) : + Monitor(dir, IN_MOVE | IN_DELETE | IN_CREATE | IN_ONLYDIR) +{ +} + +bool MediaMonitor::event_accepted( + struct inotify_event &event __attribute__((unused))) +{ + return true; +} + +void MediaMonitor::inject_event(bool is_add, const char *path) +{ + SDL_UserEvent e = { + .type = SDL_USEREVENT, + .code = is_add ? 2 : 0, + .data1 = strdup(path), + .data2 = NULL, + }; + + /* Sleep for a bit, to ensure that the media will be mounted + * on the mountpoint before we start looking for OPKs */ + sleep(1); + + DEBUG("MediaMonitor: Injecting event code %i\n", e.code); + + /* Inject an user event, that will be handled as a "repaint" + * event by the InputManager */ + SDL_PushEvent((SDL_Event *) &e); +} + +#endif /* ENABLE_INOTIFY */ diff --git a/src/mediamonitor.h b/src/mediamonitor.h new file mode 100644 index 0000000..a8b79de --- /dev/null +++ b/src/mediamonitor.h @@ -0,0 +1,18 @@ +#ifndef __MEDIAMONITOR_H__ +#define __MEDIAMONITOR_H__ +#ifdef ENABLE_INOTIFY + +#include "monitor.h" + +class MediaMonitor: public Monitor { + public: + MediaMonitor(std::string dir); + virtual ~MediaMonitor() { }; + + private: + virtual bool event_accepted(struct inotify_event &event); + virtual void inject_event(bool is_add, const char *path); +}; + +#endif /* ENABLE_INOTIFY */ +#endif /* __MEDIAMONITOR_H__ */