mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Generaci?n preliminar del ?ndice alfabetico (web)
Ordenaci?n naturalSorting para el contenido + fusi?n de folders/comics Se han a?adido expresiones regulares para parsear las URIs
This commit is contained in:
parent
dc6fcf3677
commit
989b5704e2
@ -28,7 +28,7 @@ ComicDB::ComicDB(qulonglong cparentId, QString cname, QString cpath, QString cha
|
||||
_hasCover = true;
|
||||
}
|
||||
|
||||
QList<LibraryItem *> ComicDB::getComicsFromParent(qulonglong parentId, QSqlDatabase & db)
|
||||
QList<LibraryItem *> ComicDB::getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort)
|
||||
{
|
||||
QList<LibraryItem *> list;
|
||||
|
||||
@ -52,7 +52,7 @@ QList<LibraryItem *> ComicDB::getComicsFromParent(qulonglong parentId, QSqlDatab
|
||||
currentItem->path = record.value(3).toString();
|
||||
currentItem->info.load(record.value(4).toString(),db);
|
||||
int lessThan = 0;
|
||||
if(list.isEmpty())
|
||||
if(list.isEmpty() || !sort)
|
||||
list.append(currentItem);
|
||||
else
|
||||
{
|
||||
|
@ -123,7 +123,7 @@ public:
|
||||
ComicDB(qulonglong cparentId, QString cname, QString cpath, QString chash, QSqlDatabase & database);
|
||||
//Comic(QString fn, QString fp):name(fn),path(fp),knownParent(false), knownId(false){};
|
||||
|
||||
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase & db);
|
||||
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||
bool isDir();
|
||||
|
||||
bool load(qulonglong id, QSqlDatabase & db);
|
||||
|
@ -33,7 +33,7 @@ qulonglong Folder::insert(QSqlDatabase & db)
|
||||
return query.lastInsertId().toULongLong();
|
||||
}
|
||||
|
||||
QList<LibraryItem *> Folder::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db)
|
||||
QList<LibraryItem *> Folder::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort)
|
||||
{
|
||||
QList<LibraryItem *> list;
|
||||
|
||||
@ -52,7 +52,8 @@ QList<LibraryItem *> Folder::getFoldersFromParent(qulonglong parentId, QSqlDatab
|
||||
//TODO sort by sort indicator and name
|
||||
currentItem = new Folder(record.value("id").toULongLong(),record.value("parentId").toULongLong(),record.value("name").toString(),record.value("path").toString());
|
||||
int lessThan = 0;
|
||||
if(list.isEmpty())
|
||||
|
||||
if(list.isEmpty() || !sort)
|
||||
list.append(currentItem);
|
||||
else
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
Folder(qulonglong id, QSqlDatabase & db);//loads a folder from db;
|
||||
void setId(qulonglong sid){id = sid;knownId = true;};
|
||||
void setFather(qulonglong pid){parentId = pid;knownParent = true;};
|
||||
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db);
|
||||
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||
qulonglong insert(QSqlDatabase & db);
|
||||
bool isDir(){return true;};
|
||||
void removeFromDB(QSqlDatabase & db);
|
||||
|
@ -1347,7 +1347,7 @@ QList<LibraryItem *> LibraryWindow::getFolderContentFromLibrary(const QString &
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraries.value(libraryName)+"/.yacreaderlibrary");
|
||||
|
||||
QList<LibraryItem *> list = Folder::getFoldersFromParent(folderId,db);
|
||||
QList<LibraryItem *> list = Folder::getFoldersFromParent(folderId,db,false);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraries.value(libraryName));
|
||||
@ -1359,7 +1359,7 @@ QList<LibraryItem *> LibraryWindow::getFolderComicsFromLibrary(const QString & l
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraries.value(libraryName)+"/.yacreaderlibrary");
|
||||
|
||||
QList<LibraryItem *> list = ComicDB::getComicsFromParent(folderId,db);
|
||||
QList<LibraryItem *> list = ComicDB::getComicsFromParent(folderId,db,false);
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraries.value(libraryName));
|
||||
|
@ -6,6 +6,16 @@
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
struct LibraryItemSorter
|
||||
{
|
||||
bool operator()(const LibraryItem * a,const LibraryItem * b) const
|
||||
{
|
||||
return naturalSortLessThanCI(a->name,b->name);
|
||||
}
|
||||
};
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
FolderController::FolderController() {}
|
||||
@ -16,10 +26,8 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
|
||||
|
||||
|
||||
QString y = session.get("xxx").toString();
|
||||
response.writeText(QString("session xxx : %1 <br/>").arg(y));
|
||||
//response.writeText(QString("session xxx : %1 <br/>").arg(y));
|
||||
|
||||
Template t=Static::templateLoader->getTemplate("folder",request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
@ -30,6 +38,13 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
QList<LibraryItem *> folderContent = mw->getFolderContentFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderComics = mw->getFolderComicsFromLibrary(libraryName,parentId);
|
||||
|
||||
folderContent.append(folderComics);
|
||||
|
||||
qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter());
|
||||
folderComics.clear();
|
||||
|
||||
|
||||
|
||||
qulonglong backId = mw->getParentFromComicFolderId(libraryName,parentId);
|
||||
|
||||
|
||||
@ -72,7 +87,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
int numFolderPages = numFolders / 10 + ((numFolders%10)>0?1:0);
|
||||
int numPages = totalLength / 10 + ((totalLength%10)>0?1:0);
|
||||
|
||||
response.writeText(QString("Number of pages : %1 <br/>").arg(numPages));
|
||||
//response.writeText(QString("Number of pages : %1 <br/>").arg(numPages));
|
||||
|
||||
if(page < 0)
|
||||
page = 0;
|
||||
@ -90,9 +105,27 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
int i = 0;
|
||||
while(i<numFoldersAtCurrentPage)
|
||||
{
|
||||
LibraryItem * item = folderContent.at(i + (page*10));
|
||||
t.setVariable(QString("element%1.name").arg(i),folderContent.at(i + (page*10))->name);
|
||||
t.setVariable(QString("element%1.url").arg(i),"/library/"+libraryName+"/folder/"+QString("%1").arg(folderContent.at(i + (page*10))->id));
|
||||
t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*10))->id));
|
||||
if(item->isDir())
|
||||
{
|
||||
t.setVariable(QString("element%1.image.width").arg(i),"92px");
|
||||
t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||
|
||||
t.setVariable(QString("element%1.browse").arg(i),QString("<a href=\"%1\">Browse</a>").arg(QString("/library/%1/folder/%2").arg(libraryName).arg(item->id)));
|
||||
|
||||
//t.setVariable(QString("element%1.url").arg(i),"/library/"+libraryName+"/folder/"+QString("%1").arg(folderContent.at(i + (page*10))->id));
|
||||
t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*10))->id));
|
||||
}
|
||||
else
|
||||
{
|
||||
const ComicDB * comic = (ComicDB *)item;
|
||||
t.setVariable(QString("element%1.browse").arg(i),"");
|
||||
t.setVariable(QString("element%1.image.width").arg(i),"80px");
|
||||
t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id));
|
||||
//t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||
t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg").arg(libraryName).arg(comic->info.hash));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -122,8 +155,8 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
|
||||
if(numComics == 0)
|
||||
numComicsAtCurrentPage = 0;
|
||||
response.writeText(QString("numComicsAtCurrentPage : %1 <br/>").arg(numComicsAtCurrentPage));
|
||||
response.writeText(QString("comicsOffset : %1 <br/>").arg(comicsOffset));
|
||||
//response.writeText(QString("numComicsAtCurrentPage : %1 <br/>").arg(numComicsAtCurrentPage));
|
||||
//response.writeText(QString("comicsOffset : %1 <br/>").arg(comicsOffset));
|
||||
|
||||
t.loop("elementcomic",numComicsAtCurrentPage);
|
||||
//
|
||||
@ -143,21 +176,62 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
|
||||
if(numPages > 1)
|
||||
{
|
||||
t.loop("page",numPages);
|
||||
int z = 0;
|
||||
while(z < numPages)
|
||||
{
|
||||
|
||||
t.setVariable(QString("page%1.url").arg(z),"/library/"+libraryName+"/folder/"+QString("%1").arg(parentId)+QString("?page=%1").arg(z));
|
||||
if(page == z)
|
||||
t.setVariable(QString("page%1.number").arg(z),QString("<strong>%1</strong>").arg(z));
|
||||
else
|
||||
t.setVariable(QString("page%1.number").arg(z),QString("%1").arg(z));
|
||||
z++;
|
||||
}
|
||||
QMap<QString,int> indexCount;
|
||||
|
||||
QString firstChar;
|
||||
int xyz = 1;
|
||||
for(QList<LibraryItem *>::const_iterator itr=folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
firstChar = QString((*itr)->name[0]).toUpper();
|
||||
firstChar = firstChar.normalized(QString::NormalizationForm_D).at(0);//TODO _D or _KD??
|
||||
bool ok;
|
||||
int dec = firstChar.toInt(&ok, 10);
|
||||
if(ok)
|
||||
firstChar = "#";
|
||||
//response.writeText(QString("%1 - %2 <br />").arg((*itr)->name).arg(xyz));
|
||||
if(indexCount.contains(firstChar))
|
||||
indexCount.insert(firstChar, indexCount.value(firstChar)+1);
|
||||
else
|
||||
indexCount.insert(firstChar, 1);
|
||||
|
||||
xyz++;
|
||||
}
|
||||
|
||||
QList<QString> index = indexCount.keys();
|
||||
qSort(index.begin(),index.end(),naturalSortLessThanCI);
|
||||
t.loop("index",index.length());
|
||||
int i=0;
|
||||
int count=0;
|
||||
int indexPage=0;
|
||||
for(QList<QString>::const_iterator itr=index.constBegin();itr!=index.constEnd();itr++)
|
||||
{
|
||||
//response.writeText(QString("%1 - %2 <br />").arg(*itr).arg(count));
|
||||
t.setVariable(QString("index%1.indexname").arg(i), *itr);
|
||||
t.setVariable(QString("index%1.url").arg(i),QString("/library/%1/folder/%2?page=%3").arg(libraryName).arg(parentId).arg(indexPage));
|
||||
i++;
|
||||
count += indexCount.value(*itr);
|
||||
indexPage = count/elementsPerPage;
|
||||
|
||||
}
|
||||
|
||||
t.loop("page",numPages);
|
||||
int z = 0;
|
||||
while(z < numPages)
|
||||
{
|
||||
|
||||
t.setVariable(QString("page%1.url").arg(z),QString("/library/%1/folder/%2?page=%3").arg(libraryName).arg(parentId).arg(z));
|
||||
if(page == z)
|
||||
t.setVariable(QString("page%1.number").arg(z),QString("<strong>%1</strong>").arg(z));
|
||||
else
|
||||
t.setVariable(QString("page%1.number").arg(z),QString("%1").arg(z));
|
||||
z++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
t.loop("page",0);
|
||||
t.loop("index",0);
|
||||
}
|
||||
|
||||
response.write(t.toLatin1(),true);
|
||||
|
||||
|
@ -1,61 +1,67 @@
|
||||
/**
|
||||
@file
|
||||
@author Stefan Frings
|
||||
*/
|
||||
|
||||
#include "requestmapper.h"
|
||||
#include "static.h"
|
||||
#include "staticfilecontroller.h"
|
||||
#include "controllers/dumpcontroller.h"
|
||||
#include "controllers/templatecontroller.h"
|
||||
#include "controllers/formcontroller.h"
|
||||
#include "controllers/fileuploadcontroller.h"
|
||||
#include "controllers/sessioncontroller.h"
|
||||
|
||||
#include "controllers/librariescontroller.h"
|
||||
#include "controllers/foldercontroller.h"
|
||||
#include "controllers/covercontroller.h"
|
||||
#include "controllers/comiccontroller.h"
|
||||
#include "controllers/folderinfocontroller.h"
|
||||
#include "controllers/pagecontroller.h"
|
||||
|
||||
RequestMapper::RequestMapper(QObject* parent)
|
||||
:HttpRequestHandler(parent) {}
|
||||
|
||||
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
QByteArray path=request.getPath();
|
||||
qDebug("RequestMapper: path=%s",path.data());
|
||||
|
||||
//primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada
|
||||
if(path == "/")
|
||||
{
|
||||
LibrariesController().service(request, response);
|
||||
}
|
||||
|
||||
//listar el contenido del folder
|
||||
else if(path.contains("folder") && !path.contains("info"))
|
||||
{
|
||||
FolderController().service(request, response);
|
||||
}
|
||||
else if (path.contains("folder") && path.contains("info"))
|
||||
{
|
||||
FolderInfoController().service(request, response);
|
||||
}
|
||||
else if(path.contains("cover") )
|
||||
{
|
||||
CoverController().service(request, response);
|
||||
}
|
||||
else if(path.contains("comic") && !path.contains("page"))
|
||||
{
|
||||
ComicController().service(request, response);
|
||||
}
|
||||
else if(path.contains("page"))
|
||||
{
|
||||
PageController().service(request,response);
|
||||
}
|
||||
else
|
||||
{
|
||||
Static::staticFileController->service(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
@file
|
||||
@author Stefan Frings
|
||||
*/
|
||||
|
||||
#include "requestmapper.h"
|
||||
#include "static.h"
|
||||
#include "staticfilecontroller.h"
|
||||
#include "controllers/dumpcontroller.h"
|
||||
#include "controllers/templatecontroller.h"
|
||||
#include "controllers/formcontroller.h"
|
||||
#include "controllers/fileuploadcontroller.h"
|
||||
#include "controllers/sessioncontroller.h"
|
||||
|
||||
#include "controllers/librariescontroller.h"
|
||||
#include "controllers/foldercontroller.h"
|
||||
#include "controllers/covercontroller.h"
|
||||
#include "controllers/comiccontroller.h"
|
||||
#include "controllers/folderinfocontroller.h"
|
||||
#include "controllers/pagecontroller.h"
|
||||
|
||||
RequestMapper::RequestMapper(QObject* parent)
|
||||
:HttpRequestHandler(parent) {}
|
||||
|
||||
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
QByteArray path=request.getPath();
|
||||
qDebug("RequestMapper: path=%s",path.data());
|
||||
|
||||
QRegExp folder("/library/.+/folder/[0-9]+/?");//(?page=[0-9]+)?
|
||||
QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?");
|
||||
QRegExp comic("/library/.+/comic/[0-9]+/?");
|
||||
QRegExp comicClose("/library/.+/comic/[0-9]+/close/?");
|
||||
QRegExp cover("/library/.+/cover/[0-9a-f]+.jpg");
|
||||
QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?");
|
||||
|
||||
//primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada
|
||||
if(path == "/")
|
||||
{
|
||||
LibrariesController().service(request, response);
|
||||
}
|
||||
//listar el contenido del folder
|
||||
else if(folder.exactMatch(path))
|
||||
{
|
||||
FolderController().service(request, response);
|
||||
}
|
||||
else if (folderInfo.exactMatch(path))
|
||||
{
|
||||
FolderInfoController().service(request, response);
|
||||
}
|
||||
else if(cover.exactMatch(path))
|
||||
{
|
||||
CoverController().service(request, response);
|
||||
}
|
||||
else if(comic.exactMatch(path))
|
||||
{
|
||||
ComicController().service(request, response);
|
||||
}
|
||||
else if(comicPage.exactMatch(path))
|
||||
{
|
||||
PageController().service(request,response);
|
||||
}
|
||||
else
|
||||
{
|
||||
Static::staticFileController->service(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -16,14 +16,12 @@
|
||||
|
||||
<ul id="itemContainer">
|
||||
{loop element}
|
||||
<li><img style="width: 92px" src="/images/f.png"/><a href="{element.url}">{element.name}</a> - <a href="{element.downloadurl}">Download</a></li>
|
||||
<li><img style="width: {element.image.width}" src="{element.image.url}"/> <p>{element.name}</p> {element.browse} - <a href="{element.downloadurl}">Download</a></li>
|
||||
{end element}
|
||||
|
||||
{loop elementcomic}
|
||||
<li><img style="width: 80px" src="{elementcomic.coverulr}" /> <a href="{elementcomic.url}">{elementcomic.name}</a></li>
|
||||
{end elementcomic}
|
||||
</ul>
|
||||
|
||||
<div>{loop index} <a href="{index.url}"> {index.indexname} </a> {end index}</div>
|
||||
<br />
|
||||
<div>{loop page} <a href="{page.url}"> {page.number} </a> {end page}</div>
|
||||
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user