Fuel
Check-in [6a6a654b0d]
Not logged in
Overview
Comment:Support for Fossil queries FileActionDialog now becomes a (lame) question dialog box when no data is provided
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6a6a654b0db2537fc73774e7dc37d25cb2ae63d7
User & Date: kostas 2011-08-06 16:15:50.633
Context
2011-08-07
03:14
Improved support for fossil interactive questions check-in: 2c36e183b8 user: kostas tags: trunk
2011-08-06
16:15
Support for Fossil queries FileActionDialog now becomes a (lame) question dialog box when no data is provided check-in: 6a6a654b0d user: kostas tags: trunk
15:34
FileActionDialog now supports variable modal buttons check-in: d80b84c6b5 user: kostas tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to FileActionDialog.cpp.
18
19
20
21
22
23
24




25
26

27
28
29
30
31
32
33
		checkBox->setText(checkBoxText);
		checkBox->setEnabled(true);
		checkBox->setChecked(*checkBoxResult);
		this->checkBoxResult = checkBoxResult;
		ui->verticalLayout->insertWidget(2, checkBox);
	}





	foreach(const QString &s, listData)
		itemModel.appendRow(new QStandardItem(s));

}

FileActionDialog::~FileActionDialog()
{
	delete ui;
}








>
>
>
>
|
|
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
		checkBox->setText(checkBoxText);
		checkBox->setEnabled(true);
		checkBox->setChecked(*checkBoxResult);
		this->checkBoxResult = checkBoxResult;
		ui->verticalLayout->insertWidget(2, checkBox);
	}

	if(listData.empty())
		ui->listView->setVisible(false);
	else
	{
		foreach(const QString &s, listData)
			itemModel.appendRow(new QStandardItem(s));
	}
}

FileActionDialog::~FileActionDialog()
{
	delete ui;
}

Changes to MainWindow.cpp.
441
442
443
444
445
446
447
















448
449
450
451
452
453
454
{
	int exit_code = EXIT_FAILURE;
	if(!runFossilRaw(args, output, &exit_code, silent, detached))
		return false;

	return exit_code == EXIT_SUCCESS;
}
















//------------------------------------------------------------------------------
// Run fossil. Returns true if execution was succesfull regardless if fossil
// issued an error
bool MainWindow::runFossilRaw(const QStringList &args, QStringList *output, int *exitCode, bool silent, bool detached)
{
	if(!silent)
		log("> fossil "+args.join(" ")+"\n");







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
{
	int exit_code = EXIT_FAILURE;
	if(!runFossilRaw(args, output, &exit_code, silent, detached))
		return false;

	return exit_code == EXIT_SUCCESS;
}

//------------------------------------------------------------------------------
static QString ParseFossilQuery(QString query)
{
	// Extract question
	int qend = query.indexOf('(');
	if(qend == -1)
		qend = query.indexOf('[');
	Q_ASSERT(qend!=-1);
	query = query.left(qend);
	query = query.trimmed();
	query += "?";
	query[0]=QString(query[0]).toUpper()[0];
	return query;
}

//------------------------------------------------------------------------------
// Run fossil. Returns true if execution was succesfull regardless if fossil
// issued an error
bool MainWindow::runFossilRaw(const QStringList &args, QStringList *output, int *exitCode, bool silent, bool detached)
{
	if(!silent)
		log("> fossil "+args.join(" ")+"\n");
467
468
469
470
471
472
473









474













475


476






477














478



479


480




















481
482
483



484
485

486
487
488





489
490
491
492
493
494
495
	process.start(settings.fossilPath, args);
	if(!process.waitForStarted())
	{
		log("Could not start fossil executable '"+settings.fossilPath + "''\n");
		return false;
	}










	process.waitForFinished();













	QString std_output = process.readAllStandardOutput();









	QStringList lines = std_output.split('\n');


















	for(QStringList::iterator it=lines.begin(); it!=lines.end(); ++it)


	{




















		QString line = it->trimmed();
		if(line.isEmpty())
			continue;



		if(output)
			output->append(line);

		if(!silent)
			log(line+"\n");
	}






	QProcess::ExitStatus es = process.exitStatus();

	if(es!=QProcess::NormalExit)
		return false;

	if(exitCode)







>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>

>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
>
|
|
>
|
|
|
>
>
>
>
>







483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
	process.start(settings.fossilPath, args);
	if(!process.waitForStarted())
	{
		log("Could not start fossil executable '"+settings.fossilPath + "''\n");
		return false;
	}

#ifdef Q_WS_WIN
	const char *ans_yes = "y\r\n";
	const char *ans_no = "n\r\n";
	const char *ans_always = "a\r\n";
#else
	const char *ans_yes = "y\n";
	const char *ans_no = "n\n";
	const char *ans_always = "a\n";
#endif

	QStringList local_output;
	while(process.state()==QProcess::Running || !process.atEnd())
	{
		bool has_line = process.canReadLine();
		qint64 bytes_available=process.bytesAvailable();

		if(!process.waitForReadyRead(1*1000) && !has_line && bytes_available==0)
			break;

		// If no line yet, but some bytes available, maybe fossil is waiting for
		// user input
		if(!has_line && bytes_available>0)
		{
			QString line = process.readAll();
			line = line.trimmed();
			QString query = line.toLower();

			// Have we encountered a y/n query?
			if(line[line.length()-1]=='?' && query.indexOf("y/n")!=-1)
			{
				log(line);
				// Extract question
				query = ParseFossilQuery(query);

				int res =  QMessageBox::question(this, "Fossil", query, QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
				if(res==QMessageBox::Yes)
				{
					process.write(ans_yes, COUNTOF(ans_yes));
					log("Y\n");
				}
				else
				{
					process.write(ans_no, COUNTOF(ans_no));
					log("N\n");
				}
			}
			// Have we encountered a y/n/always query?
			else if(line[line.length()-1]=='?' && query.indexOf("a=always/y/n")!=-1)
			{
				log(line);
				// Extract question
				query = ParseFossilQuery(query);

				int res =  QMessageBox::question(this, "Fossil", query, QMessageBox::Yes|QMessageBox::No|QMessageBox::YesToAll, QMessageBox::No);
				if(res==QDialogButtonBox::Yes)
				{
					process.write(ans_yes, COUNTOF(ans_yes));
					log("Y\n");
				}
				else if(res==QDialogButtonBox::YesToAll)
				{
					process.write(ans_always, COUNTOF(ans_always));
					log("A\n");
				}
				else
				{
					process.write(ans_no, COUNTOF(ans_no));
					log("N\n");
				}
			}
		}

		while(process.canReadLine())
		{
			QString line = process.readLine();
			line = line.trimmed();
			//QString line = it->trimmed();
			if(line.isEmpty())
				continue;

			local_output.append(line);

			if(output)
				output->append(line);

			if(!silent)
				log(line+"\n");
		}

	}

	// Must be finished by now
	Q_ASSERT(process.state()==QProcess::NotRunning);

	QProcess::ExitStatus es = process.exitStatus();

	if(es!=QProcess::NormalExit)
		return false;

	if(exitCode)