mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
saving
This commit is contained in:
@@ -16,6 +16,7 @@ ListBookController::ListBookController(Responder * parentResponder):
|
||||
m_readBookController(this)
|
||||
{
|
||||
m_nbFiles = filesWithExtension(".txt", m_files, NB_FILES);
|
||||
cleanRemovedBookRecord();
|
||||
}
|
||||
|
||||
int ListBookController::numberOfRows() const
|
||||
@@ -72,4 +73,30 @@ bool ListBookController::handleEvent(Ion::Events::Event event)
|
||||
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");
|
||||
for(int i=0; i<nb; i++)
|
||||
{
|
||||
Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordWithExtensionAtIndex("txt", i);
|
||||
if(!hasBook(r.fullName()))
|
||||
{
|
||||
r.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||
void didBecomeFirstResponder() override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
bool hasBook(const char* filename) const;
|
||||
void cleanRemovedBookRecord();
|
||||
private:
|
||||
SelectableTableView m_tableView;
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ View * ReadBookController::view()
|
||||
|
||||
void ReadBookController::setBook(const External::Archive::File& file)
|
||||
{
|
||||
m_file = &file;
|
||||
loadPosition();
|
||||
m_readerView.setText(reinterpret_cast<const char*>(file.data), file.dataLength);
|
||||
}
|
||||
|
||||
@@ -30,7 +32,38 @@ bool ReadBookController::handleEvent(Ion::Events::Event event)
|
||||
m_readerView.previousPage();
|
||||
return true;
|
||||
}
|
||||
if(event == Ion::Events::Back || event == Ion::Events::Home)
|
||||
{
|
||||
savePosition();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReadBookController::savePosition() const
|
||||
{
|
||||
int pageOffset = m_readerView.getPageOffset();
|
||||
Ion::Storage::Record::ErrorStatus status = Ion::Storage::sharedStorage()->createRecordWithFullName(m_file->name, &pageOffset, sizeof(pageOffset));
|
||||
if(Ion::Storage::Record::ErrorStatus::NameTaken == status)
|
||||
{
|
||||
Ion::Storage::Record::Data data;
|
||||
data.buffer = &pageOffset;
|
||||
data.size = sizeof(pageOffset);
|
||||
status = Ion::Storage::sharedStorage()->recordNamed(m_file->name).setValue(data);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadBookController::loadPosition()
|
||||
{
|
||||
Ion::Storage::Record r = Ion::Storage::sharedStorage()->recordNamed(m_file->name);
|
||||
if(Ion::Storage::sharedStorage()->hasRecord(r))
|
||||
{
|
||||
int pageOffset = *(static_cast<const int*>(r.value().buffer));
|
||||
m_readerView.setPageOffset(pageOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_readerView.setPageOffset(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,8 +14,12 @@ public:
|
||||
|
||||
void setBook(const External::Archive::File& file);
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
|
||||
void savePosition() const;
|
||||
void loadPosition();
|
||||
private:
|
||||
WordWrapTextView m_readerView;
|
||||
const External::Archive::File* m_file;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -146,4 +146,14 @@ void WordWrapTextView::drawRect(KDContext * ctx, KDRect rect) const
|
||||
m_nextPageOffset = startOfWord - text();
|
||||
}
|
||||
|
||||
int WordWrapTextView::getPageOffset() const
|
||||
{
|
||||
return m_pageOffset;
|
||||
}
|
||||
|
||||
void WordWrapTextView::setPageOffset(int o)
|
||||
{
|
||||
m_pageOffset = o;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,8 @@ public:
|
||||
void setText(const char*, int length);
|
||||
void nextPage();
|
||||
void previousPage();
|
||||
|
||||
int getPageOffset() const;
|
||||
void setPageOffset(int o);
|
||||
protected:
|
||||
int m_pageOffset = 0;
|
||||
mutable int m_nextPageOffset = 0;
|
||||
|
||||
Reference in New Issue
Block a user