sdkcreationmw/sdkruntimes/emumenubar/menubar/Push.cpp
author rajpuroh
Mon, 08 Mar 2010 12:09:11 +0530
changeset 0 b26acd06ea60
child 1 ac50fd48361b
permissions -rw-r--r--
First Contribution of SDK components
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     1
/*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     2
* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     3
* All rights reserved.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     4
* This component and the accompanying materials are made available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     6
* which accompanies this distribution, and is available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     8
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     9
* Initial Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    11
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    12
* Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    13
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    14
* Description:  Push support
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    15
 *
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    16
*/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    17
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    18
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    19
#include "EcmtMenubar.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    20
#include "EcmtWin32.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    21
#include "httpfile.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    22
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    23
#include <e32base.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    24
#include <apgtask.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    25
#include <apgcli.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    26
#include <vwsdef.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    27
#include <viewcli.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    28
#include <cmanobserver.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    29
#include <e32property.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    30
#include <PSVariables.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    31
#include <EscapeUtils.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    32
#include <emulator.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    33
#include <sacls.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    34
#include <msvids.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    35
#include <msvstd.hrh>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    36
#include <mmssettings.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    37
#include <PushLog.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    38
#include <PushMessage.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    39
#include <PushDispatcher.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    40
#include <CPushHandlerBase.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    41
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    42
// We define CWatcherLog locally because CWatcherLog::NewL is not
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    43
// exported from watcher.dll
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    44
#undef IMPORT_C
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    45
#define IMPORT_C
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    46
#include <watcher.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    47
  
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    48
// MACROS
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    49
#define __S8(x) _S8(x)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    50
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    51
// Some view ids
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    52
#define KMessagingUid TUid::Uid(0x100058C5)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    53
#define KMessagingCentreMainViewUid TVwsViewId(KMessagingUid,TUid::Uid(0x01))
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    54
#define KMessagingCentreInboxView TVwsViewId(KMessagingUid,TUid::Uid(0x02))
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    55
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    56
// Known push content types
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    57
typedef enum _TPushMessageType {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    58
    EWapPush,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    59
    EMultipart,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    60
    EMmsMessage
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    61
} TPushMessageType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    62
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    63
typedef struct _PushType {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    64
    const TText* ext;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    65
    const TText8* contentType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    66
    TPushMessageType msgType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    67
    TUint8 wapContentType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    68
} PushType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    69
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    70
// WAP encoded content types must have 0x80 bit set
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    71
const TUint8 WAP_MP_MIX = 0xA3; // application/vnd.wap.multipart.mixed
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    72
const TUint8 WAP_MP_ALT = 0xA6; // application/vnd.wap.multipart.alternative
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    73
const TUint8 WAP_MP_REL = 0xB3; // application/vnd.wap.multipart.related
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    74
static const PushType pushTypes[] = {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    75
    {_S("sic"),__S8("application/vnd.wap.sic"), EWapPush, 0xAE},
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    76
    {_S("slc"),__S8("application/vnd.wap.slc"), EWapPush, 0xB0},
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    77
    {_S("coc"),__S8("application/vnd.wap.coc"), EWapPush, 0xB2},
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    78
    {_S("mms"),__S8("application/vnd.wap.mms-message"), EMmsMessage, 0},
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    79
    {_S("mpc"),__S8("application/vnd.wap.multipart.mixed"), EMultipart, WAP_MP_MIX},
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    80
    {_S("mpc"),__S8("application/vnd.wap.multipart.related"), EMultipart, WAP_MP_REL},
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    81
    {_S("mpc"),__S8("application/vnd.wap.multipart.alternative"), EMultipart, WAP_MP_ALT}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    82
};
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    83
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    84
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    85
// This class implements MWapPushLog and MConnManObserver interfaces
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    86
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    87
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    88
class CEcmtMenubar::CWapPushSupport :
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    89
    public MWapPushLog, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    90
    public MConnManObserver
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    91
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    92
public:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    93
    // MWapPushLog
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    94
    void WPLPrintf(const TDesC&);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    95
    void WPLPrintfL(CPushMessage&);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    96
    void WPLLogBinaryAsHex(const TDesC&);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    97
    void WPLLogError(const TDesC&,TInt );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    98
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    99
    // MConnManObserver
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   100
    void CMOpenConnectionL(TPushConnPoint&);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   101
    void CMWatcherComplete(CCOWatcherBase&, TInt);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   102
};
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   103
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   104
// MWapPushLog
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   105
void CEcmtMenubar::CWapPushSupport::WPLPrintf(const TDesC&) {}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   106
void CEcmtMenubar::CWapPushSupport::WPLPrintfL(CPushMessage&) {}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   107
void CEcmtMenubar::CWapPushSupport::WPLLogBinaryAsHex(const TDesC&) {}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   108
void CEcmtMenubar::CWapPushSupport::WPLLogError(const TDesC&,TInt ) {}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   109
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   110
// MConnManObserver
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   111
void CEcmtMenubar::CWapPushSupport::CMOpenConnectionL(TPushConnPoint&) {}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   112
void CEcmtMenubar::CWapPushSupport::CMWatcherComplete(CCOWatcherBase&,TInt) {}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   113
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   114
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   115
// CWatcherLog
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   116
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   117
CWatcherLog* CWatcherLog::NewL(RFs& aFs)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   118
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   119
    CWatcherLog* self = new(ELeave)CWatcherLog(aFs);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   120
    CleanupStack::PushL(self);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   121
    self->ConstructL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   122
    CleanupStack::Pop();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   123
    return self;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   124
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   125
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   126
CWatcherLog::CWatcherLog(RFs& aFs) : CBase(), iFs(aFs)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   127
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   128
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   129
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   130
CWatcherLog::~CWatcherLog()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   131
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   132
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   133
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   134
void CWatcherLog::ConstructL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   135
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   136
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   137
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   138
void CWatcherLog::Printf(TRefByValue<const TDesC16>,...)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   139
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   140
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   141
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   142
void CWatcherLog::Printf(TRefByValue<const TDesC8>,...)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   143
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   144
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   145
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   146
TBool CWatcherLog::IsLogging() const
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   147
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   148
    return EFalse;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   149
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   150
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   151
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   152
// Some obscure code
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   153
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   154
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   155
inline void LaunchViewL(const TVwsViewId& aViewId,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   156
                        TUid aCustomMessageId,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   157
                        const TDesC8& aCustomMessage)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   158
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   159
    CVwsSessionWrapper* view = CVwsSessionWrapper::NewLC();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   160
    view->CreateActivateViewEvent(aViewId, aCustomMessageId, aCustomMessage);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   161
    CleanupStack::PopAndDestroy(view);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   162
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   163
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   164
inline void LaunchMmsViewL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   165
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   166
    LaunchViewL(KMessagingCentreInboxView, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   167
        TUid::Uid(KMsvGlobalInBoxIndexEntryIdValue), 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   168
        KNullDesC8());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   169
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   170
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   171
inline void LaunchPushViewL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   172
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   173
    // The same view handles Wap Push messages as well as MMS messages
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   174
    LaunchMmsViewL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   175
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   176
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   177
inline void InboxStatusNotifyL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   178
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   179
    TInt r =  RProperty::Define(KUidSystemCategory, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   180
                                KUidInboxStatus.iUid, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   181
                                RProperty::EInt);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   182
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   183
    if (r == KErrNone)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   184
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   185
        RProperty::Set(KUidSystemCategory, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   186
                       KUidInboxStatus.iUid, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   187
                       ESADocumentsInInbox );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   188
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   189
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   190
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   191
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   192
// MMS support
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   193
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   194
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   195
/**
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   196
 * Reads the location of the mmsin directory from localmode.ini
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   197
 * This is a Java-style property file, only in Unicode.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   198
 * See CMmsWatcher::ReadLocalModeConfigData() method in
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   199
 * S60\mmsengine\mmswatcher\src\mmswatcher.cpp
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   200
 * The algorithm is reproduced here, with all its problems,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   201
 * because we want it to exactly match what CMmsWatcher does
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   202
 */
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   203
HBufC* CEcmtMenubar::ReadMmsInDir(RFs& aFs)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   204
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   205
    HBufC* mmsInBuf = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   206
    RFileReadStream reader;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   207
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   208
    // Actually, if localmode.ini file does not exist, the MMS watcher
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   209
    // does not poll the mmsin directory and everything we are doing
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   210
    // here is useless. Should we create localmode.ini file if it 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   211
    // doesn't exist? But then SDK would have to be restarted because
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   212
    // MMS watcher only attempts to read this file on startup... Hmm.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   213
    TInt err = reader.Open(aFs,KMmsLocalModeConfigFile,EFileShareReadersOnly);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   214
    if (err == KErrNone)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   215
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   216
        TChar delim = 0x000A;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   217
        TBuf<128> line;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   218
        while (err == KErrNone)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   219
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   220
            TRAP(err, reader.ReadL( line, delim ) );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   221
            if (err == KErrNone)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   222
            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   223
                TInt length = line.Length();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   224
                if (length > 2)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   225
                {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   226
                    // Check for comment line
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   227
                    if (line[0] != '#')
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   228
                    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   229
                        // Check for byte order mark
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   230
                        if (line[0] == 0xFEFF)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   231
                        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   232
                            line.Delete( 0, 1 );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   233
                            length = line.Length();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   234
                        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   235
                        // Drop CR+LF from the end of line
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   236
                        line.Delete(length-2, 2);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   237
                        TInt sep = line.Locate('=');
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   238
                        if (sep > 0)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   239
                        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   240
                            TPtrC key = line.Left(sep);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   241
                            if (key.CompareF(KMmsLocalmodeInDirectory) == 0)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   242
                            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   243
                                mmsInBuf = line.Mid(sep+1).Alloc();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   244
                                break;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   245
                            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   246
                        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   247
                    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   248
                }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   249
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   250
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   251
        reader.Close();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   252
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   253
    return mmsInBuf;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   254
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   255
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   256
// Returns reference to the mmsin directory 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   257
const TDesC& CEcmtMenubar::MmmInDirL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   258
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   259
    if (!iMmsInDir)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   260
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   261
        iMmsInDirBuf = ReadMmsInDir(FsSessionL());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   262
        if (iMmsInDirBuf)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   263
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   264
            iMmsInDir = iMmsInDirBuf;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   265
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   266
        else
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   267
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   268
            iMmsInDir = &KMmsDefaultLocalModeDir;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   269
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   270
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   271
    return *iMmsInDir;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   272
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   273
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   274
// Simulates an MMS message
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   275
void CEcmtMenubar::SimulateMmsL(const TDesC8& aMessageBody)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   276
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   277
    // First copy the file to the phone's file system
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   278
    const TDesC& mmsDir = MmmInDirL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   279
    RFs& fs = FsSessionL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   280
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   281
    // Make sure the directory exists
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   282
    TUint attr = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   283
    if (fs.Att(mmsDir,attr) != KErrNone || !(attr & KEntryAttDir))
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   284
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   285
        fs.Delete(mmsDir); // Ignore errors
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   286
        User::LeaveIfError(fs.MkDir(mmsDir));
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   287
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   288
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   289
    // Create a temporary file. The extension must be .mms
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   290
    RFile file;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   291
    TInt err = KErrAlreadyExists;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   292
    for (TInt i=0; err == KErrAlreadyExists && i<1000; i++)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   293
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   294
        _LIT(KMmsFilePrefix,"TMP");
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   295
        _LIT(KMmsExt,".mms");
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   296
        TFileName name;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   297
        name.Copy(mmsDir);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   298
        name.Append(KMmsFilePrefix());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   299
        name.AppendFormat(_L("%04d"),i);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   300
        name.Append(KMmsExt());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   301
        err = file.Create(fs,name,EFileWrite);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   302
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   303
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   304
    // Write the file
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   305
    User::LeaveIfError(err);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   306
    err = file.Write(aMessageBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   307
    file.Close();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   308
    User::LeaveIfError(err);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   309
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   310
    // Open the Messaging application
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   311
    InboxStatusNotifyL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   312
    LaunchMmsViewL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   313
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   314
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   315
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   316
// Push support
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   317
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   318
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   319
/**
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   320
 * Returns a reference to CWatcherLog.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   321
 */
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   322
CWatcherLog& CEcmtMenubar::WatcherLogL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   323
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   324
    if (!iWatcherLog)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   325
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   326
        iWatcherLog = CWatcherLog::NewL(FsSessionL());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   327
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   328
    return *iWatcherLog;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   329
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   330
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   331
/**
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   332
 * Wap push simulator. Takes care of destroying CPushMessage
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   333
 */
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   334
void CEcmtMenubar::SimulateWapPushL(CPushMessage* aPushMessage)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   335
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   336
    TPtrC8 rAppURI;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   337
    TInt rAppID;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   338
    TBool rIsAnInt;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   339
    CPushHandlerBase* appHandlerPtr = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   340
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   341
    CleanupStack::PushL(aPushMessage);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   342
    if (!iWapPushSupport) iWapPushSupport = new(ELeave)CWapPushSupport;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   343
    if (aPushMessage->GetAppIdL(rAppURI, rAppID, rIsAnInt))
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   344
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   345
        if(rIsAnInt)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   346
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   347
            appHandlerPtr = &PushAppDispatcher::GetHandlerL(rAppID,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   348
                *iWapPushSupport, *iWapPushSupport);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   349
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   350
        else
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   351
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   352
            appHandlerPtr = &PushAppDispatcher::GetHandlerL(rAppURI,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   353
                *iWapPushSupport, *iWapPushSupport);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   354
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   355
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   356
    else
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   357
    {   // If no AppID defined, use the default User Agent
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   358
        appHandlerPtr= &PushAppDispatcher::GetHandlerL(KUserAgentAppHandler,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   359
            *iWapPushSupport, *iWapPushSupport);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   360
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   361
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   362
    if (appHandlerPtr)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   363
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   364
        appHandlerPtr->HandleMessageL(aPushMessage);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   365
        CleanupStack::Pop(aPushMessage);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   366
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   367
    else
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   368
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   369
        CleanupStack::PopAndDestroy(aPushMessage);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   370
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   371
    
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   372
    // Show the indicator
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   373
    InboxStatusNotifyL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   374
    LaunchPushViewL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   375
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   376
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   377
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   378
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   379
// The main routine that does all the Push/MMS work
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   380
// --------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   381
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   382
/**
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   383
 * Detects whether the file is an MMS or a Wap Push message and
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   384
 * attempts to push it to the phone. Returns ETrue on success,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   385
 * EFalse on failure or if the file does not seem to contain
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   386
 * push content.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   387
 */
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   388
TBool CEcmtMenubar::LoadFileAsPushL(const TDesC& aFileName)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   389
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   390
    // First check if this is an HTTP response file.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   391
    ParseHttpResponse* resp = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   392
    const PushType* pushType = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   393
    char* fname = STRING_ToMultiByteN(aFileName.Ptr(),aFileName.Length());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   394
    if (fname)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   395
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   396
        resp = HTTP_ParseFile(fname, HttpFalse);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   397
        if (resp)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   398
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   399
            if (HTTP_ResponseStatus(resp) == HTTP_STATUS_CODE_OK)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   400
            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   401
                const HttpContent* content = HTTP_ResponseContent(resp);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   402
                if (content && content->type)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   403
                {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   404
                    for (TInt i=0; i<COUNT(pushTypes) && !pushType; i++)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   405
                    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   406
                        const char* type = (char*)pushTypes[i].contentType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   407
                        if (!strcmp(type, content->type))
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   408
                        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   409
                            pushType = pushTypes + i;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   410
                        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   411
                    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   412
                }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   413
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   414
            if (!pushType)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   415
            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   416
                HTTP_ResponseDelete(resp);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   417
                resp = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   418
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   419
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   420
        MEM_Free(fname);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   421
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   422
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   423
    // Now check if this file has one of the DRM extensions
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   424
    if (!pushType)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   425
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   426
        TPtrC fileExt(FileExt(aFileName));
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   427
        for (TInt i=0; i<COUNT(pushTypes) && !pushType; i++)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   428
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   429
            if (fileExt.CompareF(TPtrC(pushTypes[i].ext)) == 0) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   430
                pushType = pushTypes + i;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   431
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   432
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   433
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   434
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   435
    // If we suspect that this is a push or MMS message, load the file
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   436
    // into a memory buffer
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   437
    HBufC8* msgBody = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   438
    if (pushType)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   439
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   440
        if (resp)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   441
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   442
            const HttpContent* hc = HTTP_ResponseContent(resp);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   443
            msgBody = HBufC8::New(hc->size); // No leaving, please
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   444
            if (msgBody)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   445
            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   446
                msgBody->Des().Append(TPtrC8((TText8*)hc->data, hc->size));
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   447
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   448
            HTTP_ResponseDelete(resp);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   449
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   450
        else
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   451
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   452
            msgBody = ReadExtFile(aFileName);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   453
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   454
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   455
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   456
    if (msgBody && msgBody->Length() > 0)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   457
    {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   458
        // File has been loaded. Do something with it
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   459
        CleanupStack::PushL(msgBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   460
        if (pushType->msgType == EWapPush || 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   461
            pushType->msgType == EMultipart)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   462
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   463
            HBufC8* msgHeader = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   464
            TUint8 wapContentType = pushType->wapContentType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   465
            if (pushType->msgType == EMultipart)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   466
            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   467
                const TUint8 * msgData = msgBody->Ptr();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   468
                TInt msgLen = msgBody->Length();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   469
                if (msgLen > 1 && msgData[0] >= 1 && msgData[0] < msgLen && (
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   470
                    msgData[1] == WAP_MP_MIX || 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   471
                    msgData[1] == WAP_MP_ALT ||
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   472
                    msgData[1] == WAP_MP_REL))
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   473
                {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   474
                    // Looks like multipart message contains encoded headers
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   475
                    // Separate body from the headers
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   476
                    HBufC8* msgBody2 = msgBody->Mid(msgData[0]+1,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   477
                        msgLen-msgData[0]-1).AllocLC();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   478
                    msgHeader = msgBody->Mid(1,msgData[0]).AllocL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   479
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   480
                    // Switch to the new body
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   481
                    CleanupStack::Pop(msgBody2);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   482
                    CleanupStack::PopAndDestroy(msgBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   483
                    msgBody = msgBody2;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   484
                    msgLen = msgBody->Length();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   485
                    CleanupStack::PushL(msgBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   486
                    CleanupStack::PushL(msgHeader);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   487
                }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   488
                else
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   489
                {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   490
                    // Assume application/vnd.wap.multipart.mixed
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   491
                    wapContentType = WAP_MP_MIX;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   492
                }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   493
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   494
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   495
            if (!msgHeader)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   496
            {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   497
                // We have no headers, allocate a fake one with just
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   498
                // the content type
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   499
                msgHeader = HBufC8::NewLC(1);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   500
                TPtr8 msgHeaderDes(msgHeader->Des());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   501
                msgHeaderDes.SetLength(1);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   502
                msgHeaderDes[0] = wapContentType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   503
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   504
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   505
            CPushMessage* msg = CPushMessage::NewL(msgHeader, msgBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   506
            CleanupStack::Pop(msgHeader);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   507
            CleanupStack::Pop(msgBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   508
            SimulateWapPushL(msg);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   509
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   510
        else
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   511
        {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   512
            SimulateMmsL(*msgBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   513
            CleanupStack::PopAndDestroy(msgBody);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   514
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   515
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   516
        return ETrue;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   517
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   518
    return EFalse;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   519
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   520
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   521
/**
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   522
 * Local Variables:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   523
 * c-basic-offset: 4
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   524
 * indent-tabs-mode: nil
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   525
 * End:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   526
 */