update PB library only if item is book

pull/23/head
JuanJakobo 2021-06-06 14:43:58 +02:00
parent 8c7dd3e8ae
commit b8361eecce
6 changed files with 50 additions and 16 deletions

View File

@ -169,8 +169,8 @@ void EventHandler::contextMenuHandler(const int index)
OpenProgressbar(1, "Removing...", "Removing Files.", 0, EventHandler::DialogHandlerStatic); OpenProgressbar(1, "Removing...", "Removing Files.", 0, EventHandler::DialogHandlerStatic);
if (_nextcloud.removeItem(_tempItemID)) if (_nextcloud.removeItem(_tempItemID))
{ {
updatePBLibrary();
_listView->drawEntry(_tempItemID); _listView->drawEntry(_tempItemID);
Util::updatePBLibrary();
} }
else else
{ {
@ -267,6 +267,19 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
return 0; return 0;
} }
void EventHandler::updatePBLibrary()
{
if (_nextcloud.getItems().at(_tempItemID).getType() == Itemtype::IFOLDER)
{
Util::updatePBLibrary(15);
}
else
{
if (_nextcloud.getItems().at(_tempItemID).isBook())
Util::updatePBLibrary(5);
}
}
void EventHandler::startDownload() void EventHandler::startDownload()
{ {
if (_nextcloud.isWorkOffline()) if (_nextcloud.isWorkOffline())
@ -286,7 +299,7 @@ void EventHandler::startDownload()
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(); updatePBLibrary();
CloseProgressbar(); CloseProgressbar();
_listView->drawEntry(_tempItemID); _listView->drawEntry(_tempItemID);

View File

@ -86,6 +86,12 @@ private:
*/ */
int pointerHandler(const int type, const int par1, const int par2); int pointerHandler(const int type, const int par1, const int par2);
/**
* Updates PB Library
*
*/
void updatePBLibrary();
/** /**
* Starts the download of an item * Starts the download of an item
* *

View File

@ -62,13 +62,9 @@ Item::Item(const string &localPath, FileState state, Itemtype type) : _localPath
Util::decodeUrl(_title); Util::decodeUrl(_title);
} }
void Item::open() const bool Item::isBook() const
{ {
if(_state==FileState::ICLOUD) if (_fileType.find("application/epub+zip") != string::npos ||
{
Message(ICON_ERROR,"File not found.","Could not find file.",1000);
}
else if (_fileType.find("application/epub+zip") != string::npos ||
_fileType.find("application/pdf") != string::npos || _fileType.find("application/pdf") != string::npos ||
_fileType.find("application/octet-stream") != string::npos || _fileType.find("application/octet-stream") != string::npos ||
_fileType.find("text/plain") != string::npos || _fileType.find("text/plain") != string::npos ||
@ -78,6 +74,17 @@ void Item::open() const
_fileType.find("application/x-mobipocket-ebook") != string::npos || _fileType.find("application/x-mobipocket-ebook") != string::npos ||
_fileType.find("application/vnd.openxmlformats-officedocument.wordprocessingml.document") != string::npos || _fileType.find("application/vnd.openxmlformats-officedocument.wordprocessingml.document") != string::npos ||
_fileType.find("application/x-fictionbook+xml") != string::npos) _fileType.find("application/x-fictionbook+xml") != string::npos)
return true;
return false;
}
void Item::open() const
{
if (_state == FileState::ICLOUD)
{
Message(ICON_ERROR, "File not found.", "Could not find file.", 1000);
}
else if(isBook())
{ {
OpenBook(_localPath.c_str(), "", 0); OpenBook(_localPath.c_str(), "", 0);

View File

@ -46,6 +46,12 @@ public:
*/ */
Item(const std::string &localPath, FileState state, Itemtype type); Item(const std::string &localPath, FileState state, Itemtype type);
/**
* Checks if item is a book
*/
bool isBook() const;
/** /**
* Tries to open the item by checking the file format and then executes the fitting action * Tries to open the item by checking the file format and then executes the fitting action
*/ */

View File

@ -7,17 +7,18 @@
//------------------------------------------------------------------- //-------------------------------------------------------------------
#include "util.h" #include "util.h"
#include "inkview.h" #include "inkview.h"
#include "log.h"
#include <string> #include <string>
#include <math.h> #include <math.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <tuple> #include <tuple>
#include <signal.h> #include <signal.h>
pid_t child_pid = -1; //Global 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)
@ -89,8 +90,8 @@ void Util::decodeUrl(string &text)
char *buffer; char *buffer;
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
buffer = curl_easy_unescape(curl,text.c_str(),0,NULL); buffer = curl_easy_unescape(curl, text.c_str(), 0, NULL);
text = buffer; text = buffer;
curl_free(buffer); curl_free(buffer);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
@ -102,23 +103,24 @@ void kill_child(int sig)
kill(child_pid, SIGTERM); kill(child_pid, SIGTERM);
} }
void Util::updatePBLibrary() void Util::updatePBLibrary(int seconds)
{ {
//TODO how determine time? UpdateProgressbar("Updating PB library", 99);
UpdateProgressbar("Updating PB library", 50);
//https://stackoverflow.com/questions/6501522/how-to-kill-a-child-process-by-the-parent-process //https://stackoverflow.com/questions/6501522/how-to-kill-a-child-process-by-the-parent-process
signal(SIGALRM, (void (*)(int))kill_child); signal(SIGALRM, (void (*)(int))kill_child);
child_pid = fork(); child_pid = fork();
if (child_pid > 0) if (child_pid > 0)
{ {
//parent //parent
alarm(5); alarm(seconds);
wait(NULL); wait(NULL);
} }
else if (child_pid == 0) else if (child_pid == 0)
{ {
//child //child
string cmd = "/ebrmain/bin/scanner.app"; string cmd = "/ebrmain/bin/scanner.app";
//TODO parse in response of exec to determine when to kill?
execlp(cmd.c_str(), cmd.c_str(), (char *)NULL); execlp(cmd.c_str(), cmd.c_str(), (char *)NULL);
exit(1);
} }
} }

View File

@ -57,7 +57,7 @@ public:
* Updates the library of the Pocketbook * Updates the library of the Pocketbook
* *
*/ */
static void updatePBLibrary(); static void updatePBLibrary(int seconds);
private: private:
Util() {} Util() {}