⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printwinc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * $Id: PrintWinC.C,v 1.3 2000/05/07 12:26:12 fnevgeny Exp $ * * Copyright (c) 1993 HAL Computer Systems International, Ltd. *  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. *                  1315 Dell Avenue *                  Campbell, CA  95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#include <config.h>#include "PrintWinC.h"#include "IshAppC.h"#include "AppPrefC.h"#include "MainWinC.h"#include "MsgItemC.h"#include "MsgC.h"#include "LoginWinC.h"#include "MsgPartC.h"#include "Mailcap.h"#include "Fork.h"#include "FolderC.h"#include "HeadPrefC.h"#include "HeaderC.h"#include "Query.h"#include "FileMsgC.h"#include "ParamC.h"#include <hgl/WArgList.h>#include <hgl/rsrc.h>#include <hgl/VBoxC.h>#include <hgl/VItemC.h>#include <hgl/RegexC.h>#include <hgl/WXmString.h>#include <hgl/TextMisc.h>#include <hgl/SysErr.h>#include <hgl/PtrListC.h>#include <Xm/Frame.h>#include <Xm/RowColumn.h>#include <Xm/ToggleB.h>#include <Xm/PushB.h>#include <Xm/Form.h>#include <Xm/Label.h>#include <Xm/TextF.h>#include <Xm/MessageB.h>#include <Xm/AtomMgr.h>#include <Xm/Protocols.h>#include <unistd.h>     // For sleep#include <signal.h>#include <errno.h>#include <sys/wait.h>PtrListC	*PrintWinC::fetchProcList = NULL;/*--------------------------------------------------------------- *  Function to determine if a mime message contains any enriched text */BooleanContainsEnriched(MsgPartC *part, Boolean doNext=True){   if ( !part ) return False;   if ( debuglev > 0 )      cout <<"Checking for enriched text in " <<part->conStr <<endl;   Boolean	enriched = False;   if ( part->IsMultipart() ) {      if ( part->IsAlternative() ) {	 MsgPartC	*child = part->BestAlternative(True/*forPrinting*/);	 enriched = ContainsEnriched(child, False/*doNext*/);      }      else if ( ContainsEnriched(part->child) )	 enriched = True;   }   else      enriched = part->IsEnriched();   if ( !enriched && doNext && part->next )      enriched = ContainsEnriched(part->next);   if ( debuglev > 0 && enriched ) cout <<"Found one" <<endl;   return enriched;} // End ContainsEnriched/*--------------------------------------------------------------- *  Method to determine if a mime message contains any richtext */BooleanContainsRich(MsgPartC *part, Boolean doNext=True){   if ( !part ) return False;   if ( debuglev > 0 )      cout <<"Checking for richtext in " <<part->conStr <<endl;   Boolean	isRich = False;   if ( part->IsMultipart() ) {      if ( part->IsAlternative() ) {	 MsgPartC	*child = part->BestAlternative(True/*forPrinting*/);	 isRich = ContainsRich(child, False/*doNext*/);      }      else if ( ContainsRich(part->child) )	 isRich = True;   }   else      isRich = part->IsRichText();   if ( !isRich && doNext && part->next )      isRich = ContainsRich(part->next);   if ( debuglev > 0 && isRich ) cout <<"Found one" <<endl;   return isRich;} // End ContainsRich/*--------------------------------------------------------------- *  Function to convert from text to enriched text in a string */voidMakeEnriched(StringC& string){   if ( string.size() == 0 ) return;   static RegexC	*ltnl = NULL;   if ( !ltnl ) ltnl = new RegexC("[<\n]");//// Count the number of '<'s and '\n's//   int	ltCount = string.NumberOf('<');   int	nlCount = string.NumberOf('\n');//// Allocate space to hold the result//   unsigned	strSize = string.size() + ltCount*2 + nlCount*2 + 1;   StringC	newStr(strSize);   StringC	sub;//// Loop through string and make the following substitutions://    '<'  becomes <<//    x*'\n' becomes (x+1)*'\n'//   int	pos, startPos = 0;   int	endPos = string.size() - 1;   while ( (pos=ltnl->search(string,startPos)) >= 0 ) {//// Copy text up to (but not including) the found character//      int	len = pos - startPos;      if ( len > 0 ) {	 sub = string(startPos, len);	 newStr += sub;      }            if ( string[pos] == '<' ) newStr += "<<";      else {	 newStr += "\n\n";	// Add one extra//// Copy any more newlines//	 while ( pos < endPos && string[pos+1] == '\n' ) {	    newStr += "\n";	    pos++;	 }      }      startPos = pos + 1;   } // End for each '<' or '\n'//// Add any remaining text//   if ( startPos < string.size() ) {      int       len = string.size() - startPos;      if ( len > 0 ) {	 sub = string(startPos, len);	 newStr += sub;      }   }   string = newStr;} // End MakeEnriched/*--------------------------------------------------------------- *  Function to convert from text to rich text in a string */voidMakeRich(StringC& string){   if ( string.size() == 0 ) return;   static RegexC	*ltnl = NULL;   if ( !ltnl ) ltnl = new RegexC("[<\n]");//// Count the number of '<'s and '\n's//   int	ltCount = string.NumberOf('<');   int	nlCount = string.NumberOf('\n');//// Allocate space to hold the result//   unsigned	strSize = string.size() + ltCount*3 + nlCount*4 + 1;   StringC	newStr(strSize);   StringC	sub;//// Loop through string and make the following substitutions://    '<'  becomes <lt>//    '\n' becomes <nl>\n//   int	pos, startPos = 0;   while ( (pos=ltnl->search(string,startPos)) >= 0 ) {//// Copy text up to (but not including) the found character//      int	len = pos - startPos;      if ( len > 0 ) {	 sub = string(startPos, len);	 newStr += sub;      }            if ( string[pos] == '<' ) newStr += "<lt>";      else		        newStr += "<nl>\n";      startPos = pos + 1;   } // End for each '<' or '\n'//// Add any remaining text//   if ( startPos < string.size() ) {      int       len = string.size() - startPos;      if ( len > 0 ) {	 sub = string(startPos, len);	 newStr += sub;      }   }   string = newStr;} // End MakeRich/*--------------------------------------------------------------- *  Function to convert ">From " to "From " in string */voidRestoreFroms(StringC& str){//// Look for occurrences of ">From " at the beginning of a line.  Replace//    them with "From "//   if ( str.StartsWith(">From ") ) str.CutBeg(1);   str.Replace("\n>From ", "\nFrom ");} // End RestoreFroms/*--------------------------------------------------------------- *  Dialog constructor */PrintWinC::PrintWinC(Widget parent) : HalDialogC("printWin", parent){   printQueryWin = NULL;   getQueryWin   = NULL;   loginWin      = NULL;   if ( !fetchProcList ) fetchProcList = new PtrListC;   WArgList	args;   Widget	list[4];//// Create appForm hierarchy//// appForm//    RowColumn	appRC//       Frame	hdrFrame//       Frame	ordFrame//       Form	cmdForm//   args.Reset();   args.LeftAttachment(XmATTACH_FORM);   args.RightAttachment(XmATTACH_FORM);   args.TopAttachment(XmATTACH_FORM);   args.BottomAttachment(XmATTACH_FORM);   args.Packing(XmPACK_TIGHT);   args.Orientation(XmVERTICAL);   Widget	appRC = XmCreateRowColumn(appForm, "appRC", ARGS);   Widget	hdrFrame = XmCreateFrame(appRC, "hdrFrame", 0,0);   		ordFrame = XmCreateFrame(appRC, "ordFrame", 0,0);   Widget	cmdForm  = XmCreateForm(appRC, "cmdForm", 0,0);//// Create hdrFrame hierarchy////   hdrFrame//	RadioBox	hdrRadio//	   ToggleButton	hdrAllTB//	   ToggleButton	hdrDispTB//	   ToggleButton	hdrNoneTB//   args.Reset();   args.Packing(XmPACK_TIGHT);   Widget hdrRadio = XmCreateRadioBox(hdrFrame, "hdrRadio", ARGS);   hdrAllTB  = XmCreateToggleButton(hdrRadio, "hdrAllTB",  0,0);   hdrDispTB = XmCreateToggleButton(hdrRadio, "hdrDispTB", 0,0);   hdrNoneTB = XmCreateToggleButton(hdrRadio, "hdrNoneTB", 0,0);   list[0] = hdrAllTB;   list[1] = hdrDispTB;   list[2] = hdrNoneTB;   XtManageChildren(list, 3);   XtManageChild(hdrRadio);//// Create ordFrame hierarchy////   ordFrame//	RadioBox	ordRadio//	   ToggleButton	ordParallelTB//	   ToggleButton	ordSerialTB//   args.Reset();   args.Packing(XmPACK_TIGHT);   Widget ordRadio = XmCreateRadioBox(ordFrame, "ordRadio", ARGS);   ordParallelTB = XmCreateToggleButton(ordRadio, "ordParallelTB", 0,0);   ordSerialTB   = XmCreateToggleButton(ordRadio, "ordSerialTB",   0,0);   list[0] = ordParallelTB;   list[1] = ordSerialTB;   XtManageChildren(list, 2);   XtManageChild(ordRadio);//// Create cmdForm hierarchy////   cmdForm//	Label		cmdLabel//	TextField	cmdTF//   args.Reset();   args.LeftAttachment(XmATTACH_FORM);   args.TopAttachment(XmATTACH_FORM);   args.BottomAttachment(XmATTACH_FORM);   args.RightAttachment(XmATTACH_NONE);   Widget	cmdLabel = XmCreateLabel(cmdForm, "cmdLabel", ARGS);   args.Reset();   args.LeftAttachment(XmATTACH_WIDGET, cmdLabel);   args.TopAttachment(XmATTACH_FORM);   args.BottomAttachment(XmATTACH_FORM);   args.RightAttachment(XmATTACH_FORM);   cmdTF = CreateTextField(cmdForm, "cmdTF", ARGS);   list[0] = cmdTF;   list[1] = cmdLabel;   XtManageChildren(list, 2);	// cmdForm children   list[0] = hdrFrame;//   list[1] = cmdForm;   XtManageChildren(list, 1);	// appRC children   XtManageChild(appRC);	// appForm children//// Create buttonRC hierarchy////   buttonRC//	PushButton	printPB//	PushButton	cancelPB//	PushButton	helpPB//   AddButtonBox();   Widget printPB  = XmCreatePushButton(buttonRC, "printPB",  0,0);   Widget cancelPB = XmCreatePushButton(buttonRC, "cancelPB", 0,0);   Widget helpPB   = XmCreatePushButton(buttonRC, "helpPB",   0,0);   list[0] = printPB;   list[1] = cancelPB;   list[2] = helpPB;   XtManageChildren(list, 3);	// buttonRC children   XtAddCallback(printPB, XmNactivateCallback, (XtCallbackProc)DoPrint,          	 (XtPointer)this);   XtAddCallback(cancelPB, XmNactivateCallback, (XtCallbackProc)DoHide, 		 (XtPointer)this);   XtAddCallback(helpPB, XmNactivateCallback, (XtCallbackProc)HalAppC::DoHelp, 		 (char *) "helpcard");   XtVaSetValues(appForm, XmNdefaultButton, printPB, NULL);   HandleHelp();//// Initialize settings//   XmToggleButtonSetState(ordParallelTB, True, True);   XmToggleButtonSetState(hdrDispTB, True, True);   XmTextFieldSetString(cmdTF, ishApp->appPrefs->printCmd);   printStr      = get_string(*ishApp, "printString",				       "Message sent to printer");   multiPrintStr = get_string(*ishApp, "multiPrintString",				       "Messages sent to printer");} // End PrintWinC constructor/*--------------------------------------------------------------- *  Destructor */PrintWinC::~PrintWinC(){   if ( ishApp->exiting ) {//// Kill any retrieval processes still running//      u_int	count = fetchProcList->size();      for (int i=count-1; i>=0; i--) {	 FetchProcT	*data = (FetchProcT*)*(*fetchProcList)[i];	 if ( kill(-data->pid, 0) == 0 ) kill(-data->pid, SIGKILL);      }   }}/*--------------------------------------------------------------- *  Callback to handle print */voidPrintWinC::DoPrint(Widget, PrintWinC *This, XtPointer){   This->cancelled = False;   VItemListC&	selList = ishApp->mainWin->MsgVBox().SelItems();   unsigned	selCount = selList.size();   Boolean	usePopup = ( ishApp->mainWin->popupMsg &&   			    !ishApp->mainWin->popupOnSelected);   unsigned	prtCount = usePopup ? 1 : selCount;   Boolean	printed;   StringC	statusMsg;   if ( prtCount > 1 ) {      Boolean parallel = XmToggleButtonGetState(This->ordParallelTB);      if ( parallel )	 printed = This->PrintParallel(selList);      else {//// Loop through looking for mime messages//         Boolean	anyMime = False;	 for (int i=0; !anyMime && i<selCount; i++) {	    MsgItemC	*item = (MsgItemC*)selList[i];	    anyMime = item->IsMime();	 }	 This->askAboutPrint = True;	 if ( anyMime )	    printed = This->PrintSerialMime(selList);	 else	    printed = This->PrintSerial(selList);      } // End if serial      if ( printed )	 statusMsg = This->multiPrintStr;   }   else { // A single message      MsgItemC	*item = NULL;      MsgC	*msg  = NULL;      if ( ishApp->mainWin->popupMsg ) {	 msg  = ishApp->mainWin->popupMsg;	 item = msg->icon;      }      else {	 item = (MsgItemC*)selList[0];	 msg = item->msg;      }      This->askAboutPrint = True;      if ( msg->IsMime() ) printed = This->PrintMime(msg);      else                 printed = This->Print(msg);      if ( printed && !This->cancelled )	 statusMsg = This->printStr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -