Database: sqlite default to appdata kworship.db
[kworship.git] / kworship / KwFilterManager.cpp
blob8b94029af2eaff2855ad63f9483394b9a267c6a8
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()
39 , m_loadMimeFilters()
40 , m_saveMimeFilters()
41 , m_importMimeFilters()
42 , m_exportMimeFilters()
43 , m_defaultSaveMimeType()
47 /// Destructor.
48 KwFilterManager::~KwFilterManager()
50 // Delete all filters.
51 foreach (KwLoadSaveFilter* filter, m_loadSaveFilters)
53 delete filter;
55 foreach (KwImportFilter* filter, m_importFilters)
57 delete filter;
59 foreach (KwExportFilter* filter, m_exportFilters)
61 delete filter;
66 * Main interface
69 /// Add a load save filter.
70 void KwFilterManager::addLoadSaveFilter(KwLoadSaveFilter* loadSaveFilter, bool makeDefault)
72 m_loadSaveFilters += loadSaveFilter;
74 // Update hashes of filters for each mime type
75 QStringList mimes = loadSaveFilter->importMimeTypes();
76 foreach (QString mime, mimes)
78 m_loadMimeFilters[mime] = loadSaveFilter;
80 mimes = loadSaveFilter->exportMimeTypes();
81 foreach (QString mime, mimes)
83 m_saveMimeFilters[mime] = loadSaveFilter;
86 if (makeDefault)
88 m_defaultLoadSaveFilter = loadSaveFilter;
89 Q_ASSERT(mimes.size() >= 1);
90 m_defaultSaveMimeType = mimes[0];
94 /// Add an import filter.
95 void KwFilterManager::addImportFilter(KwImportFilter* importFilter)
97 m_importFilters += importFilter;
99 // Update hash of import filters for each mime type
100 QStringList mimes = importFilter->importMimeTypes();
101 foreach (QString mime, mimes)
103 m_importMimeFilters[mime] = importFilter;
107 /// Add an export filter.
108 void KwFilterManager::addExportFilter(KwExportFilter* exportFilter)
110 m_exportFilters += exportFilter;
112 // Update hash of export filters for each mime type
113 QStringList mimes = exportFilter->exportMimeTypes();
114 foreach (QString mime, mimes)
116 m_exportMimeFilters[mime] = exportFilter;
120 /// Get load mime types.
121 QStringList KwFilterManager::loadMimeTypes() const
123 return m_loadMimeFilters.keys();
126 /// Get save mime types.
127 QStringList KwFilterManager::saveMimeTypes() const
129 return m_saveMimeFilters.keys();
132 /// Get import mime types.
133 QStringList KwFilterManager::importMimeTypes() const
135 return m_importMimeFilters.keys();
138 /// Get export mime types.
139 QStringList KwFilterManager::exportMimeTypes() const
141 return m_exportMimeFilters.keys();
144 /// Get the default save mime type.
145 const QString& KwFilterManager::defaultSaveMimeType() const
147 return m_defaultSaveMimeType;
150 /// Get the load filter for a mime type.
151 KwLoadSaveFilter* KwFilterManager::loadFilterFromMimeType(const QString& mimeType)
153 if (m_loadMimeFilters.contains(mimeType))
155 return m_loadMimeFilters[mimeType];
157 else
159 return 0;
163 /// Get the save filter for a mime type.
164 KwLoadSaveFilter* KwFilterManager::saveFilterFromMimeType(const QString& mimeType)
166 if (m_saveMimeFilters.contains(mimeType))
168 return m_saveMimeFilters[mimeType];
170 else
172 return 0;
176 /// Get the import filter for a mime type.
177 KwImportFilter* KwFilterManager::importFilterFromMimeType(const QString& mimeType)
179 if (m_importMimeFilters.contains(mimeType))
181 return m_importMimeFilters[mimeType];
183 else
185 return 0;
189 /// Get the export filter for a mime type.
190 KwExportFilter* KwFilterManager::exportFilterFromMimeType(const QString& mimeType)
192 if (m_exportMimeFilters.contains(mimeType))
194 return m_exportMimeFilters[mimeType];
196 else
198 return 0;