Esempio n. 1
0
// ---------------------------------------------------------------
// PrintThread
//
// Loads the printer add-on and calls its take_job function with
// the spool file as argument.
//
// Parameters:
//    job - the spool job.
// ---------------------------------------------------------------
void 
Printer::PrintThread(Job* job)
{
	// Wait until resource is available
	fResource->Lock();
	bool failed = true;
		// Can we continue?
	if (!fAbort) {
		BPath path;
		bool canOpenFile;
		{
			BEntry entry(&job->EntryRef());
			path.SetTo(&entry);
			BFile jobFile(path.Path(), B_READ_WRITE);
			canOpenFile = jobFile.InitCheck() == B_OK;
		}
				// Tell the printer to print the spooled job
		if (canOpenFile && PrintSpooledJob(path.Path()) == B_OK) {
				// Remove spool file if printing was successful.
			job->Remove(); failed = false;
		}
	}
		// Set status of spooled job on error
	if (failed)
		job->SetStatus(kFailed);
	fResource->Unlock();
	job->Release();
	atomic_add(&fProcessing, -1);
	Release();
		// Notify print_server to process next spooled job
	be_app_messenger.SendMessage(PSRV_PRINT_SPOOLED_JOB);
}
	bool MultiCoreEvaluationRunner::init() {
		bool ok = true;
		
		Core::getInstance()->registerThread(this);
		
		
		
		
		if(mMinIndex < 0 || mMaxIndex < 0 || mMinIndex > mMaxIndex) {
			Core::log("MultiCoreEvaluationRunner: Indices for evaluations have not been valid: min="
						+ QString::number(mMinIndex) + " max=" + QString::number(mMaxIndex) + "!", true);
			return false;
		}
		
		QFile jobFile(mJobFile);
		if(!jobFile.exists()) {
			Core::log("MultiCoreEvaluationRunner: Could not access job file [" + mJobFile + "]!", true);
			return false;
		}
		
		
		Core::log("MultiCoreEvaluationRunner: FileScript: " + mJobFile + " MinIndex: " 
					+ QString::number(mMinIndex) + " MaxIndex: " + QString::number(mMaxIndex), true);
		
		
		
		
		return ok;
	}
Esempio n. 3
0
// ---------------------------------------------------------------
// HasCurrentPrinter
//
// Try to read the printer name from job file.
//
// Parameters:
//    name - the printer name.
//
// Returns:
//    true if successful.
// ---------------------------------------------------------------
bool Printer::HasCurrentPrinter(BString& name)
{
	BMessage settings;
		// read settings from spool file and get printer name
	BFile jobFile(&fJob->EntryRef(), B_READ_WRITE);
	return jobFile.InitCheck() == B_OK
		&& jobFile.Seek(sizeof(print_file_header), SEEK_SET) == sizeof(print_file_header)
		&& settings.Unflatten(&jobFile) == B_OK
		&& settings.FindString(PSRV_FIELD_CURRENT_PRINTER, &name) == B_OK;
}
Esempio n. 4
0
bool KMThreadJob::saveJobs()
{
	TQFile	f(jobFile());
	if (f.open(IO_WriteOnly))
	{
		TQTextStream	t(&f);
		TQIntDictIterator<KMJob>	it(m_jobs);
		for (;it.current();++it)
			t << it.current()->id() << CHARSEP << it.current()->name() << CHARSEP << it.current()->printer() << CHARSEP << it.current()->owner() << CHARSEP << it.current()->size() << endl;
		return true;
	}
	return false;
}
Esempio n. 5
0
bool KMThreadJob::loadJobs()
{
	TQFile	f(jobFile());
	if (f.exists() && f.open(IO_ReadOnly))
	{
		TQTextStream	t(&f);
		TQString		line;

		m_jobs.clear();
		while (!t.eof())
		{
			line = t.readLine().stripWhiteSpace();
			if (line.isEmpty())
				continue;
			TQStringList	ll = TQStringList::split(CHARSEP,line,true);
			if (ll.count() == 5)
			{
				KMJob	*job = new KMJob();
				job->setId(ll[0].toInt());
				job->setName(ll[1]);
				job->setPrinter(ll[2]);
				job->setOwner(ll[3]);
				job->setSize(ll[4].toInt());
				job->setState(KMJob::Printing);
				job->setType(KMJob::Threaded);
				job->setUri("proc:/"+ll[0]);
				if (job->id() > 0 && checkJob(job->id()))
					m_jobs.insert(job->id(),job);
				else
					delete job;
			}
		}
		return true;
	}
	return false;
}
Esempio n. 6
0
int main(int argc, char* argv[]) {
	BApplication app("application/x-vnd.Haiku.dump-print-job");
	
	bool printPicture = false;
	bool hasFiles = false;
	
	for (int i = 1; i < argc; i ++) {
		const char* arg = argv[i];
		if (strcmp(arg, "--pictures") == 0) {
			printPicture = true;
			continue;
		}

		hasFiles = true;
		BFile jobFile(arg, B_READ_WRITE);
		if (jobFile.InitCheck() != B_OK) {
			fprintf(stderr, "Error opening file %s!\n", arg);
			continue;
		}			

		PrintJobReader reader(&jobFile);
		if (reader.InitCheck() != B_OK) {
			fprintf(stderr, "Error reading spool file %s!", arg); 
			continue;
		}
		
		printf("Spool file: %s\n", arg); 
		printf("Job settings message:\n");
		reader.JobSettings()->PrintToStream();
		
		int32 pages = reader.NumberOfPages();
		printf("Number of pages: %d\n", (int)pages);
		for (int page = 0; page < pages; page ++) {
			printf("Page: %d\n", page+1);
			PrintJobPage pjp;
			if (reader.GetPage(page, pjp) != B_OK) {
				fprintf(stderr, "Error reading page!\n");
				break;
			}
				
			BPicture picture;
			BPoint pos; 
			BRect rect;
			printf("Number of pictures: %ld\n", pjp.NumberOfPictures());
			while (pjp.NextPicture(picture, pos, rect) == B_OK) {
				printf("Picture position = (%f, %f) bounds = [l: %f t: %f r: %f b: %f]\n",
					pos.x, pos.y,
					rect.left, rect.top, rect.right, rect.bottom);

				if (printPicture) {
					printf("Picture:\n");
					PicturePrinter printer;
					printer.Iterate(&picture);
				}
			}
		}
	}
	
	if (!hasFiles)
		printArguments(argv[0]);
}