| author | teknolog | 
| Mon, 05 Apr 2010 13:54:26 +0100 | |
| changeset 84 | 3b59b88b089e | 
| parent 80 | 50345a6ad0c3 | 
| child 92 | 70749e2f572d | 
| permissions | -rw-r--r-- | 
| 2 | 1 | /* | 
| 2 | * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB | |
| 3 | * | |
| 4 | * All rights reserved. | |
| 5 | * This component and the accompanying materials are made available | |
| 6 | * under the terms of the License "Eclipse Public License v1.0" | |
| 7 | * which accompanies this distribution, and is available | |
| 8 | * at the URL "http://www.eclipse.org/legal/epl-v10.html". | |
| 9 | * | |
| 10 | * Initial Contributors: | |
| 11 | * EmbedDev AB - initial contribution. | |
| 12 | * | |
| 13 | * Contributors: | |
| 14 | * | |
| 15 | * Description: | |
| 16 | * | |
| 17 | */ | |
| 18 | ||
| 19 | #include "PodcastSearchView.h" | |
| 20 | #include "PodcastAppUi.h" | |
| 21 | #include "FeedEngine.h" | |
| 22 | #include "ShowEngine.h" | |
| 23 | #include "SettingsEngine.h" | |
| 24 | #include "PodcastApp.h" | |
| 25 | #include "PodcastUtils.h" | |
| 26 | #include <caknfileselectiondialog.h> | |
| 27 | #include <podcast.rsg> | |
| 28 | #include <podcast.mbg> | |
| 29 | #include <gulicon.h> | |
| 30 | #include <eikenv.h> | |
| 31 | #include <e32const.h> | |
| 32 | #include <eikdialg.h> | |
| 33 | #include <aknquerydialog.h> | |
| 34 | #include <caknmemoryselectiondialog.h> | |
| 35 | #include <caknfilenamepromptdialog.h> | |
| 36 | #include <BAUTILS.H> | |
| 37 | #include <pathinfo.h> | |
| 38 | #include <f32file.h> | |
| 39 | #include <akntoolbarextension.h> | |
| 40 | ||
| 41 | const TInt KMaxFeedNameLength = 100; | |
| 42 | const TInt KDefaultGran = 5; | |
| 43 | const TInt KNumberOfFilesMaxLength = 4; | |
| 44 | #define KMaxMessageLength 200 | |
| 45 | #define KMaxTitleLength 100 | |
| 46 | const TInt KMimeBufLength = 100; | |
| 47 | ||
| 48 | _LIT(KUnknownUpdateDateString, "?/?"); | |
| 49 | _LIT(KSearchResultFormat, "%d\t%S\t%S"); | |
| 50 | ||
| 51 | CPodcastSearchView* CPodcastSearchView::NewL(CPodcastModel& aPodcastModel) | |
| 52 |     {
 | |
| 53 | CPodcastSearchView* self = CPodcastSearchView::NewLC(aPodcastModel); | |
| 54 | CleanupStack::Pop( self ); | |
| 55 | return self; | |
| 56 | } | |
| 57 | ||
| 58 | CPodcastSearchView* CPodcastSearchView::NewLC(CPodcastModel& aPodcastModel) | |
| 59 |     {
 | |
| 60 | CPodcastSearchView* self = new ( ELeave ) CPodcastSearchView(aPodcastModel); | |
| 61 | CleanupStack::PushL( self ); | |
| 62 | self->ConstructL(); | |
| 63 | return self; | |
| 64 | } | |
| 65 | ||
| 66 | CPodcastSearchView::CPodcastSearchView(CPodcastModel& aPodcastModel):iPodcastModel(aPodcastModel) | |
| 67 | {
 | |
| 68 | } | |
| 69 | ||
| 70 | void CPodcastSearchView::ConstructL() | |
| 71 | {
 | |
| 72 | BaseConstructL(R_PODCAST_SEARCHVIEW); | |
| 73 | CPodcastListView::ConstructL(); | |
| 74 | iPodcastModel.FeedEngine().AddObserver(this); | |
| 75 | CArrayPtr< CGulIcon >* icons = new(ELeave) CArrayPtrFlat< CGulIcon >(1); | |
| 76 | CleanupStack::PushL( icons ); | |
| 77 | ||
| 78 | // Load the bitmap for empty icon | |
| 79 | CFbsBitmap* bitmap = NULL; | |
| 80 | CFbsBitmap* mask = NULL;// | |
| 81 | ||
| 82 | // Load the bitmap for feed icon | |
| 83 | ||
| 84 | // Load svg.-image and mask with a single call | |
| 85 | AknIconUtils::CreateIconL(bitmap, | |
| 86 | mask, | |
| 87 | iEikonEnv->EikAppUi()->Application()->BitmapStoreName(), | |
| 88 | EMbmPodcastFeed, | |
| 89 | EMbmPodcastFeed_mask); | |
| 90 | /* | |
| 91 | 	bitmap = iEikonEnv->CreateBitmapL( _L("*"),EMbmPodcastFeed_40x40);*/
 | |
| 92 | CleanupStack::PushL( bitmap ); | |
| 93 | // Load the mask for feed icon | |
| 94 | 	/*mask = iEikonEnv->CreateBitmapL( _L("*"),EMbmPodcastFeed_40x40m );	
 | |
| 95 | */ | |
| 96 | CleanupStack::PushL( mask ); | |
| 97 | // Append the feed icon to icon array | |
| 98 | icons->AppendL( CGulIcon::NewL( bitmap, mask ) ); | |
| 99 | CleanupStack::Pop(2); // bitmap, mask | |
| 100 | ||
| 101 | iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons ); | |
| 102 | CleanupStack::Pop(icons); // icons | |
| 103 | ||
| 104 | iListContainer->Listbox()->SetListBoxObserver(this); | |
| 105 | ||
| 106 | SetEmptyTextL(R_PODCAST_EMPTY_SEARCH); | |
| 107 | } | |
| 108 | ||
| 109 | CPodcastSearchView::~CPodcastSearchView() | |
| 110 |     {
 | |
| 111 | iPodcastModel.FeedEngine().RemoveObserver(this); | |
| 112 | ||
| 113 | if(iLongTapDetector) | |
| 114 | delete iLongTapDetector, iLongTapDetector = NULL; | |
| 115 | ||
| 116 | if(iStylusPopupMenu) | |
| 117 | delete iStylusPopupMenu, iStylusPopupMenu = NULL; | |
| 118 | ||
| 119 | } | |
| 120 | ||
| 121 | TUid CPodcastSearchView::Id() const | |
| 122 | {
 | |
| 123 | return KUidPodcastSearchViewID; | |
| 124 | } | |
| 125 | ||
| 126 | void CPodcastSearchView::DoActivateL(const TVwsViewId& aPrevViewId, | |
| 127 | TUid aCustomMessageId, | |
| 128 | const TDesC8& aCustomMessage) | |
| 129 | {
 | |
| 130 | CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage); | |
| 131 | iPreviousView = TVwsViewId(KUidPodcast, KUidPodcastFeedViewID); | |
| 49 
43e204e6ae2e
Fix for accidental merge regressions. Text fixes for tool tip and settings.
 teknolog parents: 
24diff
changeset | 132 | |
| 
43e204e6ae2e
Fix for accidental merge regressions. Text fixes for tool tip and settings.
 teknolog parents: 
24diff
changeset | 133 | ((CPodcastAppUi*)AppUi())->NaviSetTextL(R_SEARCH_RESULTS); | 
| 54 | 134 | |
| 135 | UpdateListboxItemsL(); | |
| 49 
43e204e6ae2e
Fix for accidental merge regressions. Text fixes for tool tip and settings.
 teknolog parents: 
24diff
changeset | 136 | UpdateToolbar(); | 
| 2 | 137 | } | 
| 138 | ||
| 139 | void CPodcastSearchView::DoDeactivate() | |
| 140 | {
 | |
| 141 | CPodcastListView::DoDeactivate(); | |
| 84 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
80diff
changeset | 142 | TRAP_IGNORE(((CPodcastAppUi*)AppUi())->NaviShowTabGroupL()); | 
| 2 | 143 | } | 
| 144 | ||
| 145 | ||
| 146 | void CPodcastSearchView::HandleListBoxEventL(CEikListBox* /* aListBox */, TListBoxEvent aEventType) | |
| 147 | {
 | |
| 148 | 	DP("CPodcastSearchView::HandleListBoxEventL BEGIN");
 | |
| 149 | switch(aEventType) | |
| 150 | 	{
 | |
| 151 | case EEventEnterKeyPressed: | |
| 152 | case EEventItemDoubleClicked: | |
| 153 | case EEventItemActioned: | |
| 154 | 		{
 | |
| 155 | HandleCommandL(EPodcastAddSearchResult); | |
| 156 | } | |
| 157 | break; | |
| 158 | default: | |
| 159 | break; | |
| 160 | } | |
| 161 | 	DP("CPodcastSearchView::HandleListBoxEventL END");
 | |
| 162 | } | |
| 163 | ||
| 164 | void CPodcastSearchView::UpdateListboxItemsL() | |
| 165 | 	{
 | |
| 166 | 	DP("CPodcastSearchView::UpdateListboxItemsL BEGIN");
 | |
| 167 | 	if(!iListContainer->IsVisible()) {
 | |
| 168 | 		DP("CPodcastSearchView::UpdateListboxItemsL END (not visible)");
 | |
| 169 | return; | |
| 170 | } | |
| 171 | const RFeedInfoArray* searchItems = NULL; | |
| 172 | searchItems = &iPodcastModel.FeedEngine().GetSearchResults(); | |
| 173 | TInt len = searchItems->Count(); | |
| 174 | TListItemProperties itemProps; | |
| 175 | iListContainer->Listbox()->Reset(); | |
| 176 | iListContainer->Listbox()->ItemDrawer()->ClearAllPropertiesL(); | |
| 177 | iItemIdArray.Reset(); | |
| 178 | iItemArray->Reset(); | |
| 179 | ||
| 180 | if (len > 0) | |
| 181 | 		{
 | |
| 182 | for (int i=0;i<len;i++) | |
| 183 | 			{				
 | |
| 184 | CFeedInfo *fi = (*searchItems)[i]; | |
| 185 | iItemIdArray.Append(fi->Uid()); | |
| 186 | TInt iconIndex = 0; | |
| 187 | ||
| 188 | TBuf<512> descr; | |
| 189 | descr.Copy(fi->Description().Left(512)); | |
| 15 
93d9f66bf50b
Cleaning description better for second line in search results
 teknolog parents: 
14diff
changeset | 190 | PodcastUtils::RemoveAllFormatting(descr); | 
| 2 | 191 | iListboxFormatbuffer.Format(KSearchResultFormat(), iconIndex, &fi->Title(), &descr); | 
| 192 | iItemArray->AppendL(iListboxFormatbuffer); | |
| 193 | iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(i, itemProps); | |
| 194 | } | |
| 195 | } | |
| 196 | else | |
| 197 | 		{					
 | |
| 198 | TBuf<KMaxFeedNameLength> itemName; | |
| 199 | iEikonEnv->ReadResourceL(itemName, R_PODCAST_NO_SEARCH_RESULTS); | |
| 200 | iItemArray->Reset(); | |
| 201 | iItemIdArray.Reset(); | |
| 202 | ||
| 203 | TListItemProperties itemProps; | |
| 204 | itemProps.SetDimmed(ETrue); | |
| 205 | itemProps.SetHiddenSelection(ETrue); | |
| 206 | iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps); | |
| 207 | } | |
| 208 | iListContainer->Listbox()->HandleItemAdditionL(); | |
| 209 | 	DP("CPodcastSearchView::UpdateListboxItemsL END");
 | |
| 210 | } | |
| 211 | ||
| 212 | /** | |
| 213 | * Command handling function intended for overriding by sub classes. | |
| 214 | * Default implementation is empty. | |
| 215 | * @param aCommand ID of the command to respond to. | |
| 216 | */ | |
| 217 | void CPodcastSearchView::HandleCommandL(TInt aCommand) | |
| 218 | 	{
 | |
| 219 | //CloseToolbarExtension(); | |
| 220 | switch(aCommand) | |
| 221 | 		{
 | |
| 222 | case EPodcastAddSearchResult: | |
| 223 | 			{
 | |
| 224 | TInt index = iListContainer->Listbox()->CurrentItemIndex(); | |
| 225 | ||
| 226 | if(index < iItemArray->MdcaCount() && index >= 0) | |
| 227 | 				{
 | |
| 228 | CFeedInfo *newInfo = iPodcastModel.FeedEngine().GetSearchResults()[index]; | |
| 229 | ||
| 230 | // ask if user wants to add the feed | |
| 231 | TBuf<KMaxMessageLength> templ; | |
| 232 | TBuf<KMaxMessageLength> message; | |
| 233 | ||
| 234 | iEikonEnv->ReadResourceL(templ, R_ADD_FEED_QUERY); | |
| 235 | message.Format(templ, &newInfo->Title()); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
24diff
changeset | 236 | 				if(ShowQueryMessageL(message)) {
 | 
| 2 | 237 | TBool added = iPodcastModel.FeedEngine().AddFeedL(*newInfo); | 
| 238 | ||
| 239 | if (added) | |
| 240 | 						{					
 | |
| 241 | // ask if user wants to update it now | |
| 242 | TBuf<KMaxMessageLength> message; | |
| 243 | iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
24diff
changeset | 244 | if(ShowQueryMessageL(message)) | 
| 2 | 245 | 							{
 | 
| 246 | CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(newInfo->Uid()); | |
| 247 | ||
| 248 | iPodcastModel.SetActiveFeedInfo(info); | |
| 249 | AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID, TUid::Uid(0), KNullDesC8()); | |
| 250 | iPodcastModel.FeedEngine().UpdateFeedL(info->Uid()); | |
| 251 | } | |
| 252 | } | |
| 253 | else | |
| 254 | 						{
 | |
| 255 | TBuf<KMaxMessageLength> message; | |
| 256 | iEikonEnv->ReadResourceL(message, R_ADD_FEED_EXISTS); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
24diff
changeset | 257 | ShowErrorMessageL(message); | 
| 2 | 258 | } | 
| 259 | } | |
| 260 | } | |
| 261 | } | |
| 262 | break; | |
| 263 | default: | |
| 264 | CPodcastListView::HandleCommandL(aCommand); | |
| 265 | break; | |
| 266 | } | |
| 267 | UpdateToolbar(); | |
| 268 | } | |
| 269 | ||
| 7 | 270 | void CPodcastSearchView::OpmlParsingComplete(TInt /*aError*/, TUint /*aNumFeedsImported*/) | 
| 2 | 271 | 	{
 | 
| 272 | 	DP("CPodcastSearchView::OpmlParsingComplete BEGIN");
 | |
| 54 | 273 | |
| 2 | 274 | 	DP("CPodcastSearchView::OpmlParsingComplete END");
 | 
| 275 | } | |
| 276 | ||
| 13 | 277 | void CPodcastSearchView::UpdateToolbar(TBool aVisible) | 
| 2 | 278 | {
 | 
| 279 | TBool disableAdd = iItemArray->MdcaCount() == 0 || iSearchRunning; | |
| 280 | ||
| 281 | CAknToolbar* toolbar = Toolbar(); | |
| 282 | ||
| 283 | if (toolbar) | |
| 284 | 		{
 | |
| 14 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 285 | 		if (iListContainer->IsVisible()) {
 | 
| 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 286 | toolbar->SetToolbarVisibility(aVisible); | 
| 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 287 | } | 
| 2 | 288 | toolbar->SetItemDimmed(EPodcastAddSearchResult, disableAdd, ETrue ); | 
| 289 | toolbar->HideItem(EPodcastSearch, iSearchRunning, ETrue ); | |
| 290 | toolbar->HideItem(EPodcastCancelUpdateAllFeeds, !iSearchRunning, ETrue); | |
| 291 | } | |
| 292 | } |