2002-03-11 17:00:41 +00:00
|
|
|
/**
|
|
|
|
* \file xforms_helpers.C
|
|
|
|
* Copyright 2000-2002 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
2000-11-02 14:47:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-04-23 08:16:27 +00:00
|
|
|
#ifdef __GNUG__
|
2000-11-02 14:47:47 +00:00
|
|
|
#pragma implementation
|
|
|
|
#endif
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
#include "xforms_helpers.h"
|
2002-03-25 11:00:17 +00:00
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "gettext.h"
|
2001-12-12 09:56:03 +00:00
|
|
|
#include "lyxlength.h"
|
2002-01-16 16:34:03 +00:00
|
|
|
#include "lyxgluelength.h"
|
2002-03-25 11:00:17 +00:00
|
|
|
|
2002-03-13 11:26:36 +00:00
|
|
|
#include "support/LAssert.h"
|
|
|
|
#include "support/FileInfo.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h" // frontStrip, strip
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2002-03-25 11:00:17 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2002-03-25 11:00:17 +00:00
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
using std::ofstream;
|
|
|
|
using std::pair;
|
2000-11-02 14:47:47 +00:00
|
|
|
using std::vector;
|
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
// Set an FL_OBJECT to activated or deactivated
|
|
|
|
void setEnabled(FL_OBJECT * ob, bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
fl_activate_object(ob);
|
|
|
|
fl_set_object_lcol(ob, FL_BLACK);
|
|
|
|
} else {
|
|
|
|
fl_deactivate_object(ob);
|
|
|
|
fl_set_object_lcol(ob, FL_INACTIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
// Given an fl_choice, create a vector of its entries
|
|
|
|
vector<string> const getVectorFromChoice(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
vector<string> vec;
|
|
|
|
if (!ob || ob->objclass != FL_CHOICE)
|
|
|
|
return vec;
|
|
|
|
|
|
|
|
for(int i = 0; i < fl_get_choice_maxitems(ob); ++i) {
|
|
|
|
string const text = fl_get_choice_item_text(ob, i+1);
|
|
|
|
vec.push_back(strip(frontStrip(text)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-15 15:31:19 +00:00
|
|
|
/// Given an fl_input, return its contents.
|
|
|
|
string const getStringFromInput(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
if (!ob || ob->objclass != FL_INPUT)
|
|
|
|
return string();
|
|
|
|
|
|
|
|
char const * tmp = fl_get_input(ob);
|
|
|
|
return (tmp) ? tmp : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-14 12:47:17 +00:00
|
|
|
// Given an fl_browser, return the contents of line
|
2002-01-08 10:05:53 +00:00
|
|
|
string const getStringFromBrowser(FL_OBJECT * ob, int line)
|
|
|
|
{
|
2002-03-21 21:21:28 +00:00
|
|
|
if (!ob || ob->objclass != FL_BROWSER ||
|
2002-01-08 10:05:53 +00:00
|
|
|
line < 1 || line > fl_get_browser_maxline(ob))
|
|
|
|
return string();
|
|
|
|
|
|
|
|
char const * tmp = fl_get_browser_line(ob, line);
|
|
|
|
return (tmp) ? tmp : string();
|
|
|
|
}
|
|
|
|
|
2002-01-14 12:47:17 +00:00
|
|
|
// Given an fl_browser, return the contents of the currently
|
|
|
|
// highlighted line.
|
|
|
|
// If nothing is selected, return an empty string
|
|
|
|
string const getSelectedStringFromBrowser(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
if (!ob || ob->objclass != FL_BROWSER)
|
|
|
|
return string();
|
|
|
|
|
|
|
|
int const line = fl_get_browser(ob);
|
|
|
|
if (line < 1 || line > fl_get_browser_maxline(ob))
|
|
|
|
return string();
|
|
|
|
|
|
|
|
if (!fl_isselected_browser_line(ob, line))
|
|
|
|
return string();
|
|
|
|
|
|
|
|
char const * tmp = fl_get_browser_line(ob, line);
|
|
|
|
return (tmp) ? tmp : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
// Given an fl_browser, create a vector of its entries
|
|
|
|
vector<string> const getVectorFromBrowser(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
vector<string> vec;
|
|
|
|
if (!ob || ob->objclass != FL_BROWSER)
|
|
|
|
return vec;
|
|
|
|
|
|
|
|
for(int i = 0; i < fl_get_browser_maxline(ob); ++i) {
|
|
|
|
string const text = fl_get_browser_line(ob, i+1);
|
|
|
|
vec.push_back(strip(frontStrip(text)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-09 12:36:36 +00:00
|
|
|
string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
|
|
|
|
{
|
|
|
|
// Paranoia check
|
|
|
|
lyx::Assert(input && input->objclass == FL_INPUT &&
|
|
|
|
choice && choice->objclass == FL_CHOICE);
|
|
|
|
|
2001-10-11 17:28:28 +00:00
|
|
|
string const length = strip(frontStrip(fl_get_input(input)));
|
2001-10-09 15:20:10 +00:00
|
|
|
if (length.empty())
|
2001-10-11 17:28:28 +00:00
|
|
|
return string();
|
2001-10-09 12:36:36 +00:00
|
|
|
|
2002-01-16 16:34:03 +00:00
|
|
|
//don't return unit-from-choice if the input(field) contains a unit
|
|
|
|
if (isValidGlueLength(length))
|
|
|
|
return length;
|
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
string unit = strip(frontStrip(fl_get_choice_text(choice)));
|
|
|
|
unit = subst(unit, "%%", "%");
|
2001-10-09 12:36:36 +00:00
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
return length + unit;
|
2001-10-09 12:36:36 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-10-09 12:36:36 +00:00
|
|
|
|
2001-12-11 17:26:52 +00:00
|
|
|
void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
|
|
|
|
string const & str,
|
|
|
|
string const & default_unit)
|
|
|
|
{
|
2002-02-11 18:57:30 +00:00
|
|
|
// use input field only for gluelengths
|
|
|
|
if (!isValidLength(str) && !isStrDbl(str)) {
|
|
|
|
fl_set_input(input, str.c_str());
|
2002-03-22 11:41:23 +00:00
|
|
|
// we assume that "default_unit" is in the choice as "we"
|
|
|
|
// have control over that!
|
|
|
|
// No need to check for it's precence in the choice, therefore.
|
2002-02-11 18:57:30 +00:00
|
|
|
fl_set_choice_text(choice, default_unit.c_str());
|
|
|
|
} else {
|
|
|
|
updateWidgetsFromLength(input, choice,
|
2001-12-11 17:26:52 +00:00
|
|
|
LyXLength(str), default_unit);
|
2002-02-11 18:57:30 +00:00
|
|
|
}
|
2001-12-11 17:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
|
|
|
|
LyXLength const & len,
|
|
|
|
string const & default_unit)
|
|
|
|
{
|
|
|
|
// Paranoia check
|
|
|
|
lyx::Assert(input && input->objclass == FL_INPUT &&
|
|
|
|
choice && choice->objclass == FL_CHOICE);
|
|
|
|
|
|
|
|
if (len.zero()) {
|
|
|
|
fl_set_input(input, "");
|
|
|
|
fl_set_choice_text(choice, default_unit.c_str());
|
|
|
|
} else {
|
|
|
|
ostringstream buffer;
|
|
|
|
buffer << len.value();
|
|
|
|
fl_set_input(input, buffer.str().c_str());
|
2002-03-22 11:41:23 +00:00
|
|
|
|
|
|
|
// Set the choice to the desired unit, if present in the choice.
|
|
|
|
// Else set the choice to the default unit.
|
|
|
|
string const unit = subst(stringFromUnit(len.unit()),"%","%%");
|
|
|
|
|
|
|
|
vector<string> const vec = getVectorFromChoice(choice);
|
|
|
|
vector<string>::const_iterator it =
|
|
|
|
std::find(vec.begin(), vec.end(), unit);
|
|
|
|
if (it != vec.end()) {
|
|
|
|
fl_set_choice_text(choice, unit.c_str());
|
|
|
|
} else {
|
|
|
|
fl_set_choice_text(choice, default_unit.c_str());
|
|
|
|
}
|
2001-12-11 17:26:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-02 14:47:47 +00:00
|
|
|
// Take a string and add breaks so that it fits into a desired label width, w
|
2000-12-29 12:48:02 +00:00
|
|
|
string formatted(string const & sin, int w, int size, int style)
|
2000-11-02 14:47:47 +00:00
|
|
|
{
|
|
|
|
string sout;
|
2000-12-29 12:48:02 +00:00
|
|
|
if (sin.empty()) return sout;
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2002-03-18 15:56:00 +00:00
|
|
|
string::size_type curpos = 0;
|
|
|
|
string line;
|
|
|
|
for(;;) {
|
|
|
|
string::size_type const nxtpos1 = sin.find(' ', curpos);
|
|
|
|
string::size_type const nxtpos2 = sin.find('\n', curpos);
|
|
|
|
string::size_type const nxtpos = std::min(nxtpos1, nxtpos1);
|
|
|
|
|
|
|
|
string const word = nxtpos == string::npos ?
|
|
|
|
sin.substr(curpos) : sin.substr(curpos, nxtpos-curpos);
|
|
|
|
|
|
|
|
bool const newline = (nxtpos2 != string::npos &&
|
|
|
|
nxtpos2 < nxtpos1);
|
|
|
|
|
|
|
|
string const line_plus_word =
|
|
|
|
line.empty() ? word : line + ' ' + word;
|
|
|
|
|
|
|
|
int const length =
|
|
|
|
fl_get_string_width(style, size,
|
|
|
|
line_plus_word.c_str(),
|
|
|
|
int(line_plus_word.length()));
|
|
|
|
|
|
|
|
if (length >= w) {
|
|
|
|
sout += line + '\n';
|
|
|
|
if (newline) {
|
|
|
|
sout += word + '\n';
|
|
|
|
line.erase();
|
|
|
|
} else {
|
|
|
|
line = word;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (newline) {
|
|
|
|
sout += line_plus_word + '\n';
|
|
|
|
line.erase();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!line.empty())
|
|
|
|
line += ' ';
|
|
|
|
line += word;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-03-18 15:56:00 +00:00
|
|
|
if (nxtpos == string::npos) {
|
|
|
|
if (!line.empty())
|
|
|
|
sout += line;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos = nxtpos+1;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-11-02 14:47:47 +00:00
|
|
|
return sout;
|
|
|
|
}
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
|
2002-03-13 11:26:36 +00:00
|
|
|
void setCursorColor(int color)
|
|
|
|
{
|
|
|
|
fl_set_cursor_color(FL_DEFAULT_CURSOR, color, FL_WHITE);
|
|
|
|
fl_set_cursor_color(XC_xterm, color, FL_WHITE);
|
|
|
|
fl_set_cursor_color(XC_watch, color, FL_WHITE);
|
|
|
|
fl_set_cursor_color(XC_sb_right_arrow, color, FL_WHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
// sorted by hand to prevent LyXLex from complaining on read().
|
|
|
|
keyword_item xformTags[] = {
|
2002-03-11 09:54:42 +00:00
|
|
|
{ "\\gui_background", FL_COL1 },
|
2000-11-15 18:02:45 +00:00
|
|
|
{ "\\gui_buttonbottom", FL_BOTTOM_BCOL },
|
2002-03-11 09:54:42 +00:00
|
|
|
{ "\\gui_buttonleft", FL_LEFT_BCOL },
|
|
|
|
{ "\\gui_buttonright", FL_RIGHT_BCOL },
|
|
|
|
{ "\\gui_buttontop", FL_TOP_BCOL },
|
|
|
|
{ "\\gui_inactive", FL_INACTIVE },
|
|
|
|
{ "\\gui_pointer", FL_FREE_COL16 },
|
|
|
|
{ "\\gui_push_button", FL_YELLOW },
|
2002-03-21 21:21:28 +00:00
|
|
|
{ "\\gui_selected", FL_MCOL },
|
2002-03-11 09:54:42 +00:00
|
|
|
{ "\\gui_text", FL_BLACK }
|
2000-11-15 18:02:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
const int xformCount = sizeof(xformTags) / sizeof(keyword_item);
|
|
|
|
|
|
|
|
} // namespace anon
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
bool XformsColor::read(string const & filename)
|
2000-11-15 18:02:45 +00:00
|
|
|
{
|
|
|
|
LyXLex lexrc(xformTags, xformCount);
|
|
|
|
if (!lexrc.setFile(filename))
|
|
|
|
return false;
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
while (lexrc.isOK()) {
|
2000-11-15 18:02:45 +00:00
|
|
|
int const le = lexrc.lex();
|
|
|
|
|
|
|
|
switch (le) {
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown tag `$$Token'");
|
2002-03-21 21:21:28 +00:00
|
|
|
continue;
|
2000-11-15 18:02:45 +00:00
|
|
|
case LyXLex::LEX_FEOF:
|
|
|
|
continue;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
string const tag = lexrc.getString();
|
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
RGBColor col;
|
|
|
|
|
|
|
|
if (!lexrc.next()) break;
|
2001-08-06 19:13:25 +00:00
|
|
|
col.r = lexrc.getInteger();
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
if (!lexrc.next()) break;
|
2001-08-06 19:13:25 +00:00
|
|
|
col.g = lexrc.getInteger();
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
if (!lexrc.next()) break;
|
2001-08-06 19:13:25 +00:00
|
|
|
col.b = lexrc.getInteger();
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
fl_mapcolor(le, col.r, col.g, col.b);
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
|
|
if (tag == "\\gui_pointer") {
|
2002-03-13 11:26:36 +00:00
|
|
|
setCursorColor(FL_FREE_COL16);
|
2002-03-11 09:54:42 +00:00
|
|
|
}
|
2000-11-15 18:02:45 +00:00
|
|
|
}
|
2002-03-13 11:26:36 +00:00
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
bool XformsColor::write(string const & filename)
|
2000-11-15 18:02:45 +00:00
|
|
|
{
|
|
|
|
ofstream os(filename.c_str());
|
|
|
|
if (!os)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
os << "### This file is part of\n"
|
|
|
|
<< "### ========================================================\n"
|
|
|
|
<< "### LyX, The Document Processor\n"
|
|
|
|
<< "###\n"
|
|
|
|
<< "### Copyright 1995 Matthias Ettrich\n"
|
2002-03-11 09:54:42 +00:00
|
|
|
<< "### Copyright 1995-2002 The LyX Team.\n"
|
2000-11-15 18:02:45 +00:00
|
|
|
<< "###\n"
|
|
|
|
<< "### ========================================================\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "# This file is written by LyX, if you want to make your own\n"
|
|
|
|
<< "# modifications you should do them from inside LyX and save\n"
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
for (int i = 0; i < xformCount; ++i) {
|
|
|
|
string const tag = xformTags[i].tag;
|
|
|
|
int const colorID = xformTags[i].code;
|
|
|
|
RGBColor color;
|
|
|
|
|
|
|
|
fl_getmcolor(colorID, &color.r, &color.g, &color.b);
|
|
|
|
|
|
|
|
os << tag << " "
|
|
|
|
<< color.r << " " << color.g << " " << color.b << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2000-11-21 15:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
string RWInfo::error_message;
|
|
|
|
|
|
|
|
bool RWInfo::WriteableDir(string const & name)
|
|
|
|
{
|
|
|
|
error_message.erase();
|
|
|
|
|
|
|
|
if (!AbsolutePath(name)) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("The absolute path is required.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo const tp(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (!tp.isOK() || !tp.isDir()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Directory does not exist.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tp.writable()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Cannot write to this directory.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RWInfo::ReadableDir(string const & name)
|
|
|
|
{
|
|
|
|
error_message.erase();
|
|
|
|
|
|
|
|
if (!AbsolutePath(name)) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("The absolute path is required.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo const tp(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (!tp.isOK() || !tp.isDir()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Directory does not exist.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tp.readable()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Cannot read this directory.");
|
2000-11-21 15:46:13 +00:00
|
|
|
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()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("No file input.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const dir = OnlyPath(name);
|
|
|
|
if (!AbsolutePath(dir)) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("The absolute path is required.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo d(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
|
|
|
|
if (!d.isOK() || !d.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
d.newFile(dir);
|
|
|
|
}
|
|
|
|
|
2002-01-07 17:57:21 +00:00
|
|
|
if (!d.isOK() || !d.isDir()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Directory does not exist.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-11-21 15:46:13 +00:00
|
|
|
if (!d.writable()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Cannot write to this directory.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo f(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (dir == name || (f.isOK() && f.isDir())) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("A file is required, not a directory.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-01-07 10:17:44 +00:00
|
|
|
if (f.isOK() && f.exist() && !f.writable()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Cannot write to this file.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-11-21 15:46:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RWInfo::ReadableFile(string const & name)
|
|
|
|
{
|
|
|
|
error_message.erase();
|
|
|
|
|
|
|
|
if (name.empty()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("No file input.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const dir = OnlyPath(name);
|
|
|
|
if (!AbsolutePath(dir)) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("The absolute path is required.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo d(name);
|
2002-01-07 17:57:21 +00:00
|
|
|
|
2002-01-07 10:17:44 +00:00
|
|
|
if (!d.isOK() && !d.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
d.newFile(dir);
|
|
|
|
}
|
|
|
|
|
2002-01-07 17:57:21 +00:00
|
|
|
if (!d.isOK() || !d.isDir()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Directory does not exist.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-11-21 15:46:13 +00:00
|
|
|
if (!d.readable()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Cannot read from this directory.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo f(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (dir == name || (f.isOK() && f.isDir())) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("A file is required, not a directory.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f.exist()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("File does not exist.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-11-21 15:46:13 +00:00
|
|
|
if (!f.readable()) {
|
2002-04-02 17:04:23 +00:00
|
|
|
error_message = _("Cannot read from this file.");
|
2000-11-21 15:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|