Exemple #1
0
// convert list of expressions into a classad
//
static void printJobIfConstraint(std::vector<std::string> & exprs, const char* constraint, ExprTree *constraintExpr)
{
	if ( ! exprs.size())
		return;

	ClassAd ad;
	size_t ix;

	// convert lines vector into classad.
	while ((ix = exprs.size()) > 0) {
		const char * pexpr = exprs[ix-1].c_str();
		if ( ! ad.Insert(pexpr)) {
			dprintf(D_ALWAYS,"failed to create classad; bad expr = '%s'\n", pexpr);
			printf( "\t*** Warning: Bad history file; skipping malformed ad(s)\n" );
			exprs.clear();
			return;
		}
		exprs.pop_back();
	}

	if (!constraint || constraint[0]=='\0' || EvalBool(&ad, constraintExpr)) {
		printJob(ad);
		matchCount++; // if control reached here, match has occured
	}
}
Exemple #2
0
void handleGjob(gJobPtr cur) {
    int i;

    /*
     * Do whatever you want and free the structure.
     */
    printf("%d Jobs registered\n", cur->nbJobs);
    for (i = 0; i < cur->nbJobs; i++) printJob(cur->jobs[i]);
}
void
ShowImageWindow::_PrepareForPrint()
{
	if (fPrintSettings == NULL) {
		BPrintJob printJob(fImageView->Image()->name);
		if (printJob.ConfigJob() == B_OK)
			fPrintSettings = printJob.Settings();
	}

	fPrintOptions.SetBounds(fImageView->Bitmap()->Bounds());
	fPrintOptions.SetWidth(fImageView->Bitmap()->Bounds().Width() + 1);

	new PrintOptionsWindow(BPoint(Frame().left + 30, Frame().top + 50),
		&fPrintOptions, this);
}
bool
ShowImageWindow::_PageSetup()
{
	BPrintJob printJob(fImageView->Image()->name);
	if (fPrintSettings != NULL)
		printJob.SetSettings(new BMessage(*fPrintSettings));

	status_t status = printJob.ConfigPage();
	if (status == B_OK) {
		delete fPrintSettings;
		fPrintSettings = printJob.Settings();
	}

	return status == B_OK;
}
BMessage* PDocument::PrintSettings(void)
{
	TRACE();
	status_t result = B_OK;
	BPrintJob printJob(Title());
	if (! printerSetting)
	{
		result = printJob.ConfigPage();
		if ((result == B_OK) && (Lock()))
		{
			SetPrintSettings (printJob.Settings());
			paperRect 		= new BRect(printJob.PaperRect());
			printableRect	= new BRect(printJob.PrintableRect());
			SetModified();
			Unlock();
		}
	}
	return printerSetting;
}
Exemple #6
0
static void printJobAds(ClassAdList & jobs)
{
	if(longformat && use_xml) {
		std::string out;
		AddClassAdXMLFileHeader(out);
		printf("%s\n", out.c_str());
	}

	jobs.Open();
	ClassAd	*job;
	while (( job = jobs.Next())) {
		printJob(*job);
	}
	jobs.Close();

	if(longformat && use_xml) {
		std::string out;
		AddClassAdXMLFileFooter(out);
		printf("%s\n", out.c_str());
	}
}
Exemple #7
0
void
ShowImageWindow::_Print(BMessage *msg)
{
	status_t st;
	if (msg->FindInt32("status", &st) != B_OK || st != B_OK)
		return;

	_SavePrintOptions();

	BString name;
	fImageView->GetName(&name);

	BPrintJob printJob(name.String());
	if (fPrintSettings)
		printJob.SetSettings(new BMessage(*fPrintSettings));

	if (printJob.ConfigJob() == B_OK) {
		delete fPrintSettings;
		fPrintSettings = printJob.Settings();

		// first/lastPage is unused for now
		int32 firstPage = printJob.FirstPage();
		int32 lastPage = printJob.LastPage();
		BRect printableRect = printJob.PrintableRect();

		if (firstPage < 1)
			firstPage = 1;
		if (lastPage < firstPage)
			lastPage = firstPage;

		BBitmap* bitmap = fImageView->GetBitmap();
		float imageWidth = bitmap->Bounds().Width() + 1.0;
		float imageHeight = bitmap->Bounds().Height() + 1.0;

		float width;
		switch (fPrintOptions.Option()) {
			case PrintOptions::kFitToPage: {
				float w1 = printableRect.Width()+1;
				float w2 = imageWidth * (printableRect.Height() + 1) / imageHeight;
				if (w2 < w1)
					width = w2;
				else
					width = w1;
			}	break;
			case PrintOptions::kZoomFactor:
				width = imageWidth * fPrintOptions.ZoomFactor();
				break;
			case PrintOptions::kDPI:
				width = imageWidth * 72.0 / fPrintOptions.DPI();
				break;
			case PrintOptions::kWidth:
			case PrintOptions::kHeight:
				width = fPrintOptions.Width();
				break;

			default:
				// keep compiler silent; should not reach here
				width = imageWidth;
		}

		// TODO: eventually print large images on several pages
		printJob.BeginJob();
		fImageView->SetScale(width / imageWidth);
		// coordinates are relative to printable rectangle
		BRect bounds(bitmap->Bounds());
		printJob.DrawView(fImageView, bounds, BPoint(0, 0));
		fImageView->SetScale(1.0);
		printJob.SpoolPage();
		printJob.CommitJob();
	}
}
void PDocument::Print(void)
{
	TRACE();
	status_t	result	= B_OK;
	BPrintJob	printJob("doc_name");
	if (Lock())
	{
		if (printerSetting == NULL)
		{
			result = printJob.ConfigPage();
			if (result == B_OK)
			{
				// Get the user Settings
				SetPrintSettings(printJob.Settings());
				// Use the new settings for your internal use
				paperRect = new BRect(printJob.PaperRect());
				printableRect = new BRect(printJob.PrintableRect());
			}
		}
		// Setup the driver with user settings
		printJob.SetSettings(printerSetting);

		result = printJob.ConfigJob();
		if (result == B_OK)
		{
			// WARNING: here, setup CANNOT be NULL.
	         if (printerSetting == NULL)
	         {
	            // something's wrong, handle the error and bail out
	         }
//**dont know why this was here :-)      		 delete printerSetting;

			// Get the user Settings
			SetPrintSettings( printJob.Settings());
			paperRect 		= new BRect(printJob.PaperRect());
			printableRect	= new BRect(printJob.PrintableRect());

			// Now you have to calculate the number of pages
			// (note: page are zero-based)
			int32 firstPage = printJob.FirstPage();
			int32 lastPage = printJob.LastPage();

			// Verify the range is correct
			// 0 ... LONG_MAX -> Print all the document
			// n ... LONG_MAX -> Print from page n to the end
			// n ... m -> Print from page n to page m
			PEditor *activePEditor=editorManager->GetActivPEditor();
			if (activePEditor != NULL)
			{
				BView *editorView=activePEditor->GetView();
				if (editorView != NULL)
				{
					// calculate the Number of Pages
					bool locked	= editorView->LockLooper();
					int32 xPages,yPages;
					BRect editorRect = editorView->Bounds();
					xPages=editorRect.IntegerWidth()/printableRect->IntegerWidth();
					if (editorRect.IntegerWidth()%printableRect->IntegerWidth() > 0)
						xPages++;
					yPages=editorRect.IntegerHeight()/printableRect->IntegerHeight();
					if (editorRect.IntegerHeight()% printableRect->IntegerHeight() > 0)
						yPages++;
					int32 document_last_page= xPages*yPages;
					if (lastPage > document_last_page)
						lastPage = document_last_page;
					int32 nbPages = lastPage - firstPage + 1;
					if (nbPages <= 0)
						;
						//**return B_ERROR;
					// Now we can print the page
					printJob.BeginJob();
					// Print all pages
						bool can_continue = printJob.CanContinue();
					for (int i=firstPage-1; can_continue && i<lastPage ; i++)
					{
						float xStart	= (i%xPages)*printableRect->Width();
						float yStart	= (i/xPages)*printableRect->Height();
						BRect viewRect(xStart,yStart,xStart+printableRect->Width(),yStart+printableRect->Height());
//						printJob.DrawView(editorView, viewRect, BPoint(0,0));
						printJob.DrawView(editorView, viewRect, BPoint(printableRect->left,printableRect->top));
						printJob.SpoolPage();
						/*if (user_has_canceled)
						{
		       	        // tell the print_server to cancel the printjob
   	 	   	        	printJob.CancelJob();
							can_continue = false;
							break;
   	         		}*/
						can_continue = printJob.CanContinue();
					}
					if (can_continue)
						printJob.CommitJob();
					else
						result = B_ERROR;
					if (locked) editorView->UnlockLooper();
				}
			}
			else
			{
				//**error like no active Editor
			}
		}
		Unlock();
	}
}
Exemple #9
0
// Read history from a remote schedd
static void readHistoryRemote(classad::ExprTree *constraintExpr)
{
	printHeader();
	if(longformat && use_xml) {
		std::string out;
		AddClassAdXMLFileHeader(out);
		printf("%s\n", out.c_str());
	}

	classad::ClassAd ad;
	classad::ExprList *projList(new classad::ExprList());
	classad::ExprTree *projTree = static_cast<classad::ExprTree*>(projList);
	ad.Insert(ATTR_PROJECTION, projTree);
	ad.Insert(ATTR_REQUIREMENTS, constraintExpr);
	ad.InsertAttr(ATTR_NUM_MATCHES, specifiedMatch <= 0 ? -1 : specifiedMatch);

	DCSchedd schedd(g_name.size() ? g_name.c_str() : NULL, g_pool.size() ? g_pool.c_str() : NULL);
	if (!schedd.locate(Daemon::LOCATE_FOR_LOOKUP)) {
		fprintf(stderr, "Unable to locate remote schedd (name=%s, pool=%s).\n", g_name.c_str(), g_pool.c_str());
		exit(1);
	}
	Sock* sock;
	if (!(sock = schedd.startCommand(QUERY_SCHEDD_HISTORY, Stream::reli_sock, 0))) {
		fprintf(stderr, "Unable to send history command to remote schedd;\n"
			"Typically, either the schedd is not responding, does not authorize you, or does not support remote history.\n");
		exit(1);
	}
	classad_shared_ptr<Sock> sock_sentry(sock);

	if (!putClassAd(sock, ad) || !sock->end_of_message()) {
		fprintf(stderr, "Unable to send request to remote schedd; likely a server or network error.\n");
		exit(1);
	}

	while (true) {
		compat_classad::ClassAd ad;
		if (!getClassAd(sock, ad)) {
			fprintf(stderr, "Failed to recieve remote ad.\n");
			exit(1);
		}
		long long intVal;
		if (ad.EvaluateAttrInt(ATTR_OWNER, intVal) && (intVal == 0)) { // Last ad.
			if (!sock->end_of_message()) {
				fprintf(stderr, "Unable to close remote socket.\n");
			}
			sock->close();
			std::string errorMsg;
			if (ad.EvaluateAttrInt(ATTR_ERROR_CODE, intVal) && intVal && ad.EvaluateAttrString(ATTR_ERROR_STRING, errorMsg)) {
				fprintf(stderr, "Error %lld: %s\n", intVal, errorMsg.c_str());
				exit(intVal);
			}
			if (ad.EvaluateAttrInt("MalformedAds", intVal) && intVal) {
				fprintf(stderr, "Remote side had parse errors on history file");
				exit(1);
			}
			if (!ad.EvaluateAttrInt(ATTR_NUM_MATCHES, intVal) || (intVal != matchCount)) {
				fprintf(stderr, "Client and server do not agree on number of ads sent;\n"
					"Indicates lost network packets or an internal error\n");
				exit(1);
			}
			break;
		}
		matchCount++;
		printJob(ad);
	}

	if(longformat && use_xml) {
		std::string out;
		AddClassAdXMLFileFooter(out);
		printf("%s\n", out.c_str());
	}
}