[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Opening "unsupported" file types
From:       Clarence Dang <dang () kde ! org>
Date:       2003-05-11 12:12:39
[Download RAW message or body]

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

["fallback2ascii.patch" (text/x-diff)]

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() ) {


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic