browserutilities/feedsengine/FeedsUI/FeedsApp/src/FeedsDocument.cpp
changeset 0 dd21522fd290
child 36 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Feeds application's document instance.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AiwGenericParam.h>
       
    20 #include <StringLoader.h>
       
    21 
       
    22 #include <FeedsApp.rsg>
       
    23 
       
    24 #include "FeedsAppUi.h"
       
    25 #include "FeedsDocument.h"
       
    26 #include "LeakTracker.h"
       
    27 #include "Logger.h"
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CFeedsDocument::CFeedsDocument()
       
    32 //
       
    33 // C++ default constructor can NOT contain any code, that might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CFeedsDocument::CFeedsDocument(CEikApplication& aApp):
       
    37         CAiwGenericParamConsumer(aApp)
       
    38     {
       
    39     LEAK_TRACKER_INCREMENT(CLeakTracker::EFeedsDocument);
       
    40     }
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CFeedsDocument::NewL()
       
    45 //
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CFeedsDocument* CFeedsDocument::NewL(CEikApplication& aApp)
       
    50     {
       
    51     CFeedsDocument* self = NewLC(aApp);
       
    52     CleanupStack::Pop(self);
       
    53 
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CFeedsDocument::NewLC()
       
    60 //
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CFeedsDocument* CFeedsDocument::NewLC(CEikApplication& aApp)
       
    65     {
       
    66     CFeedsDocument* self = new (ELeave) CFeedsDocument(aApp);
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69 
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CFeedsDocument::ConstructL()
       
    76 //
       
    77 // Symbian 2nd phase constructor can leave.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CFeedsDocument::ConstructL()
       
    81     {
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CFeedsDocument::~CFeedsDocument()
       
    87 //
       
    88 // Destructor.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CFeedsDocument::~CFeedsDocument()
       
    92     {
       
    93     LEAK_TRACKER_DECREMENT(CLeakTracker::EFeedsDocument);
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CFeedsDocument::CreateAppUiL()
       
    99 //
       
   100 // Create the application user interface, and return a pointer to it
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CEikAppUi* CFeedsDocument::CreateAppUiL()
       
   104     {
       
   105     return(static_cast<CEikAppUi*>(new (ELeave) CFeedsAppUi));
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CFeedsDocument::OpenFileL()
       
   111 //
       
   112 // Opens a given file from the app-framework.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CFeedsDocument::OpenFileL(CFileStore*& /*aFileStore*/, RFile& /*aFile*/)
       
   116     {
       
   117  #if 0       
       
   118     const CAiwGenericParamList* params = GetInputParameters();
       
   119     const TAiwGenericParam*     param;
       
   120     TPtrC                       url(KNullDesC);
       
   121     TPtrC                       contentType(KNullDesC);
       
   122     TPtrC                       charSet(KNullDesC);
       
   123     TBool                       urlSet = EFalse;
       
   124 //    TInt                        size;
       
   125     HBufC8*                     buffer = NULL;    
       
   126     
       
   127     // Get the url from the parms.
       
   128     if (params)
       
   129         {
       
   130         TInt index;
       
   131 
       
   132         // Source URL.
       
   133         index = 0;
       
   134         param = params->FindFirst(index, EGenericParamURL, EVariantTypeDesC);
       
   135         if (param != NULL)
       
   136             {
       
   137             url.Set(param->Value().AsDes());
       
   138             urlSet = ETrue;
       
   139             }
       
   140 
       
   141         // Content-type.
       
   142         index = 0;
       
   143         param = params->FindFirst(index, EGenericParamMIMEType, EVariantTypeDesC);
       
   144         if (param != NULL)
       
   145             {
       
   146             contentType.Set(param->Value().AsDes());
       
   147             }
       
   148 
       
   149         // Charset.
       
   150         index = 0;
       
   151         param = params->FindFirst(index, EGenericParamCharSet, EVariantTypeDesC);
       
   152         if (param != NULL)
       
   153             {
       
   154             charSet.Set(param->Value().AsDes());
       
   155             }
       
   156         }
       
   157 
       
   158     // Read the buffer from the file.
       
   159     User::LeaveIfError(aFile.Size(size));
       
   160     buffer = HBufC8::NewLC(size);
       
   161     TPtr8 bufferPtr(buffer->Des());
       
   162     
       
   163     User::LeaveIfError(aFile.Read(bufferPtr, size));
       
   164 
       
   165     // If the url was set then subscribe to the Feed.
       
   166     if (urlSet)
       
   167         {
       
   168         SubscribeToL(url, contentType, charSet, *buffer);
       
   169         }
       
   170             
       
   171     // In any case, show the feed using the downloaded buffer.
       
   172     iUpdateTopicViewTask = CUpdateTopicViewTask::NewL(buffer, *this);
       
   173     iUpdateTopicViewTask->StartTaskL();
       
   174     iUpdateTopicViewTask->EnableAutoDeleteL();
       
   175 
       
   176     CleanupStack::Pop(buffer);
       
   177 #endif
       
   178     }
       
   179     
       
   180 #if 0    
       
   181 // -----------------------------------------------------------------------------
       
   182 // CFeedDocument::SubscribeToL
       
   183 // 
       
   184 // Subscribes to a feed, provided via OpenFileL (from an external app).
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CFeedsDocument::SubscribeToL(const TDesC& aUrl, const TDesC& aContentType, 
       
   188         const TDesC& aCharSet, HBufC8& aFeedBuffer)
       
   189     {   
       
   190     TPtr8          bufferPtr(aFeedBuffer.Des());
       
   191     CFeedHandler*  feedHandler = NULL;
       
   192     CFeed*         feed = NULL;
       
   193     const TDesC*   feedName = NULL;
       
   194     HBufC*         noName = NULL;
       
   195 
       
   196     // TODO: This may also be used with an empty aFile -> via an html link element.
       
   197 
       
   198     // Parse the buffer.
       
   199     if (bufferPtr.Length() > 0)
       
   200         {
       
   201         // TODO: could avoid this if we waited until the topic-view is updated.
       
   202         feedHandler = (CFeedHandler*) Singletons::Get(Singletons::EFeedHandler);
       
   203         
       
   204         TRAPD(err, feed = feedHandler->ParseL(&bufferPtr, aContentType, aCharSet));
       
   205         if (err == KErrNone)
       
   206             {
       
   207             CleanupStack::PushL(feed);
       
   208             }
       
   209         }
       
   210     
       
   211     // If possible use the feed's name.
       
   212     if (feed != NULL)
       
   213         {
       
   214         feedName = feed->Get(CFeed::ETitle);
       
   215         }
       
   216        
       
   217     // Otherwise use the default name.        
       
   218     if (feedName == NULL)
       
   219         {
       
   220         noName = StringLoader::LoadLC(R_FEEDS_NEW_FEED_ITEM);
       
   221         feedName = *noName;
       
   222         }
       
   223     
       
   224     // Subscribe to the feed. 
       
   225     SubscribeToL(*feedName, aUrl);
       
   226     
       
   227     // Cleanup
       
   228     if (noName != NULL)
       
   229         {
       
   230         CleanupStack::PopAndDestroy(noName);
       
   231         }
       
   232         
       
   233     if (feed != NULL)
       
   234         {
       
   235         CleanupStack::PopAndDestroy(feed);        
       
   236         }
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CFeedDocument::SubscribeToL
       
   242 // 
       
   243 // Subscribes to a feed.
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CFeedsDocument::SubscribeToL(const TDesC& aName, const TDesC& aUrl)
       
   247     {   
       
   248     CFolderView*  folderView = NULL;
       
   249     
       
   250     // Subscribe to the feed. 
       
   251     folderView = (CFolderView*) Singletons::Get(Singletons::EFolderView);    
       
   252     folderView->ImportFeedL(aName, aUrl);
       
   253     }
       
   254 #endif