Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread_view.cpp
More file actions
Latest commit
140 lines (117 loc) · 3.4 KB
/
Copy pathread_view.cpp
File metadata and controls
140 lines (117 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include"read_view.h"
#include<QDir>
#include<QDebug>
#include<QTextCodec>
#include<QSqlDatabase>
#include<QStandardPaths>
Read_View::Read_View(QObject *parent) : QObject(parent)
{
m_currentBook=0;
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF8")); // 改为GBK编码
loadDir();
}
QQmlListProperty<Reader_Book> Read_View::books()
{
return QQmlListProperty<Reader_Book>(this,this,
&Read_View::appendBooks,
&Read_View::booksCount,
&Read_View::booksAt,
&Read_View::clearBooks
);
}
intRead_View::booksCount()
{
//qDebug() << "books:" << Book_shelf.count();
return Book_shelf.count();
}
voidRead_View::appendBooks(Reader_Book *chapter)
{
Book_shelf.append(chapter);
}
Reader_Book *Read_View::booksAt(int index)
{
if(index>=0 && Book_shelf.size()>index){
qDebug() << Book_shelf.at(index);
return Book_shelf.at(index);
}else{
returnnullptr;
}
}
voidRead_View::clearBooks()
{
for(int i=0;i<Book_shelf.count();i++){
delete Book_shelf[i];
}
Book_shelf.clear();
}
voidRead_View::sorted()
{
//排序
return ;
}
intRead_View::currentBook()
{
return m_currentBook;
}
voidRead_View::setCurrentBook(int index)
{
if(index==m_currentBook)return;
m_currentBook=index;
currentBookChanged(index);
}
voidRead_View::loadDir(QString path)
{
//path=QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first();
//path="/storage/emulated/0/book/";
QDir Dir(path);
if(!Dir.exists()){
qDebug() << " error error path";
return ;
}else {
qDebug() << path <<Dir.count();
}
for (unsigned i=0;i<Dir.count();i++) {
loadBook(Dir.absolutePath()+"/"+Dir[i]+"/",Dir[i],i);
//qDebug() << Dir[i];
}
}
voidRead_View::loadBook(QString path,QString name,int index)
{
QDir Dir(path);
if(!Dir.exists()){
qDebug() << " error error path";
}else {
qDebug() << path;
}
QString temContent; //章节内容
QString temName; //章节目录
Reader_Book *temBook=new Reader_Book;
for (unsigned i=0;i<Dir.count()-1;i++) {
temName=Dir.absolutePath()+"/"+Dir[i]; //读取章节
qDebug() << temName;
// 问题?读取时只从文件名开头数字最小的开始读取,如开头为20和100,会先读取100
Book_chapter *chapt=newBook_chapter(temName,Dir[i]); //把每本小说的所有章节的所在目录和章节名字一起放入chapt中
temBook->appendChart(chapt);
}
temBook->setBookSource(path);
temBook->setBookName(name);
temBook->setindex(index);
temBook->setimage(Dir.absolutePath()+"/"+name+".jpg");
Book_shelf.append(temBook);
}
voidRead_View::appendBooks(QQmlListProperty<Reader_Book> *list, Reader_Book *book)
{
reinterpret_cast<Read_View*>(list->data)->appendBooks(book);
}
intRead_View::booksCount(QQmlListProperty<Reader_Book> *list)
{
returnreinterpret_cast<Read_View*>(list->data)->booksCount();
}
Reader_Book *Read_View::booksAt(QQmlListProperty<Reader_Book> *list, int index)
{
returnreinterpret_cast<Read_View*>(list->data)->booksAt(index);
}
voidRead_View::clearBooks(QQmlListProperty<Reader_Book> *list)
{
returnreinterpret_cast<Read_View*>(list->data)->clearBooks();
}