]> git.lyx.org Git - lyx.git/blob - src/mover.C
- Link against qt-mt333.lib which is what the current qt3 cvs produces
[lyx.git] / src / mover.C
1 /**
2  * \file mover.C
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 "mover.h"
12
13 #include "support/filetools.h"
14 #include "support/lstrings.h"
15 #include "support/lyxlib.h"
16 #include "support/systemcall.h"
17
18 #include <sstream>
19
20 using std::ostringstream;
21 using std::string;
22
23 namespace support = lyx::support;
24
25 Movers movers;
26 Movers system_movers;
27
28
29 bool Mover::do_copy(string const & from, string const & to,
30                     string const &) const
31 {
32         return support::copy(from, to);
33 }
34
35
36 bool Mover::do_rename(string const & from, string const & to,
37                       string const &) const
38 {
39         return support::rename(from, to);
40 }
41
42
43 bool SpecialisedMover::do_copy(string const & from, string const & to,
44                                string const & latex) const
45 {
46         if (command_.empty())
47                 return Mover::do_copy(from, to, latex);
48
49         string command = support::LibScriptSearch(command_);
50         command = support::subst(command, "$$i", from);
51         command = support::subst(command, "$$o", to);
52         command = support::subst(command, "$$l", latex);
53
54         support::Systemcall one;
55         return one.startscript(support::Systemcall::Wait, command) == 0;
56 }
57
58
59 bool SpecialisedMover::do_rename(string const & from, string const & to,
60                                  string const & latex) const
61 {
62         if (command_.empty())
63                 return Mover::do_rename(from, to, latex);
64
65         if (!do_copy(from, to, latex))
66                 return false;
67         return support::unlink(from) == 0;
68 }
69
70
71 void Movers::set(string const & fmt, string const & command)
72 {
73         specials_[fmt] = SpecialisedMover(command);
74 }
75
76
77 Mover const & Movers::operator()(string const & fmt) const
78 {
79         SpecialsMap::const_iterator const it = specials_.find(fmt);
80         return (it == specials_.end()) ? default_ : it->second;
81 }
82
83
84 string const Movers::command(string  const & fmt) const
85 {
86         SpecialsMap::const_iterator const it = specials_.find(fmt);
87         return (it == specials_.end()) ? string() : it->second.command();
88 }