コード例 #1
0
ファイル: SGF.cpp プロジェクト: wendelbsilva/OpenFuseki
void
SGF::load(std::string f)
{
    filename = f;

    // Get Tokens
    std::vector<std::string> tokens;
    std::vector<int> depths;
    tokenizer(tokens, depths);

    // Some SGF comes with a lot of empty spaces and enter at the beginning
    // Remove all that stuff
    int first = 0;
    boost::algorithm::trim(tokens[first]);
    while(tokens[first] == ""){
	first++;
	boost::algorithm::trim(tokens[first]);
    }
    // Parse Info
    parseInfo(tokens[first]);

    std::stack<std::shared_ptr<Node> > stack;
    stack.push( root );
    root->comment = comment;

    for(unsigned i=first+1; i<tokens.size(); ++i)
    {
	// Create Node
	std::shared_ptr<Node> node(new Node());
	node->depth = depths[i];

	// Get From Stack
	std::shared_ptr<Node> parent = stack.top();

	// If node.depth == parent.depth, pop parent and add child to stack
	if (parent->depth == node->depth){
	    stack.pop();
	    stack.push( node );
	}
	// if node.depth > parent.depth, leave parent there and add child to stack
	else if (node->depth > parent->depth){
	    stack.push( node );
	}
	// if node.depth < parent.depth, pop parent until equal depth
	else if (node->depth < parent->depth){
	    while(stack.size() != 0 && node->depth < parent->depth){
		stack.pop();
		parent = stack.top();
	    }
	}

	// Parse Information
	node->parseString( tokens[i] );

	// Set Move Number
	node->number = parent->number + 1;	
	parent->children.push_back( node );
	node->parent = parent;
    }
}
コード例 #2
0
ファイル: uciengine.cpp プロジェクト: ajithcj/cutechess
void UciEngine::parseInfo(const QStringRef& line)
{
	static const QString types[] =
	{
		"depth",
		"seldepth",
		"time",
		"nodes",
		"pv",
		"multipv",
		"score",
		"currmove",
		"currmovenumber",
		"hashfull",
		"nps",
		"tbhits",
		"cpuload",
		"string",
		"refutation",
		"currline"
	};

	int type = -1;
	QStringRef token(nextToken(line));
	QVarLengthArray<QStringRef> tokens;

	while (!token.isNull())
	{
		token = parseUciTokens(token, types, 16, tokens, type);
		parseInfo(tokens, type);
	}
}
コード例 #3
0
CAIInterfaceLibraryInfo::CAIInterfaceLibraryInfo(
		const std::string& interfaceInfoFile) {

	std::vector<InfoItem> tmpInfo;
	parseInfo(tmpInfo, interfaceInfoFile);
	std::vector<InfoItem>::const_iterator ii;
	for (ii = tmpInfo.begin(); ii != tmpInfo.end(); ++ii) {
		SetInfo(ii->key, ii->value, ii->desc);
	}
}
コード例 #4
0
CAIInterfaceLibraryInfo::CAIInterfaceLibraryInfo(
		const std::string& interfaceInfoFile) {

	std::vector<InfoItem> tmpInfo;
	parseInfo(tmpInfo, interfaceInfoFile);
	std::vector<InfoItem>::iterator ii;
	for (ii = tmpInfo.begin(); ii != tmpInfo.end(); ++ii) {
		// TODO remove this, once we support non-string value types for AI Interface info
		info_convertToStringValue(&(*ii));
		SetInfo(ii->key, ii->valueTypeString, ii->desc);
	}
}
コード例 #5
0
ファイル: ArtistWidget.cpp プロジェクト: ErrAza/amarok
void
ArtistWidget::fetchInfo()
{
    // we genere the url for the demand on the lastFM Api
    KUrl url;
    url.setScheme( "http" );
    url.setHost( "ws.audioscrobbler.com" );
    url.setPath( "/2.0/" );
    url.addQueryItem( "method", "artist.getInfo" );
    url.addQueryItem( "api_key", Amarok::lastfmApiKey() );
    url.addQueryItem( "artist", m_artist->name() );

    The::networkAccessManager()->getData( url, this,
         SLOT(parseInfo(KUrl,QByteArray,NetworkAccessManagerProxy::Error)) );
}
コード例 #6
0
CSkirmishAILibraryInfo::CSkirmishAILibraryInfo(
		const std::string& aiInfoFile,
		const std::string& aiOptionFile) {

	std::vector<InfoItem> tmpInfo;
	parseInfo(tmpInfo, aiInfoFile);
	std::vector<InfoItem>::const_iterator ii;
	for (ii = tmpInfo.begin(); ii != tmpInfo.end(); ++ii) {
		SetInfo(ii->key, ii->value, ii->desc);
	}

	if (!aiOptionFile.empty()) {
		parseOptions(options, aiOptionFile);
	}
}
コード例 #7
0
CSkirmishAILibraryInfo::CSkirmishAILibraryInfo(
		const std::string& aiInfoFile,
		const std::string& aiOptionFile) {

	std::vector<InfoItem> tmpInfo;
	parseInfo(tmpInfo, aiInfoFile);
	std::vector<InfoItem>::iterator ii;
	for (ii = tmpInfo.begin(); ii != tmpInfo.end(); ++ii) {
		// TODO remove this, once we support non-string value types for Skirmish AI info
		info_convertToStringValue(&(*ii));
		SetInfo(ii->key, ii->valueTypeString, ii->desc);
	}

	if (!aiOptionFile.empty()) {
		parseOptions(options, aiOptionFile);
	}
}
コード例 #8
0
ファイル: info_lastfm.cpp プロジェクト: sushantg11/cuberok
void InfoLastFM::requestFinished(int id, bool err)
{
    if(err) {
        proxy->error(QString("Last.FM info: Request failed: %1.").arg(http.errorString()));
        if(httpGetId == id) httpGetId = 0;
        if(httpPostId == id) httpPostId = 0;
    } else {
        if(httpGetId == id) {
            httpGetId = 0;
            if(needInfo) {
                QByteArray arr = http.readAll();
                QString text = QString::fromUtf8((const char*)arr);
                proxy->log("Last.FM info response:" + text);
                QString artist, album, mbid, imageUrl, info;
                parseInfo(text, artist, album, mbid, imageUrl, info);
                if(album.size()) { // album found
                    if(imageUrl.size() && infoType == SInfo::AlbumArt)
                        proxy->setResponse(requestId, SInfo(SInfo::AlbumArt, "", imageUrl));
                    if(info.size() && infoType == SInfo::AlbumText)
                        proxy->setResponse(requestId, SInfo(SInfo::AlbumText, info, ""));
                } else if(artist.size()) { // artist found
                    if(imageUrl.size() && infoType == SInfo::ArtistArt)
                        proxy->setResponse(requestId, SInfo(SInfo::ArtistArt, "", imageUrl));
                    if(info.size() && infoType == SInfo::ArtistText)
                        proxy->setResponse(requestId, SInfo(SInfo::ArtistText, info, ""));
                }
                //emit xmlInfo(QString::fromUtf8((const char*)arr));
                needInfo = false;
            } else {
            }
        } else if(httpPostId == id) {
            httpPostId = 0;
            QString request = http.readAll();
            if(request.startsWith("OK")) {
                // nothing to do
            } else {
                proxy->warning("Last.FM info: Unknown response:  " + request);
            }
        }
    }
    doQueue();
}
コード例 #9
0
//! ----  slot_send_fanart_info_request -----------------------------------------
void CPlexusArtist::requestInfo(int id)
{
  //REMOVE ACENTOS E CARACTERES ESPECIAIS
  QString artistName = artist();
  artistName = artistName.normalized(QString::NormalizationForm_D);
  artistName = artistName.replace(QRegExp("[^a-zA-Z0-9\\s]"), "");
  //FIM REMOVE ACENTOS E CARACTERES ESPECIAIS

  CLog::log(LOG_INFO, "PROVIDER", "Requesting info for: '"+artistName+"'", "PlexusArtist");

  QUrlQuery url("http://plexusdynamics.com/admin/api/getartist.php?");
  url.addQueryItem("key", apiKey());
  url.addQueryItem("artist", artistName);

  QObject *reply = CNetworkAccess::instance()->get(url.query());
  _listRequests[reply] = id;

  CLog::log(LOG_DEBUG, "PROVIDER", "Connecting Signals", "PlexusArtist");
  connect(reply, SIGNAL(data(QByteArray)), this, SLOT(parseInfo(QByteArray)));
  connect(reply, SIGNAL(error(QNetworkReply*)), this, SLOT(stopSearch()));
}
コード例 #10
0
//! ----  slot_send_fanart_info_request -----------------------------------------
void CHTBackdrops::requestInfo(int id)
{
  //REMOVE ACENTOS E CARACTERES ESPECIAIS
  QString artistName = artist();
  artistName = artistName.normalized(QString::NormalizationForm_D);
  artistName = artistName.replace(QRegExp("[^a-zA-Z0-9\\s]"), "");
  //FIM REMOVE ACENTOS E CARACTERES ESPECIAIS

  CLog::log(LOG_INFO, "PROVIDER", "Requesting info for: '"+artistName+"'", "HTBackDrops");

  QUrlQuery url("http://htbackdrops.org/api/"+apiKey()+"/searchXML/?");
  url.addQueryItem("default_operator", "and");
  url.addQueryItem("keywords", artistName);

  QObject *reply = CNetworkAccess::instance()->get(url.query());
  _listRequests[reply] = id;

  CLog::log(LOG_DEBUG, "PROVIDER", "Connecting Signals", "HTBackDrops");
  connect(reply, SIGNAL(data(QByteArray)), this, SLOT(parseInfo(QByteArray)));
  connect(reply, SIGNAL(error(QNetworkReply*)), this, SLOT(stopSearch()));
}
コード例 #11
0
ファイル: uciengine.cpp プロジェクト: eliaskousk/cutechess
void UciEngine::parseLine(const QString& line)
{
	const QStringRef command(firstToken(line));

	if (command == "info")
	{
		if (m_ignoreThinking)
			return;
		parseInfo(command);
	}
	else if (command == "bestmove")
	{
		m_ponderState = NotPondering;
		if (m_ignoreThinking)
		{
			m_ignoreThinking = false;
			if (!m_bmBuffer.isEmpty())
			{
				foreach (const QString& line, m_bmBuffer)
					write(line, Unbuffered);
				m_bmBuffer.clear();
			}
			else
コード例 #12
0
ファイル: contexthelp.cpp プロジェクト: ktechlab/ktechlab-0.3
void ContextHelp::setContextHelp( QString name, QString help )
{
	//BEGIN modify help string as appropriate
	help = help.stripWhiteSpace();
	parseInfo( help );
	RichTextEditor::makeUseStandardFont( & help );
	addLinkTypeAppearances( & help );
	//END modify help string as appropriate
	
	// HACK Adjust top spacing according to whether the item description uses <p>.
	// This is because the help editor uses paragraphs, but old item help stored
	// in the items just uses <br>
	QFont f;
	int fontPixelSize = QFontInfo( f ).pixelSize();
	if ( help.contains( "<p>" ) )
		m_pBrowserView->setMarginHeight( 3-fontPixelSize );
	else
		m_pBrowserView->setMarginHeight( 3 );
	
	m_pNameLabel->setText( name );
	m_pBrowser->begin( itemLibrary()->itemDescriptionsDirectory() );
	m_pBrowser->write( help );
	m_pBrowser->end();
}
コード例 #13
0
FindSubtitlesWindow::FindSubtitlesWindow( QWidget * parent, Qt::WindowFlags f )
	: QDialog(parent,f)
{
	setupUi(this);

	set = 0; // settings

	subtitles_for_label->setBuddy(file_chooser->lineEdit());

	progress->hide();

	connect( file_chooser, SIGNAL(fileChanged(QString)),
             this, SLOT(setMovie(QString)) );
	connect( file_chooser->lineEdit(), SIGNAL(textChanged(const QString &)),
             this, SLOT(updateRefreshButton()) );

	connect( refresh_button, SIGNAL(clicked()),
             this, SLOT(refresh()) );

	connect( download_button, SIGNAL(clicked()),
             this, SLOT(download()) );

	/*
	connect( language_filter, SIGNAL(editTextChanged(const QString &)),
             this, SLOT(applyFilter(const QString &)) );
	*/
	connect( language_filter, SIGNAL(activated(int)),
             this, SLOT(applyCurrentFilter()) );

	table = new QStandardItemModel(this);
	table->setColumnCount(COL_USER + 1);

	proxy_model = new QSortFilterProxyModel(this);
	proxy_model->setSourceModel(table);
	proxy_model->setFilterKeyColumn(COL_LANG);
	proxy_model->setFilterRole(Qt::UserRole);

	view->setModel(proxy_model);
	view->setRootIsDecorated(false);
	view->setSortingEnabled(true);
	view->setAlternatingRowColors(true);
	view->header()->setSortIndicator(COL_LANG, Qt::AscendingOrder);
	view->setEditTriggers(QAbstractItemView::NoEditTriggers);
	view->setContextMenuPolicy( Qt::CustomContextMenu );

	connect(view, SIGNAL(activated(const QModelIndex &)),
            this, SLOT(itemActivated(const QModelIndex &)) );
	connect(view->selectionModel(), SIGNAL(currentChanged(const QModelIndex &,const QModelIndex &)),
            this, SLOT(currentItemChanged(const QModelIndex &,const QModelIndex &)) );

	connect(view, SIGNAL(customContextMenuRequested(const QPoint &)),
            this, SLOT(showContextMenu(const QPoint &)) );

	downloader = new SimpleHttp(this);

	connect( downloader, SIGNAL(downloadFailed(QString)),
             this, SLOT(showError(QString)) );
	connect( downloader, SIGNAL(downloadFinished(QByteArray)), 
             this, SLOT(downloadFinished()) );
	connect( downloader, SIGNAL(downloadFinished(QByteArray)), 
             this, SLOT(parseInfo(QByteArray)) );
	connect( downloader, SIGNAL(stateChanged(int)),
             this, SLOT(updateRefreshButton()) );

	connect( downloader, SIGNAL(connecting(QString)),
             this, SLOT(connecting(QString)) );
	connect( downloader, SIGNAL(dataReadProgress(int, int)),
             this, SLOT(updateDataReadProgress(int, int)) );

#ifdef DOWNLOAD_SUBS
	include_lang_on_filename = true;

	file_downloader = new FileDownloader(this);
	file_downloader->setModal(true);
	connect( file_downloader, SIGNAL(downloadFailed(QString)),
             this, SLOT(showError(QString)), Qt::QueuedConnection );
	connect( file_downloader, SIGNAL(downloadFinished(const QByteArray &)),
             this, SLOT(archiveDownloaded(const QByteArray &)), Qt::QueuedConnection );
#endif

	// Actions
	downloadAct = new QAction(this);
	downloadAct->setEnabled(false);
	connect( downloadAct, SIGNAL(triggered()), this, SLOT(download()) );

	copyLinkAct = new QAction(this);
	copyLinkAct->setEnabled(false);
	connect( copyLinkAct, SIGNAL(triggered()), this, SLOT(copyLink()) );

	context_menu = new QMenu(this);
	context_menu->addAction(downloadAct);
	context_menu->addAction(copyLinkAct);

	retranslateStrings();

	language_filter->setCurrentIndex(0);
}
コード例 #14
0
ファイル: uciengine.cpp プロジェクト: ajithcj/cutechess
void UciEngine::parseLine(const QString& line)
{
	const QStringRef command(firstToken(line));

	if (command == "info")
	{
		parseInfo(command);
	}
	else if (command == "bestmove")
	{
		if (state() != Thinking)
		{
			if (state() == FinishingGame)
				pong();
			else
				qDebug() << "Unexpected move from" << name();
			return;
		}

		QString moveString(nextToken(command).toString());
		m_moveStrings += " " + moveString;
		Chess::Move move = board()->moveFromString(moveString);

		if (!move.isNull())
			emitMove(move);
		else
			forfeit(Chess::Result::IllegalMove, moveString);
	}
	else if (command == "readyok")
	{
		pong();
	}
	else if (command == "uciok")
	{
		if (state() == Starting)
		{
			onProtocolStart();
			ping();
		}
	}
	else if (command == "id")
	{
		QStringRef tag(nextToken(command));
		if (tag == "name" && name() == "UciEngine")
			setName(nextToken(tag, true).toString());
	}
	else if (command == "registration")
	{
		if (nextToken(command) == "error")
		{
			qDebug("Failed to register UCI engine %s", qPrintable(name()));
			write("register later");
		}
	}
	else if (command == "option")
	{
		EngineOption* option = parseOption(command);
		QString variant;

		if (option == 0 || !option->isValid())
			qDebug("Invalid UCI option from %s: %s",
				qPrintable(name()), qPrintable(line));
		else if (!(variant = variantFromUci(option->name())).isEmpty())
			addVariant(variant);
		else if (option->name() == "UCI_Opponent")
			m_sendOpponentsName = true;
		else if (option->name() == "Ponder"
		     ||  (option->name().startsWith("UCI_") &&
			  option->name() != "UCI_LimitStrength" &&
			  option->name() != "UCI_Elo"))
		{
			// TODO: Deal with UCI features
		}
		else
		{
			addOption(option);
			return;
		}

		delete option;
	}
}
コード例 #15
0
ファイル: kword13import.cpp プロジェクト: JeremiasE/KFormula
KoFilter::ConversionStatus KWord13Import::convert( const QByteArray& from, const QByteArray& to )
{
    if ( to != "application/vnd.oasis.opendocument.text"
        || from != "application/x-kword" )
    {
        return KoFilter::NotImplemented;
    }

    // We need KimageIO's help in OOWriterWorker::convertUnknownImage


    KWord13Document kwordDocument;

    const QString fileName( m_chain->inputFile() );
    if ( fileName.isEmpty() )
    {
        kError(30520) << "No input file name!";
        return KoFilter::StupidError;
    }

    KoStore* store = KoStore::createStore( fileName, KoStore::Read );
    if ( store && store->hasFile( "maindoc.xml" ) )
    {
        kDebug(30520) <<"Maindoc.xml found in KoStore!";

        // We do not really care about errors while reading/parsing documentinfo
        store->open( "documentinfo.xml" );
        KoStoreDevice ioInfo( store );
        ioInfo.open( QIODevice::ReadOnly );
        kDebug (30520) <<"Processing document info...";
        if ( ! parseInfo ( &ioInfo, kwordDocument ) )
        {
            kWarning(30520) << "Parsing documentinfo.xml has failed. Ignoring!";
        }
        ioInfo.close();
        store->close();

        // ### TODO: error return values
        if ( ! store->open( "maindoc.xml" ) )
        {
            kError(30520) << "Opening root has failed";
            delete store;
            return KoFilter::StupidError;
        }
        KoStoreDevice ioMain( store );
        ioMain.open( QIODevice::ReadOnly );
        kDebug (30520) <<"Processing root...";
        if ( ! parseRoot ( &ioMain, kwordDocument ) )
        {
            kWarning(30520) << "Parsing maindoc.xml has failed! Aborting!";
            delete store;
            return KoFilter::StupidError;
        }
        ioMain.close();
        store->close();

        if ( store->open( "preview.png" ) )
        {

            kDebug(30520) <<"Preview found!";
            KoStoreDevice ioPreview( store );
            ioPreview.open( QIODevice::ReadOnly );
            const QByteArray image ( ioPreview.readAll() );
            if ( image.isNull() )
            {
                kWarning(30520) << "Loading of preview failed! Ignoring!";
            }
            else
            {
                kwordDocument.m_previewFile = new KTemporaryFile();
                kwordDocument.m_previewFile->setSuffix(".png");
                kwordDocument.m_previewFile->open(); // ### TODO check KTemporaryFile
                // ### TODO: check if file is correctly written
                kwordDocument.m_previewFile->write( image );
                kwordDocument.m_previewFile->close();
            }
            ioPreview.close();
            store->close();
        }
        else
        {
            kDebug(30520) <<"No preview found!";
        }
    }
    else
    {
        kWarning(30520) << "Opening store has failed. Trying raw XML file!";
        // Be sure to undefine store
        delete store;
        store = 0;

        QFile file( fileName );
        file.open( QIODevice::ReadOnly );
        if ( ! parseRoot( &file, kwordDocument ) )
        {
            kError(30520) << "Could not process document! Aborting!";
            file.close();
            return KoFilter::StupidError;
        }
        file.close();
    }

    if ( store && ! postParse( store, kwordDocument ) )
    {
        kError(30520) << "Error during post-parsing! Aborting!";
        return  KoFilter::StupidError;
    }

    // We have finished with the input store/file, so close the store (already done for a raw XML file)
    kDebug(30520) <<"Deleting input store...";
    delete store;
    store = 0;
    kDebug(30520) <<"Input store deleted!";

    KWord13OasisGenerator generator;

    kDebug(30520) << __FILE__ <<":" << __LINE__;

    if ( ! generator.prepare( kwordDocument ) )
    {
        kError(30520) << "Could not prepare the OASIS document! Aborting!";
        return KoFilter::StupidError;
    }

    const QString filenameOut ( m_chain->outputFile() );

    if ( filenameOut.isEmpty() )
    {
        kError(30520) << "Empty file name for saving as OASIS! Aborting!";
        return KoFilter::StupidError;
    }

    if ( ! generator.generate( filenameOut, kwordDocument ) )
    {
        kError(30520) << "Could not save as OASIS! Aborting!";
        return KoFilter::StupidError;
    }

    kDebug(30520) <<"Filter has finished!";

    return KoFilter::OK;
}
コード例 #16
0
ファイル: dingwidget.cpp プロジェクト: opieproject/opie
BroswerContent DingWidget::setText( QString word )
{
	queryword = word;
	return parseInfo();
}