]> git.lyx.org Git - lyx.git/blob - src/Mover.cpp
header cleanup.
[lyx.git] / src / Mover.cpp
1 /**
2  * \file Mover.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Mover.h"
14
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
17 #include "support/Systemcall.h"
18
19 #include <fstream>
20 #include <sstream>
21
22 using namespace std;
23 using namespace lyx::support;
24
25 namespace lyx {
26
27
28 bool Mover::copy(FileName const & from, FileName const & to) const
29 {
30         return do_copy(from, to, to.absFilename());
31 }
32
33
34 bool Mover::do_copy(FileName const & from, FileName const & to,
35                     string const &) const
36 {
37         return from.copyTo(to);
38 }
39
40
41 bool Mover::rename(FileName const & from,
42                    FileName const & to) const
43 {
44         return do_rename(from, to, to.absFilename());
45 }
46
47
48 bool Mover::do_rename(FileName const & from, FileName const & to,
49                       string const &) const
50 {
51         return from.moveTo(to);
52 }
53
54
55 bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
56                                string const & latex) const
57 {
58         if (command_.empty())
59                 return Mover::do_copy(from, to, latex);
60
61         string command = libScriptSearch(command_);
62         command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
63         command = subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
64         command = subst(command, "$$l", quoteName(latex));
65
66         Systemcall one;
67         return one.startscript(Systemcall::Wait, command) == 0;
68 }
69
70
71 bool SpecialisedMover::do_rename(FileName const & from, FileName const & to,
72                                  string const & latex) const
73 {
74         if (command_.empty())
75                 return Mover::do_rename(from, to, latex);
76
77         if (!do_copy(from, to, latex))
78                 return false;
79         return from.removeFile();
80 }
81
82
83 void Movers::set(string const & fmt, string const & command)
84 {
85         specials_[fmt] = SpecialisedMover(command);
86 }
87
88
89 Mover const & Movers::operator()(string const & fmt) const
90 {
91         SpecialsMap::const_iterator const it = specials_.find(fmt);
92         if (it == specials_.end())
93                 return default_;
94         return  it->second;
95 }
96
97
98 string const Movers::command(string  const & fmt) const
99 {
100         SpecialsMap::const_iterator const it = specials_.find(fmt);
101         return (it == specials_.end()) ? string() : it->second.command();
102 }
103
104
105 } // namespace lyx