Skip to content

Commit 38e31e6

Browse files
committed
trac#30282 allow loading of print properties with files
Before mail merge is startet, WollMux configures LO to load print properties with files and resets the property after mail merge has finished.
1 parent 38c228b commit 38e31e6

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

src/de/muenchen/allg/itd51/wollmux/print/OOoBasedMailMerge.java

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import com.sun.star.util.CloseVetoException;
8181
import com.sun.star.util.URL;
8282
import com.sun.star.util.XCancellable;
83+
import com.sun.star.util.XChangesBatch;
8384

8485
import de.muenchen.allg.afid.UNO;
8586
import de.muenchen.allg.afid.UnoProps;
@@ -175,8 +176,18 @@ public static void oooMailMerge(final XPrintModel pmod, OutputType type)
175176

176177
String dbName = registerTempDatasouce(dataSource);
177178

178-
File inputFile =
179-
createAndAdjustInputFile(tmpDir, pmod.getTextDocument(), dbName);
179+
boolean loadPrintSettings = false;
180+
try
181+
{
182+
loadPrintSettings = modifyLoadPrinterSetting(true);
183+
} catch (Exception e1)
184+
{
185+
LOGGER.warn(
186+
"Die Option 'Laden von Druckeinstellungen mit dem Dokument' konnte nicht gesetzt werden.\n"
187+
+ "Seriendrucke auf einem Drucker haben eventuell falsche Optionen gesetzt.");
188+
LOGGER.debug("", e1);
189+
}
190+
File inputFile = createAndAdjustInputFile(tmpDir, pmod.getTextDocument(), dbName);
180191

181192
LOGGER.debug(L.m("Temporäre Datenquelle: %1", dbName));
182193
if (pmod.isCanceled()) {
@@ -191,11 +202,7 @@ public static void oooMailMerge(final XPrintModel pmod, OutputType type)
191202
new ProgressUpdater(pmod, (int) Math.ceil((double) ds.getSize()
192203
/ countNextSets(pmod.getTextDocument())));
193204

194-
XPropertySet inSettings = UNO.XPropertySet(UNO.XMultiServiceFactory(pmod.getTextDocument())
195-
.createInstance("com.sun.star.document.Settings"));
196-
byte[] printerSetup = (byte[]) inSettings.getPropertyValue("PrinterSetup");
197-
String pNameSD = (String) inSettings.getPropertyValue("PrinterName");
198-
t = runMailMerge(dbName, tmpDir, inputFile, updater, type, pNameSD, printerSetup);
205+
t = runMailMerge(dbName, tmpDir, inputFile, updater, type);
199206
}
200207
catch (Exception e)
201208
{
@@ -226,6 +233,15 @@ public static void oooMailMerge(final XPrintModel pmod, OutputType type)
226233
removeTempDatasource(dbName, tmpDir);
227234
ds.remove();
228235
inputFile.delete();
236+
try
237+
{
238+
modifyLoadPrinterSetting(loadPrintSettings);
239+
} catch (Exception e1)
240+
{
241+
LOGGER.warn(
242+
"Die Einstellung 'Laden von Druckeinstellungen mit dem Dokument' konnte nicht zurückgesetzt werden.");
243+
LOGGER.debug("", e1);
244+
}
229245

230246
// ... jetzt können wir nach Benutzerabbruch aufhören
231247
if (pmod.isCanceled()) return;
@@ -764,6 +780,31 @@ public File getCSVFile()
764780
}
765781
}
766782

783+
/**
784+
* Modifies the configuration option for loading print properties when files are opened.
785+
*
786+
* @param load
787+
* True if the properties should be loaded, false otherwise. @return The value before the
788+
* modification.
789+
* @throws com.sun.star.uno.Exception
790+
* Couldn't modify the property.
791+
*/
792+
private static Boolean modifyLoadPrinterSetting(boolean load) throws com.sun.star.uno.Exception
793+
{
794+
Object cp = UNO.createUNOService("com.sun.star.configuration.ConfigurationProvider");
795+
com.sun.star.beans.PropertyValue aPathArgument = new com.sun.star.beans.PropertyValue();
796+
aPathArgument.Name = "nodepath";
797+
aPathArgument.Value = "/org.openoffice.Office.Common/Save/Document";
798+
799+
Object ca = UNO.XMultiServiceFactory(cp).createInstanceWithArguments(
800+
"com.sun.star.configuration.ConfigurationUpdateAccess", new Object[] { aPathArgument });
801+
XPropertySet props = UNO.XPropertySet(ca);
802+
boolean lastValue = AnyConverter.toBoolean(props.getPropertyValue("LoadPrinter"));
803+
props.setPropertyValue("LoadPrinter", load);
804+
UnoRuntime.queryInterface(XChangesBatch.class, ca).commitChanges();
805+
return lastValue;
806+
}
807+
767808
/**
768809
* Erzeugt das aus origDoc abgeleitete, für den OOo-Seriendruck heranzuziehende
769810
* Input-Dokument im Verzeichnis tmpDir und nimmt alle notwendigen Anpassungen vor,
@@ -1363,12 +1404,11 @@ public Short getUNOMailMergeType()
13631404
* Drucker fuer den Seriendruck
13641405
* @throws Exception
13651406
* falls der MailMergeService nicht erzeugt werden kann.
1366-
*
1407+
*
13671408
* @author Christoph Lutz (D-III-ITD-D101)
13681409
*/
13691410
private static MailMergeThread runMailMerge(String dbName, final File outputDir,
1370-
File inputFile, final ProgressUpdater progress, final OutputType type,
1371-
String printerName, byte[] printerSetup) throws Exception
1411+
File inputFile, final ProgressUpdater progress, final OutputType type) throws Exception
13721412
{
13731413
final XJob mailMerge =
13741414
UnoRuntime.queryInterface(XJob.class, UNO.xMCF.createInstanceWithContext(
@@ -1394,17 +1434,6 @@ public void notifyMailMergeEvent(MailMergeEvent event)
13941434
{
13951435
progress.setMessage(L.m("Sende Druckauftrag - bitte warten..."));
13961436
}
1397-
if (type == OutputType.toPrinter)
1398-
{
1399-
try {
1400-
XPropertySet inSettings = UNO.XPropertySet(UNO.XMultiServiceFactory(event.Model)
1401-
.createInstance("com.sun.star.document.Settings"));
1402-
inSettings.setPropertyValue("PrinterSetup", printerSetup);
1403-
inSettings.setPropertyValue("PrinterName", printerName);
1404-
} catch (com.sun.star.uno.Exception e) {
1405-
LOGGER.error("Druckereinstellungen konnten nicht gesetzt werden.", e);
1406-
}
1407-
}
14081437
}
14091438
});
14101439

@@ -1431,14 +1460,6 @@ else if (type == OutputType.toShell)
14311460
else if (type == OutputType.toPrinter)
14321461
{
14331462
mmProps.add(new NamedValue("SinglePrintJobs", Boolean.FALSE));
1434-
// is also set in notifyMailMergeEvent-Method, but if it isn't set here
1435-
// the default printer is always used.
1436-
PropertyValue[] printOps = new PropertyValue[1];
1437-
printOps[0] = new PropertyValue();
1438-
printOps[0].Name = "PrinterName";
1439-
printOps[0].Value = printerName;
1440-
LOGGER.debug(L.m("Seriendruck - Setze Drucker: %1", printerName));
1441-
mmProps.add(new NamedValue("PrintOptions", printOps));
14421463
}
14431464
MailMergeThread t = new MailMergeThread(mailMerge, outputDir, mmProps);
14441465
t.start();

0 commit comments

Comments
 (0)