80
80
import com .sun .star .util .CloseVetoException ;
81
81
import com .sun .star .util .URL ;
82
82
import com .sun .star .util .XCancellable ;
83
+ import com .sun .star .util .XChangesBatch ;
83
84
84
85
import de .muenchen .allg .afid .UNO ;
85
86
import de .muenchen .allg .afid .UnoProps ;
@@ -175,8 +176,18 @@ public static void oooMailMerge(final XPrintModel pmod, OutputType type)
175
176
176
177
String dbName = registerTempDatasouce (dataSource );
177
178
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 );
180
191
181
192
LOGGER .debug (L .m ("Temporäre Datenquelle: %1" , dbName ));
182
193
if (pmod .isCanceled ()) {
@@ -191,11 +202,7 @@ public static void oooMailMerge(final XPrintModel pmod, OutputType type)
191
202
new ProgressUpdater (pmod , (int ) Math .ceil ((double ) ds .getSize ()
192
203
/ countNextSets (pmod .getTextDocument ())));
193
204
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 );
199
206
}
200
207
catch (Exception e )
201
208
{
@@ -226,6 +233,15 @@ public static void oooMailMerge(final XPrintModel pmod, OutputType type)
226
233
removeTempDatasource (dbName , tmpDir );
227
234
ds .remove ();
228
235
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
+ }
229
245
230
246
// ... jetzt können wir nach Benutzerabbruch aufhören
231
247
if (pmod .isCanceled ()) return ;
@@ -764,6 +780,31 @@ public File getCSVFile()
764
780
}
765
781
}
766
782
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
+
767
808
/**
768
809
* Erzeugt das aus origDoc abgeleitete, für den OOo-Seriendruck heranzuziehende
769
810
* Input-Dokument im Verzeichnis tmpDir und nimmt alle notwendigen Anpassungen vor,
@@ -1363,12 +1404,11 @@ public Short getUNOMailMergeType()
1363
1404
* Drucker fuer den Seriendruck
1364
1405
* @throws Exception
1365
1406
* falls der MailMergeService nicht erzeugt werden kann.
1366
- *
1407
+ *
1367
1408
* @author Christoph Lutz (D-III-ITD-D101)
1368
1409
*/
1369
1410
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
1372
1412
{
1373
1413
final XJob mailMerge =
1374
1414
UnoRuntime .queryInterface (XJob .class , UNO .xMCF .createInstanceWithContext (
@@ -1394,17 +1434,6 @@ public void notifyMailMergeEvent(MailMergeEvent event)
1394
1434
{
1395
1435
progress .setMessage (L .m ("Sende Druckauftrag - bitte warten..." ));
1396
1436
}
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
- }
1408
1437
}
1409
1438
});
1410
1439
@@ -1431,14 +1460,6 @@ else if (type == OutputType.toShell)
1431
1460
else if (type == OutputType .toPrinter )
1432
1461
{
1433
1462
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 ));
1442
1463
}
1443
1464
MailMergeThread t = new MailMergeThread (mailMerge , outputDir , mmProps );
1444
1465
t .start ();
0 commit comments