summaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qabstractfileengine.cpp
blob: de0fd50ed03045eaefbd0e606cc24d7d094c8a92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! [0]
class ZipEngineHandler(QAbstractFileEngineHandler):
    def create(self, fileName):
        # ZipEngineHandler returns a ZipEngine for all .zip files
        if fileName.toLower().endsWith(".zip"):
            return ZipEngine(fileName)
        else
            return None

def main():
    app = QApplication(sys.argv)

    engine = ZipEngineHandler()

    window = MainWindow()
    window.show()

    return app.exec()
//! [0]


//! [1]
def create(fileName):
    # ZipEngineHandler returns a ZipEngine for all .zip files
    if fileName.lower().endswith(".zip"):
        return ZipEngine(fileName)
    else
        return None
//! [1]


//! [2]
# @arg filters QDir.Filters
# @arg filterNames QStringList
# @return QAbstractFileEngineIterator
def beginEntryList(filters, filterNames):
    return CustomFileEngineIterator(filters, filterNames)
//! [2]


//! [3]
class CustomIterator(QAbstractFileEngineIterator):
    def __init__(self, nameFilters, filters):
        QAbstractFileEngineIterator.__init__(self, nameFilters, filters)

        self.index = 0
        # In a real iterator, these entries are fetched from the
        # file system based on the value of path().
        self.entries << "entry1" << "entry2" << "entry3"

    def hasNext(self):
        return self.index < self.entries.size() - 1

    def next(self):
       if not self.hasNext():
           return None
       index += 1
       return currentFilePath()

    def currentFileName(self):
       return self.entries.at(index)
//! [3]