mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[reader] Make improve coding style and added empty view message
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
Default,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,settings
|
Default,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,reader,settings
|
||||||
HidePython,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,settings
|
HidePython,calculation,rpn,graph,code,statistics,probability,solver,atomic,sequence,regression,reader,settings
|
||||||
|
|||||||
|
@@ -1,4 +1,4 @@
|
|||||||
apps += reader::App
|
apps += Reader::App
|
||||||
app_headers += apps/reader/app.h
|
app_headers += apps/reader/app.h
|
||||||
|
|
||||||
app_sreader_src = $(addprefix apps/reader/,\
|
app_sreader_src = $(addprefix apps/reader/,\
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "apps/i18n.h"
|
#include "apps/i18n.h"
|
||||||
|
|
||||||
|
|
||||||
namespace reader {
|
namespace Reader {
|
||||||
|
|
||||||
I18n::Message App::Descriptor::name() {
|
I18n::Message App::Descriptor::name() {
|
||||||
return I18n::Message::ReaderApp;
|
return I18n::Message::ReaderApp;
|
||||||
@@ -32,7 +32,8 @@ App::Descriptor * App::Snapshot::descriptor() {
|
|||||||
App::App(Snapshot * snapshot) :
|
App::App(Snapshot * snapshot) :
|
||||||
::App(snapshot, &m_stackViewController),
|
::App(snapshot, &m_stackViewController),
|
||||||
m_listBookController(&m_stackViewController),
|
m_listBookController(&m_stackViewController),
|
||||||
m_stackViewController(nullptr, &m_listBookController)
|
m_alternateEmptyViewController(&m_stackViewController, &m_listBookController, &m_listBookController),
|
||||||
|
m_stackViewController(&m_modalViewController, &m_alternateEmptyViewController)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <escher.h>
|
#include <escher.h>
|
||||||
#include "list_book_controller.h"
|
#include "list_book_controller.h"
|
||||||
|
|
||||||
namespace reader {
|
namespace Reader {
|
||||||
|
|
||||||
class App : public ::App {
|
class App : public ::App {
|
||||||
public:
|
public:
|
||||||
@@ -22,6 +22,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
App(Snapshot * snapshot);
|
App(Snapshot * snapshot);
|
||||||
ListBookController m_listBookController;
|
ListBookController m_listBookController;
|
||||||
|
AlternateEmptyViewController m_alternateEmptyViewController;
|
||||||
StackViewController m_stackViewController;
|
StackViewController m_stackViewController;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Leser"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "LESER"
|
||||||
NoFileToDisplay = "Keine Dateien zum Anzeigen!"
|
NoFileToDisplay = "Keine Dateien zum Anzeigen"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Reader"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "READER"
|
||||||
NoFileToDisplay = "No file to display!"
|
NoFileToDisplay = "No file to display"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Lector"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "LECTOR"
|
||||||
NoFileToDisplay ="No hay archivos para mostrar!"
|
NoFileToDisplay ="No hay archivos para mostrar"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Liseuse"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "LISEUSE"
|
||||||
NoFileToDisplay = "Aucun fichier à afficher!"
|
NoFileToDisplay = "Aucun fichier à afficher"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Olvasó"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "OLVASÓ"
|
||||||
NoFileToDisplay ="Nincs megjeleníthető fájl"
|
NoFileToDisplay = "Nincs megjeleníthető fájl"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Lettore"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "LETTORE"
|
||||||
NoFileToDisplay ="essun file da visualizzare"
|
NoFileToDisplay = "essun file da visualizzare"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Lezer"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "LEZER"
|
||||||
NoFileToDisplay ="Geen bestanden om weer te geven"
|
NoFileToDisplay = "Geen bestanden om weer te geven"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
ReaderApp = "Reader"
|
ReaderApp = "Leitor"
|
||||||
ReaderAppCapital = "READER"
|
ReaderAppCapital = "LEITOR"
|
||||||
NoFileToDisplay ="Nenhum arquivo para exibir"
|
NoFileToDisplay = "Nenhum arquivo para exibir"
|
||||||
@@ -1,102 +1,100 @@
|
|||||||
#include "list_book_controller.h"
|
#include "list_book_controller.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include <escher/metric.h>
|
||||||
#include "apps/i18n.h"
|
#include "apps/i18n.h"
|
||||||
|
|
||||||
namespace reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
View* ListBookController::view()
|
View* ListBookController::view() {
|
||||||
{
|
return &m_tableView;
|
||||||
return &m_tableView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListBookController::ListBookController(Responder * parentResponder):
|
ListBookController::ListBookController(Responder * parentResponder):
|
||||||
ViewController(parentResponder),
|
ViewController(parentResponder),
|
||||||
m_tableView(this, this, this),
|
m_tableView(this, this, this),
|
||||||
m_readBookController(this)
|
m_readBookController(this)
|
||||||
{
|
{
|
||||||
m_nbFiles = filesWithExtension(".txt", m_files, NB_FILES);
|
m_filesNumber = filesWithExtension(".txt", m_files, k_maxFilesNumber);
|
||||||
cleanRemovedBookRecord();
|
cleanRemovedBookRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ListBookController::numberOfRows() const
|
int ListBookController::numberOfRows() const {
|
||||||
{
|
return m_filesNumber;
|
||||||
return m_nbFiles;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KDCoordinate ListBookController::cellHeight()
|
KDCoordinate ListBookController::cellHeight() {
|
||||||
{
|
return Metric::StoreRowHeight;
|
||||||
return 50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HighlightCell * ListBookController::reusableCell(int index)
|
HighlightCell * ListBookController::reusableCell(int index) {
|
||||||
{
|
return &m_cells[index];
|
||||||
return &m_cells[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ListBookController::reusableCellCount() const
|
int ListBookController::reusableCellCount() const {
|
||||||
{
|
return k_cellsNumber;
|
||||||
return NB_CELLS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListBookController::willDisplayCellForIndex(HighlightCell * cell, int index)
|
void ListBookController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||||
{
|
MessageTableCell* myTextCell = static_cast<MessageTableCell*>(cell);
|
||||||
MessageTableCell* myTextCell = static_cast<MessageTableCell*>(cell);
|
MessageTextView* textView = static_cast<MessageTextView*>(myTextCell->labelView());
|
||||||
MessageTextView* textView = static_cast<MessageTextView*>(myTextCell->labelView());
|
textView->setText(m_files[index].name);
|
||||||
textView->setText(m_files[index].name);
|
myTextCell->setMessageFont(KDFont::LargeFont); //TODO set cell font at building ?
|
||||||
myTextCell->setMessageFont(KDFont::LargeFont);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListBookController::didBecomeFirstResponder()
|
void ListBookController::didBecomeFirstResponder() {
|
||||||
{
|
if (selectedRow() < 0) {
|
||||||
if (selectedRow() < 0) {
|
selectCellAtLocation(0, 0);
|
||||||
selectCellAtLocation(0, 0);
|
}
|
||||||
}
|
Container::activeApp()->setFirstResponder(&m_tableView);
|
||||||
Container::activeApp()->setFirstResponder(&m_tableView);
|
}
|
||||||
if(m_nbFiles == 0)
|
|
||||||
|
bool ListBookController::handleEvent(Ion::Events::Event event) {
|
||||||
|
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right)
|
||||||
|
{
|
||||||
|
m_readBookController.setBook(m_files[selectedRow()]);
|
||||||
|
static_cast<StackViewController*>(parentResponder())->push(&m_readBookController);
|
||||||
|
Container::activeApp()->setFirstResponder(&m_readBookController);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ListBookController::hasBook(const char* filename) const {
|
||||||
|
for(int i=0;i<m_filesNumber;i++)
|
||||||
|
{
|
||||||
|
if(strcmp(m_files[i].name, filename) == 0)
|
||||||
{
|
{
|
||||||
Container::activeApp()->displayWarning(I18n::Message::NoFileToDisplay);
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ListBookController::handleEvent(Ion::Events::Event event)
|
void ListBookController::cleanRemovedBookRecord() {
|
||||||
{
|
|
||||||
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right)
|
|
||||||
{
|
|
||||||
|
|
||||||
m_readBookController.setBook(m_files[selectedRow()]);
|
|
||||||
static_cast<StackViewController*>(parentResponder())->push(&m_readBookController);
|
|
||||||
Container::activeApp()->setFirstResponder(&m_readBookController);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ListBookController::hasBook(const char* filename) const
|
|
||||||
{
|
|
||||||
for(int i=0;i<m_nbFiles;i++)
|
|
||||||
{
|
|
||||||
if(strcmp(m_files[i].name, filename) == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ListBookController::cleanRemovedBookRecord()
|
|
||||||
{
|
|
||||||
int nb = Ion::Storage::sharedStorage()->numberOfRecordsWithExtension("txt");
|
int nb = Ion::Storage::sharedStorage()->numberOfRecordsWithExtension("txt");
|
||||||
for(int i=0; i<nb; i++)
|
for(int i=0; i<nb; i++)
|
||||||
{
|
{
|
||||||
Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordWithExtensionAtIndex("txt", i);
|
Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordWithExtensionAtIndex("txt", i);
|
||||||
if(!hasBook(r.fullName()))
|
if(!hasBook(r.fullName()))
|
||||||
{
|
{
|
||||||
r.destroy();
|
r.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ListBookController::isEmpty() const {
|
||||||
|
return m_filesNumber == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
I18n::Message ListBookController::emptyMessage() {
|
||||||
|
return I18n::Message::NoFileToDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
Responder * ListBookController::defaultController() {
|
||||||
|
return parentResponder();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,35 +6,35 @@
|
|||||||
|
|
||||||
#include "read_book_controller.h"
|
#include "read_book_controller.h"
|
||||||
|
|
||||||
namespace reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
class ListBookController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource
|
class ListBookController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource, public AlternateEmptyViewDefaultDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ListBookController(Responder * parentResponder);
|
ListBookController(Responder * parentResponder);
|
||||||
View* view() override;
|
View* view() override;
|
||||||
|
|
||||||
int numberOfRows() const override;
|
int numberOfRows() const override;
|
||||||
KDCoordinate cellHeight() override;
|
KDCoordinate cellHeight() override;
|
||||||
HighlightCell * reusableCell(int index) override;
|
HighlightCell * reusableCell(int index) override;
|
||||||
int reusableCellCount() const override;
|
int reusableCellCount() const override;
|
||||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||||
void didBecomeFirstResponder() override;
|
void didBecomeFirstResponder() override;
|
||||||
bool handleEvent(Ion::Events::Event event) override;
|
bool handleEvent(Ion::Events::Event event) override;
|
||||||
bool hasBook(const char* filename) const;
|
bool hasBook(const char* filename) const;
|
||||||
void cleanRemovedBookRecord();
|
void cleanRemovedBookRecord();
|
||||||
|
bool isEmpty() const override;
|
||||||
|
I18n::Message emptyMessage() override;
|
||||||
|
Responder * defaultController() override;
|
||||||
private:
|
private:
|
||||||
SelectableTableView m_tableView;
|
SelectableTableView m_tableView;
|
||||||
|
static const int k_maxFilesNumber = 20;
|
||||||
static const int NB_FILES = 20;
|
External::Archive::File m_files[k_maxFilesNumber];
|
||||||
External::Archive::File m_files[NB_FILES];
|
int m_filesNumber = 0;
|
||||||
int m_nbFiles = 0;
|
static const int k_cellsNumber = 6;
|
||||||
|
MessageTableCellWithChevron m_cells[k_cellsNumber];
|
||||||
static const int NB_CELLS = 6;
|
ReadBookController m_readBookController;
|
||||||
MessageTableCell m_cells[NB_CELLS];
|
|
||||||
|
|
||||||
ReadBookController m_readBookController;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "read_book_controller.h"
|
#include "read_book_controller.h"
|
||||||
|
|
||||||
namespace reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
ReadBookController::ReadBookController(Responder * parentResponder) :
|
ReadBookController::ReadBookController(Responder * parentResponder) :
|
||||||
@@ -8,60 +8,49 @@ ReadBookController::ReadBookController(Responder * parentResponder) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
View * ReadBookController::view()
|
View * ReadBookController::view() {
|
||||||
{
|
|
||||||
return &m_readerView;
|
return &m_readerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadBookController::setBook(const External::Archive::File& file)
|
void ReadBookController::setBook(const External::Archive::File& file) {
|
||||||
{
|
m_file = &file;
|
||||||
m_file = &file;
|
loadPosition();
|
||||||
loadPosition();
|
m_readerView.setText(reinterpret_cast<const char*>(file.data), file.dataLength);
|
||||||
m_readerView.setText(reinterpret_cast<const char*>(file.data), file.dataLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadBookController::handleEvent(Ion::Events::Event event)
|
bool ReadBookController::handleEvent(Ion::Events::Event event) {
|
||||||
{
|
if(event == Ion::Events::Down) {
|
||||||
if(event == Ion::Events::Down)
|
m_readerView.nextPage();
|
||||||
{
|
return true;
|
||||||
m_readerView.nextPage();
|
}
|
||||||
return true;
|
if(event == Ion::Events::Up) {
|
||||||
}
|
m_readerView.previousPage();
|
||||||
if(event == Ion::Events::Up)
|
return true;
|
||||||
{
|
}
|
||||||
m_readerView.previousPage();
|
if(event == Ion::Events::Back || event == Ion::Events::Home) {
|
||||||
return true;
|
savePosition();
|
||||||
}
|
}
|
||||||
if(event == Ion::Events::Back || event == Ion::Events::Home)
|
return false;
|
||||||
{
|
|
||||||
savePosition();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadBookController::savePosition() const
|
void ReadBookController::savePosition() const {
|
||||||
{
|
|
||||||
int pageOffset = m_readerView.getPageOffset();
|
int pageOffset = m_readerView.getPageOffset();
|
||||||
Ion::Storage::Record::ErrorStatus status = Ion::Storage::sharedStorage()->createRecordWithFullName(m_file->name, &pageOffset, sizeof(pageOffset));
|
Ion::Storage::Record::ErrorStatus status = Ion::Storage::sharedStorage()->createRecordWithFullName(m_file->name, &pageOffset, sizeof(pageOffset));
|
||||||
if(Ion::Storage::Record::ErrorStatus::NameTaken == status)
|
if(Ion::Storage::Record::ErrorStatus::NameTaken == status) {
|
||||||
{
|
Ion::Storage::Record::Data data;
|
||||||
Ion::Storage::Record::Data data;
|
data.buffer = &pageOffset;
|
||||||
data.buffer = &pageOffset;
|
data.size = sizeof(pageOffset);
|
||||||
data.size = sizeof(pageOffset);
|
status = Ion::Storage::sharedStorage()->recordNamed(m_file->name).setValue(data);
|
||||||
status = Ion::Storage::sharedStorage()->recordNamed(m_file->name).setValue(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadBookController::loadPosition()
|
void ReadBookController::loadPosition() {
|
||||||
{
|
|
||||||
Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordNamed(m_file->name);
|
Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordNamed(m_file->name);
|
||||||
if(Ion::Storage::sharedStorage()->hasRecord(r))
|
if(Ion::Storage::sharedStorage()->hasRecord(r)) {
|
||||||
{
|
|
||||||
int pageOffset = *(static_cast<const int*>(r.value().buffer));
|
int pageOffset = *(static_cast<const int*>(r.value().buffer));
|
||||||
m_readerView.setPageOffset(pageOffset);
|
m_readerView.setPageOffset(pageOffset);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
m_readerView.setPageOffset(0);
|
m_readerView.setPageOffset(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "apps/external/archive.h"
|
#include "apps/external/archive.h"
|
||||||
#include "word_wrap_view.h"
|
#include "word_wrap_view.h"
|
||||||
|
|
||||||
namespace reader {
|
namespace Reader {
|
||||||
|
|
||||||
class ReadBookController : public ViewController {
|
class ReadBookController : public ViewController {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -8,109 +8,100 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
bool stringEndsWith(const char* str, const char* pattern)
|
bool stringEndsWith(const char* str, const char* pattern) {
|
||||||
{
|
int strLength = strlen(str);
|
||||||
int strLength = strlen(str);
|
int patternLength = strlen(pattern);
|
||||||
int patternLength = strlen(pattern);
|
if (patternLength > strLength) {
|
||||||
if (patternLength > strLength)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const char* strIter = str + strlen(str);
|
|
||||||
const char* patternIter = pattern + strlen(pattern);
|
|
||||||
|
|
||||||
while(*strIter == *patternIter)
|
|
||||||
{
|
|
||||||
if(patternIter == pattern)
|
|
||||||
return true;
|
|
||||||
strIter--;
|
|
||||||
patternIter--;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* strIter = str + strlen(str);
|
||||||
|
const char* patternIter = pattern + strlen(pattern);
|
||||||
|
|
||||||
|
while(*strIter == *patternIter) {
|
||||||
|
if(patternIter == pattern) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
strIter--;
|
||||||
|
patternIter--;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stringNCopy(char* dest, int max, const char* src, int len)
|
void stringNCopy(char* dest, int max, const char* src, int len) {
|
||||||
{
|
while(len>0 && max >1 && *src)
|
||||||
while(len>0 && max >1 && *src)
|
{
|
||||||
{
|
*dest = *src;
|
||||||
*dest = *src;
|
dest++;
|
||||||
dest++;
|
src++;
|
||||||
src++;
|
len--;
|
||||||
len--;
|
max--;
|
||||||
max--;
|
}
|
||||||
}
|
*dest=0;
|
||||||
*dest=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEVICE
|
#ifdef DEVICE
|
||||||
|
|
||||||
int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize)
|
int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) {
|
||||||
{
|
size_t nbTotalFiles = External::Archive::numberOfFiles();
|
||||||
size_t nbTotalFiles = External::Archive::numberOfFiles();
|
int nbFiles = 0;
|
||||||
int nbFiles = 0;
|
for(size_t i=0; i < nbTotalFiles; ++i)
|
||||||
for(size_t i=0; i < nbTotalFiles; ++i)
|
{
|
||||||
|
External::Archive::File file;
|
||||||
|
External::Archive::fileAtIndex(i, file);
|
||||||
|
if(stringEndsWith(file.name, ".txt"))
|
||||||
{
|
{
|
||||||
External::Archive::File file;
|
files[nbFiles] = file;
|
||||||
External::Archive::fileAtIndex(i, file);
|
nbFiles++;
|
||||||
if(stringEndsWith(file.name, ".txt"))
|
if(nbFiles == filesSize)
|
||||||
{
|
break;
|
||||||
files[nbFiles] = file;
|
|
||||||
nbFiles++;
|
|
||||||
if(nbFiles == filesSize)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nbFiles;
|
}
|
||||||
|
return nbFiles;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void fillFileData(External::Archive::File& file)
|
static void fillFileData(External::Archive::File& file) {
|
||||||
{
|
file.data = nullptr;
|
||||||
file.data = nullptr;
|
file.dataLength = 0;
|
||||||
file.dataLength = 0;
|
|
||||||
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
if (stat(file.name, &info) != 0)
|
if (stat(file.name, &info) != 0) {
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
unsigned char* content = new unsigned char[info.st_size];
|
||||||
unsigned char* content = new unsigned char[info.st_size];
|
if (content == NULL) {
|
||||||
if (content == NULL)
|
return;
|
||||||
{
|
}
|
||||||
return ;
|
FILE *fp = fopen(file.name, "rb");
|
||||||
}
|
if (fp == NULL) {
|
||||||
FILE *fp = fopen(file.name, "rb");
|
return ;
|
||||||
if (fp == NULL)
|
}
|
||||||
{
|
|
||||||
return ;
|
fread(content, info.st_size, 1, fp);
|
||||||
}
|
fclose(fp);
|
||||||
|
file.data = content;
|
||||||
fread(content, info.st_size, 1, fp);
|
file.dataLength = info.st_size;
|
||||||
fclose(fp);
|
|
||||||
file.data = content;
|
|
||||||
file.dataLength = info.st_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize)
|
int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) {
|
||||||
{
|
|
||||||
dirent *file;
|
dirent *file;
|
||||||
DIR *d = opendir(".");
|
DIR *d = opendir(".");
|
||||||
int nb = 0;
|
int nb = 0;
|
||||||
if (d)
|
if (d) {
|
||||||
{
|
while ((file = readdir(d)) != NULL) {
|
||||||
while ((file = readdir(d)) != NULL)
|
if(stringEndsWith(file->d_name, extension)) {
|
||||||
{
|
|
||||||
if(stringEndsWith(file->d_name, extension))
|
|
||||||
{
|
|
||||||
files[nb].name = strdup(file->d_name);//will probably leak
|
files[nb].name = strdup(file->d_name);//will probably leak
|
||||||
fillFileData(files[nb]);
|
fillFileData(files[nb]);
|
||||||
nb++;
|
nb++;
|
||||||
if(nb == filesSize)
|
if(nb == filesSize) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
#include <apps/external/archive.h>
|
#include <apps/external/archive.h>
|
||||||
|
|
||||||
namespace reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
bool stringEndsWith(const char* str, const char* end);
|
bool stringEndsWith(const char* str, const char* end);
|
||||||
int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) ;
|
int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize);
|
||||||
void stringNCopy(char* dest, int max, const char* src, int len);
|
void stringNCopy(char* dest, int max, const char* src, int len);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,155 +2,138 @@
|
|||||||
|
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
namespace reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
void WordWrapTextView::nextPage()
|
void WordWrapTextView::nextPage() {
|
||||||
{
|
if(m_nextPageOffset >= m_length) {
|
||||||
if(m_nextPageOffset >= m_length)
|
return;
|
||||||
return;
|
}
|
||||||
m_pageOffset = m_nextPageOffset;
|
m_pageOffset = m_nextPageOffset;
|
||||||
markRectAsDirty(bounds());
|
markRectAsDirty(bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WordWrapTextView::setText(const char* text, int length)
|
void WordWrapTextView::setText(const char* text, int length) {
|
||||||
{
|
PointerTextView::setText(text);
|
||||||
PointerTextView::setText(text);
|
m_length = length;
|
||||||
m_length = length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WordWrapTextView::previousPage()
|
void WordWrapTextView::previousPage() {
|
||||||
{
|
if(m_pageOffset <= 0) {
|
||||||
if(m_pageOffset <= 0)
|
return;
|
||||||
return;
|
}
|
||||||
|
const int spaceWidth = m_font->stringSize(" ").width();
|
||||||
|
|
||||||
const int spaceWidth = m_font->stringSize(" ").width();
|
const char * endOfWord = text() + m_pageOffset;
|
||||||
|
const char * startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord);
|
||||||
|
|
||||||
|
KDPoint textPosition(m_frame.width() - margin, m_frame.height() - margin);
|
||||||
|
|
||||||
const char * endOfWord = text() + m_pageOffset;
|
while(startOfWord>=text()) {
|
||||||
const char * startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord);
|
endOfWord = UTF8Helper::EndOfWord(startOfWord);
|
||||||
|
KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord);
|
||||||
|
KDPoint previousTextPosition = KDPoint(textPosition.x()-textSize.width(), textPosition.y());
|
||||||
|
|
||||||
KDPoint textPosition(m_frame.width() - margin, m_frame.height() - margin);
|
if(previousTextPosition.x() < margin) {
|
||||||
|
textPosition = KDPoint(m_frame.width() - margin, textPosition.y() - textSize.height());
|
||||||
|
previousTextPosition = KDPoint(textPosition.x() - textSize.width(), textPosition.y());
|
||||||
|
}
|
||||||
|
if(textPosition.y() - textSize.height() < margin) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
while(startOfWord>=text())
|
|
||||||
{
|
|
||||||
endOfWord = UTF8Helper::EndOfWord(startOfWord);
|
|
||||||
KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord);
|
|
||||||
KDPoint previousTextPosition = KDPoint(textPosition.x()-textSize.width(), textPosition.y());
|
|
||||||
|
|
||||||
if(previousTextPosition.x() < margin)
|
|
||||||
{
|
|
||||||
textPosition = KDPoint(m_frame.width() - margin, textPosition.y() - textSize.height());
|
|
||||||
previousTextPosition = KDPoint(textPosition.x() - textSize.width(), textPosition.y());
|
|
||||||
}
|
|
||||||
if(textPosition.y() - textSize.height() < margin)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
--startOfWord;
|
|
||||||
while(startOfWord >= text() && *startOfWord == ' ')
|
|
||||||
{
|
|
||||||
previousTextPosition = KDPoint(previousTextPosition.x() - spaceWidth, previousTextPosition.y());
|
|
||||||
--startOfWord;
|
|
||||||
}
|
|
||||||
if(previousTextPosition.x() < margin)
|
|
||||||
{
|
|
||||||
previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while(startOfWord >= text() && *startOfWord == '\n')
|
--startOfWord;
|
||||||
{
|
while(startOfWord >= text() && *startOfWord == ' ') {
|
||||||
previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height());
|
previousTextPosition = KDPoint(previousTextPosition.x() - spaceWidth, previousTextPosition.y());
|
||||||
--startOfWord;
|
--startOfWord;
|
||||||
}
|
|
||||||
|
|
||||||
if(previousTextPosition.y() - textSize.height() < margin)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
textPosition = previousTextPosition;
|
|
||||||
endOfWord = startOfWord;
|
|
||||||
startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord);
|
|
||||||
}
|
}
|
||||||
if(startOfWord == text())
|
if(previousTextPosition.x() < margin) {
|
||||||
m_pageOffset = 0;
|
previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height());
|
||||||
else
|
|
||||||
m_pageOffset = UTF8Helper::EndOfWord(startOfWord) - text() + 1;
|
|
||||||
markRectAsDirty(bounds());
|
|
||||||
}
|
|
||||||
|
|
||||||
void WordWrapTextView::drawRect(KDContext * ctx, KDRect rect) const
|
|
||||||
{
|
|
||||||
ctx->fillRect(KDRect(0, 0, bounds().width(), bounds().height()), m_backgroundColor);
|
|
||||||
|
|
||||||
const char * endOfFile = text() + m_length;
|
|
||||||
const char * startOfWord = text() + m_pageOffset;
|
|
||||||
const char * endOfWord = UTF8Helper::EndOfWord(startOfWord);
|
|
||||||
KDPoint textPosition(margin, margin);
|
|
||||||
|
|
||||||
const int wordMaxLength = 128;
|
|
||||||
char word[wordMaxLength];
|
|
||||||
|
|
||||||
const int spaceWidth = m_font->stringSize(" ").width();
|
|
||||||
|
|
||||||
while(startOfWord < endOfFile)
|
|
||||||
{
|
|
||||||
|
|
||||||
KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord);
|
|
||||||
KDPoint nextTextPosition = KDPoint(textPosition.x()+textSize.width(), textPosition.y());
|
|
||||||
|
|
||||||
if(nextTextPosition.x() > m_frame.width() - margin)
|
|
||||||
{
|
|
||||||
textPosition = KDPoint(margin, textPosition.y() + textSize.height());
|
|
||||||
nextTextPosition = KDPoint(margin + textSize.width(), textPosition.y());
|
|
||||||
}
|
|
||||||
if(textPosition.y() + textSize.height() > m_frame.height() - margin)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
stringNCopy(word, wordMaxLength, startOfWord, endOfWord-startOfWord);
|
|
||||||
ctx->drawString(word, textPosition, m_font, m_textColor, m_backgroundColor);
|
|
||||||
|
|
||||||
while(*endOfWord == ' ')
|
|
||||||
{
|
|
||||||
nextTextPosition = KDPoint(nextTextPosition.x() + spaceWidth, nextTextPosition.y());
|
|
||||||
++endOfWord;
|
|
||||||
}
|
|
||||||
if(nextTextPosition.x() > m_frame.width() - margin)
|
|
||||||
{
|
|
||||||
nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
while(*endOfWord == '\n')
|
|
||||||
{
|
|
||||||
nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height());
|
|
||||||
++endOfWord;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nextTextPosition.y() + textSize.height() > m_frame.height() - margin)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
textPosition = nextTextPosition;
|
|
||||||
startOfWord = endOfWord;
|
|
||||||
endOfWord = UTF8Helper::EndOfWord(startOfWord);
|
|
||||||
}
|
}
|
||||||
m_nextPageOffset = startOfWord - text();
|
|
||||||
|
|
||||||
|
while(startOfWord >= text() && *startOfWord == '\n') {
|
||||||
|
previousTextPosition = KDPoint(m_frame.width() - margin, previousTextPosition.y() - textSize.height());
|
||||||
|
--startOfWord;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(previousTextPosition.y() - textSize.height() < margin) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
textPosition = previousTextPosition;
|
||||||
|
endOfWord = startOfWord;
|
||||||
|
startOfWord = UTF8Helper::BeginningOfWord(text(), endOfWord);
|
||||||
|
}
|
||||||
|
if(startOfWord == text()) {
|
||||||
|
m_pageOffset = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_pageOffset = UTF8Helper::EndOfWord(startOfWord) - text() + 1;
|
||||||
|
}
|
||||||
|
markRectAsDirty(bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
int WordWrapTextView::getPageOffset() const
|
void WordWrapTextView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||||
{
|
ctx->fillRect(KDRect(0, 0, bounds().width(), bounds().height()), m_backgroundColor);
|
||||||
return m_pageOffset;
|
|
||||||
|
const char * endOfFile = text() + m_length;
|
||||||
|
const char * startOfWord = text() + m_pageOffset;
|
||||||
|
const char * endOfWord = UTF8Helper::EndOfWord(startOfWord);
|
||||||
|
KDPoint textPosition(margin, margin);
|
||||||
|
|
||||||
|
const int wordMaxLength = 128;
|
||||||
|
char word[wordMaxLength];
|
||||||
|
|
||||||
|
const int spaceWidth = m_font->stringSize(" ").width();
|
||||||
|
|
||||||
|
while(startOfWord < endOfFile) {
|
||||||
|
|
||||||
|
KDSize textSize = m_font->stringSizeUntil(startOfWord, endOfWord);
|
||||||
|
KDPoint nextTextPosition = KDPoint(textPosition.x()+textSize.width(), textPosition.y());
|
||||||
|
|
||||||
|
if(nextTextPosition.x() > m_frame.width() - margin) {
|
||||||
|
textPosition = KDPoint(margin, textPosition.y() + textSize.height());
|
||||||
|
nextTextPosition = KDPoint(margin + textSize.width(), textPosition.y());
|
||||||
|
}
|
||||||
|
if(textPosition.y() + textSize.height() > m_frame.height() - margin) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
stringNCopy(word, wordMaxLength, startOfWord, endOfWord-startOfWord);
|
||||||
|
ctx->drawString(word, textPosition, m_font, m_textColor, m_backgroundColor);
|
||||||
|
|
||||||
|
while(*endOfWord == ' ') {
|
||||||
|
nextTextPosition = KDPoint(nextTextPosition.x() + spaceWidth, nextTextPosition.y());
|
||||||
|
++endOfWord;
|
||||||
|
}
|
||||||
|
if(nextTextPosition.x() > m_frame.width() - margin) {
|
||||||
|
nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
while(*endOfWord == '\n') {
|
||||||
|
nextTextPosition = KDPoint(margin, nextTextPosition.y() + textSize.height());
|
||||||
|
++endOfWord;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nextTextPosition.y() + textSize.height() > m_frame.height() - margin) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
textPosition = nextTextPosition;
|
||||||
|
startOfWord = endOfWord;
|
||||||
|
endOfWord = UTF8Helper::EndOfWord(startOfWord);
|
||||||
|
}
|
||||||
|
m_nextPageOffset = startOfWord - text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WordWrapTextView::setPageOffset(int o)
|
int WordWrapTextView::getPageOffset() const {
|
||||||
{
|
return m_pageOffset;
|
||||||
m_pageOffset = o;
|
}
|
||||||
|
|
||||||
|
void WordWrapTextView::setPageOffset(int o) {
|
||||||
|
m_pageOffset = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,23 +3,23 @@
|
|||||||
|
|
||||||
#include <escher.h>
|
#include <escher.h>
|
||||||
|
|
||||||
namespace reader
|
namespace Reader
|
||||||
{
|
{
|
||||||
|
|
||||||
class WordWrapTextView : public PointerTextView {
|
class WordWrapTextView : public PointerTextView {
|
||||||
public:
|
public:
|
||||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||||
void setText(const char*, int length);
|
void setText(const char*, int length);
|
||||||
void nextPage();
|
void nextPage();
|
||||||
void previousPage();
|
void previousPage();
|
||||||
int getPageOffset() const;
|
int getPageOffset() const;
|
||||||
void setPageOffset(int o);
|
void setPageOffset(int o);
|
||||||
protected:
|
protected:
|
||||||
int m_pageOffset = 0;
|
int m_pageOffset = 0;
|
||||||
mutable int m_nextPageOffset = 0;
|
mutable int m_nextPageOffset = 0;
|
||||||
int m_length = 0;
|
int m_length = 0;
|
||||||
|
|
||||||
static const int margin = 10;
|
static const int margin = 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ const char * AlternateEmptyViewController::title() {
|
|||||||
bool AlternateEmptyViewController::handleEvent(Ion::Events::Event event) {
|
bool AlternateEmptyViewController::handleEvent(Ion::Events::Event event) {
|
||||||
if (m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
|
if (m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
|
||||||
if (event != Ion::Events::Home && event != Ion::Events::OnOff) {
|
if (event != Ion::Events::Home && event != Ion::Events::OnOff) {
|
||||||
m_contentView.alternateEmptyViewDelegate()->defaultController()->handleEvent(Ion::Events::Back);
|
return m_contentView.alternateEmptyViewDelegate()->defaultController()->handleEvent(Ion::Events::Back);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user