summaryrefslogtreecommitdiff
path: root/src/frontend/bookshelfmanager/btinstallmgr.cpp
blob: 652ff041e6e1f850a0fa41a6bb14cf0ebcb5c5fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2011 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "frontend/bookshelfmanager/btinstallmgr.h"

#include "backend/managers/cswordbackend.h"
#include "backend/btinstallbackend.h"
#include <QList>
#include <QObject>
#include <QString>
#include <QStringList>

// Sword includes:
#include <installmgr.h>
#include <ftptrans.h>


using namespace sword;

BtInstallMgr::BtInstallMgr()
        : InstallMgr(BtInstallBackend::configPath().toLatin1(), this),
        m_totalBytes(1), m_completedBytes(0), m_firstCallOfPreStatus(true)
{ //use this class also as status reporter
    this->setFTPPassive(true);
}

BtInstallMgr::~BtInstallMgr() {
    //doesn't really help because it only sets a flag
    terminate(); //make sure to close the connection
}

bool BtInstallMgr::isUserDisclaimerConfirmed() const {
    // \todo Check from config if it's been confirmed with "don't show this anymore" checked.
    // Create a dialog with the message, checkbox and Continue/Cancel, Cancel as default.
    return true;
}

void BtInstallMgr::statusUpdate(double dltotal, double dlnow) {
    if (dlnow > dltotal)
        dlnow = dltotal;

    int totalPercent = (int)((float)(dlnow + m_completedBytes) / (float)(m_totalBytes) * 100.0);

    if (totalPercent > 100) {
        totalPercent = 100;
    }
    else if (totalPercent < 0) {
        totalPercent = 0;
    }

    int filePercent  = (int)((float)(dlnow) / (float)(dltotal + 1) * 100.0);
    if (filePercent > 100) {
        filePercent = 100;
    }
    else if (filePercent < 0) {
        filePercent = 0;
    }
    //qApp->processEvents();
    emit percentCompleted(totalPercent, filePercent);
}


void BtInstallMgr::preStatus(long totalBytes, long completedBytes, const char* message) {
    if (m_firstCallOfPreStatus) {
        m_firstCallOfPreStatus = false;
        emit downloadStarted();
    }
    m_completedBytes = completedBytes;
    m_totalBytes = (totalBytes > 0) ? totalBytes : 1; //avoid division by zero
}