1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
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"
32 #include <KMessageBox>
37 * Constructors + destructor
40 /// Primary constructor.
41 KwKWorshipFilter::KwKWorshipFilter()
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";
51 KwKWorshipFilter::~KwKWorshipFilter()
59 KwDocument
* KwKWorshipFilter::load(const KUrl
& url
, const QString
& mimeType
)
61 /// @todo Handle non-local files
62 if (!url
.isLocalFile())
65 i18n("Non-local loads not yet supported"),
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");
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");
90 Q_ASSERT(!"Unsupported mime type");
93 doc
->setModified(false);
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"),
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()),
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");
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()),
148 doc
->setModified(false);
157 void KwKWorshipFilter::v_saveLimitations(KwDocument
* doc
, const QString
& mimeType
, Limitations
* o_limitations
)
159 /// @todo Implement KwKWorshipFilter::v_saveLimitations