imageeditor/IEPB/src/iepbres.cpp
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <barsread.h> 
       
    22 #include <bautils.h>
       
    23 #include <eikenv.h> 
       
    24 #include <coneresloader.h> 
       
    25 
       
    26 
       
    27 #include <ImageEditorPluginBase.rsg>
       
    28 #include "iepbres.h"
       
    29 #include "ImageEditorPluginBase.hrh"
       
    30 
       
    31 //=============================================================================
       
    32 CPluginResource * CPluginResource::NewL (
       
    33     const TDesC &   aResourcePath,
       
    34     const TDesC &   aResourceFile
       
    35     )
       
    36 {
       
    37     CPluginResource * self = new (ELeave) CPluginResource;
       
    38     CleanupStack::PushL (self);
       
    39     self->ConstructL (aResourcePath, aResourceFile);
       
    40     CleanupStack::Pop (); // self;
       
    41     return self;
       
    42 }
       
    43 
       
    44 //=============================================================================
       
    45 CPluginResource::~CPluginResource ()
       
    46 {
       
    47 	delete iPluginName;
       
    48 	delete iPluginIconFileName;
       
    49 	delete iPluginFilterDllName;
       
    50 	
       
    51     if (iParameters)
       
    52 	{
       
    53 		iParameters->Reset();
       
    54 	}
       
    55 	delete iParameters;
       
    56 
       
    57     if (iSk1Cmds)
       
    58     {
       
    59         iSk1Cmds->Reset();
       
    60     }
       
    61     delete iSk1Cmds;
       
    62 
       
    63     if (iSk1Texts)
       
    64     {
       
    65         iSk1Texts->Reset();
       
    66     }
       
    67     delete iSk1Texts;
       
    68 
       
    69     if (iSk2Cmds)
       
    70     {
       
    71         iSk2Cmds->Reset();
       
    72     }
       
    73     delete iSk2Cmds;
       
    74 
       
    75     if (iSk2Texts)
       
    76     {
       
    77         iSk2Texts->Reset();
       
    78     }
       
    79     delete iSk2Texts;
       
    80     
       
    81     if (iMSKCmds)
       
    82     {
       
    83         iMSKCmds->Reset();
       
    84     }
       
    85     delete iMSKCmds;
       
    86 
       
    87     if (iMSKTexts)
       
    88     {
       
    89         iMSKTexts->Reset();
       
    90     }
       
    91     delete iMSKTexts;
       
    92     
       
    93     if (iMenuItems)
       
    94     {
       
    95         iMenuItems->Reset();
       
    96     }
       
    97     delete iMenuItems;
       
    98 }
       
    99 
       
   100 //=============================================================================
       
   101 const TPluginInt & CPluginResource::PluginUID () const
       
   102 {
       
   103     return iPluginUID;
       
   104 }
       
   105 
       
   106 //=============================================================================
       
   107 const TPluginUiType & CPluginResource::PluginUiType() const
       
   108 {
       
   109     return iPluginUIType;
       
   110 }
       
   111 
       
   112 //=============================================================================
       
   113 const TPluginFilterType & CPluginResource::PluginFilterType() const
       
   114 {
       
   115     return iPluginFilterType;
       
   116 }
       
   117 
       
   118 //=============================================================================
       
   119 const TPluginScope & CPluginResource::PluginScope() const
       
   120 {
       
   121     return iPluginScope;
       
   122 }
       
   123 
       
   124 //=============================================================================
       
   125 const TPluginInt & CPluginResource::PluginDisplayOrder() const
       
   126 {
       
   127     return iPluginDisplayOrder;
       
   128 }
       
   129 
       
   130 //=============================================================================
       
   131 const TPtrC CPluginResource::PluginName () const
       
   132 {
       
   133     return iPluginName->Des();
       
   134 }
       
   135 
       
   136 //=============================================================================
       
   137 const TPtrC CPluginResource::IconFileName() const
       
   138 {
       
   139     return iPluginIconFileName->Des();
       
   140 }
       
   141 
       
   142 //=============================================================================
       
   143 const TPtrC CPluginResource::FilterFileName () const
       
   144 {
       
   145     return iPluginFilterDllName->Des();
       
   146 }
       
   147 
       
   148 //=============================================================================
       
   149 const CDesCArray * CPluginResource::GetParameters () const
       
   150 {
       
   151 	return (CDesCArray *)iParameters;
       
   152 }
       
   153 
       
   154 //=============================================================================
       
   155 const CDesCArray * CPluginResource::Sk1Texts () const
       
   156 {
       
   157     return iSk1Texts;
       
   158 }
       
   159 
       
   160 //=============================================================================
       
   161 const CArrayFix<TInt> * CPluginResource::Sk1CommandIds() const
       
   162 {
       
   163     return iSk1Cmds;
       
   164 }
       
   165 
       
   166 //=============================================================================
       
   167 const CDesCArray * CPluginResource::Sk2Texts () const
       
   168 {
       
   169     return iSk2Texts;
       
   170 }
       
   171 
       
   172 //=============================================================================
       
   173 const CArrayFix<TInt> * CPluginResource::Sk2CommandIds() const
       
   174 {
       
   175     return iSk2Cmds;
       
   176 }
       
   177 
       
   178 //=============================================================================
       
   179 const CDesCArray * CPluginResource::MSKTexts () const
       
   180 {
       
   181     return iMSKTexts;
       
   182 }
       
   183 
       
   184 //=============================================================================
       
   185 const CArrayFix<TInt> * CPluginResource::MSKCommandIds() const
       
   186 {
       
   187     return iMSKCmds;
       
   188 }
       
   189 
       
   190 //=============================================================================
       
   191 const CMenuItemArray * CPluginResource::MenuItems() const
       
   192 {
       
   193     return iMenuItems;
       
   194 }
       
   195 
       
   196 //=============================================================================
       
   197 CPluginResource::CPluginResource()
       
   198 {
       
   199 
       
   200 }
       
   201 
       
   202 //=============================================================================
       
   203 void CPluginResource::ConstructL (
       
   204     const TDesC &   aResourcePath,
       
   205     const TDesC &   aResourceFile
       
   206     )
       
   207 {
       
   208 
       
   209 	CEikonEnv* env = CEikonEnv::Static();
       
   210 
       
   211     /**
       
   212     *
       
   213     *   PLUG-IN INFO
       
   214     *
       
   215     */
       
   216   
       
   217     //  Create resource utility
       
   218 	TFileName file_name;
       
   219 	file_name.Copy (aResourcePath);
       
   220 	file_name.Append (aResourceFile);
       
   221     BaflUtils::NearestLanguageFile( env->FsSession(), file_name );
       
   222 
       
   223     RConeResourceLoader res_loader ( *env );
       
   224     CleanupClosePushL (res_loader);
       
   225 	res_loader.OpenL ( file_name );
       
   226 
       
   227     //  Construct resource reader
       
   228     HBufC8 * res8 = env->AllocReadResourceAsDes8LC (R_PLUGIN_INFO);
       
   229     TResourceReader resource;
       
   230     resource.SetBuffer (res8);
       
   231 
       
   232     //  Read plug-in UID
       
   233     iPluginUID = resource.ReadInt32();    
       
   234 
       
   235     //  Read plug-in UID
       
   236     iPluginUIType = (TPluginUiType)resource.ReadInt32();    
       
   237 
       
   238     //  Read plug-in UID
       
   239     iPluginFilterType = (TPluginFilterType)resource.ReadInt32();    
       
   240 
       
   241     //  Read plug-in UID
       
   242     iPluginScope = (TPluginScope)resource.ReadInt32();
       
   243 
       
   244     //  Read plug-in display priority
       
   245     iPluginDisplayOrder = resource.ReadInt32();
       
   246 
       
   247     //  Read plug-in name
       
   248     iPluginName = resource.ReadHBufCL();
       
   249     if ( !iPluginName )
       
   250     {
       
   251         User::Leave (KErrGeneral);
       
   252     }
       
   253 
       
   254     //  Read icon file name
       
   255     iPluginIconFileName = resource.ReadHBufCL();
       
   256     if ( !iPluginIconFileName )
       
   257     {
       
   258         User::Leave (KErrGeneral);
       
   259     }
       
   260 
       
   261     //  Read filter file name
       
   262     iPluginFilterDllName = resource.ReadHBufCL();
       
   263 
       
   264     CleanupStack::PopAndDestroy(); // res8
       
   265 
       
   266 
       
   267     /**
       
   268     *
       
   269     *   PLUG-IN PARAMETERS
       
   270     *
       
   271     */
       
   272 
       
   273 	//	Read resource to descriptor
       
   274 	res8 = env->AllocReadResourceAsDes8LC (R_PLUGIN_PARS);
       
   275 
       
   276 	//	Set resource reader buffer
       
   277 	resource.SetBuffer (res8);
       
   278 
       
   279 	//	Read extra parameter count
       
   280 	TInt16 arraycount = (TInt16)resource.ReadInt16();
       
   281 
       
   282 	if (arraycount > 0)
       
   283 	{
       
   284 		//	Construct a new descriptor array
       
   285 		if (!iParameters)
       
   286 		{
       
   287 			iParameters = new (ELeave) CDesCArraySeg(16);
       
   288 		}
       
   289 
       
   290 		//	Read extra parameters to array
       
   291 		for (TInt i = 0; i < arraycount; ++i)
       
   292 		{
       
   293 			//	Construct a flat descriptor array and read all the parameter names 
       
   294 			HBufC * parameter = resource.ReadHBufCL();
       
   295             CleanupStack::PushL(parameter);
       
   296 			TPtrC ptr = parameter->Des();
       
   297 			iParameters->AppendL (ptr);
       
   298             CleanupStack::PopAndDestroy(); // parameter
       
   299 		}
       
   300     }
       
   301     CleanupStack::PopAndDestroy(); // res8
       
   302 
       
   303 
       
   304     /**
       
   305     *
       
   306     *   SOFT KEY 1
       
   307     *
       
   308     */
       
   309 
       
   310 	//	Read resource to descriptor
       
   311 	res8 = env->AllocReadResourceAsDes8LC (R_SK1_ITEMS);
       
   312     
       
   313 	//	Set resource reader buffer
       
   314 	resource.SetBuffer (res8);
       
   315 
       
   316 	//	Read menu item 
       
   317 	arraycount = (TInt16)resource.ReadInt16();
       
   318 
       
   319 	if (arraycount > 0)
       
   320 	{
       
   321         
       
   322 		//	Construct a new descriptor array
       
   323 		if (!iSk1Cmds)
       
   324 		{
       
   325 			iSk1Cmds = new (ELeave) CArrayFixSeg<TInt>(8);
       
   326 		}
       
   327 		if (!iSk1Texts)
       
   328 		{
       
   329 			iSk1Texts = new (ELeave) CDesCArraySeg(8);
       
   330 		}
       
   331 
       
   332 		//	Read extra parameters to array
       
   333 		for (TInt i = 0; i < arraycount; ++i)
       
   334 		{
       
   335             //  Read command ID
       
   336             TInt cmd = resource.ReadInt32();
       
   337             iSk1Cmds->AppendL(cmd);
       
   338 
       
   339             //  Read the menu item text
       
   340             HBufC * menutext = resource.ReadHBufCL();
       
   341             CleanupStack::PushL (menutext);
       
   342             TPtrC ptr = menutext->Des();
       
   343             iSk1Texts->AppendL ( ptr );
       
   344             CleanupStack::PopAndDestroy(); // menutext
       
   345 		}
       
   346     }
       
   347     CleanupStack::PopAndDestroy(); // res8
       
   348 
       
   349     /**
       
   350     *
       
   351     *   SOFT KEY 2
       
   352     *
       
   353     */
       
   354 
       
   355 	//	Read resource to descriptor
       
   356 	res8 = env->AllocReadResourceAsDes8LC (R_SK2_ITEMS);
       
   357     
       
   358 	//	Set resource reader buffer
       
   359 	resource.SetBuffer (res8);
       
   360 
       
   361 	//	Read menu item 
       
   362 	arraycount = (TInt16)resource.ReadInt16();
       
   363 
       
   364 	if (arraycount > 0)
       
   365 	{
       
   366         
       
   367 		//	Construct a new descriptor array
       
   368 		if (!iSk2Cmds)
       
   369 		{
       
   370 			iSk2Cmds = new (ELeave) CArrayFixSeg<TInt>(8);
       
   371 		}
       
   372 		if (!iSk2Texts)
       
   373 		{
       
   374 			iSk2Texts = new (ELeave) CDesCArraySeg(8);
       
   375 		}
       
   376 
       
   377 		//	Read extra parameters to array
       
   378 		for (TInt i = 0; i < arraycount; ++i)
       
   379 		{
       
   380             //  Read command ID
       
   381             TInt cmd = resource.ReadInt32();
       
   382             iSk2Cmds->AppendL(cmd);
       
   383 
       
   384             //  Read the menu item text
       
   385             HBufC * menutext = resource.ReadHBufCL();
       
   386             CleanupStack::PushL (menutext);
       
   387             TPtrC ptr = menutext->Des();
       
   388             iSk2Texts->AppendL ( ptr );
       
   389             CleanupStack::PopAndDestroy(); // menutext
       
   390 		}
       
   391     }
       
   392     CleanupStack::PopAndDestroy(); // res8
       
   393 
       
   394     /**
       
   395     *
       
   396     *   MIDDLE SOFTKEY
       
   397     *
       
   398     */
       
   399     
       
   400 	//	Read resource to descriptor
       
   401 	res8 = env->AllocReadResourceAsDes8LC (R_MSK_ITEMS);
       
   402     
       
   403 	//	Set resource reader buffer
       
   404 	resource.SetBuffer (res8);
       
   405 
       
   406 	//	Read menu item 
       
   407 	arraycount = (TInt16)resource.ReadInt16();
       
   408 
       
   409 	if (arraycount > 0)
       
   410 	{
       
   411         
       
   412 		//	Construct a new descriptor array
       
   413 		if (!iMSKCmds)
       
   414 		{
       
   415 			iMSKCmds = new (ELeave) CArrayFixSeg<TInt>(8);
       
   416 		}
       
   417 		if (!iMSKTexts)
       
   418 		{
       
   419 			iMSKTexts = new (ELeave) CDesCArraySeg(8);
       
   420 		}
       
   421 
       
   422 		//	Read extra parameters to array
       
   423 		for (TInt i = 0; i < arraycount; ++i)
       
   424 		{
       
   425             //  Read command ID
       
   426             TInt cmd = resource.ReadInt32();
       
   427             iMSKCmds->AppendL(cmd);
       
   428 
       
   429             //  Read the menu item text
       
   430             HBufC * menutext = resource.ReadHBufCL();
       
   431             CleanupStack::PushL (menutext);
       
   432             TPtrC ptr = menutext->Des();
       
   433             iMSKTexts->AppendL ( ptr );
       
   434             CleanupStack::PopAndDestroy(); // menutext
       
   435 		}
       
   436     }
       
   437     CleanupStack::PopAndDestroy(); // res8
       
   438     
       
   439     /**
       
   440     *
       
   441     *   MENU ITEMS
       
   442     *
       
   443     */
       
   444 
       
   445     //	Read resource to descriptor
       
   446 	res8 = env->AllocReadResourceAsDes8LC (R_MENU_ITEMS);
       
   447 
       
   448 	//	Set resource reader buffer
       
   449 	resource.SetBuffer (res8);
       
   450 
       
   451 	//	Read menu item 
       
   452 	arraycount = (TInt16)resource.ReadInt16();
       
   453 
       
   454 	if (arraycount > 0)
       
   455 	{
       
   456         
       
   457 		//	Construct a new descriptor array
       
   458 		if (!iMenuItems)
       
   459 		{
       
   460 			iMenuItems = new (ELeave) CMenuItemArray(8);
       
   461 		}
       
   462 
       
   463 		//	Read extra parameters to array
       
   464 		for (TInt i = 0; i < arraycount; ++i)
       
   465 		{
       
   466 			//	Construct and initialize a new menu item
       
   467             CEikMenuPaneItem::SData item;
       
   468             item.iFlags = 0;
       
   469             item.iCascadeId = 0;
       
   470 
       
   471             //  Read command ID
       
   472             item.iCommandId = resource.ReadInt32();
       
   473 
       
   474             //  Read the menu item text
       
   475             HBufC * menutext = resource.ReadHBufCL();
       
   476             CleanupStack::PushL(menutext);
       
   477             item.iText.Copy ( menutext->Des() );
       
   478 
       
   479             //  Add menu item to array
       
   480             iMenuItems->AppendL (item);
       
   481             CleanupStack::PopAndDestroy(menutext);
       
   482 		}
       
   483 
       
   484     }
       
   485 
       
   486 	CleanupStack::PopAndDestroy (2); // res8, res_loader
       
   487 
       
   488 }