]> Git trees. - libqmvoc.git/commitdiff
Add a static pattern() method to KEduVocDocument to get a KFileDialog-suited filter...
authorPino Toscano <pino@kde.org>
Fri, 2 Mar 2007 19:00:34 +0000 (19:00 +0000)
committerPino Toscano <pino@kde.org>
Fri, 2 Mar 2007 19:00:34 +0000 (19:00 +0000)
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
kdeeducore/keduvocdocument.h

index 724cbbd5c043f2935316f27b6b12cd2b9290ad94..cafea0bcbc97f189f0c5b1bc7a06fbc807ae9b24 100644 (file)
@@ -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"
index 3cf29a872ad96a09ff0952c4d2034eb1e9464530..f2d804e965558fbbaca379e60d067a3c0971deca 100644 (file)
@@ -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);