Switch to side-by-side view

--- a/src/internfile/internfile.cpp
+++ b/src/internfile/internfile.cpp
@@ -1,5 +1,5 @@
 #ifndef lint
-static char rcsid[] = "@(#$Id: internfile.cpp,v 1.8 2005-11-14 09:59:17 dockes Exp $ (C) 2004 J.F.Dockes";
+static char rcsid[] = "@(#$Id: internfile.cpp,v 1.9 2005-11-18 15:19:14 dockes Exp $ (C) 2004 J.F.Dockes";
 #endif
 #include <unistd.h>
 #include <sys/types.h>
@@ -72,23 +72,24 @@
 
 void FileInterner::tmpcleanup()
 {
-    if (tdir.empty() || tfile.empty())
+    if (m_tdir.empty() || m_tfile.empty())
 	return;
-    if (unlink(tfile.c_str()) < 0) {
+    if (unlink(m_tfile.c_str()) < 0) {
 	LOGERR(("FileInterner::tmpcleanup: unlink(%s) errno %d\n", 
-		tfile.c_str(), errno));
+		m_tfile.c_str(), errno));
 	return;
     }
 }
 
-// Handler==0 on return says we're in error
+// Handler==0 on return says we're in error, will be handled when calling
+// internfile
 FileInterner::FileInterner(const std::string &f, RclConfig *cnf, 
 			   const string& td, const string *imime)
-    : fn(f), config(cnf), tdir(td), handler(0) 
+    : m_fn(f), m_cfg(cnf), m_tdir(td), m_handler(0)
 {
-    // Note that we are actually going to access the file, so that it's ok 
-    // to check this config variable at every call even if it can only change
-    // when we change directories 
+    // We are actually going to access the file, so it's ok
+    // performancewise to check this config variable at every call
+    // even if it can only change when we change directories
     string usfc;
     int usfci;
     if (!cnf->getConfParam("usesystemfilecommand", usfc)) 
@@ -97,17 +98,19 @@
 	usfci = atoi(usfc.c_str()) ? 1 : 0;
     LOGDEB1(("FileInterner::FileInterner: usfci now %d\n", usfci));
 
+    bool forPreview = imime ? true : false;
+
     // We need to run mime type identification in any case to check
     // for a compressed file.
-    mime = mimetype(fn, config->getMimeMap(), usfci);
+    m_mime = mimetype(m_fn, m_cfg->getMimeMap(), usfci);
 
     // If identification fails, try to use the input parameter. Note that this 
     // is normally not a compressed type (it's the mime type from the db)
-    if (mime.empty() && imime)
-	mime = *imime;
-    if (mime.empty()) {
+    if (m_mime.empty() && imime)
+	m_mime = *imime;
+    if (m_mime.empty()) {
 	// No mime type: not listed in our map, or present in stop list
-	LOGDEB(("FileInterner::FileInterner: (no mime) [%s]\n", fn.c_str()));
+	LOGDEB(("FileInterner::FileInterner: (no mime) [%s]\n", m_fn.c_str()));
 	return;
     }
 
@@ -115,42 +118,45 @@
     // uncompressed file, and rerun the mime type identification, then do the
     // rest with the temp file.
     list<string>ucmd;
-    if (getUncompressor(mime, config->getMimeConf(), ucmd)) {
-	if (!uncompressfile(config, fn, ucmd, tdir, tfile)) {
+    if (getUncompressor(m_mime, m_cfg->getMimeConf(), ucmd)) {
+	if (!uncompressfile(m_cfg, m_fn, ucmd, m_tdir, m_tfile)) {
 	    return;
 	}
-	LOGDEB(("internfile: after ucomp: tdir %s, tfile %s\n", 
-		tdir.c_str(), tfile.c_str()));
-	fn = tfile;
-	mime = mimetype(fn, config->getMimeMap(), usfci);
-	if (mime.empty() && imime)
-	    mime = *imime;
-	if (mime.empty()) {
+	LOGDEB(("internfile: after ucomp: m_tdir %s, tfile %s\n", 
+		m_tdir.c_str(), m_tfile.c_str()));
+	m_fn = m_tfile;
+	m_mime = mimetype(m_fn, m_cfg->getMimeMap(), usfci);
+	if (m_mime.empty() && imime)
+	    m_mime = *imime;
+	if (m_mime.empty()) {
 	    // No mime type ?? pass on.
-	    LOGDEB(("internfile: (no mime) [%s]\n", fn.c_str()));
+	    LOGDEB(("internfile: (no mime) [%s]\n", m_fn.c_str()));
 	    return;
 	}
     }
 
     // Look for appropriate handler
-    handler = getMimeHandler(mime, config->getMimeConf());
-    if (!handler) {
+    m_handler = getMimeHandler(m_mime, m_cfg->getMimeConf());
+    if (!m_handler) {
 	// No handler for this type, for now :(
-	LOGDEB(("FileInterner::FileInterner: %s: no handler\n", mime.c_str()));
+	LOGDEB(("FileInterner::FileInterner: %s: no handler\n", 
+		m_mime.c_str()));
 	return;
     }
-
-    LOGDEB(("FileInterner::FileInterner: %s [%s]\n",mime.c_str(), fn.c_str()));
+    m_handler->setForPreview(forPreview);
+    LOGDEB(("FileInterner::FileInterner: %s [%s]\n", m_mime.c_str(), 
+	    m_fn.c_str()));
 }
 
 FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, string& ipath)
 {
-    if (!handler)
+    if (!m_handler)
 	return FIError;
 
     // Turn file into a document. The document has fields for title, body 
     // etc.,  all text converted to utf8
-    MimeHandler::Status mhs = handler->mkDoc(config, fn,  mime, doc, ipath);
+    MimeHandler::Status mhs = 
+	m_handler->mkDoc(m_cfg, m_fn, m_mime, doc, ipath);
     FileInterner::Status ret = FIError;
     switch (mhs) {
     case MimeHandler::MHError: break;
@@ -158,13 +164,13 @@
     case MimeHandler::MHAgain: ret = FIAgain;break;
     }
 
-    doc.mimetype = mime;
+    doc.mimetype = m_mime;
     return ret;
 }
 
 FileInterner::~FileInterner()
 {
-    delete handler; 
-    handler = 0;
+    delete m_handler; 
+    m_handler = 0;
     tmpcleanup();
 }