summaryrefslogtreecommitdiff
path: root/src/backend/btinstallbackend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/btinstallbackend.cpp')
-rw-r--r--src/backend/btinstallbackend.cpp78
1 files changed, 39 insertions, 39 deletions
diff --git a/src/backend/btinstallbackend.cpp b/src/backend/btinstallbackend.cpp
index c1136bf..7eb3ff4 100644
--- a/src/backend/btinstallbackend.cpp
+++ b/src/backend/btinstallbackend.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2011 by the BibleTime developers.
+* Copyright 1999-2014 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -14,9 +14,9 @@
#include <QFile>
#include <QFileInfo>
#include "backend/managers/cswordbackend.h"
-#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "backend/btinstallmgr.h"
#include "util/directory.h"
-#include "util/dialogutil.h"
+#include "frontend/messagedialog.h"
// Sword includes:
#include <filemgr.h>
@@ -31,13 +31,22 @@ namespace BtInstallBackend {
/** Adds the source described by Source to the backend. */
bool addSource(sword::InstallSource& source) {
SWConfig config(configFilename().toLatin1());
- if (!strcmp(source.type, "FTP")) {
- //make sure the path doesn't have a trailing slash, sword doesn't like it
+ if (isRemote(source)) {
if (source.directory[ source.directory.length()-1 ] == '/') {
- source.directory--; //make one char shorter
+ source.directory--;
+ }
+ if (!strcmp(source.type, "FTP")) {
+ config["Sources"].insert( std::make_pair(SWBuf("FTPSource"), source.getConfEnt()) );
+ }
+ else if (!strcmp(source.type, "SFTP")) {
+ config["Sources"].insert( std::make_pair(SWBuf("SFTPSource"), source.getConfEnt()) );
+ }
+ else if (!strcmp(source.type, "HTTP")) {
+ config["Sources"].insert( std::make_pair(SWBuf("HTTPSource"), source.getConfEnt()) );
+ }
+ else if (!strcmp(source.type, "HTTPS")) {
+ config["Sources"].insert( std::make_pair(SWBuf("HTTPSSource"), source.getConfEnt()) );
}
-
- config["Sources"].insert( std::make_pair(SWBuf("FTPSource"), source.getConfEnt()) );
}
else if (!strcmp(source.type, "DIR")) {
config["Sources"].insert( std::make_pair(SWBuf("DIRSource"), source.getConfEnt()) );
@@ -68,7 +77,7 @@ sword::InstallSource source(const QString &name) {
return is;
}
- sourceBegin++;//next source
+ ++sourceBegin; //next source
}
}
}
@@ -87,15 +96,10 @@ bool deleteSource(const QString &name) {
SWConfig config(configFilename().toLatin1());
//this code can probably be shortened by using the stl remove_if functionality
- std::pair< ConfigEntMap::iterator, ConfigEntMap::iterator > range =
- isRemote(is)
- ? config["Sources"].equal_range("FTPSource")
- : config["Sources"].equal_range("DIRSource");
-
- ConfigEntMap::iterator it = range.first;
SWBuf sourceConfigEntry = is.getConfEnt();
bool notFound = true;
- while (it != range.second) {
+ ConfigEntMap::iterator it = config["Sources"].begin();
+ while (it != config["Sources"].end()) {
//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);
@@ -111,8 +115,8 @@ bool deleteSource(const QString &name) {
QStringList l = sce.split('|');
l.removeLast();
sce = l.join("|").append("|");
- it = range.first;
- while (it != range.second) {
+ it = config["Sources"].begin();
+ while (it != config["Sources"].end()) {
if (it->second == sce) {
config["Sources"].erase(it);
break;
@@ -132,7 +136,10 @@ QList<CSwordModuleInfo*> moduleList(QString /*name*/) {
}
bool isRemote(const sword::InstallSource& source) {
- return !strcmp(source.type, "FTP");
+ return !strcmp(source.type, "FTP") ||
+ !strcmp(source.type, "SFTP") ||
+ !strcmp(source.type, "HTTP") ||
+ !strcmp(source.type, "HTTPS");
}
QString configPath() {
@@ -171,7 +178,7 @@ bool setTargetList( const QStringList& targets ) {
if (!i.exists() || !i.isWritable()) {
// There is no way to save to the file
qWarning() << "The Sword config file is not writable!";
- util::showWarning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!"));
+ message::showWarning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!"));
return false;
}
@@ -179,7 +186,7 @@ bool setTargetList( const QStringList& targets ) {
SWConfig conf(filename.toLocal8Bit());
conf.Sections.clear();
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
// On Windows, add the sword directory to the config file.
QString swordPath = DU::convertDirSeparators( DU::getApplicationSwordDir().absolutePath());
conf["Install"].insert(
@@ -190,7 +197,7 @@ bool setTargetList( const QStringList& targets ) {
bool setDataPath = false;
for (QStringList::const_iterator it = targets.begin(); it != targets.end(); ++it) {
QString t = DU::convertDirSeparators(*it);
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
if (t.contains(DU::convertDirSeparators(DU::getUserHomeDir().canonicalPath().append("\\Sword")))) {
#else
if (t.contains(DU::getUserHomeDir().canonicalPath().append("/.sword"))) {
@@ -217,7 +224,7 @@ QStringList sourceNameList() {
QStringList names;
//add Sword remote sources
- for (InstallSourceMap::iterator it = mgr.sources.begin(); it != mgr.sources.end(); it++) {
+ for (InstallSourceMap::iterator it = mgr.sources.begin(); it != mgr.sources.end(); ++it) {
names << QString::fromLocal8Bit(it->second->caption);
}
@@ -232,7 +239,7 @@ QStringList sourceNameList() {
InstallSource is("DIR", sourceBegin->second.c_str());
names << QString::fromLatin1(is.caption.c_str());
- sourceBegin++;
+ ++sourceBegin;
}
}
@@ -249,7 +256,7 @@ QString swordConfigFilename() {
namespace DU = util::directory;
qDebug() << "Sword config:"
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
<< DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf");
return DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf");
// return DU::getApplicationDir().absolutePath().append("/sword.conf");
@@ -262,27 +269,20 @@ QString swordConfigFilename() {
QDir swordDir() {
namespace DU = util::directory;
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
return QDir(DU::getUserHomeDir().absolutePath().append("/Sword/"));
#else
return QDir(DU::getUserHomeDir().absolutePath().append("/.sword/"));
#endif
}
-CSwordBackend* backend( const sword::InstallSource& is) {
- CSwordBackend* ret = 0;
+CSwordBackend * backend(const sword::InstallSource & is) {
/// \anchor BackendNotSingleton
- if (isRemote(is)) {
- ret = new CSwordBackend( QString(is.localShadow.c_str()), false );
- }
- else {
- ret = new CSwordBackend( QString(is.directory.c_str()), false);
- }
-
- Q_ASSERT(ret);
- if (ret) {
- ret->initModules(CSwordBackend::OtherChange);
- }
+ CSwordBackend * const ret = new CSwordBackend(isRemote(is)
+ ? is.localShadow.c_str()
+ : is.directory.c_str(),
+ false);
+ ret->initModules(CSwordBackend::OtherChange);
return ret;
}