From 36eb3ce0bc3463dd993d86d8efe741ad4d37be06 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 2 Mar 2007 19:00:34 +0000 Subject: [PATCH] Add a static pattern() method to KEduVocDocument to get a KFileDialog-suited filter string with all the documents supported when reading/writing. This way, applications that use KEduVocDocument won't need to hardcode anymore the patterns themselves. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=638631 --- kdeeducore/keduvocdocument.cpp | 32 ++++++++++++++++++++++++++++++++ kdeeducore/keduvocdocument.h | 15 +++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/kdeeducore/keduvocdocument.cpp b/kdeeducore/keduvocdocument.cpp index 724cbbd..cafea0b 100644 --- a/kdeeducore/keduvocdocument.cpp +++ b/kdeeducore/keduvocdocument.cpp @@ -1148,4 +1148,36 @@ void KEduVocDocument::shuffle() setModified(); } + +QString KEduVocDocument::pattern(Mode mode) +{ + static const struct SupportedFilter + { + bool reading; + bool writing; + const char* extensions; + const char* description; + } filters[] = { + { true, true, "*.kvtml", I18N_NOOP("KDE Vocabulary Document") }, + { true, false, "*.wql", I18N_NOOP("KWordQuiz Document") }, + { true, false, "*.xml.qz *.pau.gz", I18N_NOOP("Pauker Lesson") }, + { true, false, "*.voc", I18N_NOOP("Vokabeltrainer") }, + { true, true, "*.csv", I18N_NOOP("Text") }, + // last is marker for the end, do not remove it + { false, false, 0, 0 } + }; + QStringList newfilters; + QStringList allext; + for (int i = 0; filters[i].extensions; ++i) { + if ((mode == Reading && filters[i].reading) || + (mode == Writing && filters[i].writing)) { + newfilters.append(QLatin1String(filters[i].extensions) + '|' + i18n(filters[i].description)); + allext.append(QLatin1String(filters[i].extensions)); + } + } + newfilters.prepend(allext.join(" ") + '|' + i18n("All supported documents")); + return newfilters.join("\n"); +} + + #include "keduvocdocument.moc" diff --git a/kdeeducore/keduvocdocument.h b/kdeeducore/keduvocdocument.h index 3cf29a8..f2d804e 100644 --- a/kdeeducore/keduvocdocument.h +++ b/kdeeducore/keduvocdocument.h @@ -751,6 +751,21 @@ public: FileType detectFileType(const QString &fileName); + enum Mode { + Reading, + Writing + }; + + /** + * Create a string with the supported document types, that can be used + * as filter in KFileDialog. It includes also an entry to match all the + * supported types. + * + * @param mode the mode for the supported document types + * @returns the filter string + */ + static QString pattern(Mode mode); + Q_SIGNALS: void progressChanged (KEduVocDocument *, int curr_percent); void docModified (bool mod); -- 2.47.3