contentstorage/cahandler/url/src/caurlhandler.cpp
changeset 83 156f692b1687
parent 61 8e5041d13c84
child 98 d2f833ab7940
equal deleted inserted replaced
80:397d00875918 83:156f692b1687
    13  *
    13  *
    14  * Description:  ?Description
    14  * Description:  ?Description
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <w32std.h>
    18 #include <QDesktopServices>
    19 #include <apgtask.h>
    19 #include <QUrl>
    20 #include <apgcli.h>
    20 
    21 #include <AknTaskList.h>
    21 #include <caentry.h>
    22 
    22 
    23 #include "caurlhandler.h"
    23 #include "caurlhandler.h"
    24 #include "cadef.h"
       
    25 #include "cainnerentry.h"
       
    26 
    24 
    27 // ================= MEMBER FUNCTIONS =======================
    25 static const QString caAttrUrl("url");
    28 
    26 
    29 // --------------------------------------------------------------------------
    27 CaUrlHandler::CaUrlHandler(QObject *parent)
    30 // CCaUrlHandler::~CCaUrlHandler
    28 {
    31 // --------------------------------------------------------------------------
    29     Q_UNUSED(parent);
    32 //
    30 }
    33 CCaUrlHandler::~CCaUrlHandler()
       
    34     {
       
    35     }
       
    36 
    31 
    37 // --------------------------------------------------------------------------
    32 CaUrlHandler::~CaUrlHandler()
    38 // CCaUrlHandler::NewL
    33 {
    39 // --------------------------------------------------------------------------
    34 }
    40 //
       
    41 CCaUrlHandler* CCaUrlHandler::NewL()
       
    42     {
       
    43     CCaUrlHandler* handler = new ( ELeave ) CCaUrlHandler();
       
    44     CleanupStack::PushL( handler );
       
    45     handler->ConstructL();
       
    46     CleanupStack::Pop( handler );
       
    47     return handler;
       
    48     }
       
    49 
    35 
    50 // --------------------------------------------------------------------------
    36 int CaUrlHandler::execute(const CaEntry &entry, const QString &command)
    51 // CCaUrlHandler::CCaUrlHandler
    37 {
    52 // --------------------------------------------------------------------------
    38     int err(KErrGeneral);
    53 //
    39     if (command == caCmdOpen) {
    54 CCaUrlHandler::CCaUrlHandler()
    40         QString attribute = entry.attribute(caAttrUrl);
    55     {
    41         if (!attribute.isNull() &&
    56     }
    42             QDesktopServices::openUrl(QUrl(attribute))) {
    57 
    43             err = KErrNone;
    58 // --------------------------------------------------------------------------
       
    59 // CCaUrlHandler::ConstructL
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 void CCaUrlHandler::ConstructL()
       
    63     {
       
    64     }
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CCaUrlHandler::HandleCommandL
       
    68 // --------------------------------------------------------------------------
       
    69 //
       
    70 void CCaUrlHandler::HandleCommandL( CCaInnerEntry& aEntry,
       
    71         const TDesC8& aCommand )
       
    72     {
       
    73 
       
    74     if( !aCommand.Compare( KCaCmdOpen() ) )
       
    75         {
       
    76         const RCaEntryAttrArray& attributes = aEntry.GetAttributes();
       
    77         TInt attributesArrayCount = attributes.Count();
       
    78         for( int i = 0; i < attributesArrayCount; ++i )
       
    79             {
       
    80             const CCaEntryAttribute * const attribute = attributes[i];
       
    81             if( attribute->Name().Compare( KCaAttrUrl ) == 0 )
       
    82                 {
       
    83                 LaunchUrlL( attribute->Value() );
       
    84                 break;
       
    85                 }
       
    86             }
       
    87         }
       
    88     else
       
    89         {
       
    90         User::Leave( KErrNotSupported );
       
    91         }
    44         }
    92     }
    45     }
    93 
    46     return err;
    94 // --------------------------------------------------------------------------
    47 }
    95 // CCaUrlHandler::LaunchUrlL
       
    96 // --------------------------------------------------------------------------
       
    97 //
       
    98 
       
    99 void CCaUrlHandler::LaunchUrlL( const TDesC& aUrl )
       
   100     {
       
   101     // Launches browser stand-alone.
       
   102     // Browser is launched with a parameter 4 ("4 http://...."), which 
       
   103     // Start/Continue the browser specifying a URL. 
       
   104     // Other available parameters are described in the Browser API Specification
       
   105     // Document.
       
   106     TInt length = aUrl.Length() + KBrowserPrefix.iTypeLength;
       
   107 
       
   108     RWsSession wsSession;
       
   109     User::LeaveIfError( wsSession.Connect() );
       
   110     CleanupClosePushL<RWsSession> ( wsSession );
       
   111 
       
   112     CAknTaskList* taskList = CAknTaskList::NewL( wsSession );
       
   113     TApaTask task = taskList->FindRootApp( KUidBrowser );
       
   114     delete taskList;
       
   115 
       
   116     if( task.Exists() )
       
   117         {
       
   118         HBufC8* param8 = HBufC8::NewLC( length );
       
   119         TPtr8 ptr8 = param8->Des();
       
   120         ptr8.Append( KBrowserPrefix );
       
   121         ptr8.Append( aUrl );
       
   122 
       
   123         // Sends message to existing Browser task.
       
   124         task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
       
   125         CleanupStack::PopAndDestroy( param8 );
       
   126         }
       
   127     else
       
   128         {
       
   129         HBufC* buf = HBufC::NewLC( length );
       
   130         TPtr ptr = buf->Des();
       
   131         ptr.Append( KBrowserPrefix );
       
   132         ptr.Append( aUrl );
       
   133 
       
   134         RApaLsSession appArcSession;
       
   135         User::LeaveIfError( appArcSession.Connect() );
       
   136         CleanupClosePushL<RApaLsSession> ( appArcSession );
       
   137         TThreadId id;
       
   138         appArcSession.StartDocument( *buf, KUidBrowser, id );
       
   139         CleanupStack::PopAndDestroy( &appArcSession );
       
   140         CleanupStack::PopAndDestroy( buf );
       
   141         }
       
   142 
       
   143     CleanupStack::PopAndDestroy( &wsSession );
       
   144     }