fixed compilation for Qt5.5 in OSX

This commit is contained in:
Luis Ángel San Martín
2015-07-18 10:54:14 +02:00
commit 3ed6d78f75
935 changed files with 81053 additions and 0 deletions

174
common/bookmarks.cpp Normal file
View File

@ -0,0 +1,174 @@
#include "bookmarks.h"
#include <QFile>
#include <QDataStream>
#include <QCoreApplication>
#include <QFileInfo>
#include <QMessageBox>
#include <QList>
#include "yacreader_global.h"
Bookmarks::Bookmarks()
:lastPageIndex(0)
{
list.load();
}
void Bookmarks::setLastPage(int index,const QImage & page)
{
lastPageIndex = index;
lastPage = page;
}
void Bookmarks::setBookmark(int index,const QImage & page)
{
if(!bookmarks.contains(index))
{
bookmarks.insert(index,page);
latestBookmarks.push_front(index);
if(latestBookmarks.count()>3)
{
bookmarks.remove(latestBookmarks.back());
latestBookmarks.pop_back();
}
}
else //udate de pixmap;
{
bookmarks[index]=page;
}
}
void Bookmarks::removeBookmark(int index)
{
bookmarks.remove(index);
}
QList<int> Bookmarks::getBookmarkPages() const
{
return bookmarks.keys();
}
QImage Bookmarks::getBookmarkPixmap(int page) const
{
return bookmarks.value(page);
}
QImage Bookmarks::getLastPagePixmap() const
{
return lastPage;
}
int Bookmarks::getLastPage() const
{
return lastPageIndex;
}
bool Bookmarks::isBookmark(int page)
{
return bookmarks.contains(page);
}
bool Bookmarks::imageLoaded(int page)
{
return !bookmarks.value(page).isNull();
}
void Bookmarks::newComic(const QString & path)
{
QFileInfo f(path);
QString comicID = f.fileName().toLower()+QString::number(f.size());
clear();
BookmarksList::Bookmark b = list.get(comicID);
comicPath=comicID;
lastPageIndex = b.lastPage;
latestBookmarks = b.bookmarks;
for(int i=0;i<latestBookmarks.count();i++)
bookmarks.insert(latestBookmarks.at(i),QImage());
added = b.added;
}
void Bookmarks::clear()
{
bookmarks.clear();
latestBookmarks.clear();
lastPageIndex=0;
lastPage = QImage();
}
bool Bookmarks::load(const QList<int> & bookmarkIndexes, int lastPage)
{
lastPageIndex = lastPage;
foreach(int b, bookmarkIndexes)
if(b != -1)
{
latestBookmarks.push_back(b);
bookmarks.insert(b,QImage());
}
return true;
}
void Bookmarks::save()
{
BookmarksList::Bookmark b;
b.lastPage = lastPageIndex;
b.bookmarks = getBookmarkPages();
BookmarksList::Bookmark previousBookmarks;
bool updated = ((previousBookmarks.lastPage != b.lastPage) || (previousBookmarks.bookmarks != b.bookmarks));
if(b.added.isNull() || updated)
b.added = QDateTime::currentDateTime();
list.add(comicPath,b);
list.save();
}
//-----------------------------------------------------------------------------
void BookmarksList::load()
{
QFile f(YACReader::getSettingsPath()+"/bookmarks.yacr");
if(f.open(QIODevice::ReadOnly))
{
QDataStream dataS(&f);
dataS >> list;
f.close();
}
}
void BookmarksList::save()
{
QFile f(YACReader::getSettingsPath()+"/bookmarks.yacr");
f.open(QIODevice::WriteOnly);
QDataStream dataS(&f);
if(list.count()>numMaxBookmarks)
deleteOldest(list.count()-numMaxBookmarks);
dataS << list;
f.close();
}
void BookmarksList::deleteOldest(int num)
{
Q_UNUSED(num)
QString comic;
QDateTime date(QDate(10000,1,1));//TODO MAX_DATE??
for(QMap<QString,Bookmark>::const_iterator itr=list.begin();itr!=list.end();itr++)
{
if(itr->added<date)
{
comic=itr.key();
date = itr->added;
}
}
list.remove(comic);
}
void BookmarksList::add(const QString & comicID, const Bookmark & b)
{
list.insert(comicID,b);
}
BookmarksList::Bookmark BookmarksList::get(const QString & comicID)
{
//if(list.contains(comicID)
return list.value(comicID);
}

80
common/bookmarks.h Normal file
View File

@ -0,0 +1,80 @@
#ifndef BOOKMARKS_H
#define BOOKMARKS_H
#include <QObject>
#include <QMap>
#include <QImage>
#include <QString>
#include <QMap>
#include <QDateTime>
class BookmarksList
{
public:
struct Bookmark {
int lastPage;
QList<int> bookmarks;
QDateTime added;
Bookmark():lastPage(0){};
friend QDataStream & operator<< ( QDataStream & out, const Bookmark & bm )
{
out << bm.lastPage;
out << bm.bookmarks;
out << bm.added;
return out;
}
friend QDataStream & operator>> ( QDataStream & in, Bookmark & bm )
{
in >> bm.lastPage;
in >> bm.bookmarks;
in >> bm.added;
return in;
}
};
BookmarksList():numMaxBookmarks(400){}
void load();
void save();
void add(const QString & comicID, const Bookmark & b);
Bookmark get(const QString & comicID);
protected:
QMap<QString,Bookmark> list;
void deleteOldest(int num);
private:
int numMaxBookmarks;
};
class Bookmarks : public QObject
{
Q_OBJECT
protected:
QString comicPath;
//bookmarks setted by the user
QMap<int,QImage> bookmarks;
QList<int> latestBookmarks;
//last page readed
int lastPageIndex;
QImage lastPage;
BookmarksList list;
QDateTime added;
public:
Bookmarks();
void setLastPage(int index,const QImage & page);
void setBookmark(int index,const QImage & page);
void removeBookmark(int index);
QList<int> getBookmarkPages() const;
QImage getBookmarkPixmap(int page) const;
QImage getLastPagePixmap() const;
int getLastPage() const;
bool isBookmark(int page);
bool imageLoaded(int page);
void newComic(const QString & path);
void clear();
void save();
bool load(const QList<int> & bookmarkIndexes, int lastPage);
};
#endif // BOOKMARKS_H

View File

@ -0,0 +1,84 @@
#include "check_new_version.h"
#include <QMessageBox>
#include <QUrl>
#include <QtGlobal>
#include <QStringList>
#include <QNetworkAccessManager>
#include <QEventLoop>
#include <QTimer>
#include <QNetworkRequest>
#include <QNetworkReply>
#define PREVIOUS_VERSION "6.0.0"
HttpVersionChecker::HttpVersionChecker()
:HttpWorker("https://bitbucket.org/luisangelsm/yacreader/wiki/Home")
{
connect(this,SIGNAL(dataReady(const QByteArray &)),this,SLOT(checkNewVersion(const QByteArray &)));
}
void HttpVersionChecker::checkNewVersion(const QByteArray & data)
{
checkNewVersion(QString(data));
}
bool HttpVersionChecker::checkNewVersion(QString sourceContent)
{
#ifdef Q_OS_WIN32
QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32.*");
#endif
#if defined Q_OS_UNIX && !defined Q_OS_MAC
QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}X11.*");
#endif
#ifdef Q_OS_MAC
QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}Mac.*");
#endif
int index = 0;
bool newVersion = false;
bool sameVersion = true;
//bool currentVersionIsNewer = false;
#ifdef QT_DEBUG
QString version(PREVIOUS_VERSION);
#else
QString version(VERSION);
#endif
QStringList sl = version.split(".");
if((index = rx.indexIn(sourceContent))!=-1)
{
int length = qMin(sl.size(),(rx.cap(4)!="")?4:3);
for(int i=0;i<length;i++)
{
if(rx.cap(i+1).toInt()<sl.at(i).toInt())
{
return false;
}
if(rx.cap(i+1).toInt()>sl.at(i).toInt()){
newVersion=true;
break;
}
else
sameVersion = sameVersion && rx.cap(i+1).toInt()==sl.at(i).toInt();
}
if(!newVersion && sameVersion)
{
if((sl.size()==3)&&(rx.cap(4)!=""))
newVersion = true;
}
}
if(newVersion == true)
{
emit newVersionDetected();
return true;
}
else
{
return false;
}
}

View File

@ -0,0 +1,27 @@
#ifndef __CHECKUPDATE_H
#define __CHECKUPDATE_H
#include "http_worker.h"
#include "yacreader_global.h"
#include <QWidget>
#include <QByteArray>
#include <QThread>
class HttpVersionChecker : public HttpWorker
{
Q_OBJECT
public:
HttpVersionChecker();
public slots:
private:
bool found;
private slots:
bool checkNewVersion(QString sourceContent);
void checkNewVersion(const QByteArray & data);
signals:
void newVersionDetected();
};
#endif

827
common/comic.cpp Normal file
View File

@ -0,0 +1,827 @@
#include "comic.h"
#include <QPixmap>
#include <QRegExp>
#include <QString>
#include <algorithm>
#include <QDir>
#include <QFileInfoList>
#include <QApplication>
#include "bookmarks.h" //TODO desacoplar la dependencia con bookmarks
#include "qnaturalsorting.h"
#include "compressed_archive.h"
#include "comic_db.h"
#include "QsLog.h"
const QStringList Comic::imageExtensions = QStringList() << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp" << "*.webp";
const QStringList Comic::literalImageExtensions = QStringList() << "jpg" << "jpeg" << "png" << "gif" << "tiff" << "tif" << "bmp" << "webp";
#ifndef use_unarr
const QStringList Comic::comicExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.7z" << "*.cb7" << "*.arj" << "*.cbt";
const QStringList Comic::literalComicExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "7z" << "cb7" << "arj" << "cbt";
#else
const QStringList Comic::comicExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.cbt";
const QStringList Comic::literalComicExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "cbt";
#endif
//-----------------------------------------------------------------------------
Comic::Comic()
:_pages(),_index(0),_path(),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false)
{
setup();
}
//-----------------------------------------------------------------------------
Comic::Comic(const QString & pathFile, int atPage )
:_pages(),_index(0),_path(pathFile),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false),_firstPage(atPage)
{
setup();
}
//-----------------------------------------------------------------------------
Comic::~Comic()
{
delete bm;
}
//-----------------------------------------------------------------------------
void Comic::setup()
{
connect(this,SIGNAL(pageChanged(int)),this,SLOT(checkIsBookmark(int)));
connect(this,SIGNAL(imageLoaded(int)),this,SLOT(updateBookmarkImage(int)));
connect(this,SIGNAL(imageLoaded(int)),this,SLOT(setPageLoaded(int)));
}
//-----------------------------------------------------------------------------
int Comic::nextPage()
{
if(_index<_pages.size()-1)
{
_index++;
emit pageChanged(_index);
}
else
emit isLast();
return _index;
}
//---------------------------------------------------------------------------
int Comic::previousPage()
{
if(_index>0)
{
_index--;
emit pageChanged(_index);
}
else
emit isCover();
return _index;
}
//-----------------------------------------------------------------------------
void Comic::setIndex(unsigned int index)
{
int previousIndex = _index;
if(static_cast<int>(index)<_pages.size()-1)
_index = index;
else
_index = _pages.size()-1;
if(previousIndex != _index)
emit pageChanged(_index);
}
//-----------------------------------------------------------------------------
/*QPixmap * Comic::currentPage()
{
QPixmap * p = new QPixmap();
p->loadFromData(_pages[_index]);
return p;
}
//-----------------------------------------------------------------------------
QPixmap * Comic::operator[](unsigned int index)
{
QPixmap * p = new QPixmap();
p->loadFromData(_pages[index]);
return p;
}*/
bool Comic::load(const QString & path, const ComicDB & comic)
{
Q_UNUSED(path);
Q_UNUSED(comic);
return false;
};
//-----------------------------------------------------------------------------
bool Comic::loaded()
{
return _loaded;
}
//-----------------------------------------------------------------------------
void Comic::loadFinished()
{
emit imagesLoaded();
}
//-----------------------------------------------------------------------------
void Comic::setBookmark()
{
QImage p;
p.loadFromData(_pages[_index]);
bm->setBookmark(_index,p);
//emit bookmarksLoaded(*bm);
emit bookmarksUpdated();
}
//-----------------------------------------------------------------------------
void Comic::removeBookmark()
{
bm->removeBookmark(_index);
//emit bookmarksLoaded(*bm);
emit bookmarksUpdated();
}
//-----------------------------------------------------------------------------
void Comic::saveBookmarks()
{
QImage p;
p.loadFromData(_pages[_index]);
bm->setLastPage(_index,p);
bm->save();
}
//-----------------------------------------------------------------------------
void Comic::checkIsBookmark(int index)
{
emit isBookmark(bm->isBookmark(index));
}
//-----------------------------------------------------------------------------
void Comic::updateBookmarkImage(int index)
{
if(bm->isBookmark(index))
{
QImage p;
p.loadFromData(_pages[index]);
bm->setBookmark(index,p);
emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
}
if(bm->getLastPage() == index)
{
QImage p;
p.loadFromData(_pages[index]);
bm->setLastPage(index,p);
emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
}
}
//-----------------------------------------------------------------------------
void Comic::setPageLoaded(int page)
{
_loadedPages[page] = true;
}
//-----------------------------------------------------------------------------
QByteArray Comic::getRawPage(int page)
{
if(page < 0 || page >= _pages.size())
return QByteArray();
return _pages[page];
}
//-----------------------------------------------------------------------------
bool Comic::pageIsLoaded(int page)
{
if(page < 0 || page >= _pages.size())
return false;
return _loadedPages[page];
}
bool Comic::fileIsComic(const QString &path)
{
QFileInfo info(path);
return literalComicExtensions.contains(info.suffix());
}
QList<QString> Comic::findValidComicFiles(const QList<QUrl> &list)
{
QLOG_DEBUG() << "-findValidComicFiles-";
QList<QString> validComicFiles;
QString currentPath;
foreach (QUrl url, list) {
currentPath = url.toLocalFile();
if(Comic::fileIsComic(currentPath))
validComicFiles << currentPath;
else if(QFileInfo(currentPath).isDir())
{
validComicFiles << findValidComicFilesInFolder(currentPath);
}
}
QLOG_DEBUG() << "-" << validComicFiles << "-";
return validComicFiles;
}
QList<QString> Comic::findValidComicFilesInFolder(const QString &path)
{
QLOG_DEBUG() << "-findValidComicFilesInFolder-" << path;
if(!QFileInfo(path).isDir())
return QList<QString>();
QList<QString> validComicFiles;
QDir folder(path);
folder.setNameFilters(Comic::comicExtensions);
folder.setFilter(QDir::AllDirs|QDir::Files|QDir::NoDotAndDotDot);
QFileInfoList folderContent = folder.entryInfoList();
QString currentPath;
foreach (QFileInfo info, folderContent) {
currentPath = info.absoluteFilePath();
if(info.isDir())
validComicFiles << findValidComicFilesInFolder(currentPath); //find comics recursively
else if(Comic::fileIsComic(currentPath))
{
validComicFiles << currentPath;
}
}
return validComicFiles;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
FileComic::FileComic()
:Comic()
{
}
FileComic::FileComic(const QString & path, int atPage )
:Comic(path,atPage)
{
load(path,atPage);
}
FileComic::~FileComic()
{
_pages.clear();
_loadedPages.clear();
_fileNames.clear();
_newOrder.clear();
_order.clear();
}
bool FileComic::load(const QString & path, int atPage)
{
QFileInfo fi(path);
if(fi.exists())
{
if(atPage == -1)
{
bm->newComic(path);
emit bookmarksUpdated();
}
_firstPage = atPage;
//emit bookmarksLoaded(*bm);
_path = QDir::cleanPath(path);
//load files size
return true;
}
else
{
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
emit errorOpening();
return false;
}
}
bool FileComic::load(const QString & path, const ComicDB & comic)
{
QFileInfo fi(path);
if(fi.exists())
{
QList<int> bookmarkIndexes;
bookmarkIndexes << comic.info.bookmark1 << comic.info.bookmark2 << comic.info.bookmark3;
if(bm->load(bookmarkIndexes,comic.info.currentPage-1))
emit bookmarksUpdated();
_firstPage = comic.info.currentPage-1;
_path = QDir::cleanPath(path);
return true;
}
else
{
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
moveToThread(QApplication::instance()->thread());
emit errorOpening();
return false;
}
}
QList<QString> FileComic::filter(const QList<QString> & src)
{
QList<QString> extensions = getSupportedImageLiteralFormats();
QList<QString> filtered;
bool fileAccepted = false;
foreach(QString fileName,src)
{
fileAccepted = false;
if(!fileName.contains("__MACOSX"))
{
foreach(QString extension,extensions)
{
if(fileName.endsWith(extension,Qt::CaseInsensitive))
{
fileAccepted = true;
break;
}
}
}
if(fileAccepted)
filtered.append(fileName);
}
return filtered;
}
//DELEGATE methods
void FileComic::fileExtracted(int index, const QByteArray & rawData)
{
/*QFile f("c:/temp/out2.txt");
f.open(QIODevice::Append);
QTextStream out(&f);*/
int sortedIndex = _fileNames.indexOf(_order.at(index));
//out << sortedIndex << " , ";
//f.close();
if(sortedIndex == -1)
return;
_pages[sortedIndex] = rawData;
emit imageLoaded(sortedIndex);
emit imageLoaded(sortedIndex,_pages[sortedIndex]);
}
void FileComic::crcError(int index)
{
emit crcErrorFound(tr("CRC error on page (%1): some of the pages will not be displayed correctly").arg(index+1));
}
//TODO: comprobar que si se produce uno de estos errores, la carga del c<>mic es irrecuperable
void FileComic::unknownError(int index)
{
Q_UNUSED(index)
emit errorOpening(tr("Unknown error opening the file"));
//emit errorOpening();
}
//--------------------------------------
QList<QVector<quint32> > FileComic::getSections(int & sectionIndex)
{
QVector<quint32> sortedIndexes;
foreach(QString name, _fileNames)
{
sortedIndexes.append(_order.indexOf(name));
}
QList<QVector <quint32> > sections;
quint32 previous = 0;
sectionIndex = -1;
int sectionCount = 0;
QVector <quint32> section;
int idx = 0;
unsigned int realIdx;
foreach(quint32 i, sortedIndexes)
{
if(_firstPage == idx)
{
sectionIndex = sectionCount;
realIdx = i;
}
if(previous <= i)
{
//out << "idx : " << i << endl;
section.append(i);
previous = i;
}
else
{
if(sectionIndex == sectionCount) //found
{
if(section.indexOf(realIdx)!=0)
{
QVector <quint32> section1;
QVector <quint32> section2;
foreach(quint32 si,section)
{
if(si<realIdx)
section1.append(si);
else
section2.append(si);
}
sectionIndex++;
sections.append(section1);
sections.append(section2);
//out << "SPLIT" << endl;
}
else
{
sections.append(section);
}
}
else
sections.append(section);
section = QVector <quint32> ();
//out << "---------------" << endl;
section.append(i);
//out << "idx : " << i << endl;
previous = i;
sectionCount++;
}
idx++;
}
if(sectionIndex == sectionCount) //found
{
if(section.indexOf(realIdx)!=0)
{
QVector <quint32> section1;
QVector <quint32> section2;
foreach(quint32 si,section)
{
if(si<realIdx)
section1.append(si);
else
section2.append(si);
}
sectionIndex++;
sections.append(section1);
sections.append(section2);
//out << "SPLIT" << endl;
}
else
{
sections.append(section);
}
}
else
sections.append(section);
//out << "se han encontrado : " << sections.count() << " sectionIndex : " << sectionIndex << endl;
return sections;
}
void FileComic::process()
{
CompressedArchive archive(_path);
if(!archive.toolsLoaded())
{
moveToThread(QApplication::instance()->thread());
emit errorOpening(tr("7z not found"));
return;
}
if(!archive.isValid())
{
moveToThread(QApplication::instance()->thread());
emit errorOpening(tr("Format not supported"));
return;
}
//se filtran para obtener s<>lo los formatos soportados
_order = archive.getFileNames();
_fileNames = filter(_order);
if(_fileNames.size()==0)
{
//QMessageBox::critical(NULL,tr("File error"),tr("File not found or not images in file"));
moveToThread(QApplication::instance()->thread());
emit errorOpening();
return;
}
//TODO, cambiar por listas
//_order = _fileNames;
_pages.resize(_fileNames.size());
_loadedPages = QVector<bool>(_fileNames.size(),false);
emit pageChanged(0); // this indicates new comic, index=0
emit numPages(_pages.size());
_loaded = true;
_cfi=0;
qSort(_fileNames.begin(),_fileNames.end(), naturalSortLessThanCI);
if(_firstPage == -1)
_firstPage = bm->getLastPage();
if(_firstPage >= _pages.length())
_firstPage = 0;
_index = _firstPage;
emit(openAt(_index));
int sectionIndex;
QList<QVector <quint32> > sections = getSections(sectionIndex);
for(int i = sectionIndex; i<sections.count() ; i++)
archive.getAllData(sections.at(i),this);
for(int i = 0; i<sectionIndex; i++)
archive.getAllData(sections.at(i),this);
//archive.getAllData(QVector<quint32>(),this);
/*
foreach(QString name,_fileNames)
{
index = _order.indexOf(name);
sortedIndex = _fileNames.indexOf(name);
_pages[sortedIndex] = allData.at(index);
emit imageLoaded(sortedIndex);
emit imageLoaded(sortedIndex,_pages[sortedIndex]);
}*/
moveToThread(QApplication::instance()->thread());
emit imagesLoaded();
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
FolderComic::FolderComic()
:Comic()
{
}
FolderComic::FolderComic(const QString & path, int atPage )
:Comic(path, atPage )
{
load(path, atPage );
}
FolderComic::~FolderComic()
{
}
bool FolderComic::load(const QString & path, int atPage )
{
_path = path;
if(atPage == -1)
{
bm->newComic(_path);
emit bookmarksUpdated();
}
_firstPage = atPage;
//emit bookmarksLoaded(*bm);
return true;
}
void FolderComic::process()
{
QDir d(_path);
d.setNameFilters(getSupportedImageFormats());
d.setFilter(QDir::Files|QDir::NoDotAndDotDot);
//d.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware);
QFileInfoList list = d.entryInfoList();
qSort(list.begin(),list.end(),naturalSortLessThanCIFileInfo);
int nPages = list.size();
_pages.clear();
_pages.resize(nPages);
_loadedPages = QVector<bool>(nPages,false);
if(nPages==0)
{
//TODO emitir este mensaje en otro sitio
//QMessageBox::critical(NULL,QObject::tr("No images found"),QObject::tr("There are not images on the selected folder"));
moveToThread(QApplication::instance()->thread());
emit errorOpening();
}
else
{
if(_firstPage == -1)
_firstPage = bm->getLastPage();
if(_firstPage >= _pages.length())
_firstPage = 0;
_index = _firstPage;
emit(openAt(_index));
emit pageChanged(0); // this indicates new comic, index=0
emit numPages(_pages.size());
_loaded = true;
int count=0;
int i=_firstPage;
while(count<nPages)
{
QFile f(list.at(i).absoluteFilePath());
f.open(QIODevice::ReadOnly);
_pages[i]=f.readAll();
emit imageLoaded(i);
emit imageLoaded(i,_pages[i]);
i++;
if(i==nPages)
i=0;
count++;
}
}
moveToThread(QApplication::instance()->thread());
emit imagesLoaded();
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
PDFComic::PDFComic()
:Comic()
{
}
PDFComic::PDFComic(const QString & path, int atPage)
:Comic(path,atPage)
{
load(path,atPage);
}
PDFComic::~PDFComic()
{
}
bool PDFComic::load(const QString & path, int atPage)
{
QFileInfo fi(path);
if(fi.exists())
{
_path = path;
if(atPage == -1)
{
bm->newComic(_path);
emit bookmarksUpdated();
}
_firstPage = atPage;
//emit bookmarksLoaded(*bm);
return true;
}
else
{
moveToThread(QApplication::instance()->thread());
emit errorOpening();
return false;
}
}
bool PDFComic::load(const QString & path, const ComicDB & comic)
{
QFileInfo fi(path);
if(fi.exists())
{
QList<int> bookmarkIndexes;
bookmarkIndexes << comic.info.bookmark1 << comic.info.bookmark2 << comic.info.bookmark3;
if(bm->load(bookmarkIndexes,comic.info.currentPage-1))
emit bookmarksUpdated();
_firstPage = comic.info.currentPage-1;
_path = QDir::cleanPath(path);
return true;
}
else
{
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
moveToThread(QApplication::instance()->thread());
emit errorOpening();
return false;
}
}
void PDFComic::process()
{
#ifdef Q_OS_MAC
pdfComic = new MacOSXPDFComic();
if(!pdfComic->openComic(_path))
{
delete pdfComic;
emit errorOpening();
return;
}
#else
pdfComic = Poppler::Document::load(_path);
if (!pdfComic)
{
//delete pdfComic;
//pdfComic = 0;
moveToThread(QApplication::instance()->thread());
emit errorOpening();
return;
}
if (pdfComic->isLocked())
{
moveToThread(QApplication::instance()->thread());
emit errorOpening();
return;
}
//pdfComic->setRenderHint(Poppler::Document::Antialiasing, true);
pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true);
#endif
int nPages = pdfComic->numPages();
emit pageChanged(0); // this indicates new comic, index=0
emit numPages(nPages);
_loaded = true;
//QMessageBox::critical(NULL,QString("%1").arg(nPages),tr("Invalid PDF file"));
_pages.clear();
_pages.resize(nPages);
_loadedPages = QVector<bool>(nPages,false);
if(_firstPage == -1)
_firstPage = bm->getLastPage();
if(_firstPage >= _pages.length())
_firstPage = 0;
_index = _firstPage;
emit(openAt(_index));
//buffer index to avoid race conditions
int buffered_index = _index;
for(int i=buffered_index;i<nPages;i++)
renderPage(i);
for(int i=0;i<buffered_index;i++)
renderPage(i);
delete pdfComic;
moveToThread(QApplication::instance()->thread());
emit imagesLoaded();
}
void PDFComic::renderPage(int page)
{
#ifdef Q_OS_MAC
{
QImage img = pdfComic->getPage(page);
if(!img.isNull())
{
QByteArray ba;
QBuffer buf(&ba);
img.save(&buf, "jpg");
_pages[page] = ba;
emit imageLoaded(page);
emit imageLoaded(page,_pages[page]);
}
}
pdfComic->releaseLastPageData();
#else
Poppler::Page* pdfpage = pdfComic->page(page);
if (pdfpage)
{
QImage img = pdfpage->renderToImage(150,150);
delete pdfpage;
QByteArray ba;
QBuffer buf(&ba);
img.save(&buf, "jpg");
_pages[page] = ba;
emit imageLoaded(page);
emit imageLoaded(page,_pages[page]);
}
#endif
}
Comic * FactoryComic::newComic(const QString & path)
{
QFileInfo fi(path);
if(fi.exists())
{
if(fi.isFile())
{
if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0)
return new PDFComic();
else
return new FileComic();
}
else
{
if(fi.isDir())
return new FolderComic();
else
return NULL;
}
}
else
return NULL;
}

182
common/comic.h Normal file
View File

@ -0,0 +1,182 @@
#ifndef __COMIC_H
#define __COMIC_H
#include <QtCore>
#include <QImage>
#include <QtGui>
#include <QByteArray>
#include <QMap>
#include "extract_delegate.h"
#include "bookmarks.h"
#ifdef Q_OS_MAC
#include "pdf_comic.h"
#else
#if QT_VERSION >= 0x050000
#include "poppler-qt5.h"
#else
#include "poppler-qt4.h"
#endif
#endif
class ComicDB;
//#define EXTENSIONS << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp" Comic::getSupportedImageFormats()
//#define EXTENSIONS_LITERAL << ".jpg" << ".jpeg" << ".png" << ".gif" << ".tiff" << ".tif" << ".bmp" //Comic::getSupportedImageLiteralFormats()
class Comic : public QObject
{
Q_OBJECT
protected:
//Comic pages, one QPixmap for each file.
QVector<QByteArray> _pages;
QVector<bool> _loadedPages;
//QVector<uint> _sizes;
QStringList _fileNames;
QMap<QString,int> _newOrder;
QList<QString> _order;
int _index;
QString _path;
bool _loaded;
int _cfi;
//open the comic at this point
int _firstPage;
bool _isPDF;
public:
static const QStringList imageExtensions;
static const QStringList literalImageExtensions;
static const QStringList comicExtensions;
static const QStringList literalComicExtensions;
Bookmarks * bm;
//Constructors
Comic();
Comic(const QString & pathFile, int atPage = -1);
~Comic();
void setup();
//Load pages from file
virtual bool load(const QString & path, int atPage = -1) = 0;
virtual bool load(const QString & path, const ComicDB & comic);
/*void loadFromFile(const QString & pathFile);
void loadFromDir(const QString & pathDir);
void loadFromPDF(const QString & pathPDF);*/
int nextPage();
int previousPage();
void setIndex(unsigned int index);
unsigned int getIndex(){return _index;};
unsigned int numPages(){return _pages.size();}
//QPixmap * currentPage();
bool loaded();
//QPixmap * operator[](unsigned int index);
QVector<QByteArray> * getRawData(){return &_pages;}
QByteArray getRawPage(int page);
bool pageIsLoaded(int page);
inline static QStringList getSupportedImageFormats() { return imageExtensions;}
inline static QStringList getSupportedImageLiteralFormats() { return literalImageExtensions;}
static bool fileIsComic(const QString &path);
static QList<QString> findValidComicFiles(const QList<QUrl> & list);
static QList<QString> findValidComicFilesInFolder(const QString &path);
public slots:
void loadFinished();
void setBookmark();
void removeBookmark();
void saveBookmarks();
void checkIsBookmark(int index);
void updateBookmarkImage(int);
void setPageLoaded(int page);
signals:
void imagesLoaded();
void imageLoaded(int index);
void imageLoaded(int index,const QByteArray & image);
void pageChanged(int index);
void openAt(int index);
void numPages(unsigned int numPages);
void errorOpening();
void errorOpening(QString);
void crcErrorFound(QString);
void isBookmark(bool);
void bookmarksUpdated();
void isCover();
void isLast();
};
class FileComic : public Comic, public ExtractDelegate
{
Q_OBJECT
private:
QList<QVector<quint32> > getSections(int & sectionIndex);
public:
FileComic();
FileComic(const QString & path, int atPage = -1);
~FileComic();
void fileExtracted(int index, const QByteArray & rawData);
virtual bool load(const QString & path, int atPage = -1);
virtual bool load(const QString & path, const ComicDB & comic);
void crcError(int index);
void unknownError(int index);
static QList<QString> filter(const QList<QString> & src);
public slots:
void process();
};
class FolderComic : public Comic
{
Q_OBJECT
private:
//void run();
public:
FolderComic();
FolderComic(const QString & path, int atPage = -1);
~FolderComic();
virtual bool load(const QString & path, int atPage = -1);
public slots:
void process();
};
class PDFComic : public Comic
{
Q_OBJECT
private:
//pdf
#ifdef Q_OS_MAC
MacOSXPDFComic * pdfComic;
#else
Poppler::Document * pdfComic;
#endif
void renderPage(int page);
//void run();
public:
PDFComic();
PDFComic(const QString & path, int atPage = -1);
~PDFComic();
virtual bool load(const QString & path, int atPage = -1);
virtual bool load(const QString & path, const ComicDB & comic);
public slots:
void process();
};
class FactoryComic
{
public:
static Comic * newComic(const QString & path);
};
#endif

483
common/comic_db.cpp Normal file
View File

@ -0,0 +1,483 @@
#include "comic_db.h"
#include <QVariant>
#include <QFileInfo>
//-----------------------------------------------------------------------------
//COMIC------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ComicDB::ComicDB()
{
}
bool ComicDB::isDir()
{
return false;
}
QString ComicDB::toTXT()
{
QString txt;
//Legacy info
txt.append(QString("comicid:%1\r\n").arg(id));
txt.append(QString("hash:%1\r\n").arg(info.hash));
txt.append(QString("path:%1\r\n").arg(path));
txt.append(QString("numpages:%1\r\n").arg(info.numPages.toString()));
//new 7.0
txt.append(QString("rating:%1\r\n").arg(info.rating));
txt.append(QString("currentPage:%1\r\n").arg(info.currentPage));
txt.append(QString("contrast:%1\r\n").arg(info.contrast));
//Informaci<63>n general
if(!info.coverPage.isNull())
txt.append(QString("coverPage:%1\r\n").arg(info.coverPage.toString()));
if(!info.title.isNull())
txt.append(QString("title:%1\r\n").arg(info.title.toString()));
if(!info.number.isNull())
txt.append(QString("number:%1\r\n").arg(info.number.toString()));
if(!info.isBis.isNull())
txt.append(QString("isBis:%1\r\n").arg(info.isBis.toBool()?"1":"0"));
if(!info.count.isNull())
txt.append(QString("count:%1\r\n").arg(info.count.toString()));
if(!info.volume.isNull())
txt.append(QString("volume:%1\r\n").arg(info.volume.toString()));
if(!info.storyArc.isNull())
txt.append(QString("storyArc:%1\r\n").arg(info.storyArc.toString()));
if(!info.arcNumber.isNull())
txt.append(QString("arcNumber:%1\r\n").arg(info.arcNumber.toString()));
if(!info.arcCount.isNull())
txt.append(QString("arcCount:%1\r\n").arg(info.arcCount.toString()));
if(!info.genere.isNull())
txt.append(QString("genere:%1\r\n").arg(info.genere.toString()));
//Autores
if(!info.writer.isNull())
txt.append(QString("writer:%1\r\n").arg(info.writer.toString()));
if(!info.penciller.isNull())
txt.append(QString("penciller:%1\r\n").arg(info.penciller.toString()));
if(!info.inker.isNull())
txt.append(QString("inker:%1\r\n").arg(info.inker.toString()));
if(!info.colorist.isNull())
txt.append(QString("colorist:%1\r\n").arg(info.colorist.toString()));
if(!info.letterer.isNull())
txt.append(QString("letterer:%1\r\n").arg(info.letterer.toString()));
if(!info.coverArtist.isNull())
txt.append(QString("coverArtist:%1\r\n").arg(info.coverArtist.toString()));
//Publicaci<63>n
if(!info.date.isNull())
txt.append(QString("date:%1\r\n").arg(info.date.toString()));
if(!info.publisher.isNull())
txt.append(QString("publisher:%1\r\n").arg(info.publisher.toString()));
if(!info.format.isNull())
txt.append(QString("format:%1\r\n").arg(info.format.toString()));
if(!info.color.isNull())
txt.append(QString("color:%1\r\n").arg(info.color.toString()));
if(!info.ageRating.isNull())
txt.append(QString("ageRating:%1\r\n").arg(info.ageRating.toString()));
//Argumento
if(!info.synopsis.isNull())
txt.append(QString("synopsis:%1\r\n").arg(info.synopsis.toString()));
if(!info.characters.isNull())
txt.append(QString("characters:%1\r\n").arg(info.characters.toString()));
if(!info.notes.isNull())
txt.append(QString("notes:%1\r\n").arg(info.notes.toString()));
return txt;
}
QString ComicDB::getFileName() const
{
return QFileInfo(path).fileName();
}
QString ComicDB::getTitleOrFileName() const
{
if(!info.title.isNull() && info.title.toString().isEmpty())
return info.title.toString();
else
return QFileInfo(path).fileName();
}
QString ComicDB::getParentFolderName() const
{
QStringList paths = path.split('/');
if(paths.length()<2)
return "";
else
return paths[paths.length()-2];
}
qulonglong ComicDB::getFileSize() const
{
//the size is encoded in the hash after the SHA-1
return info.hash.right(info.hash.length()-40).toLongLong();
}
//-----------------------------------------------------------------------------
//COMIC_INFO-------------------------------------------------------------------
//-----------------------------------------------------------------------------
ComicInfo::ComicInfo()
:existOnDb(false),
rating(0),
hasBeenOpened(false),
currentPage(1),
bookmark1(-1),
bookmark2(-1),
bookmark3(-1),
brightness(-1),
contrast(-1),
gamma(-1)
{
}
ComicInfo::ComicInfo(const ComicInfo & comicInfo)
{
operator=(comicInfo);
}
ComicInfo::~ComicInfo()
{
}
//the default operator= should work
ComicInfo & ComicInfo::operator=(const ComicInfo & comicInfo)
{
hash = comicInfo.hash;
id = comicInfo.id;
existOnDb = comicInfo.existOnDb;
read = comicInfo.read;
edited = comicInfo.edited;
hasBeenOpened = comicInfo.hasBeenOpened;
rating = comicInfo.rating;
currentPage = comicInfo.currentPage;
bookmark1 = comicInfo.bookmark1;
bookmark2 = comicInfo.bookmark2;
bookmark3 = comicInfo.bookmark3;
brightness = comicInfo.brightness;
contrast = comicInfo.contrast;
gamma = comicInfo.gamma;
title = comicInfo.title;
coverPage = comicInfo.coverPage;
numPages = comicInfo.numPages;
number = comicInfo.number;
isBis = comicInfo.isBis;
count = comicInfo.count;
volume = comicInfo.volume;
storyArc = comicInfo.storyArc;
arcNumber = comicInfo.arcNumber;
arcCount = comicInfo.arcCount;
genere = comicInfo.genere;
writer = comicInfo.writer;
penciller = comicInfo.penciller;
inker = comicInfo.inker;
colorist = comicInfo.colorist;
letterer = comicInfo.letterer;
coverArtist = comicInfo.coverArtist;
date = comicInfo.date;
publisher = comicInfo.publisher;
format = comicInfo.format;
color = comicInfo.color;
ageRating = comicInfo.ageRating;
synopsis = comicInfo.synopsis;
characters = comicInfo.characters;
notes = comicInfo.notes;
comicVineID = comicInfo.comicVineID;
return *this;
}
//set fields
/*
void ComicInfo::setTitle(QString value)
{
setValue(title,value);
}
void ComicInfo::setCoverPage(int value)
{
setValue(coverPage,value);
}
void ComicInfo::setNumPages(int value)
{
setValue(numPages,value);
}
void ComicInfo::setNumber(int value)
{
setValue(number,value);
}
void ComicInfo::setIsBis(bool value)
{
setValue(isBis,value);
}
void ComicInfo::setCount(int value)
{
setValue(count,value);
}
void ComicInfo::setVolume(QString value)
{
setValue(volume,value);
}
void ComicInfo::setStoryArc(QString value)
{
setValue(storyArc,value);
}
void ComicInfo::setArcNumber(int value)
{
setValue(arcNumber,value);
}
void ComicInfo::setArcCount(int value)
{
setValue(arcCount,value);
}
void ComicInfo::setGenere(QString value)
{
setValue(genere,value);
}
void ComicInfo::setWriter(QString value)
{
setValue(writer,value);
}
void ComicInfo::setPenciller(QString value)
{
setValue(penciller,value);
}
void ComicInfo::setInker(QString value)
{
setValue(inker,value);
}
void ComicInfo::setColorist(QString value)
{
setValue(colorist,value);
}
void ComicInfo::setLetterer(QString value)
{
setValue(letterer,value);
}
void ComicInfo::setCoverArtist(QString value)
{
setValue(coverArtist,value);
}
void ComicInfo::setDate(QString value)
{
setValue(date,value);
}
void ComicInfo::setPublisher(QString value)
{
setValue(publisher,value);
}
void ComicInfo::setFormat(QString value)
{
setValue(format,value);
}
void ComicInfo::setColor(bool value)
{
setValue(color,value);
}
void ComicInfo::setAgeRating(QString value)
{
setValue(ageRating,value);
}
void ComicInfo::setSynopsis(QString value)
{
setValue(synopsis,value);
}
void ComicInfo::setCharacters(QString value)
{
setValue(characters,value);
}
void ComicInfo::setNotes(QString value)
{
setValue(notes,value);
}*/
QPixmap ComicInfo::getCover(const QString & basePath)
{
if(cover.isNull())
{
cover.load(basePath + "/.yacreaderlibrary/covers/" + hash + ".jpg");
}
QPixmap c;
c.convertFromImage(cover);
return c;
}
QDataStream &operator<<(QDataStream & stream, const ComicDB & comic)
{
stream << comic.id;
stream << comic.name;
stream << comic.parentId;
stream << comic.path;
stream << comic._hasCover;
stream << comic.info;
return stream;
}
QDataStream &operator>>(QDataStream & stream, ComicDB & comic)
{
stream >> comic.id;
stream >> comic.name;
stream >> comic.parentId;
stream >> comic.path;
stream >> comic._hasCover;
stream >> comic.info;
return stream;
}
QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo)
{
stream << comicInfo.id;
stream << comicInfo.read;
stream << comicInfo.edited;
stream << comicInfo.hash;
stream << comicInfo.existOnDb;
stream << comicInfo.hasBeenOpened;
stream << comicInfo.rating;
stream << comicInfo.currentPage;
stream << comicInfo.bookmark1;
stream << comicInfo.bookmark2;
stream << comicInfo.bookmark3;
stream << comicInfo.brightness;
stream << comicInfo.contrast;
stream << comicInfo.gamma;
stream << comicInfo.title;
stream << comicInfo.coverPage;
stream << comicInfo.numPages;
stream << comicInfo.number;
stream << comicInfo.isBis;
stream << comicInfo.count;
stream << comicInfo.volume;
stream << comicInfo.storyArc;
stream << comicInfo.arcNumber;
stream << comicInfo.arcCount;
stream << comicInfo.genere;
stream << comicInfo.writer;
stream << comicInfo.penciller;
stream << comicInfo.inker;
stream << comicInfo.colorist;
stream << comicInfo.letterer;
stream << comicInfo.coverArtist;
stream << comicInfo.date;
stream << comicInfo.publisher;
stream << comicInfo.format;
stream << comicInfo.color;
stream << comicInfo.ageRating;
stream << comicInfo.synopsis;
stream << comicInfo.characters;
stream << comicInfo.notes;
stream << comicInfo.comicVineID;
return stream;
}
QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo)
{
stream >> comicInfo.id;
stream >> comicInfo.read;
stream >> comicInfo.edited;
stream >> comicInfo.hash;
stream >> comicInfo.existOnDb;
stream >> comicInfo.hasBeenOpened;
stream >> comicInfo.rating;
stream >> comicInfo.currentPage;
stream >> comicInfo.bookmark1;
stream >> comicInfo.bookmark2;
stream >> comicInfo.bookmark3;
stream >> comicInfo.brightness;
stream >> comicInfo.contrast;
stream >> comicInfo.gamma;
stream >> comicInfo.title;
stream >> comicInfo.coverPage;
stream >> comicInfo.numPages;
stream >> comicInfo.number;
stream >> comicInfo.isBis;
stream >> comicInfo.count;
stream >> comicInfo.volume;
stream >> comicInfo.storyArc;
stream >> comicInfo.arcNumber;
stream >> comicInfo.arcCount;
stream >> comicInfo.genere;
stream >> comicInfo.writer;
stream >> comicInfo.penciller;
stream >> comicInfo.inker;
stream >> comicInfo.colorist;
stream >> comicInfo.letterer;
stream >> comicInfo.coverArtist;
stream >> comicInfo.date;
stream >> comicInfo.publisher;
stream >> comicInfo.format;
stream >> comicInfo.color;
stream >> comicInfo.ageRating;
stream >> comicInfo.synopsis;
stream >> comicInfo.characters;
stream >> comicInfo.notes;
stream >> comicInfo.comicVineID;
return stream;
}

157
common/comic_db.h Normal file
View File

@ -0,0 +1,157 @@
#ifndef __COMICDB_H
#define __COMICDB_H
#include "library_item.h"
#include <QVariant>
#include <QList>
#include <QPixmap>
#include <QImage>
#include <QMetaType>
class ComicInfo
{
public:
ComicInfo();
ComicInfo(const ComicInfo & comicInfo);
~ComicInfo();
ComicInfo & operator=(const ComicInfo & comicInfo);
//mandatory fields
qulonglong id;
bool read;
bool edited;
QString hash;
bool existOnDb;
int rating;
bool hasBeenOpened;
//viewer
int currentPage;
int bookmark1;
int bookmark2;
int bookmark3;
int brightness;
int contrast;
int gamma;
//-----------------
QVariant title;//string
QVariant coverPage;//int
QVariant numPages;//int
QVariant number;//int
QVariant isBis;//bool
QVariant count;//int
QVariant volume;//string
QVariant storyArc;//string
QVariant arcNumber;//int
QVariant arcCount;//int
QVariant genere;//string
QVariant writer;//string
QVariant penciller;//string
QVariant inker;//string
QVariant colorist;//string
QVariant letterer;//string
QVariant coverArtist;//string
QVariant date;//string
QVariant publisher;//string
QVariant format;//string
QVariant color;//bool
QVariant ageRating;//string
QVariant synopsis;//string
QVariant characters;//string
QVariant notes;//string
QVariant comicVineID;//string
QImage cover;
/*void setTitle(QVariant value);
void setCoverPage(QVariant value);
void setNumPages(QVariant value);
void setNumber(QVariant value);
void setIsBis(QVariant value);
void setCount(QVariant value);
void setVolume(QVariant value);
void setStoryArc(QVariant value);
void setArcNumber(QVariant value);
void setArcCount(QVariant value);
void setGenere(QVariant value);
void setWriter(QVariant value);
void setPenciller(QVariant value);
void setInker(QVariant value);
void setColorist(QVariant value);
void setLetterer(QVariant value);
void setCoverArtist(QVariant value);
void setDate(QVariant value);
void setPublisher(QVariant value);
void setFormat(QVariant value);
void setColor(QVariant value);
void setAgeRating(QVariant value);
void setSynopsis(QVariant value);
void setCharacters(QVariant value);
void setNotes(QVariant value);*/
QPixmap getCover(const QString & basePath);
friend QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo);
friend QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo);
private:
};
class ComicDB : public LibraryItem
{
public:
ComicDB();
bool isDir();
bool _hasCover;
bool hasCover() {return _hasCover;};
//return comic file name
QString getFileName() const;
//returns comic title if it isn't null or empty, in other case returns fileName
QString getTitleOrFileName() const;
//returns parent folder name
QString getParentFolderName() const;
//return the size of the file in bytes
qulonglong getFileSize() const;
QString toTXT();
ComicInfo info;
bool operator==(const ComicDB & other){return id == other.id;};
friend QDataStream &operator<<(QDataStream &, const ComicDB &);
friend QDataStream &operator>>(QDataStream &, ComicDB &);
};
Q_DECLARE_METATYPE(ComicDB);
#endif

View File

@ -0,0 +1 @@
#include "custom_widgets.h"

6
common/custom_widgets.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __CUSTOM_WIDGETS_H
#define __CUSTOM_WIDGETS_H
#endif

21
common/exit_check.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "exit_check.h"
#include "yacreader_global.h"
#include <QMessageBox>
using namespace YACReader;
void YACReader::exitCheck(int ret)
{
switch(ret)
{
case YACReader::SevenZNotFound:
QMessageBox::critical(0,QObject::tr("7z lib not found"),QObject::tr("unable to load 7z lib from ./utils"));
break;
default:
break;
}
}

9
common/exit_check.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef EXIT_CHECK_H
#define EXIT_CHECK_H
namespace YACReader
{
void exitCheck(int ret);
}
#endif

0
common/folder.cpp Normal file
View File

30
common/folder.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef __FOLDER_H
#define __FOLDER_H
#include "library_item.h"
#include <QList>
class Folder : public LibraryItem
{
public:
bool knownParent;
bool knownId;
Folder():knownParent(false), knownId(false){};
Folder(qulonglong sid, qulonglong pid,QString fn, QString fp):knownParent(true), knownId(true){id = sid; parentId = pid;name = fn; path = fp;};
Folder(QString fn, QString fp):knownParent(false), knownId(false){name = fn; path = fp;};
void setId(qulonglong sid){id = sid;knownId = true;};
void setFather(qulonglong pid){parentId = pid;knownParent = true;};
bool isDir() {return true;};
bool isFinished() const {return finished;};
bool isCompleted() const {return completed;};
void setFinished(bool b) {finished = b;};
void setCompleted(bool b) {completed = b;};
private:
bool finished;
bool completed;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,383 @@
//OpenGL Coverflow API by J.Roth
#ifndef __YACREADER_FLOW_GL_H
#define __YACREADER_FLOW_GL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
#include <QtWidgets>
#include "pictureflow.h" //TODO mover los tipos de flow de sitio
#include "scroll_management.h"
class ImageLoaderGL;
class QGLContext;
class WidgetLoader;
class ImageLoaderByteArrayGL;
enum Performance
{
low=0,
medium,
high,
ultraHigh
};
//Cover Vector
struct YACReader3DVector{
float x;
float y;
float z;
float rot;
};
//the image/texture info struct
struct YACReader3DImage{
QOpenGLTexture * texture;
//char name[256];
float width;
float height;
int index;
YACReader3DVector current;
YACReader3DVector animEnd;
};
struct Preset{
/*** Animation Settings ***/
//sets the speed of the animation
float animationStep;
//sets the acceleration of the animation
float animationSpeedUp;
//sets the maximum speed of the animation
float animationStepMax;
//sets the distance of view
float animationFadeOutDist;
//sets the rotation increasion
float preRotation;
//sets the light strenght on rotation
float viewRotateLightStrenght;
//sets the speed of the rotation
float viewRotateAdd;
//sets the speed of reversing the rotation
float viewRotateSub;
//sets the maximum view angle
float viewAngle;
/*** Position Configuration ***/
//the X Position of the Coverflow
float cfX;
//the Y Position of the Coverflow
float cfY;
//the Z Position of the Coverflow
float cfZ;
//the X Rotation of the Coverflow
float cfRX;
//the Y Rotation of the Coverflow
float cfRY;
//the Z Rotation of the Coverflow
float cfRZ;
//sets the rotation of each cover
float rotation;
//sets the distance between the covers
float xDistance;
//sets the distance between the centered and the non centered covers
float centerDistance;
//sets the pushback amount
float zDistance;
//sets the elevation amount
float yDistance;
float zoom;
};
extern struct Preset defaultYACReaderFlowConfig;
extern struct Preset presetYACReaderFlowClassicConfig;
extern struct Preset presetYACReaderFlowStripeConfig;
extern struct Preset presetYACReaderFlowOverlappedStripeConfig;
extern struct Preset pressetYACReaderFlowUpConfig;
extern struct Preset pressetYACReaderFlowDownConfig;
class YACReaderFlowGL : public QOpenGLWidget, public ScrollManagement
{
Q_OBJECT
protected:
int timerId;
/*** System variables ***/
YACReader3DImage dummy;
int viewRotateActive;
float stepBackup;
/*functions*/
void calcPos(YACReader3DImage & image, int pos);
void calcVector(YACReader3DVector & vector, int pos);
//returns true if the animation is finished for Current
bool animate(YACReader3DVector &currentVector, YACReader3DVector &toVector);
void drawCover(const YACReader3DImage & image);
void udpatePerspective(int width, int height);
int updateCount;
WidgetLoader * loader;
int fontSize;
QOpenGLTexture * defaultTexture;
QOpenGLTexture * markTexture;
QOpenGLTexture * readingTexture;
void initializeGL();
void paintGL();
void timerEvent(QTimerEvent *);
//number of Covers
int numObjects;
int lazyPopulateObjects;
bool showMarks;
QVector<bool> loaded;
QVector<YACReaderComicReadStatus> marks;
QVector<YACReader3DImage> images;
bool hasBeenInitialized;
Performance performance;
bool bUseVSync;
/*** Animation Settings ***/
Preset config;
//sets/returns the curent selected cover
int currentSelected;
//defines the position of the centered cover
YACReader3DVector centerPos;
/*** Style ***/
//sets the amount of shading of the covers in the back (0-1)
float shadingTop;
float shadingBottom;
//sets the reflection strenght (0-1)
float reflectionUp;
float reflectionBottom;
/*** System info ***/
float viewRotate;
//sets the updateInterval in ms
static int updateInterval;
void startAnimationTimer();
void stopAnimationTimer();
public:
/*Constructor*/
YACReaderFlowGL(QWidget *parent = 0,struct Preset p = pressetYACReaderFlowDownConfig);
virtual ~YACReaderFlowGL();
//size;
QSize minimumSizeHint() const;
//QSize sizeHint() const;
/*functions*/
//if called it moves the coverflow to the left
void showPrevious();
//if called it moves the coverflow to the right
void showNext();
//go to
void setCurrentIndex(int pos);
//must be called whenever the coverflow animation is stopped
void cleanupAnimation();
//Draws the coverflow
void draw();
//updates the coverflow
void updatePositions();
//inserts a new item to the coverflow
//if item is set to a value > -1 it updates a already set value
//otherwise a new entry is set
void insert(char *name, QOpenGLTexture * texture, float x, float y, int item = -1);
//removes a item
virtual void remove(int item);
//replaces the texture of the item 'item' with Tex
void replace(char *name, QOpenGLTexture * texture, float x, float y, int item);
//create n covers with the default nu
void populate(int n);
/*Info*/
//retuns the YACReader3DImage Struct of the current selected item
//to read title or textures
YACReader3DImage getCurrentSelected();
public slots:
void setCF_RX(int value);
//the Y Rotation of the Coverflow
void setCF_RY(int value);
//the Z Rotation of the Coverflow
void setCF_RZ(int value);
//perspective
void setZoom(int zoom);
void setRotation(int angle);
//sets the distance between the covers
void setX_Distance(int distance);
//sets the distance between the centered and the non centered covers
void setCenter_Distance(int distance);
//sets the pushback amount
void setZ_Distance(int distance);
void setCF_Y(int value);
void setCF_Z(int value);
void setY_Distance(int value);
void setFadeOutDist(int value);
void setLightStrenght(int value);
void setMaxAngle(int value);
void setPreset(const Preset & p);
void setPerformance(Performance performance);
void useVSync(bool b);
virtual void updateImageData() = 0;
void reset();
void reload();
//interface with yacreaderlibrary, compatibility
void setShowMarks(bool value);
void setMarks(QVector<YACReaderComicReadStatus> marks);
void setMarkImage(QImage & image);
void markSlide(int index, YACReaderComicReadStatus status);
void unmarkSlide(int index);
void setSlideSize(QSize size);
void clear();
void setCenterIndex(unsigned int index);
void showSlide(int index);
int centerIndex();
void updateMarks();
//void setFlowType(PictureFlow::FlowType flowType);
void render();
//void paintEvent(QPaintEvent *event);
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent * event);
void keyPressEvent(QKeyEvent *event);
void resizeGL(int width, int height);
friend class ImageLoaderGL;
friend class ImageLoaderByteArrayGL;
signals:
void centerIndexChanged(int);
void selected(unsigned int);
};
class YACReaderComicFlowGL : public YACReaderFlowGL
{
public:
YACReaderComicFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig);
void setImagePaths(QStringList paths);
void updateImageData();
void remove(int item);
void resortCovers(QList<int> newOrder);
friend class ImageLoaderGL;
private:
ImageLoaderGL * worker;
protected:
QList<QString> paths;
};
class YACReaderPageFlowGL : public YACReaderFlowGL
{
public:
YACReaderPageFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig);
~YACReaderPageFlowGL();
void updateImageData();
void populate(int n);
QVector<bool> imagesReady;
QVector<QByteArray> rawImages;
QVector<bool> imagesSetted;
friend class ImageLoaderByteArrayGL;
private:
ImageLoaderByteArrayGL * worker;
};
class ImageLoaderGL : public QThread
{
public:
ImageLoaderGL(YACReaderFlowGL * flow);
~ImageLoaderGL();
// returns FALSE if worker is still busy and can't take the task
bool busy() const;
void generate(int index, const QString& fileName);
void reset(){idx = -1;fileName="";}
int index() const { return idx; }
void lock();
void unlock();
QImage result();
YACReaderFlowGL * flow;
GLuint resultTexture;
QImage loadImage(const QString& fileName);
protected:
void run();
private:
QMutex mutex;
QWaitCondition condition;
bool restart;
bool working;
int idx;
QString fileName;
QSize size;
QImage img;
};
class ImageLoaderByteArrayGL : public QThread
{
public:
ImageLoaderByteArrayGL(YACReaderFlowGL * flow);
~ImageLoaderByteArrayGL();
// returns FALSE if worker is still busy and can't take the task
bool busy() const;
void generate(int index, const QByteArray& raw);
void reset(){idx = -1; rawData.clear();}
int index() const { return idx; }
QImage result();
YACReaderFlowGL * flow;
GLuint resultTexture;
QImage loadImage(const QByteArray& rawData);
protected:
void run();
private:
QMutex mutex;
QWaitCondition condition;
bool restart;
bool working;
int idx;
QByteArray rawData;
QSize size;
QImage img;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,380 @@
//OpenGL Coverflow API by J.Roth
#ifndef __YACREADER_FLOW_GL_H
#define __YACREADER_FLOW_GL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <QtOpenGL>
#include <QGLWidget>
#include <QtWidgets>
#include "pictureflow.h" //TODO mover los tipos de flow de sitio
#include "scroll_management.h"
class ImageLoaderGL;
class QGLContext;
class WidgetLoader;
class ImageLoaderByteArrayGL;
enum Performance
{
low=0,
medium,
high,
ultraHigh
};
//Cover Vector
struct YACReader3DVector{
float x;
float y;
float z;
float rot;
};
//the image/texture info struct
struct YACReader3DImage{
GLuint texture;
//char name[256];
float width;
float height;
int index;
YACReader3DVector current;
YACReader3DVector animEnd;
};
struct Preset{
/*** Animation Settings ***/
//sets the speed of the animation
float animationStep;
//sets the acceleration of the animation
float animationSpeedUp;
//sets the maximum speed of the animation
float animationStepMax;
//sets the distance of view
float animationFadeOutDist;
//sets the rotation increasion
float preRotation;
//sets the light strenght on rotation
float viewRotateLightStrenght;
//sets the speed of the rotation
float viewRotateAdd;
//sets the speed of reversing the rotation
float viewRotateSub;
//sets the maximum view angle
float viewAngle;
/*** Position Configuration ***/
//the X Position of the Coverflow
float cfX;
//the Y Position of the Coverflow
float cfY;
//the Z Position of the Coverflow
float cfZ;
//the X Rotation of the Coverflow
float cfRX;
//the Y Rotation of the Coverflow
float cfRY;
//the Z Rotation of the Coverflow
float cfRZ;
//sets the rotation of each cover
float rotation;
//sets the distance between the covers
float xDistance;
//sets the distance between the centered and the non centered covers
float centerDistance;
//sets the pushback amount
float zDistance;
//sets the elevation amount
float yDistance;
float zoom;
};
extern struct Preset defaultYACReaderFlowConfig;
extern struct Preset presetYACReaderFlowClassicConfig;
extern struct Preset presetYACReaderFlowStripeConfig;
extern struct Preset presetYACReaderFlowOverlappedStripeConfig;
extern struct Preset pressetYACReaderFlowUpConfig;
extern struct Preset pressetYACReaderFlowDownConfig;
class YACReaderFlowGL : public QGLWidget, public ScrollManagement
{
Q_OBJECT
protected:
int timerId;
/*** System variables ***/
YACReader3DImage dummy;
int viewRotateActive;
float stepBackup;
/*functions*/
void calcPos(YACReader3DImage & image, int pos);
void calcVector(YACReader3DVector & vector, int pos);
//returns true if the animation is finished for Current
bool animate(YACReader3DVector &currentVector, YACReader3DVector &toVector);
void drawCover(const YACReader3DImage & image);
void udpatePerspective(int width, int height);
int updateCount;
WidgetLoader * loader;
int fontSize;
GLuint defaultTexture;
GLuint markTexture;
GLuint readingTexture;
void initializeGL();
void paintGL();
void timerEvent(QTimerEvent *);
//number of Covers
int numObjects;
int lazyPopulateObjects;
bool showMarks;
QVector<bool> loaded;
QVector<YACReaderComicReadStatus> marks;
QVector<YACReader3DImage> images;
bool hasBeenInitialized;
Performance performance;
bool bUseVSync;
/*** Animation Settings ***/
Preset config;
//sets/returns the curent selected cover
int currentSelected;
//defines the position of the centered cover
YACReader3DVector centerPos;
/*** Style ***/
//sets the amount of shading of the covers in the back (0-1)
float shadingTop;
float shadingBottom;
//sets the reflection strenght (0-1)
float reflectionUp;
float reflectionBottom;
/*** System info ***/
float viewRotate;
//sets the updateInterval in ms
static int updateInterval;
void startAnimationTimer();
void stopAnimationTimer();
public:
/*Constructor*/
YACReaderFlowGL(QWidget *parent = 0,struct Preset p = pressetYACReaderFlowDownConfig);
virtual ~YACReaderFlowGL();
//size;
QSize minimumSizeHint() const;
//QSize sizeHint() const;
/*functions*/
//if called it moves the coverflow to the left
void showPrevious();
//if called it moves the coverflow to the right
void showNext();
//go to
void setCurrentIndex(int pos);
//must be called whenever the coverflow animation is stopped
void cleanupAnimation();
//Draws the coverflow
void draw();
//updates the coverflow
void updatePositions();
//inserts a new item to the coverflow
//if item is set to a value > -1 it updates a already set value
//otherwise a new entry is set
void insert(const char *name, GLuint Tex, float x, float y,int item = -1);
//removes a item
virtual void remove(int item);
//replaces the texture of the item 'item' with Tex
void replace(const char *name, GLuint Tex, float x, float y,int item);
//create n covers with the default nu
void populate(int n);
/*Info*/
//retuns the YACReader3DImage Struct of the current selected item
//to read title or textures
YACReader3DImage getCurrentSelected();
public slots:
void setCF_RX(int value);
//the Y Rotation of the Coverflow
void setCF_RY(int value);
//the Z Rotation of the Coverflow
void setCF_RZ(int value);
//perspective
void setZoom(int zoom);
void setRotation(int angle);
//sets the distance between the covers
void setX_Distance(int distance);
//sets the distance between the centered and the non centered covers
void setCenter_Distance(int distance);
//sets the pushback amount
void setZ_Distance(int distance);
void setCF_Y(int value);
void setCF_Z(int value);
void setY_Distance(int value);
void setFadeOutDist(int value);
void setLightStrenght(int value);
void setMaxAngle(int value);
void setPreset(const Preset & p);
void setPerformance(Performance performance);
void useVSync(bool b);
virtual void updateImageData() = 0;
void reset();
void reload();
//interface with yacreaderlibrary, compatibility
void setShowMarks(bool value);
void setMarks(QVector<YACReaderComicReadStatus> marks);
void setMarkImage(QImage & image);
void markSlide(int index, YACReaderComicReadStatus status);
void unmarkSlide(int index);
void setSlideSize(QSize size);
void clear();
void setCenterIndex(unsigned int index);
void showSlide(int index);
int centerIndex();
void updateMarks();
//void setFlowType(PictureFlow::FlowType flowType);
void render();
//void paintEvent(QPaintEvent *event);
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent * event);
void keyPressEvent(QKeyEvent *event);
void resizeGL(int width, int height);
friend class ImageLoaderGL;
friend class ImageLoaderByteArrayGL;
signals:
void centerIndexChanged(int);
void selected(unsigned int);
};
class YACReaderComicFlowGL : public YACReaderFlowGL
{
public:
YACReaderComicFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig);
void setImagePaths(QStringList paths);
void updateImageData();
void remove(int item);
void resortCovers(QList<int> newOrder);
friend class ImageLoaderGL;
private:
ImageLoaderGL * worker;
protected:
QList<QString> paths;
};
class YACReaderPageFlowGL : public YACReaderFlowGL
{
public:
YACReaderPageFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig);
~YACReaderPageFlowGL();
void updateImageData();
void populate(int n);
QVector<bool> imagesReady;
QVector<QByteArray> rawImages;
QVector<bool> imagesSetted;
friend class ImageLoaderByteArrayGL;
private:
ImageLoaderByteArrayGL * worker;
};
class ImageLoaderGL : public QThread
{
public:
ImageLoaderGL(YACReaderFlowGL * flow);
~ImageLoaderGL();
// returns FALSE if worker is still busy and can't take the task
bool busy() const;
void generate(int index, const QString& fileName);
void reset(){idx = -1;fileName="";}
int index() const { return idx; }
void lock();
void unlock();
QImage result();
YACReaderFlowGL * flow;
GLuint resultTexture;
QImage loadImage(const QString& fileName);
protected:
void run();
private:
QMutex mutex;
QWaitCondition condition;
bool restart;
bool working;
int idx;
QString fileName;
QSize size;
QImage img;
};
class ImageLoaderByteArrayGL : public QThread
{
public:
ImageLoaderByteArrayGL(YACReaderFlowGL * flow);
~ImageLoaderByteArrayGL();
// returns FALSE if worker is still busy and can't take the task
bool busy() const;
void generate(int index, const QByteArray& raw);
void reset(){idx = -1; rawData.clear();}
int index() const { return idx; }
QImage result();
YACReaderFlowGL * flow;
GLuint resultTexture;
QImage loadImage(const QByteArray& rawData);
protected:
void run();
private:
QMutex mutex;
QWaitCondition condition;
bool restart;
bool working;
int idx;
QByteArray rawData;
QSize size;
QImage img;
};
#endif

65
common/http_worker.cpp Normal file
View File

@ -0,0 +1,65 @@
#include "http_worker.h"
#include <QMessageBox>
#include <QUrl>
#include <QtGlobal>
#include <QStringList>
#include <QNetworkAccessManager>
#include <QEventLoop>
#include <QTimer>
#include <QNetworkRequest>
#include <QNetworkReply>
#define PREVIOUS_VERSION "6.0.0"
HttpWorker::HttpWorker(const QString & urlString)
:QThread(),url(urlString),_error(false),_timeout(false)
{
}
void HttpWorker::get()
{
this->start();
}
QByteArray HttpWorker::getResult()
{
return result;
}
bool HttpWorker::wasValid()
{
return !_error;
}
bool HttpWorker::wasTimeout()
{
return _timeout;
}
void HttpWorker::run()
{
QNetworkAccessManager manager;
QEventLoop q;
QTimer tT;
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit()));
QNetworkReply *reply = manager.get(QNetworkRequest(url));
tT.start(5000); // 5s timeout
q.exec();
if(tT.isActive()){
// download complete
_error = !(reply->error() == QNetworkReply::NoError);
result = reply->readAll();
emit dataReady(result);
tT.stop();
} else {
_timeout = true;
emit timeout();
}
}

32
common/http_worker.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef __HTTP_WORKER_H
#define __HTTP_WORKER_H
#include <QWidget>
#include <QByteArray>
#include <QThread>
#include <QUrl>
#include "yacreader_global.h"
class HttpWorker : public QThread
{
Q_OBJECT
public:
HttpWorker(const QString & urlString);
public slots:
void get();
QByteArray getResult();
bool wasValid();
bool wasTimeout();
private:
void run();
QUrl url;
int httpGetId;
QByteArray result;
bool _error;
bool _timeout;
signals:
void dataReady(const QByteArray &);
void timeout();
};
#endif

0
common/library_item.cpp Normal file
View File

16
common/library_item.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __LIBRARY_ITEM_H
#define __LIBRARY_ITEM_H
#include <QObject>
class LibraryItem
{
public:
virtual bool isDir() = 0;
QString name;
QString path;
qulonglong parentId;
qulonglong id;
};
#endif

View File

@ -0,0 +1,54 @@
#include "onstart_flow_selection_dialog.h"
#include <QPushButton>
#include <QHBoxLayout>
#include <qlocale.h>
OnStartFlowSelectionDialog::OnStartFlowSelectionDialog(QWidget * parent)
:QDialog(parent)
{
setModal(true);
QPushButton * acceptHW = new QPushButton(this);
connect(acceptHW,SIGNAL(clicked()),this,SLOT(accept()));
QPushButton * rejectHW = new QPushButton(this); //and use SW flow
connect(rejectHW,SIGNAL(clicked()),this,SLOT(reject()));
acceptHW->setGeometry(90,165,110,118);
acceptHW->setFlat(true);
acceptHW->setAutoFillBackground(true);
rejectHW->setGeometry(464,165,110,118);
rejectHW->setFlat(true);
rejectHW->setAutoFillBackground(true);
QPalette paletteHW;
QLocale locale = this->locale();
QLocale::Language language = locale.language();
/*if(language == QLocale::Spanish)
paletteHW.setBrush(acceptHW->backgroundRole(), QBrush(QImage(":/images/useNewFlowButton_es.png")));
else
paletteHW.setBrush(acceptHW->backgroundRole(), QBrush(QImage(":/images/useNewFlowButton.png")));*/
paletteHW.setBrush(acceptHW->backgroundRole(), QBrush(QImage(":/images/nonexxx.png")));
acceptHW->setPalette(paletteHW);
QPalette paletteSW;
paletteSW.setBrush(rejectHW->backgroundRole(), QBrush(QImage(":/images/nonexxx.png")));
rejectHW->setPalette(paletteSW);
//QHBoxLayout * layout = new QHBoxLayout;
//layout->addWidget(acceptHW);
//layout->addWidget(rejectHW);
QPalette palette;
if(language == QLocale::Spanish)
palette.setBrush(this->backgroundRole(), QBrush(QImage(":/images/onStartFlowSelection_es.png")));
else
palette.setBrush(this->backgroundRole(), QBrush(QImage(":/images/onStartFlowSelection.png")));
setPalette(palette);
//setLayout(layout);
resize(664,371);
}

View File

@ -0,0 +1,13 @@
#ifndef ONSTART_FLOW_SELECTION_DIALOG_H
#define ONSTART_FLOW_SELECTION_DIALOG_H
#include <QDialog>
class OnStartFlowSelectionDialog : public QDialog
{
Q_OBJECT
public:
OnStartFlowSelectionDialog(QWidget * parent = 0);
};
#endif

69
common/opengl_checker.cpp Normal file
View File

@ -0,0 +1,69 @@
#include "opengl_checker.h"
#include "QsLog.h"
OpenGLChecker::OpenGLChecker()
:compatibleOpenGLVersion(true)
{
QOpenGLContext * openGLContext = new QOpenGLContext();
openGLContext->create();
if(!openGLContext->isValid())
{
compatibleOpenGLVersion = false;
description = "unable to create QOpenGLContext";
}
QSurfaceFormat format = openGLContext->format();
int majorVersion = format.majorVersion();
int minorVersion = format.minorVersion();
QString type;
switch (format.renderableType()) {
case QSurfaceFormat::OpenGL:
type = "desktop";
break;
case QSurfaceFormat::OpenGLES:
type = "OpenGL ES";
break;
case QSurfaceFormat::OpenVG:
type = "OpenVG";
default: case QSurfaceFormat::DefaultRenderableType:
type = "unknown";
break;
}
delete openGLContext;
description = QString("%1.%2 %3").arg(majorVersion).arg(minorVersion).arg(type);
if(format.renderableType() != QSurfaceFormat::OpenGL) //Desktop OpenGL
compatibleOpenGLVersion = false;
#ifdef Q_OS_WIN //TODO check Qt version, and set this values depending on the use of QOpenGLWidget or QGLWidget
static const int majorTargetVersion = 1;
static const int minorTargetVersion = 4;
#else
static const int majorTargetVersion = 2;
static const int minorTargetVersion = 0;
#endif
if(majorVersion < majorTargetVersion)
compatibleOpenGLVersion = false;
if(majorVersion == majorTargetVersion && minorVersion < minorTargetVersion)
compatibleOpenGLVersion = false;
}
QString OpenGLChecker::textVersionDescription()
{
return description;
}
bool OpenGLChecker::hasCompatibleOpenGLVersion()
{
return compatibleOpenGLVersion;
}

17
common/opengl_checker.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef OPENGL_CHECKER_H
#define OPENGL_CHECKER_H
#include <QOpenGLContext>
class OpenGLChecker
{
public:
OpenGLChecker();
bool hasCompatibleOpenGLVersion();
QString textVersionDescription();
private:
QString description;
bool compatibleOpenGLVersion;
};
#endif // OPENGL_CHECKER_H

22
common/pdf_comic.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef PDF_COMIC_H
#define PDF_COMIC_H
#include <QObject>
#include <QImage>
class MacOSXPDFComic
{
public:
MacOSXPDFComic();
~MacOSXPDFComic();
bool openComic(const QString & path);
void closeComic();
unsigned int numPages();
QImage getPage(const int page);
void releaseLastPageData();
private:
void * document;
void * lastPageData;
};
#endif // PDF_COMIC_H

117
common/pdf_comic.mm Normal file
View File

@ -0,0 +1,117 @@
#include "pdf_comic.h"
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
#include "QsLog.h"
#include "QsLogDest.h"
MacOSXPDFComic::MacOSXPDFComic()
{
}
MacOSXPDFComic::~MacOSXPDFComic()
{
CGPDFDocumentRelease((CGPDFDocumentRef)document);
}
bool MacOSXPDFComic::openComic(const QString &path)
{
CFURLRef pdfFileUrl;
CFStringRef str;
str=CFStringCreateWithCString( kCFAllocatorDefault,path.toUtf8().data(),kCFStringEncodingUTF8);
pdfFileUrl=CFURLCreateWithFileSystemPath( kCFAllocatorDefault,str,kCFURLPOSIXPathStyle,true );
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfFileUrl);
document = pdf;
CFRelease(str);
CFRelease(pdfFileUrl);
return true;
}
void MacOSXPDFComic::closeComic()
{
//CGPDFDocumentRelease((CGPDFDocumentRef)document);
}
unsigned int MacOSXPDFComic::numPages()
{
return (int)CGPDFDocumentGetNumberOfPages((CGPDFDocumentRef)document);
}
QImage MacOSXPDFComic::getPage(const int pageNum)
{
CGPDFPageRef page = CGPDFDocumentGetPage((CGPDFDocumentRef)document, pageNum+1);
// Changed this line for the line above which is a generic line
//CGPDFPageRef page = [self getPage:page_number];
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
int width = 1200;
//NSLog(@"-----%f",pageRect.size.width);
CGFloat pdfScale = float(width)/pageRect.size.width;
pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);
pageRect.origin = CGPointZero;
CGColorSpaceRef genericColorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(NULL,
pageRect.size.width,
pageRect.size.height,
8, 0,
genericColorSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little
);
CGContextSetInterpolationQuality(bitmapContext, kCGInterpolationHigh);
CGContextSetRenderingIntent(bitmapContext, kCGRenderingIntentDefault);
CGContextSetRGBFillColor( bitmapContext, 1.0, 1.0, 1.0, 1.0 );
CGContextFillRect( bitmapContext, CGContextGetClipBoundingBox( bitmapContext ));
//CGContextTranslateCTM( bitmapContext, 0, pageRect.size.height );
//CGContextScaleCTM( bitmapContext, 1.0, -1.0 );
CGContextConcatCTM(bitmapContext, CGAffineTransformMakeScale(pdfScale, pdfScale));
/*CGAffineTransform pdfXfm = CGPDFPageGetDrawingTransform( page, kCGPDFMediaBox, CGRectMake(pageRect.origin.x, pageRect.origin.y, pageRect.size.width, pageRect.size.height) , 0, true );
*/
//CGContextConcatCTM( bitmapContext, pdfXfm );
CGContextDrawPDFPage(bitmapContext, page);
CGImageRef image = CGBitmapContextCreateImage(bitmapContext);
QImage qtImage;
CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(image));
lastPageData = (void *)dataRef;
const uchar *bytes = (const uchar *)CFDataGetBytePtr(dataRef);
qtImage = QImage(bytes, pageRect.size.width, pageRect.size.height, QImage::Format_ARGB32);
CGImageRelease(image);
//CFRelease(dataRef);
CGContextRelease(bitmapContext);
//CGPDFPageRelease(page);
CGColorSpaceRelease(genericColorSpace);
return qtImage;
}
void MacOSXPDFComic::releaseLastPageData()
{
CFRelease((CFDataRef)lastPageData);
}

1409
common/pictureflow.cpp Normal file

File diff suppressed because it is too large Load Diff

228
common/pictureflow.h Normal file
View File

@ -0,0 +1,228 @@
/*
PictureFlow - animated image show widget
http://pictureflow.googlecode.com
Copyright (C) 2008 Ariya Hidayat (ariya@kde.org)
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef PICTUREFLOW_H
#define PICTUREFLOW_H
#include <qwidget.h>
#include "yacreader_global.h" //FlowType
class PictureFlowPrivate;
using namespace YACReader;
/*!
Class PictureFlow implements an image show widget with animation effect
like Apple's CoverFlow (in iTunes and iPod). Images are arranged in form
of slides, one main slide is shown at the center with few slides on
the left and right sides of the center slide. When the next or previous
slide is brought to the front, the whole slides flow to the right or
the right with smooth animation effect; until the new slide is finally
placed at the center.
*/
class PictureFlow : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(QSize slideSize READ slideSize WRITE setSlideSize)
Q_PROPERTY(int slideCount READ slideCount)
Q_PROPERTY(int centerIndex READ centerIndex WRITE setCenterIndex)
public:
enum ReflectionEffect
{
NoReflection,
PlainReflection,
BlurredReflection
};
/*!
Creates a new PictureFlow widget.
*/
PictureFlow(QWidget* parent = 0, FlowType flowType = CoverFlowLike);
/*!
Destroys the widget.
*/
~PictureFlow();
/*!
Returns the background color.
*/
QColor backgroundColor() const;
/*!
Sets the background color. By default it is black.
*/
void setBackgroundColor(const QColor& c);
/*!
Returns the dimension of each slide (in pixels).
*/
QSize slideSize() const;
/*!
Sets the dimension of each slide (in pixels).
*/
void setSlideSize(QSize size);
/*!
Returns the total number of slides.
*/
int slideCount() const;
/*!
Returns QImage of specified slide.
*/
QImage slide(int index) const;
/*!
Returns the index of slide currently shown in the middle of the viewport.
*/
int centerIndex() const;
/*!
Returns the effect applied to the reflection.
*/
ReflectionEffect reflectionEffect() const;
/*!
Sets the effect applied to the reflection. The default is PlainReflection.
*/
void setReflectionEffect(ReflectionEffect effect);
public slots:
/*!
Adds a new slide.
*/
void addSlide(const QImage& image);
/*!
Adds a new slide.
*/
void addSlide(const QPixmap& pixmap);
/*!
Removes an existing slide.
*/
void removeSlide(int index);
/*!
Sets an image for specified slide. If the slide already exists,
it will be replaced.
*/
void setSlide(int index, const QImage& image);
/*!
Sets a pixmap for specified slide. If the slide already exists,
it will be replaced.
*/
void setSlide(int index, const QPixmap& pixmap);
/*!
Sets slide to be shown in the middle of the viewport. No animation
effect will be produced, unlike using showSlide.
*/
void setCenterIndex(int index);
/*!
Clears all slides.
*/
void clear();
/*!
Shows previous slide using animation effect.
*/
void showPrevious();
/*!
Shows next slide using animation effect.
*/
void showNext();
/*!
Go to specified slide using animation effect.
*/
void showSlide(unsigned int index);
/*!
Rerender the widget. Normally this function will be automatically invoked
whenever necessary, e.g. during the transition animation.
*/
void render();
/*!
Schedules a rendering update. Unlike render(), this function does not cause
immediate rendering.
*/
void triggerRender();
void setFlowType(FlowType flowType);
void setMarkImage(const QImage & mark);
void markSlide(int index, YACReaderComicReadStatus readStatus = Read);
void updateMarks();
void unmarkSlide(int index);
void setMarks(const QVector<YACReaderComicReadStatus> & marks);
void setShowMarks(bool enable);
QVector<YACReaderComicReadStatus> getMarks();
void resortCovers(QList<int> newOrder);
signals:
void centerIndexChanged(int index);
void centerIndexChangedSilent(int index);
public:
void paintEvent(QPaintEvent *event);
void keyPressEvent(QKeyEvent* event);
void mousePressEvent(QMouseEvent* event);
void resizeEvent(QResizeEvent* event);
private slots:
void updateAnimation();
private:
PictureFlowPrivate* d;
QImage mark;
int framesSkip;
};
#endif // PICTUREFLOW_H

262
common/qnaturalsorting.cpp Normal file
View File

@ -0,0 +1,262 @@
/* This file contains parts of the KDE libraries
Copyright (C) 1999 Ian Zepp (icszepp@islc.net)
Copyright (C) 2006 by Dominic Battre <dominic@battre.de>
Copyright (C) 2006 by Martin Pool <mbp@canonical.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "qnaturalsorting.h"
//from KDE
/*
int naturalCompare(const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity)
{
// This method chops the input a and b into pieces of
// digits and non-digits (a1.05 becomes a | 1 | . | 05)
// and compares these pieces of a and b to each other
// (first with first, second with second, ...).
//
// This is based on the natural sort order code code by Martin Pool
// http://sourcefrog.net/projects/natsort/
// Martin Pool agreed to license this under LGPL or GPL.
// FIXME: Using toLower() to implement case insensitive comparison is
// sub-optimal, but is needed because we compare strings with
// localeAwareCompare(), which does not know about case sensitivity.
// A task has been filled for this in Qt Task Tracker with ID 205990.
// http://trolltech.com/developer/task-tracker/index_html?method=entry&id=205990
QString a;
QString b;
if (caseSensitivity == Qt::CaseSensitive) {
a = _a;
b = _b;
} else {
a = _a.toLower();
b = _b.toLower();
}
const QChar* currA = a.unicode(); // iterator over a
const QChar* currB = b.unicode(); // iterator over b
if (currA == currB) {
return 0;
}
const QChar* begSeqA = currA; // beginning of a new character sequence of a
const QChar* begSeqB = currB;
while (!currA->isNull() && !currB->isNull()) {
if (currA->unicode() == QChar::ObjectReplacementCharacter) {
return 1;
}
if (currB->unicode() == QChar::ObjectReplacementCharacter) {
return -1;
}
if (currA->unicode() == QChar::ReplacementCharacter) {
return 1;
}
if (currB->unicode() == QChar::ReplacementCharacter) {
return -1;
}
// find sequence of characters ending at the first non-character
while (!currA->isNull() && !currA->isDigit() && !currA->isPunct() && !currA->isSpace()) {
++currA;
}
while (!currB->isNull() && !currB->isDigit() && !currB->isPunct() && !currB->isSpace()) {
++currB;
}
// compare these sequences
const QStringRef& subA(a.midRef(begSeqA - a.unicode(), currA - begSeqA));
const QStringRef& subB(b.midRef(begSeqB - b.unicode(), currB - begSeqB));
const int cmp = QStringRef::localeAwareCompare(subA, subB);
if (cmp != 0) {
return cmp < 0 ? -1 : +1;
}
if (currA->isNull() || currB->isNull()) {
break;
}
// find sequence of characters ending at the first non-character
while (currA->isPunct() || currA->isSpace() || currB->isPunct() || currB->isSpace()) {
if (*currA != *currB) {
return (*currA < *currB) ? -1 : +1;
}
++currA;
++currB;
}
// now some digits follow...
if ((*currA == '0') || (*currB == '0')) {
// one digit-sequence starts with 0 -> assume we are in a fraction part
// do left aligned comparison (numbers are considered left aligned)
while (1) {
if (!currA->isDigit() && !currB->isDigit()) {
break;
} else if (!currA->isDigit()) {
return +1;
} else if (!currB->isDigit()) {
return -1;
} else if (*currA < *currB) {
return -1;
} else if (*currA > *currB) {
return + 1;
}
++currA;
++currB;
}
} else {
// No digit-sequence starts with 0 -> assume we are looking at some integer
// do right aligned comparison.
//
// The longest run of digits wins. That aside, the greatest
// value wins, but we can't know that it will until we've scanned
// both numbers to know that they have the same magnitude.
bool isFirstRun = true;
int weight = 0;
while (1) {
if (!currA->isDigit() && !currB->isDigit()) {
if (weight != 0) {
return weight;
}
break;
} else if (!currA->isDigit()) {
if (isFirstRun) {
return *currA < *currB ? -1 : +1;
} else {
return -1;
}
} else if (!currB->isDigit()) {
if (isFirstRun) {
return *currA < *currB ? -1 : +1;
} else {
return +1;
}
} else if ((*currA < *currB) && (weight == 0)) {
weight = -1;
} else if ((*currA > *currB) && (weight == 0)) {
weight = + 1;
}
++currA;
++currB;
isFirstRun = false;
}
}
begSeqA = currA;
begSeqB = currB;
}
if (currA->isNull() && currB->isNull()) {
return 0;
}
return currA->isNull() ? -1 : + 1;
}
*/
static inline QChar getNextChar(const QString &s, int location)
{
return (location < s.length()) ? s.at(location) : QChar();
}
int naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
{
for (int l1 = 0, l2 = 0; l1 <= s1.count() && l2 <= s2.count(); ++l1, ++l2) {
// skip spaces, tabs and 0's
QChar c1 = getNextChar(s1, l1);
while (c1.isSpace())
c1 = getNextChar(s1, ++l1);
QChar c2 = getNextChar(s2, l2);
while (c2.isSpace())
c2 = getNextChar(s2, ++l2);
if (c1.isDigit() && c2.isDigit()) {
while (c1.digitValue() == 0)
c1 = getNextChar(s1, ++l1);
while (c2.digitValue() == 0)
c2 = getNextChar(s2, ++l2);
int lookAheadLocation1 = l1;
int lookAheadLocation2 = l2;
int currentReturnValue = 0;
// find the last digit, setting currentReturnValue as we go if it isn't equal
for (
QChar lookAhead1 = c1, lookAhead2 = c2;
(lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length());
lookAhead1 = getNextChar(s1, ++lookAheadLocation1),
lookAhead2 = getNextChar(s2, ++lookAheadLocation2)
) {
bool is1ADigit = !lookAhead1.isNull() && lookAhead1.isDigit();
bool is2ADigit = !lookAhead2.isNull() && lookAhead2.isDigit();
if (!is1ADigit && !is2ADigit)
break;
if (!is1ADigit)
return -1;
if (!is2ADigit)
return 1;
if (currentReturnValue == 0) {
if (lookAhead1 < lookAhead2) {
currentReturnValue = -1;
} else if (lookAhead1 > lookAhead2) {
currentReturnValue = 1;
}
}
}
if (currentReturnValue != 0)
return currentReturnValue;
}
if (cs == Qt::CaseInsensitive) {
if (!c1.isLower()) c1 = c1.toLower();
if (!c2.isLower()) c2 = c2.toLower();
}
int r = QString::localeAwareCompare(c1, c2);
if (r < 0)
return -1;
if (r > 0)
return 1;
}
// The two strings are the same (02 == 2) so fall back to the normal sort
return QString::compare(s1, s2, cs);
}
bool naturalSortLessThanCS( const QString &left, const QString &right )
{
return (naturalCompare( left, right, Qt::CaseSensitive ) < 0);
}
bool naturalSortLessThanCI( const QString &left, const QString &right )
{
return (naturalCompare( left, right, Qt::CaseInsensitive ) < 0);
}
bool naturalSortLessThanCIFileInfo(const QFileInfo & left,const QFileInfo & right)
{
return naturalSortLessThanCI(left.fileName(),right.fileName());
}
bool naturalSortLessThanCILibraryItem(LibraryItem * left, LibraryItem * right)
{
return naturalSortLessThanCI(left->name,right->name);
}

15
common/qnaturalsorting.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __QNATURALSORTING_H
#define __QNATURALSORTING_H
#include <QString>
#include <QFileInfo>
#include "library_item.h"
bool naturalSortLessThanCS( const QString &left, const QString &right );
bool naturalSortLessThanCI( const QString &left, const QString &right );
bool naturalSortLessThanCIFileInfo(const QFileInfo & left,const QFileInfo & right);
bool naturalSortLessThanCILibraryItem(LibraryItem * left, LibraryItem * right);
#endif

View File

@ -0,0 +1,61 @@
#include "scroll_management.h"
ScrollManagement::ScrollManagement()
{
wheelTimer = new QTime();
wheelTimer->start();
wheelAccumulator = 0;
}
ScrollManagement::Movement ScrollManagement::getMovement(QWheelEvent *event)
{
/*QLOG_DEBUG() << "WheelEvent angle delta : " << event->angleDelta();
QLOG_DEBUG() << "WheelEvent pixel delta : " << event->pixelDelta();*/
int tooFast = 1;
int timeThrottle = 16;
int minimumMove = 70;
//avoid any events overflood
if((wheelTimer->elapsed() < tooFast)){
event->setAccepted(true);
return None;
}
// Accumulate the delta
if(event->delta()<0 != wheelAccumulator<0 ) //different sign means change in direction
wheelAccumulator = 0;
wheelAccumulator += event->delta();
//Do not process events too fast
if((wheelTimer->elapsed() < timeThrottle)){
event->setAccepted(true);
return None;
}
//small intervals are ignored until with have enough acumulated delta
if((wheelAccumulator < minimumMove) && (wheelAccumulator > -minimumMove)){
event->setAccepted(true);
return None;
}
Movement m;
if(wheelAccumulator<0)
m = Forward;
else
m = Backward;
event->accept();
//Clean up
wheelAccumulator = 0;
wheelTimer->restart();
return m;
}
ScrollManagement::~ScrollManagement()
{
}

View File

@ -0,0 +1,25 @@
#ifndef SCROLLMANAGAMENT_H
#define SCROLLMANAGAMENT_H
#include <QTime>
#include <QWheelEvent>
class ScrollManagement
{
public:
enum Movement{
None,
Forward,
Backward
};
ScrollManagement();
ScrollManagement::Movement getMovement(QWheelEvent * event);
~ScrollManagement();
private:
QTime * wheelTimer;
int wheelAccumulator;
};
#endif // SCROLLMANAGAMENT_H

141
common/yacreader_global.cpp Normal file
View File

@ -0,0 +1,141 @@
#include "yacreader_global.h"
#include <QAction>
using namespace YACReader;
QString YACReader::getSettingsPath()
{
#if QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#endif
}
void YACReader::addSperator(QWidget *w)
{
QAction * separator = new QAction(w);
separator->setSeparator(true);
w->addAction(separator);
}
QAction * YACReader::createSeparator()
{
QAction * a = new QAction(0);
a->setSeparator(true);
return a;
}
QString YACReader::colorToName(LabelColors colors)
{
switch(colors){
case YRed:
return "red";
case YOrange:
return "orange";
case YYellow:
return "yellow";
case YGreen:
return "green";
case YCyan:
return "cyan";
case YBlue:
return "blue";
case YViolet:
return "violet";
case YPurple:
return "purple";
case YPink:
return "pink";
case YWhite:
return "white";
case YLight:
return "light";
case YDark:
return "dark";
}
}
QIcon YACReader::noHighlightedIcon(const QString &path)
{
QPixmap p(path);
QIcon icon;//(path);
icon.addFile(path,p.size(),QIcon::Normal);
icon.addFile(path,p.size(),QIcon::Selected);
return icon;
}
void YACReader::colorize(QImage &img, QColor &col)
{
QRgb *data = (QRgb *)img.bits();
QRgb *end = data + img.width()*img.height();
int rcol = col.red(), gcol = col.green(), bcol = col.blue();
while(data != end) {
*data = qRgba(rcol,gcol,bcol,qAlpha(*data));
++data;
}
}
QString YACReader::labelColorToRGBString(LabelColors color)
{
switch (color) {
case YRed:
return "#FD777C";
case YOrange:
return "#FEBF34";
case YYellow:
return "#F5E934";
case YGreen:
return "#B6E525";
case YCyan:
return "#9FFFDD";
case YBlue:
return "#82C7FF";
case YViolet:
return "#8286FF";
case YPurple:
return "#E39FFF";
case YPink:
return "#FF9FDD";
#ifdef Q_OS_MAC
case YWhite:
return "#E3E3E3";
#else
case YWhite:
return "#FFFFFF";
#endif
case YLight:
return "#C8C8C8";
case YDark:
return "#ABABAB";
}
}
QList<qulonglong> YACReader::mimeDataToComicsIds(const QMimeData *data)
{
QList<qulonglong> comicIds;
QByteArray rawData = data->data(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat);
QDataStream in(&rawData,QIODevice::ReadOnly);
in >> comicIds; //deserialize the list of indentifiers
return comicIds;
}

145
common/yacreader_global.h Normal file
View File

@ -0,0 +1,145 @@
#ifndef __YACREADER_GLOBAL_H
#define __YACREADER_GLOBAL_H
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif
#include <QWidget>
#include <QMimeData>
#define VERSION "8.0.0"
#define PATH "PATH"
#define MAG_GLASS_SIZE "MAG_GLASS_SIZE"
#define ZOOM_LEVEL "ZOOM_LEVEL"
#define SLIDE_SIZE "SLIDE_SIZE"
#define GO_TO_FLOW_SIZE "GO_TO_FLOW_SIZE"
#define FLOW_TYPE_SW "FLOW_TYPE_SW"
#define FIT "FIT"
#define FLOW_TYPE "FLOW_TYPE"
#define FULLSCREEN "FULLSCREEN"
#define FIT_TO_WIDTH_RATIO "FIT_TO_WIDTH_RATIO"
#define Y_WINDOW_POS "POS"
#define Y_WINDOW_SIZE "SIZE"
#define MAXIMIZED "MAXIMIZED"
#define DOUBLE_PAGE "DOUBLE_PAGE"
#define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE"
#define ADJUST_TO_FULL_SIZE "ADJUST_TO_FULL_SIZE"
#define BACKGROUND_COLOR "BACKGROUND_COLOR"
#define ALWAYS_ON_TOP "ALWAYS_ON_TOP"
#define SHOW_TOOLBARS "SHOW_TOOLBARS"
#define BRIGHTNESS "BRIGHTNESS"
#define CONTRAST "CONTRAST"
#define GAMMA "GAMMA"
#define SHOW_INFO "SHOW_INFO"
#define FLOW_TYPE_GL "FLOW_TYPE_GL"
#define Y_POSITION "Y_POSITION"
#define COVER_DISTANCE "COVER_DISTANCE"
#define CENTRAL_DISTANCE "CENTRAL_DISTANCE"
#define ZOOM_LEVEL "ZOOM_LEVEL"
#define Z_COVER_OFFSET "Z_COVER_OFFSET"
#define COVER_ROTATION "COVER_ROTATION"
#define FADE_OUT_DIST "FADE_OUT_DIST"
#define LIGHT_STRENGTH "LIGHT_STRENGTH"
#define MAX_ANGLE "MAX_ANGLE"
#define PERFORMANCE "PERFORMANCE"
#define USE_OPEN_GL "USE_OPEN_GL"
#define X_ROTATION "X_ROTATION"
#define Y_COVER_OFFSET "Y_COVER_OFFSET"
#define V_SYNC "V_SYNC"
#define SERVER_ON "SERVER_ON"
#define MAIN_WINDOW_GEOMETRY "MAIN_WINDOW_GEOMETRY"
#define MAIN_WINDOW_STATE "MAIN_WINDOW_STATE"
#define COMICS_VIEW_HEADERS "COMICS_VIEW_HEADERS"
#define COMICS_VIEW_HEADERS_GEOMETRY "COMICS_VIEW_HEADERS_GEOMETRY"
#define COMICS_VIEW_STATUS "COMICS_VIEW_STATUS"
#define COMICS_VIEW_FLOW_SPLITTER_STATUS "COMICS_VIEW_FLOW_SPLITTER_STATUS"
#define SIDEBAR_SPLITTER_STATUS "SIDEBAR_SPLITTER_STATUS"
#define NUM_DAYS_BETWEEN_VERSION_CHECKS "NUM_DAYS_BETWEEN_VERSION_CHECKS"
#define LAST_VERSION_CHECK "LAST_VERSION_CHECK"
#define YACREADERLIBRARY_GUID "ea343ff3-2005-4865-b212-7fa7c43999b8"
#define LIBRARIES "LIBRARIES"
#define COMIC_VINE_API_KEY "COMIC_VINE_API_KEY"
namespace YACReader
{
static const QString YACReaderLibrarComiscSelectionMimeDataFormat = "application/yacreaderlibrary-comics-ids";
static const QString YACReaderLibrarSubReadingListMimeDataFormat = "application/yacreaderlibrary-sublist-rows";
enum FlowType
{
CoverFlowLike=0,
Strip,
StripOverlapped,
Modern,
Roulette,
Custom
};
enum YACReaderIPCMessages
{
RequestComicInfo = 0,
SendComicInfo,
};
enum YACReaderComicReadStatus
{
Unread = 0,
Read = 1,
Opened = 2
};
enum YACReaderErrors
{
SevenZNotFound = 700
};
enum ComicsViewStatus
{
Flow,
Grid
};
enum SearchModifiers{
NoModifiers = 0,
OnlyRead,
OnlyUnread,
ByAuthor
};
enum LabelColors{
YRed = 1,
YOrange,
YYellow,
YGreen,
YCyan,
YBlue,
YViolet,
YPurple,
YPink,
YWhite,
YLight,
YDark
};
QString getSettingsPath();
void addSperator(QWidget * w);
QAction * createSeparator();
QString colorToName(LabelColors colors);
QIcon noHighlightedIcon(const QString & path);
void colorize(QImage &img, QColor &col);
QString labelColorToRGBString(LabelColors color);
QList<qulonglong> mimeDataToComicsIds(const QMimeData * data);
}
#endif