]> git.lyx.org Git - lyx.git/blob - src/support/os_unix.cpp
Introduce FileName::changePermission() and fix ConverterCache.
[lyx.git] / src / support / os_unix.cpp
1 /**
2  * \file os_unix.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Ruurd A. Reitsma
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  * Various OS specific functions
11  */
12
13 #include <config.h>
14
15 #include "support/os.h"
16 #include "support/docstring.h"
17
18 #ifdef __APPLE__
19 #include <Carbon/Carbon.h>
20 #endif
21
22 using namespace std;
23
24 namespace lyx {
25 namespace support {
26 namespace os {
27
28 void init(int, char *[])
29 {}
30
31
32 string current_root()
33 {
34         return "/";
35 }
36
37
38 docstring::size_type common_path(docstring const & p1, docstring const & p2)
39 {
40         docstring::size_type i = 0;
41         docstring::size_type const p1_len = p1.length();
42         docstring::size_type const p2_len = p2.length();
43         while (i < p1_len && i < p2_len && p1[i] == p2[i])
44                 ++i;
45         if ((i < p1_len && i < p2_len)
46             || (i < p1_len && p1[i] != '/' && i == p2_len)
47             || (i < p2_len && p2[i] != '/' && i == p1_len))
48         {
49                 if (i)
50                         --i;     // here was the last match
51                 while (i && p1[i] != '/')
52                         --i;
53         }
54         return i;
55 }
56
57
58 string external_path(string const & p)
59 {
60         return p;
61 }
62
63
64 string internal_path(string const & p)
65 {
66         return p;
67 }
68
69
70 string external_path_list(string const & p)
71 {
72         return p;
73 }
74
75
76 string internal_path_list(string const & p)
77 {
78         return p;
79 }
80
81
82 string latex_path(string const & p)
83 {
84         return p;
85 }
86
87
88 bool is_absolute_path(string const & p)
89 {
90         return !p.empty() && p[0] == '/';
91 }
92
93
94 char const * popen_read_mode()
95 {
96         return "r";
97 }
98
99
100 string const & nulldev()
101 {
102         static string const nulldev_ = "/dev/null";
103         return nulldev_;
104 }
105
106
107 shell_type shell()
108 {
109         return UNIX;
110 }
111
112
113 char path_separator()
114 {
115         return ':';
116 }
117
118
119 void windows_style_tex_paths(bool)
120 {}
121
122 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
123 {
124 #ifdef __APPLE__
125 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
126         CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
127                                         (UInt8 *) ext.c_str(), ext.length(),
128                                         kCFStringEncodingISOLatin1, false);
129         // this is what we would like to do but it seems that the
130         // viewer for PDF is often quicktime...
131         //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer :  kLSRolesEditor;
132         (void)mode;
133         LSRolesMask role = kLSRolesAll;
134         FSRef outAppRef;
135         OSStatus status =
136                 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
137                                         cfs_ext, role, &outAppRef, NULL);
138         CFRelease(cfs_ext);
139
140         return status != kLSApplicationNotFoundErr;
141 #else
142         // silence compiler warnings
143         (void)ext;
144         (void)mode;
145
146         // currently, no default viewer is tried for non-windows system
147         // support for KDE/Gnome/Macintosh may be added later
148         return false;
149 #endif
150 }
151
152
153 bool autoOpenFile(string const & filename, auto_open_mode const mode)
154 {
155 #ifdef __APPLE__
156 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
157         FSRef fileref;
158         OSStatus status =
159                 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
160         if (status != 0)
161                 return false;
162
163         // this is what we would like to do but it seems that the
164         // viewer for PDF is often quicktime...
165         //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer :  kLSRolesEditor;
166         (void)mode;
167         LSRolesMask role = kLSRolesAll;
168         FSRef outAppRef;
169
170         status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
171         if (status == kLSApplicationNotFoundErr)
172                 return false;
173
174         LSLaunchFSRefSpec inLaunchSpec;
175         inLaunchSpec.appRef = &outAppRef;
176         inLaunchSpec.numDocs = 1;
177         inLaunchSpec.itemRefs = &fileref;
178         inLaunchSpec.passThruParams = NULL;
179         inLaunchSpec.launchFlags = kLSLaunchDefaults;
180         inLaunchSpec.asyncRefCon = NULL;
181         status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
182
183         return status != kLSApplicationNotFoundErr;
184 #else
185         // silence compiler warnings
186         (void)filename;
187         (void)mode;
188
189         // currently, no default viewer is tried for non-windows system
190         // support for KDE/Gnome/Macintosh may be added later
191         return false;
192 #endif
193 }
194
195 } // namespace os
196 } // namespace support
197 } // namespace lyx