| author | teknolog | 
| Thu, 25 Feb 2010 21:08:38 +0000 | |
| changeset 15 | 93d9f66bf50b | 
| parent 14 | 4e75731546eb | 
| child 24 | ca50ea154990 | 
| 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 | #include <akntitle.h> | |
| 41 | ||
| 42 | const TInt KMaxFeedNameLength = 100; | |
| 43 | const TInt KDefaultGran = 5; | |
| 44 | const TInt KNumberOfFilesMaxLength = 4; | |
| 45 | #define KMaxMessageLength 200 | |
| 46 | #define KMaxTitleLength 100 | |
| 47 | const TInt KMimeBufLength = 100; | |
| 48 | ||
| 49 | _LIT(KUnknownUpdateDateString, "?/?"); | |
| 50 | _LIT(KSearchResultFormat, "%d\t%S\t%S"); | |
| 51 | ||
| 52 | CPodcastSearchView* CPodcastSearchView::NewL(CPodcastModel& aPodcastModel) | |
| 53 |     {
 | |
| 54 | CPodcastSearchView* self = CPodcastSearchView::NewLC(aPodcastModel); | |
| 55 | CleanupStack::Pop( self ); | |
| 56 | return self; | |
| 57 | } | |
| 58 | ||
| 59 | CPodcastSearchView* CPodcastSearchView::NewLC(CPodcastModel& aPodcastModel) | |
| 60 |     {
 | |
| 61 | CPodcastSearchView* self = new ( ELeave ) CPodcastSearchView(aPodcastModel); | |
| 62 | CleanupStack::PushL( self ); | |
| 63 | self->ConstructL(); | |
| 64 | return self; | |
| 65 | } | |
| 66 | ||
| 67 | CPodcastSearchView::CPodcastSearchView(CPodcastModel& aPodcastModel):iPodcastModel(aPodcastModel) | |
| 68 | {
 | |
| 69 | } | |
| 70 | ||
| 71 | void CPodcastSearchView::ConstructL() | |
| 72 | {
 | |
| 73 | BaseConstructL(R_PODCAST_SEARCHVIEW); | |
| 74 | CPodcastListView::ConstructL(); | |
| 75 | iPodcastModel.FeedEngine().AddObserver(this); | |
| 76 | CArrayPtr< CGulIcon >* icons = new(ELeave) CArrayPtrFlat< CGulIcon >(1); | |
| 77 | CleanupStack::PushL( icons ); | |
| 78 | ||
| 79 | // Load the bitmap for empty icon | |
| 80 | CFbsBitmap* bitmap = NULL; | |
| 81 | CFbsBitmap* mask = NULL;// | |
| 82 | ||
| 83 | // Load the bitmap for feed icon | |
| 84 | ||
| 85 | // Load svg.-image and mask with a single call | |
| 86 | AknIconUtils::CreateIconL(bitmap, | |
| 87 | mask, | |
| 88 | iEikonEnv->EikAppUi()->Application()->BitmapStoreName(), | |
| 89 | EMbmPodcastFeed, | |
| 90 | EMbmPodcastFeed_mask); | |
| 91 | /* | |
| 92 | 	bitmap = iEikonEnv->CreateBitmapL( _L("*"),EMbmPodcastFeed_40x40);*/
 | |
| 93 | CleanupStack::PushL( bitmap ); | |
| 94 | // Load the mask for feed icon | |
| 95 | 	/*mask = iEikonEnv->CreateBitmapL( _L("*"),EMbmPodcastFeed_40x40m );	
 | |
| 96 | */ | |
| 97 | CleanupStack::PushL( mask ); | |
| 98 | // Append the feed icon to icon array | |
| 99 | icons->AppendL( CGulIcon::NewL( bitmap, mask ) ); | |
| 100 | CleanupStack::Pop(2); // bitmap, mask | |
| 101 | ||
| 102 | iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons ); | |
| 103 | CleanupStack::Pop(icons); // icons | |
| 104 | ||
| 105 | iListContainer->Listbox()->SetListBoxObserver(this); | |
| 106 | ||
| 107 | SetEmptyTextL(R_PODCAST_EMPTY_SEARCH); | |
| 108 | } | |
| 109 | ||
| 110 | CPodcastSearchView::~CPodcastSearchView() | |
| 111 |     {
 | |
| 112 | iPodcastModel.FeedEngine().RemoveObserver(this); | |
| 113 | ||
| 114 | if(iLongTapDetector) | |
| 115 | delete iLongTapDetector, iLongTapDetector = NULL; | |
| 116 | ||
| 117 | if(iStylusPopupMenu) | |
| 118 | delete iStylusPopupMenu, iStylusPopupMenu = NULL; | |
| 119 | ||
| 120 | } | |
| 121 | ||
| 122 | TUid CPodcastSearchView::Id() const | |
| 123 | {
 | |
| 124 | return KUidPodcastSearchViewID; | |
| 125 | } | |
| 126 | ||
| 127 | void CPodcastSearchView::DoActivateL(const TVwsViewId& aPrevViewId, | |
| 128 | TUid aCustomMessageId, | |
| 129 | const TDesC8& aCustomMessage) | |
| 130 | {
 | |
| 131 | UpdateToolbar(); | |
| 132 | ||
| 133 | CAknTitlePane* titlePane = static_cast<CAknTitlePane*> | |
| 134 | ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); | |
| 135 | ||
| 136 | HBufC* title = iEikonEnv->AllocReadResourceLC(R_SEARCH_RESULTS); | |
| 137 | titlePane->SetTextL( *title, ETrue ); | |
| 138 | CleanupStack::PopAndDestroy(title); | |
| 139 | ||
| 140 | CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage); | |
| 141 | iPreviousView = TVwsViewId(KUidPodcast, KUidPodcastFeedViewID); | |
| 142 | } | |
| 143 | ||
| 144 | void CPodcastSearchView::DoDeactivate() | |
| 145 | {
 | |
| 146 | CPodcastListView::DoDeactivate(); | |
| 147 | CAknTitlePane* titlePane = static_cast<CAknTitlePane*> | |
| 148 | ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); | |
| 149 | titlePane->SetTextToDefaultL(); | |
| 11 | 150 | ((CPodcastAppUi*)AppUi())->SetTabsVisibleL(ETrue); | 
| 2 | 151 | } | 
| 152 | ||
| 153 | ||
| 154 | void CPodcastSearchView::HandleListBoxEventL(CEikListBox* /* aListBox */, TListBoxEvent aEventType) | |
| 155 | {
 | |
| 156 | 	DP("CPodcastSearchView::HandleListBoxEventL BEGIN");
 | |
| 157 | switch(aEventType) | |
| 158 | 	{
 | |
| 159 | case EEventEnterKeyPressed: | |
| 160 | case EEventItemDoubleClicked: | |
| 161 | case EEventItemActioned: | |
| 162 | 		{
 | |
| 163 | HandleCommandL(EPodcastAddSearchResult); | |
| 164 | } | |
| 165 | break; | |
| 166 | default: | |
| 167 | break; | |
| 168 | } | |
| 169 | 	DP("CPodcastSearchView::HandleListBoxEventL END");
 | |
| 170 | } | |
| 171 | ||
| 172 | void CPodcastSearchView::UpdateListboxItemsL() | |
| 173 | 	{
 | |
| 174 | 	DP("CPodcastSearchView::UpdateListboxItemsL BEGIN");
 | |
| 175 | 	if(!iListContainer->IsVisible()) {
 | |
| 176 | 		DP("CPodcastSearchView::UpdateListboxItemsL END (not visible)");
 | |
| 177 | return; | |
| 178 | } | |
| 179 | const RFeedInfoArray* searchItems = NULL; | |
| 180 | searchItems = &iPodcastModel.FeedEngine().GetSearchResults(); | |
| 181 | TInt len = searchItems->Count(); | |
| 182 | TListItemProperties itemProps; | |
| 183 | iListContainer->Listbox()->Reset(); | |
| 184 | iListContainer->Listbox()->ItemDrawer()->ClearAllPropertiesL(); | |
| 185 | iItemIdArray.Reset(); | |
| 186 | iItemArray->Reset(); | |
| 187 | ||
| 188 | if (len > 0) | |
| 189 | 		{
 | |
| 190 | for (int i=0;i<len;i++) | |
| 191 | 			{				
 | |
| 192 | CFeedInfo *fi = (*searchItems)[i]; | |
| 193 | iItemIdArray.Append(fi->Uid()); | |
| 194 | TInt iconIndex = 0; | |
| 195 | ||
| 196 | TBuf<512> descr; | |
| 197 | descr.Copy(fi->Description().Left(512)); | |
| 15 
93d9f66bf50b
Cleaning description better for second line in search results
 teknolog parents: 
14diff
changeset | 198 | PodcastUtils::RemoveAllFormatting(descr); | 
| 2 | 199 | iListboxFormatbuffer.Format(KSearchResultFormat(), iconIndex, &fi->Title(), &descr); | 
| 200 | iItemArray->AppendL(iListboxFormatbuffer); | |
| 201 | iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(i, itemProps); | |
| 202 | } | |
| 203 | } | |
| 204 | else | |
| 205 | 		{					
 | |
| 206 | TBuf<KMaxFeedNameLength> itemName; | |
| 207 | iEikonEnv->ReadResourceL(itemName, R_PODCAST_NO_SEARCH_RESULTS); | |
| 208 | iItemArray->Reset(); | |
| 209 | iItemIdArray.Reset(); | |
| 210 | ||
| 211 | TListItemProperties itemProps; | |
| 212 | itemProps.SetDimmed(ETrue); | |
| 213 | itemProps.SetHiddenSelection(ETrue); | |
| 214 | iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps); | |
| 215 | } | |
| 216 | iListContainer->Listbox()->HandleItemAdditionL(); | |
| 217 | 	DP("CPodcastSearchView::UpdateListboxItemsL END");
 | |
| 218 | } | |
| 219 | ||
| 220 | /** | |
| 221 | * Command handling function intended for overriding by sub classes. | |
| 222 | * Default implementation is empty. | |
| 223 | * @param aCommand ID of the command to respond to. | |
| 224 | */ | |
| 225 | void CPodcastSearchView::HandleCommandL(TInt aCommand) | |
| 226 | 	{
 | |
| 227 | //CloseToolbarExtension(); | |
| 228 | switch(aCommand) | |
| 229 | 		{
 | |
| 230 | case EPodcastAddSearchResult: | |
| 231 | 			{
 | |
| 232 | TInt index = iListContainer->Listbox()->CurrentItemIndex(); | |
| 233 | ||
| 234 | if(index < iItemArray->MdcaCount() && index >= 0) | |
| 235 | 				{
 | |
| 236 | CFeedInfo *newInfo = iPodcastModel.FeedEngine().GetSearchResults()[index]; | |
| 237 | ||
| 238 | // ask if user wants to add the feed | |
| 239 | TBuf<KMaxMessageLength> templ; | |
| 240 | TBuf<KMaxMessageLength> message; | |
| 241 | ||
| 242 | iEikonEnv->ReadResourceL(templ, R_ADD_FEED_QUERY); | |
| 243 | message.Format(templ, &newInfo->Title()); | |
| 244 | 				if(ShowQueryMessage(message)) {
 | |
| 245 | TBool added = iPodcastModel.FeedEngine().AddFeedL(*newInfo); | |
| 246 | ||
| 247 | if (added) | |
| 248 | 						{					
 | |
| 249 | // ask if user wants to update it now | |
| 250 | TBuf<KMaxMessageLength> message; | |
| 251 | iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS); | |
| 252 | if(ShowQueryMessage(message)) | |
| 253 | 							{
 | |
| 254 | CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(newInfo->Uid()); | |
| 255 | ||
| 256 | iPodcastModel.ActiveShowList().Reset(); | |
| 257 | iPodcastModel.SetActiveFeedInfo(info); | |
| 258 | AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID, TUid::Uid(0), KNullDesC8()); | |
| 259 | iPodcastModel.FeedEngine().UpdateFeedL(info->Uid()); | |
| 260 | } | |
| 261 | } | |
| 262 | else | |
| 263 | 						{
 | |
| 264 | TBuf<KMaxMessageLength> message; | |
| 265 | iEikonEnv->ReadResourceL(message, R_ADD_FEED_EXISTS); | |
| 266 | ShowErrorMessage(message); | |
| 267 | } | |
| 268 | } | |
| 269 | } | |
| 270 | } | |
| 271 | break; | |
| 272 | default: | |
| 273 | CPodcastListView::HandleCommandL(aCommand); | |
| 274 | break; | |
| 275 | } | |
| 276 | UpdateToolbar(); | |
| 277 | } | |
| 278 | ||
| 7 | 279 | void CPodcastSearchView::OpmlParsingComplete(TInt /*aError*/, TUint /*aNumFeedsImported*/) | 
| 2 | 280 | 	{
 | 
| 281 | 	DP("CPodcastSearchView::OpmlParsingComplete BEGIN");
 | |
| 282 | UpdateListboxItemsL(); | |
| 283 | UpdateToolbar(); | |
| 284 | 	DP("CPodcastSearchView::OpmlParsingComplete END");
 | |
| 285 | } | |
| 286 | ||
| 13 | 287 | void CPodcastSearchView::UpdateToolbar(TBool aVisible) | 
| 2 | 288 | {
 | 
| 289 | TBool disableAdd = iItemArray->MdcaCount() == 0 || iSearchRunning; | |
| 290 | ||
| 291 | CAknToolbar* toolbar = Toolbar(); | |
| 292 | ||
| 293 | if (toolbar) | |
| 294 | 		{
 | |
| 14 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 295 | 		if (iListContainer->IsVisible()) {
 | 
| 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 296 | toolbar->SetToolbarVisibility(aVisible); | 
| 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 297 | } | 
| 2 | 298 | toolbar->SetItemDimmed(EPodcastAddSearchResult, disableAdd, ETrue ); | 
| 299 | toolbar->HideItem(EPodcastSearch, iSearchRunning, ETrue ); | |
| 300 | toolbar->HideItem(EPodcastCancelUpdateAllFeeds, !iSearchRunning, ETrue); | |
| 301 | } | |
| 302 | } |