Now saves using KwKWorshipFilter instead of KwDocument
[kworship.git] / kworship / KwKWorshipFilter.cpp
blob8f951198ed5156d479cf042d72dbb55150dcfb34
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 KwKWorshipFilter.cpp
22 * @brief Main KWorship archive load and save filter.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwKWorshipFilter.h"
27 #include "KwDocument.h"
28 #include "KwArchive.h"
29 #include "KwPlaylistList.h"
31 #include <KUrl>
32 #include <KMessageBox>
33 #include <KLocale>
34 #include <KSaveFile>
37 * Constructors + destructor
40 /// Primary constructor.
41 KwKWorshipFilter::KwKWorshipFilter()
42 : KwLoadSaveFilter()
44 m_importMimeTypes += "application/x-kworship-archive";
45 m_exportMimeTypes += "application/x-kworship-archive";
46 m_importMimeTypes += "application/x-kworship+xml";
47 m_exportMimeTypes += "application/x-kworship+xml";
50 /// Destructor.
51 KwKWorshipFilter::~KwKWorshipFilter()
56 * Main interface
59 KwDocument* KwKWorshipFilter::load(const KUrl& url, const QString& mimeType)
61 /// @todo Handle non-local files
62 if (!url.isLocalFile())
64 KMessageBox::error(0,
65 i18n("Non-local loads not yet supported"),
66 i18n("KWorship"));
67 return 0;
70 KwDocument* doc = new KwDocument(this, mimeType, url);
71 if (mimeType == "application/x-kworship-archive")
73 // Open archive object and read it
74 KwArchive archive(url.toLocalFile(), false);
75 Q_ASSERT(archive.isReading());
77 KwPlaylistList* playlist = archive.extractPlaylist("0");
78 if (0 != playlist)
80 doc->setPlaylist(playlist);
83 else if (mimeType == "application/x-kworship+xml")
85 /// @todo Implement non-archived load
86 Q_ASSERT(!"Non archived load not implemented");
88 else
90 Q_ASSERT(!"Unsupported mime type");
93 doc->setModified(false);
95 return doc;
98 bool KwKWorshipFilter::save(KwDocument* doc, const KUrl& url, const QString& mimeType)
100 /// @todo Handle non-local files
101 if (!url.isLocalFile())
103 KMessageBox::error(0,
104 i18n("Non-local loads not yet supported"),
105 i18n("KWorship"));
106 return false;
108 KSaveFile file;
109 file.setFileName(url.toLocalFile());
110 if (!file.open(QFile::WriteOnly))
112 KMessageBox::error(0,
113 i18n("Cannot write file %1:\n%2.")
114 .arg(file.fileName())
115 .arg(file.errorString()),
116 i18n("KWorship"));
117 return false;
120 if (mimeType == "application/x-kworship-archive")
122 // Open archive object and fill it
123 KwArchive archive(&file, true);
124 Q_ASSERT(archive.isWriting());
126 archive.addPlaylist(doc->playlist());
128 else if (mimeType == "application/x-kworship+xml")
130 /// @todo Implement non-archived save
131 Q_ASSERT(!"Non archived save not implemented");
133 else
135 Q_ASSERT(!"Unsupported mime type");
138 if (!file.finalize())
140 KMessageBox::error(0,
141 i18n("Cannot finalize file %1:\n%2.")
142 .arg(file.fileName())
143 .arg(file.errorString()),
144 i18n("KWorship"));
145 return false;
148 doc->setModified(false);
150 return true;
154 * Virtual interface
157 void KwKWorshipFilter::v_saveLimitations(KwDocument* doc, const QString& mimeType, Limitations* o_limitations)
159 /// @todo Implement KwKWorshipFilter::v_saveLimitations
160 Q_ASSERT(false);