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

📄 printwinc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 4 页
字号:
// Create the dialog if necessary//   if ( !printQueryWin ) {      BusyCursor(True);      WArgList	args;      args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL);      if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM);      Widget	w = XmCreateQuestionDialog(*this, "printQueryWin", ARGS);      XtAddCallback(w, XmNokCallback, (XtCallbackProc)AnswerQuery,		    (XtPointer)&answer);      XtAddCallback(w, XmNcancelCallback, (XtCallbackProc)AnswerQuery,		    (XtPointer)&answer);      XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HalAppC::DoHelp,		    (char *) "helpcard");//// Trap window manager close function//      XmAddWMProtocolCallback(XtParent(w), halApp->delWinAtom,			      (XtCallbackProc)WmClose,			      (caddr_t)&answer);      Widget	choiceFrame = XmCreateFrame(w, "choiceFrame", 0,0);      args.Reset();      args.Orientation(XmVERTICAL);      args.Packing(XmPACK_COLUMN);      args.RadioBehavior(True);      Widget choiceRadio = XmCreateRowColumn(choiceFrame, "choiceRadio", ARGS);      printOneYesTB = XmCreateToggleButton(choiceRadio, "printOneYesTB", 0,0);      printOneNoTB  = XmCreateToggleButton(choiceRadio, "printOneNoTB",  0,0);      printAllYesTB = XmCreateToggleButton(choiceRadio, "printAllYesTB", 0,0);      printAllNoTB  = XmCreateToggleButton(choiceRadio, "printAllNoTB",  0,0);      Widget wlist[4];      wlist[0] = printOneYesTB;      wlist[1] = printOneNoTB;      wlist[2] = printAllYesTB;      wlist[3] = printAllNoTB;      XtManageChildren(wlist, 4);      XtManageChild(choiceRadio);      XtManageChild(choiceFrame);      printQueryWin = w;      BusyCursor(False);      XmToggleButtonSetState(printOneYesTB, True, True);   } // End if dialog not created//// Set the strings, depending on this type//   StringC	msg;   if ( part->IsExternal() )      msg = get_string(printQueryWin, "attachmentMsg", "Print $NAME");   else      msg = get_string(printQueryWin, "inclusionMsg", "Print $NAME");//// Insert the file name//   StringC	name;   part->GetFileName(name);   msg.Replace("$NAME", name);   WXmString	wxmstr = (char*)msg;   XtVaSetValues(printQueryWin, XmNmessageString, (XmString)wxmstr, NULL);//// Show the dialog//   XtManageChild(printQueryWin);   XMapRaised(halApp->display, XtWindow(XtParent(printQueryWin)));//// Simulate the main event loop and wait for the answer//   answer = QUERY_NONE;   while ( answer == QUERY_NONE ) {      XtAppProcessEvent(halApp->context, XtIMXEvent);      XSync(halApp->display, False);   }   XtUnmanageChild(printQueryWin);   XSync(halApp->display, False);   XmUpdateDisplay(printQueryWin);//// Set state based on user's answer//   if ( answer == QUERY_CANCEL ) {      cancelled = True;      return False;   }   if ( XmToggleButtonGetState(printOneYesTB) ) return True;   if ( XmToggleButtonGetState(printOneNoTB)  ) return False;   if ( XmToggleButtonGetState(printAllYesTB) ) {      askAboutPrint = False;      printAll = True;      return True;   }   if ( XmToggleButtonGetState(printAllNoTB) ) {      askAboutPrint = False;      printAll = False;      return False;   }   return False;} // End OkToPrint/*--------------------------------------------------------------- *  Method to query user to see if part should be retrieved */BooleanPrintWinC::OkToGet(MsgPartC *part){//// See if the user already answered.//   if ( !askAboutPrint ) return printAll;   static QueryAnswerT	answer;//// Create the dialog if necessary//   if ( !getQueryWin ) {      BusyCursor(True);      WArgList	args;      args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL);      if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM);      Widget	w = XmCreateQuestionDialog(*this, "getQueryWin", ARGS);      XtAddCallback(w, XmNokCallback, (XtCallbackProc)AnswerQuery,		    (XtPointer)&answer);      XtAddCallback(w, XmNcancelCallback, (XtCallbackProc)AnswerQuery,		    (XtPointer)&answer);      XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HalAppC::DoHelp,		    (char *) "helpcard");//// Trap window manager close function//      XmAddWMProtocolCallback(XtParent(w), halApp->delWinAtom,			      (XtCallbackProc)WmClose,			      (caddr_t)&answer);      Widget	choiceFrame = XmCreateFrame(w, "choiceFrame", 0,0);      args.Reset();      args.Orientation(XmVERTICAL);      args.Packing(XmPACK_COLUMN);      args.RadioBehavior(True);      Widget choiceRadio = XmCreateRowColumn(choiceFrame, "choiceRadio", ARGS);      getOneYesTB = XmCreateToggleButton(choiceRadio, "getOneYesTB", 0,0);      getOneNoTB  = XmCreateToggleButton(choiceRadio, "getOneNoTB",  0,0);      getAllYesTB = XmCreateToggleButton(choiceRadio, "getAllYesTB", 0,0);      getAllNoTB  = XmCreateToggleButton(choiceRadio, "getAllNoTB",  0,0);      Widget wlist[4];      wlist[0] = getOneYesTB;      wlist[1] = getOneNoTB;      wlist[2] = getAllYesTB;      wlist[3] = getAllNoTB;      XtManageChildren(wlist, 4);      XtManageChild(choiceRadio);      XtManageChild(choiceFrame);      getQueryWin = w;      BusyCursor(False);      XmToggleButtonSetState(getOneYesTB, True, True);   } // End if dialog not created//// Stick in the file name//   StringC msg = get_string(getQueryWin, "messageString", "Retrieve $NAME");   StringC name;   part->GetFileName(name);   msg.Replace("$NAME", name);   WXmString	wxmstr = (char*)msg;   XtVaSetValues(getQueryWin, XmNmessageString, (XmString)wxmstr, NULL);//// Show the dialog//   XtManageChild(getQueryWin);   XMapRaised(halApp->display, XtWindow(XtParent(getQueryWin)));//// Simulate the main event loop and wait for the answer//   answer = QUERY_NONE;   while ( answer == QUERY_NONE ) {      XtAppProcessEvent(halApp->context, XtIMXEvent);      XSync(halApp->display, False);   }   XtUnmanageChild(getQueryWin);   XSync(halApp->display, False);   XmUpdateDisplay(getQueryWin);//// Set state based on user's answer//   if ( answer == QUERY_CANCEL ) {      cancelled = True;      return False;   }   if ( XmToggleButtonGetState(getOneYesTB) ) return True;   if ( XmToggleButtonGetState(getOneNoTB)  ) return False;   if ( XmToggleButtonGetState(getAllYesTB) ) {      askAboutPrint = False;      printAll = True;      return True;   }   if ( XmToggleButtonGetState(getAllNoTB) ) {      askAboutPrint = False;      printAll = False;      return False;   }   return False;} // End OkToGet/*--------------------------------------------------------------- *  Method to query user to see if mail-server message should be sent */BooleanPrintWinC::OkToSend(MsgPartC *part){   static QueryAnswerT	answer;   static Widget	sendQueryWin = NULL;//// Create the dialog if necessary//   if ( !sendQueryWin ) {      BusyCursor(True);      WArgList	args;      args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL);      if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM);      Widget	w = XmCreateQuestionDialog(*this, "sendQueryWin", ARGS);      XtAddCallback(w, XmNokCallback, (XtCallbackProc)AnswerQuery,				      (XtPointer)&answer);      XtAddCallback(w, XmNcancelCallback, (XtCallbackProc)AnswerQuery,					  (XtPointer)&answer);      XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HalAppC::DoHelp,					(char *) "helpcard");//// Trap window manager close function//      XmAddWMProtocolCallback(XtParent(w), halApp->delWinAtom,			      (XtCallbackProc)WmClose,			      (caddr_t)&answer);      sendQueryWin = w;      BusyCursor(False);   } // End if dialog not created//// Add the recipient name//   StringC	label = get_string(sendQueryWin, "messageString",			"Send following message to \"$SERVER\".\n\n$MESSAGE");   ParamC	*server = part->Param("server");   if ( !server ) {      label = "There is no mail server specified for this body part.";      PopupMessage(label);      return False;   }   label.Replace("$SERVER", server->val);//// Add the body//   StringC	body;   part->GetText(body);   int	pos = label.PosOf("$MESSAGE");   if ( pos < 0 ) {      while ( !label.EndsWith("\n\n") ) label += '\n';      label += body;   }   else      label(pos, 8) = body;   WXmString	wxmstr = (char*)label;   XtVaSetValues(sendQueryWin, XmNmessageString, (XmString)wxmstr, NULL);//// Show the dialog//   XtManageChild(sendQueryWin);   XMapRaised(halApp->display, XtWindow(XtParent(sendQueryWin)));//// Simulate the main event loop and wait for the answer//   answer = QUERY_NONE;   while ( answer == QUERY_NONE ) {      XtAppProcessEvent(halApp->context, XtIMXEvent);      XSync(halApp->display, False);   }   XtUnmanageChild(sendQueryWin);   XSync(halApp->display, False);   XmUpdateDisplay(sendQueryWin);//// Set state based on user's answer//   return (answer == QUERY_YES);} // End OkToSend/*--------------------------------------------------------------- *  Method to retrieve part */BooleanPrintWinC::GetPart(MsgPartC *part){   if ( !part->NeedFetch() ) return True;//// Prompt user for name and password if necessary//   if ( part->IsFTP() && part->userName.size() == 0 ) {//// Look up the ftp address//      ParamC	*site = part->Param("site");      if ( !site ) {	 StringC errmsg("The FTP site name was not specified for file: ");	 part->GetFileName(errmsg);	 errmsg += ".\nThe file could not be retrieved.";	 PopupMessage(errmsg);	 return False;      }//// Prompt for login//      if ( !loginWin ) loginWin = new LoginWinC(*this);      if ( !loginWin->GetLogin(site->val, part->userName, part->userPass) ) {	 cancelled = True;	 return False;      }   } // End if password needed//// For security reasons, confirm retrieval of mail-server attachments.// We don't want someone sending an attachment that will cause someone//   else to send obnoxious mail.//   if ( part->IsMail() && !OkToSend(part) ) return False;//// Look for a mailcap entry for message/external-body//   MailcapC	*mcap = MailcapEntry(MESSAGE_S, EXTERNAL_BODY_S, part);   if ( !mcap ) {      StringC errmsg = "I could not find a mailcap entry for: ";      errmsg += "message/external-body.";      errmsg += ".\nExternal files cannot be retrieved.";      PopupMessage(errmsg);      return False;   }//// See if there's a fetch command//   if ( mcap->present.size() == 0 ) {      StringC errmsg = "The mailcap entry for message/external-body does ";      errmsg += "not specify a command for getting the file.";      errmsg += ".\nExternal files cannot be retrieved.";      PopupMessage(errmsg);      return False;   }//// Clear out the old external file name and create a new name//   StringC	file;   if ( part->delDataFile && part->dataFile.size() > 0 ) {      file = part->dataFile;	// Reuse name      unlink(part->dataFile);      part->dataFile.Clear();      part->delDataFile = False;   }   else {      char	*cs = tempnam(NULL, "prnt.");      file = cs;      free(cs);   }//// If this is a mail server attachment, write the commands to the temp file//   if ( part->IsMail() ) {      StringC	body;      part->GetText(body);      if ( !body.WriteFile(file) ) {	 StringC errmsg = "Could not write file \"";	 errmsg += file;	 errmsg += "\" to send to mail server.\n";	 errmsg += SystemErrorMessage(errno);	 errmsg += ".\nThe file could not be retrieved.";	 PopupMessage(errmsg);	 return False;      }   } // End if mail server//// Build a data record to store info about this fetch//   FetchProcT	*data = new FetchProcT;   data->win  = this;   data->part = part;   data->file = file;//// Build the command for retrieval.  The present command is used since this//   is a message/external-body type.//   data->cmdStr = BuildCommand(mcap->present, part, file);   data->pid    = -1;   CallbackC	doneCb((CallbackFn*)FinishedGet, data);   data->pid = ForkIt(data->cmdStr, &doneCb);//// If the pid is < 0, an error occurred//   if ( data->pid < 0 ) {      PopupMessage(ForkStatusMsg(data->cmdStr, (int)data->pid));      delete data;   }//// Add this process to the list of running processes//   else {      void	*tmp = (void*)data;      fetchProcList->add(tmp);   }   return False;} // End GetPart/*--------------------------------------------------------------- *  Signal handler to catch completion of external file retrieval */voidPrintWinC::FinishedGet(int status, FetchProcT *data){   PrintWinC	*This = data->win;//// Remove this data from the list of active fetches//   void	*tmp = (void*)data;   fetchProcList->remove(tmp);   MsgPartC	*part = data->part;   StringC	name;   part->GetFileName(name);   if ( debuglev > 0 ) cout <<"FinishedGet for file: " <<name <<endl;   if ( status != 0 || part->IsMail() ) {      StringC	statmsg("File \"");      statmsg += name;      if ( status != 0 ) {	 statmsg += "\" could not be retrieved.\n";	 statmsg += ForkStatusMsg(data->cmdStr, status, data->pid);      }      else if ( part->IsMail() )	 statmsg += "\" will arrive by mail a later time.";      if ( This->IsShown() )	 This->PopupMessage(statmsg);      else	 halApp->PopupMessage(statmsg);   }   else {      part->dataFile    = data->file;      part->delDataFile = True;      if ( !This->IsShown() ) {	 StringC	statmsg("File \"");	 statmsg += name;	 statmsg += "\" has arrived and will now be printed.";	 halApp->PopupMessage(statmsg);      }      This->PrintNonText(part);   }   delete data;} // End FinishedGet/*--------------------------------------------------------------- *  Method to handle print of multiple messages in parallel */

⌨️ 快捷键说明

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