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