├── screenshots ├── ItemMenu.bmp ├── ListView.bmp ├── MainMenu.bmp └── ContentDialog.bmp ├── .gitignore ├── src ├── api │ ├── model.h │ ├── pocketModel.h │ ├── sqliteConnector.h │ ├── pocket.h │ ├── sqliteConnector.cpp │ └── pocket.cpp ├── ui │ ├── listViewEntry.cpp │ ├── pocketViewEntry.h │ ├── listViewEntry.h │ ├── pocketView.h │ ├── pocketView.cpp │ ├── pocketViewEntry.cpp │ ├── listView.h │ └── listView.cpp ├── util │ ├── log.cpp │ ├── log.h │ ├── util.h │ └── util.cpp ├── handler │ ├── contextMenu.h │ ├── contextMenu.cpp │ ├── mainMenu.h │ ├── mainMenu.cpp │ ├── eventHandler.h │ └── eventHandler.cpp ├── main.cpp └── libs │ └── json │ └── json-forwards.h ├── README.md ├── CMakeLists.txt └── LICENSE /screenshots/ItemMenu.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JuanJakobo/Pocketbook-Read-offline/HEAD/screenshots/ItemMenu.bmp -------------------------------------------------------------------------------- /screenshots/ListView.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JuanJakobo/Pocketbook-Read-offline/HEAD/screenshots/ListView.bmp -------------------------------------------------------------------------------- /screenshots/MainMenu.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JuanJakobo/Pocketbook-Read-offline/HEAD/screenshots/MainMenu.bmp -------------------------------------------------------------------------------- /screenshots/ContentDialog.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JuanJakobo/Pocketbook-Read-offline/HEAD/screenshots/ContentDialog.bmp -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeLists.txt.user 2 | CMakeCache.txt 3 | CMakeFiles 4 | CMakeScripts 5 | Testing 6 | Makefile 7 | cmake_install.cmake 8 | install_manifest.txt 9 | compile_commands.json 10 | CTestTestfile.cmake 11 | _deps 12 | 13 | bin/ 14 | build/ 15 | .vscode/* 16 | *.code-workspace 17 | 18 | tags -------------------------------------------------------------------------------- /src/api/model.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // model.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 23.04.2021 6 | // Description: global model 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef MODEL 10 | #define MODEL 11 | 12 | #include 13 | 14 | struct Entry 15 | { 16 | std::string id; 17 | }; 18 | #endif 19 | -------------------------------------------------------------------------------- /src/ui/listViewEntry.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // hnCommentViewEntry.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "inkview.h" 10 | #include "listViewEntry.h" 11 | 12 | ListViewEntry::ListViewEntry(int page, const irect &rect) : _page(page), _position(rect) 13 | { 14 | } -------------------------------------------------------------------------------- /src/api/pocketModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //------------------------------------------------------------------ 3 | // pocketModel.h 4 | // 5 | // Author: JuanJakobo 6 | // Date: 23.04.2021 7 | // Description: Describes the structure of an pocket item 8 | //------------------------------------------------------------------- 9 | #include "model.h" 10 | 11 | #include 12 | 13 | enum IStatus 14 | { 15 | UNREAD, 16 | ARCHIVED, 17 | TODELETE 18 | }; 19 | 20 | enum PIsDownloaded 21 | { 22 | PNOTDOWNLOADED, 23 | PDOWNLOADED, 24 | PINVALID 25 | }; 26 | 27 | struct PocketItem : Entry 28 | { 29 | std::string title; 30 | IStatus status; 31 | std::string url; 32 | std::string excerpt; 33 | std::string path; 34 | int reading_time; // in min 35 | bool starred; 36 | PIsDownloaded downloaded{PIsDownloaded::PNOTDOWNLOADED}; 37 | }; 38 | -------------------------------------------------------------------------------- /src/util/log.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // log.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "log.h" 10 | #include "eventHandler.h" 11 | #include "inkview.h" 12 | 13 | #include 14 | #include 15 | 16 | void Log::writeInfoLog(const std::string &text) 17 | { 18 | writeLog("Info:" + text); 19 | } 20 | 21 | void Log::writeErrorLog(const std::string &text) 22 | { 23 | writeLog("Error:" + text); 24 | } 25 | 26 | void Log::writeLog(const std::string &text) 27 | { 28 | std::ofstream log(CONFIG_FOLDER + std::string("/logfile.txt"), std::ios_base::app | std::ios_base::out); 29 | 30 | time_t rawtime; 31 | struct tm *timeinfo; 32 | char buffer[80]; 33 | 34 | time(&rawtime); 35 | timeinfo = localtime(&rawtime); 36 | 37 | strftime(buffer, sizeof(buffer), "%d/%b/%Y:%H:%M:%S %z", timeinfo); 38 | 39 | log << buffer << ':' << text << "\n"; 40 | 41 | log.close(); 42 | } 43 | -------------------------------------------------------------------------------- /src/util/log.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // log.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 05.08.2020 6 | // Description: Deals with log entries 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef LOG 10 | #define LOG 11 | 12 | #include 13 | 14 | class Log 15 | { 16 | public: 17 | /** 18 | * Writes a error log entry to the log file 19 | * 20 | * @param text that shall be written to the log 21 | */ 22 | static void writeErrorLog(const std::string &text); 23 | 24 | /** 25 | * Writes a info log entry to the log file 26 | * 27 | * @param text that shall be written to the log 28 | */ 29 | static void writeInfoLog(const std::string &text); 30 | 31 | private: 32 | Log() {} 33 | 34 | /** 35 | * Writes a log entry to the log file 36 | * 37 | * @param text that shall be written to the log 38 | */ 39 | static void writeLog(const std::string &text); 40 | }; 41 | #endif 42 | -------------------------------------------------------------------------------- /src/handler/contextMenu.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // contextMenu.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 14.06.2020 6 | // Description: Handles the menubar and the menu 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef CONTEXT_MENU 10 | #define CONTEXT_MENU 11 | 12 | #include "inkview.h" 13 | #include "pocketModel.h" 14 | 15 | #include 16 | 17 | class ContextMenu 18 | { 19 | public: 20 | ContextMenu(); 21 | 22 | ~ContextMenu(); 23 | 24 | /** 25 | * Shows the menu on the screen, lets the user choose menu options and then redirects the handler to the caller 26 | * 27 | * @param y y-coordinate of the item 28 | * @param handler which action does the menu buttons start 29 | * @param item that shall be handled 30 | * @return int returns if the event was handled 31 | */ 32 | int createMenu(int y, const iv_menuhandler &handler, const PocketItem &item); 33 | 34 | 35 | private: 36 | char *_menu = strdup("Menu"); 37 | char *_star; 38 | char *_archive; 39 | char *_download; 40 | }; 41 | #endif 42 | -------------------------------------------------------------------------------- /src/ui/pocketViewEntry.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // pocketViewEntry.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // Description: An pocketViewEntry that handles an item of a listview 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef POCKETVIEWENTRY 10 | #define POCKETVIEWENTRY 11 | 12 | #include "listViewEntry.h" 13 | #include "pocketModel.h" 14 | 15 | class PocketViewEntry : public ListViewEntry 16 | { 17 | public: 18 | /** 19 | * Creates an pocketViewEntry 20 | * 21 | * @param Page site of the listView the Entry is shown 22 | * @param Rect area of the screen the item is positioned 23 | * @param entry entry that shall be drawn 24 | */ 25 | PocketViewEntry(int page, const irect &position, const PocketItem &entry); 26 | 27 | /** 28 | * draws the pocketViewEntry to the screen 29 | * 30 | * @param entryFont font for the entry itself 31 | * @param entryFontBold bold font for the header 32 | * @param fontHeight height of the font 33 | */ 34 | void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) override; 35 | 36 | PocketItem *get() override { return &_entry; }; 37 | 38 | private: 39 | PocketItem _entry; 40 | }; 41 | #endif 42 | -------------------------------------------------------------------------------- /src/ui/listViewEntry.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // listViewEntry.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // Description: An listViewEntry that handles an item of a listview 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef LISTVIEWENTRY 10 | #define LISTVIEWENTRY 11 | 12 | #include "inkview.h" 13 | #include "model.h" 14 | 15 | class ListViewEntry 16 | { 17 | public: 18 | /** 19 | * Creates an ListViewEntry 20 | * 21 | * @param Page site of the listView the Entry is shown 22 | * @param Rect area of the screen the item is positioned 23 | */ 24 | ListViewEntry(int page, const irect &position); 25 | 26 | virtual ~ListViewEntry(){}; 27 | 28 | irect *getPosition() { return &_position; } 29 | int getPage() const { return _page; } 30 | 31 | /** 32 | * Draws the listViewEntry to the screen 33 | * 34 | * @param entryFont font for the entry itself 35 | * @param entryFontBold bold font for the header 36 | * @param fontHeight height of the font 37 | */ 38 | virtual void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) = 0; 39 | 40 | virtual Entry* get() = 0; 41 | 42 | protected: 43 | int _page; 44 | irect _position; 45 | }; 46 | #endif -------------------------------------------------------------------------------- /src/ui/pocketView.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // listView.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // Description: An UI class to display items in a listview 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef POCKETVIEW 10 | #define POCKETVIEW 11 | 12 | #include "pocketModel.h" 13 | #include "listView.h" 14 | #include "pocketViewEntry.h" 15 | 16 | #include 17 | #include 18 | 19 | class PocketView final : public ListView 20 | { 21 | public: 22 | /** 23 | * Displays a list view 24 | * 25 | * @param ContentRect area of the screen where the list view is placed 26 | * @param Items items that shall be shown in the listview 27 | * @param page page that is shown, default is 1 28 | */ 29 | PocketView(const irect *contentRect, const std::vector &pocketItems, int page = 1); 30 | 31 | /** 32 | * Gets the current page and returns the itemIds till the page 33 | * 34 | * @return a vector containing the itemIds 35 | */ 36 | std::vector getEntriesTillPage(); 37 | 38 | PocketItem *getCurrentEntry() { return getEntry(_selectedEntry); }; 39 | 40 | PocketItem *getEntry(int entryID) { return std::dynamic_pointer_cast(_entries.at(entryID))->get(); }; 41 | }; 42 | #endif 43 | -------------------------------------------------------------------------------- /src/handler/contextMenu.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // contextMenu.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 14.06.2020 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "contextMenu.h" 10 | #include "inkview.h" 11 | 12 | #include 13 | 14 | ContextMenu::ContextMenu() 15 | { 16 | } 17 | 18 | ContextMenu::~ContextMenu() 19 | { 20 | free(_menu); 21 | free(_star); 22 | free(_download); 23 | free(_archive); 24 | } 25 | 26 | int ContextMenu::createMenu(int y, const iv_menuhandler &handler, const PocketItem &item) 27 | { 28 | std::string text = "Remove item"; 29 | if(item.downloaded == PIsDownloaded::PNOTDOWNLOADED) 30 | text = "Download item"; 31 | _download = strdup(text.c_str()); 32 | 33 | text = "Mark unread"; 34 | if(item.status == IStatus::UNREAD) 35 | text = "Archive"; 36 | _archive = strdup(text.c_str()); 37 | 38 | text = "Star"; 39 | if(item.starred) 40 | text = "Unstar"; 41 | _star = strdup(text.c_str()); 42 | 43 | imenu contextMenu[] = 44 | { 45 | {ITEM_HEADER, 0, _menu, NULL}, 46 | {ITEM_ACTIVE, 101, _download, NULL}, 47 | {ITEM_ACTIVE, 102, _archive, NULL}, 48 | {ITEM_ACTIVE, 103, _star, NULL}, 49 | {0, 0, NULL, NULL}}; 50 | 51 | OpenMenu(contextMenu, 0, ScreenWidth(), y, handler); 52 | 53 | return 1; 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PB Read offline 2 | A basic client to access an pocket instance via a Pocketbook ebook-reader. 3 | 4 |        5 | 6 | ## Features 7 | 8 | * Show Pocket articles the user has stored 9 | * Modify items 10 | * Download articles to read them offline 11 | * Show unread and starred items 12 | * Open content in Pocketbook reader 13 | * Handle everything by touch or keys 14 | 15 | ## Installation 16 | Download and unzip the file from releases and place the Readoffline.app into the "applications" folder of your pocketbook. 17 | Once you disconnect the Pocketbook from the PC, the application should be visibile in the application launcher. 18 | 19 | ## How to build 20 | 21 | First you need to install the basic build tools for linux. 22 | 23 | Then you have to download the Pocketbook SDK (https://github.com/pocketbook/SDK_6.3.0/tree/5.19). 24 | 25 | In the CMakeLists.txt of this project you have to set the root of the TOOLCHAIN_PATH to the location where you saved the SDK. 26 | This could be for example: 27 | 28 | `SET (TOOLCHAIN_PATH "../../SDK/SDK_6.3.0/SDK-B288")` 29 | 30 | Then you have to setup cmake by: 31 | 32 | `cmake .` 33 | 34 | To build the application run: 35 | 36 | `make` 37 | 38 | In the file pocket.h an Consumer_Key has to be added. 39 | 40 | ## Disclamer 41 | Use as your own risk! 42 | Even though the possibility is really low, the application could harm your device or even break it. 43 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // main.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 14.06.2020 6 | // Description: sets the inkview main handler 7 | //------------------------------------------------------------------- 8 | 9 | #include "inkview.h" 10 | #include "eventHandler.h" 11 | #include "log.h" 12 | 13 | EventHandler *events = nullptr; 14 | /** 15 | * Handles events and redirects them 16 | * 17 | * @param type event type 18 | * @param par1 first argument of the event 19 | * @param par2 second argument of the event 20 | * @return int returns if the event was handled 21 | */ 22 | int Inkview_handler(int type, int par1, int par2) 23 | { 24 | switch (type) 25 | { 26 | case EVT_INIT: 27 | { 28 | events = new EventHandler(); 29 | return 1; 30 | break; 31 | } 32 | case EVT_EXIT: 33 | case EVT_HIDE: 34 | { 35 | delete events; 36 | return 1; 37 | break; 38 | } 39 | default: 40 | { 41 | return events->eventDistributor(type, par1, par2); 42 | break; 43 | } 44 | } 45 | return 0; 46 | } 47 | 48 | int main() 49 | { 50 | OpenScreen(); 51 | SetOrientation(0); 52 | 53 | //draw startscreen 54 | auto textHeight = ScreenHeight() / 30; 55 | auto startscreenFont = OpenFont("LiberationMono", textHeight, FONT_BOLD); 56 | SetFont(startscreenFont, BLACK); 57 | DrawTextRect(0, (ScreenHeight() / 3) * 2, ScreenWidth(), textHeight, "Readoffline", ALIGN_CENTER); 58 | CloseFont(startscreenFont); 59 | FullUpdate(); 60 | 61 | InkViewMain(Inkview_handler); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /src/ui/pocketView.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // PocketView.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "pocketView.h" 10 | #include "pocketViewEntry.h" 11 | #include "pocketModel.h" 12 | 13 | #include 14 | #include 15 | 16 | using std::vector; 17 | 18 | PocketView::PocketView(const irect *contentRect, const vector &pocketItems, int page) : ListView(contentRect, page) 19 | { 20 | auto pageHeight = 0; 21 | auto contentHeight = _contentRect->h - _footerHeight; 22 | auto entrycount = pocketItems.size(); 23 | 24 | _entries.reserve(entrycount); 25 | 26 | auto i = 0; 27 | while (i < entrycount) 28 | { 29 | auto entrySize = TextRectHeight(contentRect->w, pocketItems.at(i).title.c_str(), 0) + 2.5 * _entryFontHeight; 30 | 31 | if ((pageHeight + entrySize) > contentHeight) 32 | { 33 | pageHeight = 0; 34 | _page++; 35 | } 36 | irect rect = iRect(_contentRect->x, _contentRect->y + pageHeight, _contentRect->w, entrySize, 0); 37 | 38 | _entries.emplace_back(std::unique_ptr(new PocketViewEntry(_page, rect, pocketItems.at(i)))); 39 | 40 | i++; 41 | pageHeight = pageHeight + entrySize; 42 | } 43 | draw(); 44 | } 45 | 46 | vector PocketView::getEntriesTillPage() 47 | { 48 | std::vector temp; 49 | { 50 | for (size_t i = 0; i < _entries.size(); i++) 51 | { 52 | if (_entries.at(i)->getPage() <= _shownPage) 53 | temp.push_back(getEntry(i)->id); 54 | } 55 | } 56 | return temp; 57 | } 58 | -------------------------------------------------------------------------------- /src/handler/mainMenu.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // mainMenu.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 14.06.2020 6 | // Description: Handles the menubar and the menu 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef MAIN_MENU 10 | #define MAIN_MENU 11 | 12 | #include "inkview.h" 13 | 14 | #include 15 | 16 | class MainMenu 17 | { 18 | public: 19 | /** 20 | * Defines fonds, sets global Event Handler and starts new content 21 | * 22 | * @param name name of the application 23 | */ 24 | MainMenu(const std::string &name); 25 | 26 | ~MainMenu(); 27 | 28 | irect *getContentRect() { return &_contentRect; }; 29 | irect *getMenuButtonRect() { return &_menuButtonRect; }; 30 | 31 | /** 32 | * Shows the menu on the screen, lets the user choose menu options and then redirects the handler to the caller 33 | * 34 | * @param mainView if true mainView will be shown 35 | * @return int returns if the event was handled 36 | */ 37 | int createMenu(bool mainView, const iv_menuhandler &handler); 38 | 39 | private: 40 | ifont *_menuFont; 41 | 42 | int _panelMenuBeginX; 43 | int _panelMenuBeginY; 44 | int _panelMenuHeight; 45 | int _mainMenuWidth; 46 | irect _menuButtonRect; 47 | 48 | imenu _mainMenu; 49 | irect _contentRect; 50 | 51 | char *_menu = strdup("Menu"); 52 | char *_showUnread = strdup("Show unread"); 53 | char *_showStarred = strdup("Show starred"); 54 | char *_showDownloaded = strdup("Show downloaded"); 55 | char *_markAsReadTillPage = strdup("Archive till page"); 56 | char *_info = strdup("Info"); 57 | char *_exit = strdup("Close App"); 58 | 59 | }; 60 | #endif 61 | -------------------------------------------------------------------------------- /src/api/sqliteConnector.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // sqliteConnector.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 18.07.2021 6 | // Description: Interface to store itms in a sqlite db 7 | // 8 | //------------------------------------------------------------------- 9 | 10 | #ifndef SQLITECONNECTOR 11 | #define SQLITECONNECTOR 12 | 13 | #include "sqlite3.h" 14 | #include "pocketModel.h" 15 | 16 | #include 17 | #include 18 | 19 | enum UpdateAction 20 | { 21 | IDOWNLOADED, 22 | ISTATUS, 23 | ISTARRED 24 | }; 25 | 26 | class SqliteConnector 27 | { 28 | public: 29 | /** 30 | * Creates a new database object 31 | * 32 | * @param DBpath the path where the database is placed 33 | */ 34 | SqliteConnector(const std::string &DBpath); 35 | 36 | /** 37 | * Selectes the pocket entries 38 | * 39 | * @return vector of PocketItems that has been received 40 | * 41 | * @param PIsDownloaded the downloaded status of the pocket items 42 | */ 43 | std::vector selectPocketEntries(PIsDownloaded download = PIsDownloaded::PINVALID); 44 | 45 | /** 46 | * Update pocket items in DB 47 | * 48 | * @param the entryID that shall be updates 49 | * @param toUpdate that shall be updated 50 | * @param value the value that shall be written 51 | * 52 | * @return true if updates was succesfull 53 | */ 54 | bool updatePocketItem(const std::string &entryID, int toUpdate, int value); 55 | 56 | /** 57 | * Insert new pocketEntries to the DB 58 | * 59 | * @param entries that shall be inserted 60 | * 61 | * @return true if updates was succesfull 62 | */ 63 | bool insertPocketEntries(const std::vector &entries); 64 | 65 | private: 66 | std::string _dbpath; 67 | sqlite3 *_db; 68 | 69 | /** 70 | * Opens the DB and creates the table if necessary 71 | * 72 | * @return true if was sucessfull 73 | */ 74 | bool open(); 75 | }; 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/ui/pocketViewEntry.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // listViewEntry.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "pocketViewEntry.h" 10 | #include "pocketModel.h" 11 | 12 | #include 13 | 14 | PocketViewEntry::PocketViewEntry(int page, const irect &position, const PocketItem &entry) : ListViewEntry(page, position), _entry(entry) 15 | { 16 | } 17 | 18 | void PocketViewEntry::draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) 19 | { 20 | SetFont(entryFontBold, BLACK); 21 | int heightOfTitle = TextRectHeight(_position.w, _entry.title.c_str(), 0); 22 | DrawTextRect(_position.x, _position.y, _position.w, heightOfTitle, _entry.title.c_str(), ALIGN_LEFT); 23 | 24 | SetFont(entryFont, BLACK); 25 | auto shortendURL = _entry.url; 26 | auto start = 0; 27 | auto counter = 0; 28 | 29 | while ((start = shortendURL.find("/", start)) != std::string::npos && counter < 2) 30 | { 31 | start += 1; 32 | counter++; 33 | } 34 | 35 | shortendURL = shortendURL.substr(0, start); 36 | 37 | DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, shortendURL.c_str(), ALIGN_LEFT); 38 | 39 | std::string textLeft; 40 | if(_entry.downloaded == PIsDownloaded::PDOWNLOADED) 41 | textLeft = "downloaded"; 42 | if (_entry.starred) 43 | { 44 | if(!textLeft.empty()) 45 | textLeft += " || "; 46 | textLeft += "starred"; 47 | } 48 | 49 | DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, textLeft.c_str(), ALIGN_LEFT); 50 | if(_entry.status == IStatus::UNREAD) 51 | textLeft = "unread"; 52 | else 53 | textLeft = "archived"; 54 | DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, textLeft.c_str(), ALIGN_RIGHT); 55 | 56 | if (_entry.reading_time > 0) 57 | DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, (std::to_string(_entry.reading_time) + " min").c_str(), ALIGN_RIGHT); 58 | 59 | int line = (_position.y + _position.h) - 1; 60 | DrawLine(0, line, ScreenWidth(), line, BLACK); 61 | } 62 | -------------------------------------------------------------------------------- /src/handler/mainMenu.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // mainMenu.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 14.06.2020 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "inkview.h" 10 | #include "mainMenu.h" 11 | 12 | #include 13 | 14 | using std::string; 15 | 16 | MainMenu::MainMenu(const string &name) 17 | { 18 | _panelMenuHeight = ScreenHeight() / 18; 19 | _mainMenuWidth = ScreenWidth() / 3; 20 | _panelMenuBeginY = 0; 21 | _panelMenuBeginX = ScreenWidth() - _mainMenuWidth; 22 | 23 | _menuButtonRect = iRect(_mainMenuWidth * 2, _panelMenuBeginY, _mainMenuWidth, _panelMenuHeight, ALIGN_RIGHT); 24 | 25 | _menuFont = OpenFont("LiberationMono-Bold", _panelMenuHeight / 2, FONT_STD); 26 | 27 | SetFont(_menuFont, BLACK); 28 | DrawTextRect(0, _panelMenuBeginY, ScreenWidth(), _panelMenuHeight, name.c_str(), ALIGN_CENTER); 29 | DrawTextRect2(&_menuButtonRect, "Menu"); 30 | DrawLine(0, _panelMenuHeight - 1, ScreenWidth(), _panelMenuHeight - 1, BLACK); 31 | 32 | _contentRect = iRect(0, _panelMenuHeight, ScreenWidth(), (ScreenHeight() - _panelMenuHeight), 0); 33 | SetPanelType(0); 34 | PartialUpdate(0, _panelMenuBeginY, ScreenWidth(), _panelMenuHeight); 35 | } 36 | 37 | MainMenu::~MainMenu() 38 | { 39 | CloseFont(_menuFont); 40 | free(_menu); 41 | free(_showDownloaded); 42 | free(_showUnread); 43 | free(_showStarred); 44 | free(_markAsReadTillPage); 45 | free(_info); 46 | free(_exit); 47 | } 48 | 49 | int MainMenu::createMenu(bool mainView, const iv_menuhandler &handler) 50 | { 51 | imenu mainMenu[] = 52 | { 53 | {ITEM_HEADER, 0, _menu, NULL}, 54 | {mainView ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 101, _showDownloaded, NULL}, 55 | {mainView ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 102, _showUnread, NULL}, 56 | {mainView ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 103, _showStarred, NULL}, 57 | {mainView ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 104, _markAsReadTillPage, NULL}, 58 | {ITEM_ACTIVE, 105, _info, NULL}, 59 | {ITEM_ACTIVE, 106, _exit, NULL}, 60 | {0, 0, NULL, NULL}}; 61 | 62 | OpenMenu(mainMenu, 0, _panelMenuBeginX, _panelMenuBeginY, handler); 63 | 64 | return 1; 65 | } 66 | -------------------------------------------------------------------------------- /src/util/util.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // util.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // Description: Various utility methods 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef UTIL 10 | #define UTIL 11 | 12 | #include 13 | 14 | enum Action 15 | { 16 | IWriteSecret, 17 | IReadSecret, 18 | IWriteString, 19 | IReadString 20 | }; 21 | 22 | class Util 23 | { 24 | public: 25 | /** 26 | * Handles the return of curl command 27 | * 28 | */ 29 | static size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp); 30 | 31 | /** 32 | * Saves the return of curl command 33 | * 34 | */ 35 | static size_t writeData(void *ptr, size_t size, size_t nmemb, FILE *stream); 36 | 37 | /** 38 | * Checks if a network connection can be established and 39 | * 40 | * @throws error that the network connection could not be established 41 | * 42 | */ 43 | static void connectToNetwork(); 44 | 45 | /** 46 | * Enables the access to the config file 47 | * 48 | * @param actions taht shall be performed 49 | * @param name of the config that shall be read 50 | * @param value that shall be written to the config 51 | * 52 | * @return string that has been found in the config file 53 | */ 54 | static std::string accessConfig(const Action &action, const std::string &name, const std::string &value = std::string()); 55 | 56 | 57 | /** 58 | * Gets the data fom a URL (for example to download a picture) 59 | * 60 | * @param url the url where the data should be downlaoded from 61 | * 62 | * @throws error if the html file cannot be downloaded 63 | * 64 | * @return string the data that have been received from the URL 65 | */ 66 | static std::string getData(const std::string &url); 67 | 68 | /** 69 | * Removes chars that are forbidden in an path 70 | * 71 | * @param string that has to be changed 72 | * @return string that has been adjusted 73 | */ 74 | static std::string clearString(std::string title); 75 | 76 | /** 77 | * Creates an html file, downloades the pictures and saves it to path 78 | * 79 | * @param title the name the html should be saved 80 | * @param content the html content 81 | * 82 | * @return path where the html file is saved to 83 | */ 84 | static std::string createHtml(std::string title, std::string content); 85 | 86 | /** 87 | * Decode an html file and transform html tags 88 | * 89 | * @param data a reference to the data that shall be decoded 90 | */ 91 | static void decodeHTML(std::string &data); 92 | 93 | /** 94 | * Replace for a string all data with an other string 95 | * 96 | * @param data the complete text 97 | * @param replace text that should be replaced 98 | * @param by text by that the text should be replaced 99 | */ 100 | static void replaceAll(std::string &data, const std::string &replace, const std::string &by); 101 | 102 | private: 103 | Util() {} 104 | }; 105 | #endif 106 | -------------------------------------------------------------------------------- /src/api/pocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //------------------------------------------------------------------ 3 | // pocket.h 4 | // 5 | // Author: JuanJakobo 6 | // Date: 22.04.2021 7 | // Description: Interface to the pocket API 8 | // 9 | //------------------------------------------------------------------- 10 | #include "pocketModel.h" 11 | #include "json/json.h" 12 | 13 | #include 14 | #include 15 | 16 | enum class PocketAction 17 | { 18 | ADD, // Add a new item 19 | ARCHIVE, // Move an item to the archive 20 | READD, // Unarchive an item 21 | FAVORITE, // Mark an item as favorite 22 | UNFAVORITE, // unfavorite an item 23 | DELETE // permanently remove an item 24 | }; 25 | 26 | 27 | class Pocket 28 | { 29 | public: 30 | /** 31 | * Creates a new pocket object containing token to access the api 32 | * 33 | */ 34 | Pocket(); 35 | 36 | /** 37 | * Adds an URL to pocket 38 | * If multiple URLs shall be added modify should be used 39 | * 40 | * @param url that shall be added to pocket 41 | */ 42 | void addItems(const std::string &url); 43 | 44 | /** 45 | * Retrieve a Users Pocket Data 46 | * 47 | * @return vector of PocketItems that has been received 48 | */ 49 | std::vector getItems(); 50 | 51 | /** 52 | * Gets the text and images, creates an html out of it and stores the path inside the item 53 | * 54 | * @param item for that the text shall be downloaded 55 | */ 56 | void getText(PocketItem *item); 57 | 58 | /** 59 | * Modify a Users Pocket Data 60 | * 61 | * @param action that shall be performed 62 | * @param ids the ids that shall be modified 63 | */ 64 | void sendItems(PocketAction action, const std::vector &ids); 65 | 66 | /** 67 | * Modify a single item 68 | * 69 | * @param action that shall be performed 70 | * @param id the id that shall be modified 71 | */ 72 | void sendItem(PocketAction action, const std::string &id); 73 | 74 | private: 75 | std::string _accessToken; 76 | 77 | /** 78 | * Opens the login dialog 79 | */ 80 | void loginDialog(); 81 | 82 | /** 83 | * Get the code to start the login process 84 | * 85 | * @return the code that has been received 86 | */ 87 | std::string getCode(); 88 | 89 | /** 90 | * Receives the AccessToken and the username and stores these 91 | * 92 | * @param the code that has been received from the net 93 | */ 94 | void getAccessToken(const std::string &code); 95 | 96 | /** 97 | * Determines the action from the enum 98 | * 99 | * @param receivces the action enum 100 | * 101 | * @returns the action as string 102 | */ 103 | std::string determineAction(PocketAction action); 104 | 105 | /** 106 | * Accesses the Pocketapi and returns the result as a json 107 | * 108 | * @param apiEndpoint the endpoint that shall be accessed 109 | * @param data the post data 110 | * 111 | * @return the result as a json 112 | */ 113 | Json::Value post(const std::string &apiEndpoint, const std::string &data); 114 | }; 115 | -------------------------------------------------------------------------------- /src/ui/listView.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // listView.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // Description: An UI class to display items in a listview 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef LISTVIEW 10 | #define LISTVIEW 11 | 12 | #include "listViewEntry.h" 13 | #include "model.h" 14 | 15 | #include 16 | #include 17 | 18 | class ListView 19 | { 20 | public: 21 | /** 22 | * Displays a list view 23 | * 24 | * @param ContentRect area of the screen where the list view is placed 25 | * @param Items items that shall be shown in the listview 26 | */ 27 | ListView(const irect *contentRect, int page); 28 | 29 | virtual ~ListView(); 30 | 31 | //TODO is the usage of the pointer okay? 32 | /** 33 | * returns the clicked entry 34 | * 35 | * @return Entry that has been clicked is returned 36 | */ 37 | virtual Entry *getCurrentEntry() = 0; 38 | 39 | /** 40 | * get the entry with the id 41 | * 42 | * @params entryID 43 | * 44 | * @return Entry that has been clicked 45 | */ 46 | virtual Entry *getEntry(int entryID) = 0; 47 | 48 | /** 49 | * returns the number of the currently displayed page 50 | * 51 | * @return the number of the page 52 | */ 53 | int getShownPage(){return _shownPage;}; 54 | 55 | /** 56 | * Navigates to the next page 57 | */ 58 | void nextPage() { this->actualizePage(_shownPage + 1); }; 59 | 60 | /** 61 | * Navigates to the prev page 62 | */ 63 | void prevPage() { this->actualizePage(_shownPage - 1); }; 64 | 65 | /** 66 | * Navigates to first page 67 | */ 68 | void firstPage() { this->actualizePage(1); }; 69 | 70 | /** 71 | * Redraws the currently selected entry to the screen 72 | */ 73 | void reDrawCurrentEntry(); 74 | 75 | /** 76 | * Inverts the color of the currently selected entry 77 | */ 78 | void invertCurrentEntryColor(); 79 | 80 | /** 81 | * Checkes if the listview has been clicked and either changes the page or returns item ID 82 | * 83 | * @param x x-coordinate 84 | * @param y y-coordinate 85 | * @return true if was clicked 86 | */ 87 | bool checkIfEntryClicked(int x, int y); 88 | 89 | /** 90 | * Returns the current Entry Iterator 91 | * 92 | * @return the current Entry Iterator 93 | */ 94 | int getCurrentEntryItertator() const {return _selectedEntry;}; 95 | 96 | /** 97 | * Clears the screen and draws entries and footer 98 | * 99 | */ 100 | void draw(); 101 | 102 | protected: 103 | int _footerHeight; 104 | int _footerFontHeight; 105 | int _entryFontHeight; 106 | const irect *_contentRect; 107 | std::vector> _entries; 108 | ifont *_footerFont; 109 | ifont *_entryFont; 110 | ifont *_entryFontBold; 111 | int _page = 1; 112 | int _shownPage; 113 | irect _pageIcon; 114 | irect _nextPageButton; 115 | irect _prevPageButton; 116 | irect _firstPageButton; 117 | irect _lastPageButton; 118 | int _selectedEntry; 119 | 120 | 121 | /** 122 | * Iterates through the items and sends them to the listViewEntry Class for drawing 123 | */ 124 | void drawEntries(); 125 | 126 | /** 127 | * Draws the footer including a page changer 128 | */ 129 | void drawFooter(); 130 | 131 | /** 132 | * Updates an entry 133 | * 134 | * @param entryID the id of the item that shall be inverted 135 | */ 136 | void updateEntry(int entryID); 137 | 138 | /** 139 | * Navigates to the selected page 140 | * 141 | * @param pageToShow page that shall be shown 142 | */ 143 | void actualizePage(int pageToShow); 144 | }; 145 | #endif 146 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED (VERSION 3.10.1) 2 | 3 | PROJECT (Readofflinebook-Readoffline VERSION 0.2) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | 7 | include(FetchContent) 8 | 9 | set(CMAKE_SYSTEM_NAME Linux) 10 | set(CMAKE_SYSTEM_VERSION 1.0) 11 | set(CMAKE_SYSTEM_PROCESSOR armv7a) 12 | set(BUILD_SHARED_LIBS ON) 13 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 14 | 15 | SET (TOOLCHAIN_PATH "../../SDK/SDK_6.3.0/SDK-B288") 16 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 17 | 18 | set(CMAKE_FIND_ROOT_PATH "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/") 19 | set(CMAKE_INCLUDE_PATH "/usr/include") 20 | message("CMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH}") 21 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 24 | include_directories("${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/include/freetype2") 25 | list(APPEND CMAKE_MODULE_PATH "${TOOLCHAIN_PATH}/usr/share/cmake/modules") 26 | list(REMOVE_DUPLICATES CMAKE_MODULE_PATH) 27 | set(QT_QMAKE_EXECUTABLE "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/qt5/bin/qmake") 28 | set(CMAKE_PREFIX_PATH "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/ebrmain/lib/cmake") 29 | 30 | set(CMAKE_C_COMPILER "${TOOLCHAIN_PATH}/usr/bin/arm-obreey-linux-gnueabi-clang") 31 | set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PATH}/usr/bin/arm-obreey-linux-gnueabi-clang++") 32 | set(CMAKE_C_FLAGS "-fsigned-char -Werror-return-type" CACHE STRING "" FORCE) 33 | set(CMAKE_CXX_FLAGS "-fsigned-char -Werror-return-type" CACHE STRING "" FORCE) 34 | set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O2 -pipe -fomit-frame-pointer -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp " CACHE STRING "" FORCE) 35 | set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2 -pipe -fomit-frame-pointer -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp " CACHE STRING "" FORCE) 36 | set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -O0 -g -pipe -fomit-frame-pointer -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp " CACHE STRING "" FORCE) 37 | set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -O0 -g -pipe -fomit-frame-pointer -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp " CACHE STRING "" FORCE) 38 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" CACHE STRING "" FORCE) 39 | set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "-s" CACHE STRING "" FORCE) 40 | set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,defs" CACHE STRING "" FORCE) 41 | 42 | add_definitions(-DPLATFORM_FC) 43 | set(PB_PLATFORM "ARM" CACHE STRING "ARM|PC Readonly!") 44 | 45 | set(CMAKE_INSTALL_PREFIX "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/local" CACHE PATH "Installation Prefix") 46 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Debug|Release|RelWithDebInfo|MinSizeRel") 47 | set(ENV{PKG_CONFIG_DIR} "") 48 | set(ENV{PKG_CONFIG_LIBDIR} ${CMAKE_FIND_ROOT_PATH}/usr/lib/pkgconfig) 49 | set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_FIND_ROOT_PATH}) 50 | set(ENV{LD_LIBRARY_PATH} ${TOOLCHAIN_PATH}/usr/lib) 51 | list(APPEND PB_LINK_DIRECTORIES "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/lib") 52 | list(APPEND PB_LINK_DIRECTORIES "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/local/lib") 53 | list(APPEND PB_INCLUDE_DIRECTORIES "${TOOLCHAIN_PATH}/usr/arm-obreey-linux-gnueabi/sysroot/usr/include") 54 | 55 | 56 | set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp 57 | ${CMAKE_SOURCE_DIR}/src/handler/eventHandler.cpp 58 | ${CMAKE_SOURCE_DIR}/src/handler/contextMenu.cpp 59 | ${CMAKE_SOURCE_DIR}/src/handler/mainMenu.cpp 60 | ${CMAKE_SOURCE_DIR}/src/api/pocket.cpp 61 | ${CMAKE_SOURCE_DIR}/src/api/sqliteConnector.cpp 62 | ${CMAKE_SOURCE_DIR}/src/ui/listView.cpp 63 | ${CMAKE_SOURCE_DIR}/src/ui/listViewEntry.cpp 64 | ${CMAKE_SOURCE_DIR}/src/ui/pocketView.cpp 65 | ${CMAKE_SOURCE_DIR}/src/ui/pocketViewEntry.cpp 66 | ${CMAKE_SOURCE_DIR}/src/util/util.cpp 67 | ${CMAKE_SOURCE_DIR}/src/util/log.cpp 68 | ${CMAKE_SOURCE_DIR}/src/libs/jsoncpp.cpp 69 | ) 70 | 71 | add_executable(Readoffline.app ${SOURCES}) 72 | 73 | include_directories( 74 | ${CMAKE_SOURCE_DIR}/src/handler/ 75 | ${CMAKE_SOURCE_DIR}/src/util/ 76 | ${CMAKE_SOURCE_DIR}/src/ui/ 77 | ${CMAKE_SOURCE_DIR}/src/api/ 78 | ${CMAKE_SOURCE_DIR}/src/libs/ 79 | ) 80 | 81 | target_link_libraries(Readoffline.app PRIVATE sqlite3 inkview pthread freetype curl) 82 | 83 | INSTALL (TARGETS Readoffline.app) 84 | -------------------------------------------------------------------------------- /src/handler/eventHandler.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // eventHandler.h 3 | // 4 | // Author: JuanJakobo 5 | // Date: 22.04.2021 6 | // Description: Handles all events and directs them 7 | //------------------------------------------------------------------- 8 | 9 | #ifndef EVENT_HANDLER 10 | #define EVENT_HANDLER 11 | 12 | #include "inkview.h" 13 | 14 | #include "mainMenu.h" 15 | #include "contextMenu.h" 16 | 17 | #include "pocket.h" 18 | #include "pocketModel.h" 19 | #include "pocketView.h" 20 | 21 | #include "sqliteConnector.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | enum Views 29 | { 30 | DEFAULTVIEW, 31 | PKVIEW 32 | }; 33 | 34 | const std::string CONFIG_FOLDER = "/mnt/ext1/system/config/readoffline"; 35 | const std::string CONFIG_PATH = CONFIG_FOLDER + "/readoffline.cfg"; 36 | const std::string ARTICLE_FOLDER = "/mnt/ext1/readoffline"; 37 | const std::string IMAGE_FOLDER = "/mnt/ext1/readoffline/img"; 38 | const std::string DB_PATH = ARTICLE_FOLDER + "/data.db"; 39 | 40 | class EventHandler 41 | { 42 | public: 43 | /** 44 | * Defines fonds, sets global Event Handler and starts new content 45 | */ 46 | EventHandler(); 47 | 48 | ~EventHandler(); 49 | 50 | /** 51 | * Handles events and redirects them 52 | * 53 | * @param type event type 54 | * @param par1 first argument of the event 55 | * @param par2 second argument of the event 56 | * @return int returns if the event was handled 57 | */ 58 | int eventDistributor(const int type, const int par1, const int par2); 59 | 60 | private: 61 | static std::unique_ptr _eventHandlerStatic; 62 | std::unique_ptr _pocketView; 63 | std::vector _items; 64 | std::unique_ptr _pocket; 65 | MainMenu _menu = MainMenu("Readoffline"); 66 | ContextMenu _contextMenu = ContextMenu(); 67 | SqliteConnector _sqliteCon = SqliteConnector(DB_PATH); 68 | Views _currentView; 69 | int _pocketViewShownPage = 1; 70 | 71 | /** 72 | * Function needed to call C function, redirects to real function 73 | * 74 | * @param index int of the menu that is set 75 | */ 76 | static void mainMenuHandlerStatic(const int index); 77 | 78 | /** 79 | * Handles menu events and redirects them 80 | * 81 | * @param index int of the menu that is set 82 | */ 83 | void mainMenuHandler(const int index); 84 | 85 | 86 | /** 87 | * Function needed to call C function, redirects to real function 88 | * 89 | * @param index int of the menu that is set 90 | */ 91 | static void contextMenuHandlerStatic(const int index); 92 | 93 | /** 94 | * Handles context menu events and redirects them 95 | * 96 | * @param index int of the menu that is set 97 | */ 98 | void contextMenuHandler(const int index); 99 | 100 | /** 101 | * Handles pointer Events 102 | * 103 | * @param type event type 104 | * @param par1 first argument of the event 105 | * @param par2 second argument of the event 106 | * @return int returns if the event was handled 107 | */ 108 | int pointerHandler(const int type, const int par1, const int par2); 109 | 110 | /** 111 | * Handles key Events 112 | * 113 | * @param type event type 114 | * @param par1 first argument of the event (is the key) 115 | * @param par2 second argument of the event 116 | * @return int returns if the event was handled 117 | */ 118 | int keyHandler(const int type, const int par1, const int par2); 119 | 120 | 121 | /** 122 | * Draws pocket items to a screen 123 | * 124 | * @param vector of the pocketItems that shall be drawn 125 | * 126 | * @return true if the items could be drawn an the item size is bigger than 0 127 | */ 128 | bool drawPocketItems(const std::vector &pocketItems); 129 | 130 | /** 131 | * 132 | * Draws the pocket items to an ListView 133 | * 134 | * @param status the status of the items 135 | * @param favorited if the favorited should be drawn 136 | * 137 | */ 138 | void filterAndDrawPocket(IStatus status, bool favorited); 139 | 140 | }; 141 | #endif 142 | -------------------------------------------------------------------------------- /src/ui/listView.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // listView.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "inkview.h" 10 | #include "listView.h" 11 | #include "listViewEntry.h" 12 | 13 | #include 14 | #include 15 | 16 | using std::string; 17 | using std::vector; 18 | 19 | ListView::ListView(const irect *contentRect, int page) : _contentRect(contentRect), _shownPage(page) 20 | { 21 | _entries.clear(); 22 | 23 | _footerHeight = _contentRect->h / 15; 24 | _footerFontHeight = 0.3 * _footerHeight; 25 | _entryFontHeight = 30; 26 | 27 | _footerFont = OpenFont("LiberationMono", _footerFontHeight, 1); 28 | _entryFont = OpenFont("LiberationMono", _entryFontHeight, 1); 29 | _entryFontBold = OpenFont("LiberationMono-Bold", _entryFontHeight, 1); 30 | 31 | SetFont(_entryFont, BLACK); 32 | 33 | _pageIcon = iRect(_contentRect->w - 100, _contentRect->h + _contentRect->y - _footerHeight, 100, _footerHeight, ALIGN_CENTER); 34 | _firstPageButton = iRect(_contentRect->x, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER); 35 | _prevPageButton = iRect(_contentRect->x + 150, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER); 36 | _nextPageButton = iRect(_contentRect->x + 300, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER); 37 | _lastPageButton = iRect(_contentRect->x + 450, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER); 38 | } 39 | 40 | ListView::~ListView() 41 | { 42 | CloseFont(_entryFont); 43 | CloseFont(_entryFontBold); 44 | CloseFont(_footerFont); 45 | } 46 | 47 | void ListView::draw() 48 | { 49 | FillAreaRect(_contentRect, WHITE); 50 | drawEntries(); 51 | drawFooter(); 52 | PartialUpdate(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h); 53 | } 54 | 55 | void ListView::reDrawCurrentEntry() 56 | { 57 | FillAreaRect(_entries.at(_selectedEntry)->getPosition(), WHITE); 58 | _entries.at(_selectedEntry)->draw(_entryFont, _entryFontBold, _entryFontHeight); 59 | updateEntry(_selectedEntry); 60 | } 61 | 62 | void ListView::invertCurrentEntryColor() 63 | { 64 | InvertAreaBW(_entries.at(_selectedEntry)->getPosition()->x, _entries.at(_selectedEntry)->getPosition()->y, _entries.at(_selectedEntry)->getPosition()->w, _entries.at(_selectedEntry)->getPosition()->h); 65 | updateEntry(_selectedEntry); 66 | } 67 | 68 | void ListView::drawEntries() 69 | { 70 | for (unsigned int i = 0; i < _entries.size(); i++) 71 | { 72 | if (_entries.at(i)->getPage() == _shownPage) 73 | _entries.at(i)->draw(_entryFont, _entryFontBold, _entryFontHeight); 74 | } 75 | } 76 | 77 | bool ListView::checkIfEntryClicked(int x, int y) 78 | { 79 | if (IsInRect(x, y, &_firstPageButton)) 80 | { 81 | firstPage(); 82 | } 83 | else if (IsInRect(x, y, &_nextPageButton)) 84 | { 85 | nextPage(); 86 | } 87 | else if (IsInRect(x, y, &_prevPageButton)) 88 | { 89 | prevPage(); 90 | } 91 | else if (IsInRect(x, y, &_lastPageButton)) 92 | { 93 | actualizePage(_page); 94 | } 95 | else 96 | { 97 | for (unsigned int i = 0; i < _entries.size(); i++) 98 | { 99 | if (_entries.at(i)->getPage() == _shownPage && IsInRect(x, y, _entries.at(i)->getPosition()) == 1) 100 | { 101 | _selectedEntry = i; 102 | return true; 103 | } 104 | } 105 | } 106 | return false; 107 | } 108 | 109 | void ListView::drawFooter() 110 | { 111 | SetFont(_footerFont, WHITE); 112 | string footer = std::to_string(_shownPage) + "/" + std::to_string(_page); 113 | FillAreaRect(&_pageIcon, BLACK); 114 | 115 | DrawTextRect2(&_pageIcon, footer.c_str()); 116 | FillAreaRect(&_firstPageButton, BLACK); 117 | DrawTextRect2(&_firstPageButton, "First"); 118 | FillAreaRect(&_prevPageButton, BLACK); 119 | DrawTextRect2(&_prevPageButton, "Prev"); 120 | FillAreaRect(&_nextPageButton, BLACK); 121 | DrawTextRect2(&_nextPageButton, "Next"); 122 | FillAreaRect(&_lastPageButton, BLACK); 123 | DrawTextRect2(&_lastPageButton, "Last"); 124 | } 125 | 126 | void ListView::updateEntry(int entryID) 127 | { 128 | PartialUpdate(_entries.at(entryID)->getPosition()->x, _entries.at(entryID)->getPosition()->y, _entries.at(entryID)->getPosition()->w, _entries.at(entryID)->getPosition()->h); 129 | } 130 | 131 | void ListView::actualizePage(int pageToShow) 132 | { 133 | if (pageToShow > _page) 134 | { 135 | Message(ICON_INFORMATION, "Info", "You have reached the last page, to return to the first, please click \"first.\"", 1200); 136 | } 137 | else if (pageToShow < 1) 138 | { 139 | Message(ICON_INFORMATION, "Info", "You are already on the first page.", 1200); 140 | } 141 | else 142 | { 143 | _shownPage = pageToShow; 144 | FillArea(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h, WHITE); 145 | drawEntries(); 146 | drawFooter(); 147 | PartialUpdate(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/api/sqliteConnector.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // sqliteConnector.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 18.07.2021 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "sqlite3.h" 10 | #include "pocketModel.h" 11 | #include "sqliteConnector.h" 12 | #include "log.h" 13 | 14 | #include 15 | #include 16 | 17 | using std::vector; 18 | using std::string; 19 | 20 | SqliteConnector::SqliteConnector(const string &DBpath) : _dbpath(DBpath) 21 | { 22 | } 23 | 24 | vector SqliteConnector::selectPocketEntries(PIsDownloaded downloaded) 25 | { 26 | open(); 27 | int rs; 28 | sqlite3_stmt *stmt = 0; 29 | vector entries; 30 | 31 | if(downloaded == PIsDownloaded::PINVALID) 32 | { 33 | rs = sqlite3_prepare_v2(_db, "SELECT id, status, title, url, excerpt, path, reading_time, starred, downloaded FROM 'PocketItems';", -1, &stmt, 0); 34 | } 35 | else 36 | { 37 | rs = sqlite3_prepare_v2(_db, "SELECT id, status, title, url, excerpt, path, reading_time, starred, downloaded FROM 'PocketItems' WHERE downloaded = ?;", -1, &stmt, 0); 38 | rs = sqlite3_bind_int(stmt, 1, downloaded); 39 | } 40 | 41 | auto test = sqlite3_column_count(stmt); 42 | 43 | while (sqlite3_step(stmt) == SQLITE_ROW) 44 | { 45 | PocketItem temp; 46 | 47 | temp.id = reinterpret_cast(sqlite3_column_text(stmt, 0)); 48 | temp.status = static_cast(sqlite3_column_int(stmt,1)); 49 | temp.title = reinterpret_cast(sqlite3_column_text(stmt, 2)); 50 | temp.url =reinterpret_cast(sqlite3_column_text(stmt, 3)); 51 | temp.excerpt = reinterpret_cast(sqlite3_column_text(stmt, 4)); 52 | temp.path = reinterpret_cast(sqlite3_column_text(stmt, 5)); 53 | temp.reading_time = sqlite3_column_int(stmt, 6); 54 | temp.starred = (sqlite3_column_int(stmt, 7) == 1) ? true : false; 55 | temp.downloaded = static_cast(sqlite3_column_int(stmt,8)); 56 | entries.push_back(temp); 57 | } 58 | sqlite3_finalize(stmt); 59 | sqlite3_close(_db); 60 | return entries; 61 | } 62 | 63 | bool SqliteConnector::updatePocketItem(const string &entryID, int toUpdate, int value) 64 | { 65 | open(); 66 | int rs; 67 | sqlite3_stmt *stmt = 0; 68 | 69 | switch (toUpdate) 70 | { 71 | case UpdateAction::IDOWNLOADED: 72 | { 73 | rs = sqlite3_prepare_v2(_db, "UPDATE 'PocketItems' SET downloaded=? WHERE id=?", -1, &stmt, 0); 74 | rs = sqlite3_bind_int(stmt, 1, value); 75 | break; 76 | } 77 | case UpdateAction::ISTATUS: 78 | { 79 | rs = sqlite3_prepare_v2(_db, "UPDATE 'PocketItems' SET status=? WHERE id=?", -1, &stmt, 0); 80 | rs = sqlite3_bind_int(stmt, 1, value); 81 | break; 82 | } 83 | case UpdateAction::ISTARRED: 84 | { 85 | rs = sqlite3_prepare_v2(_db, "UPDATE 'PocketItems' SET starred=? WHERE id=?", -1, &stmt, 0); 86 | rs = sqlite3_bind_int(stmt, 1, value); 87 | break; 88 | } 89 | } 90 | 91 | rs = sqlite3_bind_text(stmt,2, entryID.c_str(), entryID.length(),NULL); 92 | rs = sqlite3_step(stmt); 93 | 94 | if (rs != SQLITE_DONE) 95 | { 96 | Log::writeErrorLog(sqlite3_errmsg(_db) + std::string(" (Error Code: ") + std::to_string(rs) + ")"); 97 | return false; 98 | } 99 | rs = sqlite3_clear_bindings(stmt); 100 | rs = sqlite3_reset(stmt); 101 | 102 | sqlite3_finalize(stmt); 103 | sqlite3_close(_db); 104 | 105 | return true; 106 | } 107 | 108 | bool SqliteConnector::insertPocketEntries(const std::vector &entries) 109 | { 110 | open(); 111 | int rs; 112 | sqlite3_stmt *stmt = 0; 113 | 114 | rs = sqlite3_prepare_v2(_db, "INSERT INTO 'PocketItems' (id, status, title, url, excerpt, path, reading_time, starred, downloaded) VALUES (?,?,?,?,?,?,?,?,?);", -1, &stmt, 0); 115 | rs = sqlite3_exec(_db, "BEGIN TRANSACTION;", NULL, NULL, NULL); 116 | 117 | for (auto ent : entries) 118 | { 119 | rs = sqlite3_bind_text(stmt, 1, ent.id.c_str(), ent.id.length(),NULL); 120 | rs = sqlite3_bind_int(stmt, 2, ent.status); 121 | rs = sqlite3_bind_text(stmt, 3, ent.title.c_str(), ent.title.length(), NULL); 122 | rs = sqlite3_bind_text(stmt, 4, ent.url.c_str(), ent.url.length(), NULL); 123 | rs = sqlite3_bind_text(stmt, 5, ent.excerpt.c_str(), ent.excerpt.length(), NULL); 124 | rs = sqlite3_bind_text(stmt, 6, ent.path.c_str(), ent.path.length(), NULL); 125 | rs = sqlite3_bind_int(stmt, 7, ent.reading_time); 126 | rs = sqlite3_bind_int(stmt, 8, (ent.starred) ? 1 : 0); 127 | rs = sqlite3_bind_int(stmt, 9, ent.downloaded); 128 | 129 | rs = sqlite3_step(stmt); 130 | if (rs == SQLITE_CONSTRAINT) 131 | { 132 | //TODO what if item is already there? update? --> use replace? 133 | } 134 | else if (rs != SQLITE_DONE) 135 | { 136 | Log::writeErrorLog(sqlite3_errmsg(_db) + std::string(" (Error Code: ") + std::to_string(rs) + ")"); 137 | } 138 | rs = sqlite3_clear_bindings(stmt); 139 | rs = sqlite3_reset(stmt); 140 | } 141 | 142 | sqlite3_exec(_db, "END TRANSACTION;", NULL, NULL, NULL); 143 | 144 | sqlite3_finalize(stmt); 145 | sqlite3_close(_db); 146 | 147 | return true; 148 | } 149 | 150 | 151 | bool SqliteConnector::open() 152 | { 153 | int rs; 154 | 155 | rs = sqlite3_open(_dbpath.c_str(), &_db); 156 | 157 | 158 | if (rs) 159 | { 160 | Log::writeErrorLog("Could not open DB at " + _dbpath); 161 | } 162 | rs = sqlite3_exec(_db, "CREATE TABLE IF NOT EXISTS PocketItems (id TEXT PRIMARY KEY, status INT, title TEXT, url TEXT, excerpt TEXT, path TEXT, reading_time INT, starred INT, downloaded INT);", NULL, 0, NULL); 163 | return true; 164 | } 165 | -------------------------------------------------------------------------------- /src/util/util.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // util.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 04.08.2020 6 | // 7 | //------------------------------------------------------------------- 8 | #include "util.h" 9 | #include "inkview.h" 10 | #include "eventHandler.h" 11 | #include "log.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using std::string; 20 | 21 | size_t Util::writeCallback(void *contents, size_t size, size_t nmemb, void *userp) 22 | { 23 | ((string *)userp)->append((char *)contents, size * nmemb); 24 | return size * nmemb; 25 | } 26 | 27 | size_t Util::writeData(void *ptr, size_t size, size_t nmemb, FILE *stream) 28 | { 29 | size_t written = iv_fwrite(ptr, size, nmemb, stream); 30 | return written; 31 | } 32 | 33 | //https://github.com/pmartin/pocketbook-demo/blob/master/devutils/wifi.cpp 34 | void Util::connectToNetwork() 35 | { 36 | //NetError, NetErrorMessage 37 | iv_netinfo *netinfo = NetInfo(); 38 | if (netinfo->connected){ 39 | ShowHourglassForce(); 40 | return; 41 | } 42 | 43 | const char *network_name = nullptr; 44 | int result = NetConnect2(network_name, 1); 45 | if (result != 0) 46 | { 47 | throw std::runtime_error("Could not connect to the internet."); 48 | } 49 | 50 | netinfo = NetInfo(); 51 | if (netinfo->connected){ 52 | ShowHourglassForce(); 53 | return; 54 | } 55 | 56 | throw std::runtime_error("Could not connect to the internet."); 57 | } 58 | 59 | string Util::accessConfig(const Action &action, const string &name, const string &value) 60 | { 61 | iconfigedit *temp = nullptr; 62 | iconfig *config = OpenConfig(CONFIG_PATH.c_str(), temp); 63 | string returnValue; 64 | 65 | switch (action) 66 | { 67 | case Action::IWriteSecret: 68 | if (!value.empty()) 69 | WriteSecret(config, name.c_str(), value.c_str()); 70 | returnValue = {}; 71 | break; 72 | case Action::IReadSecret: 73 | returnValue = ReadSecret(config, name.c_str(), ""); 74 | break; 75 | case Action::IWriteString: 76 | if (!value.empty()) 77 | WriteString(config, name.c_str(), value.c_str()); 78 | returnValue = {}; 79 | break; 80 | case Action::IReadString: 81 | returnValue = ReadString(config, name.c_str(), ""); 82 | break; 83 | default: 84 | break; 85 | } 86 | CloseConfig(config); 87 | 88 | return returnValue; 89 | } 90 | 91 | string Util::getData(const string &url) 92 | { 93 | Util::connectToNetwork(); 94 | 95 | string readBuffer; 96 | CURLcode res; 97 | CURL *curl = curl_easy_init(); 98 | 99 | if (curl) 100 | { 101 | struct curl_slist *headers = NULL; 102 | curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); 103 | curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 104 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Util::writeCallback); 105 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); 106 | curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 107 | 108 | res = curl_easy_perform(curl); 109 | curl_easy_cleanup(curl); 110 | 111 | if (res == CURLE_OK) 112 | { 113 | long response_code; 114 | curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); 115 | 116 | switch (response_code) 117 | { 118 | case 200: 119 | return readBuffer; 120 | default: 121 | throw std::runtime_error("HTML Error Code" + std::to_string(response_code)); 122 | } 123 | } 124 | else 125 | { 126 | Log::writeErrorLog(std::to_string(res) + url); 127 | throw std::runtime_error("Curl RES Error Code " + std::to_string(res)); 128 | } 129 | } 130 | return {}; 131 | } 132 | 133 | string Util::clearString(string title) 134 | { 135 | const std::string forbiddenInFiles = "<>\\/:?\"|"; 136 | std::transform(title.begin(), title.end(), title.begin(), [&forbiddenInFiles](char c) 137 | { return forbiddenInFiles.find(c) != std::string::npos ? ' ' : c; }); 138 | return title; 139 | } 140 | 141 | string Util::createHtml(string title, string content) 142 | { 143 | 144 | title = clearString(title); 145 | 146 | string path = ARTICLE_FOLDER + "/" + title + ".html"; 147 | if (iv_access(path.c_str(), W_OK) != 0) 148 | { 149 | string result = content; 150 | 151 | auto found = content.find(""); 206 | //html 207 | replaceAll(data, "'", "\'"); 208 | replaceAll(data, "/", "/"); 209 | replaceAll(data, "

", "\n"); 210 | replaceAll(data, "", "\""); 211 | replaceAll(data, "", "\""); 212 | } 213 | 214 | void Util::replaceAll(std::string &data, const std::string &replace, const std::string &by) 215 | { 216 | auto start = 0; 217 | while ((start = data.find(replace, start)) != std::string::npos) 218 | { 219 | data.replace(start, replace.size(), by); 220 | start += by.length(); 221 | } 222 | 223 | } 224 | -------------------------------------------------------------------------------- /src/api/pocket.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // pocket.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 22.04.2021 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "pocket.h" 10 | #include "eventHandler.h" 11 | #include "log.h" 12 | #include "pocketModel.h" 13 | #include "util.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | using std::string; 20 | using std::vector; 21 | 22 | namespace 23 | { 24 | using namespace std::string_literals; 25 | const auto POCKET_URL{"https://getpocket.com/v3/"s}; 26 | const auto CONSUMER_KEY{""s}; 27 | } // namespace 28 | 29 | Pocket::Pocket() 30 | { 31 | if (iv_access(CONFIG_PATH.c_str(), W_OK) == 0) 32 | _accessToken = Util::accessConfig(Action::IReadSecret, "AccessToken"); 33 | 34 | if (_accessToken.empty()) 35 | loginDialog(); 36 | } 37 | 38 | void Pocket::loginDialog() 39 | { 40 | try 41 | { 42 | auto code = getCode(); 43 | auto dialogResult = 44 | DialogSynchro(ICON_QUESTION, "Action", 45 | ("Please type the URL below into your browser to grant this application access to Pocket. " 46 | "After you accepted please click done.(It is normal that, once you accepted, the page fails " 47 | "to load) \n https://getpocket.com/auth/authorize?request_token=" + 48 | code) 49 | .c_str(), 50 | "Done", "Cancel", NULL); 51 | switch (dialogResult) 52 | { 53 | case 1: { 54 | getAccessToken(code); 55 | break; 56 | } 57 | default: 58 | CloseApp(); 59 | break; 60 | } 61 | } 62 | catch (const std::exception &e) 63 | { 64 | Log::writeErrorLog(e.what()); 65 | Message(ICON_INFORMATION, "Error while logging in.", e.what(), 1200); 66 | loginDialog(); 67 | } 68 | } 69 | 70 | string Pocket::getCode() 71 | { 72 | const auto root{ 73 | post("oauth/request", "{\"consumer_key\":\"" + CONSUMER_KEY + "\", \"redirect_uri\":\"github.com\"}")}; 74 | if (!root["code"].isString()) 75 | { 76 | throw std::runtime_error("could not receive code."); 77 | } 78 | return root["code"].asString(); 79 | } 80 | 81 | void Pocket::getAccessToken(const string &code) 82 | { 83 | const auto root = post("oauth/authorize", "{\"consumer_key\":\"" + CONSUMER_KEY + "\", \"code\":\"" + code + "\"}"); 84 | if (root["username"].isString()) 85 | { 86 | Util::accessConfig(Action::IWriteSecret, "Username", root["username"].asString()); 87 | } 88 | 89 | if (root["access_token"].isString()) 90 | { 91 | _accessToken = root["access_token"].asString(); 92 | Util::accessConfig(Action::IWriteSecret, "AccessToken", _accessToken); 93 | } 94 | else 95 | { 96 | throw std::runtime_error("could not receive authentifcation token."); 97 | } 98 | } 99 | 100 | void Pocket::addItems(const string &url) 101 | { 102 | // TODO curl url-encode url 103 | string postData = "{\"consumer_key\":\"" + CONSUMER_KEY + "\", \"access_token\":\"" + _accessToken + 104 | "\",\"url\":\"" + url + "\"}"; 105 | const auto root = post("add", postData); 106 | } 107 | 108 | 109 | vector Pocket::getItems() 110 | { 111 | string postData = "{\"consumer_key\":\"" + CONSUMER_KEY + "\", \"access_token\":\"" + _accessToken + 112 | "\",\"detailType\":\"simple\",\"contentType\":\"article\",\"state\":\"all\""; 113 | auto lastUpdate = Util::accessConfig(Action::IReadString, "lastUpdate"); 114 | if (!lastUpdate.empty()) 115 | { 116 | postData += ",\"since\":" + lastUpdate; 117 | } 118 | postData += '}'; 119 | 120 | auto const j = post("get", postData); 121 | 122 | if (j["since"].isNumeric()) 123 | { 124 | const auto since = j["since"].asString(); 125 | Util::accessConfig(Action::IWriteString, "lastUpdate", since); 126 | } 127 | 128 | vector tempItems; 129 | for (const auto &element : j["list"]) 130 | { 131 | PocketItem temp; 132 | if (element["item_id"].isString()) 133 | { 134 | temp.id = element["item_id"].asString(); 135 | } 136 | if (element["given_url"].isString()) 137 | { 138 | temp.url = element["given_url"].asString(); 139 | } 140 | if (element.isMember("favorite")) 141 | { 142 | temp.starred = (element["favorite"].asString() != "0"); 143 | } 144 | if (element.isMember("status")) 145 | { 146 | if (element["status"].asString() == "0") 147 | { 148 | temp.status = IStatus::UNREAD; 149 | } 150 | else if (element["status"].asString() == "1") 151 | { 152 | temp.status = IStatus::ARCHIVED; 153 | } 154 | else if (element["status"].asString() == "2") 155 | { 156 | temp.status = IStatus::TODELETE; 157 | } 158 | } 159 | if (element["resolved_title"].isString()) 160 | { 161 | temp.title = element["resolved_title"].asString(); 162 | temp.path = ARTICLE_FOLDER + "/" + Util::clearString(temp.title) + ".html"; 163 | } 164 | if (element["excerpt"].isString()) 165 | { 166 | temp.excerpt = element["excerpt"].asString(); 167 | } 168 | if (element["time_to_read"].isNumeric()) 169 | { 170 | temp.reading_time = element["time_to_read"].asInt(); 171 | } 172 | 173 | tempItems.push_back(temp); 174 | } 175 | 176 | return tempItems; 177 | } 178 | 179 | void Pocket::getText(PocketItem *item) 180 | { 181 | 182 | } 183 | 184 | string Pocket::determineAction(PocketAction action) 185 | { 186 | string stAction; 187 | switch (action) 188 | { 189 | case PocketAction::ADD: 190 | stAction = "add"; 191 | break; 192 | case PocketAction::ARCHIVE: 193 | stAction = "archive"; 194 | break; 195 | case PocketAction::READD: 196 | stAction = "readd"; 197 | break; 198 | case PocketAction::FAVORITE: 199 | stAction = "favorite"; 200 | break; 201 | case PocketAction::UNFAVORITE: 202 | stAction = "unfavorite"; 203 | break; 204 | case PocketAction::DELETE: 205 | stAction = "delete"; 206 | break; 207 | } 208 | return stAction; 209 | } 210 | 211 | void Pocket::sendItem(PocketAction action, const string &id) 212 | { 213 | // response does not help here as it is always the same 214 | std::string postData = 215 | "{\"consumer_key\":\"" + CONSUMER_KEY + "\",\"access_token\":\"" + _accessToken + "\",\"actions\":["; 216 | postData += "{\"action\":\"" + determineAction(action) + "\",\"item_id\":\"" + id + "\"}]}"; 217 | auto const j = post("send", postData); 218 | } 219 | 220 | void Pocket::sendItems(PocketAction action, const vector &ids) 221 | { 222 | 223 | std::string postData = 224 | "{\"consumer_key\":\"" + CONSUMER_KEY + "\",\"access_token\":\"" + _accessToken + "\",\"actions\":["; 225 | string stAction = determineAction(action); 226 | auto comma{false}; 227 | for (auto id : ids) 228 | { 229 | if (comma) 230 | { 231 | postData += ','; 232 | } 233 | postData += "{\"action\":\"" + stAction + "\",\"item_id\":\"" + id + "\"}"; 234 | if (!comma) 235 | { 236 | comma = true; 237 | } 238 | } 239 | postData += "]}"; 240 | auto const j = post("send", postData); 241 | } 242 | 243 | Json::Value Pocket::post(const string &apiEndpoint, const string &data) 244 | { 245 | Util::connectToNetwork(); 246 | 247 | string url = POCKET_URL + apiEndpoint; 248 | 249 | string readBuffer; 250 | CURLcode res; 251 | CURL *curl = curl_easy_init(); 252 | 253 | if (curl) 254 | { 255 | 256 | struct curl_slist *headers = NULL; 257 | headers = curl_slist_append(headers, "Content-Type: application/json; charset=UTF-8"); 258 | headers = curl_slist_append(headers, "X-Accept: application/json"); 259 | curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); 260 | curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 261 | 262 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Util::writeCallback); 263 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); 264 | 265 | curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); 266 | 267 | res = curl_easy_perform(curl); 268 | curl_easy_cleanup(curl); 269 | 270 | if (res == CURLE_OK) 271 | { 272 | long response_code; 273 | curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); 274 | 275 | switch (response_code) 276 | { 277 | case 200: { 278 | Json::Value root; 279 | Json::Reader reader; 280 | if (reader.parse(readBuffer, root)) 281 | { 282 | return root; 283 | } 284 | constexpr auto err_msg{"Failed to parse Response to json"}; 285 | Log::writeErrorLog(err_msg); 286 | throw std::runtime_error(err_msg); 287 | } 288 | case 400: 289 | throw std::runtime_error( 290 | "Invalid request, please make sure you follow the documentation for proper syntax"); 291 | case 401: 292 | throw std::runtime_error("Problem authenticating the user"); 293 | case 403: 294 | throw std::runtime_error( 295 | "User was authenticated, but access denied due to lack of permission or rate limiting."); 296 | case 503: 297 | throw std::runtime_error("Pocket's sync server is down for scheduled maintenance."); 298 | default: 299 | throw std::runtime_error("HTML Error Code" + std::to_string(response_code)); 300 | } 301 | } 302 | else 303 | { 304 | Log::writeErrorLog("pocket API: " + url + " RES Error Code: " + std::to_string(res)); 305 | throw std::runtime_error("Curl RES Error Code " + std::to_string(res)); 306 | } 307 | } 308 | return {}; 309 | } 310 | -------------------------------------------------------------------------------- /src/handler/eventHandler.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | // eventHandler.cpp 3 | // 4 | // Author: JuanJakobo 5 | // Date: 22.04.2021 6 | // 7 | //------------------------------------------------------------------- 8 | 9 | #include "eventHandler.h" 10 | #include "inkview.h" 11 | 12 | #include "mainMenu.h" 13 | #include "contextMenu.h" 14 | 15 | #include "pocket.h" 16 | #include "pocketModel.h" 17 | #include "pocketView.h" 18 | 19 | #include "util.h" 20 | #include "log.h" 21 | #include "sqliteConnector.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | using std::string; 32 | using std::vector; 33 | 34 | std::unique_ptr EventHandler::_eventHandlerStatic; 35 | pthread_mutex_t mutexEntries; 36 | 37 | EventHandler::EventHandler() 38 | { 39 | //create an copy of the eventhandler to handle methods that require static functions 40 | _eventHandlerStatic = std::unique_ptr(this); 41 | 42 | if (iv_access(CONFIG_FOLDER.c_str(), W_OK) != 0) 43 | iv_mkdir(CONFIG_FOLDER.c_str(), 0777); 44 | if (iv_access(ARTICLE_FOLDER.c_str(), W_OK) != 0) 45 | iv_mkdir(ARTICLE_FOLDER.c_str(), 0777); 46 | 47 | if (iv_access(IMAGE_FOLDER.c_str(), W_OK) != 0) 48 | iv_mkdir(IMAGE_FOLDER.c_str(), 0777); 49 | 50 | _pocket = std::unique_ptr(new Pocket()); 51 | 52 | _items = _sqliteCon.selectPocketEntries(PIsDownloaded::PDOWNLOADED); 53 | for(size_t i = 0; i < _items.size(); i++) 54 | { 55 | if (iv_access(_items.at(i).path.c_str(), W_OK) != 0) 56 | { 57 | _items.at(i).downloaded = PIsDownloaded::PNOTDOWNLOADED; 58 | _sqliteCon.updatePocketItem(_items.at(i).id,UpdateAction::IDOWNLOADED, PIsDownloaded::PNOTDOWNLOADED); 59 | break; 60 | } 61 | } 62 | drawPocketItems(_items); 63 | 64 | } 65 | 66 | EventHandler::~EventHandler() 67 | { 68 | } 69 | 70 | int EventHandler::eventDistributor(const int type, const int par1, const int par2) 71 | { 72 | if (ISPOINTEREVENT(type)) 73 | return EventHandler::pointerHandler(type, par1, par2); 74 | else if (ISKEYEVENT(type)) 75 | return EventHandler::keyHandler(type, par1, par2); 76 | 77 | return 0; 78 | } 79 | 80 | void EventHandler::mainMenuHandlerStatic(const int index) 81 | { 82 | _eventHandlerStatic->mainMenuHandler(index); 83 | } 84 | 85 | void EventHandler::mainMenuHandler(const int index) 86 | { 87 | switch (index) 88 | { 89 | //show downloaded 90 | case 101: 91 | { 92 | _items = _sqliteCon.selectPocketEntries(PIsDownloaded::PDOWNLOADED); 93 | drawPocketItems(_items); 94 | break; 95 | } 96 | //show unread 97 | case 102: 98 | { 99 | filterAndDrawPocket(IStatus::UNREAD,false); 100 | break; 101 | } 102 | //show starred 103 | case 103: 104 | { 105 | filterAndDrawPocket(IStatus::UNREAD,true); 106 | break; 107 | } 108 | //Mark as read till page 109 | case 104: 110 | { 111 | _pocket->sendItems(PocketAction::ARCHIVE, _pocketView->getEntriesTillPage()); 112 | _items = _sqliteCon.selectPocketEntries(PIsDownloaded::PDOWNLOADED); 113 | drawPocketItems(_items); 114 | break; 115 | } 116 | case 105: 117 | { 118 | Message(ICON_INFORMATION, "Info", "Info", 1200); 119 | break; 120 | } 121 | //Exit 122 | case 106: 123 | CloseApp(); 124 | break; 125 | default: 126 | break; 127 | } 128 | } 129 | 130 | void EventHandler::contextMenuHandlerStatic(const int index) 131 | { 132 | _eventHandlerStatic->contextMenuHandler(index); 133 | } 134 | 135 | void EventHandler::contextMenuHandler(const int index) 136 | { 137 | try{ 138 | 139 | switch (index) 140 | { 141 | //Mark/Unmark to download 142 | case 101: 143 | { 144 | if(_pocketView->getCurrentEntry()->downloaded != PIsDownloaded::PDOWNLOADED) 145 | { 146 | _pocket->getText(_pocketView->getCurrentEntry()); 147 | _pocketView->getCurrentEntry()->downloaded = PIsDownloaded::PDOWNLOADED; 148 | } 149 | else 150 | { 151 | remove(_pocketView->getCurrentEntry()->path.c_str()); 152 | string title = _pocketView->getCurrentEntry()->title; 153 | string cmd = "rm -rf \"" + ARTICLE_FOLDER + "/img/" + title + "/\""; 154 | system(cmd.c_str()); 155 | _pocketView->getCurrentEntry()->downloaded = PIsDownloaded::PNOTDOWNLOADED; 156 | } 157 | _sqliteCon.updatePocketItem(_pocketView->getCurrentEntry()->id, UpdateAction::IDOWNLOADED, _pocketView->getCurrentEntry()->downloaded); 158 | _pocketView->reDrawCurrentEntry(); 159 | HideHourglass(); 160 | break; 161 | } 162 | //Archive/readd 163 | case 102: 164 | { 165 | if(_pocketView->getCurrentEntry()->status == IStatus::UNREAD) 166 | { 167 | _pocket->sendItem(PocketAction::ARCHIVE, _pocketView->getCurrentEntry()->id); 168 | _pocketView->getCurrentEntry()->status = IStatus::ARCHIVED; 169 | } 170 | else if(_pocketView->getCurrentEntry()->status == IStatus::ARCHIVED) 171 | { 172 | _pocket->sendItem(PocketAction::READD, _pocketView->getCurrentEntry()->id); 173 | _pocketView->getCurrentEntry()->status = IStatus::UNREAD; 174 | } 175 | _sqliteCon.updatePocketItem(_pocketView->getCurrentEntry()->id, UpdateAction::ISTATUS, _pocketView->getCurrentEntry()->status); 176 | _pocketView->reDrawCurrentEntry(); 177 | HideHourglass(); 178 | break; 179 | 180 | } 181 | //Unstar/Star 182 | case 103: 183 | { 184 | if(_pocketView->getCurrentEntry()->starred) 185 | { 186 | _pocket->sendItem(PocketAction::UNFAVORITE, _pocketView->getCurrentEntry()->id); 187 | } 188 | else 189 | { 190 | _pocket->sendItem(PocketAction::FAVORITE, _pocketView->getCurrentEntry()->id); 191 | } 192 | _pocketView->getCurrentEntry()->starred = !_pocketView->getCurrentEntry()->starred; 193 | _sqliteCon.updatePocketItem(_pocketView->getCurrentEntry()->id, UpdateAction::ISTARRED, _pocketView->getCurrentEntry()->starred); 194 | _pocketView->reDrawCurrentEntry(); 195 | HideHourglass(); 196 | break; 197 | } 198 | default: 199 | { 200 | _pocketView->invertCurrentEntryColor(); 201 | break; 202 | } 203 | } 204 | } 205 | catch (const std::exception &e) 206 | { 207 | 208 | _pocketView->invertCurrentEntryColor(); 209 | Log::writeErrorLog(e.what()); 210 | Message(ICON_INFORMATION, "Error",e.what(), 1000); 211 | } 212 | } 213 | 214 | int EventHandler::pointerHandler(const int type, const int par1, const int par2) 215 | { 216 | if (type == EVT_POINTERLONG) 217 | { 218 | if (_currentView == Views::PKVIEW) 219 | { 220 | if (_pocketView->checkIfEntryClicked(par1, par2)) 221 | _pocketView->invertCurrentEntryColor(); 222 | 223 | _contextMenu.createMenu(par2, EventHandler::contextMenuHandlerStatic,*_pocketView->getCurrentEntry()); 224 | return 1; 225 | } 226 | } 227 | else if (type == EVT_POINTERUP) 228 | { 229 | //if menu is clicked 230 | if (IsInRect(par1, par2, _menu.getMenuButtonRect()) == 1) 231 | { 232 | auto mainView = true; 233 | 234 | return _menu.createMenu(mainView, EventHandler::mainMenuHandlerStatic); 235 | } 236 | else if (_currentView == Views::PKVIEW) 237 | { 238 | if (_pocketView->checkIfEntryClicked(par1, par2)) 239 | { 240 | _pocketView->invertCurrentEntryColor(); 241 | 242 | 243 | int dialogResult = DialogSynchro(ICON_INFORMATION, "Action",(_pocketView->getCurrentEntry()->title + "\n" + _pocketView->getCurrentEntry()->excerpt + "...").c_str(), "Read article", "Cancel", NULL); 244 | switch (dialogResult) 245 | { 246 | case 1: 247 | { 248 | try{ 249 | if(_pocketView->getCurrentEntry()->downloaded == PIsDownloaded::PNOTDOWNLOADED) 250 | { 251 | _pocket->getText(_pocketView->getCurrentEntry()); 252 | _sqliteCon.updatePocketItem(_pocketView->getCurrentEntry()->id, UpdateAction::IDOWNLOADED, PIsDownloaded::PDOWNLOADED); 253 | _pocketView->getCurrentEntry()->downloaded = PIsDownloaded::PDOWNLOADED; 254 | _pocketView->reDrawCurrentEntry(); 255 | } 256 | else 257 | _pocketView->invertCurrentEntryColor(); 258 | 259 | OpenBook(_pocketView->getCurrentEntry()->path.c_str(),"",0); 260 | break; 261 | } 262 | catch (const std::exception &e) 263 | { 264 | 265 | Log::writeErrorLog(e.what()); 266 | Message(ICON_INFORMATION, "Error",e.what(), 1000); 267 | } 268 | } 269 | default: 270 | { 271 | _pocketView->invertCurrentEntryColor(); 272 | break; 273 | } 274 | } 275 | 276 | } 277 | return 1; 278 | } 279 | } 280 | return 0; 281 | } 282 | 283 | int EventHandler::keyHandler(const int type, const int par1, const int par2) 284 | { 285 | //menu button 286 | if (type == EVT_KEYPRESS) 287 | { 288 | 289 | if (_currentView == Views::PKVIEW) 290 | { 291 | if (par1 == 23) 292 | { 293 | _pocketView->firstPage(); 294 | return 1; 295 | } 296 | //left button -> pre page 297 | else if (par1 == 24) 298 | { 299 | _pocketView->prevPage(); 300 | return 1; 301 | } 302 | //right button -> next page 303 | else if (par1 == 25) 304 | { 305 | _pocketView->nextPage(); 306 | return 1; 307 | } 308 | } 309 | } 310 | 311 | return 0; 312 | } 313 | 314 | bool EventHandler::drawPocketItems(const vector &pocketItems) 315 | { 316 | if (pocketItems.size() > 0) 317 | { 318 | _pocketView.reset(new PocketView(_menu.getContentRect(),pocketItems,1)); 319 | _pocketView->draw(); 320 | _currentView = Views::PKVIEW; 321 | return true; 322 | } 323 | else 324 | { 325 | FillAreaRect(_menu.getContentRect(), WHITE); 326 | DrawTextRect2(_menu.getContentRect(), "no entries to show"); 327 | _pocketView.reset(); 328 | _currentView = Views::DEFAULTVIEW; 329 | PartialUpdate(_menu.getContentRect()->x, _menu.getContentRect()->y, _menu.getContentRect()->w, _menu.getContentRect()->h); 330 | return false; 331 | } 332 | 333 | } 334 | 335 | void EventHandler::filterAndDrawPocket(IStatus status, bool favorited) 336 | { 337 | try{ 338 | _items.clear(); 339 | vector newEntries = _pocket->getItems(); 340 | _sqliteCon.insertPocketEntries(newEntries); 341 | vector oldEntries = _sqliteCon.selectPocketEntries(); 342 | for(size_t i = 0; i < newEntries.size(); i++) 343 | { 344 | for(size_t j = 0; j < oldEntries.size();j++) 345 | { 346 | if(newEntries.at(i).id == oldEntries.at(j).id) 347 | { 348 | //TODO filter in DB favorited and status are there, both needed? 349 | if(newEntries.at(i).starred != oldEntries.at(j).starred) 350 | _sqliteCon.updatePocketItem(oldEntries.at(j).id, UpdateAction::ISTARRED, newEntries.at(i).starred); 351 | if(newEntries.at(i).status != oldEntries.at(j).status) 352 | _sqliteCon.updatePocketItem(oldEntries.at(j).id, UpdateAction::ISTATUS, newEntries.at(i).status); 353 | break; 354 | } 355 | } 356 | } 357 | 358 | oldEntries = _sqliteCon.selectPocketEntries(); 359 | for(size_t j = 0; j < oldEntries.size();j++) 360 | { 361 | if(favorited){ 362 | if(oldEntries.at(j).starred == favorited) 363 | _items.push_back(oldEntries.at(j)); 364 | }else{ 365 | if(oldEntries.at(j).status == status) 366 | _items.push_back(oldEntries.at(j)); 367 | } 368 | } 369 | 370 | drawPocketItems(_items); 371 | } 372 | catch (const std::exception &e) 373 | { 374 | 375 | Log::writeErrorLog(e.what()); 376 | Message(ICON_INFORMATION, "Error",e.what(), 1000); 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /src/libs/json/json-forwards.h: -------------------------------------------------------------------------------- 1 | /// Json-cpp amalgamated forward header (http://jsoncpp.sourceforge.net/). 2 | /// It is intended to be used with #include "json/json-forwards.h" 3 | /// This header provides forward declaration for all JsonCpp types. 4 | 5 | // ////////////////////////////////////////////////////////////////////// 6 | // Beginning of content of file: LICENSE 7 | // ////////////////////////////////////////////////////////////////////// 8 | 9 | /* 10 | The JsonCpp library's source code, including accompanying documentation, 11 | tests and demonstration applications, are licensed under the following 12 | conditions... 13 | 14 | Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all 15 | jurisdictions which recognize such a disclaimer. In such jurisdictions, 16 | this software is released into the Public Domain. 17 | 18 | In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 19 | 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and 20 | The JsonCpp Authors, and is released under the terms of the MIT License (see below). 21 | 22 | In jurisdictions which recognize Public Domain property, the user of this 23 | software may choose to accept it either as 1) Public Domain, 2) under the 24 | conditions of the MIT License (see below), or 3) under the terms of dual 25 | Public Domain/MIT License conditions described here, as they choose. 26 | 27 | The MIT License is about as close to Public Domain as a license can get, and is 28 | described in clear, concise terms at: 29 | 30 | http://en.wikipedia.org/wiki/MIT_License 31 | 32 | The full text of the MIT License follows: 33 | 34 | ======================================================================== 35 | Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 36 | 37 | Permission is hereby granted, free of charge, to any person 38 | obtaining a copy of this software and associated documentation 39 | files (the "Software"), to deal in the Software without 40 | restriction, including without limitation the rights to use, copy, 41 | modify, merge, publish, distribute, sublicense, and/or sell copies 42 | of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be 46 | included in all copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 49 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 50 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 51 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 52 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 53 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 54 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 55 | SOFTWARE. 56 | ======================================================================== 57 | (END LICENSE TEXT) 58 | 59 | The MIT license is compatible with both the GPL and commercial 60 | software, affording one all of the rights of Public Domain with the 61 | minor nuisance of being required to keep the above copyright notice 62 | and license text in the source code. Note also that by accepting the 63 | Public Domain "license" you can re-license your copy using whatever 64 | license you like. 65 | 66 | */ 67 | 68 | // ////////////////////////////////////////////////////////////////////// 69 | // End of content of file: LICENSE 70 | // ////////////////////////////////////////////////////////////////////// 71 | 72 | #ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED 73 | #define JSON_FORWARD_AMALGAMATED_H_INCLUDED 74 | /// If defined, indicates that the source file is amalgamated 75 | /// to prevent private header inclusion. 76 | #define JSON_IS_AMALGAMATION 77 | 78 | // ////////////////////////////////////////////////////////////////////// 79 | // Beginning of content of file: include/json/version.h 80 | // ////////////////////////////////////////////////////////////////////// 81 | 82 | #ifndef JSON_VERSION_H_INCLUDED 83 | #define JSON_VERSION_H_INCLUDED 84 | 85 | // Note: version must be updated in three places when doing a release. This 86 | // annoying process ensures that amalgamate, CMake, and meson all report the 87 | // correct version. 88 | // 1. /meson.build 89 | // 2. /include/json/version.h 90 | // 3. /CMakeLists.txt 91 | // IMPORTANT: also update the SOVERSION!! 92 | 93 | #define JSONCPP_VERSION_STRING "1.9.5" 94 | #define JSONCPP_VERSION_MAJOR 1 95 | #define JSONCPP_VERSION_MINOR 9 96 | #define JSONCPP_VERSION_PATCH 5 97 | #define JSONCPP_VERSION_QUALIFIER 98 | #define JSONCPP_VERSION_HEXA \ 99 | ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) 100 | 101 | #ifdef JSONCPP_USING_SECURE_MEMORY 102 | #undef JSONCPP_USING_SECURE_MEMORY 103 | #endif 104 | #define JSONCPP_USING_SECURE_MEMORY 0 105 | // If non-zero, the library zeroes any memory that it has allocated before 106 | // it frees its memory. 107 | 108 | #endif // JSON_VERSION_H_INCLUDED 109 | 110 | // ////////////////////////////////////////////////////////////////////// 111 | // End of content of file: include/json/version.h 112 | // ////////////////////////////////////////////////////////////////////// 113 | 114 | // ////////////////////////////////////////////////////////////////////// 115 | // Beginning of content of file: include/json/allocator.h 116 | // ////////////////////////////////////////////////////////////////////// 117 | 118 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 119 | // Distributed under MIT license, or public domain if desired and 120 | // recognized in your jurisdiction. 121 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 122 | 123 | #ifndef JSON_ALLOCATOR_H_INCLUDED 124 | #define JSON_ALLOCATOR_H_INCLUDED 125 | 126 | #include 127 | #include 128 | 129 | #pragma pack(push) 130 | #pragma pack() 131 | 132 | namespace Json 133 | { 134 | template class SecureAllocator 135 | { 136 | public: 137 | // Type definitions 138 | using value_type = T; 139 | using pointer = T *; 140 | using const_pointer = const T *; 141 | using reference = T &; 142 | using const_reference = const T &; 143 | using size_type = std::size_t; 144 | using difference_type = std::ptrdiff_t; 145 | 146 | /** 147 | * Allocate memory for N items using the standard allocator. 148 | */ 149 | pointer allocate(size_type n) 150 | { 151 | // allocate using "global operator new" 152 | return static_cast(::operator new(n * sizeof(T))); 153 | } 154 | 155 | /** 156 | * Release memory which was allocated for N items at pointer P. 157 | * 158 | * The memory block is filled with zeroes before being released. 159 | */ 160 | void deallocate(pointer p, size_type n) 161 | { 162 | // memset_s is used because memset may be optimized away by the compiler 163 | memset_s(p, n * sizeof(T), 0, n * sizeof(T)); 164 | // free using "global operator delete" 165 | ::operator delete(p); 166 | } 167 | 168 | /** 169 | * Construct an item in-place at pointer P. 170 | */ 171 | template void construct(pointer p, Args &&...args) 172 | { 173 | // construct using "placement new" and "perfect forwarding" 174 | ::new (static_cast(p)) T(std::forward(args)...); 175 | } 176 | 177 | size_type max_size() const 178 | { 179 | return size_t(-1) / sizeof(T); 180 | } 181 | 182 | pointer address(reference x) const 183 | { 184 | return std::addressof(x); 185 | } 186 | 187 | const_pointer address(const_reference x) const 188 | { 189 | return std::addressof(x); 190 | } 191 | 192 | /** 193 | * Destroy an item in-place at pointer P. 194 | */ 195 | void destroy(pointer p) 196 | { 197 | // destroy using "explicit destructor" 198 | p->~T(); 199 | } 200 | 201 | // Boilerplate 202 | SecureAllocator() 203 | { 204 | } 205 | template SecureAllocator(const SecureAllocator &) 206 | { 207 | } 208 | template struct rebind 209 | { 210 | using other = SecureAllocator; 211 | }; 212 | }; 213 | 214 | template bool operator==(const SecureAllocator &, const SecureAllocator &) 215 | { 216 | return true; 217 | } 218 | 219 | template bool operator!=(const SecureAllocator &, const SecureAllocator &) 220 | { 221 | return false; 222 | } 223 | 224 | } // namespace Json 225 | 226 | #pragma pack(pop) 227 | 228 | #endif // JSON_ALLOCATOR_H_INCLUDED 229 | 230 | // ////////////////////////////////////////////////////////////////////// 231 | // End of content of file: include/json/allocator.h 232 | // ////////////////////////////////////////////////////////////////////// 233 | 234 | // ////////////////////////////////////////////////////////////////////// 235 | // Beginning of content of file: include/json/config.h 236 | // ////////////////////////////////////////////////////////////////////// 237 | 238 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 239 | // Distributed under MIT license, or public domain if desired and 240 | // recognized in your jurisdiction. 241 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 242 | 243 | #ifndef JSON_CONFIG_H_INCLUDED 244 | #define JSON_CONFIG_H_INCLUDED 245 | #include 246 | #include 247 | #include 248 | #include 249 | #include 250 | #include 251 | #include 252 | #include 253 | 254 | // If non-zero, the library uses exceptions to report bad input instead of C 255 | // assertion macros. The default is to use exceptions. 256 | #ifndef JSON_USE_EXCEPTION 257 | #define JSON_USE_EXCEPTION 1 258 | #endif 259 | 260 | // Temporary, tracked for removal with issue #982. 261 | #ifndef JSON_USE_NULLREF 262 | #define JSON_USE_NULLREF 1 263 | #endif 264 | 265 | /// If defined, indicates that the source file is amalgamated 266 | /// to prevent private header inclusion. 267 | /// Remarks: it is automatically defined in the generated amalgamated header. 268 | // #define JSON_IS_AMALGAMATION 269 | 270 | // Export macros for DLL visibility 271 | #if defined(JSON_DLL_BUILD) 272 | #if defined(_MSC_VER) || defined(__MINGW32__) 273 | #define JSON_API __declspec(dllexport) 274 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 275 | #elif defined(__GNUC__) || defined(__clang__) 276 | #define JSON_API __attribute__((visibility("default"))) 277 | #endif // if defined(_MSC_VER) 278 | 279 | #elif defined(JSON_DLL) 280 | #if defined(_MSC_VER) || defined(__MINGW32__) 281 | #define JSON_API __declspec(dllimport) 282 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 283 | #endif // if defined(_MSC_VER) 284 | #endif // ifdef JSON_DLL_BUILD 285 | 286 | #if !defined(JSON_API) 287 | #define JSON_API 288 | #endif 289 | 290 | #if defined(_MSC_VER) && _MSC_VER < 1800 291 | #error \ 292 | "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities" 293 | #endif 294 | 295 | #if defined(_MSC_VER) && _MSC_VER < 1900 296 | // As recommended at 297 | // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 298 | extern JSON_API int msvc_pre1900_c99_snprintf(char *outBuf, size_t size, const char *format, ...); 299 | #define jsoncpp_snprintf msvc_pre1900_c99_snprintf 300 | #else 301 | #define jsoncpp_snprintf std::snprintf 302 | #endif 303 | 304 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for 305 | // integer 306 | // Storages, and 64 bits integer support is disabled. 307 | // #define JSON_NO_INT64 1 308 | 309 | // JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools. 310 | // C++11 should be used directly in JSONCPP. 311 | #define JSONCPP_OVERRIDE override 312 | 313 | #ifdef __clang__ 314 | #if __has_extension(attribute_deprecated_with_message) 315 | #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) 316 | #endif 317 | #elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc) 318 | #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) 319 | #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) 320 | #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 321 | #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) 322 | #endif // GNUC version 323 | #elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates 324 | // MSVC) 325 | #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) 326 | #endif // __clang__ || __GNUC__ || _MSC_VER 327 | 328 | #if !defined(JSONCPP_DEPRECATED) 329 | #define JSONCPP_DEPRECATED(message) 330 | #endif // if !defined(JSONCPP_DEPRECATED) 331 | 332 | #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6)) 333 | #define JSON_USE_INT64_DOUBLE_CONVERSION 1 334 | #endif 335 | 336 | #if !defined(JSON_IS_AMALGAMATION) 337 | 338 | #include "allocator.h" 339 | #include "version.h" 340 | 341 | #endif // if !defined(JSON_IS_AMALGAMATION) 342 | 343 | namespace Json 344 | { 345 | using Int = int; 346 | using UInt = unsigned int; 347 | #if defined(JSON_NO_INT64) 348 | using LargestInt = int; 349 | using LargestUInt = unsigned int; 350 | #undef JSON_HAS_INT64 351 | #else // if defined(JSON_NO_INT64) 352 | // For Microsoft Visual use specific types as long long is not supported 353 | #if defined(_MSC_VER) // Microsoft Visual Studio 354 | using Int64 = __int64; 355 | using UInt64 = unsigned __int64; 356 | #else // if defined(_MSC_VER) // Other platforms, use long long 357 | using Int64 = int64_t; 358 | using UInt64 = uint64_t; 359 | #endif // if defined(_MSC_VER) 360 | using LargestInt = Int64; 361 | using LargestUInt = UInt64; 362 | #define JSON_HAS_INT64 363 | #endif // if defined(JSON_NO_INT64) 364 | 365 | template 366 | using Allocator = typename std::conditional, std::allocator>::type; 367 | using String = std::basic_string, Allocator>; 368 | using IStringStream = std::basic_istringstream; 369 | using OStringStream = std::basic_ostringstream; 370 | using IStream = std::istream; 371 | using OStream = std::ostream; 372 | } // namespace Json 373 | 374 | // Legacy names (formerly macros). 375 | using JSONCPP_STRING = Json::String; 376 | using JSONCPP_ISTRINGSTREAM = Json::IStringStream; 377 | using JSONCPP_OSTRINGSTREAM = Json::OStringStream; 378 | using JSONCPP_ISTREAM = Json::IStream; 379 | using JSONCPP_OSTREAM = Json::OStream; 380 | 381 | #endif // JSON_CONFIG_H_INCLUDED 382 | 383 | // ////////////////////////////////////////////////////////////////////// 384 | // End of content of file: include/json/config.h 385 | // ////////////////////////////////////////////////////////////////////// 386 | 387 | // ////////////////////////////////////////////////////////////////////// 388 | // Beginning of content of file: include/json/forwards.h 389 | // ////////////////////////////////////////////////////////////////////// 390 | 391 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 392 | // Distributed under MIT license, or public domain if desired and 393 | // recognized in your jurisdiction. 394 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 395 | 396 | #ifndef JSON_FORWARDS_H_INCLUDED 397 | #define JSON_FORWARDS_H_INCLUDED 398 | 399 | #if !defined(JSON_IS_AMALGAMATION) 400 | #include "config.h" 401 | #endif // if !defined(JSON_IS_AMALGAMATION) 402 | 403 | namespace Json 404 | { 405 | 406 | // writer.h 407 | class StreamWriter; 408 | class StreamWriterBuilder; 409 | class Writer; 410 | class FastWriter; 411 | class StyledWriter; 412 | class StyledStreamWriter; 413 | 414 | // reader.h 415 | class Reader; 416 | class CharReader; 417 | class CharReaderBuilder; 418 | 419 | // json_features.h 420 | class Features; 421 | 422 | // value.h 423 | using ArrayIndex = unsigned int; 424 | class StaticString; 425 | class Path; 426 | class PathArgument; 427 | class Value; 428 | class ValueIteratorBase; 429 | class ValueIterator; 430 | class ValueConstIterator; 431 | 432 | } // namespace Json 433 | 434 | #endif // JSON_FORWARDS_H_INCLUDED 435 | 436 | // ////////////////////////////////////////////////////////////////////// 437 | // End of content of file: include/json/forwards.h 438 | // ////////////////////////////////////////////////////////////////////// 439 | 440 | #endif // ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED 441 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------