1   /**
2    * JHylaFax - A java client for HylaFAX.
3    *
4    * Copyright (C) 2005 by Steffen Pingel <steffenp@gmx.de>
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19   */
20  package net.sf.jhylafax;
21  
22  import static net.sf.jhylafax.JHylaFAX.i18n;
23  import gnu.hylafax.HylaFAXClient;
24  import javax.swing.JFrame;
25  import net.sf.jhylafax.fax.FaxJob;
26  import net.sf.jhylafax.fax.HylaFAXClientHelper;
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.xnap.commons.gui.ErrorDialog;
30  import org.xnap.commons.io.Job;
31  import org.xnap.commons.io.ProgressMonitor;
32  import org.xnap.commons.io.UserAbortException;
33  
34  /**
35   * A dialog for polling of faxes.
36   * 
37   * @author Steffen Pingel
38   */
39  public class PollDialog extends AbstractFaxDialog {
40  
41  	private final static Log logger = LogFactory.getLog(PollDialog.class);
42  	
43  	public PollDialog(JFrame owner) {
44  		super(owner);
45  		
46  		addNumberTextField();
47  		addDateControls();
48  		
49  		FaxJob job = new FaxJob(); 
50  		HylaFAXClientHelper.initializeFromSettings(job);
51  		setJob(job);
52  		
53  		updateLabels();
54  		pack();
55  	}
56  	
57  	@Override
58  	public boolean apply() {
59  		if (!super.apply()) {
60  			return false;
61  		}
62  
63  		Job<?> ioJob = new Job() {
64  			public Object run(ProgressMonitor monitor) throws Exception
65  			{
66  				monitor.setTotalSteps(4);
67  				
68  				HylaFAXClient client = JHylaFAX.getInstance().getConnection(monitor);
69  				monitor.work(1);
70  				
71  				gnu.hylafax.Job pollJob = client.createJob();
72  				HylaFAXClientHelper.applyParameter(pollJob, getJob());
73  				pollJob.setProperty("POLL", "\"\" \"\"");
74  				monitor.work(1);
75  								
76  				client.submit(pollJob);
77  				monitor.work(2);
78  				
79  				return null;
80  			}
81  		};
82  		
83  		try {
84  			JHylaFAX.getInstance().runJob(PollDialog.this, ioJob);
85  			JHylaFAX.getInstance().updateTables();
86  		} 
87  		catch (UserAbortException e) {
88  			return false;
89  		} 
90  		catch (Exception e) {
91  			logger.debug("Error polling fax", e);
92  			ErrorDialog.showError(this, i18n.tr("Could not poll fax"), 
93  					i18n.tr("JHylaFAX Error"),
94  					e);
95  			return false;
96  		}
97  		return true;
98  	}
99  	
100 	public void updateLabels() {
101 		super.updateLabels();
102 		
103 		setTitle(i18n.tr("Poll Fax"));
104 	}
105 
106 }