]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/Liason.C
use the new sstream return non-pods as const, use string instead of char * in a lot...
[lyx.git] / src / frontends / Liason.C
index 7da6ed7da46c01cae2c1d0f6ae12096c87da1544..c0a4b31fc3de67765c1283d952d0630151a96c9c 100644 (file)
@@ -1,7 +1,21 @@
+/* This file is part of
+ * ====================================================== 
+ * 
+ *           LyX, The Document Processor
+ *        
+ *           Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-2000 The LyX Team.
+ *
+ * ====================================================== */
+
 #include <config.h>
 
-//#include "config.h"
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "Liason.h"
+#include "LyXView.h"
 #include "BufferView.h"
 #include "buffer.h"
 #include "lyxrc.h"
 #include "support/lstrings.h"
 #include "support/filetools.h"
 #include "support/path.h"
+#include "exporter.h"
+#include "converter.h"
+#include "minibuffer.h"
+#include "support/syscall.h"
+
+using std::endl;
 
 extern LyXRC lyxrc;
+#ifndef NEW_EXPORT
 extern bool RunScript(Buffer * buffer, bool wait, string const & command,
                      string const & orgname = string(), bool need_shell=true);
-
+#endif
 
 #ifdef CXX_WORKING_NAMESPACES
 namespace Liason 
@@ -32,7 +53,9 @@ PrinterParams getPrinterParams(Buffer * buffer)
 
 bool printBuffer(Buffer * buffer, PrinterParams const & pp) 
 {
+#ifndef NEW_EXPORT
        bool result(false);
+#endif
        string command(lyxrc.print_command + ' ');
        
        if (pp.target == PrinterParams::PRINTER
@@ -72,12 +95,6 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp)
                command += lyxrc.print_reverse_flag + ' ';
        }
 
-       BufferParams params(buffer->params);
-       if (params.orientation
-           == BufferParams::ORIENTATION_LANDSCAPE) {
-               command += lyxrc.print_landscape_flag + ' ';
-       }
-
        if (1 < pp.count_copies) {
                if (pp.unsorted_copies) {
                        command += lyxrc.print_copies_flag;
@@ -93,57 +110,60 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp)
                command += lyxrc.print_extra_options + ' ';
        }
 
-       char real_papersize = params.papersize;
-       if (real_papersize == BufferParams::PAPER_DEFAULT) {
-               real_papersize = lyxrc.default_papersize;
-       }
+       command += Converter::dvips_options(buffer) + ' ';
 
-       if (params.use_geometry
-           && params.papersize2 == BufferParams::VM_PAPER_CUSTOM
-           && !lyxrc.print_paper_dimension_flag.empty()
-           && !params.paperwidth.empty()
-           && !params.paperheight.empty()) {
-               // using a custom papersize
-               command += lyxrc.print_paper_dimension_flag + ' ';
-               command += params.paperwidth + ',';
-               command += params.paperheight + ' ';
-       } else if (!lyxrc.print_paper_flag.empty()
-                  && (real_papersize != BufferParams::PAPER_USLETTER
-                      || params.orientation 
-                      == BufferParams::ORIENTATION_PORTRAIT)) {
-               // There's a problem with US Letter + landscape
-               string paper;
-               switch (real_papersize) {
-               case BufferParams::PAPER_USLETTER:
-                       paper = "letter";
-                       break;
-               case BufferParams::PAPER_A3PAPER:
-                       paper = "a3";
-                       break;
-               case BufferParams::PAPER_A4PAPER:
-                       paper = "a4";
-                       break;
-               case BufferParams::PAPER_A5PAPER:
-                       paper = "a5";
-                       break;
-               case BufferParams::PAPER_B5PAPER:
-                       paper = "b5";
-                       break;
-               case BufferParams::PAPER_EXECUTIVEPAPER:
-                       paper = "foolscap";
-                       break;
-               case BufferParams::PAPER_LEGALPAPER:
-                       paper = "legal";
-                       break;
-               default: /* If nothing else fits, keep empty value */
-                       break;
-               }
-               if (!paper.empty()) {
-                       command += lyxrc.print_paper_flag + ' ';
-                       command += paper + ' ';
-               }
+#ifdef NEW_EXPORT
+       if (!Exporter::Export(buffer, "dvi", true))
+               return false;
+
+       // Push directory path.
+       string path = OnlyPath(buffer->fileName());
+       if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
+               path = buffer->tmppath;
        }
+       Path p(path);
 
+       // there are three cases here:
+       // 1. we print to a file
+       // 2. we print direct to a printer
+       // 3. we print using a spool command (print to file first)
+       Systemcalls one;
+       int res = 0;
+       string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
+       switch (pp.target) {
+       case PrinterParams::PRINTER:
+               if (!lyxrc.print_spool_command.empty()) {
+                       // case 3
+                       string psname = ChangeExtension(dviname, ".ps");
+                       command += lyxrc.print_to_file
+                               + QuoteName(psname) + ' ';
+                       command += QuoteName(dviname);
+                       string command2 = lyxrc.print_spool_command + ' ';
+                       if (!pp.printer_name.empty())
+                               command2 += lyxrc.print_spool_printerprefix
+                                       + pp.printer_name + ' ';
+                       command2 += QuoteName(psname);
+                       // First run dvips.
+                       // If successful, then spool command
+                       res = one.startscript(Systemcalls::System, command);
+                       if (res == 0)
+                               res = one.startscript(Systemcalls::SystemDontWait,
+                                                     command2);
+               } else
+                       // case 2
+                       res = one.startscript(Systemcalls::SystemDontWait, command);
+               break;
+
+       case PrinterParams::FILE:
+               // case 1
+               command += lyxrc.print_to_file
+                       + QuoteName(MakeAbsPath(pp.file_name, path));
+               command += ' ' + QuoteName(dviname);
+               res = one.startscript(Systemcalls::SystemDontWait, command);
+               break;
+       }
+       return res == 0;
+#else
        // Push directory path if necessary.
        // PS file should go where the source file is unless it's a
        // read-only directory in which case we write it to tmpdir.
@@ -193,6 +213,12 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp)
                break;
        }
        return result;
+#endif
+}
+
+void setMinibuffer(LyXView * lv, char const * msg)
+{
+       lv->getMiniBuffer()->Set(msg);
 }
 
 #ifdef CXX_WORKING_NAMESPACES