From koffice-devel Sun May 11 12:12:39 2003 From: Clarence Dang Date: Sun, 11 May 2003 12:12:39 +0000 To: koffice-devel Subject: Opening "unsupported" file types X-MARC-Message: https://marc.info/?l=koffice-devel&m=105265536803060 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary_(ID_uFGnqC7z+S8C2HQy7zdz2Q)" --Boundary_(ID_uFGnqC7z+S8C2HQy7zdz2Q) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Hi, The attached patch makes KoFilterManager to fall back to the ascii filter if it "can't handle" the source mimetype. This is so that it can open text files other than text/plain such as .cpp files and files that have been misidentified by magic as something other than text/ascii. It is a real hack and probably only makes sense for KWord. But as the filter system would normally abort in this situation, we have nothing to lose by trying text/plain. Please review. Cheers, Clarence --Boundary_(ID_uFGnqC7z+S8C2HQy7zdz2Q) Content-type: text/x-diff; charset=us-ascii; name=fallback2ascii.patch Content-transfer-encoding: 7BIT Content-disposition: attachment; filename=fallback2ascii.patch Index: koFilterManager.cc =================================================================== RCS file: /home/kde/koffice/lib/kofficecore/koFilterManager.cc,v retrieving revision 1.125 diff -u -p -r1.125 koFilterManager.cc --- koFilterManager.cc 2 Apr 2003 17:13:28 -0000 1.125 +++ koFilterManager.cc 11 May 2003 11:43:39 -0000 @@ -76,11 +76,17 @@ QString KoFilterManager::import( const Q m_graph.setSourceMimeType( t->name().latin1() ); // .latin1() is okay here (Werner) if ( !m_graph.isValid() ) { - kdError(s_area) << "Couldn't create a valid graph for this source mimetype: " - << t->name() << endl; - importErrorHelper( t->name() ); - status = KoFilter::BadConversionGraph; - return QString::null; + // FIXME: real solution is to have a dialog that lets the user choose the source mime + kdWarning(s_area) << "No import filter exists for the source mimetype \'" + << t->name() << "\' ... falling back to \'text/plain\'" << endl; + m_graph.setSourceMimeType( "text/plain" ); + if (!m_graph.isValid() ) + { + kdError(s_area) << "Couldn't create a valid graph for fallback \'text/plain\'!" << endl; + importErrorHelper( t->name() ); + status = KoFilter::BadConversionGraph; + return QString::null; + } } KoFilterChain::Ptr chain( 0 ); @@ -138,6 +144,13 @@ KoFilter::ConversionStatus KoFilterManag return KoFilter::BadMimeType; } m_graph.setSourceMimeType( t->name().latin1() ); + + if ( !m_graph.isValid() ) { + // FIXME: real solution is to have a dialog that lets the user choose the source mime + kdWarning(s_area) << "No import filter exists for the source mimetype \'" + << t->name() << "\' ... falling back to \'text/plain\'" << endl; + m_graph.setSourceMimeType( "text/plain" ); + } } if ( !m_graph.isValid() ) { --Boundary_(ID_uFGnqC7z+S8C2HQy7zdz2Q) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ koffice-devel mailing list koffice-devel@mail.kde.org http://mail.kde.org/mailman/listinfo/koffice-devel --Boundary_(ID_uFGnqC7z+S8C2HQy7zdz2Q)--