mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Added first stage of supprt for attachments
This commit is contained in:
parent
6d6001ac89
commit
9f3e1426c5
@ -35,6 +35,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const DEFAULT_SERVER="file:///tmp/.oecalendar";
|
||||
const DEFAULT_TITLE="Lunch Time";
|
||||
const DEFAULT_DESCRIPTION = "Will be out for one hour";
|
||||
const DEFAULT_LOCATION = "Restaurant";
|
||||
@ -49,6 +50,7 @@ const DEFAULT_RECUR = true;
|
||||
const DEFAULT_RECURINTERVAL = 7;
|
||||
const DEFAULT_RECURUNITS = "days";
|
||||
const DEFAULT_RECURFOREVER = true;
|
||||
const DEFAULT_ATTACHMENT = DEFAULT_SERVER
|
||||
|
||||
var iCalLib = null;
|
||||
var gObserver = null;
|
||||
@ -101,7 +103,7 @@ function Test()
|
||||
iCalLib = iCalLibComponent.QueryInterface(Components.interfaces.oeIICal);
|
||||
}
|
||||
|
||||
iCalLib.setServer( "/tmp/.oecalendar" );
|
||||
iCalLib.setServer( DEFAULT_SERVER );
|
||||
iCalLib.Test();
|
||||
alert( "Finished Test" );
|
||||
}
|
||||
@ -121,7 +123,7 @@ function TestAll()
|
||||
gTodoObserver = new Observer();
|
||||
iCalLib.addTodoObserver( gTodoObserver );
|
||||
}
|
||||
iCalLib.setServer( "/tmp/.oecalendar" );
|
||||
iCalLib.setServer( DEFAULT_SERVER );
|
||||
var id = TestAddEvent();
|
||||
if( id == 0 ) {
|
||||
alert( "Stopped Test" );
|
||||
@ -184,6 +186,10 @@ function TestAddEvent()
|
||||
var snoozetime = new Date();
|
||||
iCalEvent.setSnoozeTime( snoozetime );
|
||||
|
||||
Attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance( Components.interfaces.nsIMsgAttachment );
|
||||
Attachment.url = DEFAULT_ATTACHMENT;
|
||||
iCalEvent.addAttachment( Attachment );
|
||||
|
||||
var id = iCalLib.addEvent( iCalEvent );
|
||||
|
||||
if( id == null ){
|
||||
@ -323,7 +329,15 @@ function TestFetchEvent( id )
|
||||
alert( "TestFetchEvent(): Invalid Recur Forever" );
|
||||
return null;
|
||||
}
|
||||
|
||||
if( !iCalEvent.attachmentsArray.Count() ) {
|
||||
alert( "TestFetchEvent(): No attachment found" );
|
||||
return null;
|
||||
}
|
||||
attachment = iCalEvent.attachmentsArray.QueryElementAt( 0, Components.interfaces.nsIMsgAttachment );
|
||||
if ( attachment.url != DEFAULT_ATTACHMENT ) {
|
||||
alert( "TestFetchEvent(): Invalid attachment" );
|
||||
return null;
|
||||
}
|
||||
//TODO: Check for start and end date
|
||||
|
||||
return iCalEvent;
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include "oeICalEventImpl.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "plbase64.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
|
||||
#define strcasecmp strcmp
|
||||
|
||||
@ -169,6 +171,7 @@ oeICalEventImpl::oeICalEventImpl()
|
||||
SetAlarmUnits( "minutes" );
|
||||
SetRecurUnits( "weeks" );
|
||||
SetSyncId( "" );
|
||||
NS_NewISupportsArray(getter_AddRefs(m_attachments));
|
||||
}
|
||||
|
||||
oeICalEventImpl::~oeICalEventImpl()
|
||||
@ -1191,6 +1194,83 @@ NS_IMETHODIMP oeICalEventImpl::Clone( oeIICalEvent **ev )
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalEventImpl::GetAttachmentsArray(nsISupportsArray * *aAttachmentsArray)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAttachmentsArray);
|
||||
*aAttachmentsArray = m_attachments;
|
||||
NS_IF_ADDREF(*aAttachmentsArray);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalEventImpl::AddAttachment(nsIMsgAttachment *attachment)
|
||||
{
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::AddAttachment()\n" );
|
||||
#endif
|
||||
PRUint32 i;
|
||||
PRUint32 attachmentCount = 0;
|
||||
m_attachments->Count(&attachmentCount);
|
||||
|
||||
//Don't add twice the same attachment.
|
||||
nsCOMPtr<nsIMsgAttachment> element;
|
||||
PRBool sameUrl;
|
||||
for (i = 0; i < attachmentCount; i ++)
|
||||
{
|
||||
m_attachments->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
|
||||
if (element)
|
||||
{
|
||||
element->EqualsUrl(attachment, &sameUrl);
|
||||
if (sameUrl)
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return m_attachments->InsertElementAt(attachment, attachmentCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalEventImpl::RemoveAttachment(nsIMsgAttachment *attachment)
|
||||
{
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::RemoveAttachment()\n" );
|
||||
#endif
|
||||
PRUint32 i;
|
||||
PRUint32 attachmentCount = 0;
|
||||
m_attachments->Count(&attachmentCount);
|
||||
|
||||
nsCOMPtr<nsIMsgAttachment> element;
|
||||
PRBool sameUrl;
|
||||
for (i = 0; i < attachmentCount; i ++)
|
||||
{
|
||||
m_attachments->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
|
||||
if (element)
|
||||
{
|
||||
element->EqualsUrl(attachment, &sameUrl);
|
||||
if (sameUrl)
|
||||
{
|
||||
m_attachments->DeleteElementAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalEventImpl::RemoveAttachments()
|
||||
{
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalEventImpl::RemoveAttachments()\n" );
|
||||
#endif
|
||||
PRUint32 i;
|
||||
PRUint32 attachmentCount = 0;
|
||||
m_attachments->Count(&attachmentCount);
|
||||
|
||||
for (i = 0; i < attachmentCount; i ++)
|
||||
m_attachments->DeleteElementAt(0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool oeICalEventImpl::ParseIcalComponent( icalcomponent *comp )
|
||||
{
|
||||
#ifdef ICAL_DEBUG_ALL
|
||||
@ -1529,6 +1609,25 @@ bool oeICalEventImpl::ParseIcalComponent( icalcomponent *comp )
|
||||
m_snoozetimes.push_back( snoozetimeinms );
|
||||
}
|
||||
}
|
||||
|
||||
//attachments
|
||||
for( prop = icalcomponent_get_first_property( vevent, ICAL_X_PROPERTY );
|
||||
prop != 0 ;
|
||||
prop = icalcomponent_get_next_property( vevent, ICAL_X_PROPERTY ) ) {
|
||||
icalparameter *tmppar = icalproperty_get_first_parameter( prop, ICAL_MEMBER_PARAMETER );
|
||||
if ( tmppar != 0 ) {
|
||||
tmpstr = icalparameter_get_member( tmppar );
|
||||
if( strcmp( tmpstr, "Attachment" ) == 0 ) {
|
||||
nsresult rv;
|
||||
tmpstr = (char *)icalproperty_get_value_as_string( prop );
|
||||
nsCOMPtr<nsIMsgAttachment> attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv);
|
||||
if ( NS_SUCCEEDED(rv) && attachment ) {
|
||||
attachment->SetUrl( tmpstr );
|
||||
AddAttachment( attachment );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1836,7 +1935,8 @@ icalcomponent* oeICalEventImpl::AsIcalComponent()
|
||||
|
||||
//snoozetimes
|
||||
icalcomponent *tmpcomp=NULL;
|
||||
for( unsigned int i=0; i<m_snoozetimes.size(); i++ ) {
|
||||
unsigned int i;
|
||||
for( i=0; i<m_snoozetimes.size(); i++ ) {
|
||||
if( tmpcomp == NULL )
|
||||
tmpcomp = icalcomponent_new( ICAL_X_COMPONENT );
|
||||
icaltimetype snoozetime = ConvertFromPrtime( m_snoozetimes[i] );
|
||||
@ -1846,6 +1946,41 @@ icalcomponent* oeICalEventImpl::AsIcalComponent()
|
||||
if( tmpcomp )
|
||||
icalcomponent_add_component( vevent, tmpcomp );
|
||||
|
||||
PRUint32 attachmentCount = 0;
|
||||
m_attachments->Count(&attachmentCount);
|
||||
nsCOMPtr<nsIMsgAttachment> element;
|
||||
for (i = 0; i < attachmentCount; i ++) {
|
||||
m_attachments->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
|
||||
if (element)
|
||||
{
|
||||
char *url;
|
||||
element->GetUrl( &url );
|
||||
icalparameter *tmppar = icalparameter_new_member( "Attachment" );
|
||||
prop = icalproperty_new_x( url );
|
||||
icalproperty_add_parameter( prop, tmppar );
|
||||
icalcomponent_add_property( vevent, prop );
|
||||
/* icalattach *attach= icalattach_new_from_url( url );
|
||||
if( attach ) {
|
||||
char tst[100]= "testing";
|
||||
char *buffer;
|
||||
buffer = PL_Base64Encode( tst, strlen(tst), nsnull );
|
||||
|
||||
// strcpy( buffer, "salam" );
|
||||
// icalattachtype_set_base64( attachtype, buffer, 0 );
|
||||
prop = icalproperty_new_attach( attach );
|
||||
|
||||
// tmppar = icalparameter_new_fmttype( url );
|
||||
// icalproperty_add_parameter( prop, tmppar );
|
||||
// tmppar = icalparameter_new_encoding( ICAL_ENCODING_BASE64 );
|
||||
// icalproperty_add_parameter( prop, tmppar );
|
||||
|
||||
icalcomponent_add_property( vevent, prop );
|
||||
}*/
|
||||
nsMemory::Free( url );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//add event to newcalendar
|
||||
icalcomponent_add_component( newcalendar, vevent );
|
||||
return newcalendar;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsSupportsPrimitives.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
@ -117,6 +118,7 @@ private:
|
||||
std::vector<PRTime> m_snoozetimes;
|
||||
icaltimetype CalculateAlarmTime( icaltimetype date );
|
||||
bool IsExcepted( PRTime date );
|
||||
nsCOMPtr<nsISupportsArray> m_attachments;
|
||||
};
|
||||
|
||||
/*******************************************************************************************/
|
||||
|
@ -296,7 +296,8 @@ oeICalImpl::~oeICalImpl()
|
||||
#ifdef ICAL_DEBUG
|
||||
printf( "oeICalImpl::~oeICalImpl()\n" );
|
||||
#endif
|
||||
for( unsigned int i=0; i<m_observerlist.size(); i++ ) {
|
||||
unsigned int i;
|
||||
for( i=0; i<m_observerlist.size(); i++ ) {
|
||||
m_observerlist[i]->Release();
|
||||
}
|
||||
m_observerlist.clear();
|
||||
@ -764,7 +765,8 @@ oeICalImpl::SetServer( const char *str ) {
|
||||
|
||||
icalfileset_free(stream);
|
||||
|
||||
for( unsigned int i=0; i<m_observerlist.size(); i++ ) {
|
||||
unsigned int i;
|
||||
for( i=0; i<m_observerlist.size(); i++ ) {
|
||||
nsresult rv;
|
||||
rv = m_observerlist[i]->OnLoad();
|
||||
#ifdef ICAL_DEBUG
|
||||
@ -815,7 +817,8 @@ NS_IMETHODIMP oeICalImpl::SetBatchMode(PRBool aBatchMode)
|
||||
|
||||
// tell observers about the change
|
||||
|
||||
for( unsigned int i=0; i<m_observerlist.size(); i++ )
|
||||
unsigned int i;
|
||||
for( i=0; i<m_observerlist.size(); i++ )
|
||||
{
|
||||
if( m_batchMode ) {
|
||||
nsresult rv;
|
||||
@ -2478,3 +2481,24 @@ NS_IMETHODIMP oeICalFilter::SetPercent(PRInt16 aNewVal)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalFilter::AddAttachment(nsIMsgAttachment *attachment)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalFilter::RemoveAttachment(nsIMsgAttachment *attachment)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalFilter::RemoveAttachments()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP oeICalFilter::GetAttachmentsArray(nsISupportsArray * *aAttachmentsArray)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIMsgAttachment.idl"
|
||||
#include "nsISupportsArray.idl"
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
/**
|
||||
@ -101,6 +103,11 @@ interface oeIICalEvent : nsISupports
|
||||
void removeAllExceptions();
|
||||
void setSnoozeTime( in PRTime exdate );
|
||||
oeIICalEvent clone();
|
||||
|
||||
readonly attribute nsISupportsArray attachmentsArray;
|
||||
void addAttachment(in nsIMsgAttachment attachment);
|
||||
void removeAttachment(in nsIMsgAttachment attachment);
|
||||
void removeAttachments();
|
||||
};
|
||||
|
||||
[scriptable, uuid(f95df40e-0d5f-49ec-9ba8-4b88d3eb53e0)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user