Results 1 to 14 of 14

Thread: Draging a non-existing file to the Windows Desktop

  1. #1
    Join Date
    Jan 2006
    Location
    Stuttgart
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Draging a non-existing file to the Windows Desktop

    Hi,
    I have a somewhat sophisticated problem. I want to drag a file out of my application to the windows desktop. This is normally done by setting the drag type to “text/uri-ist” and passing the filename. Fine.

    My problem is that in the moment where I start the drag the file does not exist. I want it to create it *after* releasing the mouse button. Why? Because my application is somewhat like a ftp-client. So my application has to download the file, which - depending on the file size - can take a moment. So I can not prepare the file before the user drag it of.

    In the first moment this is something witch seems impossible, but there are a number of applications like smartFTP, or WinZIP (they have the same problem - unzipping of a file takes to long to prepare it…) witch solves the problem.

    Can someone give me a hint how to start a possible solution?

    As the solution are very much related to the Windows Operating System - Perhaps you could also point me to a good Windows related c++ Forum ?

    Many thanks in advance,
    Klaus

  2. #2
    Join Date
    Apr 2006
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    During the drag operation, you have to signal to windows to create a temp file. Once the temp file is created (after the user releases the mouse button). Copy the temp file to the location they dropped the file to.
    #
    # Make install
    # ! mutants
    #

  3. #3
    Join Date
    Jan 2006
    Location
    Stuttgart
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    hi,
    thanks for your answer. My problem with it is, that I don't know how to find out the location where the file is dropped to. Could you give me a hint how you think I can do that?
    Thanks,
    Klaus

  4. #4
    Join Date
    Apr 2006
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    Sure... Luckily windows reconizes certain drag & drop events. So just make sure that you make the drag event trigger a copy || move file command and windows should handle the rest. So you can disregard my last post.

    Let me know how it goes. I do MFC programming at work (amongst other TKs).
    #
    # Make install
    # ! mutants
    #

  5. #5
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    You don't need to create a temporary file and you should be able to implement the solution in a platform transparent way.

    You need to subclass QMimeSource and override QMimeData::retrieveData ( const QString & mimetype, QVariant::Type type ).

    Use this object when you set the data for your QDrag object.

    The method retrieveData() should automatically be called only when the drop is complete. Your override of this method is where you should implement your FTP ('get' it into a QByteArray) and provide the data (return a QVariant created from the QByteArray). The OS should take care of creating the file.

    Qt drag and drop has changed quite a lot since Qt3, but in Qt3, what you are proposing is quite easy. I apologize if this turns out to be incorrect, but the instructions above should, (in theory) do what you require.
    Last edited by Chicken Blood Machine; 4th April 2006 at 20:20.
    Save yourself some pain. Learn C++ before learning Qt.

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

    Default Re: Draging a non-existing file to the Windows Desktop

    The problem is Windows doesn't allow a drop when using uri-list as contents (it shown the "no-drop" stop sign). What contents to put there then for Windows desktop or explorer to allow it?

  7. #7
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    Quote Originally Posted by wysota
    The problem is Windows doesn't allow a drop when using uri-list as contents (it shown the "no-drop" stop sign). What contents to put there then for Windows desktop or explorer to allow it?
    Just checking with Drag Queen...you're right. So it does need a platform-specific solution. Take a look at QWindowsMime. I think you may need to provide CF_HDROP as the format.
    Save yourself some pain. Learn C++ before learning Qt.

  8. #8
    Join Date
    Apr 2006
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    Quote Originally Posted by Chicken Blood Machine
    You don't need to create a temporary file and you should be able to implement the solution in a platform transparent way.
    Quote Originally Posted by Protocol
    So you can disregard my last post.
    FYI: The above means to disregard the statement about the temp file.
    #
    # Make install
    # ! mutants
    #

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

    Default Re: Draging a non-existing file to the Windows Desktop

    Quote Originally Posted by Chicken Blood Machine
    Take a look at QWindowsMime. I think you may need to provide CF_HDROP as the format.
    Looks promising, but how does one use it?

    EDIT:
    In our situation it would probably be better to use CF_INETURL as the data dragged is an http url. Anyway we use text/uri-list (as QWindowsMime suggests) but Windows doesn't accept it. Should the conversion be done manually? And if so, then when? On the other hand if the conversion is done automatically by Qt D&D mechanism (and it probably is), why doesn't Explorer accept it? Maybe it just doesn't like remote files? But if so, then we go back to the fact that we can't use a local resource because it doesn't exist yet.

    BTW. I think Klaus should continue that discussion and not me It works fine under KDE
    Last edited by wysota; 5th April 2006 at 16:22.

  10. #10
    Join Date
    Jan 2006
    Location
    Stuttgart
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    hey - thanks for everyone. In fact this is a difficult subject.

    When I use drop Site (one of the troll examples) to check the mime-type, I see that a normal drag from the explorer is a text/uri-list, which will only work if the file is allready existing, that means, that the pointer in text/uri-list start with file:////....

    Nevertheless, when I use SmartFTP, (which has the feature I need), I see that it also draging a text/uri-list, pointing to a temporary file (file:////c:...../temp/SFTPDROP) which does not exist. The mechanism also works if I create this SFTPDROP file in the temp folder.

    @protocoll: You said, that you see a possibilty to catch the drop event. Is this a Qt-event or are you talking about an Windows event? Would you be so friendly to give me a little bit more information about how to catch this event?

    @chicken blood machine: as far as I understand CF_HDROP has a double \0\0 terminated list of strings with the names of the files. I'm not sure if this helps me, as also this file names has to point somewhere - but perhaps I make a mistake.
    In windows there is also the format CFSTR_FILECONTENTS where I could pass a stream to another application, but I'm not shure what happens if I would like to drag more than one file.

    Thanks a lot for your time,
    Klaus

  11. #11
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    If anybody's still interested, I think I've found a solution to this problem. For me explorer accepts a uri list, as long as it isn't empty. The problem was finding out when the drag operation has ended. retrieveData() is not only called after the drop.

    Qt Code:
    1. #include <QtGui>
    2. #include <windows.h>
    3.  
    4. class WinMimeData : public QMimeData
    5. {
    6. public:
    7. WinMimeData()
    8. : runOnce(true)
    9. {
    10. setUrls(QList<QUrl>()<<QUrl("tmp"));
    11. }
    12.  
    13. QVariant retrieveData(const QString& mimeType, QVariant::Type type)const
    14. {
    15. // This is surely a hack, but how else do we find out that the drag operation has completed?
    16. if(((unsigned short)GetAsyncKeyState(VK_LBUTTON))>1)
    17. return QMimeData::retrieveData(mimeType, type);
    18.  
    19. if(runOnce)
    20. {
    21. // Now we create the file:
    22. if(file.open())
    23. {
    24. file.write("Hello!");
    25. file.flush();
    26. }
    27. runOnce=false;
    28. }
    29. return QUrl("/"+file.fileName());
    30. }
    31. private:
    32. // these need to be mutable since retrieveData() is const
    33. mutable QTemporaryFile file;
    34. mutable bool runOnce;
    35. };
    36.  
    37. class Widget : public QWidget
    38. {
    39. void mousePressEvent(QMouseEvent* event)
    40. {
    41. QDrag *drag = new QDrag(this);
    42. drag->setMimeData(new WinMimeData);
    43. drag->start(Qt::CopyAction);
    44. }
    45. };
    46.  
    47. int main(int argc, char *argv[])
    48. {
    49. QApplication app(argc, argv);
    50. Widget window;
    51. window.show();
    52. return app.exec();
    53. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Draging a non-existing file to the Windows Desktop

    As far as I remember for me explorer was forbidding dropping an uri-list (containing http data) on the desktop. But it would be nice if the solution you propose worked. I think your solution won't work for files which have to be for example downloaded after the drop (or extracted from some archive). So really this isn't much different to providing an URI to an already existing file - you won't be able to implement unzipping this way, right?

  13. #13
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Draging a non-existing file to the Windows Desktop

    Quote Originally Posted by wysota View Post
    As far as I remember for me explorer was forbidding dropping an uri-list (containing http data) on the desktop. But it would be nice if the solution you propose worked. I think your solution won't work for files which have to be for example downloaded after the drop (or extracted from some archive). So really this isn't much different to providing an URI to an already existing file - you won't be able to implement unzipping this way, right?
    I don't think so. In my example the file is actually only created after the drag action has finished. Go ahead and try it if you want. I got the idea by trying to pull a file from winrar to the "drop site" example. During the drag, the drop site reports only an empty list. After you let go of the mouse button winrar starts creating a temporary file and when it's finished drop site reports the newly created temporary file.
    Of course it is kind of a hack, and I can't guarantee it will always work. Eventually Qt will have to provide this functionality, but for now I think it could work. It would be nice if somebody tried it out.

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

    Default Re: Draging a non-existing file to the Windows Desktop

    Quote Originally Posted by spud View Post
    I don't think so. In my example the file is actually only created after the drag action has finished. Go ahead and try it if you want. I got the idea by trying to pull a file from winrar to the "drop site" example. During the drag, the drop site reports only an empty list. After you let go of the mouse button winrar starts creating a temporary file and when it's finished drop site reports the newly created temporary file.
    The point is how the file is created. Could you try to check it out with a drop that starts a http download and downloads the file which is then transfered to explorer (I can't do it myself now)?

Similar Threads

  1. Windows file copy in progress, how can I tell?
    By tgreaves in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2009, 18:42
  2. qmake can't process project file on windows
    By s-troz in forum Qt Programming
    Replies: 3
    Last Post: 25th October 2008, 15:51
  3. Opening text file fails after autostartup on windows
    By yogourta in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2008, 04:52
  4. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 20:41
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21

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.