Results 1 to 7 of 7

Thread: File Dialog / Network Protocols in QT4

  1. #1
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default File Dialog / Network Protocols in QT4

    In QT3 there was a very nice way to create new protocols and register them. This was very useful, for example, to change the way that a FileDialog displays its dir listings.

    I had created a new protocol, called "sequence" that allowed me to pass different current directories to a file dialog:

    file://path/to/file.0001.jpg
    vs.
    sequence://path/to/file.#.jpg

    I have directories with thousands of video frames in them, all numbered:

    file.0001.jpg
    file.0002.jpg
    ...
    file.9998.jpg
    file.9999.jpg
    image.0001.png
    ...
    image.1234.png

    there may be multiple frame sequences in a dir, so I had an algorithm to collapse the sequences into a shorter notation:

    file.[1-9999]#.jpg
    image.[1-1234]#.jpg

    this is much easier to read and cleaner when doing video work.

    The beauty of it was that all I had to do was pass a different protocol:// to the dialog to switch between the notations!

    Now, in QT4, the network protocol has been deprecated to Q3NetworkProtocol, and I don't want to use it if it's going to be removed in the future. This is a real bummer, because now I may be forced to build a new QFileDialog object just to list files in this way.

    An additional thing that the protocol would have accomodated would have been a machine name at the beginning of the path... I have a file server (which I wrote) running on certain machines, and clients can request dir listings from each server (via a main dispatching caching server).

    Bottom line is, I wanted to be able to pass a starting protocol/path to a file dialog and be able to navigate around the directory tree, but the source of this information is not local, is not http or ftp, and NetworkProtocol does not seem to have a QT4 equivalent.

    Is there a class with a similar "operationListChildren" that I can subclass to make this work?

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

    Default Re: File Dialog / Network Protocols in QT4

    Quote Originally Posted by themolecule View Post
    Now, in QT4, the network protocol has been deprecated to Q3NetworkProtocol, and I don't want to use it if it's going to be removed in the future. This is a real bummer, because now I may be forced to build a new QFileDialog object just to list files in this way.

    An additional thing that the protocol would have accomodated would have been a machine name at the beginning of the path... I have a file server (which I wrote) running on certain machines, and clients can request dir listings from each server (via a main dispatching caching server).

    Bottom line is, I wanted to be able to pass a starting protocol/path to a file dialog and be able to navigate around the directory tree, but the source of this information is not local, is not http or ftp, and NetworkProtocol does not seem to have a QT4 equivalent.

    Is there a class with a similar "operationListChildren" that I can subclass to make this work?
    Take a look at QAbstractFileEngine.

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

    themolecule (9th September 2007)

  4. #3
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: File Dialog / Network Protocols in QT4

    Thanks, this is exactly what I was looking for...!

    After reading and re-reading the documentation and examples, I am confused about a couple points:

    It seems that I can just subclass QFSFileEngine... let's call it "RemoteFileEngine". So I can infer that I will need at least three classes:

    RemoteFileEngine
    RemoteFileEngineHandler
    RemoteFileEngineIterator

    where the iterator is the entry point to the virtual file system listings. (ie, iterator returns the beginning of a dirlisting for beginEntryList, which QFileDialog uses to populate itself). The Handler creates engine items and the Engine does all the other work.

    But after attempting to subclass I find that QFSFileEngine has methods scattered all over that reference the local file system, and it's kind of difficult to separate, or rather, override all the functions that talk to the local file system (the whole listing should be virtual, served by the server).

    I am forced to conclude that I have to subclass QAbstractFileEngine instead, but there appears to be about 20 virtual functions, and certain private variables that I'll need to create. The source is kind of obfuscated for QFSFileEngine, so it's difficult to use this as a starting place. Is there an example somewhere, or a list of the minimum methods needed to successfully subclass?

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

    Default Re: File Dialog / Network Protocols in QT4

    If your files are real files, you can subclass QFSFileEngine and reimplement those methods defined in QAbstractFileEngine that you need changed. In doubt see the sources of the mentioned classes - maybe you only need to alter one or two methods.

  6. #5
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: File Dialog / Network Protocols in QT4

    Unfortunately, it seems like QFSFileEngine is especially split between OS implementations, and is very connected to the local file system. I don't think subclassing is possible, or rather, it's pointless because so many methods would need to be overridden.

    The files I want to list are not local to the file system, and therefore the FileDialog should never need to access the local file system (except to load icons).

    I have started to write a QAbstractFileEngine subclass, but things don't seem to work right.

    The example in the documentation on QAbstractFileEngineIterator has bugs in it. It puts the iterator on the first item, which means that the first item is never retrieved. I changed the index(0) to index(-1) which helps (after fixing currentFileName to check for -1). Also, filterNames and filters seems reversed in the documentation (which is easy to fix, but still seems like a typo).

    But when the dialog is created it seems to search for history items, which seem to default to the currentDirectory (of the application). Then I set history to an empty list, and the sidebar urls to an empty list, but entries never show up in the dialog.

    After searching, I find in the code that QDirIterator is a friend to QAbstractFileEngine, which is frustrating because this disallows me to set the path() of the iterator, and instead it inherits the dir from when the FileDialog was created. Perhaps my iterator has to subclass QDirIterator? But what do I do with QDirIteratorPrivate?

    Is it really bad to use Q3NetworkProtocol, I mean, are they really gonna get rid of it?

  7. #6
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: File Dialog / Network Protocols in QT4

    this is interesting...

    http://lists.trolltech.com/qt-intere.../msg00693.html

    I think it's a wash... I should build my own FileDialog.

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

    Default Re: File Dialog / Network Protocols in QT4

    Quote Originally Posted by themolecule View Post
    Unfortunately, it seems like QFSFileEngine is especially split between OS implementations, and is very connected to the local file system. I don't think subclassing is possible, or rather, it's pointless because so many methods would need to be overridden.
    In my opinion there shouldn't be much work with it. In general you'd need to translate file paths and call default implementations.

Similar Threads

  1. File Open dialog with preview?
    By will49 in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2007, 19:08
  2. Replies: 4
    Last Post: 13th June 2007, 16:37
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  4. preview file dialog
    By mickey in forum Qt Programming
    Replies: 11
    Last Post: 22nd April 2006, 00:03
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 15:52

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.