Fix PDF content type, better publisher initialization
Stefan Bund [Mon, 15 Nov 2010 15:16:32 +0000 (16:16 +0100)]
PythonPublisher.cc
PythonPublisher.hh
Viewer.cc
main.cc

index 56d7bc4..d71cdee 100644 (file)
@@ -431,19 +431,16 @@ BOOST_PYTHON_MODULE(_pykit)
         ;
 }
 
-prefix_ pykit::PythonPublisher::PythonPublisher(std::string initPy)
+prefix_ pykit::PythonPublisher::PythonPublisher()
     : impl_ (new Impl)
 {
     try {
         PYTHON_PREPARE_IMPORT(_pykit);
         PYTHON_PREPARE_IMPORT(_qt);
         Py_Initialize();
-        py::object mainModule_ = py::import("__main__");
-        impl_->mainNamespace = py::extract<py::dict>(mainModule_.attr("__dict__"));
-        impl_->mainNamespace["__file__"] = py::str(initPy.c_str());
-        py::object ignored (
-            py::exec_file(initPy.c_str(), impl_->mainNamespace, impl_->mainNamespace));
-        impl_->pythonPublisher = py::extract<Publisher*>(impl_->mainNamespace["publisher"]);
+        py::object initModule = py::import("init");
+        impl_->mainNamespace = py::extract<py::dict>(initModule.attr("__dict__"));
+        impl_->pythonPublisher = py::extract<Publisher*>(impl_->mainNamespace["initialize"]());
     }
     catch (boost::python::error_already_set & ex) {
         PyErr_Print();
index b6b6a5e..1065a38 100644 (file)
@@ -22,7 +22,7 @@ namespace pykit {
         : public Publisher
     {
     public:
-        explicit PythonPublisher(std::string initPy);
+        explicit PythonPublisher();
         ~PythonPublisher();
 
         void publish(Request & request);
index e16ffec..c9101ee 100644 (file)
--- a/Viewer.cc
+++ b/Viewer.cc
@@ -52,7 +52,7 @@ prefix_ QObject * PDFWebPluginFactory::create(QString const & mimeType, QUrl con
                                               QStringList const & /* argumentValues */)
     const
 {
-    if (mimeType == "application/x-pdf") {
+    if (mimeType == "application/pdf") {
         pykit::PDFWidget * plugin = new pykit::PDFWidget(manager_);
         plugin->load(url);
         return plugin;
@@ -71,7 +71,7 @@ prefix_ QList<QWebPluginFactory::Plugin> PDFWebPluginFactory::plugins()
         plugin.description = "View PDF files";
         {
             QWebPluginFactory::MimeType mimeType;
-            mimeType.name = "application/x-pdf";
+            mimeType.name = "application/pdf";
             mimeType.description = "PDF file";
             plugin.mimeTypes += mimeType;
         }
diff --git a/main.cc b/main.cc
index 023e143..d83af4a 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
 
         settings.beginGroup("Viewer");
 
-        pykit::PythonPublisher publisher (settings.value("init").toString().toStdString());
+        pykit::PythonPublisher publisher;
 
         QString url (settings.value("home").toString());
         if (arguments.size()>1)