]> git.lyx.org Git - lyx.git/blob - src/mover.C
QComboBox::textChanged is a Qt3 support signal only, QComboBox::editTextChanged is...
[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 <config.h>
12
13 #include "mover.h"
14
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
17 #include "support/lyxlib.h"
18 #include "support/systemcall.h"
19
20 #include <fstream>
21 #include <sstream>
22
23
24 namespace lyx {
25
26 using std::ios;
27 using std::string;
28
29 Movers movers;
30 Movers system_movers;
31
32
33 bool Mover::do_copy(string const & from, string const & to,
34                     string const &, unsigned long int mode) const
35 {
36         return support::copy(from, to, mode);
37 }
38
39
40 bool Mover::do_rename(string const & from, string const & to,
41                       string const &) const
42 {
43         return support::rename(from, to);
44 }
45
46
47 bool SpecialisedMover::do_copy(string const & from, string const & to,
48                                string const & latex, unsigned long int mode) const
49 {
50         if (command_.empty())
51                 return Mover::do_copy(from, to, latex, mode);
52
53         if (mode != (unsigned long int)-1) {
54                 std::ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
55                 if (!ofs)
56                         return false;
57                 ofs.close();
58                 if (!support::chmod(to, mode))
59                         return false;
60         }
61
62         string command = support::libScriptSearch(command_);
63         command = support::subst(command, "$$i", from);
64         command = support::subst(command, "$$o", to);
65         command = support::subst(command, "$$l", latex);
66
67         support::Systemcall one;
68         return one.startscript(support::Systemcall::Wait, command) == 0;
69 }
70
71
72 bool SpecialisedMover::do_rename(string const & from, string const & to,
73                                  string const & latex) const
74 {
75         if (command_.empty())
76                 return Mover::do_rename(from, to, latex);
77
78         if (!do_copy(from, to, latex, (unsigned long int)-1))
79                 return false;
80         return support::unlink(from) == 0;
81 }
82
83
84 void Movers::set(string const & fmt, string const & command)
85 {
86         specials_[fmt] = SpecialisedMover(command);
87 }
88
89
90 Mover const & Movers::operator()(string const & fmt) const
91 {
92         SpecialsMap::const_iterator const it = specials_.find(fmt);
93         return (it == specials_.end()) ? default_ : it->second;
94 }
95
96
97 string const Movers::command(string  const & fmt) const
98 {
99         SpecialsMap::const_iterator const it = specials_.find(fmt);
100         return (it == specials_.end()) ? string() : it->second.command();
101 }
102
103
104 } // namespace lyx