mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 11:30:37 +02: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:
parent
69b9657af4
commit
41e4cff7ac
@ -12,7 +12,7 @@ gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \
|
|||||||
textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
|
textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
|
||||||
utilities.cpp wallpaperdialog.cpp \
|
utilities.cpp wallpaperdialog.cpp \
|
||||||
browsedialog.cpp buttonbox.cpp dialog.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 \
|
noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
|
||||||
filedialog.h filelister.h gmenu2x.h gp2x.h iconbutton.h imagedialog.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 \
|
surfacecollection.h surface.h textdialog.h textmanualdialog.h \
|
||||||
touchscreen.h translator.h utilities.h wallpaperdialog.h \
|
touchscreen.h translator.h utilities.h wallpaperdialog.h \
|
||||||
browsedialog.h buttonbox.h dialog.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@
|
AM_CFLAGS= @CFLAGS@ @SDL_CFLAGS@
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "iconbutton.h"
|
#include "iconbutton.h"
|
||||||
#include "inputdialog.h"
|
#include "inputdialog.h"
|
||||||
#include "linkapp.h"
|
#include "linkapp.h"
|
||||||
|
#include "mediamonitor.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "menusettingbool.h"
|
#include "menusettingbool.h"
|
||||||
#include "menusettingdir.h"
|
#include "menusettingdir.h"
|
||||||
@ -226,6 +227,8 @@ GMenu2X::GMenu2X()
|
|||||||
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
||||||
initMenu();
|
initMenu();
|
||||||
|
|
||||||
|
monitor = new MediaMonitor(CARD_ROOT);
|
||||||
|
|
||||||
if (!fileExists(confStr["wallpaper"])) {
|
if (!fileExists(confStr["wallpaper"])) {
|
||||||
DEBUG("No wallpaper defined; we will take the default one.\n");
|
DEBUG("No wallpaper defined; we will take the default one.\n");
|
||||||
confStr["wallpaper"] = DEFAULT_WALLPAPER_PATH;
|
confStr["wallpaper"] = DEFAULT_WALLPAPER_PATH;
|
||||||
@ -266,6 +269,7 @@ GMenu2X::~GMenu2X() {
|
|||||||
|
|
||||||
delete menu;
|
delete menu;
|
||||||
delete font;
|
delete font;
|
||||||
|
delete monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu2X::quit() {
|
void GMenu2X::quit() {
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
class ASFont;
|
class ASFont;
|
||||||
class Button;
|
class Button;
|
||||||
|
class MediaMonitor;
|
||||||
class Menu;
|
class Menu;
|
||||||
class Surface;
|
class Surface;
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ class GMenu2X {
|
|||||||
private:
|
private:
|
||||||
Touchscreen ts;
|
Touchscreen ts;
|
||||||
Menu *menu;
|
Menu *menu;
|
||||||
|
MediaMonitor *monitor;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Retrieves the free disk space on the sd
|
Retrieves the free disk space on the sd
|
||||||
|
@ -180,8 +180,12 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
|
|||||||
case SDL_USEREVENT:
|
case SDL_USEREVENT:
|
||||||
if (!event.user.code)
|
if (!event.user.code)
|
||||||
menu->removePackageLink((const char *) event.user.data1);
|
menu->removePackageLink((const char *) event.user.data1);
|
||||||
else
|
else if (event.user.code == 1)
|
||||||
menu->openPackage((const char *) event.user.data1);
|
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);
|
free(event.user.data1);
|
||||||
bevent->state = PRESSED;
|
bevent->state = PRESSED;
|
||||||
bevent->button = REPAINT;
|
bevent->button = REPAINT;
|
||||||
|
40
src/mediamonitor.cpp
Normal file
40
src/mediamonitor.cpp
Normal 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
18
src/mediamonitor.h
Normal 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__ */
|
Loading…
Reference in New Issue
Block a user