userguide/src/HelpDataProvider.cpp
changeset 24 bce8d4d2cc72
parent 15 c0dfc135a46c
child 26 97d7f0705d0a
equal deleted inserted replaced
15:c0dfc135a46c 24:bce8d4d2cc72
    34 {
    34 {
    35 	mHelpModel = new QStandardItemModel();
    35 	mHelpModel = new QStandardItemModel();
    36 	mKeywordModel = new QStandardItemModel();
    36 	mKeywordModel = new QStandardItemModel();
    37 	mSearhResultModel = new HelpProxyModel();
    37 	mSearhResultModel = new HelpProxyModel();
    38 	mSearhResultModel->setSourceModel(mKeywordModel);
    38 	mSearhResultModel->setSourceModel(mKeywordModel);
       
    39 	mAppItem = NULL;
    39 }
    40 }
    40 
    41 
    41 HelpDataProvider::~HelpDataProvider()
    42 HelpDataProvider::~HelpDataProvider()
    42 {
    43 {
    43 	delete mHelpModel;
    44 	delete mHelpModel;
    79     return mHelpModel;
    80     return mHelpModel;
    80 }
    81 }
    81 
    82 
    82 QAbstractItemModel* HelpDataProvider::getSearchData(const QString& key)
    83 QAbstractItemModel* HelpDataProvider::getSearchData(const QString& key)
    83 {
    84 {
    84 /*    if(key.isEmpty())
       
    85     {
       
    86         return mKeywordModel;
       
    87     }*/
       
    88 
       
    89 	if(key == mLastSrhKey)
    85 	if(key == mLastSrhKey)
    90 	{
    86 	{
    91 		return mSearhResultModel;
    87 		return mSearhResultModel;
    92 	}
    88 	}
    93 /*
       
    94 	if(!mLastSrhKey.isEmpty() && HelpUtils::findStr(key, mLastSrhKey) != -1)
       
    95 	{
       
    96 		searchInResult(key);
       
    97 	}
       
    98 	else
       
    99 	{
       
   100 		mSearhResultModel->removeRows(0, mSearhResultModel->rowCount());
       
   101 		searchInAllData((HelpStandardItem*)mKeywordModel->invisibleRootItem(), key);
       
   102 	}*/
       
   103 
    89 
   104 	mLastSrhKey = key;
    90 	mLastSrhKey = key;
   105     mSearhResultModel->setFilterRegExp(key);
    91     mSearhResultModel->setFilterRegExp(key);
   106 
       
   107 	
    92 	
   108     return mSearhResultModel;
    93     return mSearhResultModel;
   109 }
    94 }
   110 
    95 
   111 void HelpDataProvider::setHelpContentUrl(const QString& uid, const QString& href)
    96 void HelpDataProvider::setHelpContentUrl(const QString& uid, const QString& href)
   144 
   129 
   145 ///////////////////////////////////////////////////////////////////////////////////////
   130 ///////////////////////////////////////////////////////////////////////////////////////
   146 
   131 
   147 void HelpDataProvider::createHelpCategory()
   132 void HelpDataProvider::createHelpCategory()
   148 {
   133 {
       
   134 	constructCategory();
       
   135 
       
   136 	mHelpModel->setSortRole(Qt::DisplayRole);
       
   137 
       
   138 	constructCategory2((HelpStandardItem*)mHelpModel->invisibleRootItem());
       
   139 
       
   140 	if(mAppItem)
       
   141 	{
       
   142 		mHelpModel->appendRow(mAppItem);
       
   143 		mAppItem->sortChildren(0, HelpUtils::sortOrder());
       
   144 		constructCategory2(mAppItem);
       
   145 	}	
       
   146 
       
   147 	mKeywordModel->sort(0, HelpUtils::sortOrder());
       
   148 }
       
   149 
       
   150 void HelpDataProvider::constructCategory()
       
   151 {
   149 	QFileInfoList driveList = QDir::drives();
   152 	QFileInfoList driveList = QDir::drives();
   150 	QDir dir;
   153 	QDir dir;
   151 	QString lang = HelpUtils::UILocaleFromQtToSymbian();
   154 	QString lang = HelpUtils::UILocaleFromQtToSymbian();
   152 
   155 
   153 	QString path(HelpUtils::rootPath());
   156 	QString path(HelpUtils::rootPath());
   154 	path.append(XHTMLPATH);
   157 	path.append(XHTMLPATH);
   155 	path.append(lang);
   158 	path.append(lang);
   156 
   159 
   157 	//construct help in rom
   160 	QStringList uidList;
   158 	createBuiltInCategory(path);
   161 	QStringList titleList;
       
   162 	parseCategoryIndexXml(path, uidList, titleList);
   159 
   163 
   160 	//scan other root path and construct 3rd party help
   164 	//scan other root path and construct 3rd party help
   161 	foreach(QFileInfo fi, driveList)
   165 	foreach(QFileInfo fi, driveList)
   162 	{
   166 	{
   163 		path.clear();
   167 		path.clear();
   169 		{
   173 		{
   170 			if(QString::compare(fi.absolutePath(), HelpUtils::rootPath(), Qt::CaseInsensitive) == 0)
   174 			if(QString::compare(fi.absolutePath(), HelpUtils::rootPath(), Qt::CaseInsensitive) == 0)
   171 			{
   175 			{
   172 				continue;
   176 				continue;
   173 			}
   177 			}
   174 			constructAppHelp(path);
   178 			constructAppCategory(path, uidList);
   175 		}
   179 		}
   176 	}
   180 	}
   177 	mKeywordModel->sort(0, HelpUtils::sortOrder());
   181 
   178 }
   182 	constructBuiltInCategory(path, uidList, titleList);
   179 
   183 
   180 void HelpDataProvider::createBuiltInCategory(const QString& path)
   184 	mHelpModel->setSortRole(PriorityRole);
       
   185 	mHelpModel->sort(0, HelpUtils::sortOrder());
       
   186 }
       
   187 
       
   188 void HelpDataProvider::constructBuiltInCategory(const QString& path, const QStringList& uidList, const QStringList& titleList)
       
   189 {
       
   190 //	constructCategory2(title, uid);
       
   191 	if(uidList.count() != titleList.count())
       
   192 	{
       
   193 		//ToDo
       
   194 		return;
       
   195 	}
       
   196 
       
   197 	for(int i = 0; i < uidList.count(); i++)
       
   198 	{
       
   199 		if(mUpdateUidList.contains(uidList[i]))
       
   200 		{
       
   201 			continue;
       
   202 		}
       
   203 
       
   204 		QString uid(path);
       
   205 		uid.append(BACKSLASH);
       
   206 		uid.append(uidList[i]);
       
   207 
       
   208 		constructBuiltInCategoryItem(uid, titleList[i]);
       
   209 	}
       
   210 }
       
   211 
       
   212 void HelpDataProvider::constructAppCategory(const QString& path, QStringList& uidList)
       
   213 {
       
   214 	QDir dir(path);	
       
   215 	if(!dir.exists())
       
   216 	{
       
   217 		return;
       
   218 	}
       
   219 
       
   220 	QStringList uidDirList = dir.entryList();
       
   221 	QString pathUid;
       
   222 	foreach(QString uid, uidDirList)
       
   223 	{
       
   224 		pathUid.clear();
       
   225 		pathUid.append(path);
       
   226 		pathUid.append(BACKSLASH);
       
   227 		pathUid.append(uid);
       
   228 
       
   229 		QString titleStr;
       
   230 		parseAppMetaxml(pathUid, titleStr);
       
   231 		if(titleStr.isEmpty())
       
   232 		{
       
   233 			continue;
       
   234 		}
       
   235 
       
   236 		if(uidList.contains(uid))
       
   237 		{
       
   238 			mUpdateUidList.append(uid);
       
   239 			constructBuiltInCategoryItem(pathUid, titleStr);
       
   240 			continue;
       
   241 		}
       
   242 
       
   243 		HelpStandardItem* item = NULL;
       
   244 		item = new HelpStandardItem(titleStr);
       
   245 		item->setData(pathUid, UidRole);
       
   246 
       
   247 		if(!mAppItem)
       
   248 		{
       
   249 			mAppItem = new HelpStandardItem(qtTrId(TXT_APPLICATIONS));
       
   250 			mAppItem->setData(APPPRIORITY, PriorityRole);
       
   251 		}
       
   252 		mAppItem->appendRow(item);
       
   253 	}
       
   254 }
       
   255 
       
   256 void HelpDataProvider::constructBuiltInCategoryItem(const QString& uid, const QString& title)
       
   257 {
       
   258 	int featureId;
       
   259 	int priority;
       
   260 	parseBuiltInMetaxml(uid, featureId, priority);
       
   261 	
       
   262 	HelpStandardItem* item = NULL;
       
   263 	item = new HelpStandardItem(title);
       
   264 	item->setData(uid, UidRole);
       
   265 
       
   266 	if(item)
       
   267 	{
       
   268 		item->setData(priority, PriorityRole);
       
   269 		mHelpModel->appendRow(item);
       
   270 	}
       
   271 }
       
   272 
       
   273 void HelpDataProvider::constructCategory2(HelpStandardItem* itemParent)
       
   274 {
       
   275 	int count = itemParent->rowCount();
       
   276 	for(int i =0; i < count; i++)
       
   277 	{
       
   278 		HelpStandardItem* item = (HelpStandardItem*)itemParent->child(i);
       
   279 		constructCategory2Item(item);
       
   280 	}
       
   281 }
       
   282 
       
   283 void HelpDataProvider::constructCategory2Item(HelpStandardItem* itemParent)
       
   284 {
       
   285 	QStringList hrefList;
       
   286 	QStringList titleList;
       
   287 
       
   288 	QString uid = itemParent->data(UidRole).toString();
       
   289 	parseCategory2IndexXml(uid, hrefList, titleList);
       
   290 
       
   291 	if(hrefList.count() == 0 || hrefList.count() != titleList.count())
       
   292 	{
       
   293 		return;
       
   294 	}
       
   295 
       
   296 	for(int i = 0; i < hrefList.count(); i++)
       
   297 	{
       
   298 		HelpStandardItem* item = new HelpStandardItem(titleList[i]);
       
   299 		item->setData(hrefList[i], HrefRole);
       
   300 		itemParent->appendRow(item);
       
   301 		constructKeywordModel(titleList[i], uid, hrefList[i]);
       
   302 	}
       
   303 
       
   304 	itemParent->sortChildren(0, HelpUtils::sortOrder());
       
   305 }
       
   306 
       
   307 void HelpDataProvider::constructKeywordModel(const QString& title, const QString& uid, const QString& href)
       
   308 {
       
   309 	HelpStandardItem* itemTemp = new HelpStandardItem(title);
       
   310 	itemTemp->setData(uid, UidRole);
       
   311 	itemTemp->setData(href, HrefRole);
       
   312 	mKeywordModel->appendRow(itemTemp);
       
   313 }
       
   314 
       
   315 void HelpDataProvider::parseCategoryIndexXml(const QString& path, QStringList& uidList, QStringList& titleList)
   181 {
   316 {
   182 	QString pathIndex(path);
   317 	QString pathIndex(path);
   183 	pathIndex.append(BACKSLASH);
   318 	pathIndex.append(BACKSLASH);
   184 	pathIndex.append(INDEXXML);
   319 	pathIndex.append(INDEXXML);
   185 
   320 
   189 	}
   324 	}
   190 
   325 
   191 	//parse index xml to a stringlist, each string include id and navtitle and seperate by "specilchar"
   326 	//parse index xml to a stringlist, each string include id and navtitle and seperate by "specilchar"
   192 	QXmlQuery query;
   327 	QXmlQuery query;
   193 	query.bindVariable("inputdoc", &file);
   328 	query.bindVariable("inputdoc", &file);
   194 	QXmlItem xmlItem(SPECIALCHAR);
   329 
   195 	query.bindVariable("specilchar", xmlItem);
   330 	query.setQuery("doc($inputdoc)/collections/collection/xs:string(@id)");
   196 	query.setQuery("doc($inputdoc)/collections/collection/ \
       
   197 					string-join((xs:string(@id), xs:string(@navtitle)), $specilchar)");
       
   198 
       
   199 	if(!query.isValid())
   331 	if(!query.isValid())
   200 	{
   332 	{
   201 		return;
   333 		return;
   202 	}
   334 	}
   203 	QStringList strLst;
   335 	if(!query.evaluateTo(&uidList))
   204 	if(!query.evaluateTo(&strLst))
   336 	{
   205 	{
   337 		return;
   206 		return;
   338 	}
   207 	}
   339 
   208 
   340 	query.setQuery("doc($inputdoc)/collections/collection/xs:string(@navtitle)");
   209 	foreach(QString str, strLst)
   341 	if(!query.isValid())
   210 	{
   342 	{
   211 		QStringList temp;
   343 		return;
   212 		temp = str.split(SPECIALCHAR);
   344 	}
   213 		QString uid(path);
   345 	if(!query.evaluateTo(&titleList))
   214 		uid.append(BACKSLASH);
   346 	{
   215 		uid.append(temp[0]);
   347 		return;
   216 		HelpStandardItem* item = constructCategory2(temp[1], uid);
   348 	}
   217 		if(item)
   349 }
   218 		{
   350 
   219 			mHelpModel->appendRow(item);
   351 void HelpDataProvider::parseCategory2IndexXml(const QString& path, QStringList& hrefList, QStringList& titleList)
   220 //			constructKeywordModel(uid);
   352 {
   221 		}
   353 	QString pathIndex(path);
   222 	}
       
   223 	file.close();
       
   224 	mHelpModel->sort(0, HelpUtils::sortOrder());
       
   225 }
       
   226 
       
   227 HelpStandardItem* HelpDataProvider::constructCategory2(const QString& title, const QString& uid)
       
   228 {
       
   229 	QString pathIndex(uid);
       
   230 	pathIndex.append(BACKSLASH);
   354 	pathIndex.append(BACKSLASH);
   231 	pathIndex.append(INDEXXML);
   355 	pathIndex.append(INDEXXML);
   232 
   356 
   233 	QFile file(pathIndex);
   357 	QFile file(pathIndex);
   234 	if (!file.open(QIODevice::ReadOnly)) {
   358 	if (!file.open(QIODevice::ReadOnly)) {
   235 		return NULL;
   359 		return;
   236 	}
   360 	}
   237 
   361 
   238 	//parse index xml to a stringlist, each string include href and navtitle and seperate by "specilchar"
   362 	//parse index xml to a stringlist, each string include href and navtitle and seperate by "specilchar"
   239 	QXmlQuery query;
   363 	QXmlQuery query;
   240 	QXmlItem xmlItem(SPECIALCHAR);
   364 	QXmlItem xmlItem(SPECIALCHAR);
   241 	query.bindVariable("inputdoc", &file);
   365 	query.bindVariable("inputdoc", &file);
   242 	query.bindVariable("specilchar", xmlItem);
   366 
   243 	query.setQuery("doc($inputdoc)/topics/topicref/ \
   367 	query.setQuery("doc($inputdoc)/topics/topicref/xs:string(@href)");	
   244 					string-join((xs:string(@href), xs:string(@navtitle)), $specilchar)");
       
   245 	if(!query.isValid())
   368 	if(!query.isValid())
   246 	{
   369 	{
   247 		return NULL;
   370 		return;
   248 	}
   371 	}
   249 
   372 	if(!query.evaluateTo(&hrefList))
   250 	QStringList strLst;
   373 	{
   251 	if(!query.evaluateTo(&strLst))
   374 		return;
   252 	{
       
   253 		return NULL;
       
   254 	}	
   375 	}	
   255 	if(strLst.count() <= 0)
   376 
   256 	{
   377 	query.setQuery("doc($inputdoc)/topics/topicref/xs:string(@navtitle)");
   257 		return NULL;
   378 	if(!query.isValid())
   258 	}
   379 	{
   259 
   380 		return;
   260 	HelpStandardItem* itemParent = NULL;
   381 	}
   261 	itemParent = new HelpStandardItem(title);
   382 	if(!query.evaluateTo(&titleList))
   262 	itemParent->setData(uid, UidRole);
   383 	{
   263 	foreach(QString str, strLst)
   384 		return;
   264 	{
   385 	}
   265 		QStringList temp;
   386 }
   266 		temp = str.split(SPECIALCHAR);
   387 
   267 		HelpStandardItem* item = new HelpStandardItem(temp[1]);
   388 void HelpDataProvider::parseBuiltInMetaxml(const QString& path, int& featureId, int& priority)
   268 		item->setData(temp[0], HrefRole);
   389 {
   269 		itemParent->appendRow(item);
   390 	QString pathMetaxml(path);
   270 		constructKeywordModel(temp[1], uid, temp[0]);
   391 	pathMetaxml.append(BACKSLASH);
   271 	}
   392 	pathMetaxml.append(METAXML);
   272 
   393 
   273 	file.close();
   394 	featureId = -1;
   274 	itemParent->sortChildren(0, HelpUtils::sortOrder());
   395 	priority = -1;
   275 	return itemParent;
   396 
   276 }
   397 	QFile file(pathMetaxml);
   277 
   398 	if (!file.open(QIODevice::ReadOnly))
   278 void HelpDataProvider::constructAppHelp(const QString& path)
   399 	{
   279 {
   400 		return;
   280 	QDir dir(path);	
   401 	}
   281 	if(!dir.exists())
   402 
   282 	{
   403 	QXmlQuery query;
   283 		return;
   404 	QString str;
   284 	}
   405 	query.bindVariable("inputdoc", &file);
   285 
   406 
   286 	QStringList uidList = dir.entryList();
   407 	query.setQuery("doc($inputdoc)/meta/title/number(@FeatureId)");
   287 	HelpStandardItem* itemApp = NULL;
   408 	if(query.isValid() && query.evaluateTo(&str))
   288 	QString pathTemp;
   409 	{
   289 	foreach(QString uid, uidList)
   410 		featureId = str.toInt();
   290 	{
   411 	}
   291 		pathTemp.clear();
   412 
   292 		pathTemp.append(path);
   413 	query.setQuery("doc($inputdoc)/meta/number(priority)");	
   293 		pathTemp.append(BACKSLASH);
   414 	if(query.isValid() && query.evaluateTo(&str))
   294 		pathTemp.append(uid);
   415 	{
   295 		pathTemp.append(BACKSLASH);
   416 		priority = str.toInt();
   296 		pathTemp.append(METAXML);
   417 	}
   297 		QFile file(pathTemp);
   418 }
   298 		if (!file.open(QIODevice::ReadOnly)) {
   419 
   299 			continue;
   420 void HelpDataProvider::parseAppMetaxml(const QString& path, QString& title)
   300 		}
   421 {
   301 
   422 	QString pathMetaxml(path);
   302 		//parse meta xml, get the title string
   423 	pathMetaxml.append(BACKSLASH);
   303 		QXmlQuery query;
   424 	pathMetaxml.append(METAXML);
   304 		query.bindVariable("inputdoc", &file);
   425 	QFile file(pathMetaxml);
   305 		query.setQuery("doc($inputdoc)/meta/string(title)");
   426 	if (!file.open(QIODevice::ReadOnly)) {
   306 		if(!query.isValid())
   427 		return;
   307 		{
   428 	}
   308 			continue;
   429 
   309 		}
   430 	//parse meta xml, get the title string
   310 		QString titleStr;
   431 	QXmlQuery query;
   311 		if(!query.evaluateTo(&titleStr))
   432 	query.bindVariable("inputdoc", &file);
   312 		{
   433 	query.setQuery("doc($inputdoc)/meta/string(title)");
   313 			continue;
   434 	if(!query.isValid())
   314 		}
   435 	{
   315 
   436 		return;
   316 		pathTemp.clear();
   437 	}
   317 		pathTemp.append(path);
   438 
   318 		pathTemp.append(BACKSLASH);
   439 	if(!query.evaluateTo(&title))
   319 		pathTemp.append(uid);
   440 	{
   320 		HelpStandardItem* item = constructCategory2(titleStr, pathTemp);
   441 		return;
   321 		if(item)
   442 	}
   322 		{
   443 }
   323 			if(!itemApp)
       
   324 			{
       
   325 				itemApp = new HelpStandardItem("Applications");
       
   326 			}
       
   327 			itemApp->appendRow(item);
       
   328 //			constructKeywordModel(pathTemp);
       
   329 		}
       
   330 		file.close();
       
   331 	}
       
   332 
       
   333 	if(itemApp)
       
   334 	{
       
   335 		itemApp->sortChildren(0, HelpUtils::sortOrder());
       
   336 		mHelpModel->appendRow(itemApp);
       
   337 	}
       
   338 }
       
   339 
       
   340 /*
       
   341 void HelpDataProvider::searchInAllData(HelpStandardItem* item, const QString& key)
       
   342 {
       
   343 	if(item->rowCount() > 0)
       
   344 	{
       
   345 		for(int i = 0; i < item->rowCount(); i++)
       
   346 		{		
       
   347 			searchInAllData((HelpStandardItem*)item->child(i),key);
       
   348 		}
       
   349 	}
       
   350 	else
       
   351 	{
       
   352 		if(HelpUtils::findStr(item->text(), key) != -1)
       
   353 		{
       
   354 			HelpStandardItem* itemSearch = new HelpStandardItem(item->text());
       
   355 			itemSearch->setData(item->data(UidRole), UidRole);
       
   356 			itemSearch->setData(item->data(HrefRole), HrefRole);
       
   357 			mSearhResultModel->appendRow(itemSearch);
       
   358 		}
       
   359 	}
       
   360 }
       
   361 
       
   362 void HelpDataProvider::searchInResult(const QString& key)
       
   363 {
       
   364 	for(int i = 0; i < mSearhResultModel->rowCount();)
       
   365 	{
       
   366 		QStandardItem* item = mSearhResultModel->item(i);
       
   367 		if(HelpUtils::findStr(item->text(), key) == -1)
       
   368 		{
       
   369 			mSearhResultModel->removeRow(i);
       
   370 		}
       
   371 		else
       
   372 		{
       
   373 			i++;
       
   374 		}
       
   375 	}
       
   376 }
       
   377 */
       
   378 void HelpDataProvider::constructKeywordModel(const QString& title, const QString& uid, const QString& href)
       
   379 {
       
   380 	HelpStandardItem* itemTemp = new HelpStandardItem(title);
       
   381 	itemTemp->setData(uid, UidRole);
       
   382 	itemTemp->setData(href, HrefRole);
       
   383 	mKeywordModel->appendRow(itemTemp);
       
   384 }
       
   385 
       
   386 HelpStandardItem* HelpDataProvider::findItemWithHref(HelpStandardItem* itemParent, const QString& href)
       
   387 {
       
   388 	for(int i = 0; i < itemParent->rowCount(); i++)
       
   389 	{
       
   390 		if(QString::compare(itemParent->child(i)->data(HrefRole).toString(), href, Qt::CaseInsensitive) == 0)
       
   391 		{
       
   392 			return (HelpStandardItem *)(itemParent->child(i));
       
   393 		}
       
   394 	}
       
   395 	return NULL;
       
   396 }