[accounting] Add 'load chart' query (bug 86)
[abstract.git] / base / aaFact.cpp
blobd7cb04a19ebfc6d2054c59419706b32a77917501
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 "nsEmbedString.h"
27 #include "nsIObserverService.h"
29 /* Project includes */
30 #include "aaIFlow.h"
31 #include "aaIResource.h"
32 #include "aaIEvent.h"
33 #include "aaIHandler.h"
34 #include "aaFact.h"
36 aaFact::aaFact()
37 :mHasEvent(PR_FALSE), mAmount(0.0), mBroadcasting(PR_FALSE)
41 aaFact::~aaFact()
45 NS_IMPL_ISUPPORTS2(aaFact,
46 aaIDataNode,
47 aaIFact)
49 /* aaIDataNode */
50 NS_IMETHODIMP
51 aaFact::GetId(PRInt64 *aId)
53 NS_ENSURE_ARG_POINTER(aId);
54 *aId = mId;
55 return NS_OK;
57 NS_IMETHODIMP
58 aaFact::SetId(PRInt64 aId)
60 mId = aId;
61 return NS_OK;
64 NS_IMETHODIMP
65 aaFact::Accept(aaIHandler* aQuery)
67 NS_ENSURE_ARG_POINTER(aQuery);
68 return aQuery->HandleFact(this);
71 NS_IMETHODIMP
72 aaFact::GetEdited(PRBool* aEdited)
74 NS_ENSURE_ARG_POINTER(aEdited);
75 *aEdited = PR_FALSE;
76 return NS_OK;
80 /* aaIFact */
81 NS_IMETHODIMP
82 aaFact::GetEventId(PRInt64 *aEventId)
84 NS_ENSURE_ARG_POINTER( aEventId );
85 if (NS_UNLIKELY( !mHasEvent ))
86 return NS_ERROR_NOT_INITIALIZED;
87 *aEventId = mEventId;
88 return NS_OK;
91 NS_IMETHODIMP
92 aaFact::GetTime(PRTime *aTime)
94 NS_ENSURE_ARG_POINTER( aTime );
95 if (NS_UNLIKELY( !mHasEvent ))
96 return NS_ERROR_NOT_INITIALIZED;
97 *aTime = mTime;
98 return NS_OK;
100 PRTime
101 aaFact::PickTime()
103 return mTime;
106 NS_IMETHODIMP
107 aaFact::SetEvent(aaIEvent *aEvent)
109 if (NS_UNLIKELY( ! aEvent )) {
110 mHasEvent = PR_FALSE;
111 return NS_OK;
113 aEvent->GetId( &mEventId );
114 aEvent->GetTime( &mTime );
115 mHasEvent = PR_TRUE;
116 return NS_OK;
119 NS_IMETHODIMP
120 aaFact::GetTakeFrom(aaIFlow * *aTakeFrom)
122 NS_ENSURE_ARG_POINTER( aTakeFrom );
123 NS_IF_ADDREF( *aTakeFrom = mTakeFrom );
124 return NS_OK;
126 NS_IMETHODIMP
127 aaFact::SetTakeFrom(aaIFlow *aTakeFrom)
129 mTakeFrom = aTakeFrom;
130 if (! mBroadcasting)
131 return NS_OK;
132 nsCOMPtr<nsIObserverService> broadcaster = do_GetService(
133 "@mozilla.org/observer-service;1");
134 NS_ENSURE_TRUE(broadcaster, NS_OK);
135 broadcaster->NotifyObservers(this, "fact-from-flow-change", nsnull);
136 return NS_OK;
138 aaIFlow *
139 aaFact::PickTakeFrom()
141 return mTakeFrom;
144 NS_IMETHODIMP
145 aaFact::GetGiveTo(aaIFlow * *aGiveTo)
147 NS_ENSURE_ARG_POINTER( aGiveTo );
148 NS_IF_ADDREF( *aGiveTo = mGiveTo );
149 return NS_OK;
151 NS_IMETHODIMP
152 aaFact::SetGiveTo(aaIFlow *aGiveTo)
154 mGiveTo = aGiveTo;
155 if (! mBroadcasting)
156 return NS_OK;
157 nsCOMPtr<nsIObserverService> broadcaster = do_GetService(
158 "@mozilla.org/observer-service;1");
159 NS_ENSURE_TRUE(broadcaster, NS_OK);
160 broadcaster->NotifyObservers(this, "fact-to-flow-change", nsnull);
161 return NS_OK;
163 aaIFlow *
164 aaFact::PickGiveTo()
166 return mGiveTo;
169 NS_IMETHODIMP
170 aaFact::GetAmount(double *aAmount)
172 NS_ENSURE_ARG_POINTER( aAmount );
173 *aAmount = mAmount;
174 return NS_OK;
176 NS_IMETHODIMP
177 aaFact::SetAmount(double aAmount)
179 mAmount = aAmount;
180 return NS_OK;
183 double
184 aaFact::PickAmount()
186 return mAmount;
189 NS_IMETHODIMP
190 aaFact::GetBroadcasting(PRBool *aBroadcasting)
192 NS_ENSURE_ARG_POINTER(aBroadcasting);
193 *aBroadcasting = mBroadcasting;
194 return NS_OK;
196 NS_IMETHODIMP
197 aaFact::SetBroadcasting(PRBool aBroadcasting)
199 mBroadcasting = aBroadcasting;
200 return NS_OK;