diff options
Diffstat (limited to 'src/frontend/bookshelfmanager/instbackend.cpp')
-rw-r--r-- | src/frontend/bookshelfmanager/instbackend.cpp | 128 |
1 files changed, 86 insertions, 42 deletions
diff --git a/src/frontend/bookshelfmanager/instbackend.cpp b/src/frontend/bookshelfmanager/instbackend.cpp index caf1e08..d671430 100644 --- a/src/frontend/bookshelfmanager/instbackend.cpp +++ b/src/frontend/bookshelfmanager/instbackend.cpp @@ -7,31 +7,26 @@ * **********/ -#include "instbackend.h" +#include "frontend/bookshelfmanager/instbackend.h" -#include "frontend/bookshelfmanager/btinstallmgr.h" -#include "backend/managers/cswordbackend.h" - -#include "util/cpointers.h" -#include "util/directoryutil.h" - -//Qt includes +#include <functional> +#include <map> +#include <QDebug> +#include <QDir> #include <QFile> #include <QFileInfo> -#include <QDir> -#include <QMessageBox> - -#include <QDebug> +#include <utility> +#include "backend/managers/cswordbackend.h" +#include "frontend/bookshelfmanager/btinstallmgr.h" +#include "util/cpointers.h" +#include "util/directory.h" +#include "util/dialogutil.h" -//Sword includes +// Sword includes: #include <filemgr.h> #include <swconfig.h> #include <swbuf.h> -//Stl includes -#include <functional> -#include <map> -#include <utility> using namespace sword; @@ -39,7 +34,7 @@ namespace instbackend { /** Adds the source described by Source to the backend. */ bool addSource(sword::InstallSource& source) { - qDebug("backend::addSource"); + qDebug() << "backend::addSource"; SWConfig config(configFilename().toLatin1()); if (!strcmp(source.type, "FTP")) { //make sure the path doesn't have a trailing slash, sword doesn't like it @@ -58,7 +53,7 @@ bool addSource(sword::InstallSource& source) { /** Returns the Source struct. */ sword::InstallSource source(QString name) { - qDebug("backend::source"); + qDebug() << "backend::source"; BtInstallMgr mgr; InstallSourceMap::iterator source = mgr.sources.find(name.toLatin1().data()); if (source != mgr.sources.end()) { @@ -93,7 +88,7 @@ sword::InstallSource source(QString name) { /** Deletes the source. */ bool deleteSource(QString name) { - qDebug("backend::deleteSource"); + qDebug() << "backend::deleteSource"; sword::InstallSource is = source(name ); SWConfig config(configFilename().toLatin1()); @@ -105,28 +100,48 @@ bool deleteSource(QString name) { : config["Sources"].equal_range("DIRSource"); ConfigEntMap::iterator it = range.first; + SWBuf sourceConfigEntry = is.getConfEnt(); + bool notFound = true; while (it != range.second) { - if (it->second == is.getConfEnt()) { - // qWarning("found the source!"); + //SWORD lib gave us a "nice" surprise: getConfEnt() adds uid, so old sources added by BT are not recognized here + if (it->second == sourceConfigEntry) { config["Sources"].erase(it); + notFound = false; break; } ++it; } + if (notFound) { + qDebug() << "source was not found, try without uid"; + //try again without uid + QString sce(sourceConfigEntry.c_str()); + QStringList l = sce.split('|'); + l.removeLast(); + sce = l.join("|").append("|"); + it = range.first; + while (it != range.second) { + qDebug() << it->second; + if (it->second == sce) { + config["Sources"].erase(it); + break; + } + ++it; + } + } config.Save(); - return true; //TODO: dummy + return true; /// \todo dummy } /** Refreshes the remote source module list. */ bool refreshSource(QString /*name*/) { // not possible until manager and progressdialog work together - return true; //TODO: dummy + return true; /// \todo dummy } /** Returns the moduleinfo list for the source. Delete the pointer after using. IS THIS POSSIBLE?*/ QList<CSwordModuleInfo*> moduleList(QString /*name*/) { - QList<CSwordModuleInfo*> list; //TODO: dummy + QList<CSwordModuleInfo*> list; /// \todo dummy return list; } @@ -135,10 +150,8 @@ bool isRemote(const sword::InstallSource& source) { } const QString configPath() { - const char *envhomedir = getenv("HOME"); - QString confPath = QString(envhomedir ? envhomedir : "."); - confPath.append("/.sword/InstallMgr"); - + QString confPath = util::directory::getUserHomeSwordDir().absolutePath(); + confPath.append("/InstallMgr"); return confPath; } @@ -147,16 +160,18 @@ const QString configFilename() { } QStringList targetList() { - qDebug("backend::targetList"); + qDebug() << "backend::targetList"; QStringList names = CPointers::backend()->swordDirList(); return names; } bool setTargetList( const QStringList& targets ) { - qDebug("backend::setTargetList"); + namespace DU = util::directory; + + qDebug() << "backend::setTargetList"; //saves a new Sword config using the provided target list //QString filename = KGlobal::dirs()->saveLocation("data", "bibletime/") + "sword.conf"; //default is to assume the real location isn't writable - //QString filename = util::filesystem::DirectoryUtil::getUserBaseDir().canonicalPath().append("/.sword/sword.conf"); + //QString filename = util::DirectoryUtil::getUserBaseDir().canonicalPath().append("/.sword/sword.conf"); //bool directAccess = false; QString filename = swordConfigFilename(); QFileInfo i(filename); @@ -177,15 +192,30 @@ bool setTargetList( const QStringList& targets ) { else { // There is no way to save to the file qWarning() << "The Sword config file is not writable!"; - QMessageBox::warning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!")); + util::showWarning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!")); return false; } + + filename = util::directory::convertDirSeparators(filename); SWConfig conf(filename.toLocal8Bit()); conf.Sections.clear(); + +#ifdef Q_WS_WIN + // On Windows, add the sword directory to the config file. + QString swordPath = DU::convertDirSeparators( DU::getApplicationSwordDir().absolutePath()); + conf["Install"].insert( + std::make_pair( SWBuf("LocalePath"), swordPath.toLocal8Bit().data() ) + ); +#endif + bool setDataPath = false; for (QStringList::const_iterator it = targets.begin(); it != targets.end(); ++it) { - QString t = *it; - if (t.contains( util::filesystem::DirectoryUtil::getUserHomeDir().canonicalPath().append("/.sword") )) { + QString t = DU::convertDirSeparators(*it); +#ifdef Q_WS_WIN + if (t.contains(DU::convertDirSeparators(DU::getUserHomeDir().canonicalPath().append("\\Sword")))) { +#else + if (t.contains(DU::getUserHomeDir().canonicalPath().append("/.sword"))) { +#endif //we don't want $HOME/.sword in the config continue; } @@ -202,7 +232,7 @@ bool setTargetList( const QStringList& targets ) { } QStringList sourceList() { - qDebug("backend::sourceList"); + qDebug() << "backend::sourceList"; BtInstallMgr mgr; Q_ASSERT(mgr.installConf); @@ -233,23 +263,37 @@ QStringList sourceList() { void initPassiveFtpMode() { - qDebug("backend::initPassiveFtpMode"); + qDebug() << "backend::initPassiveFtpMode"; SWConfig config(configFilename().toLatin1()); config["General"]["PassiveFTP"] = "true"; config.Save(); } const QString swordConfigFilename() { - qDebug("backend::swordConfigFilename"); - qDebug() << util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/sword.conf"); - return util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/sword.conf"); + namespace DU = util::directory; + + qDebug() << "backend::swordConfigFilename"; +#ifdef Q_WS_WIN + qDebug() << DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf"); + return DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf"); +// return DU::getApplicationDir().absolutePath().append("/sword.conf"); +#else + qDebug() << DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf"); + return DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf"); +#endif } const QDir swordDir() { - return QDir(util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/")); + namespace DU = util::directory; + +#ifdef Q_WS_WIN + return QDir(DU::getUserHomeDir().absolutePath().append("/Sword/")); +#else + return QDir(DU::getUserHomeDir().absolutePath().append("/.sword/")); +#endif } CSwordBackend* backend( const sword::InstallSource& is) { - qDebug("backend::backend"); + qDebug() << "backend::backend"; CSwordBackend* ret = 0; if (isRemote(is)) { ret = new CSwordBackend( QString(is.localShadow.c_str()), false ); |