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) 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"
25 #include "nsStringAPI.h"
26 #include "nsIMutableArray.h"
27 #include "nsCOMArray.h"
29 /* Project includes */
32 #include "aaIHandler.h"
33 #include "aaIStorager.h"
35 #include "aaEventBase.h"
39 aaEventBase::aaEventBase(aaEvent
*aParent
)
40 :mParent(aParent
), mId(0), mTag((const PRUnichar
*) nsnull
),
41 mHasTime(PR_FALSE
), mRead(PR_FALSE
), mEdited(PR_FALSE
)
45 aaEventBase::~aaEventBase()
49 NS_IMPL_ISUPPORTS5(aaEventBase
,
57 aaEventBase::GetId(PRInt64
*aId
)
59 NS_ENSURE_ARG_POINTER(aId
);
64 aaEventBase::SetId(PRInt64 aId
)
76 aaEventBase::Accept(aaIHandler
* aQuery
)
78 NS_ENSURE_ARG_POINTER(aQuery
);
80 rv
= aQuery
->HandleEvent(this);
81 if (NS_FAILED(rv
)) return rv
;
84 for (i
= 0; i
< mFacts
.Count(); i
++) {
85 rv
= mFacts
[i
]->Accept(aQuery
);
86 NS_ENSURE_SUCCESS(rv
, rv
);
93 aaEventBase::GetEdited(PRBool
* aEdited
)
95 NS_ENSURE_ARG_POINTER(aEdited
);
101 aaEventBase::Sync(aaIStorager
*aStorager
, aaISqliteChannel
*aChannel
)
105 rv
= aStorager
->Delete(aChannel
);
106 NS_ENSURE_SUCCESS(rv
, rv
);
109 rv
= aStorager
->Insert(aChannel
);
110 if (NS_FAILED(rv
)) return rv
;
118 aaEventBase::GetTag(nsAString
& aTag
)
125 aaEventBase::SetTag(const nsAString
& aTag
)
127 if (mTag
.Equals(aTag
))
136 aaEventBase::GetTime(PRTime
*aTime
)
138 NS_ENSURE_TRUE( mHasTime
, NS_ERROR_NOT_INITIALIZED
);
139 NS_ENSURE_ARG_POINTER( aTime
);
144 aaEventBase::SetTime(PRTime aTime
)
147 PR_ExplodeTime(aTime
, &PR_LocalTimeParameters
, &tm
);
148 tm
.tm_params
.tp_gmt_offset
= 0;
149 tm
.tm_params
.tp_dst_offset
= 0;
154 mTime
= PR_ImplodeTime(&tm
);
161 aaEventBase::GetLength(PRUint32
*aLength
)
163 NS_ENSURE_ARG_POINTER( aLength
);
164 *aLength
= mFacts
.Count();
169 aaEventBase::QueryElementAt(PRUint32 index
, const nsIID
& uuid
, void * *result
)
171 NS_ENSURE_TRUE( index
< (PRUint32
) mFacts
.Count(), NS_ERROR_INVALID_ARG
);
172 NS_ENSURE_ARG_POINTER( result
);
173 return mFacts
[index
]->QueryInterface(uuid
, result
);
177 aaEventBase::IndexOf(PRUint32 startIndex
, nsISupports
*element
, PRUint32
*_retval
)
179 return NS_ERROR_NOT_IMPLEMENTED
;
183 aaEventBase::Enumerate(nsISimpleEnumerator
**_retval
)
185 return NS_ERROR_NOT_IMPLEMENTED
;
188 /* nsIMutableArray */
190 aaEventBase::AppendElement(nsISupports
*element
, PRBool weak
)
192 NS_ENSURE_TRUE(!weak
, NS_ERROR_NOT_IMPLEMENTED
);
193 nsCOMPtr
<aaIFact
> fact
= do_QueryInterface(element
);
194 NS_ENSURE_TRUE(fact
, NS_ERROR_INVALID_ARG
);
197 rv
= fact
->SetEvent(mParent
);
198 NS_ENSURE_SUCCESS(rv
, rv
);
200 PRBool res
= mFacts
.AppendObject(fact
);
201 NS_ENSURE_TRUE(res
, NS_ERROR_FAILURE
);
207 aaEventBase::RemoveElementAt(PRUint32 index
)
209 return NS_ERROR_NOT_IMPLEMENTED
;
213 aaEventBase::InsertElementAt(nsISupports
*element
, PRUint32 index
, PRBool weak
)
215 return NS_ERROR_NOT_IMPLEMENTED
;
219 aaEventBase::ReplaceElementAt(nsISupports
*element
, PRUint32 index
, PRBool weak
)
221 return NS_ERROR_NOT_IMPLEMENTED
;