Add mac specific configuration
[pykit.git] / Viewer.cc
1 // $Id$
2 //
3 // Copyright (C) 2010
4 //     Stefan Bund <info@j32.de>
5
6 /** \file
7     \brief Viewer non-inline non-template implementation */
8
9 #include "Viewer.hh"
10 //#include "Viewer.ih"
11
12 // Custom includes
13 #include <iostream>
14 #include <QWebPluginFactory>
15 #include "Publisher.hh"
16 #ifdef POPPLER
17 #include "PDFWidget.hh"
18 #endif
19
20 //#include "Viewer.mpp"
21 #define prefix_
22 ///////////////////////////////cc.p////////////////////////////////////////
23
24 #ifdef POPPLER
25
26 namespace {
27
28     class PDFWebPluginFactory
29         : public QWebPluginFactory
30     {
31     public:
32         PDFWebPluginFactory(QNetworkAccessManager * manager, QObject * parent = 0);
33
34         QObject * create(QString const & mimeType, QUrl const & url,
35                          QStringList const & argumentNames, QStringList const & argumentValues)
36             const;
37         QList<QWebPluginFactory::Plugin> plugins() const;
38
39     private:
40         QNetworkAccessManager * manager_;
41     };
42
43 }
44
45 prefix_ PDFWebPluginFactory::PDFWebPluginFactory(QNetworkAccessManager * manager,
46                                                  QObject * parent)
47     : QWebPluginFactory(parent), manager_ (manager)
48 {}
49
50 prefix_ QObject * PDFWebPluginFactory::create(QString const & mimeType, QUrl const & url,
51                                               QStringList const & /* argumentNames */,
52                                               QStringList const & /* argumentValues */)
53     const
54 {
55     if (mimeType == "application/x-pdf") {
56         pykit::PDFWidget * plugin = new pykit::PDFWidget(manager_);
57         plugin->load(url);
58         return plugin;
59     }
60     return 0;
61 }
62
63 prefix_ QList<QWebPluginFactory::Plugin> PDFWebPluginFactory::plugins()
64     const
65 {
66     QList<QWebPluginFactory::Plugin> plugins;
67
68     {
69         QWebPluginFactory::Plugin plugin;
70         plugin.name = "PDF viewer";
71         plugin.description = "View PDF files";
72         {
73             QWebPluginFactory::MimeType mimeType;
74             mimeType.name = "application/x-pdf";
75             mimeType.description = "PDF file";
76             plugin.mimeTypes += mimeType;
77         }
78         plugins += plugin;
79     }
80
81     return plugins;
82 }
83
84 #endif
85
86 ///////////////////////////////////////////////////////////////////////////
87 // pykit::Viewer
88
89 prefix_ pykit::Viewer::Viewer(QUrl const & url, Publisher * publisher, QWidget * parent)
90     : QWebView (parent)
91 {
92     QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
93     page()->setNetworkAccessManager(
94         new InternalNetworkAccessManager(page()->networkAccessManager(), this, publisher));
95 #ifdef POPPLER
96     page()->setPluginFactory(new PDFWebPluginFactory (page()->networkAccessManager(), this));
97 #endif
98     load(url);
99 }
100
101 ///////////////////////////////cc.e////////////////////////////////////////
102 #undef prefix_
103 //#include "Viewer.mpp"
104
105 \f
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
109 // comment-column: 40
110 // c-file-style: "j32"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -U"
114 // End: