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