1
0

Implemented some more actions

This commit is contained in:
Patrick Gaskin
2020-04-22 21:00:00 -04:00
parent c113045a71
commit 9d231999a7
4 changed files with 74 additions and 5 deletions

13
res/doc
View File

@@ -32,10 +32,15 @@
# nickel_setting - one of:
# invert - toggles FeatureSettings.InvertScreen (all versions)
# screenshots - toggles FeatureSettings.Screenshots (all versions) (TODO)
# nickel_extras - one of:
# TODO
# nickel_extras - the mimetype of the plugin, or one of:
# web_browser (TODO)
# unblock_it
# sketch_pad
# solitaire
# sudoku
# word_scramble
# misc - one of:
# force_usb_connection - forces a usb connection dialog to be shown (TODO)
# force_usb_connection - forces a usb connection dialog to be shown
# rescan_books - forces nickel to rescan books (TODO)
#
# For example, you might have a configuration file in KOBOeReader/.adds/nmi/mystuff like:
@@ -43,6 +48,8 @@
# menu_item :main :Show an error :dbg_error :This is an error message!
# menu_item :reader :Invert Screen :nickel_setting :invert
#
# You will need to reboot to see any changes.
#
# If there is a error in the configuration, an item which displays it will be
# added to the main menu. If an internal error occurs, it is written to syslog,
# which can be viewed over telnet or SSH (the username is root) with the command

View File

@@ -1,7 +1,9 @@
#include <alloca.h>
#include <dlfcn.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "action_cc.h"
@@ -9,6 +11,7 @@
typedef void Device;
typedef void Settings;
typedef void PlugWorkflowManager;
extern "C" int nmi_action_nickelsetting(const char *arg, char **err_out) {
#define NMI_ERR_RET 1
@@ -79,7 +82,7 @@ extern "C" int nmi_action_nickelsetting(const char *arg, char **err_out) {
} else {
// TODO: more settings
Settings_SettingsD(settings);
NMI_RETURN_ERR("unknown setting name");
NMI_RETURN_ERR("unknown setting name '%s'", arg);
}
#undef vtable_ptr
@@ -90,3 +93,60 @@ extern "C" int nmi_action_nickelsetting(const char *arg, char **err_out) {
NMI_RETURN_OK(0);
#undef NMI_ERR_RET
}
extern "C" int nmi_action_nickelextras(const char *arg, char **err_out) {
#define NMI_ERR_RET 1
if (!strcmp(arg, "web_browser")) {
NMI_RETURN_ERR("not implemented yet"); // TODO
}
const char* mimetype;
if (strchr(arg, '/')) mimetype = arg;
else if (!strcmp(arg, "unblock_it")) mimetype = "application/x-games-RushHour";
else if (!strcmp(arg, "sketch_pad")) mimetype = "application/x-games-Scribble";
else if (!strcmp(arg, "solitaire")) mimetype = "application/x-games-Solitaire";
else if (!strcmp(arg, "sudoku")) mimetype = "application/x-games-Sudoku";
else if (!strcmp(arg, "word_scramble")) mimetype = "application/x-games-Boggle";
else NMI_RETURN_ERR("unknown beta feature name or plugin mimetype '%s'", arg);
void (*ExtrasPluginLoader_loadPlugin)(const char*);
reinterpret_cast<void*&>(ExtrasPluginLoader_loadPlugin) = dlsym(RTLD_DEFAULT, "_ZN18ExtrasPluginLoader10loadPluginEPKc");
NMI_ASSERT(ExtrasPluginLoader_loadPlugin, "could not dlsym ExtrasPluginLoader::loadPlugin");
ExtrasPluginLoader_loadPlugin(mimetype);
NMI_RETURN_OK(0);
#undef NMI_ERR_RET
}
extern "C" int nmi_action_nickelmisc(const char *arg, char **err_out) {
#define NMI_ERR_RET 1
if (!strcmp(arg, "rescan_books")) {
PlugWorkflowManager *(*PlugWorkflowManager_sharedInstance)();
reinterpret_cast<void*&>(PlugWorkflowManager_sharedInstance) = dlsym(RTLD_DEFAULT, "_ZN19PlugWorkflowManager14sharedInstanceEv");
NMI_ASSERT(PlugWorkflowManager_sharedInstance, "could not dlsym PlugWorkflowManager::sharedInstance");
void (*PlugWorkflowManager_unplugged)(PlugWorkflowManager*);
reinterpret_cast<void*&>(PlugWorkflowManager_unplugged) = dlsym(RTLD_DEFAULT, "_ZN19PlugWorkflowManager9unpluggedEv");
NMI_ASSERT(PlugWorkflowManager_unplugged, "could not dlsym PlugWorkflowManager::unplugged");
PlugWorkflowManager *wf = PlugWorkflowManager_sharedInstance();
NMI_ASSERT(wf, "could not get shared PlugWorkflowManager pointer");
PlugWorkflowManager_unplugged(wf);
// TODO: finish this up
NMI_RETURN_ERR("not completely implemented yet");
} else if (!strcmp(arg, "force_usb_connection")) {
FILE *nhs;
NMI_ASSERT((nhs = fopen("/tmp/nickel-hardware-status", "w")), "could not open nickel hardware status pipe: %s", strerror(errno));
const char *msg = "usb plug add";
NMI_ASSERT(fputs(msg, nhs) >= 0, "could not write message '%s' to pipe: %s", msg, strerror(errno));
fclose(nhs);
} else {
NMI_RETURN_ERR("unknown action '%s'", arg);
}
NMI_RETURN_OK(0);
#undef NMI_ERR_RET
}

View File

@@ -5,6 +5,8 @@ extern "C" {
#endif
int nmi_action_nickelsetting(const char *arg, char **err_out);
int nmi_action_nickelextras(const char *arg, char **err_out);
int nmi_action_nickelmisc(const char *arg, char **err_out);
#ifdef __cplusplus
}

View File

@@ -90,7 +90,7 @@ extern "C" MenuTextItem* _nmi_menu_hook(void* _this, QMenu* menu, QString const&
NMI_LOG("Item '%s' pressed...", it->lbl);
char *err;
if (it->act(it->arg, &err) && err) {
NMI_LOG("Got error %s, displaying...", err);
NMI_LOG("Got error: '%s', displaying...", err);
ConfirmationDialogFactory_showOKDialog(QString::fromUtf8(it->lbl), QString::fromUtf8(err));
free(err);
return;