Hi Jürgen,

On Thu, Oct 27, 2011 at 12:01:09PM +0200, Jürgen Schmidt wrote:
> Hi Bert,
> 
> i assume it is again a threading issue on MacOS and the used Java
> API requires the main thread as well. I don't have a solution yet
> for you and i am not aware of any existing solution but we have to
> solve this issue anyway. But at the moment we have many other thinks
> to do with our ongoing IP clearance.
> 
> But your extensions is quite interesting and of course very useful
> for probably many users.
> 
> We can also think about a further UNO API to ask for the system
> default printer because the code should be available somewhere.

it is already available in
http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XPrinterServer.html#getPrinterNames

@Bert: see attached code.

Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina
/*
 * PrinterServerDemo.java
 *
 * Created on 2011.10.27 - 12:48:21
 *
 */

package org.openoffice.sdk.ui;

import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.uno.UnoRuntime;

/**
 *
 * @author ariel
 */
public class PrinterServerDemo {
    
    /** Creates a new instance of PrinterServerDemo */
    public PrinterServerDemo() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
            if (xContext == null) {
                System.err.println("ERROR: Could not bootstrap default 
Office.");
            } else {
                // 
http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XPrinterServer.html
                com.sun.star.awt.XPrinterServer xPrinterServer = 
(com.sun.star.awt.XPrinterServer)
                        UnoRuntime.queryInterface( 
com.sun.star.awt.XPrinterServer.class,
                        xContext.getServiceManager().createInstanceWithContext(
                        "com.sun.star.awt.PrinterServer", xContext));
                if ( xPrinterServer != null ){
                    String[] sPrinters = xPrinterServer.getPrinterNames();
                    for (String sPrinter : sPrinters) {
                        System.out.printf("Printer: %s\n", sPrinter);
                    }
                }
            }
        }
        catch (java.lang.Exception e){
            e.printStackTrace();
        }
        finally {
            System.exit( 0 );
        }
    }
    
}

Attachment: pgp2ADgufrqMz.pgp
Description: PGP signature

Reply via email to