Added RemoveObserver() and fixed GetNextNEvents()

This commit is contained in:
mostafah%oeone.com 2002-04-17 22:03:27 +00:00
Родитель 66636a9ed7
Коммит ec7d5ef34c
5 изменённых файлов: 53 добавлений и 22 удалений

Просмотреть файл

@ -38,32 +38,18 @@
#include <oeIICal.h>
#include <oeICalImpl.h>
#include <nsIServiceManager.h>
#include "nsIComponentRegistrar.h"
main()
{
nsresult rv;
char buf[80];
// Initialize XPCOM
rv = NS_InitXPCOM(nsnull, nsnull);
if (NS_FAILED(rv))
{
printf("ERROR: XPCOM intialization error [%x].\n", rv);
return -1;
}
// Do Autoreg to make sure our component is registered. The real way of
// doing this is running the xpcom registraion tool, regxpcom, at install
// time to get components registered and not make this call everytime.
// Ignore return value.
//
// Here we use the global component manager. Note that this will cause
// linkage dependency to XPCOM library. We feel that linkage dependency
// to XPCOM is inevitable and this is simpler to code.
// To break free from such dependencies, we can GetService() the component
// manager from the service manager that is returned from NS_InitXPCOM().
// We feel that linkage dependency to XPCOM library is inevitable.
(void) nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);
nsCOMPtr<nsIServiceManager> servMan;
NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
registrar->AutoRegister(nsnull);
// Create an instance of our component
nsCOMPtr<oeIICal> mysample = do_CreateInstance(OE_ICAL_CONTRACTID, &rv);

Просмотреть файл

@ -85,6 +85,7 @@ public:
icalcomponent *AsIcalComponent();
icaltimetype GetNextAlarmTime( icaltimetype begin );
bool matchId( const char *id );
icaltimetype GetNextRecurrence( icaltimetype begin );
private:
char *m_id;
char *m_syncid;
@ -112,7 +113,6 @@ private:
icaltimetype m_lastalarmack;
std::vector<PRTime> m_exceptiondates;
std::vector<PRTime> m_snoozetimes;
icaltimetype GetNextRecurrence( icaltimetype begin );
icaltimetype CalculateAlarmTime( icaltimetype date );
bool IsExcepted( PRTime date );
};

Просмотреть файл

@ -248,6 +248,7 @@ oeICalImpl::~oeICalImpl()
for( unsigned int i=0; i<m_observerlist.size(); i++ ) {
m_observerlist[i]->Release();
}
m_observerlist.clear();
if( m_alarmtimer ) {
if ( m_alarmtimer->GetDelay() != 0 )
m_alarmtimer->Cancel();
@ -1170,10 +1171,30 @@ oeICalImpl::GetEventsForRange( PRTime checkdateinms, PRTime checkenddateinms, ns
return NS_OK;
}
icaltimetype oeICalImpl::GetNextEvent( icaltimetype starting ) {
#ifdef ICAL_DEBUG_ALL
printf( "oeICalImpl::GetNextEvent()\n" );
#endif
icaltimetype soonest = icaltime_null_time();
EventList *tmplistptr = &m_eventlist;
while( tmplistptr ) {
if( tmplistptr->event ) {
oeIICalEvent* tmpevent = tmplistptr->event;
icaltimetype next = ((oeICalEventImpl *)tmpevent)->GetNextRecurrence( starting );
if( !icaltime_is_null_time( next ) && ( icaltime_is_null_time( soonest ) || (icaltime_compare( soonest, next ) > 0) ) ) {
soonest = next;
}
}
tmplistptr = tmplistptr->next;
}
return soonest;
}
NS_IMETHODIMP
oeICalImpl::GetNextNEvents( PRTime datems, PRInt32 maxcount, nsISimpleEnumerator **datelist, nsISimpleEnumerator **eventlist ) {
#ifdef ICAL_DEBUG
printf( "oeICalImpl::GetNextNEvents()\n" );
printf( "oeICalImpl::GetNextNEvents( %d )\n", maxcount );
#endif
nsCOMPtr<oeEventEnumerator> eventEnum = new oeEventEnumerator( );
@ -1233,6 +1254,24 @@ oeICalImpl::AddObserver(oeIICalObserver *observer)
return NS_OK;
}
NS_IMETHODIMP
oeICalImpl::RemoveObserver(oeIICalObserver *observer)
{
#ifdef ICAL_DEBUG
printf( "oeICalImpl::RemoveObserver()\n" );
#endif
if( observer ) {
for( unsigned int i=0; i<m_observerlist.size(); i++ ) {
if( observer == m_observerlist[i] ) {
m_observerlist.erase( &m_observerlist[i] );
observer->Release();
break;
}
}
}
return NS_OK;
}
void AlarmTimerCallback(nsITimer *aTimer, void *aClosure)
{
#ifdef ICAL_DEBUG

Просмотреть файл

@ -44,6 +44,10 @@
#define OE_ICAL_CONTRACTID "@mozilla.org/ical;1"
extern "C" {
#include "ical.h"
}
class EventList {
public:
oeIICalEvent* event;
@ -137,6 +141,7 @@ class oeICalImpl : public oeIICal
NS_DECL_OEIICAL
void SetupAlarmManager();
private:
icaltimetype GetNextEvent( icaltimetype starting );
std::vector<oeIICalObserver*> m_observerlist;
bool m_batchMode;
EventList m_eventlist;

Просмотреть файл

@ -119,6 +119,7 @@ interface oeIICal : nsISupports
void setServer( in string str );
void addObserver( in oeIICalObserver observer );
void removeObserver( in oeIICalObserver observer );
string addEvent( in oeIICalEvent icalevent );
string modifyEvent( in oeIICalEvent icalevent );
void deleteEvent( in string id );