transport: empty test for sqlite converter
[abstract.git] / view / aaTreeViewTranscript.cpp
blob03bdf3453b59bf5bca93aabf4177626446d36b87
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
24 #include "nsCOMPtr.h"
25 #include "nsComponentManagerUtils.h"
26 #include "nsServiceManagerUtils.h"
27 #include "nsStringAPI.h"
29 /* Unfrozen API */
30 #include "nsIArray.h"
31 #include "nsArrayUtils.h"
32 #include "nsITreeColumns.h"
33 #include "nsIAtom.h"
34 #include "nsIAtomService.h"
36 /* Project includes */
37 #include "aaIEntity.h"
38 #include "aaIFlow.h"
39 #include "aaIResource.h"
40 #include "aaIFact.h"
41 #include "aaIBalance.h"
42 #include "aaITransaction.h"
43 #include "aaISqlTransaction.h"
44 #include "aaITranscript.h"
45 #include "aaReportKeys.h"
46 #include "aaViewUtils.h"
47 #include "aaTreeViewTranscript.h"
49 aaTreeViewTranscript::aaTreeViewTranscript()
51 mComplexLoader = do_CreateInstance(AA_TRANSCRIPT_CONTRACT);
54 aaTreeViewTranscript::~aaTreeViewTranscript()
58 NS_IMPL_ISUPPORTS_INHERITED0(aaTreeViewTranscript, aaTreeView)
60 /* Helpers */
61 PRBool
62 chooseSide(aaIFact *fact, PRInt64 ownId)
64 if (! fact)
65 return PR_FALSE;
67 if (ownId) {
68 if (fact->PickTakeFrom() && fact->PickTakeFrom()->PickId() == ownId)
69 return PR_FALSE;
70 else
71 return PR_TRUE;
74 if (fact->PickGiveTo() && fact->PickGiveTo()->PickId())
75 return PR_FALSE;
76 return PR_TRUE;
79 nsresult
80 aaTreeViewTranscript::getColumn0(aaITransaction *txn, PRInt64 flowId,
81 PRUint32 flags, nsAString & _retval)
83 if (! txn->PickFact())
84 return NS_OK;
86 assignDate(_retval, txn->PickFact()->PickTime());
87 return NS_OK;
90 nsresult
91 aaTreeViewTranscript::getColumn1(aaITransaction *txn, PRInt64 flowId,
92 PRUint32 flags, nsAString & _retval)
94 if (! txn->PickFact())
95 return NS_OK;
97 aaIFlow *flow = nsnull;
98 if (chooseSide(txn->PickFact(), flowId)) {
99 flow = txn->PickFact()->PickTakeFrom();
100 } else {
101 flow = txn->PickFact()->PickGiveTo();
104 if (flow)
105 flow->GetTag(_retval);
107 return NS_OK;
110 nsresult
111 aaTreeViewTranscript::getColumn2(aaITransaction *txn, PRInt64 flowId,
112 PRUint32 flags, nsAString & _retval)
114 if (! txn->PickFact())
115 return NS_OK;
117 if (flowId) {
118 if (chooseSide(txn->PickFact(), flowId)) {
119 if (flags)
120 assignDouble(_retval, txn->PickValue() + (txn->PickHasEarnings() ?
121 txn->PickEarnings() : 0.0));
122 else
123 assignDouble(_retval, txn->PickFact()->PickAmount());
125 } else if (txn->PickEarnings() < 0.0) {
126 assignDouble(_retval, -txn->PickEarnings());
129 return NS_OK;
132 nsresult
133 aaTreeViewTranscript::getColumn3(aaITransaction *txn, PRInt64 flowId,
134 PRUint32 flags, nsAString & _retval)
136 if (! txn->PickFact())
137 return NS_OK;
139 if (flowId) {
140 if (! chooseSide(txn->PickFact(), flowId)) {
141 if (flags)
142 assignDouble(_retval, txn->PickValue());
143 else
144 assignDouble(_retval, txn->PickFact()->PickAmount());
146 } else if (txn->PickEarnings() > 0.0) {
147 assignDouble(_retval, txn->PickEarnings());
150 return NS_OK;
153 nsresult (*const aaTreeViewTranscript::colFuncs[])(aaITransaction *,
154 PRInt64 flowId, PRUint32 flags, nsAString &) =
156 &aaTreeViewTranscript::getColumn0
157 ,&aaTreeViewTranscript::getColumn1
158 ,&aaTreeViewTranscript::getColumn2
159 ,&aaTreeViewTranscript::getColumn3
162 /* Private functions */
163 nsresult
164 aaTreeViewTranscript::doGetCellText(PRInt32 row, nsITreeColumn *col,
165 nsAString & _retval)
167 nsresult rv;
168 _retval.Truncate();
170 PRInt32 ci = getColumnIndex(col, sizeof(colFuncs));
171 NS_ENSURE_TRUE(ci >= 0, NS_OK);
173 nsCOMPtr<aaITransaction> txn(do_QueryElementAt(mDataSet, row, &rv));
174 NS_ENSURE_SUCCESS(rv, rv);
175 NS_ENSURE_TRUE(txn, NS_OK);
177 nsCOMPtr<aaITranscript> transcript(do_QueryInterface(mDataSet, &rv));
178 NS_ENSURE_SUCCESS(rv, rv);
180 nsCOMPtr<aaIFlow> flow;
181 rv = transcript->GetFlow(getter_AddRefs(flow));
182 NS_ENSURE_TRUE(flow, rv);
184 if (!flow)
185 return NS_OK;
186 return colFuncs[ci](txn,flow->PickId(), mFlags, _retval);