[storage] Fix dependency
[abstract.git] / view / aaTreeViewTranscript.cpp
blob9117b27a56f5ad8e19257de372b6cf8798d1331f
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 "nsServiceManagerUtils.h"
26 #include "nsStringAPI.h"
27 #include "nsEmbedString.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 "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)
57 /* Helpers */
58 PRBool
59 chooseSide(aaIFact *fact, PRInt64 ownId)
61 if (! fact)
62 return PR_FALSE;
64 if (ownId) {
65 if (fact->PickTakeFrom() && fact->PickTakeFrom()->PickId() == ownId)
66 return PR_FALSE;
67 else
68 return PR_TRUE;
71 if (fact->PickGiveTo() && fact->PickGiveTo()->PickId())
72 return PR_FALSE;
73 return PR_TRUE;
76 nsresult
77 aaTreeViewTranscript::getColumn0(aaITransaction *txn, PRInt64 flowId,
78 PRUint32 flags, nsAString & _retval)
80 if (! txn->PickFact())
81 return NS_OK;
83 assignDate(_retval, txn->PickFact()->PickTime());
84 return NS_OK;
87 nsresult
88 aaTreeViewTranscript::getColumn1(aaITransaction *txn, PRInt64 flowId,
89 PRUint32 flags, nsAString & _retval)
91 if (! txn->PickFact())
92 return NS_OK;
94 aaIFlow *flow = nsnull;
95 if (chooseSide(txn->PickFact(), flowId)) {
96 flow = txn->PickFact()->PickTakeFrom();
97 } else {
98 flow = txn->PickFact()->PickGiveTo();
101 if (flow)
102 flow->GetTag(_retval);
104 return NS_OK;
107 nsresult
108 aaTreeViewTranscript::getColumn2(aaITransaction *txn, PRInt64 flowId,
109 PRUint32 flags, nsAString & _retval)
111 if (! txn->PickFact())
112 return NS_OK;
114 if (flowId) {
115 if (chooseSide(txn->PickFact(), flowId)) {
116 if (flags)
117 assignDouble(_retval, txn->PickValue() + (txn->PickHasEarnings() ?
118 txn->PickEarnings() : 0.0));
119 else
120 assignDouble(_retval, txn->PickFact()->PickAmount());
122 } else if (txn->PickEarnings() < 0.0) {
123 assignDouble(_retval, -txn->PickEarnings());
126 return NS_OK;
129 nsresult
130 aaTreeViewTranscript::getColumn3(aaITransaction *txn, PRInt64 flowId,
131 PRUint32 flags, nsAString & _retval)
133 if (! txn->PickFact())
134 return NS_OK;
136 if (flowId) {
137 if (! chooseSide(txn->PickFact(), flowId)) {
138 if (flags)
139 assignDouble(_retval, txn->PickValue());
140 else
141 assignDouble(_retval, txn->PickFact()->PickAmount());
143 } else if (txn->PickEarnings() > 0.0) {
144 assignDouble(_retval, txn->PickEarnings());
147 return NS_OK;
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 */
160 nsresult
161 aaTreeViewTranscript::doGetCellText(PRInt32 row, nsITreeColumn *col,
162 nsAString & _retval)
164 nsresult rv;
165 _retval.Truncate();
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())
178 return NS_OK;
179 return colFuncs[ci](txn,transcript->PickLoadedFlow()->PickId(), mFlags,
180 _retval);