Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FSSync support #17

Merged
merged 4 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cli/ndb_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ void NDBCli::connectSignals() {
NDBCLI_SIG_CONNECT(dlgConfirmTextInput, handleSignalParam1);
NDBCLI_SIG_CONNECT(pfmAboutToConnect, handleSignalParam0);
NDBCLI_SIG_CONNECT(pfmDoneProcessing, handleSignalParam0);
NDBCLI_SIG_CONNECT(fssFinished, handleSignalParam0);
NDBCLI_SIG_CONNECT(fssGotNumFilesToProcess, handleSignalParam1);
NDBCLI_SIG_CONNECT(fssParseProgress, handleSignalParam1);
NDBCLI_SIG_CONNECT(wmLinkQualityForConnectedNetwork, handleSignalParam1);
NDBCLI_SIG_CONNECT(wmMacAddressAvailable, handleSignalParam1);
NDBCLI_SIG_CONNECT(wmNetworkConnected, handleSignalParam0);
Expand Down
69 changes: 69 additions & 0 deletions src/ndb/NDBDbus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ NDBDbus::NDBDbus(QObject* parent) : QObject(parent), QDBusContext() {
// Resolve the rest of the Nickel symbols up-front
// PlugWorkFlowManager
NDB_RESOLVE_SYMBOL("_ZN19PlugWorkflowManager14sharedInstanceEv", nh_symoutptr(nSym.PlugWorkflowManager_sharedInstance));
// N3FSSyncManager
NDB_RESOLVE_SYMBOL("_ZN15N3FSSyncManager14sharedInstanceEv", nh_symoutptr(nSym.N3FSSyncManager__sharedInstance));
NDB_RESOLVE_SYMBOL("_ZN15N3FSSyncManager4syncERK11QStringList", nh_symoutptr(nSym.N3FSSyncManager__sync));
// WirelessManager
NDB_RESOLVE_SYMBOL("_ZN15WirelessManager14sharedInstanceEv", nh_symoutptr(nSym.WirelesManager_sharedInstance));
// Toast
Expand Down Expand Up @@ -713,6 +716,72 @@ void NDBDbus::pfmRescanBooksFull() {
return ndbNickelMisc("rescan_books_full");
}

/*!
* \brief Begins a filesystem sync to add/remove content from onboard storage
*
* This is a more targeted option to add new content compared to \l pfmRescanBooks
* and \l pfmRescanBooksFull. It is what the browser uses when downloading
* ebook files.
*
* Emits \l fssGotNumFilesToProcess signal to specify the number of files
* to be added, \l fssParseProgress to specify the current progress, and the
* \l fssFinished signal is emitted when complete.
*
* \since 0.3.0
*/
void NDBDbus::n3fssSyncOnboard() {
QStringList path("/mnt/onboard");
return n3fssSync(&path);
}

/*!
* \brief Begins a filesystem sync to add/remove content from sd storage
*
* This is a more targeted option to add new content compared to \l pfmRescanBooks
* and \l pfmRescanBooksFull. It is what the browser uses when downloading
* ebook files.
*
* Emits \l fssGotNumFilesToProcess signal to specify the number of files
* to be added, \l fssParseProgress to specify the current progress, and the
* \l fssFinished signal is emitted when complete.
*
* \since 0.3.0
*/
void NDBDbus::n3fssSyncSD() {
QStringList path("/mnt/sd");
return n3fssSync(&path);
}

/*!
* \brief Begins a filesystem sync to add/remove content from onboard and sd storage
*
* This is a more targeted option to add new content compared to \l pfmRescanBooks
* and \l pfmRescanBooksFull. It is what the browser uses when downloading
* ebook files.
*
* Emits \l fssGotNumFilesToProcess signal to specify the number of files
* to be added, \l fssParseProgress to specify the current progress, and the
* \l fssFinished signal is emitted when complete.
*
* \since 0.3.0
*/
void NDBDbus::n3fssSyncBoth() {
QStringList paths = QStringList() << "/mnt/onboard" << "/mnt/sd";
return n3fssSync(&paths);
}

void NDBDbus::n3fssSync(QStringList* paths) {
NDB_DBUS_USB_ASSERT((void) 0);
NDB_DBUS_ASSERT((void) 0, QDBusError::InternalError,
nSym.N3FSSyncManager__sharedInstance && nSym.N3FSSyncManager__sync, "no N3FSSyncManager symbols");
N3FSSyncManager* n3fssm = nSym.N3FSSyncManager__sharedInstance();
NDB_DBUS_ASSERT((void) 0, QDBusError::InternalError, n3fssm, "could not get N3FSSyncManager::sharedInstance()");
QObject::connect(n3fssm, SIGNAL(finished()), this, SIGNAL(fssFinished()), Qt::UniqueConnection);
QObject::connect(n3fssm, SIGNAL(gotNumFilesToProcess(int)), this, SIGNAL(fssGotNumFilesToProcess(int)), Qt::UniqueConnection);
QObject::connect(n3fssm, SIGNAL(parseProgress(int)), this, SIGNAL(fssParseProgress(int)), Qt::UniqueConnection);
return nSym.N3FSSyncManager__sync(n3fssm, paths);
}

void NDBDbus::ndbNickelMisc(const char *action) {
nm_action_result_t *res = nm_action_nickel_misc(action);
if (!res) {
Expand Down
13 changes: 13 additions & 0 deletions src/ndb/NDBDbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ typedef void MainWindowController;
typedef QDialog ConfirmationDialog;
typedef QWidget N3Dialog;
typedef void Device;
typedef QObject FSSyncManager;
typedef FSSyncManager N3FSSyncManager;

#ifndef NDB_DBUS_IFACE_NAME
#define NDB_DBUS_IFACE_NAME "com.github.shermp.nickeldbus"
Expand Down Expand Up @@ -48,6 +50,10 @@ class NDBDbus : public QObject, protected QDBusContext {
// PlugworkFlowManager signals
void pfmDoneProcessing();
void pfmAboutToConnect();
// FSSyncManager signals
void fssFinished();
void fssGotNumFilesToProcess(int num);
void fssParseProgress(int progress);
// WirelessManager signals
void wmTryingToConnect();
void wmNetworkConnected();
Expand Down Expand Up @@ -94,6 +100,10 @@ class NDBDbus : public QObject, protected QDBusContext {
// PlugWorkFlowManager
void pfmRescanBooks();
void pfmRescanBooksFull();
// N3FSSyncManager
void n3fssSyncOnboard();
void n3fssSyncSD();
void n3fssSyncBoth();
// Wireless methods (WirelessFlowManager)
void wfmConnectWireless();
void wfmConnectWirelessSilently();
Expand Down Expand Up @@ -138,6 +148,8 @@ class NDBDbus : public QObject, protected QDBusContext {
Device *(*Device__getCurrentDevice)();
QByteArray (*Device__userAgent)(Device*);
QSize (*Image__sizeForType)(Device*, QString const&);
N3FSSyncManager* (*N3FSSyncManager__sharedInstance)();
void (*N3FSSyncManager__sync)(N3FSSyncManager* _this, QStringList* paths);
} nSym;
QTimer *viewTimer;
bool ndbInUSBMS();
Expand All @@ -152,6 +164,7 @@ class NDBDbus : public QObject, protected QDBusContext {
void rvConnectSignals(QWidget* rv);
void dlgConfirmLineEditFull(QString const& title, QString const& acceptText, QString const& rejectText, bool isPassword, QString const& setText);
enum Result dlgConfirmCreatePreset(QString const& title, QString const& body, QString const& acceptText, QString const& rejectText);
void n3fssSync(QStringList* paths);
};

} // namespace NDB
Expand Down