transport: empty test for sqlite converter
[abstract.git] / view / aaTreeViewQuote.cpp
bloba1e551774434af87b5e1673593d54ef95590f3fd
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) 2008 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"
28 #include "nsTextFormatter.h"
30 /* Unfrozen API */
31 #include "nsIArray.h"
32 #include "nsArrayUtils.h"
33 #include "nsITreeColumns.h"
34 #include "nsIAtom.h"
35 #include "nsIAtomService.h"
37 /* Project includes */
38 #include "aaIResource.h"
39 #include "aaIQuote.h"
40 #include "aaISqlRequest.h"
41 #include "aaAccountLoaders.h"
42 #include "aaViewUtils.h"
43 #include "aaTreeViewQuote.h"
45 aaTreeViewQuote::aaTreeViewQuote()
47 mDataLoader = do_CreateInstance(AA_LOADQUOTE_CONTRACT);
50 aaTreeViewQuote::~aaTreeViewQuote()
54 NS_IMPL_ISUPPORTS_INHERITED0(aaTreeViewQuote, aaTreeView)
56 /* Helpers */
57 nsresult
58 aaTreeViewQuote::getColumn0(aaIQuote *quote, PRUint32 flags,
59 nsAString & _retval)
61 nsresult rv;
63 nsCOMPtr<aaIResource> resource;
64 rv = quote->GetResource(getter_AddRefs(resource));
65 NS_ENSURE_TRUE(resource, NS_OK);
67 return resource->GetTag(_retval);
70 nsresult
71 aaTreeViewQuote::getColumn1(aaIQuote *quote, PRUint32 flags,
72 nsAString & _retval)
74 NS_ENSURE_TRUE(quote, NS_OK);
76 assignDate(_retval, quote->PickTime());
77 return NS_OK;
80 nsresult
81 aaTreeViewQuote::getColumn2(aaIQuote *quote, PRUint32 flags,
82 nsAString & _retval)
84 NS_ENSURE_TRUE(quote, NS_OK);
86 assignSignificantDouble(_retval, quote->PickRate());
87 return NS_OK;
90 nsresult (*const
91 aaTreeViewQuote::colFuncs[])(aaIQuote *, PRUint32 flags,
92 nsAString &) = {
93 &aaTreeViewQuote::getColumn0,
94 &aaTreeViewQuote::getColumn1,
95 &aaTreeViewQuote::getColumn2
98 /* Private functions */
99 nsresult
100 aaTreeViewQuote::doGetCellText(PRInt32 row, nsITreeColumn *col,
101 nsAString & _retval)
103 nsresult rv;
104 _retval.Truncate();
106 PRInt32 ci = getColumnIndex(col, sizeof(colFuncs));
107 NS_ENSURE_TRUE(ci >= 0, NS_OK);
109 nsCOMPtr<aaIQuote> quote(do_QueryElementAt(mDataSet, row, &rv));
110 NS_ENSURE_SUCCESS(rv, rv);
111 NS_ENSURE_TRUE(quote, NS_OK);
113 return colFuncs[ci](quote, mFlags, _retval);
116 NS_IMETHODIMP
117 aaTreeViewQuote::convertSortColumnToString(nsITreeColumn* col, nsACString& name)
119 nsresult rc = NS_OK;
120 PRInt32 idx = -1;
122 NS_ENSURE_ARG_POINTER(col);
124 name.Truncate();
126 rc = col->GetIndex(&idx);
127 NS_ENSURE_SUCCESS(rc, rc);
129 switch (idx) {
130 case 0:
131 name = NS_LITERAL_CSTRING("quote.tag");
132 break;
133 case 1:
134 name = NS_LITERAL_CSTRING("quote.date");
135 break;
136 case 2:
137 name = NS_LITERAL_CSTRING("quote.rate");
138 break;
139 default:
140 name.Truncate();
141 return NS_ERROR_INVALID_ARG;
144 return rc;