| author | teknolog | 
| Sun, 28 Feb 2010 19:35:33 +0000 | |
| changeset 24 | ca50ea154990 | 
| parent 15 | 93d9f66bf50b | 
| child 35 | 66c5303f3610 | 
| child 49 | 43e204e6ae2e | 
| child 60 | 4d230e702aa3 | 
| 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 ) ) ); | |
| 24 
ca50ea154990
Moved search result title to navipane. Fixed but 1832
 teknolog parents: 
15diff
changeset | 135 | |
| 
ca50ea154990
Moved search result title to navipane. Fixed but 1832
 teknolog parents: 
15diff
changeset | 136 | ((CPodcastAppUi*)AppUi())->NaviSetTextL(R_SEARCH_RESULTS); | 
| 
ca50ea154990
Moved search result title to navipane. Fixed but 1832
 teknolog parents: 
15diff
changeset | 137 | |
| 2 | 138 | CPodcastListView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage); | 
| 139 | iPreviousView = TVwsViewId(KUidPodcast, KUidPodcastFeedViewID); | |
| 140 | } | |
| 141 | ||
| 142 | void CPodcastSearchView::DoDeactivate() | |
| 143 | {
 | |
| 144 | CPodcastListView::DoDeactivate(); | |
| 145 | CAknTitlePane* titlePane = static_cast<CAknTitlePane*> | |
| 146 | ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); | |
| 147 | titlePane->SetTextToDefaultL(); | |
| 24 
ca50ea154990
Moved search result title to navipane. Fixed but 1832
 teknolog parents: 
15diff
changeset | 148 | ((CPodcastAppUi*)AppUi())->NaviShowTabGroupL(); | 
| 2 | 149 | } | 
| 150 | ||
| 151 | ||
| 152 | void CPodcastSearchView::HandleListBoxEventL(CEikListBox* /* aListBox */, TListBoxEvent aEventType) | |
| 153 | {
 | |
| 154 | 	DP("CPodcastSearchView::HandleListBoxEventL BEGIN");
 | |
| 155 | switch(aEventType) | |
| 156 | 	{
 | |
| 157 | case EEventEnterKeyPressed: | |
| 158 | case EEventItemDoubleClicked: | |
| 159 | case EEventItemActioned: | |
| 160 | 		{
 | |
| 161 | HandleCommandL(EPodcastAddSearchResult); | |
| 162 | } | |
| 163 | break; | |
| 164 | default: | |
| 165 | break; | |
| 166 | } | |
| 167 | 	DP("CPodcastSearchView::HandleListBoxEventL END");
 | |
| 168 | } | |
| 169 | ||
| 170 | void CPodcastSearchView::UpdateListboxItemsL() | |
| 171 | 	{
 | |
| 172 | 	DP("CPodcastSearchView::UpdateListboxItemsL BEGIN");
 | |
| 173 | 	if(!iListContainer->IsVisible()) {
 | |
| 174 | 		DP("CPodcastSearchView::UpdateListboxItemsL END (not visible)");
 | |
| 175 | return; | |
| 176 | } | |
| 177 | const RFeedInfoArray* searchItems = NULL; | |
| 178 | searchItems = &iPodcastModel.FeedEngine().GetSearchResults(); | |
| 179 | TInt len = searchItems->Count(); | |
| 180 | TListItemProperties itemProps; | |
| 181 | iListContainer->Listbox()->Reset(); | |
| 182 | iListContainer->Listbox()->ItemDrawer()->ClearAllPropertiesL(); | |
| 183 | iItemIdArray.Reset(); | |
| 184 | iItemArray->Reset(); | |
| 185 | ||
| 186 | if (len > 0) | |
| 187 | 		{
 | |
| 188 | for (int i=0;i<len;i++) | |
| 189 | 			{				
 | |
| 190 | CFeedInfo *fi = (*searchItems)[i]; | |
| 191 | iItemIdArray.Append(fi->Uid()); | |
| 192 | TInt iconIndex = 0; | |
| 193 | ||
| 194 | TBuf<512> descr; | |
| 195 | descr.Copy(fi->Description().Left(512)); | |
| 15 
93d9f66bf50b
Cleaning description better for second line in search results
 teknolog parents: 
14diff
changeset | 196 | PodcastUtils::RemoveAllFormatting(descr); | 
| 2 | 197 | iListboxFormatbuffer.Format(KSearchResultFormat(), iconIndex, &fi->Title(), &descr); | 
| 198 | iItemArray->AppendL(iListboxFormatbuffer); | |
| 199 | iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(i, itemProps); | |
| 200 | } | |
| 201 | } | |
| 202 | else | |
| 203 | 		{					
 | |
| 204 | TBuf<KMaxFeedNameLength> itemName; | |
| 205 | iEikonEnv->ReadResourceL(itemName, R_PODCAST_NO_SEARCH_RESULTS); | |
| 206 | iItemArray->Reset(); | |
| 207 | iItemIdArray.Reset(); | |
| 208 | ||
| 209 | TListItemProperties itemProps; | |
| 210 | itemProps.SetDimmed(ETrue); | |
| 211 | itemProps.SetHiddenSelection(ETrue); | |
| 212 | iListContainer->Listbox()->ItemDrawer()->SetPropertiesL(0, itemProps); | |
| 213 | } | |
| 214 | iListContainer->Listbox()->HandleItemAdditionL(); | |
| 215 | 	DP("CPodcastSearchView::UpdateListboxItemsL END");
 | |
| 216 | } | |
| 217 | ||
| 218 | /** | |
| 219 | * Command handling function intended for overriding by sub classes. | |
| 220 | * Default implementation is empty. | |
| 221 | * @param aCommand ID of the command to respond to. | |
| 222 | */ | |
| 223 | void CPodcastSearchView::HandleCommandL(TInt aCommand) | |
| 224 | 	{
 | |
| 225 | //CloseToolbarExtension(); | |
| 226 | switch(aCommand) | |
| 227 | 		{
 | |
| 228 | case EPodcastAddSearchResult: | |
| 229 | 			{
 | |
| 230 | TInt index = iListContainer->Listbox()->CurrentItemIndex(); | |
| 231 | ||
| 232 | if(index < iItemArray->MdcaCount() && index >= 0) | |
| 233 | 				{
 | |
| 234 | CFeedInfo *newInfo = iPodcastModel.FeedEngine().GetSearchResults()[index]; | |
| 235 | ||
| 236 | // ask if user wants to add the feed | |
| 237 | TBuf<KMaxMessageLength> templ; | |
| 238 | TBuf<KMaxMessageLength> message; | |
| 239 | ||
| 240 | iEikonEnv->ReadResourceL(templ, R_ADD_FEED_QUERY); | |
| 241 | message.Format(templ, &newInfo->Title()); | |
| 242 | 				if(ShowQueryMessage(message)) {
 | |
| 243 | TBool added = iPodcastModel.FeedEngine().AddFeedL(*newInfo); | |
| 244 | ||
| 245 | if (added) | |
| 246 | 						{					
 | |
| 247 | // ask if user wants to update it now | |
| 248 | TBuf<KMaxMessageLength> message; | |
| 249 | iEikonEnv->ReadResourceL(message, R_ADD_FEED_SUCCESS); | |
| 250 | if(ShowQueryMessage(message)) | |
| 251 | 							{
 | |
| 252 | CFeedInfo *info = iPodcastModel.FeedEngine().GetFeedInfoByUid(newInfo->Uid()); | |
| 253 | ||
| 254 | iPodcastModel.ActiveShowList().Reset(); | |
| 255 | iPodcastModel.SetActiveFeedInfo(info); | |
| 256 | AppUi()->ActivateLocalViewL(KUidPodcastShowsViewID, TUid::Uid(0), KNullDesC8()); | |
| 257 | iPodcastModel.FeedEngine().UpdateFeedL(info->Uid()); | |
| 258 | } | |
| 259 | } | |
| 260 | else | |
| 261 | 						{
 | |
| 262 | TBuf<KMaxMessageLength> message; | |
| 263 | iEikonEnv->ReadResourceL(message, R_ADD_FEED_EXISTS); | |
| 264 | ShowErrorMessage(message); | |
| 265 | } | |
| 266 | } | |
| 267 | } | |
| 268 | } | |
| 269 | break; | |
| 270 | default: | |
| 271 | CPodcastListView::HandleCommandL(aCommand); | |
| 272 | break; | |
| 273 | } | |
| 274 | UpdateToolbar(); | |
| 275 | } | |
| 276 | ||
| 7 | 277 | void CPodcastSearchView::OpmlParsingComplete(TInt /*aError*/, TUint /*aNumFeedsImported*/) | 
| 2 | 278 | 	{
 | 
| 279 | 	DP("CPodcastSearchView::OpmlParsingComplete BEGIN");
 | |
| 280 | UpdateListboxItemsL(); | |
| 281 | UpdateToolbar(); | |
| 282 | 	DP("CPodcastSearchView::OpmlParsingComplete END");
 | |
| 283 | } | |
| 284 | ||
| 13 | 285 | void CPodcastSearchView::UpdateToolbar(TBool aVisible) | 
| 2 | 286 | {
 | 
| 287 | TBool disableAdd = iItemArray->MdcaCount() == 0 || iSearchRunning; | |
| 288 | ||
| 289 | CAknToolbar* toolbar = Toolbar(); | |
| 290 | ||
| 291 | if (toolbar) | |
| 292 | 		{
 | |
| 14 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 293 | 		if (iListContainer->IsVisible()) {
 | 
| 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 294 | toolbar->SetToolbarVisibility(aVisible); | 
| 
4e75731546eb
Fix so toolbars only change visibility for the visible view
 teknolog parents: 
13diff
changeset | 295 | } | 
| 2 | 296 | toolbar->SetItemDimmed(EPodcastAddSearchResult, disableAdd, ETrue ); | 
| 297 | toolbar->HideItem(EPodcastSearch, iSearchRunning, ETrue ); | |
| 298 | toolbar->HideItem(EPodcastCancelUpdateAllFeeds, !iSearchRunning, ETrue); | |
| 299 | } | |
| 300 | } |