Results 1 to 12 of 12

Thread: Dragging files from QListWidget to another app (file browser)

  1. #1
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Dragging files from QListWidget to another app (file browser)

    Hi,
    I have a QListWidget showing a list of remote files, that the user can download. I want the user to be able to drag an item from the list to his desktop for example, in order to download it. I can use the dragEnterEvent function, but the problem is I can't set immediatly the mime data, as I have to download the file first.
    Actually, I thought to provide an empty mime data, to get the place where the file was dropped and to download the data to that file, but I don't see a way to do this.
    Any idea ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dragging files from QListWidget to another app (file browser)

    Is the file available over some standard protocol like http or ftp? If so, you might want to try using text/uri-list (or simmilar) mime-type and your desktop manager will handle the rest. Are you sure you really want the dragEnterEvent? You won't be able to drop any items on the desktop this way, only on your widget for which you implement the event. If you want to do it with the desktop, you have to offer some mime-type the desktop is aware of (like text/uri-list) and it'll handle the rest.

    You might want to try to drop it as some custom file and download the file after the drop is done. I think you should implement it when the method starting the drag (I don't remember its name right now) returns.

  3. The following user says thank you to wysota for this useful post:

    madcat (29th June 2006)

  4. #3
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dragging files from QListWidget to another app (file browser)

    Hi, thanks for your answer.
    The protocol is not standard, so I can't let the desktop manager deal with it... Maybe I didn't talk about the right functions, anyway the problem is still here : I can't provide the data when the drag occurs, and I gotta find a workaround

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dragging files from QListWidget to another app (file browser)

    Well... you have to find a mime which the "other application" understands and use it. Take a look at the mime database and search for a type which represents a generic file and use it (but a file, not a filename -- so uri-list is out of the question). Then implement your drag. Eventually you'll call QDrag::start(). Now if I understand the mechanism correctly, as a return value, you'll get an action which already occured. You should download the file here. Now a good question is what to do next -- how to inform the other app that the file was downloaded. You should make some experiments to see when appropriate calls are made (for example, when does QDrag::start() return). If you come up with some results, please share them with me, and we'll see what to do next.

  6. The following user says thank you to wysota for this useful post:

    madcat (29th June 2006)

  7. #5
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dragging files from QListWidget to another app (file browser)

    Hi,
    OK, say I play it with QDrag::start(). You say I have a way to get informed of the place where the file was dropped (ie. explorer/nautilus/konqueror/... will inform me of the folder ?). If yes, then you solved my problem. The other app (the file browser) shouldn't be informed when the download is finished, the application will tell the user it is.

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dragging files from QListWidget to another app (file browser)

    Quote Originally Posted by madcat
    You say I have a way to get informed of the place where the file was dropped (ie. explorer/nautilus/konqueror/... will inform me of the folder ?).
    No, unfortunately I don't I don't have the slightest idea how to retrieve the "path". It all depends on what object you actually perform the drop. It doesn't have to be a "path" at all.

    The other app (the file browser) shouldn't be informed when the download is finished, the application will tell the user it is.
    It should, because it has to react on the drop. It should work in such a way, that you transfer the contents of the file to that "other" application and it saves the file (or whatever it is) to the appropriate place. That's how in general drag&drop works.

  9. #7
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dragging files from QListWidget to another app (file browser)

    If it is more clear for you : imagine an ftp client where the user could drag the files from the client to the Finder/Explorer/Konqueror/Nautilus/other... The idea is to get the place where the file was dropped, and to download the file to this place. I don't want to drop file on my app, this function is already working. Thanks for your answers though

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dragging files from QListWidget to another app (file browser)

    Quote Originally Posted by madcat
    If it is more clear for you : imagine an ftp client where the user could drag the files from the client to the Finder/Explorer/Konqueror/Nautilus/other... The idea is to get the place where the file was dropped, and to download the file to this place. I don't want to drop file on my app, this function is already working. Thanks for your answers though
    You miss one point. What happens if you drop a remote file on, for example, a text editor? According to me the file should get downloaded to some temporary file and opened in the editor. So in this case there is no "path" to download the file to. The object of the drag is the file contents itself. It is the editor which handles the drop and the ftp client which provides the contents of the file. Doing otherwise neglects the design of drag and drop. If you insist on such a behaviour, then you should do it the other way round -- drag the directory icon to your ftp client and drop it there, this way the pattern will be preserved (the target application processes the drag object (the directory) according to its own needs), you'll get the destination, etc. Of course it would be a little illogical this way... The best way is to download the file and then let the target application (the desktop manager or file manager in this case) handle the rest, bear in mind there can be no path to the target ("there is no spoon"), for example for virtual file systems.

  11. #9
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dragging files from QListWidget to another app (file browser)

    Hi,
    I agree with you, but then we return to the first problem : you say I should download the file, the drag and drop will take maybe two seconds while the download can take hours... So let's say on a drag event I create a temporary file, and start to download the contents to it. When the users drop the file on the text editor or whatever it is, it will read what have been downloaded, which could be only a part of the final file.
    Also, I don't know any qt operation that has this feature... If you have any idea, I could look at the source and try to figure out the way it's done

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dragging files from QListWidget to another app (file browser)

    Quote Originally Posted by madcat
    Hi,
    I agree with you, but then we return to the first problem : you say I should download the file, the drag and drop will take maybe two seconds while the download can take hours... So let's say on a drag event I create a temporary file, and start to download the contents to it. When the users drop the file on the text editor or whatever it is, it will read what have been downloaded, which could be only a part of the final file.
    No, because the actual drop would have to take place only when the file is already downloaded.

    Also, I don't know any qt operation that has this feature... If you have any idea, I could look at the source and try to figure out the way it's done
    KDE, its desktop manager, file manager (konqueror) and applications like kate, ark, ones that use kio_slaves to provide virtual file systems.

  13. #11
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dragging files from QListWidget to another app (file browser)

    Quote Originally Posted by wysota
    No, because the actual drop would have to take place only when the file is already downloaded.
    But does that mean the user will have the icon sticked to his mouse until the file is downloaded ?

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dragging files from QListWidget to another app (file browser)

    No, it means that the drop would have to be processed by the application when the download is already finished and not sooner. We'd probably have to check the X11 DND specs to see how it's done (as Qt follows the specs and mimics it on other platforms).

Similar Threads

  1. Suggestions/Ideas about a file browser
    By SkripT in forum Qt Programming
    Replies: 31
    Last Post: 6th April 2011, 23:17
  2. Opening swf file in the default browser
    By munna in forum Qt Programming
    Replies: 16
    Last Post: 5th May 2006, 09:33
  3. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.