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 "nsServiceManagerUtils.h"
26 #include "nsStringAPI.h"
27 #include "nsEmbedString.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 "aaITransaction.h"
42 #include "aaILoadQuery.h"
43 #include "aaITranscript.h"
44 #include "aaViewUtils.h"
45 #include "aaTreeViewTranscript.h"
47 aaTreeViewTranscript::aaTreeViewTranscript()
51 aaTreeViewTranscript::~aaTreeViewTranscript()
55 NS_IMPL_ISUPPORTS_INHERITED0(aaTreeViewTranscript
, aaTreeView
)
59 chooseSide(aaIFact
*fact
, PRInt64 ownId
)
65 if (fact
->PickTakeFrom() && fact
->PickTakeFrom()->PickId() == ownId
)
71 if (fact
->PickGiveTo() && fact
->PickGiveTo()->PickId())
77 aaTreeViewTranscript::getColumn0(aaITransaction
*txn
, PRInt64 flowId
,
78 PRUint32 flags
, nsAString
& _retval
)
80 if (! txn
->PickFact())
83 assignDate(_retval
, txn
->PickFact()->PickTime());
88 aaTreeViewTranscript::getColumn1(aaITransaction
*txn
, PRInt64 flowId
,
89 PRUint32 flags
, nsAString
& _retval
)
91 if (! txn
->PickFact())
94 aaIFlow
*flow
= nsnull
;
95 if (chooseSide(txn
->PickFact(), flowId
)) {
96 flow
= txn
->PickFact()->PickTakeFrom();
98 flow
= txn
->PickFact()->PickGiveTo();
102 flow
->GetTag(_retval
);
108 aaTreeViewTranscript::getColumn2(aaITransaction
*txn
, PRInt64 flowId
,
109 PRUint32 flags
, nsAString
& _retval
)
111 if (! txn
->PickFact())
115 if (chooseSide(txn
->PickFact(), flowId
)) {
117 assignDouble(_retval
, txn
->PickValue() + (txn
->PickHasEarnings() ?
118 txn
->PickEarnings() : 0.0));
120 assignDouble(_retval
, txn
->PickFact()->PickAmount());
122 } else if (txn
->PickEarnings() < 0.0) {
123 assignDouble(_retval
, -txn
->PickEarnings());
130 aaTreeViewTranscript::getColumn3(aaITransaction
*txn
, PRInt64 flowId
,
131 PRUint32 flags
, nsAString
& _retval
)
133 if (! txn
->PickFact())
137 if (! chooseSide(txn
->PickFact(), flowId
)) {
139 assignDouble(_retval
, txn
->PickValue());
141 assignDouble(_retval
, txn
->PickFact()->PickAmount());
143 } else if (txn
->PickEarnings() > 0.0) {
144 assignDouble(_retval
, txn
->PickEarnings());
150 nsresult (*const aaTreeViewTranscript::colFuncs
[])(aaITransaction
*,
151 PRInt64 flowId
, PRUint32 flags
, nsAString
&) =
153 &aaTreeViewTranscript::getColumn0
154 ,&aaTreeViewTranscript::getColumn1
155 ,&aaTreeViewTranscript::getColumn2
156 ,&aaTreeViewTranscript::getColumn3
159 /* Private functions */
161 aaTreeViewTranscript::doGetCellText(PRInt32 row
, nsITreeColumn
*col
,
167 PRInt32 ci
= getColumnIndex(col
, sizeof(colFuncs
));
168 NS_ENSURE_TRUE(ci
>= 0, NS_OK
);
170 nsCOMPtr
<aaITransaction
> txn(do_QueryElementAt(mDataSet
, row
, &rv
));
171 NS_ENSURE_SUCCESS(rv
, rv
);
172 NS_ENSURE_TRUE(txn
, NS_OK
);
174 nsCOMPtr
<aaITranscript
> transcript(do_QueryInterface(mDataSet
, &rv
));
175 NS_ENSURE_SUCCESS(rv
, rv
);
177 if (! transcript
->PickLoadedFlow())
179 return colFuncs
[ci
](txn
,transcript
->PickLoadedFlow()->PickId(), mFlags
,