void ofxMtJsonParser::update(){

	switch (state) {
		case DOWNLOADING_JSON: http.update(); break;
		case PARSING_JSON_IN_SUBTHREADS:
			updateParsing();
			break;

		case CHECKING_JSON:
			if(shouldStartParsingInSubThreads){
				setState(PARSING_JSON_IN_SUBTHREADS);
				shouldStartParsingInSubThreads = false;
			}break;

		case MERGE_THREAD_RESULTS:
			if(!isThreadRunning()){
				for(int i = 0; i < threads.size(); i++){ //delete threads that are long dead
					delete threads[i];
				}
				threads.clear();
				threadConfigs.clear();
				setState(FINISHED);
			}
			break;
		default: break;
	}
}
Beispiel #2
0
int RssRegexpDlg::exec()
{
	int r;
	
	if(m_feeds.isEmpty() || g_queues.isEmpty())
		return QDialog::Rejected;
	
	for(int i=0;i<m_feeds.size();i++)
	{
		comboFeed->addItem(m_feeds[i].name);
		comboFeed->setItemData(i, m_feeds[i].url);
		
		if(m_feeds[i].url == m_regexp.source)
			comboFeed->setCurrentIndex(i);
	}
	
	
	g_queuesLock.lockForRead();
	for(int i=0;i<g_queues.size();i++)
	{
		comboQueue->addItem(g_queues[i]->name());
		comboQueue->setItemData(i, g_queues[i]->uuid());
		comboQueue->setItemData(i, g_queues[i]->defaultDirectory(), Qt::UserRole+1);
		
		if(g_queues[i]->uuid() == m_regexp.queueUUID)
			comboQueue->setCurrentIndex(i);
	}
	g_queuesLock.unlock();
	
	if(m_regexp.target.isEmpty())
	{
		m_nLastQueue = comboQueue->currentIndex();
		if(m_nLastQueue != -1)
			m_regexp.target = comboQueue->itemData(m_nLastQueue, Qt::UserRole+1).toString();
		else
			m_regexp.target = QDir::homePath();
	}
	
	lineExpression->setText(m_regexp.regexp.pattern());
	lineTarget->setText(m_regexp.target);
	
	switch(m_regexp.tvs)
	{
	case RssRegexp::None:
		radioTVSNone->setChecked(true); break;
	case RssRegexp::SeasonBased:
		radioTVSSeason->setChecked(true); break;
	case RssRegexp::EpisodeBased:
		radioTVSEpisode->setChecked(true); break;
	case RssRegexp::DateBased:
		radioTVSDate->setChecked(true); break;
	}
	
	lineTVSFrom->setText(m_regexp.from);
	lineTVSTo->setText(m_regexp.to);
	checkTVSRepacks->setChecked(m_regexp.includeRepacks);
	checkTVSTrailers->setChecked(m_regexp.includeTrailers);
	checkTVSNoManuals->setChecked(m_regexp.excludeManuals);
	checkAddPaused->setChecked(m_regexp.addPaused);

	if(!m_regexp.linkRegexp.isEmpty())
	{
		radioParsingExtract->setChecked(true);
		lineParsingRegexp->setText(m_regexp.linkRegexp.pattern());
	}
	
	connect(comboQueue, SIGNAL(currentIndexChanged(int)), this, SLOT(queueChanged(int)));
	
	test();
	updateParsing();
	
	if((r = QDialog::exec()) == QDialog::Accepted)
	{
		m_regexp.regexp = QRegExp(lineExpression->text(), Qt::CaseInsensitive);
		m_regexp.target = lineTarget->text();
		
		m_regexp.queueUUID = comboQueue->itemData(comboQueue->currentIndex()).toString();
		m_regexp.source = comboFeed->itemData(comboFeed->currentIndex()).toString();
		
		m_regexp.from = lineTVSFrom->text();
		m_regexp.to = lineTVSTo->text();
		
		if(radioTVSNone->isChecked())
			m_regexp.tvs = RssRegexp::None;
		else if(radioTVSSeason->isChecked())
			m_regexp.tvs = RssRegexp::SeasonBased;
		else if(radioTVSEpisode->isChecked())
			m_regexp.tvs = RssRegexp::EpisodeBased;
		else
			m_regexp.tvs = RssRegexp::DateBased;
		
		m_strFeedName = comboFeed->currentText();
		m_regexp.includeRepacks = checkTVSRepacks->isChecked();
		m_regexp.includeTrailers = checkTVSTrailers->isChecked();
		m_regexp.excludeManuals = checkTVSNoManuals->isChecked();
		m_regexp.addPaused = checkAddPaused->isChecked();
		m_regexp.linkRegexp = QRegExp(lineParsingRegexp->text(), Qt::CaseInsensitive);
	}
	
	return r;
}