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

Qt-jambi-interest Archive, August 2007
Using QWindowsMime in Jambi


Message 1 in thread

Hi,

I'm writing a Java program using Qt which accesses a remote server and lets you manipulate the files that are on the server, quite like an FTP client. I want to make my program DnD compatible, that is, I want users to be able to drop files into my program (which is pretty much just a tree in a window) and drag files out of it. Supporting drops is very easy, as I get a handy URI and can easily upload it. The tricky part is the drags, as I don't have a URI to give to the OS (I'm currently writing it for windows, though I hope to make versions for Mac and X11 too). After looking around in the docs, I found out about QWindowsMime, but I also found out that it is not visible to the Jambi version, instead, it is used internally. When I tried setting the mime type as "text/uri-list" and a list of QUrl's as the data (using setUrls()), no conversion was done (I think), and Qt passed a "UniformResourceLocator" to Windows, which doesn't seem to be equivalent to a CF_INETURL struct. How can I make Qt convert my data to a CF_INETURL?
Another question: I saw that when I drop a hyperlink into my program, Qt introduces a new mime type: "application/x-qt-windows-mime;value="FileContents"". If I'm not mistaken, it should be parallel to CFSTR_FILECONTENTS, which can also be a solution to my problem. So I tried setting that as the mime type, but I found out using Clipspy that Qt just leaves the mime type as it is, and does not automagically make it into a CFSTR_FILECONTENTS. Is there anything I can do to make Qt do the switch?

Thanks in advance,
Ron Ofir.


Message 2 in thread

Hi, Ron.

Ron Ofir wrote:
> Hi,
>
> I'm writing a Java program using Qt which accesses a remote server and lets you manipulate the files that are on the server, quite like an FTP client. I want to make my program DnD compatible, that is, I want users to be able to drop files into my program (which is pretty much just a tree in a window) and drag files out of it. Supporting drops is very easy, as I get a handy URI and can easily upload it. The tricky part is the drags, as I don't have a URI to give to the OS (I'm currently writing it for windows, though I hope to make versions for Mac and X11 too). After looking around in the docs, I found out about QWindowsMime, but I also found out that it is not visible to the Jambi version, instead, it is used internally. When I tried setting the mime type as "text/uri-list" and a list of QUrl's as the data (using setUrls()), no conversion was done (I think), and Qt passed a "UniformResourceLocator" to Windows, which doesn't seem to be equivalent to a CF_INETURL struct. How can I make Qt convert my data to a CF_INETURL?
>   

The mime data passed to Windows if you call setUrls() contains data of 
the custom type you mention as well as "text/uri-list". Is this not 
sufficient? I'm uncertain of exactly what you are trying to achieve, so 
I'm attaching an example in which you can drag files as URI-lists and 
drop them e.g. in Windows Explorer which will then accept and process 
the mime data. If the file is remote and not mapped into the file 
system, then the URI will not be accepted by Explorer, in which case you 
need to either drop the file into an application which supports fetching 
it through the given protocol, or you have to download the file yourself 
and then pass on the URI to the downloaded file.

Does this help?

-- Eskil






import java.util.ArrayList;
import java.util.List;

import com.trolltech.qt.core.QMimeData;
import com.trolltech.qt.core.QModelIndex;
import com.trolltech.qt.core.QUrl;
import com.trolltech.qt.core.Qt;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QDirModel;
import com.trolltech.qt.gui.QDrag;
import com.trolltech.qt.gui.QTreeView;

public class UrlsMime extends QTreeView {
    
    private QDirModel model = new QDirModel();
    
    public UrlsMime() {
        setModel(model);
        setDragEnabled(true);
    }
    
    @Override
    protected void startDrag(Qt.DropActions supportedActions) {
        List<QModelIndex> selectedIndexes = this.selectedIndexes();
                
        String path = model.filePath(selectedIndexes.get(0));
        
        QMimeData mimeData = new QMimeData();
        
        List<QUrl> urls = new ArrayList<QUrl>();
        urls.add(new QUrl("file:" + path));
        mimeData.setUrls(urls);
        
        QDrag drag = new QDrag(this);
        drag.setMimeData(mimeData);

        if (drag.exec(Qt.DropAction.MoveAction) == Qt.DropAction.TargetMoveAction)
            model.refresh(model.parent(selectedIndexes.get(0)));            
       
    }
    
    public static void main(String args[]) {
        QApplication.initialize(args);
        
        UrlsMime urlsMime = new UrlsMime();
        urlsMime.show();
        
        QApplication.exec();
    }
}

Message 3 in thread

-------- Original Message --------
From: Eskil Abrahamsen Blomfeldt <eblomfel@xxxxxxxxxxxxx>
Apparently from: qt-jambi-interest-request@xxxxxxxxxxxxx
To: Ron Ofir <ron@xxxxxxxxxxxxx>
Cc: qt-jambi-interest@xxxxxxxxxxxxx
Subject: Re: Using QWindowsMime in Jambi
Date: Tue, 14 Aug 2007 12:50:08 +0200

> Hi, Ron.
>
> Ron Ofir wrote:
> > Hi,
> >
> > I'm writing a Java program using Qt which accesses a remote server and lets you manipulate the files that are on the server, quite like an FTP client. I want to make my program DnD compatible, that is, I want users to be able to drop files into my program (which is pretty much just a tree in a window) and drag files out of it. Supporting drops is very easy, as I get a handy URI and can easily upload it. The tricky part is the drags, as I don't have a URI to give to the OS (I'm currently writing it for windows, though I hope to make versions for Mac and X11 too). After looking around in the docs, I found out about QWindowsMime, but I also found out that it is not visible to the Jambi version, instead, it is used internally. When I tried setting the mime type as "text/uri-list" and a list of QUrl's as the data (using setUrls()), no conversion was done (I think), and Qt passed a "UniformResourceLocator" to Windows, which doesn't seem to be equivalent to a CF_INETURL struct. How can I make Qt convert my data to a CF_INETURL?
> >
>
> The mime data passed to Windows if you call setUrls() contains data of
> the custom type you mention as well as "text/uri-list". Is this not
> sufficient? I'm uncertain of exactly what you are trying to achieve, so
> I'm attaching an example in which you can drag files as URI-lists and
> drop them e.g. in Windows Explorer which will then accept and process
> the mime data. If the file is remote and not mapped into the file
> system, then the URI will not be accepted by Explorer, in which case you 
> need to either drop the file into an application which supports fetching 
> it through the given protocol, or you have to download the file yourself 
> and then pass on the URI to the downloaded file.
>
> Does this help?
>
> -- Eskil

The file is remote, so Explorer does not accept the drop. I understand that I have to download
the file, but when should I do it? I can't download the file beforehand as I don't know what file
the user wants to download, and there too many files to download, and they can get pretty big too.
So when should I start downloading the file? And how can I make sure Explorer won't try to move
the file before it was fully downloaded (it happens with Swing if I start downloading when the
mouse exits the window)? Also, CF_INETURL should be the flavour that I want to use, as it's
supposed to contain a URL, which is what I have. Is there anyway I can tell Jambi to use
CF_INETURL instead of CF_HDROP?

Best regards,
Ron Ofir.


Message 4 in thread

Hi, Ron.

Ron Ofir wrote:
> The file is remote, so Explorer does not accept the drop. I understand that I have to download
> the file, but when should I do it? I can't download the file beforehand as I don't know what file
> the user wants to download, and there too many files to download, and they can get pretty big too.
> So when should I start downloading the file? And how can I make sure Explorer won't try to move
>   

These are not trivial problems. Looking around the web, it has been 
asked several times before, but I did not immediately find a cross 
platform solution. Qt Jambi does not support the CF_FILECONTENTS 
clipboard type as you correctly pointed out. A possible way to get 
support for this is to combine Qt Jambi code with native code where you 
register QWindowsMime conversions, but this would not be cross platform. 
QWindowsMime is not a part of Qt Jambi because its API depends on 
native, platform specific APIs.

I'll register this as a suggestion to make an attempt at adding cross 
platform support for your use case. In the mean time, I suggest you try 
looking at open source FTP clients and similar applications written in 
Qt or KDE to see if any of them have solved the problem.

> the file before it was fully downloaded (it happens with Swing if I start downloading when the
> mouse exits the window)? Also, CF_INETURL should be the flavour that I want to use, as it's
> supposed to contain a URL, which is what I have. Is there anyway I can tell Jambi to use
> CF_INETURL instead of CF_HDROP?
>   

Qt Jambi's mime data does indeed use CF_INETURL on Windows when it 
contains urls. The Windows clipboard type for this is called 
"UniformResourceLocator", as you pointed out in an earlier mail.

-- Eskil