Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, November 2007
Jambi + launching


Message 1 in thread

Is it possible to make a Jambi application respond to double-clicking in
Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like to
select a file in Finder and have my application launched for viewing it. If
it's possible, how do I do it?

Matias Piipari

Message 2 in thread

Matias Piipari wrote:
> Is it possible to make a Jambi application respond to double-clicking in
> Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like to
> select a file in Finder and have my application launched for viewing it. If
> it's possible, how do I do it?

Hi Matias,

Creating a "native" application with Java is somewhat different for 
every platform, and its more of a Java related topic than Qt Jambi, but 
here's what I know... I'll quickly run through the various OS'es:


-- Windows --

Simple solution is to pack it into a .bat file that launchers
 > java -cp %CLASSPATH_AND_LIBRARIES% name.of.mainclass
and follow our documentation on how to do deployment of our software, 
and maybe read the few posts over the last weeks where this has come up. 
HÃvard wrote an excellent guide on how to make executable .jar files:
http://lists.trolltech.com/qt-jambi-interest/2007-11/thread00032-0.html

The other option is to write a small .exe file in C++ that resolves the 
current version of Java based on registry keys, loads the jvm.dll, and 
starts the JVM. This is how the qtjambi.exe does it. This is a bit more 
work but looks nicer as you don't get a shell when you launch the app 
and you get customized icons etc...


-- Linux --

Same as windows except its .sh files. Same goes for the binary approach 
which looks nicer in Konqueror and similar...


-- Mac OS X --

I suspect this is the one you're most curious about given that you asked 
about Finder, and I had no clue how to do this myself, but knew it had 
to be via Application Bundles, so I started digging... Turns out Apple 
provides a nice tool

/Developer/Applications/Java Tools/Jar Bundler

which helps you to set this up. Say you want to create a bundle for the 
AnalogClock example in our demo. First of all, create dependent .jar 
files according to deployment docs (or cheat like I did and download the 
.jar files in the webstart on our website). From this you get a set of 
.jar files, one for qtjambi.jar with classes. One for Mac OS X with the 
native libraries and one with the actual application, in my case a .jar 
file containing only com.trolltech.examples.AnalogClock.

- Start Jar Bundler
- Add the .jars to the Classpath
- Specify the main class
- Add an icon if you like
- Press the "Create Application" button and you have an application bundle.

I suspect that this bundle only runs on a Mac box that has java 
installed, but it should be something to get you started at least.

-
best regards,
Gunnar



Message 3 in thread

Matias Piipari wrote:
> Is it possible to make a Jambi application respond to double-clicking in
> Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like to
> select a file in Finder and have my application launched for viewing it. If
> it's possible, how do I do it?

Hi Matias,

On second review it seems that you are asking for something completely 
different then what I answered, so I'll try again...

What you want is to get some sort of file-type association between your 
application and the file type in the OS. Qt Jambi doesn't have any built 
in functionality to do this. Doing this is also different for each system.

On Windows this is part of the Registry and you can specify a list of 
applications that should be run a given filetype is activated in 
explorer. This is for instance under:

\\My Computer\HKEY_LOCAL_MACHINE_SOFTWARE\Classes\.pdf\OpenWithList

which for .pdf contains AcroRd32.exe for instance. This is also 
accessible through the folder options, I believe.

I know linux and Mac OS X have similar concepts, but I don't know their 
spesifics.

best regards,
Gunnar


Message 4 in thread

On Thursday 22 November 2007, Gunnar Sletta wrote:
> Matias Piipari wrote:
> > Is it possible to make a Jambi application respond to double-clicking in
> > Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like to
> > select a file in Finder and have my application launched for viewing it.
> > If it's possible, how do I do it?
>
> Hi Matias,
>
> On second review it seems that you are asking for something completely
> different then what I answered, so I'll try again...
>
> What you want is to get some sort of file-type association between your
> application and the file type in the OS. Qt Jambi doesn't have any built
> in functionality to do this. Doing this is also different for each system.
>
> On Windows this is part of the Registry and you can specify a list of
> applications that should be run a given filetype is activated in
> explorer. This is for instance under:
>
> \\My Computer\HKEY_LOCAL_MACHINE_SOFTWARE\Classes\.pdf\OpenWithList
>
> which for .pdf contains AcroRd32.exe for instance. This is also
> accessible through the folder options, I believe.
>
> I know linux and Mac OS X have similar concepts, but I don't know their
> spesifics.
>
> best regards,
> Gunnar

I did a quick look at how KDE handles things and I came over these two 
specifications which at least KDE does unterstand, although I do not know how 
well Gnome implements them (although freedesktop.org specs are usually 
implemented pretty well by both environments):

http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
http://standards.freedesktop.org/desktop-entry-spec/latest/

From what I can make out you have to go a long way around: first, define a 
mime type that is associated with the file patterns that you use and then 
define a .desktop file for your application which defines the icon and the 
handling application for that mime type. I found that Google Earth on Linux 
does it that way and it seems to work.

I have no idea how Mac OS handles the association. I only know that it tries 
to use file type meta data that is stored in the file system to determine 
file type and not the file name itself.

Regards,
Gregor

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 5 in thread

Gunnar Sletta wrote:
> Matias Piipari wrote:
>> Is it possible to make a Jambi application respond to double-clicking in
>> Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like to
>> select a file in Finder and have my application launched for viewing 
>> it. If
>> it's possible, how do I do it?
> 
> I know linux and Mac OS X have similar concepts, but I don't know their 
> spesifics.

Hi Matias,

Turns out a college of mine wrote an article about how this works on Mac 
OS X with Qt a few years back:

http://doc.trolltech.com/qq/qq12-mac-events.html

Its basically about adding the file type associations to the Info.plist 
in the bundle. The OS will automatically pick these associations up when 
the app is launched the first time. The article uses some low-level 
events, which have since been replaced in Qt with a more appropriate Qt 
event:

http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/gui/QFileOpenEvent.html

best regards,
Gunnar



Message 6 in thread

Oh cool! Thanks a lot for your replies, Gunnar, Gregor! This QFileOpenEvent
together with the Jar Bundler will add a nice desktop integration touch for
my app on OS X. Would be nice to be able to make menus to the dock icon too,
though, and be able to drag things into it. That'll have to wait, as I don't
have the time or will to start writing native extensions for this purpose.

It's really quite annoying that status bar/dock/KDE/gnome applet support is
still lacking in all these current Java GUI frameworks though. Consequently
this is one of those cases where it's very tempting to write applications
that would actually really work in any really consistent way on one/small
number of platforms even if very similar user interaction mechanisms are
available on many more platforms (Windows/KDE/gnome/xfce,etc all have a very
similar idea of what the status bar does, for example). I for one have no
energy to write native bits and pieces for this purpose and then test my
application on n different desktop environments :)

On Nov 23, 2007 8:42 AM, Gunnar Sletta <gunnar@xxxxxxxxxxxxx> wrote:

> Gunnar Sletta wrote:
> > Matias Piipari wrote:
> >> Is it possible to make a Jambi application respond to double-clicking
> in
> >> Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like
> to
> >> select a file in Finder and have my application launched for viewing
> >> it. If
> >> it's possible, how do I do it?
> >
> > I know linux and Mac OS X have similar concepts, but I don't know their
> > spesifics.
>
> Hi Matias,
>
> Turns out a college of mine wrote an article about how this works on Mac
> OS X with Qt a few years back:
>
> http://doc.trolltech.com/qq/qq12-mac-events.html
>
> Its basically about adding the file type associations to the Info.plist
> in the bundle. The OS will automatically pick these associations up when
> the app is launched the first time. The article uses some low-level
> events, which have since been replaced in Qt with a more appropriate Qt
> event:
>
>
> http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/gui/QFileOpenEvent.html
>
> best regards,
> Gunnar
>
>
>

Message 7 in thread

Hmm looks as though I was just informed when ranting about system
tray/status area/whatever you want to call it:

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray/

Seems to support at least KDE,Gnome and Windows! The example code doesn't
work on OS X with the now retracted Java 6 Preview Release 1 though...
Confusingly SystemTray.isSupported() returns true but no custom icon is
still drawn in the dock (application name in dock just stays at the usual
"java" ) and also there's nothing in the dock menu either and none of the
events are sent. Oh well... :)

Java 6 includes

On Nov 24, 2007 5:52 PM, Matias Piipari <matias.piipari@xxxxxxxxx> wrote:

> Oh cool! Thanks a lot for your replies, Gunnar, Gregor! This
> QFileOpenEvent together with the Jar Bundler will add a nice desktop
> integration touch for my app on OS X. Would be nice to be able to make menus
> to the dock icon too, though, and be able to drag things into it. That'll
> have to wait, as I don't have the time or will to start writing native
> extensions for this purpose.
>
> It's really quite annoying that status bar/dock/KDE/gnome applet support
> is still lacking in all these current Java GUI frameworks though.
> Consequently this is one of those cases where it's very tempting to write
> applications that would actually really work in any really consistent way on
> one/small number of platforms even if very similar user interaction
> mechanisms are available on many more platforms (Windows/KDE/gnome/xfce,etc
> all have a very similar idea of what the status bar does, for example). I
> for one have no energy to write native bits and pieces for this purpose and
> then test my application on n different desktop environments :)
>
> On Nov 23, 2007 8:42 AM, Gunnar Sletta <gunnar@xxxxxxxxxxxxx> wrote:
>
> > Gunnar Sletta wrote:
> > > Matias Piipari wrote:
> > >> Is it possible to make a Jambi application respond to double-clicking
> > in
> > >> Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like
> > to
> > >> select a file in Finder and have my application launched for viewing
> > >> it. If
> > >> it's possible, how do I do it?
> > >
> > > I know linux and Mac OS X have similar concepts, but I don't know
> > their
> > > spesifics.
> >
> > Hi Matias,
> >
> > Turns out a college of mine wrote an article about how this works on Mac
> > OS X with Qt a few years back:
> >
> > http://doc.trolltech.com/qq/qq12-mac-events.html
> >
> > Its basically about adding the file type associations to the Info.plist
> > in the bundle. The OS will automatically pick these associations up when
> > the app is launched the first time. The article uses some low-level
> > events, which have since been replaced in Qt with a more appropriate Qt
> > event:
> >
> > http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/gui/QFileOpenEvent.html
> >
> >
> > best regards,
> > Gunnar
> >
> >
> >
>

Message 8 in thread

Matias Piipari wrote:
> Hmm looks as though I was just informed when ranting about system
> tray/status area/whatever you want to call it:
> 
> http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray/

Why not use the Qt Jambi classes for this:

http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/gui/QSystemTrayIcon.html

They work on Linux, Windows and Mac OS X. There is an example in our 
demo launcher that demonstrates how its used.

-
Gunnar


Message 9 in thread

Hi guys, sorry me again :)
I've now done this filetype association, but my application doesn't receive
the event. The application window does pop up to focus though. I tried
seeing whether the app would get the QFileOpenEvent by making an event
handler function like this:
public boolean event(QEvent event) {
        System.out.println("EVENT " + event.getClass().getName());
}
and no QFileOpenEvent is seen upon double clicking a file in Finder. What am
I doing wrong?

I've set the association by doing this in the Info.plist:

<key>CFBundleDocumentTypes</key>
    <array>
      <dict>
        <key>CFBundleTypeName</key>
        <string>XMS motif set</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleTypeExtensions</key>
        <array>
          <string>xms</string>
        </array>
      </dict>
    </array>


On Nov 23, 2007 8:42 AM, Gunnar Sletta <gunnar@xxxxxxxxxxxxx> wrote:

> Gunnar Sletta wrote:
> > Matias Piipari wrote:
> >> Is it possible to make a Jambi application respond to double-clicking
> in
> >> Finder (or in Nautilus, Explorer, etc for that matter)? I.e. I'd like
> to
> >> select a file in Finder and have my application launched for viewing
> >> it. If
> >> it's possible, how do I do it?
> >
> > I know linux and Mac OS X have similar concepts, but I don't know their
> > spesifics.
>
> Hi Matias,
>
> Turns out a college of mine wrote an article about how this works on Mac
> OS X with Qt a few years back:
>
> http://doc.trolltech.com/qq/qq12-mac-events.html
>
> Its basically about adding the file type associations to the Info.plist
> in the bundle. The OS will automatically pick these associations up when
> the app is launched the first time. The article uses some low-level
> events, which have since been replaced in Qt with a more appropriate Qt
> event:
>
>
> http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/gui/QFileOpenEvent.html
>
> best regards,
> Gunnar
>
>
>

Message 10 in thread

Matias Piipari wrote:
> Hi guys, sorry me again :)
> I've now done this filetype association, but my application doesn't receive
> the event. The application window does pop up to focus though. I tried
> seeing whether the app would get the QFileOpenEvent by making an event
> handler function like this:
> public boolean event(QEvent event) {
>         System.out.println("EVENT " + event.getClass().getName());
> }
> and no QFileOpenEvent is seen upon double clicking a file in Finder. What am
> I doing wrong?
> 
> I've set the association by doing this in the Info.plist:

Hi Matias,

Where do you install the event handler? The QFileOpenEvent is only sent 
to QApplication, so you need to either subclass QApplication and 
reimplement its event() function or install an event filter on 
QApplication. I recommend installing an event filter as mixing 
subclassing QApplication with QApplication.initialize becomes a bit messy...

-
Gunnar


Message 11 in thread

Ah, good point. The event method I'd overriden earlier was in my main window
class, not in the application class which receives that event. After
installing the event filter to QApplication.instance() this works. Thanks!

On Nov 28, 2007 9:01 AM, Gunnar Sletta <gunnar@xxxxxxxxxxxxx> wrote:

> Matias Piipari wrote:
> > Hi guys, sorry me again :)
> > I've now done this filetype association, but my application doesn't
> receive
> > the event. The application window does pop up to focus though. I tried
> > seeing whether the app would get the QFileOpenEvent by making an event
> > handler function like this:
> > public boolean event(QEvent event) {
> >         System.out.println("EVENT " + event.getClass().getName());
> > }
> > and no QFileOpenEvent is seen upon double clicking a file in Finder.
> What am
> > I doing wrong?
> >
> > I've set the association by doing this in the Info.plist:
>
> Hi Matias,
>
> Where do you install the event handler? The QFileOpenEvent is only sent
> to QApplication, so you need to either subclass QApplication and
> reimplement its event() function or install an event filter on
> QApplication. I recommend installing an event filter as mixing
> subclassing QApplication with QApplication.initialize becomes a bit
> messy...
>
> -
> Gunnar
>