add preview support (remote conversion to pdf)
This commit is contained in:
parent
54542c1f68
commit
937a088656
|
@ -81,7 +81,6 @@
|
|||
</prop>
|
||||
</node>
|
||||
|
||||
|
||||
<node oor:name="m8" oor:op="replace">
|
||||
<prop oor:name="URL" oor:type="xs:string">
|
||||
<value>service:org.entrouvert.openoffice.StructureCheckDialog</value>
|
||||
|
@ -100,6 +99,26 @@
|
|||
<value>com.sun.star.text.TextDocument</value>
|
||||
</prop>
|
||||
</node>
|
||||
|
||||
<node oor:name="m9" oor:op="replace">
|
||||
<prop oor:name="URL" oor:type="xs:string">
|
||||
<value>service:org.entrouvert.openoffice.Preview</value>
|
||||
</prop>
|
||||
<prop oor:name="ImageIdentifier" oor:type="xs:string">
|
||||
<value/>
|
||||
</prop>
|
||||
<prop oor:name="Title" oor:type="xs:string">
|
||||
<value>Preview</value>
|
||||
<value xml:lang="fr-FR">Prévisualisation</value>
|
||||
</prop>
|
||||
<prop oor:name="Target" oor:type="xs:string">
|
||||
<value>_self</value>
|
||||
</prop>
|
||||
<prop oor:name="Context" oor:type="xs:string">
|
||||
<value>com.sun.star.text.TextDocument</value>
|
||||
</prop>
|
||||
</node>
|
||||
|
||||
</node>
|
||||
|
||||
<node oor:name="Tabellio.Listes" oor:op="replace">
|
||||
|
|
|
@ -959,6 +959,43 @@ class ConfigurationDialog(unohelper.Base, XJobExecutor):
|
|||
print 'exception:', e, str(e)
|
||||
|
||||
|
||||
class Preview(unohelper.Base, XJobExecutor):
|
||||
def __init__(self, ctx):
|
||||
self.ctx = ctx
|
||||
|
||||
def trigger(self, args):
|
||||
ctx = self.ctx
|
||||
try:
|
||||
smgr = self.ctx.ServiceManager
|
||||
|
||||
desktop = smgr.createInstanceWithContext(
|
||||
'com.sun.star.frame.Desktop', self.ctx )
|
||||
doc = desktop.getCurrentComponent()
|
||||
|
||||
# saving odt to local file
|
||||
temp_file = os.path.join(tempfile.gettempdir(), 'preview.odt')
|
||||
doc.storeToURL(unohelper.systemPathToFileUrl(temp_file), ())
|
||||
|
||||
href = 'http://tabellio.entrouvert.com/preview/'
|
||||
|
||||
s = urllib2.urlopen(href, data = file(temp_file).read()).read()
|
||||
temp_pdf_file = os.path.join(tempfile.gettempdir(), 'preview.pdf')
|
||||
file(temp_pdf_file, 'w').write(s)
|
||||
|
||||
# XXX: this should be generalised instead of using some special
|
||||
# knowledge about platforms
|
||||
if os.name == 'posix':
|
||||
os.system('see %s &' % temp_pdf_file)
|
||||
else:
|
||||
os.system('start file://%s' % temp_pdf_file)
|
||||
|
||||
# XXX: clean up files
|
||||
|
||||
except Exception, e:
|
||||
print 'exception:', e, str(e)
|
||||
|
||||
|
||||
|
||||
g_ImplementationHelper = unohelper.ImplementationHelper()
|
||||
|
||||
g_ImplementationHelper.addImplementation(
|
||||
|
@ -1006,3 +1043,8 @@ g_ImplementationHelper.addImplementation(
|
|||
"org.entrouvert.openoffice.ConfigurationDialog",
|
||||
("com.sun.star.task.Job",))
|
||||
|
||||
g_ImplementationHelper.addImplementation(
|
||||
Preview,
|
||||
"org.entrouvert.openoffice.Preview",
|
||||
("com.sun.star.task.Job",))
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# preview_server - SCGI server providing preview of ODF files
|
||||
# Copyright (C) 2007 Frederic Peters
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import sys
|
||||
import os
|
||||
from optparse import OptionParser
|
||||
from scgi.scgi_server import SCGIServer, SCGIHandler
|
||||
import cgi
|
||||
|
||||
class PreviewHandler(SCGIHandler):
|
||||
debug = False
|
||||
|
||||
def handle_connection(self, conn):
|
||||
input = conn.makefile('r')
|
||||
output = conn.makefile('w')
|
||||
env = self.read_env(input)
|
||||
bodysize = int(env.get('CONTENT_LENGTH', 0))
|
||||
try:
|
||||
self.produce(env, bodysize, input, output)
|
||||
finally:
|
||||
output.close()
|
||||
input.close()
|
||||
conn.close()
|
||||
|
||||
def produce(self, env, bodysize, input, output):
|
||||
uri = env.get('REQUEST_URI')[9:]
|
||||
if self.debug:
|
||||
print 'uri:', uri
|
||||
print 'bodysize:', bodysize
|
||||
|
||||
if bodysize == 0:
|
||||
print >> output, 'Content-type: text/plain'
|
||||
print >> output, ''
|
||||
print >> output, 'this server only supports POST'
|
||||
|
||||
odf_file = input.read(bodysize)
|
||||
|
||||
# XXX: add conversion to PDF here
|
||||
|
||||
pdf_file = file('unconfigured.pdf').read()
|
||||
print >> output, 'Content-type: application/pdf'
|
||||
print >> output, 'Content-length: %s' % len(pdf_file)
|
||||
print >> output, ''
|
||||
print >> output, pdf_file
|
||||
|
||||
def main():
|
||||
parser = OptionParser()
|
||||
parser.add_option('-p', '--port', dest = 'port', type='int', default = 2151)
|
||||
parser.add_option('--debug', action = 'store_true', dest = 'debug')
|
||||
options, args = parser.parse_args()
|
||||
|
||||
PreviewHandler.debug = options.debug
|
||||
SCGIServer(handler_class = PreviewHandler, port = options.port).serve()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Binary file not shown.
Reference in New Issue