#include FORMS_H_LOCATION
+#include <fstream> // ofstream
+#include <vector>
+
#ifdef __GNUG_
#pragma implementation
#endif
-#include <vector>
#include "xform_helpers.h"
-#include <fstream> // ofstream
#include "lyxlex.h"
#include "filedlg.h" // LyXFileDlg
#include "support/FileInfo.h"
using std::vector;
// Take a string and add breaks so that it fits into a desired label width, w
-string formatted( string const & sin, int w, int size, int style )
+string formatted(string const & sin, int w, int size, int style)
{
string sout;
- if (sin.empty() ) return sout;
+ if (sin.empty()) return sout;
// break sin up into a vector of individual words
vector<string> sentence;
}
-string const browseFile( string const & filename,
- string const & title,
- string const & pattern,
- pair<string,string> const & dir1,
- pair<string,string> const & dir2 )
+string const browseFile(string const & filename,
+ string const & title,
+ string const & pattern,
+ pair<string,string> const & dir1,
+ pair<string,string> const & dir2)
{
string lastPath = ".";
- if( !filename.empty() ) lastPath = OnlyPath(filename);
+ if (!filename.empty()) lastPath = OnlyPath(filename);
LyXFileDlg fileDlg;
- if( !dir1.second.empty() ) {
- FileInfo fileInfo( dir1.second );
- if( fileInfo.isOK() && fileInfo.isDir() )
- fileDlg.SetButton( 0, dir1.first, dir1.second );
+ if (!dir1.second.empty()) {
+ FileInfo fileInfo(dir1.second);
+ if (fileInfo.isOK() && fileInfo.isDir())
+ fileDlg.SetButton(0, _(dir1.first), dir1.second);
}
- if( !dir2.second.empty() ) {
- FileInfo fileInfo( dir2.second );
- if( fileInfo.isOK() && fileInfo.isDir() )
- fileDlg.SetButton( 1, dir2.first, dir2.second );
+ if (!dir2.second.empty()) {
+ FileInfo fileInfo(dir2.second);
+ if (fileInfo.isOK() && fileInfo.isDir())
+ fileDlg.SetButton(1, _(dir2.first), dir2.second);
}
bool error = false;
string buf;
do {
- string p = fileDlg.Select(title,
+ string p = fileDlg.Select(_(title),
lastPath,
- pattern, filename );
+ pattern, OnlyFilename(filename));
if (p.empty()) return p;
// sorted by hand to prevent LyXLex from complaining on read().
static
keyword_item xformTags[] = {
-// { "\\gui_active_tab", FL_LIGHTER_COL1 },
{ "\\gui_background", FL_COL1 },
{ "\\gui_buttonbottom", FL_BOTTOM_BCOL },
{ "\\gui_buttonleft", FL_LEFT_BCOL },
fl_mapcolor(le, col.r, col.g, col.b);
}
-
+
return true;
}
return true;
}
+
+
+string RWInfo::error_message;
+
+bool RWInfo::WriteableDir(string const & name)
+{
+ error_message.erase();
+
+ if (!AbsolutePath(name)) {
+ error_message = N_("The absolute path is required.");
+ return false;
+ }
+
+ FileInfo const tp(name);
+ if (!tp.isDir()) {
+ error_message = N_("Directory does not exist.");
+ return false;
+ }
+
+ if (!tp.writable()) {
+ error_message = N_("Cannot write to this directory.");
+ return false;
+ }
+
+ return true;
+}
+
+
+bool RWInfo::ReadableDir(string const & name)
+{
+ error_message.erase();
+
+ if (!AbsolutePath(name)) {
+ error_message = N_("The absolute path is required.");
+ return false;
+ }
+
+ FileInfo const tp(name);
+ if (!tp.isDir()) {
+ error_message = N_("Directory does not exist.");
+ return false;
+ }
+
+ if (!tp.readable()) {
+ error_message = N_("Cannot read this directory.");
+ return false;
+ }
+
+ return true;
+}
+
+
+bool RWInfo::WriteableFile(string const & name)
+{
+ // A writeable file is either:
+ // * An existing file to which we have write access, or
+ // * A file that doesn't yet exist but that would exist in a writeable
+ // directory.
+
+ error_message.erase();
+
+ if (name.empty()) {
+ error_message = N_("No file input.");
+ return false;
+ }
+
+ string const dir = OnlyPath(name);
+ if (!AbsolutePath(dir)) {
+ error_message = N_("The absolute path is required.");
+ return false;
+ }
+
+ FileInfo d(name);
+ if (!d.isDir()) {
+ d.newFile(dir);
+ }
+
+ if (!d.isDir()) {
+ error_message = N_("Directory does not exist.");
+ return false;
+ }
+
+ if (!d.writable()) {
+ error_message = N_("Cannot write to this directory.");
+ return false;
+ }
+
+ FileInfo f(name);
+ if (dir == name || f.isDir()) {
+ error_message = N_("A file is required, not a directory.");
+ return false;
+ }
+
+ if (f.exist() && !f.writable()) {
+ error_message = N_("Cannot write to this file.");
+ return false;
+ }
+
+ return true;
+}
+
+
+bool RWInfo::ReadableFile(string const & name)
+{
+ error_message.erase();
+
+ if (name.empty()) {
+ error_message = N_("No file input.");
+ return false;
+ }
+
+ string const dir = OnlyPath(name);
+ if (!AbsolutePath(dir)) {
+ error_message = N_("The absolute path is required.");
+ return false;
+ }
+
+ FileInfo d(name);
+ if (!d.isDir()) {
+ d.newFile(dir);
+ }
+
+ if (!d.isDir()) {
+ error_message = N_("Directory does not exist.");
+ return false;
+ }
+
+ if (!d.readable()) {
+ error_message = N_("Cannot read from this directory.");
+ return false;
+ }
+
+ FileInfo f(name);
+ if (dir == name || f.isDir()) {
+ error_message = N_("A file is required, not a directory.");
+ return false;
+ }
+
+ if (!f.exist()) {
+ error_message = N_("File does not exist.");
+ return false;
+ }
+
+ if (!f.readable()) {
+ error_message = N_("Cannot read from this file.");
+ return false;
+ }
+
+ return true;
+}