~vcs-imports/bibletime/trunk

« back to all changes in this revision

Viewing changes to bibletime/backend/cswordbookmoduleinfo.cpp

  • Committer: mgruner
  • Date: 2007-05-08 15:51:07 UTC
  • Revision ID: vcs-imports@canonical.com-20070508155107-0rj7jdmm5ivf8685
-imported source and data files to new svn module
-this is where KDE4-based development will take place

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
//BibleTime includes
 
13
#include "cswordbookmoduleinfo.h"
 
14
#include "cswordtreekey.h"
 
15
 
 
16
//Sword includes
 
17
#include <treekeyidx.h>
 
18
#include <treekey.h>
 
19
 
 
20
#include <iostream>
 
21
#include <string>
 
22
using std::cout;
 
23
using std::endl;
 
24
 
 
25
CSwordBookModuleInfo::CSwordBookModuleInfo( sword::SWModule* module, CSwordBackend* const usedBackend )
 
26
: CSwordModuleInfo(module, usedBackend),
 
27
m_depth(-1) {}
 
28
 
 
29
CSwordBookModuleInfo::CSwordBookModuleInfo( const CSwordBookModuleInfo& module )
 
30
: CSwordModuleInfo(module) {
 
31
        m_depth = module.m_depth;
 
32
}
 
33
 
 
34
CSwordBookModuleInfo::~CSwordBookModuleInfo() {}
 
35
 
 
36
const int CSwordBookModuleInfo::depth() {
 
37
        if (m_depth == -1) {
 
38
                sword::TreeKeyIdx* key = tree();
 
39
 
 
40
                if (key) {
 
41
                        key->root();
 
42
                        computeDepth(key, 0);
 
43
                }
 
44
        }
 
45
 
 
46
        return m_depth;
 
47
}
 
48
 
 
49
void CSwordBookModuleInfo::computeDepth(sword::TreeKeyIdx* key, int level ) {
 
50
        std::string savedKey;
 
51
        //      savedKey = key->getFullName(); //sword 1.5.8
 
52
        savedKey = key->getText();
 
53
 
 
54
        if (level > m_depth) {
 
55
                m_depth = level;
 
56
        }
 
57
 
 
58
        if (key->hasChildren()) {
 
59
                key->firstChild();
 
60
                computeDepth(key, level+1);
 
61
 
 
62
                key->setText( savedKey.c_str() );//return to the initial value
 
63
        }
 
64
 
 
65
        if (key->nextSibling()) {
 
66
                computeDepth(key, level);
 
67
        }
 
68
}
 
69
 
 
70
/** Returns a treekey filled with the structure of this module */
 
71
sword::TreeKeyIdx* const  CSwordBookModuleInfo::tree() const {
 
72
        sword::TreeKeyIdx* treeKey = dynamic_cast<sword::TreeKeyIdx*>((sword::SWKey*)*(module()));
 
73
        Q_ASSERT(treeKey);
 
74
        return treeKey;
 
75
}