DirectPrint/DirectPrintApp/ui/src/directprintlistview.cpp
changeset 19 2275db202402
parent 11 613a5ff70823
equal deleted inserted replaced
2:acc370d7f2f6 19:2275db202402
       
     1 /*
       
     2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd.
       
     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 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // System include files
       
    19 #include <aknviewappui.h>
       
    20 #include <akntoolbar.h>
       
    21 #include <barsread.h>
       
    22 #include <DirectPrintApp.rsg>
       
    23 
       
    24 // User include files go here:
       
    25 #include "clog.h"
       
    26 #include "directprintapp.hrh"
       
    27 #include "directprintmodel.h"
       
    28 #include "directprintlistview.h"
       
    29 
       
    30 CDirectPrintListView::CDirectPrintListView()
       
    31 	{
       
    32 	iListBox = NULL;
       
    33 	}
       
    34 
       
    35 CDirectPrintListView::~CDirectPrintListView()
       
    36 	{
       
    37 	AppUi()->RemoveFromViewStack(*this, iListBox);
       
    38 	delete iListBox;
       
    39 	delete iItemArray;
       
    40 	}
       
    41 
       
    42 CDirectPrintListView* CDirectPrintListView::NewL()
       
    43 	{
       
    44 	CDirectPrintListView* self = CDirectPrintListView::NewLC();
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 CDirectPrintListView* CDirectPrintListView::NewLC()
       
    50 	{
       
    51 	CDirectPrintListView* self = new(ELeave) CDirectPrintListView();
       
    52 	CleanupStack::PushL(self);
       
    53 	self->ConstructL();
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 void CDirectPrintListView::ConstructL()
       
    58 	{
       
    59 	LOG("CDirectPrintListView::ConstructL BEGIN");
       
    60 	BaseConstructL(R_DIRECTPRINT_PRINTERLIST_VIEW);
       
    61 
       
    62 	LOG("CDirectPrintListView::ConstructL 1");
       
    63 	iViewId = TUid::Uid(EDirectPrintPrinterListViewId);
       
    64 
       
    65 	iItemArray = new(ELeave) CDesCArrayFlat(3);
       
    66 	LOG("CDirectPrintListView::ConstructL END");
       
    67 	}
       
    68 
       
    69 void CDirectPrintListView::HandleCommandL(TInt aCommand)
       
    70 	{
       
    71 	switch (aCommand)
       
    72 		{
       
    73 		case EAknSoftkeyDone:
       
    74 			{
       
    75 			TInt index = iListBox->CurrentIndex();
       
    76 			if (index >= 0)
       
    77 				{
       
    78 				GetModel().MoveTopPrinterDataL(index);
       
    79 				}
       
    80 			AppUi()->HandleCommandL(EDirectPrintCmdIdPrinterListViewDone);
       
    81 			}
       
    82 			break;
       
    83 		case EDirectPrintCmdIdPrinterListViewDelete:
       
    84 			{
       
    85 			TInt index = iListBox->DeleteCurrentItemL();
       
    86 			if (index >= 0)
       
    87 				{
       
    88 				GetModel().RemovePrinterDataL(index);
       
    89 				iListBox->SetFocusL(0);
       
    90 				}
       
    91 			AppUi()->HandleCommandL(aCommand);
       
    92 			}
       
    93 			break;
       
    94 		case EDirectPrintCmdIdPrinterListViewNew:
       
    95 			{
       
    96 			PrepareNewDataL();
       
    97 			AppUi()->HandleCommandL(aCommand);
       
    98 			}
       
    99 			break;
       
   100 		default:
       
   101 			{
       
   102 			AppUi()->HandleCommandL(aCommand);
       
   103 			}
       
   104 			break;
       
   105 		}
       
   106 	}
       
   107 
       
   108 void CDirectPrintListView::HandleListIndexL(TInt aIndex)
       
   109 	{
       
   110 	GetModel().SetSelectPrinter(aIndex);
       
   111 	AppUi()->HandleCommandL(EDirectPrintCmdIdPrinterListViewEdit);
       
   112 	}
       
   113 
       
   114 void CDirectPrintListView::OfferToolbarEventL(TInt aCommand)
       
   115 	{
       
   116 	switch (aCommand)
       
   117 		{
       
   118 		case EDirectPrintCmdIdPrinterListViewEdit:
       
   119 			{
       
   120 			TInt index = iListBox->CurrentIndex();
       
   121 			GetModel().SetSelectPrinter(index);
       
   122 			AppUi()->HandleCommandL(aCommand);
       
   123 			}
       
   124 			break;
       
   125 		case EDirectPrintCmdIdPrinterListViewSearch:
       
   126 			{
       
   127 			AppUi()->HandleCommandL(aCommand);
       
   128 			}
       
   129 			break;
       
   130 		case EDirectPrintCmdIdPrinterListViewNew:
       
   131 			{
       
   132 			PrepareNewDataL();
       
   133 			AppUi()->HandleCommandL(aCommand);
       
   134 			}
       
   135 			break;
       
   136 		default:
       
   137 			break;
       
   138 		}
       
   139 	}
       
   140 
       
   141 void CDirectPrintListView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   142 	{
       
   143 	CAknToolbar* toolbar = AppUi()->CurrentFixedToolbar();
       
   144 	toolbar->SetToolbarObserver(this);
       
   145 
       
   146 	iItemArray->Reset();
       
   147 
       
   148 	// Create list box
       
   149 	if (!iListBox)
       
   150 		{
       
   151 		iListBox = CDirectPrintListBox::NewL(ClientRect(), iItemArray);
       
   152 		iListBox->SetMopParent(this);
       
   153 		iListBox->SetListObserver(this);
       
   154 		}
       
   155 	AppUi()->AddToStackL(*this, iListBox);
       
   156 	iListBox->MakeVisible(ETrue);
       
   157 
       
   158 	LoadListDataL();
       
   159 
       
   160 	iListBox->RedrawListL();
       
   161 
       
   162 	// set the title pane
       
   163 	SetActiveTitleL(R_DIRECTPRINT_PRINTERLIST_TITLE);
       
   164 	}
       
   165 
       
   166 void CDirectPrintListView::DoDeactivate()
       
   167 	{
       
   168 	iListBox->MakeVisible(EFalse);
       
   169 	AppUi()->RemoveFromViewStack(*this, iListBox);
       
   170 	}
       
   171 
       
   172 void CDirectPrintListView::LoadListDataL()
       
   173 	{
       
   174 	CDirectPrintModel& model = GetModel();
       
   175 	TInt count = model.PrinterCount();
       
   176 	for (TInt i=0; i<count; i++)
       
   177 		{
       
   178 		TDirectPrintPrinterData printerData;
       
   179 		model.GetPrinterDataL(i, printerData);
       
   180 
       
   181 		TBuf<50> buf;
       
   182 		buf.Format(_L("\t%S\t%S"), &printerData.iPrinterName, &printerData.iDriverName);
       
   183 		iItemArray->AppendL(buf);
       
   184 		}
       
   185 	}
       
   186 
       
   187 void CDirectPrintListView::PrepareNewDataL()
       
   188 	{
       
   189 	CDirectPrintModel& model = GetModel();
       
   190 	model.SetIsNewData(ETrue);
       
   191 	model.SetSelectPrinter(0);
       
   192 	if (model.PrinterCount() == 0)
       
   193 		{
       
   194 		model.SetCurrentPrinter(0);
       
   195 		}
       
   196 	}
       
   197