Rev 254 | Rev 278 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
178 | werner | 2 | /** @class OutputManager |
3 | Global container that handles data output. |
||
4 | |||
5 | */ |
||
6 | |||
173 | werner | 7 | #include "global.h" |
8 | #include "outputmanager.h" |
||
223 | werner | 9 | #include "helper.h" |
173 | werner | 10 | #include <QtCore> |
11 | |||
12 | // tree outputs |
||
13 | #include "treeout.h" |
||
179 | werner | 14 | #include "standout.h" |
262 | werner | 15 | #include "standdeadout.h" |
184 | werner | 16 | #include "dynamicstandout.h" |
228 | werner | 17 | #include "productionout.h" |
173 | werner | 18 | |
178 | werner | 19 | |
20 | |||
173 | werner | 21 | OutputManager::OutputManager() |
22 | { |
||
231 | werner | 23 | mTransactionOpen = false; |
173 | werner | 24 | // add all the outputs |
25 | mOutputs.append(new TreeOut); |
||
179 | werner | 26 | mOutputs.append(new StandOut); |
184 | werner | 27 | mOutputs.append(new DynamicStandOut); |
228 | werner | 28 | mOutputs.append(new ProductionOut); |
262 | werner | 29 | mOutputs.append(new StandDeadOut); |
184 | werner | 30 | |
173 | werner | 31 | } |
32 | |||
33 | OutputManager::~OutputManager() |
||
34 | { |
||
35 | qDeleteAll(mOutputs); |
||
36 | } |
||
37 | |||
38 | void OutputManager::setup() |
||
39 | { |
||
232 | werner | 40 | close(); |
173 | werner | 41 | XmlHelper &xml = const_cast<XmlHelper&>(GlobalSettings::instance()->settings()); |
42 | QString nodepath; |
||
43 | foreach(Output *o, mOutputs) { |
||
176 | werner | 44 | nodepath = QString("output.%1").arg(o->tableName()); |
173 | werner | 45 | xml.setCurrentNode(nodepath); |
46 | qDebug() << "setup of output" << o->name(); |
||
47 | o->setup(); |
||
181 | werner | 48 | bool enabled = xml.valueBool(".enabled", false); |
49 | o->setEnabled(enabled); |
||
50 | if (enabled) |
||
51 | o->open(); |
||
173 | werner | 52 | } |
231 | werner | 53 | endTransaction(); // just to be sur |
173 | werner | 54 | } |
176 | werner | 55 | |
56 | Output *OutputManager::find(const QString& tableName) |
||
57 | { |
||
58 | foreach(Output* p,mOutputs) |
||
59 | if (p->tableName()==tableName) |
||
60 | return p; |
||
61 | return NULL; |
||
62 | } |
||
63 | |||
222 | werner | 64 | void OutputManager::save() |
65 | { |
||
231 | werner | 66 | endTransaction(); |
222 | werner | 67 | } |
68 | |||
232 | werner | 69 | void OutputManager::close() |
70 | { |
||
71 | qDebug() << "outputs closed"; |
||
72 | foreach(Output *p, mOutputs) |
||
73 | p->close(); |
||
74 | } |
||
75 | |||
231 | werner | 76 | void OutputManager::startTransaction() |
77 | { |
||
78 | if (!mTransactionOpen && GlobalSettings::instance()->dbout().isValid()) { |
||
232 | werner | 79 | if (GlobalSettings::instance()->dbout().transaction()) { |
80 | qDebug() << "opening transaction"; |
||
81 | mTransactionOpen = true; |
||
82 | } |
||
231 | werner | 83 | } |
84 | } |
||
85 | void OutputManager::endTransaction() |
||
86 | { |
||
87 | if (mTransactionOpen && GlobalSettings::instance()->dbout().isValid()) { |
||
232 | werner | 88 | if (GlobalSettings::instance()->dbout().commit()) { |
89 | mTransactionOpen = false; |
||
90 | qDebug() << "database transaction commited"; |
||
91 | } |
||
92 | } |
||
231 | werner | 93 | } |
94 | |||
176 | werner | 95 | bool OutputManager::execute(const QString& tableName) |
96 | { |
||
223 | werner | 97 | DebugTimer t("OutputManager::execute()"); |
225 | werner | 98 | t.setSilent(); |
176 | werner | 99 | Output *p = find(tableName); |
100 | if (p) { |
||
182 | werner | 101 | if (!p->isEnabled()) |
102 | return false; |
||
103 | if(!p->isOpen()) |
||
104 | return false; |
||
207 | werner | 105 | if (!p->onNewRow()) { |
106 | qWarning() << "Output" << p->name() << "invalid (not at new row)!!!"; |
||
107 | return false; |
||
108 | } |
||
109 | |||
231 | werner | 110 | startTransaction(); // just assure a transaction is open.... nothing happens if already inside a transaction |
176 | werner | 111 | p->exec(); |
222 | werner | 112 | |
176 | werner | 113 | return true; |
114 | } |
||
115 | qDebug() << "output" << tableName << "not found!"; |
||
116 | return false; // no output found |
||
117 | } |
||
254 | werner | 118 | |
119 | QString OutputManager::wikiFormat() |
||
120 | { |
||
121 | QString result; |
||
122 | foreach(const Output *o, mOutputs) |
||
123 | result+=o->wikiFormat() + "\n\n"; |
||
124 | return result; |
||
125 | } |