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: */
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"
25 #include "nsComponentManagerUtils.h"
26 #include "nsServiceManagerUtils.h"
27 #include "nsStringAPI.h"
31 #include "nsArrayUtils.h"
32 #include "nsITreeColumns.h"
34 #include "nsIAtomService.h"
36 /* Project includes */
37 #include "aaIEntity.h"
39 #include "aaIResource.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
)
62 chooseSide(aaIFact
*fact
, PRInt64 ownId
)
68 if (fact
->PickTakeFrom() && fact
->PickTakeFrom()->PickId() == ownId
)
74 if (fact
->PickGiveTo() && fact
->PickGiveTo()->PickId())
80 aaTreeViewTranscript::getColumn0(aaITransaction
*txn
, PRInt64 flowId
,
81 PRUint32 flags
, nsAString
& _retval
)
83 if (! txn
->PickFact())
86 assignDate(_retval
, txn
->PickFact()->PickTime());
91 aaTreeViewTranscript::getColumn1(aaITransaction
*txn
, PRInt64 flowId
,
92 PRUint32 flags
, nsAString
& _retval
)
94 if (! txn
->PickFact())
97 aaIFlow
*flow
= nsnull
;
98 if (chooseSide(txn
->PickFact(), flowId
)) {
99 flow
= txn
->PickFact()->PickTakeFrom();
101 flow
= txn
->PickFact()->PickGiveTo();
105 flow
->GetTag(_retval
);
111 aaTreeViewTranscript::getColumn2(aaITransaction
*txn
, PRInt64 flowId
,
112 PRUint32 flags
, nsAString
& _retval
)
114 if (! txn
->PickFact())
118 if (chooseSide(txn
->PickFact(), flowId
)) {
120 assignDouble(_retval
, txn
->PickValue() + (txn
->PickHasEarnings() ?
121 txn
->PickEarnings() : 0.0));
123 assignDouble(_retval
, txn
->PickFact()->PickAmount());
125 } else if (txn
->PickEarnings() < 0.0) {
126 assignDouble(_retval
, -txn
->PickEarnings());
133 aaTreeViewTranscript::getColumn3(aaITransaction
*txn
, PRInt64 flowId
,
134 PRUint32 flags
, nsAString
& _retval
)
136 if (! txn
->PickFact())
140 if (! chooseSide(txn
->PickFact(), flowId
)) {
142 assignDouble(_retval
, txn
->PickValue());
144 assignDouble(_retval
, txn
->PickFact()->PickAmount());
146 } else if (txn
->PickEarnings() > 0.0) {
147 assignDouble(_retval
, txn
->PickEarnings());
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 */
164 aaTreeViewTranscript::doGetCellText(PRInt32 row
, nsITreeColumn
*col
,
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
);
186 return colFuncs
[ci
](txn
,flow
->PickId(), mFlags
, _retval
);