📄 printwinc.c
字号:
BooleanPrintWinC::PrintParallel(VItemListC& list){ BusyCursor(True); Boolean printed = True; unsigned count = list.size(); for (int i=0; !cancelled && i<count; i++) { MsgItemC *item = (MsgItemC*)list[i]; MsgC *msg = item->msg; askAboutPrint = True; if ( msg->IsMime() ) { if ( !PrintMime(msg) ) printed = False; } else { if ( !Print(msg) ) printed = False; } } BusyCursor(False); return printed;} // End PrintParallel/*--------------------------------------------------------------- * Method to handle print of multiple messages as a single file */BooleanPrintWinC::PrintSerial(VItemListC& list){ BusyCursor(True); StringC statusMsg;//// Create a temporary file for storing messages// char *tmpFile = tempnam(NULL, "prnt."); if ( !tmpFile ) { int err = errno; statusMsg = "Could not create temporary file for printing.\n"; statusMsg += SystemErrorMessage(err); statusMsg += "\nWill attempt to print in parallel."; PopupMessage(statusMsg, XmDIALOG_WARNING); BusyCursor(False); return PrintParallel(list); } FILE *tfp = fopen(tmpFile, "w+"); if ( !tfp ) { int err = errno; statusMsg = "Could not create temporary file for printing.\n"; statusMsg += SystemErrorMessage(err); statusMsg += "\nWill attempt to print in parallel."; PopupMessage(statusMsg, XmDIALOG_WARNING); free(tmpFile); BusyCursor(False); return PrintParallel(list); } Boolean allHeaders = XmToggleButtonGetState(hdrAllTB); Boolean noHeaders = XmToggleButtonGetState(hdrNoneTB); StringC headStr;//// Read message separator// StringC banner = get_string(*this, "messageBanner", "\n-----------------------------------\n"); StringC banStr;//// Store selected messages in temporary file// Boolean error = False; unsigned count = list.size(); int i; for (i=0; !error && i<count; i++) { MsgItemC *item = (MsgItemC*)list[i]; MsgC *msg = item->msg; int index = msg->Number();//// Write banner// if ( banner.size() > 0 ) { banStr = banner; msg->ReplaceHeaders(banStr); error = !banStr.WriteFile(tfp); }//// Write headers and body// if ( !error ) error = !msg->WriteFile(tfp, !noHeaders, allHeaders, False/*no status header*/, True/*add a blank line*/, False/*don't protect Froms*/); } // End for each selected message//// Check for errors// if ( error ) { int err = errno; statusMsg = "Could not write to temporary file for printing.\n"; statusMsg += SystemErrorMessage(err); statusMsg += "\nWill attempt to print in parallel."; PopupMessage(statusMsg, XmDIALOG_WARNING); fclose(tfp); if ( debuglev > 0 ) cout <<"Unlinking temp file" <<endl; unlink(tmpFile); free(tmpFile); BusyCursor(False); return PrintParallel(list); } fclose(tfp); error = !PrintFile(tmpFile);//// Update status// if ( !error ) { count = list.size(); for (i=0; i<count; i++) { MsgItemC *item = (MsgItemC*)list[i]; item->SetPrinted(); } } BusyCursor(False); return !error;} // End PrintSerial/*--------------------------------------------------------------- * Method to handle print of multiple messages as a single file, * taking into account that one or more of them is a MIME * message */BooleanPrintWinC::PrintSerialMime(VItemListC& list){ PtrListC sepList; StringC statusMsg; BusyCursor(True);//// Create a temporary file for storing messages// char *tmpFile = tempnam(NULL, "prnt."); if ( !tmpFile ) { int err = errno; statusMsg = "Could not create temporary file for printing.\n"; statusMsg += SystemErrorMessage(err); statusMsg += "\nWill attempt to print in parallel."; PopupMessage(statusMsg, XmDIALOG_WARNING); BusyCursor(False); return PrintParallel(list); } FILE *tfp = fopen(tmpFile, "w+"); if ( !tfp ) { int err = errno; statusMsg = "Could not create temporary file for printing.\n"; statusMsg += SystemErrorMessage(err); statusMsg += "\nWill attempt to print in parallel."; PopupMessage(statusMsg, XmDIALOG_WARNING); free(tmpFile); BusyCursor(False); return PrintParallel(list); }//// Determine what text type will be used for printing// PrintTypeT pType = PRINT_PLAIN; unsigned count = list.size(); int i; for (i=0; pType != PRINT_ENRICHED && i<count; i++) { MsgItemC *item = (MsgItemC*)list[i]; MsgC *msg = item->msg; MsgPartC *body = msg->Body(); if ( msg->IsMime() ) { if ( ContainsEnriched(body) ) pType = PRINT_ENRICHED; else if ( ContainsRich (body) ) pType = PRINT_RICH; } }//// Read message separator// StringC banner; if ( pType == PRINT_ENRICHED ) banner = get_string(*this, "enrichedBanner", "\n\n-----------------------------------\n\n"); else if ( pType == PRINT_RICH ) banner = get_string(*this, "richtextBanner", "<nl>-----------------------------------<nl>"); else banner = get_string(*this, "messageBanner", "\n-----------------------------------\n"); StringC banStr;//// Store selected messages in temporary file// StringC bodyStr; Boolean error = False; for (i=0; !error && !cancelled && i<count; i++) { MsgItemC *item = (MsgItemC*)list[i]; MsgC *msg = item->msg; int index = msg->Number();//// Write banner// if ( banner.size() > 0 ) { banStr = banner; msg->ReplaceHeaders(banStr); error = !banStr.WriteFile(tfp); } if ( error ) continue;//// Write headers// error = !PrintHeaders(msg, tfp, pType); if ( error ) continue;//// Write body// if ( msg->IsMime() ) error = !PrintText(msg->Body(), tfp, sepList, pType); else if ( pType != PRINT_PLAIN ) { bodyStr.Clear(); msg->GetBodyText(bodyStr); if ( pType == PRINT_ENRICHED ) MakeEnriched(bodyStr); else MakeRich(bodyStr); error = !bodyStr.WriteFile(tfp); } else error = !msg->WriteBody(tfp, True/*add a blank line*/, False/*don't protect froms*/);//// Check for errors// if ( error ) { int err = errno; StringC errmsg = "Couldn't write to temp file while printing message: "; errmsg += msg->Number(); errmsg += ".\n" + SystemErrorMessage(err); PopupMessage(errmsg); fclose(tfp); if ( debuglev > 0 ) cout <<"Unlinking temp file" <<endl; unlink(tmpFile); free(tmpFile); BusyCursor(False); return False; } } // End for each message//// Exit if the operation was cancelled// if ( cancelled ) { fclose(tfp); if ( debuglev > 0 ) cout <<"Unlinking temp file" <<endl; unlink(tmpFile); free(tmpFile); BusyCursor(False); return False; } fclose(tfp);//// Print the temporary file.// error = !PrintFile(tmpFile, pType); if ( error ) { BusyCursor(False); return False; }//// Now make a pass and print the separate parts// count = sepList.size(); for (i=0; !cancelled && i<count; i++) { MsgPartC *part = (MsgPartC*)*sepList[i]; PrintNonText(part); }//// Update status// count = list.size(); for (i=0; i<count; i++) { MsgItemC *item = (MsgItemC*)list[i]; item->SetPrinted(); } BusyCursor(False); return True;} // End PrintSerialMime/*--------------------------------------------------------------- * Method to print a temporary file */BooleanPrintWinC::PrintFile(char *fileName, PrintTypeT pType, Boolean isTmp, int msgnum){//// Build the print command// StringC typeStr; MailcapC *mcap = NULL; if ( pType == PRINT_ENRICHED ) { mcap = MailcapEntry("text", "enriched"); typeStr = "text/enriched"; } else if ( pType == PRINT_RICH ) { mcap = MailcapEntry("text", "richtext"); typeStr = "text/richtext"; } else { mcap = MailcapEntry("text", "plain"); typeStr = "text/plain"; } StringC cmd; if ( mcap && mcap->print.size()>0 ) cmd = mcap->print; else cmd = ishApp->appPrefs->printCmd; cmd = BuildCommand(cmd, fileName, NULL, typeStr, NULL, NULL, NULL);//// Create some callback data// PrintProcT *proc = new PrintProcT; proc->win = this; proc->msgnum = msgnum; proc->cmdStr = cmd; if ( isTmp ) proc->tmpFile = fileName; CallbackC doneCb((CallbackFn*)PrintDone, proc); proc->pid = ForkIt(cmd, &doneCb); if ( proc->pid < 0 ) { StringC errmsg = "Could not print message"; if ( msgnum >= 0 ) { errmsg += " "; errmsg += msgnum; } else errmsg += "s."; errmsg += "\n" + ForkStatusMsg(cmd, (int)proc->pid); if ( IsShown() ) PopupMessage(errmsg); else halApp->PopupMessage(errmsg); if ( isTmp ) { unlink(fileName); free(fileName); } delete proc; return False; } return True;} // End PrintFile/*--------------------------------------------------------------- * Callback for completion of ForkIt */voidPrintWinC::PrintDone(int status, PrintProcT *proc){ if ( debuglev > 0 ) cout <<"Print process finished" <<endl;//// Report status of operation// if ( status != 0 ) { StringC errmsg; if ( proc->msgnum >= 0 ) { errmsg = "Message "; errmsg += proc->msgnum; } else errmsg = "Messages"; errmsg += " not printed.\n"; errmsg += ForkStatusMsg(proc->cmdStr, status, proc->pid); proc->win->PopupMessage(errmsg); } // End if there is an error if ( proc->tmpFile.size() > 0 ) { if ( debuglev > 0 ) cout <<"Unlinking temp file" <<endl; unlink(proc->tmpFile); } delete proc; return;} // End PrintDone/*--------------------------------------------------------------- * Method to remove ordFrame */voidPrintWinC::HideOrder(){ XtUnmanageChild(ordFrame);}/*--------------------------------------------------------------- * Method to display ordFrame */voidPrintWinC::ShowOrder(){ XtManageChild(ordFrame);}#if 0/*--------------------------------------------------------------- * Method to display dialog */voidPrintWinC::Show(Widget parent){//// Figure out what the default command will be// StringC cmd; Boolean isMime = False; Boolean richtext = False; Boolean enriched = False; if ( mainWin->popupMsg && !mainWin->popupOnSelected ) { if ( mainWin->popupMsg->IsMime() ) { isMime = True; if ( ContainsEnriched(mainWin->popupMsg->Tree()) ) enriched = True; else if ( ContainsRich(mainWin->popupMsg->Tree()) ) richtext = True; } } else { VItemListC& selList = mainWin->msgTBox->get_selected(); unsigned selCount = selList.size(); for (int i=0; !richtext && !enriched && i<selCount; i++) { MsgItemC *item = (MsgItemC*)selList[i]; MsgC *msg = item->Message(); if ( msg->IsMime() ) { isMime = True; if ( ContainsEnriched(msg->Tree()) ) enriched = True; else if ( ContainsRich (msg->Tree()) ) richtext = True; } } } printEnriched = False; printAsRich = False; useForkIt = False; if ( isMime ) { if ( enriched ) printEnriched = True; else if ( richtext ) printAsRich = True; MailcapC *mcap = MailcapEntry("text", enriched ? "enriched" : (richtext ? "richtext" : "plain")); if ( mcap && mcap->print.size()>0 ) { cmd = mcap->print; useForkIt = True; } } if ( cmd.size() == 0 ) { cmd = prefs->printCmd; useForkIt = False; } XmTextFieldSetString(cmdTF, cmd); HalDialogC::Show(parent);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -