update PB library only if item is book
parent
8c7dd3e8ae
commit
b8361eecce
|
@ -169,8 +169,8 @@ void EventHandler::contextMenuHandler(const int index)
|
|||
OpenProgressbar(1, "Removing...", "Removing Files.", 0, EventHandler::DialogHandlerStatic);
|
||||
if (_nextcloud.removeItem(_tempItemID))
|
||||
{
|
||||
updatePBLibrary();
|
||||
_listView->drawEntry(_tempItemID);
|
||||
Util::updatePBLibrary();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -267,6 +267,19 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
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()
|
||||
{
|
||||
if (_nextcloud.isWorkOffline())
|
||||
|
@ -286,7 +299,7 @@ void EventHandler::startDownload()
|
|||
Log::writeLog(e.what());
|
||||
Message(ICON_ERROR, "Error", "Something has gone wrong. Please check the logs. (/system/config/nextcloud/)", 1200);
|
||||
}
|
||||
Util::updatePBLibrary();
|
||||
updatePBLibrary();
|
||||
|
||||
CloseProgressbar();
|
||||
_listView->drawEntry(_tempItemID);
|
||||
|
|
|
@ -86,6 +86,12 @@ private:
|
|||
*/
|
||||
int pointerHandler(const int type, const int par1, const int par2);
|
||||
|
||||
/**
|
||||
* Updates PB Library
|
||||
*
|
||||
*/
|
||||
void updatePBLibrary();
|
||||
|
||||
/**
|
||||
* Starts the download of an item
|
||||
*
|
||||
|
|
|
@ -62,13 +62,9 @@ Item::Item(const string &localPath, FileState state, Itemtype type) : _localPath
|
|||
Util::decodeUrl(_title);
|
||||
}
|
||||
|
||||
void Item::open() const
|
||||
bool Item::isBook() const
|
||||
{
|
||||
if(_state==FileState::ICLOUD)
|
||||
{
|
||||
Message(ICON_ERROR,"File not found.","Could not find file.",1000);
|
||||
}
|
||||
else if (_fileType.find("application/epub+zip") != string::npos ||
|
||||
if (_fileType.find("application/epub+zip") != string::npos ||
|
||||
_fileType.find("application/pdf") != string::npos ||
|
||||
_fileType.find("application/octet-stream") != 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/vnd.openxmlformats-officedocument.wordprocessingml.document") != 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);
|
||||
|
|
|
@ -46,6 +46,12 @@ public:
|
|||
*/
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -7,17 +7,18 @@
|
|||
//-------------------------------------------------------------------
|
||||
#include "util.h"
|
||||
#include "inkview.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <curl/curl.h>
|
||||
#include <tuple>
|
||||
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
pid_t child_pid = -1; //Global
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
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;
|
||||
CURL *curl = curl_easy_init();
|
||||
|
||||
buffer = curl_easy_unescape(curl,text.c_str(),0,NULL);
|
||||
text = buffer;
|
||||
buffer = curl_easy_unescape(curl, text.c_str(), 0, NULL);
|
||||
text = buffer;
|
||||
|
||||
curl_free(buffer);
|
||||
curl_easy_cleanup(curl);
|
||||
|
@ -102,23 +103,24 @@ void kill_child(int sig)
|
|||
kill(child_pid, SIGTERM);
|
||||
}
|
||||
|
||||
void Util::updatePBLibrary()
|
||||
void Util::updatePBLibrary(int seconds)
|
||||
{
|
||||
//TODO how determine time?
|
||||
UpdateProgressbar("Updating PB library", 50);
|
||||
UpdateProgressbar("Updating PB library", 99);
|
||||
//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);
|
||||
alarm(seconds);
|
||||
wait(NULL);
|
||||
}
|
||||
else if (child_pid == 0)
|
||||
{
|
||||
//child
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ public:
|
|||
* Updates the library of the Pocketbook
|
||||
*
|
||||
*/
|
||||
static void updatePBLibrary();
|
||||
static void updatePBLibrary(int seconds);
|
||||
|
||||
private:
|
||||
Util() {}
|
||||
|
|
Loading…
Reference in New Issue