Пример #1
0
int main( int argc, char* argv[] )
{
	KStandardDirs stddir;
	
	if ( argc < 3 )
	{
		std::cerr << "usage: r++ dbname directories..." << std::endl << std::endl;
		return -1;
	}
	
	bool rec = false;
	bool parseAllFiles = false;
	
	QString datadir = stddir.localkdedir() + "/" + KStandardDirs::kde_default( "data" );
	if ( ! KStandardDirs::makeDir( datadir + "/kdevcppsupport/pcs/" ) )
	{
		kdWarning() << "*error* " << "could not create " << datadir + "/kdevcppsupport/pcs/" << endl << endl;
		return -1;
	}
	
	
	if ( !QFile::exists( datadir + "/kdevcppsupport/pcs/" ) )
	{
		kdWarning() << "*error* " << datadir + "/kdevcppsupport/pcs/" << " doesn't exists!!" << endl << endl;
		return -1;
	}
	
	QString dbFileName = datadir + "/kdevcppsupport/pcs/" + argv[ 1 ] + ".db";
	// std::cout << "dbFileName = " << dbFileName << std::endl;
	if ( QFile::exists( dbFileName ) )
	{
		kdWarning() << "*error* " << "database " << dbFileName << " already exists!" << endl << endl;
		return -1;
	}
	
	
	Catalog catalog;
	catalog.open( dbFileName );
	catalog.addIndex( "kind" );
	catalog.addIndex( "name" );
	catalog.addIndex( "scope" );
	catalog.addIndex( "fileName" );
	
	RppDriver driver( &catalog );
	driver.setResolveDependencesEnabled( true );
	
	for ( int i = 2; i < argc; ++i )
	{
		QString s( argv[ i ] );
		if ( s == "-r" || s == "--recursive" )
		{
			rec = true;
			continue;
		}
		else if ( s == "-a" || s == "--all" )
		{
			parseAllFiles = true;
			continue;
		}
		else if ( s == "-f" || s == "--fast" )
		{
			driver.setResolveDependencesEnabled( false );
			continue;
		}
		else if ( s == "-c" || s == "--check-only" )
		{
			driver.setGenerateTags( false );
			continue;
		}
		else if ( s.startsWith( "-d" ) )
		{
			driver.addDocDirectory( s.mid( 2 ) );
			continue;
		}
		
		QDir dir( s );
		if ( !dir.exists() )
		{
			kdWarning() << "*error* " << "the directory " << dir.path() << " doesn't exists!" << endl << endl;
			continue;
		}
		
		parseDirectory( driver, dir, rec, parseAllFiles );
	}
	
	return 0;
}
Пример #2
0
void ktvschedule::correspondChannels()
{

	// clears all Columns before creating new ones
	t_TVGrid->removeAllColumns();
	Channels.clear();
	//
	     qInitNetworkProtocols ();
	     KStandardDirs *dirs = new KStandardDirs();
	     QString home = dirs->localkdedir () + "/share/apps/ktvschedule/";
	     QUrlOperator *urlOp = new QUrlOperator;
	//
	//Stats XML parsing
        QDomElement docElement = TvXML.documentElement();
	
	QDomNode node = docElement.firstChild();	
	
 	while( !node.isNull() )
 	{
	 QDomNode subnode=node.firstChild();
	 	 
	 QDomElement node_element=node.toElement();

	 ///////////////////////////
	 //If it is a channel, load channel name and Id

	 if (node_element.tagName()=="channel")
	  {
		ChannelNameIcon chanNameandIcon;
		bool Found = FALSE;

	 	while (!subnode.isNull())
		{
		
		QDomElement subnode_element=subnode.toElement();
		if (subnode_element.tagName()=="display-name")
			{
				if (!Found)
				{			
					chanNameandIcon.ChannelName = subnode_element.text();
					Found = TRUE;
				}
			//in fact some XML guides have many channel names. As from xmltv display names are : List the most canonical / common ones first and the most obscure names last. So we can stop.
			}
		
		if (subnode_element.tagName()=="icon")
		{
			chanNameandIcon.ChannelIcon = subnode_element.attribute("src","");

			// if the icon is on a remote location, try to fetch it localy
			if (chanNameandIcon.ChannelIcon.contains("http://")!=0)
			{
			  // if file does not exist localy, then download it
			  if (!QFile::exists(home + chanNameandIcon.ChannelIcon.section('/',-1) ) ) 
			  {
			  	urlOp->copy(chanNameandIcon.ChannelIcon, home); // donwload pixmap
			  }
			  
			   // Ok, we are going to save in the config file the url of the pics. It will be used in the channels to download missing pics.
			  QString temp = chanNameandIcon.ChannelIcon.section('/',-1); // We need a temp string
			  Config().picURL = chanNameandIcon.ChannelIcon.remove ( temp );
			  
			  // Change the location of the pixmap
			  chanNameandIcon.ChannelIcon = home + temp;
			}
			else if (chanNameandIcon.ChannelIcon.contains("file://")!=0)
			{
				// We create a temp string in order to config the picURL. Otherwise it removes usefull info from the channelIcon
				QString temp = chanNameandIcon.ChannelIcon;
				Config().picURL = temp.remove ( temp.section('/',-1) );
				
				QRegExp rx("^[0-9]{1,2}");
				QString dest=home + chanNameandIcon.ChannelName.lower().remove(" ").remove(rx)+"."+chanNameandIcon.ChannelIcon.right(3);
				if (!QFile::exists(dest))
				{
					urlOp->copy(chanNameandIcon.ChannelIcon,dest,FALSE,FALSE);
			 	}
				 // Change the location of the pixmap
			  	chanNameandIcon.ChannelIcon = dest;
				
			}
			else
			{
				qDebug("Pict is of unknown type"); 	 
			}
		}
			
		subnode=subnode.nextSibling();
			}
		
		Channels[node_element.attribute("id","")]=chanNameandIcon;
	  }
	  else
	  {
	  	// NxTvEPG have another field before the channels (about field). Do not stop
		if (node_element.tagName()!="about")
		{
			break; //no need to continue
		}
	  }
	node=node.nextSibling();
	}	
	
	// Creates collumns in the TvGrid. The QMap Channel has the channel name and id
	t_TVGrid->CreateColumns(Channels);
}