aknlayoutcompiler/src/LayoutPack.cpp
changeset 0 f58d6ec98e88
child 1 b700e12870ca
equal deleted inserted replaced
-1:000000000000 0:f58d6ec98e88
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // disable "identifier was truncated to '255' characters in the browser information" warning
       
    21 #pragma warning (disable:4786)
       
    22 
       
    23 #include "LayoutPack.h"
       
    24 #include "ZoomLevelNames.h"
       
    25 #include "LayoutCompilerErr.h"
       
    26 #include "CodeGenConsts.h"
       
    27 #include "AknLayoutConsts.h"
       
    28 
       
    29 #include <sstream>
       
    30 #include <iostream>
       
    31 
       
    32 using namespace std;
       
    33 using namespace CdlCompilerToolkit;
       
    34 
       
    35 typedef LayoutProcessArgsErr<LayoutPackage> LayoutPackageArgsErr;
       
    36 
       
    37 const string KLayoutPackCdlFile = "LayoutPack.cdl";
       
    38 
       
    39 int LayoutPackage::Process(vector<string>& args)
       
    40 	{
       
    41 	if (args.size() < 7)
       
    42 		throw LayoutPackageArgsErr();
       
    43 	
       
    44 	CZoomLevelNames zoomLevelNames;
       
    45 	zoomLevelNames.ProcessOptions(args);
       
    46 
       
    47 	string styleName;
       
    48 	string deliveryTypeName;
       
    49     string priority;
       
    50     string appUid;
       
    51 
       
    52     ProcessOptionalStringArg(args, string("-s"), styleName);
       
    53     ProcessOptionalStringArg(args, string("-d"), deliveryTypeName);
       
    54     ProcessOptionalStringArg(args, string("-p"), priority);
       
    55     ProcessOptionalStringArg(args, string("-a"), appUid);
       
    56 
       
    57 	string& name = args[2];
       
    58 	string& w = args[3];
       
    59 	string& h = args[4];
       
    60 	string& id = args[5];
       
    61 
       
    62 	for(CZoomLevelNames::iterator pZoomName = zoomLevelNames.begin(); pZoomName != zoomLevelNames.end(); ++pZoomName)
       
    63 		Process(name, w, h, id, styleName, deliveryTypeName, priority, appUid, args.begin() + 6, args.end(), pZoomName->second);
       
    64 
       
    65 	return 0;
       
    66 	}
       
    67 
       
    68 void LayoutPackage::ShowHelp(ostream& stream)
       
    69 	{
       
    70 	stream << "LayPkg [-z<zoomList>] [-s<screenStyleName>] [-d<deliverytype> -p<priority> [-a<appUid>]] <packageName> <width> <height> <layoutId> <instances>+" << endl;
       
    71 	stream << "  Creates CDL package according to Layout.cdl containing:" << endl;
       
    72 	stream << "    The name of the package." << endl;
       
    73 	stream << "    The size of screen that it applies to." << endl;
       
    74 	stream << "    The layout variant it is used for." << endl;
       
    75 	stream << "    The contents of the package." << endl;
       
    76 	stream << "  If -z<zoomList> is specified, then instances for zoom factors" << endl;
       
    77 	stream << "    (in the form \"n,string\") appearing in the file <zoomList> will be generated, " << endl;
       
    78 	stream << "    by replacing the keyword $ZOOM in the package definitions." << endl;
       
    79 	stream << "  If -s<screenStyleName> is specified, then instances for the appropriate" << endl;
       
    80 	stream << "    screen style as found in WSINI.INI will be generated." << endl;
       
    81 	stream << "  If -d<deliveryType> is specified then the delivery type will be appended to" << endl;
       
    82 	stream << "    the layout XML directory name." << endl;
       
    83 	stream << "  If -p<priority> is specified then the pack will be loaded in priority order compared to " << endl;
       
    84 	stream << "    instances of the same interface in all other packs, otherwise defaults to zero." << endl;
       
    85 	stream << "  If -a<appUid> is specified then the layout pack will only be loaded for an application" << endl;
       
    86 	stream << "    with a matching Secure UID, defaults to zero which means that the pack will be loaded" << endl;
       
    87 	stream << "    for any application ." << endl;
       
    88 	}
       
    89 
       
    90 void LayoutPackage::Process(
       
    91 	const string& aName, 
       
    92 	const string& aWidth, 
       
    93 	const string& aHeight, 
       
    94 	const string& aId, 
       
    95 	const string& aStyleName,
       
    96     const string& aDeliveryTypeName,
       
    97     const string& aPriority,
       
    98     const string& aAppUid,
       
    99 	vector<string>::const_iterator aBegin, 
       
   100 	vector<string>::const_iterator aEnd, 
       
   101 	const string& aZoomName)
       
   102 	{
       
   103 	CCdlTkCdlFileParser parser(KDirDomainSysHeader+KLayoutPackCdlFile);
       
   104 	auto_ptr<CCdlTkInterface> iface(parser.LoadAndParse(true));
       
   105 	CCdlTkPackage pkg(*iface);
       
   106 	pkg.TemplateAllImplementations();
       
   107 
       
   108 	string zoomName = CdlTkUtil::Replace("$ZOOM", aZoomName, aName);
       
   109 	string zoomIdName = "EAknUiZoom" + aZoomName;
       
   110 	string styleHash = Hash(aStyleName);
       
   111     string priority = CdlTkUtil::IntToString(CdlTkUtil::ParseInt(aPriority));
       
   112     string appUid = CdlTkUtil::IntToHexString(CdlTkUtil::ParseInt(aAppUid));
       
   113 
       
   114 	pkg.SetName(zoomName);
       
   115 
       
   116 	Implement(pkg, "name", "\"\"", string("\"")+zoomName+"\"");
       
   117 	Implement(pkg, "size", "?width", aWidth);
       
   118 	Implement(pkg, "size", "?height", aHeight);
       
   119 	Implement(pkg, "id", "?value", aId);
       
   120 	Implement(pkg, "zoom", "?value", zoomIdName);
       
   121 	Implement(pkg, "styleHash", "?value", styleHash, string("	// screen style ") + aStyleName);
       
   122 	Implement(pkg, "priority", "?value", priority);
       
   123 	Implement(pkg, "appUid", "?value", appUid);
       
   124 
       
   125 	cout << zoomName << endl;
       
   126 
       
   127 	for (; aBegin != aEnd; ++aBegin)
       
   128 		{
       
   129 		const string& arg = *aBegin;
       
   130 		if (arg.size()>=2 && arg.substr(0,2)=="-x")
       
   131 			{
       
   132 			if (++aBegin == aEnd)
       
   133 				throw LayoutPackageArgsErr();
       
   134 			string dir = *aBegin;
       
   135 			
       
   136 			dir = CdlTkUtil::Replace("\\", "/", dir);
       
   137 			if (*dir.rbegin() != '/')
       
   138 				dir += "/";
       
   139 
       
   140 			if (++aBegin == aEnd)
       
   141 				throw LayoutPackageArgsErr();
       
   142 			const string& dll = *aBegin;
       
   143 
       
   144 			if (++aBegin == aEnd)
       
   145 				throw LayoutPackageArgsErr();
       
   146 			const string& inst = *aBegin;
       
   147 
       
   148 			string zoomContent = CdlTkUtil::Replace("$ZOOM", aZoomName, inst);
       
   149 			pkg.AddExternalContent(zoomContent, dir, dll);
       
   150 			}
       
   151 		else
       
   152 			{
       
   153 			string zoomContent = CdlTkUtil::Replace("$ZOOM", aZoomName, arg);
       
   154 			pkg.AddLocalContent(zoomContent);
       
   155 			cout << zoomContent << endl;
       
   156 			}
       
   157 		}
       
   158 
       
   159 	CCdlTkWriteInstance writer(pkg);
       
   160 	writer.Process();
       
   161 	}
       
   162 
       
   163 void LayoutPackage::Implement(
       
   164 	CCdlTkPackage& aPkg, 
       
   165 	const string& aApi, 
       
   166 	const string& aTarget, 
       
   167 	const string& aReplace,
       
   168 	const string& aComment)
       
   169 	{
       
   170 	CCdlTkImplementation* impl = aPkg.Impl().Find(aApi);
       
   171 	if (!impl)
       
   172 		throw NotFoundErr(aApi + " in LayoutPack.cdl");
       
   173 	CdlTkUtil::CReplaceSet implSet;
       
   174 	implSet.Add(aTarget, aReplace);
       
   175 	implSet.Add("	//TODO: Initialise this data.", aComment);
       
   176 	impl->SetDefinition(CdlTkUtil::MultiReplace(implSet, impl->Definition()));
       
   177 	}
       
   178 
       
   179 void LayoutPackage::ProcessOptionalStringArg(vector<string>& args, const string& aOption, string& aArg)
       
   180 	{
       
   181 	for (vector<string>::iterator pArg = args.begin(); pArg != args.end(); ++pArg)
       
   182 		{
       
   183 		string& arg = *pArg;
       
   184 		if (arg.size() >= 2 && arg.substr(0,2) == aOption)
       
   185 			{
       
   186 			aArg = arg.substr(2);
       
   187 			args.erase(pArg);
       
   188 			return;
       
   189 			}
       
   190 		}
       
   191 	}
       
   192 
       
   193 string LayoutPackage::Hash(const string& aString)
       
   194 	{
       
   195 	int hash = 0;
       
   196 	for (string::const_iterator pChar = aString.begin(); pChar != aString.end(); ++pChar)
       
   197 		{
       
   198 		hash *= KAknLayoutScreenStyleNameHashMult;
       
   199 		hash += *pChar;
       
   200 		}
       
   201 	return CdlTkUtil::IntToHexString(hash);
       
   202 	}