mirror of
https://github.com/YACReader/yacreader
synced 2025-07-19 21:44:43 -04:00
moved settings files from local dir to standar paths
added YACReaderLibraries class, libraries are now identified by id
This commit is contained in:
@ -98,7 +98,8 @@ SOURCES += $$PWD/../common/comic.cpp \
|
||||
$$PWD/../common/folder.cpp \
|
||||
$$PWD/../common/library_item.cpp \
|
||||
$$PWD/yacreader_local_client.cpp \
|
||||
$$PWD/../common/http_worker.cpp
|
||||
$$PWD/../common/http_worker.cpp \
|
||||
$$PWD/../common/yacreader_global.cpp \
|
||||
|
||||
include($$PWD/../custom_widgets/custom_widgets_yacreader.pri)
|
||||
include($$PWD/../compressed_archive/wrapper.pri)
|
||||
|
@ -30,11 +30,13 @@ int main(int argc, char * argv[])
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
app.setApplicationName("YACReader");
|
||||
app.setOrganizationName("YACReader");
|
||||
|
||||
QTranslator translator;
|
||||
QString sufix = QLocale::system().name();
|
||||
translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreader_"+sufix);
|
||||
app.installTranslator(&translator);
|
||||
app.setApplicationName("YACReader");
|
||||
|
||||
MainWindowViewer * mwv = new MainWindowViewer();
|
||||
mwv->show();
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "comic_db.h"
|
||||
#include "yacreader_local_client.h"
|
||||
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <algorithm>
|
||||
#include <QApplication>
|
||||
@ -105,7 +107,7 @@ MainWindowViewer::~MainWindowViewer()
|
||||
}
|
||||
void MainWindowViewer::loadConfiguration()
|
||||
{
|
||||
settings = new QSettings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
settings = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
|
||||
Configuration & config = Configuration::getConfiguration();
|
||||
config.load(settings);
|
||||
|
@ -242,7 +242,7 @@ void OptionsDialog::fitToWidthRatio(int value)
|
||||
|
||||
void OptionsDialog::brightnessChanged(int value)
|
||||
{
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
settings.setValue(BRIGHTNESS,value);
|
||||
emit changedFilters(brightnessS->getValue(), contrastS->getValue(), gammaS->getValue());
|
||||
//emit(changedImageOptions());
|
||||
@ -250,7 +250,7 @@ void OptionsDialog::brightnessChanged(int value)
|
||||
|
||||
void OptionsDialog::contrastChanged(int value)
|
||||
{
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
settings.setValue(CONTRAST,value);
|
||||
emit changedFilters(brightnessS->getValue(), contrastS->getValue(), gammaS->getValue());
|
||||
///emit(changedImageOptions());
|
||||
@ -258,7 +258,7 @@ void OptionsDialog::contrastChanged(int value)
|
||||
|
||||
void OptionsDialog::gammaChanged(int value)
|
||||
{
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
settings.setValue(GAMMA,value);
|
||||
emit changedFilters(brightnessS->getValue(), contrastS->getValue(), gammaS->getValue());
|
||||
//emit(changedImageOptions());
|
||||
@ -269,7 +269,7 @@ void OptionsDialog::resetImageConfig()
|
||||
brightnessS->setValue(0);
|
||||
contrastS->setValue(100);
|
||||
gammaS->setValue(100);
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
settings.setValue(BRIGHTNESS,0);
|
||||
settings.setValue(CONTRAST,100);
|
||||
settings.setValue(GAMMA,100);
|
||||
@ -280,7 +280,7 @@ void OptionsDialog::resetImageConfig()
|
||||
void OptionsDialog::show()
|
||||
{
|
||||
//TODO solucionar el tema de las settings, esto s<>lo deber<65>a aparecer en una <20>nica l<>nea de c<>digo
|
||||
QSettings *s = new QSettings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings *s = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
fitToWidthRatioS->disconnect();
|
||||
fitToWidthRatioS->setSliderPosition(settings->value(FIT_TO_WIDTH_RATIO).toFloat()*100);
|
||||
connect(fitToWidthRatioS,SIGNAL(valueChanged(int)),this,SLOT(fitToWidthRatio(int)));
|
||||
|
@ -242,7 +242,7 @@ QImage BrightnessFilter::setFilter(const QImage & image)
|
||||
return result;*/
|
||||
if(level ==-1)
|
||||
{
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
return changeBrightness(image,settings.value(BRIGHTNESS,0).toInt());
|
||||
}
|
||||
else
|
||||
@ -320,7 +320,7 @@ QImage ContrastFilter::setFilter(const QImage & image)
|
||||
return result;*/
|
||||
if(level ==-1)
|
||||
{
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
return changeContrast(image,settings.value(CONTRAST,100).toInt());
|
||||
}
|
||||
else
|
||||
@ -341,7 +341,7 @@ QImage GammaFilter::setFilter(const QImage & image)
|
||||
{
|
||||
if(level ==-1)
|
||||
{
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
return changeGamma(image,settings.value(GAMMA,100).toInt());
|
||||
}
|
||||
else
|
||||
|
@ -61,7 +61,7 @@ shouldOpenPrevious(false)
|
||||
|
||||
goToDialog = new GoToDialog(this);
|
||||
|
||||
QSettings * settings = new QSettings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
|
||||
//CONFIG GOTO_FLOW--------------------------------------------------------
|
||||
if(QGLFormat::hasOpenGL() && !settings->contains(USE_OPEN_GL))
|
||||
@ -894,7 +894,7 @@ void Viewer::updateComic(ComicDB & comic)
|
||||
comic.info.bookmark3 = boomarksList[2];
|
||||
//set filters
|
||||
//TODO: avoid use settings for this...
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat);
|
||||
int brightness = settings.value(BRIGHTNESS,0).toInt();
|
||||
int contrast = settings.value(CONTRAST,100).toInt();
|
||||
int gamma = settings.value(GAMMA,100).toInt();
|
||||
|
@ -78,7 +78,8 @@ HEADERS += comic_flow.h \
|
||||
yacreader_local_server.h \
|
||||
yacreader_main_toolbar.h \
|
||||
comics_remover.h \
|
||||
../common/http_worker.h
|
||||
../common/http_worker.h \
|
||||
yacreader_libraries.h
|
||||
|
||||
SOURCES += comic_flow.cpp \
|
||||
create_library_dialog.cpp \
|
||||
@ -86,7 +87,7 @@ SOURCES += comic_flow.cpp \
|
||||
library_window.cpp \
|
||||
main.cpp \
|
||||
add_library_dialog.cpp \
|
||||
rename_library_dialog.cpp \
|
||||
rename_library_dialog.cpp \
|
||||
properties_dialog.cpp \
|
||||
options_dialog.cpp \
|
||||
export_library_dialog.cpp \
|
||||
@ -118,7 +119,9 @@ SOURCES += comic_flow.cpp \
|
||||
yacreader_local_server.cpp \
|
||||
yacreader_main_toolbar.cpp \
|
||||
comics_remover.cpp \
|
||||
../common/http_worker.cpp
|
||||
../common/http_worker.cpp \
|
||||
../common/yacreader_global.cpp \
|
||||
yacreader_libraries.cpp
|
||||
|
||||
|
||||
include(./server/server.pri)
|
||||
|
@ -75,7 +75,7 @@ void CreateLibraryDialog::setupUI()
|
||||
setWindowTitle(tr("Create new library"));
|
||||
}
|
||||
|
||||
void CreateLibraryDialog::show(const QMap<QString,QString> & libs)
|
||||
void CreateLibraryDialog::show(const YACReaderLibraries & libs)
|
||||
{
|
||||
libraries = libs;
|
||||
QDialog::show();
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef __CREATE_LIBRARY_DIALOG_H
|
||||
#define __CREATE_LIBRARY_DIALOG_H
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
@ -23,7 +25,7 @@
|
||||
QPushButton * find;
|
||||
QPushButton * accept;
|
||||
QPushButton * cancel;
|
||||
QMap<QString,QString> libraries;
|
||||
YACReaderLibraries libraries;
|
||||
void setupUI();
|
||||
public slots:
|
||||
void create();
|
||||
@ -32,7 +34,7 @@
|
||||
void setDataAndStart(QString name, QString paht);
|
||||
void nameSetted(const QString & text);
|
||||
void pathSetted(const QString & text);
|
||||
void show(const QMap<QString,QString> & libraries);
|
||||
void show(const YACReaderLibraries &libraries);
|
||||
signals:
|
||||
void createLibrary(QString source, QString target, QString name);
|
||||
void cancelCreate();
|
||||
|
@ -16,54 +16,21 @@
|
||||
#include "comic_db.h"
|
||||
#include "data_base_management.h"
|
||||
#include "folder.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
//server
|
||||
|
||||
//TODO optimizar, evitar que se tenga que leer en cada petición el archivo
|
||||
//conservar un QDateTime stático que compruebe si libraries.yacr ha sido modificado
|
||||
//libraries debe ser una variable estática
|
||||
static QDateTime lastModified;
|
||||
static QMap<QString,QString> libraries;
|
||||
|
||||
QMap<QString,QString> DBHelper::getLibraries()
|
||||
YACReaderLibraries DBHelper::getLibraries()
|
||||
{
|
||||
QFileInfo fi(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
if(fi.lastModified() == lastModified)
|
||||
return libraries;
|
||||
|
||||
lastModified = fi.lastModified();
|
||||
libraries.clear();
|
||||
QFile f(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QTextStream txtS(&f);
|
||||
QString content = txtS.readAll();
|
||||
QStringList lines = content.split('\n');
|
||||
QString line,name;
|
||||
int i=0;
|
||||
foreach(line,lines)
|
||||
{
|
||||
if((i%2)==0)
|
||||
{
|
||||
name = line;
|
||||
}
|
||||
else
|
||||
{
|
||||
//sólo se agregan las bibliotecas realmente disponibles
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(line.trimmed()+"/.yacreaderlibrary");
|
||||
if(db.isValid())
|
||||
libraries.insert(name.trimmed(),line.trimmed());
|
||||
db.close();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
f.close();
|
||||
YACReaderLibraries libraries;
|
||||
libraries.load();
|
||||
return libraries;
|
||||
}
|
||||
QList<LibraryItem *> DBHelper::getFolderContentFromLibrary(const QString & libraryName, qulonglong folderId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QList<LibraryItem *> list = DBHelper::getFoldersFromParent(folderId,db,false);
|
||||
@ -74,7 +41,7 @@ QList<LibraryItem *> DBHelper::getFolderContentFromLibrary(const QString & libra
|
||||
}
|
||||
QList<LibraryItem *> DBHelper::getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QList<LibraryItem *> list = DBHelper::getComicsFromParent(folderId,db,false);
|
||||
@ -85,7 +52,7 @@ QList<LibraryItem *> DBHelper::getFolderComicsFromLibrary(const QString & librar
|
||||
}
|
||||
qulonglong DBHelper::getParentFromComicFolderId(const QString & libraryName, qulonglong id)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
Folder f = DBHelper::loadFolder(id,db);
|
||||
@ -96,7 +63,7 @@ qulonglong DBHelper::getParentFromComicFolderId(const QString & libraryName, qul
|
||||
}
|
||||
ComicDB DBHelper::getComicInfo(const QString & libraryName, qulonglong id)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
ComicDB comic = DBHelper::loadComic(id,db);
|
||||
@ -108,7 +75,7 @@ ComicDB DBHelper::getComicInfo(const QString & libraryName, qulonglong id)
|
||||
|
||||
QList<ComicDB> DBHelper::getSiblings(const QString & libraryName, qulonglong parentId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QList<ComicDB> comics = DBHelper::getSortedComicsFromParent(parentId,db);
|
||||
@ -119,7 +86,7 @@ QList<ComicDB> DBHelper::getSiblings(const QString & libraryName, qulonglong par
|
||||
|
||||
QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QString name="";
|
||||
@ -143,19 +110,13 @@ QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
|
||||
}
|
||||
QList<QString> DBHelper::getLibrariesNames()
|
||||
{
|
||||
QStringList names = getLibraries().keys();
|
||||
QStringList names = getLibraries().getNames();
|
||||
qSort(names.begin(),names.end(),naturalSortLessThanCI);
|
||||
return names;
|
||||
}
|
||||
QString DBHelper::getLibraryName(int id)
|
||||
{
|
||||
QStringList names = getLibrariesNames();
|
||||
if(names.isEmpty())
|
||||
return "";
|
||||
if(id>=0 && id<names.count())
|
||||
return names.at(id);
|
||||
else
|
||||
return names.at(0);
|
||||
return getLibraries().getName(id);
|
||||
}
|
||||
//objects management
|
||||
//deletes
|
||||
@ -191,7 +152,7 @@ void DBHelper::update(ComicDB * comic, QSqlDatabase & db)
|
||||
|
||||
void DBHelper::update(const QString & libraryName, ComicInfo & comicInfo)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
DBHelper::update(&comicInfo,db);
|
||||
|
@ -12,12 +12,13 @@ class QSqlDatabase;
|
||||
class ComicInfo;
|
||||
class QSqlRecord;
|
||||
class QSqlQuery;
|
||||
class YACReaderLibraries;
|
||||
|
||||
class DBHelper
|
||||
{
|
||||
public:
|
||||
//server
|
||||
static QMap<QString,QString> getLibraries();
|
||||
static YACReaderLibraries getLibraries();
|
||||
static QList<LibraryItem *> getFolderContentFromLibrary(const QString & libraryName, qulonglong folderId);
|
||||
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
|
||||
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
||||
@ -59,4 +60,4 @@ private:
|
||||
static void bindField(const QString & name, bool * field, QSqlQuery & query);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -86,7 +86,7 @@ void ImportLibraryDialog::setupUI()
|
||||
setModal(true);
|
||||
setWindowTitle(tr("Extract a catalog"));
|
||||
}
|
||||
void ImportLibraryDialog::show(const QMap<QString,QString> & libs)
|
||||
void ImportLibraryDialog::show(const YACReaderLibraries &libs)
|
||||
{
|
||||
libraries = libs;
|
||||
QDialog::show();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef IMPORT_LIBRARY_DIALOG_H
|
||||
#define IMPORT_LIBRARY_DIALOG_H
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
@ -29,14 +29,14 @@
|
||||
void setupUI();
|
||||
int progressCount;
|
||||
void closeEvent ( QCloseEvent * e );
|
||||
QMap<QString,QString> libraries;
|
||||
YACReaderLibraries libraries;
|
||||
public slots:
|
||||
void add();
|
||||
void findPath();
|
||||
void findDestination();
|
||||
void close();
|
||||
void nameEntered();
|
||||
void show(const QMap<QString,QString> & libs);
|
||||
void show(const YACReaderLibraries & libs);
|
||||
|
||||
signals:
|
||||
void unpackCLC(QString clc,QString targetFolder, QString name);
|
||||
|
@ -68,13 +68,14 @@ LibraryWindow::LibraryWindow()
|
||||
setupUI();
|
||||
loadLibraries();
|
||||
|
||||
if(libraries.size()==0)
|
||||
if(libraries.isEmpty())
|
||||
{
|
||||
showNoLibrariesWidget();
|
||||
}
|
||||
else
|
||||
{
|
||||
showRootWidget();
|
||||
selectedLibrary->setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ void LibraryWindow::setupUI()
|
||||
libraryCreator = new LibraryCreator();
|
||||
packageManager = new PackageManager();
|
||||
|
||||
settings = new QSettings(QCoreApplication::applicationDirPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
settings->beginGroup("libraryConfig");
|
||||
|
||||
createActions();
|
||||
@ -754,7 +755,7 @@ void LibraryWindow::createConnections()
|
||||
|
||||
void LibraryWindow::loadLibrary(const QString & name)
|
||||
{
|
||||
if(libraries.size()>0) //si hay bibliotecas...
|
||||
if(!libraries.isEmpty()) //si hay bibliotecas...
|
||||
{
|
||||
currentFolderNavigation=0;
|
||||
backAction->setDisabled(true);
|
||||
@ -763,7 +764,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
||||
history.append(QModelIndex());
|
||||
|
||||
showRootWidget();
|
||||
QString path=libraries.value(name)+"/.yacreaderlibrary";
|
||||
QString path=libraries.getPath(name)+"/.yacreaderlibrary";
|
||||
QDir d; //TODO change this by static methods (utils class?? with delTree for example)
|
||||
QString dbVersion;
|
||||
if(d.exists(path) && d.exists(path+"/library.ydb") && (dbVersion = DataBaseManagement::checkValidDB(path+"/library.ydb")) != "") //si existe en disco la biblioteca seleccionada, y es v<>lida..
|
||||
@ -804,7 +805,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
||||
else
|
||||
disableFoldersActions(true);
|
||||
|
||||
d.setCurrent(libraries.value(name));
|
||||
d.setCurrent(libraries.getPath(name));
|
||||
d.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
||||
if(d.count()<=1) //librer<65>a de s<>lo lectura
|
||||
{
|
||||
@ -878,7 +879,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
||||
else
|
||||
{
|
||||
QString currentLibrary = selectedLibrary->currentText();
|
||||
QString path = libraries.value(selectedLibrary->currentText());
|
||||
QString path = libraries.getPath(selectedLibrary->currentText());
|
||||
if(QMessageBox::question(this,tr("Old library"),tr("Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now?").arg(currentLibrary),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
|
||||
{
|
||||
QDir d(path+"/.yacreaderlibrary");
|
||||
@ -1107,10 +1108,10 @@ void LibraryWindow::openLastCreated()
|
||||
selectedLibrary->disconnect();
|
||||
|
||||
selectedLibrary->setCurrentIndex(selectedLibrary->findText(_lastAdded));
|
||||
libraries.insert(_lastAdded,_sourceLastAdded);
|
||||
libraries.addLibrary(_lastAdded,_sourceLastAdded);
|
||||
selectedLibrary->addItem(_lastAdded,_sourceLastAdded);
|
||||
selectedLibrary->setCurrentIndex(selectedLibrary->findText(_lastAdded));
|
||||
saveLibraries();
|
||||
libraries.save();
|
||||
|
||||
connect(selectedLibrary,SIGNAL(currentIndexChanged(QString)),this,SLOT(loadLibrary(QString)));
|
||||
|
||||
@ -1147,40 +1148,17 @@ void LibraryWindow::openLibrary(QString path, QString name)
|
||||
|
||||
void LibraryWindow::loadLibraries()
|
||||
{
|
||||
QFile f(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QTextStream txtS(&f);
|
||||
QString content = txtS.readAll();
|
||||
QStringList lines = content.split('\n');
|
||||
QString line,name;
|
||||
int i=0;
|
||||
bool librariesAvailable = false;
|
||||
foreach(line,lines)
|
||||
{
|
||||
if((i%2)==0)
|
||||
{
|
||||
name = line;
|
||||
}
|
||||
else
|
||||
{
|
||||
librariesAvailable = true;
|
||||
libraries.insert(name.trimmed(),line.trimmed());
|
||||
selectedLibrary->addItem(name.trimmed(),line.trimmed());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(!librariesAvailable)
|
||||
{
|
||||
disableAllActions();
|
||||
}
|
||||
else
|
||||
selectedLibrary->setCurrentIndex(0);
|
||||
libraries.load();
|
||||
foreach(QString name,libraries.getNames())
|
||||
selectedLibrary->addItem(name,libraries.getPath(name));
|
||||
}
|
||||
|
||||
|
||||
void LibraryWindow::saveLibraries()
|
||||
{
|
||||
QFile f(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
|
||||
libraries.save();
|
||||
/*QFile f(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
if(!f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QMessageBox::critical(NULL,tr("Saving libraries file...."),tr("There was a problem saving YACReaderLibrary libraries file. Please, check if you have enough permissions in the YACReader root folder."));
|
||||
@ -1193,7 +1171,7 @@ void LibraryWindow::saveLibraries()
|
||||
txtS << i.key() << "\n";
|
||||
txtS << i.value() << "\n";
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void LibraryWindow::updateLibrary()
|
||||
@ -1202,7 +1180,7 @@ void LibraryWindow::updateLibrary()
|
||||
showImportingWidget();
|
||||
|
||||
QString currentLibrary = selectedLibrary->currentText();
|
||||
QString path = libraries.value(currentLibrary);
|
||||
QString path = libraries.getPath(currentLibrary);
|
||||
_lastAdded = currentLibrary;
|
||||
libraryCreator->updateLibrary(path,path+"/.yacreaderlibrary");
|
||||
libraryCreator->start();
|
||||
@ -1210,7 +1188,7 @@ void LibraryWindow::updateLibrary()
|
||||
|
||||
void LibraryWindow::deleteCurrentLibrary()
|
||||
{
|
||||
QString path = libraries.value(selectedLibrary->currentText());
|
||||
QString path = libraries.getPath(selectedLibrary->currentText());
|
||||
libraries.remove(selectedLibrary->currentText());
|
||||
selectedLibrary->removeItem(selectedLibrary->currentIndex());
|
||||
//selectedLibrary->setCurrentIndex(0);
|
||||
@ -1219,13 +1197,13 @@ void LibraryWindow::deleteCurrentLibrary()
|
||||
QDir d(path);
|
||||
delTree(d);
|
||||
d.rmdir(path);
|
||||
if(libraries.size()==0)//no more libraries avaliable.
|
||||
if(libraries.isEmpty())//no more libraries avaliable.
|
||||
{
|
||||
comicView->setModel(NULL);
|
||||
foldersView->setModel(NULL);
|
||||
comicFlow->clear();
|
||||
}
|
||||
saveLibraries();
|
||||
libraries.save();
|
||||
}
|
||||
|
||||
void LibraryWindow::removeLibrary()
|
||||
@ -1239,20 +1217,20 @@ void LibraryWindow::removeLibrary()
|
||||
libraries.remove(currentLibrary);
|
||||
selectedLibrary->removeItem(selectedLibrary->currentIndex());
|
||||
//selectedLibrary->setCurrentIndex(0);
|
||||
if(libraries.size()==0)//no more libraries avaliable.
|
||||
if(libraries.isEmpty())//no more libraries avaliable.
|
||||
{
|
||||
comicView->setModel(NULL);
|
||||
foldersView->setModel(NULL);
|
||||
comicFlow->clear();
|
||||
}
|
||||
saveLibraries();
|
||||
libraries.save();
|
||||
}
|
||||
else if(ret == QMessageBox::YesToAll)
|
||||
{
|
||||
deleteCurrentLibrary();
|
||||
}
|
||||
|
||||
if(libraries.size()==0)
|
||||
if(libraries.isEmpty())
|
||||
{
|
||||
disableAllActions();
|
||||
showNoLibrariesWidget();
|
||||
@ -1264,19 +1242,18 @@ void LibraryWindow::renameLibrary()
|
||||
renameLibraryDialog->show();
|
||||
}
|
||||
|
||||
void LibraryWindow::rename(QString newName)
|
||||
void LibraryWindow::rename(QString newName) //TODO replace
|
||||
{
|
||||
QString currentLibrary = selectedLibrary->currentText();
|
||||
if(newName != currentLibrary)
|
||||
{
|
||||
if(!libraries.contains(newName))
|
||||
{
|
||||
QString path = libraries.value(currentLibrary);
|
||||
libraries.remove(currentLibrary);
|
||||
libraries.rename(currentLibrary,newName);
|
||||
//selectedLibrary->removeItem(selectedLibrary->currentIndex());
|
||||
libraries.insert(newName,path);
|
||||
//libraries.addLibrary(newName,path);
|
||||
selectedLibrary->renameCurrentLibrary(newName);
|
||||
saveLibraries();
|
||||
libraries.save();
|
||||
renameLibraryDialog->close();
|
||||
#ifndef Q_OS_MAC
|
||||
if(!foldersView->currentIndex().isValid())
|
||||
@ -1306,9 +1283,9 @@ void LibraryWindow::stopLibraryCreator()
|
||||
|
||||
void LibraryWindow::setRootIndex()
|
||||
{
|
||||
if(libraries.size()>0)
|
||||
if(!libraries.isEmpty())
|
||||
{
|
||||
QString path=libraries.value(selectedLibrary->currentText())+"/.yacreaderlibrary";
|
||||
QString path=libraries.getPath(selectedLibrary->currentText())+"/.yacreaderlibrary";
|
||||
QDir d; //TODO change this by static methods (utils class?? with delTree for example)
|
||||
if(d.exists(path))
|
||||
{
|
||||
@ -1498,7 +1475,7 @@ void LibraryWindow::openContainingFolder()
|
||||
void LibraryWindow::exportLibrary(QString destPath)
|
||||
{
|
||||
QString currentLibrary = selectedLibrary->currentText();
|
||||
QString path = libraries.value(currentLibrary)+"/.yacreaderlibrary";
|
||||
QString path = libraries.getPath(currentLibrary)+"/.yacreaderlibrary";
|
||||
packageManager->createPackage(path,destPath+"/"+currentLibrary);
|
||||
}
|
||||
|
||||
@ -1517,7 +1494,7 @@ void LibraryWindow::reloadOptions()
|
||||
|
||||
QString LibraryWindow::currentPath()
|
||||
{
|
||||
return libraries.value(selectedLibrary->currentText());
|
||||
return libraries.getPath(selectedLibrary->currentText());
|
||||
}
|
||||
|
||||
void LibraryWindow::hideComicFlow(bool hide)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QModelIndex>
|
||||
#include <QFileInfo>
|
||||
#include "yacreader_global.h"
|
||||
#include <yacreader_libraries.h>
|
||||
|
||||
class QTreeView;
|
||||
class QDirModel;
|
||||
@ -97,7 +98,7 @@ private:
|
||||
TreeModel * dm;
|
||||
TableModel * dmCV;
|
||||
//QStringList paths;
|
||||
QMap<QString,QString> libraries;
|
||||
YACReaderLibraries libraries;
|
||||
QLabel * fullScreenToolTip;
|
||||
|
||||
QStackedWidget * mainWidget;
|
||||
|
@ -10,17 +10,12 @@
|
||||
#include <QSettings>
|
||||
#include <QLibrary>
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
#include <QStandardPaths>
|
||||
#else
|
||||
#include <QDesktopServices>
|
||||
#endif
|
||||
|
||||
#include "yacreader_global.h"
|
||||
#include "startup.h"
|
||||
#include "yacreader_local_server.h"
|
||||
#include "comic_db.h"
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
#include "QsLogDest.h"
|
||||
@ -110,7 +105,7 @@ void logSystemAndConfig()
|
||||
else
|
||||
QLOG_INFO() << "qrencode : not found";
|
||||
|
||||
QSettings settings(QCoreApplication::applicationDirPath()+"/YACReaderLibrary.ini",QSettings::IniFormat);
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat);
|
||||
settings.beginGroup("libraryConfig");
|
||||
if(settings.value(SERVER_ON).toBool())
|
||||
QLOG_INFO() << "server : enabled";
|
||||
@ -122,7 +117,7 @@ void logSystemAndConfig()
|
||||
else
|
||||
QLOG_INFO() << "OpenGL : disabled";
|
||||
|
||||
QLOG_INFO() << "Libraries: " << DBHelper::getLibraries();
|
||||
QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries();
|
||||
QLOG_INFO() << "--------------------------------------------";
|
||||
}
|
||||
|
||||
@ -133,16 +128,8 @@ int main( int argc, char ** argv )
|
||||
app.setApplicationName("YACReaderLibrary");
|
||||
app.setOrganizationName("YACReader");
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
QString destLog = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)+"/yacreaderlibrary.log";
|
||||
QString destErr = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)+"/yacreaderlibrary.err";
|
||||
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
|
||||
|
||||
#else
|
||||
QString destLog = QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/yacreaderlibrary.log";
|
||||
QString destErr = QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/yacreaderlibrary.err";
|
||||
QDir().mkpath(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
|
||||
#endif
|
||||
QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log";
|
||||
QDir().mkpath(YACReader::getSettingsPath());
|
||||
|
||||
Logger& logger = Logger::instance();
|
||||
logger.setLoggingLevel(QsLogging::TraceLevel);
|
||||
@ -166,7 +153,7 @@ int main( int argc, char ** argv )
|
||||
qRegisterMetaType<ComicDB>("ComicDB");
|
||||
|
||||
#ifdef SERVER_RELEASE
|
||||
QSettings * settings = new QSettings(QCoreApplication::applicationDirPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
settings->beginGroup("libraryConfig");
|
||||
|
||||
s = new Startup();
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "comiccontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
@ -38,14 +39,14 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
//que crear una clase que se encargue de estas cosas
|
||||
//<2F>Se est<73> accediendo a la UI desde un hilo?
|
||||
|
||||
QMap<QString,QString> libraries = DBHelper::getLibraries();
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryName, comicId);
|
||||
|
||||
session.setDownloadedComic(comic.info.hash);
|
||||
|
||||
Comic * comicFile = FactoryComic::newComic(libraries.value(libraryName)+comic.path);
|
||||
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryName)+comic.path);
|
||||
|
||||
if(comicFile != NULL)
|
||||
{
|
||||
@ -58,7 +59,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
connect(thread, SIGNAL(started()), comicFile, SLOT(process()));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
comicFile->load(libraries.value(libraryName)+comic.path);
|
||||
comicFile->load(libraries.getPath(libraryName)+comic.path);
|
||||
|
||||
if(thread != NULL)
|
||||
thread->start();
|
||||
@ -78,4 +79,4 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
}
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "covercontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
@ -15,7 +16,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
|
||||
response.setHeader("Connection","close");
|
||||
//response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
|
||||
QMap<QString,QString> libraries = DBHelper::getLibraries();
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||
QStringList pathElements = path.split('/');
|
||||
@ -40,7 +41,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
|
||||
// file.close();
|
||||
//}
|
||||
|
||||
QImage img(libraries.value(libraryName)+"/.yacreaderlibrary/covers/"+fileName);
|
||||
QImage img(libraries.getPath(libraryName)+"/.yacreaderlibrary/covers/"+fileName);
|
||||
if (!img.isNull()) {
|
||||
|
||||
int width = 80;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "librariescontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
@ -39,16 +40,20 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
QList<QString> names = DBHelper::getLibrariesNames();
|
||||
|
||||
t.loop("library",names.length());
|
||||
int i=0;
|
||||
while (i<names.length()) {
|
||||
t.setVariable(QString("library%1.name").arg(i),QString::number(i));
|
||||
t.setVariable(QString("library%1.label").arg(i),names.at(i));
|
||||
|
||||
int currentId = 0;
|
||||
int i = 0;
|
||||
foreach (QString name,names) {
|
||||
currentId = libraries.getId(name);
|
||||
t.setVariable(QString("library%1.name").arg(i),QString::number(currentId));
|
||||
t.setVariable(QString("library%1.label").arg(i),name);
|
||||
i++;
|
||||
}
|
||||
|
||||
response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "controllers/errorcontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
RequestMapper::RequestMapper(QObject* parent)
|
||||
:HttpRequestHandler(parent) {}
|
||||
@ -53,7 +54,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
if(!session.isNull() && session.contains("ySession"))
|
||||
{
|
||||
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().count() > library.cap(1).toInt() )
|
||||
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().contains(library.cap(1).toInt()) )
|
||||
{
|
||||
//listar el contenido del folder
|
||||
if(folder.exactMatch(path))
|
||||
@ -89,4 +90,4 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ ServerConfigDialog::ServerConfigDialog(QWidget * parent)
|
||||
|
||||
this->setFixedSize(image.size());
|
||||
|
||||
QSettings * settings = new QSettings(QCoreApplication::applicationDirPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
settings->beginGroup("libraryConfig");
|
||||
|
||||
if(settings->value(SERVER_ON,true).toBool())
|
||||
@ -184,7 +184,7 @@ ServerConfigDialog::ServerConfigDialog(QWidget * parent)
|
||||
|
||||
void ServerConfigDialog::enableServer(int status)
|
||||
{
|
||||
QSettings * settings = new QSettings(QCoreApplication::applicationDirPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
settings->beginGroup("libraryConfig");
|
||||
|
||||
if(status == Qt::Checked)
|
||||
@ -313,7 +313,7 @@ void ServerConfigDialog::regenerateQR(const QString & ip)
|
||||
void ServerConfigDialog::updatePort()
|
||||
{
|
||||
|
||||
QSettings * settings = new QSettings(QCoreApplication::applicationDirPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
settings->beginGroup("listener");
|
||||
settings->setValue("port",port->text().toInt());
|
||||
settings->endGroup();
|
||||
|
147
YACReaderLibrary/yacreader_libraries.cpp
Normal file
147
YACReaderLibrary/yacreader_libraries.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
|
||||
|
||||
YACReaderLibraries::YACReaderLibraries()
|
||||
:QObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
YACReaderLibraries::YACReaderLibraries(const YACReaderLibraries &source)
|
||||
:QObject(),libraries(source.libraries)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QList<QString> YACReaderLibraries::getNames()
|
||||
{
|
||||
return libraries.keys();
|
||||
}
|
||||
|
||||
QString YACReaderLibraries::getPath(const QString &name)
|
||||
{
|
||||
return libraries.value(name).second;
|
||||
}
|
||||
|
||||
QString YACReaderLibraries::getPath(int id)
|
||||
{
|
||||
foreach(QString name, libraries.keys())
|
||||
if(libraries.value(name).first == id)
|
||||
return libraries.value(name).second;
|
||||
return "";
|
||||
}
|
||||
|
||||
QString YACReaderLibraries::getName(int id)
|
||||
{
|
||||
foreach(QString name, libraries.keys())
|
||||
if(libraries.value(name).first == id)
|
||||
return name;
|
||||
return "";
|
||||
}
|
||||
|
||||
bool YACReaderLibraries::isEmpty()
|
||||
{
|
||||
return libraries.isEmpty();
|
||||
}
|
||||
|
||||
bool YACReaderLibraries::contains(const QString &name)
|
||||
{
|
||||
return libraries.contains(name);
|
||||
}
|
||||
|
||||
bool YACReaderLibraries::contains(int id)
|
||||
{
|
||||
foreach(QString name, libraries.keys())
|
||||
if(libraries.value(name).first == id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void YACReaderLibraries::remove(const QString &name)
|
||||
{
|
||||
libraries.remove(name);
|
||||
}
|
||||
|
||||
void YACReaderLibraries::rename(const QString &oldName, const QString &newName)
|
||||
{
|
||||
if(libraries.contains(oldName))
|
||||
{
|
||||
QPair<int,QString> value = libraries.value(oldName);
|
||||
libraries.remove(oldName);
|
||||
libraries.insert(newName,value);
|
||||
}
|
||||
}
|
||||
|
||||
int YACReaderLibraries::getId(const QString &name)
|
||||
{
|
||||
return libraries.value(name).first;
|
||||
}
|
||||
|
||||
YACReaderLibraries &YACReaderLibraries::operator=(const YACReaderLibraries &source)
|
||||
{
|
||||
libraries = source.libraries;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QMap<QString, QPair<int, QString> > YACReaderLibraries::getLibraries()
|
||||
{
|
||||
return libraries;
|
||||
}
|
||||
|
||||
|
||||
void YACReaderLibraries::addLibrary(const QString &name, const QString &path)
|
||||
{
|
||||
int newID=0;
|
||||
foreach(QString name, libraries.keys())
|
||||
newID = qMax(0,libraries.value(name).first);
|
||||
newID++;
|
||||
libraries.insert(name,QPair<int,QString>(newID,path));
|
||||
}
|
||||
|
||||
void YACReaderLibraries::load()
|
||||
{
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat);
|
||||
|
||||
if(settings.value(LIBRARIES).isValid())
|
||||
{
|
||||
QByteArray data = settings.value(LIBRARIES).toByteArray();
|
||||
QDataStream in(&data, QIODevice::ReadOnly);
|
||||
in >> libraries;
|
||||
}
|
||||
else //only for compatibility with old versions (<7.0)
|
||||
{
|
||||
QFile f(QCoreApplication::applicationDirPath()+"/libraries.yacr");
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QTextStream txtS(&f);
|
||||
QString content = txtS.readAll();
|
||||
QStringList lines = content.split('\n');
|
||||
QString line,name;
|
||||
int i=0;
|
||||
|
||||
foreach(line,lines)
|
||||
{
|
||||
if((i%2)==0)
|
||||
name = line;
|
||||
else
|
||||
addLibrary(name.trimmed(),line.trimmed());
|
||||
i++;
|
||||
}
|
||||
f.close();
|
||||
if(save())
|
||||
f.remove();
|
||||
}
|
||||
}
|
||||
|
||||
bool YACReaderLibraries::save()
|
||||
{
|
||||
QSettings settings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat);
|
||||
|
||||
QByteArray data;
|
||||
QDataStream out(&data, QIODevice::WriteOnly);
|
||||
out << libraries;
|
||||
settings.setValue(LIBRARIES, data);
|
||||
|
||||
return settings.isWritable();
|
||||
}
|
34
YACReaderLibrary/yacreader_libraries.h
Normal file
34
YACReaderLibrary/yacreader_libraries.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef YACREADER_LIBRARIES_H
|
||||
#define YACREADER_LIBRARIES_H
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class YACReaderLibraries : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
YACReaderLibraries();
|
||||
YACReaderLibraries(const YACReaderLibraries & source);
|
||||
QList<QString> getNames();
|
||||
QString getPath(const QString & name);
|
||||
QString getPath(int id);
|
||||
QString getName(int id);
|
||||
bool isEmpty();
|
||||
bool contains(const QString & name);
|
||||
bool contains(int id);
|
||||
void remove(const QString & name);
|
||||
void rename(const QString & oldName, const QString & newName);
|
||||
int getId(const QString & name);
|
||||
YACReaderLibraries & operator=(const YACReaderLibraries & source);
|
||||
QMap <QString , QPair<int,QString> > getLibraries();
|
||||
public slots:
|
||||
void addLibrary(const QString & name, const QString & path);
|
||||
void load();
|
||||
bool save();
|
||||
private:
|
||||
//name <id,path>
|
||||
QMap <QString , QPair<int,QString> > libraries;
|
||||
};
|
||||
|
||||
#endif // YACREADER_LIBRARIES_H
|
13
common/yacreader_global.cpp
Normal file
13
common/yacreader_global.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "yacreader_global.h"
|
||||
|
||||
using namespace YACReader;
|
||||
|
||||
QString YACReader::getSettingsPath()
|
||||
{
|
||||
#if QT_VERSION >= 0x050000
|
||||
return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
||||
#else
|
||||
return QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
#endif
|
||||
|
||||
}
|
@ -1,6 +1,13 @@
|
||||
#ifndef __YACREADER_GLOBAL_H
|
||||
#define __YACREADER_GLOBAL_H
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
#include <QStandardPaths>
|
||||
#else
|
||||
#include <QDesktopServices>
|
||||
#endif
|
||||
|
||||
|
||||
#define VERSION "6.5.3"
|
||||
|
||||
#define PATH "PATH"
|
||||
@ -53,6 +60,8 @@
|
||||
|
||||
#define YACREADERLIBRARY_GUID "ea343ff3-2005-4865-b212-7fa7c43999b8"
|
||||
|
||||
#define LIBRARIES "LIBRARIES"
|
||||
|
||||
namespace YACReader
|
||||
{
|
||||
|
||||
@ -79,6 +88,8 @@ namespace YACReader
|
||||
Opened = 2
|
||||
};
|
||||
|
||||
QString getSettingsPath();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user