More filter infrastructure
[kworship.git] / kworship / KwFilterManager.cpp
blob140c04f0f19bbda132660f21f3371f5848626a9a
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file KwFilterManager.cpp
22 * @brief Manages file filters.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwFilterManager.h"
27 #include "KwLoadSaveFilter.h"
30 * Constructors + destructor
33 /// Primary constructor.
34 KwFilterManager::KwFilterManager()
35 : m_defaultLoadSaveFilter(0)
36 , m_loadSaveFilters()
37 , m_importFilters()
38 , m_exportFilters()
42 /// Destructor.
43 KwFilterManager::~KwFilterManager()
45 // Delete all filters.
46 foreach (KwLoadSaveFilter* filter, m_loadSaveFilters)
48 delete filter;
50 foreach (KwImportFilter* filter, m_importFilters)
52 delete filter;
54 foreach (KwExportFilter* filter, m_exportFilters)
56 delete filter;
61 * Main interface
64 /// Add a load save filter.
65 void KwFilterManager::addLoadSaveFilter(KwLoadSaveFilter* loadSaveFilter, bool makeDefault)
67 m_loadSaveFilters += loadSaveFilter;
68 if (makeDefault)
70 m_defaultLoadSaveFilter = loadSaveFilter;
74 /// Add an import filter.
75 void KwFilterManager::addImportFilter(KwImportFilter* importFilter)
77 m_importFilters += importFilter;
80 /// Add an export filter.
81 void KwFilterManager::addExportFilter(KwExportFilter* exportFilter)
83 m_exportFilters += exportFilter;
86 /// Get load mime types.
87 QStringList KwFilterManager::loadMimeTypes() const
89 QStringList result;
90 foreach (KwLoadSaveFilter* filter, m_loadSaveFilters)
92 result += filter->importMimeTypes();
94 return result;
97 /// Get save mime types.
98 QStringList KwFilterManager::saveMimeTypes() const
100 QStringList result;
101 foreach (KwLoadSaveFilter* filter, m_loadSaveFilters)
103 result += filter->exportMimeTypes();
105 return result;
108 /// Get import mime types.
109 QStringList KwFilterManager::importMimeTypes() const
111 QStringList result;
112 foreach (KwImportFilter* filter, m_importFilters)
114 result += filter->importMimeTypes();
116 return result;
119 /// Get export mime types.
120 QStringList KwFilterManager::exportMimeTypes() const
122 QStringList result;
123 foreach (KwExportFilter* filter, m_exportFilters)
125 result += filter->exportMimeTypes();
127 return result;