incoming connections to local server are now proccessed in threads

This commit is contained in:
Luis Ángel San Martín 2013-08-19 12:24:42 +02:00
parent db9aad8521
commit 85dd3f862c
7 changed files with 181 additions and 150 deletions

View File

@ -28,7 +28,7 @@ enum Columns {
TableModel::TableModel(QObject *parent) TableModel::TableModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
{ {
connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset())); connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset()));
connect(this,SIGNAL(reset()),this,SIGNAL(modelReset())); connect(this,SIGNAL(reset()),this,SIGNAL(modelReset()));
@ -36,9 +36,9 @@ TableModel::TableModel(QObject *parent)
//! [0] //! [0]
TableModel::TableModel( QSqlQuery &sqlquery, QObject *parent) TableModel::TableModel( QSqlQuery &sqlquery, QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
{ {
setupModelData(sqlquery); setupModelData(sqlquery);
} }
//! [0] //! [0]
@ -61,8 +61,8 @@ int TableModel::columnCount(const QModelIndex &parent) const
//! [3] //! [3]
QVariant TableModel::data(const QModelIndex &index, int role) const QVariant TableModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if (index.column() == Columns::Rating && role == Qt::DecorationRole) if (index.column() == Columns::Rating && role == Qt::DecorationRole)
{ {
@ -80,23 +80,23 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
switch(index.column())//TODO obtener esto de la query switch(index.column())//TODO obtener esto de la query
{ {
case 0: case 0:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case 3: case 3:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case 7: case 7:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case Columns::CurrentPage: case Columns::CurrentPage:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
default: default:
return QVariant(Qt::AlignLeft | Qt::AlignVCenter); return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
} }
} }
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
TableItem *item = static_cast<TableItem*>(index.internalPointer()); TableItem *item = static_cast<TableItem*>(index.internalPointer());
if(index.column() == Columns::Hash) if(index.column() == Columns::Hash)
return QString::number(item->data(index.column()).toString().right(item->data(index.column()).toString().length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb"; return QString::number(item->data(index.column()).toString().right(item->data(index.column()).toString().length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb";
if(index.column() == Columns::ReadColumn) if(index.column() == Columns::ReadColumn)
@ -114,18 +114,18 @@ QVariant TableModel::data(const QModelIndex &index, int role) const
//! [4] //! [4]
Qt::ItemFlags TableModel::flags(const QModelIndex &index) const Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
} }
//! [4] //! [4]
//! [5] //! [5]
QVariant TableModel::headerData(int section, Qt::Orientation orientation, QVariant TableModel::headerData(int section, Qt::Orientation orientation,
int role) const int role) const
{ {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{ {
switch(section)//TODO obtener esto de la query switch(section)//TODO obtener esto de la query
{ {
@ -153,15 +153,15 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation,
switch(section)//TODO obtener esto de la query switch(section)//TODO obtener esto de la query
{ {
case 0: case 0:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case 3: case 3:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case 7: case 7:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
case Columns::CurrentPage: case Columns::CurrentPage:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
default: default:
return QVariant(Qt::AlignLeft | Qt::AlignVCenter); return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
} }
} }
@ -193,16 +193,16 @@ QVariant TableModel::headerData(int section, Qt::Orientation orientation,
} }
return QVariant(); return QVariant();
} }
//! [5] //! [5]
//! [6] //! [6]
QModelIndex TableModel::index(int row, int column, const QModelIndex &parent) QModelIndex TableModel::index(int row, int column, const QModelIndex &parent)
const const
{ {
if (!hasIndex(row, column, parent)) if (!hasIndex(row, column, parent))
return QModelIndex(); return QModelIndex();
return createIndex(row, column, _data.at(row)); return createIndex(row, column, _data.at(row));
} }
@ -211,18 +211,18 @@ QModelIndex TableModel::index(int row, int column, const QModelIndex &parent)
//! [7] //! [7]
QModelIndex TableModel::parent(const QModelIndex &index) const QModelIndex TableModel::parent(const QModelIndex &index) const
{ {
return QModelIndex(); return QModelIndex();
} }
//! [7] //! [7]
//! [8] //! [8]
int TableModel::rowCount(const QModelIndex &parent) const int TableModel::rowCount(const QModelIndex &parent) const
{ {
TreeItem *parentItem; TreeItem *parentItem;
if (parent.column() > 0) if (parent.column() > 0)
return 0; return 0;
if (!parent.isValid()) if (!parent.isValid())
return _data.count(); return _data.count();
return 0; return 0;

View File

@ -121,9 +121,9 @@ void LibraryWindow::doLayout()
sVertical = new QSplitter(Qt::Vertical); //spliter derecha sVertical = new QSplitter(Qt::Vertical); //spliter derecha
QSplitter * sHorizontal = new QSplitter(Qt::Horizontal); //spliter principal QSplitter * sHorizontal = new QSplitter(Qt::Horizontal); //spliter principal
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
sHorizontal->setStyleSheet("QSplitter::handle{image:none;background-color:#B8B8B8;} QSplitter::handle:vertical {height:1px;}"); sHorizontal->setStyleSheet("QSplitter::handle{image:none;background-color:#B8B8B8;} QSplitter::handle:vertical {height:1px;}");
#else #else
sHorizontal->setStyleSheet("QSplitter::handle:vertical {height:4px;}"); sHorizontal->setStyleSheet("QSplitter::handle:vertical {height:4px;}");
#endif #endif
//TOOLBARS------------------------------------------------------------------- //TOOLBARS-------------------------------------------------------------------
@ -183,7 +183,7 @@ void LibraryWindow::doLayout()
YACReaderTitledToolBar * librariesTitle = sideBar->librariesTitle; YACReaderTitledToolBar * librariesTitle = sideBar->librariesTitle;
YACReaderTitledToolBar * foldersTitle = sideBar->foldersTitle; YACReaderTitledToolBar * foldersTitle = sideBar->foldersTitle;
librariesTitle->addAction(createLibraryAction); librariesTitle->addAction(createLibraryAction);
librariesTitle->addAction(openLibraryAction); librariesTitle->addAction(openLibraryAction);
@ -191,7 +191,7 @@ void LibraryWindow::doLayout()
foldersTitle->addAction(setRootIndexAction); foldersTitle->addAction(setRootIndexAction);
foldersTitle->addAction(expandAllNodesAction); foldersTitle->addAction(expandAllNodesAction);
foldersTitle->addAction(colapseAllNodesAction); foldersTitle->addAction(colapseAllNodesAction);
//FINAL LAYOUT------------------------------------------------------------- //FINAL LAYOUT-------------------------------------------------------------
sVertical->addWidget(comicFlow); sVertical->addWidget(comicFlow);
@ -249,10 +249,10 @@ void LibraryWindow::doLayout()
comicFlow->setContextMenuPolicy(Qt::ActionsContextMenu); comicFlow->setContextMenuPolicy(Qt::ActionsContextMenu);
//collapsible disabled in macosx (only temporaly) //collapsible disabled in macosx (only temporaly)
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
sHorizontal->setCollapsible(0,false); sHorizontal->setCollapsible(0,false);
sVertical->setCollapsible(1,false); sVertical->setCollapsible(1,false);
#endif #endif
} }
@ -304,17 +304,17 @@ void LibraryWindow::createActions()
{ {
backAction = new QAction(this); backAction = new QAction(this);
QIcon icoBackButton; QIcon icoBackButton;
icoBackButton.addPixmap(QPixmap(":/images/main_toolbar/back.png"), QIcon::Normal); icoBackButton.addPixmap(QPixmap(":/images/main_toolbar/back.png"), QIcon::Normal);
//icoBackButton.addPixmap(QPixmap(":/images/main_toolbar/back_disabled.png"), QIcon::Disabled); //icoBackButton.addPixmap(QPixmap(":/images/main_toolbar/back_disabled.png"), QIcon::Disabled);
backAction->setIcon(icoBackButton); backAction->setIcon(icoBackButton);
backAction->setDisabled(true); backAction->setDisabled(true);
forwardAction = new QAction(this); forwardAction = new QAction(this);
QIcon icoFordwardButton; QIcon icoFordwardButton;
icoFordwardButton.addPixmap(QPixmap(":/images/main_toolbar/forward.png"), QIcon::Normal); icoFordwardButton.addPixmap(QPixmap(":/images/main_toolbar/forward.png"), QIcon::Normal);
//icoFordwardButton.addPixmap(QPixmap(":/images/main_toolbar/forward_disabled.png"), QIcon::Disabled); //icoFordwardButton.addPixmap(QPixmap(":/images/main_toolbar/forward_disabled.png"), QIcon::Disabled);
forwardAction->setIcon(icoFordwardButton); forwardAction->setIcon(icoFordwardButton);
forwardAction->setDisabled(true); forwardAction->setDisabled(true);
createLibraryAction = new QAction(this); createLibraryAction = new QAction(this);
createLibraryAction->setToolTip(tr("Create a new library")); createLibraryAction->setToolTip(tr("Create a new library"));
@ -388,14 +388,14 @@ void LibraryWindow::createActions()
toggleFullScreenAction->setToolTip(tr("Fullscreen mode on/off (F)")); toggleFullScreenAction->setToolTip(tr("Fullscreen mode on/off (F)"));
toggleFullScreenAction->setShortcut(Qt::Key_F); toggleFullScreenAction->setShortcut(Qt::Key_F);
QIcon icoFullscreenButton; QIcon icoFullscreenButton;
icoFullscreenButton.addPixmap(QPixmap(":/images/main_toolbar/fullscreen.png"), QIcon::Normal); icoFullscreenButton.addPixmap(QPixmap(":/images/main_toolbar/fullscreen.png"), QIcon::Normal);
toggleFullScreenAction->setIcon(icoFullscreenButton); toggleFullScreenAction->setIcon(icoFullscreenButton);
helpAboutAction = new QAction(this); helpAboutAction = new QAction(this);
helpAboutAction->setToolTip(tr("Help, About YACReader")); helpAboutAction->setToolTip(tr("Help, About YACReader"));
helpAboutAction->setShortcut(Qt::Key_F1); helpAboutAction->setShortcut(Qt::Key_F1);
QIcon icoHelpButton; QIcon icoHelpButton;
icoHelpButton.addPixmap(QPixmap(":/images/main_toolbar/help.png"), QIcon::Normal); icoHelpButton.addPixmap(QPixmap(":/images/main_toolbar/help.png"), QIcon::Normal);
helpAboutAction->setIcon(icoHelpButton); helpAboutAction->setIcon(icoHelpButton);
setRootIndexAction = new QAction(this); setRootIndexAction = new QAction(this);
@ -417,7 +417,7 @@ void LibraryWindow::createActions()
optionsAction->setShortcut(Qt::Key_C); optionsAction->setShortcut(Qt::Key_C);
optionsAction->setToolTip(tr("Show options dialog")); optionsAction->setToolTip(tr("Show options dialog"));
QIcon icoSettingsButton; QIcon icoSettingsButton;
icoSettingsButton.addPixmap(QPixmap(":/images/main_toolbar/settings.png"), QIcon::Normal); icoSettingsButton.addPixmap(QPixmap(":/images/main_toolbar/settings.png"), QIcon::Normal);
optionsAction->setIcon(icoSettingsButton); optionsAction->setIcon(icoSettingsButton);
serverConfigAction = new QAction(this); serverConfigAction = new QAction(this);
@ -528,12 +528,12 @@ void LibraryWindow::createToolBars()
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
libraryToolBar->setIconSize(QSize(16,16)); //TODO make icon size dynamic libraryToolBar->setIconSize(QSize(16,16)); //TODO make icon size dynamic
libraryToolBar->addAction(backAction); libraryToolBar->addAction(backAction);
libraryToolBar->addAction(forwardAction); libraryToolBar->addAction(forwardAction);
{QWidget * w = new QWidget(); {QWidget * w = new QWidget();
w->setFixedWidth(10); w->setFixedWidth(10);
libraryToolBar->addWidget(w);} libraryToolBar->addWidget(w);}
#ifdef SERVER_RELEASE #ifdef SERVER_RELEASE
libraryToolBar->addAction(serverConfigAction); libraryToolBar->addAction(serverConfigAction);
@ -541,9 +541,9 @@ void LibraryWindow::createToolBars()
libraryToolBar->addAction(optionsAction); libraryToolBar->addAction(optionsAction);
libraryToolBar->addAction(helpAboutAction); libraryToolBar->addAction(helpAboutAction);
{ QWidget * w2 = new QWidget(); { QWidget * w2 = new QWidget();
w2->setFixedWidth(10); w2->setFixedWidth(10);
libraryToolBar->addWidget(w2);} libraryToolBar->addWidget(w2);}
libraryToolBar->addAction(toggleFullScreenAction); libraryToolBar->addAction(toggleFullScreenAction);
@ -555,11 +555,11 @@ void LibraryWindow::createToolBars()
#else #else
libraryToolBar->backButton->setDefaultAction(backAction); libraryToolBar->backButton->setDefaultAction(backAction);
libraryToolBar->forwardButton->setDefaultAction(forwardAction); libraryToolBar->forwardButton->setDefaultAction(forwardAction);
libraryToolBar->settingsButton->setDefaultAction(optionsAction); libraryToolBar->settingsButton->setDefaultAction(optionsAction);
libraryToolBar->serverButton->setDefaultAction(serverConfigAction); libraryToolBar->serverButton->setDefaultAction(serverConfigAction);
libraryToolBar->helpButton->setDefaultAction(helpAboutAction); libraryToolBar->helpButton->setDefaultAction(helpAboutAction);
libraryToolBar->fullscreenButton->setDefaultAction(toggleFullScreenAction); libraryToolBar->fullscreenButton->setDefaultAction(toggleFullScreenAction);
#endif #endif
editInfoToolBar->setIconSize(QSize(18,18)); editInfoToolBar->setIconSize(QSize(18,18));
@ -620,9 +620,9 @@ void LibraryWindow::createMenus()
void LibraryWindow::createConnections() void LibraryWindow::createConnections()
{ {
//history navigation //history navigation
connect(backAction,SIGNAL(triggered()),this,SLOT(backward())); connect(backAction,SIGNAL(triggered()),this,SLOT(backward()));
connect(forwardAction,SIGNAL(triggered()),this,SLOT(forward())); connect(forwardAction,SIGNAL(triggered()),this,SLOT(forward()));
//libraryCreator connections //libraryCreator connections
connect(createLibraryDialog,SIGNAL(createLibrary(QString,QString,QString)),this,SLOT(create(QString,QString,QString))); connect(createLibraryDialog,SIGNAL(createLibrary(QString,QString,QString)),this,SLOT(create(QString,QString,QString)));
@ -668,7 +668,7 @@ void LibraryWindow::createConnections()
//navigations between view modes (tree,list and flow) //navigations between view modes (tree,list and flow)
connect(foldersView, SIGNAL(pressed(QModelIndex)), this, SLOT(loadCovers(QModelIndex))); connect(foldersView, SIGNAL(pressed(QModelIndex)), this, SLOT(loadCovers(QModelIndex)));
connect(foldersView, SIGNAL(pressed(QModelIndex)), this, SLOT(updateHistory(QModelIndex))); connect(foldersView, SIGNAL(pressed(QModelIndex)), this, SLOT(updateHistory(QModelIndex)));
connect(comicView, SIGNAL(pressed(QModelIndex)), this, SLOT(centerComicFlow(QModelIndex))); connect(comicView, SIGNAL(pressed(QModelIndex)), this, SLOT(centerComicFlow(QModelIndex)));
connect(comicFlow, SIGNAL(centerIndexChanged(int)), this, SLOT(updateComicView(int))); connect(comicFlow, SIGNAL(centerIndexChanged(int)), this, SLOT(updateComicView(int)));
@ -739,11 +739,11 @@ void LibraryWindow::loadLibrary(const QString & name)
{ {
if(libraries.size()>0) //si hay bibliotecas... if(libraries.size()>0) //si hay bibliotecas...
{ {
currentFolderNavigation=0; currentFolderNavigation=0;
backAction->setDisabled(true); backAction->setDisabled(true);
forwardAction->setDisabled(true); forwardAction->setDisabled(true);
history.clear(); history.clear();
history.append(QModelIndex()); history.append(QModelIndex());
showRootWidget(); showRootWidget();
QString path=libraries.value(name)+"/.yacreaderlibrary"; QString path=libraries.value(name)+"/.yacreaderlibrary";
@ -1018,7 +1018,7 @@ void LibraryWindow::openComic()
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QProcess::startDetached("open", QStringList() << "-n" << QDir::cleanPath(QCoreApplication::applicationDirPath()+"/../../../YACReader.app") << "--args" << path << comicId << libraryId /*<< page << bookmark1 << bookmark2 << bookmark3 << brightness << contrast << gamma*/);//,QStringList() << path); QProcess::startDetached("open", QStringList() << "-n" << QDir::cleanPath(QCoreApplication::applicationDirPath()+"/../../../YACReader.app") << "--args" << path << comicId << libraryId /*<< page << bookmark1 << bookmark2 << bookmark3 << brightness << contrast << gamma*/);//,QStringList() << path);
#else #else
/* \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\" \"%10\" */ /* \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\" \"%10\" */
QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\" \"%2\" \"%3\"").arg(path).arg(comicId).arg(libraryId)/*.arg(page).arg(bookmark1).arg(bookmark2).arg(bookmark3).arg(brightness).arg(contrast).arg(gamma)*/,QStringList()); QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\" \"%2\" \"%3\"").arg(path).arg(comicId).arg(libraryId)/*.arg(page).arg(bookmark1).arg(bookmark2).arg(bookmark3).arg(brightness).arg(contrast).arg(gamma)*/,QStringList());
#endif #endif
setCurrentComicOpened(); setCurrentComicOpened();
@ -1302,7 +1302,7 @@ void LibraryWindow::setRootIndex()
comicFlow->clear(); comicFlow->clear();
} }
foldersView->clearSelection(); foldersView->clearSelection();
} }
} }
@ -1322,7 +1322,7 @@ void LibraryWindow::toFullScreen()
comicFlow->setCenterIndex(comicFlow->centerIndex()); comicFlow->setCenterIndex(comicFlow->centerIndex());
comics->hide(); comics->hide();
sideBar->hide(); sideBar->hide();
libraryToolBar->hide(); libraryToolBar->hide();
showFullScreen(); showFullScreen();
@ -1346,19 +1346,19 @@ void LibraryWindow::toNormal()
comicFlow->show(); comicFlow->show();
if(fromMaximized) if(fromMaximized)
showMaximized(); showMaximized();
else else
showNormal(); showNormal();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QTimer * timer = new QTimer(); QTimer * timer = new QTimer();
timer->setSingleShot(true); timer->setSingleShot(true);
timer->start(); timer->start();
connect(timer,SIGNAL(timeout()),libraryToolBar,SLOT(show())); connect(timer,SIGNAL(timeout()),libraryToolBar,SLOT(show()));
connect(timer,SIGNAL(timeout()),timer,SLOT(deleteLater())); connect(timer,SIGNAL(timeout()),timer,SLOT(deleteLater()));
#else #else
libraryToolBar->show(); libraryToolBar->show();
#endif #endif
} }
@ -1433,23 +1433,23 @@ QFileInfo file = QDir::cleanPath(currentPath() + dmCV->getComicPath(modelIndex))
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
QString filePath = file.absoluteFilePath(); QString filePath = file.absoluteFilePath();
QStringList args; QStringList args;
args << "-e"; args << "-e";
args << "tell application \"Finder\""; args << "tell application \"Finder\"";
args << "-e"; args << "-e";
args << "activate"; args << "activate";
args << "-e"; args << "-e";
args << "select POSIX file \""+filePath+"\""; args << "select POSIX file \""+filePath+"\"";
args << "-e"; args << "-e";
args << "end tell"; args << "end tell";
QProcess::startDetached("osascript", args); QProcess::startDetached("osascript", args);
#endif #endif
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
QString filePath = file.absoluteFilePath(); QString filePath = file.absoluteFilePath();
QStringList args; QStringList args;
args << "/select," << QDir::toNativeSeparators(filePath); args << "/select," << QDir::toNativeSeparators(filePath);
QProcess::startDetached("explorer", args); QProcess::startDetached("explorer", args);
#endif #endif
} }
@ -1633,32 +1633,32 @@ void LibraryWindow::showSocial()
void LibraryWindow::backward() void LibraryWindow::backward()
{ {
if(currentFolderNavigation>0) if(currentFolderNavigation>0)
{ {
currentFolderNavigation--; currentFolderNavigation--;
loadCovers(history.at(currentFolderNavigation)); loadCovers(history.at(currentFolderNavigation));
foldersView->setCurrentIndex(history.at(currentFolderNavigation)); foldersView->setCurrentIndex(history.at(currentFolderNavigation));
forwardAction->setEnabled(true); forwardAction->setEnabled(true);
} }
if(currentFolderNavigation==0) if(currentFolderNavigation==0)
{ {
backAction->setEnabled(false); backAction->setEnabled(false);
} }
} }
void LibraryWindow::forward() void LibraryWindow::forward()
{ {
if(currentFolderNavigation<history.count()-1) if(currentFolderNavigation<history.count()-1)
{ {
currentFolderNavigation++; currentFolderNavigation++;
loadCovers(history.at(currentFolderNavigation)); loadCovers(history.at(currentFolderNavigation));
foldersView->setCurrentIndex(history.at(currentFolderNavigation)); foldersView->setCurrentIndex(history.at(currentFolderNavigation));
backAction->setEnabled(true); backAction->setEnabled(true);
} }
if(currentFolderNavigation==history.count()-1) if(currentFolderNavigation==history.count()-1)
{ {
forwardAction->setEnabled(false); forwardAction->setEnabled(false);
} }
} }
void LibraryWindow::updateHistory(const QModelIndex &mi) void LibraryWindow::updateHistory(const QModelIndex &mi)

View File

@ -106,7 +106,7 @@ private:
int i; int i;
QAction * backAction; QAction * backAction;
QAction * forwardAction; QAction * forwardAction;
QAction * openComicAction; QAction * openComicAction;
QAction * createLibraryAction; QAction * createLibraryAction;
@ -196,9 +196,9 @@ private:
//settings //settings
QSettings * settings; QSettings * settings;
//navigation backward and forward //navigation backward and forward
int currentFolderNavigation; int currentFolderNavigation;
QList<QModelIndex> history; QList<QModelIndex> history;
protected: protected:
virtual void closeEvent ( QCloseEvent * event ); virtual void closeEvent ( QCloseEvent * event );
@ -257,14 +257,13 @@ public:
QModelIndexList getSelectedComics(); QModelIndexList getSelectedComics();
void deleteComics(); void deleteComics();
//void showSocial(); //void showSocial();
void backward(); void backward();
void forward(); void forward();
void updateHistory(const QModelIndex & mi); void updateHistory(const QModelIndex & mi);
void libraryAlreadyExists(const QString & name); void libraryAlreadyExists(const QString & name);
void importLibraryPackage(); void importLibraryPackage();
void updateComicsView(quint64 libraryId, const ComicDB & comic); void updateComicsView(quint64 libraryId, const ComicDB & comic);
void setCurrentComicOpened(); void setCurrentComicOpened();
}; };
#endif #endif

View File

@ -50,7 +50,6 @@ int main( int argc, char ** argv )
LibraryWindow * mw = new LibraryWindow(); LibraryWindow * mw = new LibraryWindow();
mw->connect(localServer,SIGNAL(comicUpdated(quint64, const ComicDB &)),mw,SLOT(updateComicsView(quint64, const ComicDB &))); mw->connect(localServer,SIGNAL(comicUpdated(quint64, const ComicDB &)),mw,SLOT(updateComicsView(quint64, const ComicDB &)));
//connections to localServer //connections to localServer
mw->show(); mw->show();

View File

@ -30,6 +30,33 @@ void YACReaderLocalServer::sendResponse()
connect(clientConnection, SIGNAL(disconnected()), connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater())); clientConnection, SLOT(deleteLater()));
qRegisterMetaType<ComicDB>("ComicDB");
YACReaderClientConnectionWorker * worker = new YACReaderClientConnectionWorker(clientConnection);
connect(worker,SIGNAL(comicUpdated(quint64, ComicDB)),this,SIGNAL(comicUpdated(quint64, ComicDB)));
connect(worker,SIGNAL(finished()),worker,SLOT(deleteLater()));
worker->start();
//clientConnection->waitForBytesWritten();*/
//clientConnection->disconnectFromServer();
}
bool YACReaderLocalServer::isRunning()
{
QLocalSocket socket;
socket.connectToServer(YACREADERLIBRARY_GUID);
if (socket.waitForConnected(500))
return true; // Server is running (another instance of YACReaderLibrary has been launched)
return false;
}
YACReaderClientConnectionWorker::YACReaderClientConnectionWorker( QLocalSocket *cc)
:QThread(),clientConnection(cc)
{
}
void YACReaderClientConnectionWorker::run()
{
quint64 libraryId; quint64 libraryId;
ComicDB comic; ComicDB comic;
int tries = 0; int tries = 0;
@ -100,28 +127,16 @@ void YACReaderLocalServer::sendResponse()
} }
} }
//clientConnection->waitForBytesWritten();*/
//clientConnection->disconnectFromServer();
} }
void YACReaderLocalServer::getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & siblings) void YACReaderClientConnectionWorker::getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & siblings)
{ {
comic = DBHelper::getComicInfo(DBHelper::getLibrariesNames().at(libraryId), comic.id); comic = DBHelper::getComicInfo(DBHelper::getLibrariesNames().at(libraryId), comic.id);
siblings = DBHelper::getSiblings(DBHelper::getLibrariesNames().at(libraryId), comic.parentId); siblings = DBHelper::getSiblings(DBHelper::getLibrariesNames().at(libraryId), comic.parentId);
} }
void YACReaderLocalServer::updateComic(quint64 libraryId, ComicDB & comic) void YACReaderClientConnectionWorker::updateComic(quint64 libraryId, ComicDB & comic)
{ {
DBHelper::update(DBHelper::getLibrariesNames().at(libraryId), comic.info); DBHelper::update(DBHelper::getLibrariesNames().at(libraryId), comic.info);
emit comicUpdated(libraryId, comic); emit comicUpdated(libraryId, comic);
} }
bool YACReaderLocalServer::isRunning()
{
QLocalSocket socket;
socket.connectToServer(YACREADERLIBRARY_GUID);
if (socket.waitForConnected(500))
return true; // Server is running (another instance of YACReaderLibrary has been launched)
return false;
}

View File

@ -2,27 +2,43 @@
#define YACREADER_LOCAL_SERVER_H #define YACREADER_LOCAL_SERVER_H
#include <QObject> #include <QObject>
#include <QThread>
class QLocalServer; class QLocalServer;
class QLocalSocket;
class ComicDB; class ComicDB;
class YACReaderLocalServer : public QObject class YACReaderLocalServer : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit YACReaderLocalServer(QObject *parent = 0); explicit YACReaderLocalServer(QObject *parent = 0);
signals: signals:
void comicUpdated(quint64 libraryId, const ComicDB & comic); void comicUpdated(quint64 libraryId, const ComicDB & comic);
public slots: public slots:
bool isListening(); bool isListening();
void sendResponse(); void sendResponse();
static bool isRunning(); static bool isRunning();
private:
QLocalServer * localServer;
};
class YACReaderClientConnectionWorker : public QThread
{
Q_OBJECT
public:
YACReaderClientConnectionWorker( QLocalSocket *clientConnection);
signals:
void comicUpdated(quint64 libraryId, const ComicDB & comic);
private:
void run();
void getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & sibling); void getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & sibling);
void updateComic(quint64 libraryId, ComicDB & comic); void updateComic(quint64 libraryId, ComicDB & comic);
private:
QLocalServer * localServer; QLocalSocket *clientConnection;
}; };
#endif // YACREADER_LOCAL_SERVER_H #endif // YACREADER_LOCAL_SERVER_H

View File

@ -5,6 +5,7 @@
#include <QList> #include <QList>
#include <QPixmap> #include <QPixmap>
#include <QImage> #include <QImage>
#include <QMetaType>
class ComicInfo class ComicInfo
{ {
@ -141,5 +142,6 @@ public:
friend QDataStream &operator>>(QDataStream &, ComicDB &); friend QDataStream &operator>>(QDataStream &, ComicDB &);
}; };
Q_DECLARE_METATYPE(ComicDB);
#endif #endif