update PB library after remove or download
parent
4bb4af1412
commit
3e38b821db
|
@ -27,9 +27,6 @@ Download and unzip the file from releases and place the nextcloud.app into the "
|
||||||
To login type the servername (e.g. https://domainname) or the WebDAV URL (e.g. htts://domainname/remote.php/dav/files/UUID) (You can look up the WebDAV URL in the files app->seetings.), Username and Password. You then will be redirected to the root file folder of your nextcloud instance.
|
To login type the servername (e.g. https://domainname) or the WebDAV URL (e.g. htts://domainname/remote.php/dav/files/UUID) (You can look up the WebDAV URL in the files app->seetings.), Username and Password. You then will be redirected to the root file folder of your nextcloud instance.
|
||||||
To download a file, click on it. A synced file can be either opened, synced or removed.
|
To download a file, click on it. A synced file can be either opened, synced or removed.
|
||||||
|
|
||||||
### Known issues
|
|
||||||
* The main menu of the PB shows new books only if it turns into sleep modus. Otherwise the new books can only be opened from the nextcloud applicaton.
|
|
||||||
|
|
||||||
## How to build
|
## How to build
|
||||||
|
|
||||||
First you need to install the basic build tools for linux.
|
First you need to install the basic build tools for linux.
|
||||||
|
|
|
@ -53,6 +53,8 @@ int EventHandler::eventDistributor(const int type, const int par1, const int par
|
||||||
{
|
{
|
||||||
if (ISPOINTEREVENT(type))
|
if (ISPOINTEREVENT(type))
|
||||||
return EventHandler::pointerHandler(type, par1, par2);
|
return EventHandler::pointerHandler(type, par1, par2);
|
||||||
|
else if (ISKEYEVENT(type))
|
||||||
|
return EventHandler::keyHandler(type, par1, par2);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +191,24 @@ void EventHandler::contextMenuHandler(const int index)
|
||||||
|
|
||||||
int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
||||||
{
|
{
|
||||||
if (type == EVT_POINTERDOWN)
|
//long press to open up context menu
|
||||||
|
if (type == EVT_POINTERLONG)
|
||||||
|
{
|
||||||
|
if (_listView != nullptr)
|
||||||
|
{
|
||||||
|
tempItemID = _listView->listClicked(par1, par2);
|
||||||
|
_listView->invertEntryColor(tempItemID);
|
||||||
|
if (tempItemID != -1)
|
||||||
|
{
|
||||||
|
if (_nextcloud.getItems().at(tempItemID).getTitle().compare("...") != 0)
|
||||||
|
{
|
||||||
|
_contextMenu = std::unique_ptr<ContextMenu>(new ContextMenu());
|
||||||
|
_contextMenu->createMenu(par2, _nextcloud.getItems().at(tempItemID).getState(), EventHandler::contextMenuHandlerStatic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == EVT_POINTERUP)
|
||||||
{
|
{
|
||||||
//menu is clicked
|
//menu is clicked
|
||||||
if (IsInRect(par1, par2, _menu.getMenuButtonRect()) == 1)
|
if (IsInRect(par1, par2, _menu.getMenuButtonRect()) == 1)
|
||||||
|
@ -199,88 +218,99 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
||||||
//if listView is shown
|
//if listView is shown
|
||||||
else if (_listView != nullptr)
|
else if (_listView != nullptr)
|
||||||
{
|
{
|
||||||
int itemID = _listView->listClicked(par1, par2);
|
tempItemID = _listView->listClicked(par1, par2);
|
||||||
if (itemID != -1)
|
_listView->invertEntryColor(tempItemID);
|
||||||
|
if (tempItemID != -1)
|
||||||
{
|
{
|
||||||
int dialogResult = 0;
|
if (_nextcloud.getItems().at(tempItemID).getType() == Itemtype::IFOLDER)
|
||||||
if (_nextcloud.getItems().at(itemID).getType() == Itemtype::IFOLDER)
|
|
||||||
{
|
{
|
||||||
if (_nextcloud.getItems().at(itemID).getTitle().compare("...") == 0)
|
openFolder();
|
||||||
{
|
|
||||||
dialogResult = 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to to do?", "Open folder", "Sync Folder", "Cancel");
|
if (_nextcloud.getItems().at(tempItemID).getState() == FileState::ISYNCED || (_nextcloud.isWorkOffline() && _nextcloud.getItems().at(tempItemID).getState() == FileState::IOUTSYNCED))
|
||||||
|
{
|
||||||
|
openItem();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startDownload();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (dialogResult)
|
return 1;
|
||||||
|
}
|
||||||
|
//if loginView is shown
|
||||||
|
else if (_loginView != nullptr)
|
||||||
{
|
{
|
||||||
case 1:
|
if (_loginView->logginClicked(par1, par2) == 2)
|
||||||
FillAreaRect(_menu.getContentRect(), WHITE);
|
{
|
||||||
_menu.drawLoadingScreen();
|
ShowHourglassForce();
|
||||||
|
|
||||||
_tempPath = _nextcloud.getItems().at(itemID).getPath();
|
if (_nextcloud.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword()))
|
||||||
if (!_tempPath.empty())
|
{
|
||||||
_nextcloud.setItems(_nextcloud.getDataStructure(_tempPath));
|
|
||||||
_listView.release();
|
|
||||||
_listView = std::unique_ptr<ListView>(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
_listView = std::unique_ptr<ListView>(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
||||||
_listView->drawHeader(_tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
_loginView.reset();
|
||||||
break;
|
|
||||||
case 2:
|
FullUpdate();
|
||||||
dialogResult = 0;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_nextcloud.getItems().at(itemID).getState() == FileState::ISYNCED || (_nextcloud.isWorkOffline() && _nextcloud.getItems().at(itemID).getState() == FileState::IOUTSYNCED))
|
HideHourglass();
|
||||||
{
|
Log::writeLog("login failed.");
|
||||||
dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to do?", "Open", "Remove", "Cancel");
|
}
|
||||||
|
return 1;
|
||||||
switch (dialogResult)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
_nextcloud.getItems().at(itemID).open();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (!_nextcloud.removeItem(itemID))
|
|
||||||
Message(ICON_WARNING, "Warning", "Could not delete the file, please try again.", 1200);
|
|
||||||
_listView->drawEntry(itemID);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (dialogResult == 0)
|
void EventHandler::startDownload()
|
||||||
{
|
{
|
||||||
if (_nextcloud.isWorkOffline())
|
if (_nextcloud.isWorkOffline())
|
||||||
{
|
{
|
||||||
int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "You are in offline modus. Go back online?", "Yes", "No", "Cancel");
|
int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "You are in offline modus. Go back online?", "Yes", "No", "Cancel");
|
||||||
if (dialogResult == 2 || dialogResult == 3)
|
if (dialogResult == 2 || dialogResult == 3)
|
||||||
return 1;
|
return; // 1;
|
||||||
_nextcloud.switchWorkOffline();
|
_nextcloud.switchWorkOffline();
|
||||||
}
|
}
|
||||||
OpenProgressbar(1, "Downloading...", "Check network connection", 0, EventHandler::DialogHandlerStatic);
|
OpenProgressbar(1, "Downloading...", "Check network connection", 0, EventHandler::DialogHandlerStatic);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_nextcloud.download(itemID);
|
_nextcloud.download(tempItemID);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
Log::writeLog(e.what());
|
Log::writeLog(e.what());
|
||||||
Message(ICON_ERROR, "Error", "Something has gone wrong. Please check the logs. (/system/config/nextcloud/)", 1200);
|
Message(ICON_ERROR, "Error", "Something has gone wrong. Please check the logs. (/system/config/nextcloud/)", 1200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Util::updatePBLibrary();
|
||||||
|
|
||||||
CloseProgressbar();
|
CloseProgressbar();
|
||||||
_listView->drawEntry(itemID);
|
_listView->drawEntry(tempItemID);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventHandler::openItem()
|
||||||
|
{
|
||||||
|
_listView->invertEntryColor(tempItemID);
|
||||||
|
_nextcloud.getItems().at(tempItemID).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventHandler::openFolder()
|
||||||
|
{
|
||||||
|
FillAreaRect(_menu.getContentRect(), WHITE);
|
||||||
|
ShowHourglassForce();
|
||||||
|
|
||||||
|
_tempPath = _nextcloud.getItems().at(tempItemID).getPath();
|
||||||
|
if (!_tempPath.empty())
|
||||||
|
_nextcloud.setItems(_nextcloud.getDataStructure(_tempPath));
|
||||||
|
_listView.release();
|
||||||
|
_listView = std::unique_ptr<ListView>(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
||||||
|
_listView->drawHeader(_tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
||||||
PartialUpdate(_menu.getContentRect()->x, _menu.getContentRect()->y, _menu.getContentRect()->w, _menu.getContentRect()->h);
|
PartialUpdate(_menu.getContentRect()->x, _menu.getContentRect()->y, _menu.getContentRect()->w, _menu.getContentRect()->h);
|
||||||
|
}
|
||||||
|
|
||||||
int EventHandler::keyHandler(const int type, const int par1, const int par2)
|
int EventHandler::keyHandler(const int type, const int par1, const int par2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
MainMenu _menu = MainMenu("Nextcloud");
|
MainMenu _menu = MainMenu("Nextcloud");
|
||||||
Nextcloud _nextcloud = Nextcloud();
|
Nextcloud _nextcloud = Nextcloud();
|
||||||
std::string _tempPath;
|
std::string _tempPath;
|
||||||
|
int tempItemID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function needed to call C function, redirects to real function
|
* Function needed to call C function, redirects to real function
|
||||||
|
@ -85,6 +86,25 @@ private:
|
||||||
*/
|
*/
|
||||||
int pointerHandler(const int type, const int par1, const int par2);
|
int pointerHandler(const int type, const int par1, const int par2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the download of an item
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void startDownload();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void openFolder();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a item
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void openItem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles key Events
|
* Handles key Events
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,6 +13,11 @@
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
pid_t child_pid = -1; //Global
|
||||||
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
size_t Util::writeCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
size_t Util::writeCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
||||||
|
@ -90,3 +95,30 @@ void Util::decodeUrl(string &text)
|
||||||
curl_free(buffer);
|
curl_free(buffer);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kill_child(int sig)
|
||||||
|
{
|
||||||
|
//SIGKILL
|
||||||
|
kill(child_pid, SIGTERM);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Util::updatePBLibrary()
|
||||||
|
{
|
||||||
|
//TODO how determine time?
|
||||||
|
UpdateProgressbar("Updating PB library", 50);
|
||||||
|
//https://stackoverflow.com/questions/6501522/how-to-kill-a-child-process-by-the-parent-process
|
||||||
|
signal(SIGALRM, (void (*)(int))kill_child);
|
||||||
|
child_pid = fork();
|
||||||
|
if (child_pid > 0)
|
||||||
|
{
|
||||||
|
//parent
|
||||||
|
alarm(5);
|
||||||
|
wait(NULL);
|
||||||
|
}
|
||||||
|
else if (child_pid == 0)
|
||||||
|
{
|
||||||
|
//child
|
||||||
|
string cmd = "/ebrmain/bin/scanner.app";
|
||||||
|
execlp(cmd.c_str(), cmd.c_str(), (char *)NULL);
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,6 +53,11 @@ public:
|
||||||
*/
|
*/
|
||||||
static void decodeUrl(std::string &text);
|
static void decodeUrl(std::string &text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the library of the Pocketbook
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void updatePBLibrary();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Util() {}
|
Util() {}
|
||||||
|
|
Loading…
Reference in New Issue