1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-06-28 12:39:50 +03:00

Add a MediaMonitor, which will watch CARD_ROOT for mountpoints

Each time a directory will appear in CARD_ROOT, the MediaMonitor
will try to load all OPKs found in CARD_ROOT/${directory}/apps
This commit is contained in:
Paul Cercueil 2013-07-19 12:37:56 -04:00
parent 69b9657af4
commit 41e4cff7ac
6 changed files with 71 additions and 3 deletions

View File

@ -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@

View File

@ -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() {

View File

@ -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

View File

@ -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;

40
src/mediamonitor.cpp Normal file
View File

@ -0,0 +1,40 @@
#ifdef ENABLE_INOTIFY
#include <sys/inotify.h>
#include <SDL/SDL.h>
#include <unistd.h>
#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 */

18
src/mediamonitor.h Normal file
View File

@ -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__ */