messagingfw/sendas/test/sendastextnotifier/src/CSendAsTextNotifier.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "csendastextnotifier.h"
       
    17 #include <tmsvpackednotifierrequest.h>
       
    18 
       
    19 /** UID of the SendAs notifier channel to get the user's confirmation */
       
    20 const TUid KSendAsNotifierPluginUid     = {0x10208C14};
       
    21 const TUid KTechViewScreenOutputChannel = {0x10208C14};
       
    22 
       
    23 
       
    24 EXPORT_C CArrayPtr<MNotifierBase2>* NotifierArray()
       
    25 	{
       
    26 	CArrayPtrFlat<MNotifierBase2>* subjects=NULL;
       
    27 	TRAPD( err, subjects=new (ELeave)CArrayPtrFlat<MNotifierBase2>(1) );
       
    28 	if( err == KErrNone )
       
    29 		{
       
    30 		TRAP( err, subjects->AppendL( CSendAsTextNotifier::NewL() ) );
       
    31 		return(subjects);
       
    32 		}
       
    33 	else
       
    34 		{
       
    35 		return NULL;
       
    36 		}
       
    37 	}
       
    38 
       
    39 CSendAsTextNotifier* CSendAsTextNotifier::NewL()
       
    40 	{
       
    41 	CSendAsTextNotifier* self=new (ELeave) CSendAsTextNotifier();
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 	
       
    48 void CSendAsTextNotifier::ConstructL()
       
    49 	{
       
    50 	iSelection = new (ELeave) CMsvEntrySelection();
       
    51 	}
       
    52 
       
    53 CSendAsTextNotifier::~CSendAsTextNotifier()
       
    54 	{
       
    55 	delete iSelection;
       
    56 	}
       
    57 
       
    58 CSendAsTextNotifier::CSendAsTextNotifier()
       
    59 	{
       
    60 	iInfo.iUid      = KSendAsNotifierPluginUid;
       
    61 	iInfo.iChannel  = KTechViewScreenOutputChannel;
       
    62 	iInfo.iPriority = ENotifierPriorityHigh;
       
    63 	}
       
    64 
       
    65 void CSendAsTextNotifier::Release()
       
    66 	{
       
    67 	delete this;
       
    68 	}
       
    69 
       
    70 /**
       
    71 Called when a notifier is first loaded to allow any initial construction that is required.
       
    72  */
       
    73 CSendAsTextNotifier::TNotifierInfo CSendAsTextNotifier::RegisterL()
       
    74 	{
       
    75 	return iInfo;
       
    76 	}
       
    77 
       
    78 CSendAsTextNotifier::TNotifierInfo CSendAsTextNotifier::Info() const
       
    79 	{
       
    80 	return iInfo;
       
    81 	}
       
    82 	
       
    83 /**
       
    84 The notifier has been deactivated so resources can be freed and outstanding messages completed.
       
    85  */
       
    86 void CSendAsTextNotifier::Cancel()
       
    87 	{
       
    88 	}
       
    89 
       
    90 /**
       
    91 Start the Notifier with data aBuffer. 
       
    92 
       
    93 Not used for confirm notifiers
       
    94 */
       
    95 TPtrC8 CSendAsTextNotifier::StartL(const TDesC8& /*aBuffer*/)
       
    96 	{
       
    97 	User::Leave(KErrNotSupported);
       
    98 	return KNullDesC8();
       
    99 	}
       
   100 	
       
   101 /**
       
   102 Start the notifier with data aBuffer. aMessage should be completed when the notifier is deactivated.
       
   103 
       
   104 May be called multiple times if more than one client starts the notifier. The notifier is immediately 
       
   105 responsible for completing aMessage.
       
   106 */
       
   107 void CSendAsTextNotifier::StartL(const TDesC8& aBuffer, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   108 	{
       
   109 	// extract the notifier request parameters
       
   110 	TMsvPackedNotifierRequest::UnpackL(aBuffer, *iSelection, iSecurityInfo);
       
   111 	iMessage   = aMessage;
       
   112 
       
   113 	// Simulate "User Response"
       
   114 	CDummyObserver* ob1 = new(ELeave) CDummyObserver;
       
   115 	CleanupStack::PushL(ob1);
       
   116 
       
   117 	CMsvSession* session = CMsvSession::OpenSyncL(*ob1);
       
   118 	CleanupStack::PushL(session);
       
   119 
       
   120 	CMsvEntry* cEntry = session->GetEntryL(iSelection->At(0));
       
   121 	CleanupStack::PushL(cEntry);
       
   122 
       
   123 	TMsvEntry entry = cEntry->Entry();
       
   124 
       
   125 	// complete with TMsvEntry::iError as return code
       
   126 	if (entry.iError != KErrNone)
       
   127 		{
       
   128 		iMessage.Complete(KErrPermissionDenied);
       
   129 		}
       
   130 	else
       
   131 		{
       
   132 		iMessage.Complete(KErrNone);
       
   133 		}
       
   134 	
       
   135 	// Clear the CMsvEntrySelection
       
   136 	iSelection->Reset();
       
   137 	
       
   138 	CleanupStack::PopAndDestroy(3, ob1); // cEntry, session, ob1
       
   139 	}
       
   140 	
       
   141 /**
       
   142 Update a currently active notifier with data aBuffer.
       
   143 
       
   144 Not used for confirm notifiers
       
   145 */
       
   146 TPtrC8 CSendAsTextNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   147 	{
       
   148 	User::Leave(KErrNotSupported);
       
   149 	return KNullDesC8();
       
   150 	}
       
   151