a few more docstring<->QString conversions

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23493 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-03-05 23:10:53 +00:00
parent 32a3ce2546
commit 88293cbcfb
14 changed files with 363 additions and 362 deletions

View File

@ -57,7 +57,7 @@ public:
}; };
FileDialog::FileDialog(docstring const & t, kb_action s) FileDialog::FileDialog(QString const & t, kb_action s)
: private_(new FileDialog::Private), title_(t), success_(s) : private_(new FileDialog::Private), title_(t), success_(s)
{} {}
@ -68,32 +68,32 @@ FileDialog::~FileDialog()
} }
void FileDialog::setButton1(docstring const & label, docstring const & dir) void FileDialog::setButton1(QString const & label, QString const & dir)
{ {
private_->b1.first = label; private_->b1.first = label;
private_->b1.second = dir; private_->b1.second = dir;
} }
void FileDialog::setButton2(docstring const & label, docstring const & dir) void FileDialog::setButton2(QString const & label, QString const & dir)
{ {
private_->b2.first = label; private_->b2.first = label;
private_->b2.second = dir; private_->b2.second = dir;
} }
FileDialog::Result const FileDialog::save(docstring const & path, FileDialog::Result FileDialog::save(QString const & path,
FileFilterList const & filters, FileFilterList const & filters,
docstring const & suggested) QString const & suggested)
{ {
LYXERR(Debug::GUI, "Select with path \"" << to_utf8(path) LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", mask \"" << to_utf8(filters.as_string()) << "\", mask \"" << to_utf8(filters.as_string())
<< "\", suggested \"" << to_utf8(suggested) << '"'); << "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result; FileDialog::Result result;
result.first = FileDialog::Chosen; result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG #ifdef USE_NATIVE_FILEDIALOG
docstring const startsWith = from_utf8( QString const startsWith = from_utf8(
makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename()); makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
QString const name = QString const name =
QFileDialog::getSaveFileName(qApp->focusWidget(), QFileDialog::getSaveFileName(qApp->focusWidget(),
@ -111,66 +111,64 @@ FileDialog::Result const FileDialog::save(docstring const & path,
dlg.setAcceptMode(QFileDialog::AcceptSave); dlg.setAcceptMode(QFileDialog::AcceptSave);
dlg.setConfirmOverwrite(false); dlg.setConfirmOverwrite(false);
if (!suggested.empty()) if (!suggested.isEmpty())
dlg.selectFile(toqstr(suggested)); dlg.selectFile(suggested);
LYXERR(Debug::GUI, "Synchronous FileDialog: "); LYXERR(Debug::GUI, "Synchronous FileDialog: ");
int res = dlg.exec(); int res = dlg.exec();
LYXERR(Debug::GUI, "result " << res); LYXERR(Debug::GUI, "result " << res);
if (res == QDialog::Accepted) if (res == QDialog::Accepted)
result.second = from_utf8(internal_path( result.second = internalPath(dlg.selectedFiles()[0]);
fromqstr(dlg.selectedFiles()[0])));
dlg.hide(); dlg.hide();
#endif #endif
return result; return result;
} }
FileDialog::Result const FileDialog::open(docstring const & path, FileDialog::Result FileDialog::open(QString const & path,
FileFilterList const & filters, FileFilterList const & filters,
docstring const & suggested) QString const & suggested)
{ {
LYXERR(Debug::GUI, "Select with path \"" << to_utf8(path) LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", mask \"" << to_utf8(filters.as_string()) << "\", mask \"" << filters.as_string()
<< "\", suggested \"" << to_utf8(suggested) << '"'); << "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result; FileDialog::Result result;
result.first = FileDialog::Chosen; result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG #ifdef USE_NATIVE_FILEDIALOG
docstring const startsWith = from_utf8( QString const startsWith = toqstr(
makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename()); makeAbsPath(fromqstr(suggested), fromqstr(path)).absFilename());
result.second = from_utf8(internal_path(fromqstr( result.second = internalPath(
QFileDialog::getOpenFileName(qApp->focusWidget(), QFileDialog::getOpenFileName(qApp->focusWidget(),
toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) )))); toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ));
#else #else
LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2); LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
if (!suggested.empty()) if (!suggested.isEmpty())
dlg.selectFile(toqstr(suggested)); dlg.selectFile(suggested);
LYXERR(Debug::GUI, "Synchronous FileDialog: "); LYXERR(Debug::GUI, "Synchronous FileDialog: ");
int res = dlg.exec(); int res = dlg.exec();
LYXERR(Debug::GUI, "result " << res); LYXERR(Debug::GUI, "result " << res);
if (res == QDialog::Accepted) if (res == QDialog::Accepted)
result.second = from_utf8(internal_path( result.second = internalPath(dlg.selectedFiles()[0]);
fromqstr(dlg.selectedFiles()[0])));
dlg.hide(); dlg.hide();
#endif #endif
return result; return result;
} }
FileDialog::Result const FileDialog::opendir(docstring const & path, FileDialog::Result FileDialog::opendir(QString const & path,
docstring const & suggested) QString const & suggested)
{ {
LYXERR(Debug::GUI, "Select with path \"" << to_utf8(path) LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", suggested \"" << to_utf8(suggested) << '"'); << "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result; FileDialog::Result result;
result.first = FileDialog::Chosen; result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG #ifdef USE_NATIVE_FILEDIALOG
docstring const startsWith = from_utf8( QString const startsWith = toqstr(
makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename()); makeAbsPath(fromqstr(suggested), fromqstr(path)).absFilename());
result.second = from_utf8(internal_path(fromqstr( result.second = from_utf8(internal_path(fromqstr(
QFileDialog::getExistingDirectory(qApp->focusWidget(), QFileDialog::getExistingDirectory(qApp->focusWidget(),
toqstr(title_),toqstr(startsWith))))); toqstr(title_),toqstr(startsWith)))));
@ -181,15 +179,14 @@ FileDialog::Result const FileDialog::opendir(docstring const & path,
dlg.setFileMode(QFileDialog::DirectoryOnly); dlg.setFileMode(QFileDialog::DirectoryOnly);
if (!suggested.empty()) if (!suggested.isEmpty())
dlg.selectFile(toqstr(suggested)); dlg.selectFile(suggested);
LYXERR(Debug::GUI, "Synchronous FileDialog: "); LYXERR(Debug::GUI, "Synchronous FileDialog: ");
int res = dlg.exec(); int res = dlg.exec();
LYXERR(Debug::GUI, "result " << res); LYXERR(Debug::GUI, "result " << res);
if (res == QDialog::Accepted) if (res == QDialog::Accepted)
result.second = from_utf8(internal_path( result.second = internalPath(dlg.selectedFiles()[0]);
fromqstr(dlg.selectedFiles()[0])));
dlg.hide(); dlg.hide();
#endif #endif
return result; return result;

View File

@ -14,10 +14,10 @@
#define FILEDIALOG_H #define FILEDIALOG_H
#include "lfuns.h" #include "lfuns.h"
#include "support/docstring.h"
#include <string> #include <QString>
#include <utility>
namespace lyx { namespace lyx {
@ -32,7 +32,7 @@ class FileDialog
{ {
public: public:
/// label, directory path button /// label, directory path button
typedef std::pair<docstring, docstring> Button; typedef std::pair<QString, QString> Button;
/// result type /// result type
enum ResultType { enum ResultType {
@ -41,7 +41,7 @@ public:
}; };
/// result return /// result return
typedef std::pair<FileDialog::ResultType, docstring> Result; typedef std::pair<FileDialog::ResultType, QString> Result;
/** /**
* Constructs a file dialog with title \param title. * Constructs a file dialog with title \param title.
@ -54,26 +54,26 @@ public:
* additional directories in the navigation (an empty * additional directories in the navigation (an empty
* directory is interpreted as FileName::getcwd()) * directory is interpreted as FileName::getcwd())
*/ */
FileDialog(docstring const & title, kb_action a = LFUN_SELECT_FILE_SYNC); FileDialog(QString const & title, kb_action a = LFUN_SELECT_FILE_SYNC);
~FileDialog(); ~FileDialog();
void setButton1(docstring const & label, docstring const & dir); void setButton1(QString const & label, QString const & dir);
void setButton2(docstring const & label, docstring const & dir); void setButton2(QString const & label, QString const & dir);
/// Choose a file for opening, starting in directory \c path. /// Choose a file for opening, starting in directory \c path.
Result const open(docstring const & path, Result open(QString const & path,
support::FileFilterList const & filters, support::FileFilterList const & filters,
docstring const & suggested); QString const & suggested = QString());
/// Choose a directory, starting in directory \c path. /// Choose a directory, starting in directory \c path.
Result const opendir(docstring const & path = docstring(), Result opendir(QString const & path = QString(),
docstring const & suggested = docstring()); QString const & suggested = QString());
/// Choose a file for saving, starting in directory \c path. /// Choose a file for saving, starting in directory \c path.
Result const save(docstring const & path, Result save(QString const & path,
support::FileFilterList const & filters, support::FileFilterList const & filters,
docstring const & suggested); QString const & suggested = QString());
private: private:
class Private; class Private;
@ -81,7 +81,7 @@ private:
Private * private_; Private * private_;
/// the dialog title /// the dialog title
docstring title_; QString title_;
/// success action to perform if not synchronous /// success action to perform if not synchronous
kb_action success_; kb_action success_;

View File

@ -461,9 +461,8 @@ void GuiBibtex::getBibStyles(vector<string> & data) const
} }
vector<string>::iterator it = data.begin(); vector<string>::iterator it = data.begin();
vector<string>::iterator end = data.end(); vector<string>::iterator end = data.end();
for (; it != end; ++it) { for (; it != end; ++it)
*it = onlyFilename(*it); *it = support::onlyFilename(*it);
}
// sort on filename only (no path) // sort on filename only (no path)
sort(data.begin(), data.end()); sort(data.begin(), data.end());
} }
@ -481,9 +480,8 @@ void GuiBibtex::getBibFiles(vector<string> & data) const
} }
vector<string>::iterator it = data.begin(); vector<string>::iterator it = data.begin();
vector<string>::iterator end = data.end(); vector<string>::iterator end = data.end();
for (; it != end; ++it) { for (; it != end; ++it)
*it = onlyFilename(*it); *it = support::onlyFilename(*it);
}
// sort on filename only (no path) // sort on filename only (no path)
sort(data.begin(), data.end()); sort(data.begin(), data.end());
} }

View File

@ -232,15 +232,15 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
FileFilterList const filter(filterSpec); FileFilterList const filter(filterSpec);
// show save dialog for the graphic // show save dialog for the graphic
FileDialog dlg(_("Choose a filename to save the pasted graphic as")); FileDialog dlg(qt_("Choose a filename to save the pasted graphic as"));
FileDialog::Result result = FileDialog::Result result =
dlg.save(from_utf8(filename.onlyPath().absFilename()), filter, dlg.save(toqstr(filename.onlyPath().absFilename()), filter,
from_utf8(filename.onlyFileName())); toqstr(filename.onlyFileName()));
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return FileName(); return FileName();
string newFilename = to_utf8(result.second); string newFilename = fromqstr(result.second);
if (newFilename.empty()) { if (newFilename.empty()) {
cur.bv().message(_("Canceled.")); cur.bv().message(_("Canceled."));
return FileName(); return FileName();

View File

@ -321,7 +321,7 @@ docstring GuiInclude::browse(docstring const & in_name, Type in_type) const
break; break;
} }
docstring const docpath = from_utf8(onlyPath(buffer().absFileName())); docstring const docpath = from_utf8(support::onlyPath(buffer().absFileName()));
return browseRelFile(in_name, docpath, title, filters, false, return browseRelFile(in_name, docpath, title, filters, false,
_("Documents|#o#O"), from_utf8(lyxrc.document_path)); _("Documents|#o#O"), from_utf8(lyxrc.document_path));
@ -336,7 +336,7 @@ void GuiInclude::edit(string const & file)
else else
// tex file or other text file in verbatim mode // tex file or other text file in verbatim mode
formats.edit(buffer(), formats.edit(buffer(),
makeAbsPath(file, onlyPath(buffer().absFileName())), makeAbsPath(file, support::onlyPath(buffer().absFileName())),
"text"); "text");
} }

View File

@ -20,6 +20,7 @@
#include "BufferList.h" #include "BufferList.h"
#include "Color.h" #include "Color.h"
#include "ConverterCache.h" #include "ConverterCache.h"
#include "FileDialog.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "GuiFontExample.h" #include "GuiFontExample.h"
#include "GuiKeySymbol.h" #include "GuiKeySymbol.h"
@ -70,6 +71,154 @@ using namespace lyx::support::os;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
/////////////////////////////////////////////////////////////////////
//
// Browser Helpers
//
/////////////////////////////////////////////////////////////////////
FileName libFileSearch(QString const & dir, QString const & name,
QString const & ext = QString())
{
return support::libFileSearch(fromqstr(dir), fromqstr(name), fromqstr(ext));
}
/** Launch a file dialog and return the chosen file.
filename: a suggested filename.
title: the title of the dialog.
pattern: *.ps etc.
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
*/
QString browseFile(QString const & filename,
QString const & title,
support::FileFilterList const & filters,
bool save = false,
QString const & label1 = QString(),
QString const & dir1 = QString(),
QString const & label2 = QString(),
QString const & dir2 = QString())
{
QString lastPath = ".";
if (!filename.isEmpty())
lastPath = onlyPath(filename);
FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
dlg.setButton2(label1, dir1);
dlg.setButton2(label2, dir2);
FileDialog::Result result;
if (save)
result = dlg.save(lastPath, filters, onlyFilename(filename));
else
result = dlg.open(lastPath, filters, onlyFilename(filename));
return result.second;
}
/** Wrapper around browseFile which tries to provide a filename
* relative to the user or system directory. The dir, name and ext
* parameters have the same meaning as in the
* support::LibFileSearch function.
*/
QString browseLibFile(QString const & dir,
QString const & name,
QString const & ext,
QString const & title,
support::FileFilterList const & filters)
{
// FIXME UNICODE
QString const label1 = qt_("System files|#S#s");
QString const dir1 =
toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
QString const label2 = qt_("User files|#U#u");
QString const dir2 =
toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
QString const result = browseFile(toqstr(
libFileSearch(dir, name, ext).absFilename()),
title, filters, false, dir1, dir2);
// remove the extension if it is the default one
QString noextresult;
if (toqstr(getExtension(fromqstr(result))) == ext)
noextresult = toqstr(removeExtension(fromqstr(result)));
else
noextresult = result;
// remove the directory, if it is the default one
QString const file = onlyFilename(noextresult);
if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
return file;
else
return noextresult;
}
/** Launch a file dialog and return the chosen directory.
pathname: a suggested pathname.
title: the title of the dialog.
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
*/
QString browseDir(QString const & pathname,
QString const & title,
QString const & label1 = QString(),
QString const & dir1 = QString(),
QString const & label2 = QString(),
QString const & dir2 = QString())
{
QString lastPath = ".";
if (!pathname.isEmpty())
lastPath = onlyPath(pathname);
FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
dlg.setButton1(label1, dir1);
dlg.setButton2(label2, dir2);
FileDialog::Result const result =
dlg.opendir(lastPath, onlyFilename(pathname));
return result.second;
}
QString browseRelFile(QString const & filename, QString const & refpath,
QString const & title, FileFilterList const & filters, bool save,
QString const & label1, QString const & dir1,
QString const & label2, QString const & dir2)
{
QString const fname = toqstr(makeAbsPath(
fromqstr(filename), fromqstr(refpath)).absFilename());
QString const outname =
browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
QString const reloutname =
toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
if (reloutname.startsWith("../"))
return outname;
else
return reloutname;
}
} // namespace frontend
docstring browseRelFile(docstring const & filename, docstring const & refpath,
docstring const & title, FileFilterList const & filters, bool save,
docstring const & label1, docstring const & dir1,
docstring const & label2, docstring const & dir2)
{
return qstring_to_ucs4(frontend::browseRelFile(
toqstr(filename), toqstr(refpath),
toqstr(title), filters, save,
toqstr(label1), toqstr(dir1),
toqstr(label2), toqstr(dir2)));
}
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// //
@ -77,6 +226,8 @@ namespace frontend {
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
namespace frontend {
template<class A> template<class A>
static size_t findPos_helper(vector<A> const & vec, A const & val) static size_t findPos_helper(vector<A> const & vec, A const & val)
{ {
@ -111,7 +262,7 @@ static void setComboxFont(QComboBox * cb, string const & family,
if (!foundry.empty()) if (!foundry.empty())
fontname += " [" + toqstr(foundry) + ']'; fontname += " [" + toqstr(foundry) + ']';
for (int i = 0; i < cb->count(); ++i) { for (int i = 0; i != cb->count(); ++i) {
if (cb->itemText(i) == fontname) { if (cb->itemText(i) == fontname) {
cb->setCurrentIndex(i); cb->setCurrentIndex(i);
return; return;
@ -192,7 +343,7 @@ static void setComboxFont(QComboBox * cb, string const & family,
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefPlaintext::PrefPlaintext(QWidget * parent) PrefPlaintext::PrefPlaintext(QWidget * parent)
: PrefModule(_("Plain text"), 0, parent) : PrefModule(qt_("Plain text"), 0, parent)
{ {
setupUi(this); setupUi(this);
connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)), connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
@ -223,7 +374,7 @@ void PrefPlaintext::update(LyXRC const & rc)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefDate::PrefDate(QWidget * parent) PrefDate::PrefDate(QWidget * parent)
: PrefModule(_("Date format"), 0, parent) : PrefModule(qt_("Date format"), 0, parent)
{ {
setupUi(this); setupUi(this);
connect(DateED, SIGNAL(textChanged(QString)), connect(DateED, SIGNAL(textChanged(QString)),
@ -250,7 +401,7 @@ void PrefDate::update(LyXRC const & rc)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefInput::PrefInput(GuiPreferences * form, QWidget * parent) PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Keyboard/Mouse"), form, parent) : PrefModule(qt_("Keyboard/Mouse"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -320,7 +471,7 @@ void PrefInput::update(LyXRC const & rc)
QString PrefInput::testKeymap(QString keymap) QString PrefInput::testKeymap(QString keymap)
{ {
return toqstr(form_->browsekbmap(from_utf8(internal_path(fromqstr(keymap))))); return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
} }
@ -358,7 +509,7 @@ void PrefInput::on_keymapCB_toggled(bool keymap)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent) PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
: PrefModule(_("LaTeX"), form, parent) : PrefModule(qt_("LaTeX"), form, parent)
{ {
setupUi(this); setupUi(this);
connect(latexEncodingED, SIGNAL(textChanged(QString)), connect(latexEncodingED, SIGNAL(textChanged(QString)),
@ -425,7 +576,7 @@ void PrefLatex::update(LyXRC const & rc)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent) PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Screen fonts"), form, parent) : PrefModule(qt_("Screen fonts"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -599,7 +750,7 @@ struct ColorSorter
} // namespace anon } // namespace anon
PrefColors::PrefColors(GuiPreferences * form, QWidget * parent) PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
: PrefModule( _("Colors"), form, parent) : PrefModule(qt_("Colors"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -697,7 +848,7 @@ void PrefColors::change_lyxObjects_selection()
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefDisplay::PrefDisplay(QWidget * parent) PrefDisplay::PrefDisplay(QWidget * parent)
: PrefModule(_("Graphics"), 0, parent) : PrefModule(qt_("Graphics"), 0, parent)
{ {
setupUi(this); setupUi(this);
connect(instantPreviewCO, SIGNAL(activated(int)), connect(instantPreviewCO, SIGNAL(activated(int)),
@ -768,7 +919,7 @@ void PrefDisplay::update(LyXRC const & rc)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent) PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Paths"), form, parent) : PrefModule(qt_("Paths"), form, parent)
{ {
setupUi(this); setupUi(this);
connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir())); connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
@ -822,61 +973,55 @@ void PrefPaths::update(LyXRC const & rc)
void PrefPaths::select_exampledir() void PrefPaths::select_exampledir()
{ {
docstring file(form_->browsedir( QString file = form_->browsedir(internalPath(exampleDirED->text()),
from_utf8(internal_path(fromqstr(exampleDirED->text()))), qt_("Select directory for example files"));
_("Select directory for example files"))); if (!file.isEmpty())
if (!file.empty()) exampleDirED->setText(file);
exampleDirED->setText(toqstr(file));
} }
void PrefPaths::select_templatedir() void PrefPaths::select_templatedir()
{ {
docstring file(form_->browsedir( QString file = form_->browsedir(internalPath(templateDirED->text()),
from_utf8(internal_path(fromqstr(templateDirED->text()))), qt_("Select a document templates directory"));
_("Select a document templates directory"))); if (!file.isEmpty())
if (!file.empty()) templateDirED->setText(file);
templateDirED->setText(toqstr(file));
} }
void PrefPaths::select_tempdir() void PrefPaths::select_tempdir()
{ {
docstring file(form_->browsedir( QString file = form_->browsedir(internalPath(tempDirED->text()),
from_utf8(internal_path(fromqstr(tempDirED->text()))), qt_("Select a temporary directory"));
_("Select a temporary directory"))); if (!file.isEmpty())
if (!file.empty()) tempDirED->setText(file);
tempDirED->setText(toqstr(file));
} }
void PrefPaths::select_backupdir() void PrefPaths::select_backupdir()
{ {
docstring file(form_->browsedir( QString file = form_->browsedir(internalPath(backupDirED->text()),
from_utf8(internal_path(fromqstr(backupDirED->text()))), qt_("Select a backups directory"));
_("Select a backups directory"))); if (!file.isEmpty())
if (!file.empty()) backupDirED->setText(file);
backupDirED->setText(toqstr(file));
} }
void PrefPaths::select_workingdir() void PrefPaths::select_workingdir()
{ {
docstring file(form_->browsedir( QString file = form_->browsedir(internalPath(workingDirED->text()),
from_utf8(internal_path(fromqstr(workingDirED->text()))), qt_("Select a document directory"));
_("Select a document directory"))); if (!file.isEmpty())
if (!file.empty()) workingDirED->setText(file);
workingDirED->setText(toqstr(file));
} }
void PrefPaths::select_lyxpipe() void PrefPaths::select_lyxpipe()
{ {
docstring file(form_->browse( QString file = form_->browse(internalPath(lyxserverDirED->text()),
from_utf8(internal_path(fromqstr(lyxserverDirED->text()))), qt_("Give a filename for the LyX server pipe"));
_("Give a filename for the LyX server pipe"))); if (!file.isEmpty())
if (!file.empty()) lyxserverDirED->setText(file);
lyxserverDirED->setText(toqstr(file));
} }
@ -887,7 +1032,7 @@ void PrefPaths::select_lyxpipe()
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent) PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Spellchecker"), form, parent) : PrefModule(qt_("Spellchecker"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -981,10 +1126,9 @@ void PrefSpellchecker::update(LyXRC const & rc)
void PrefSpellchecker::select_dict() void PrefSpellchecker::select_dict()
{ {
docstring file(form_->browsedict( QString file = form_->browsedict(internalPath(persDictionaryED->text()));
from_utf8(internal_path(fromqstr(persDictionaryED->text()))))); if (!file.isEmpty())
if (!file.empty()) persDictionaryED->setText(file);
persDictionaryED->setText(toqstr(file));
} }
@ -997,7 +1141,7 @@ void PrefSpellchecker::select_dict()
PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent) PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Converters"), form, parent) : PrefModule(qt_("Converters"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -1267,7 +1411,7 @@ string FormatPrettynameValidator::str(Formats::const_iterator it) const
PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent) PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
: PrefModule(_("File formats"), form, parent) : PrefModule(qt_("File formats"), form, parent)
{ {
setupUi(this); setupUi(this);
formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats())); formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
@ -1466,7 +1610,7 @@ void PrefFileformats::on_formatRemovePB_clicked()
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefLanguage::PrefLanguage(QWidget * parent) PrefLanguage::PrefLanguage(QWidget * parent)
: PrefModule(_("Language"), 0, parent) : PrefModule(qt_("Language"), 0, parent)
{ {
setupUi(this); setupUi(this);
@ -1555,7 +1699,7 @@ void PrefLanguage::update(LyXRC const & rc)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefPrinter::PrefPrinter(QWidget * parent) PrefPrinter::PrefPrinter(QWidget * parent)
: PrefModule(_("Printer"), 0, parent) : PrefModule(qt_("Printer"), 0, parent)
{ {
setupUi(this); setupUi(this);
@ -1653,7 +1797,7 @@ void PrefPrinter::update(LyXRC const & rc)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent) PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
: PrefModule(_("User interface"), form, parent) : PrefModule(qt_("User interface"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -1752,11 +1896,9 @@ void PrefUserInterface::update(LyXRC const & rc)
void PrefUserInterface::select_ui() void PrefUserInterface::select_ui()
{ {
docstring const name = QString file = form_->browseUI(internalPath(uiFileED->text()));
from_utf8(internal_path(fromqstr(uiFileED->text()))); if (!file.isEmpty())
docstring file = form_->browseUI(name); uiFileED->setText(file);
if (!file.empty())
uiFileED->setText(toqstr(file));
} }
@ -1775,7 +1917,7 @@ GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent) PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
: PrefModule(_("Shortcuts"), form, parent) : PrefModule(qt_("Shortcuts"), form, parent)
{ {
setupUi(this); setupUi(this);
@ -2018,13 +2160,11 @@ void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
void PrefShortcuts::select_bind() void PrefShortcuts::select_bind()
{ {
docstring const name = QString file = form_->browsebind(internalPath(bindFileED->text()));
from_utf8(internal_path(fromqstr(bindFileED->text()))); if (!file.isEmpty()) {
docstring file = form_->browsebind(name); bindFileED->setText(file);
if (!file.empty()) {
bindFileED->setText(toqstr(file));
system_bind_ = KeyMap(); system_bind_ = KeyMap();
system_bind_.read(to_utf8(file)); system_bind_.read(fromqstr(file));
updateShortcutsTW(); updateShortcutsTW();
} }
} }
@ -2170,7 +2310,7 @@ void PrefShortcuts::shortcut_clearPB_pressed()
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
PrefIdentity::PrefIdentity(QWidget * parent) PrefIdentity::PrefIdentity(QWidget * parent)
: PrefModule(_("Identity"), 0, parent) : PrefModule(qt_("Identity"), 0, parent)
{ {
setupUi(this); setupUi(this);
@ -2258,7 +2398,7 @@ GuiPreferences::GuiPreferences(GuiView & lv)
void GuiPreferences::add(PrefModule * module) void GuiPreferences::add(PrefModule * module)
{ {
BOOST_ASSERT(module); BOOST_ASSERT(module);
prefsPS->addPanel(module, toqstr(module->title())); prefsPS->addPanel(module, module->title());
connect(module, SIGNAL(changed()), this, SLOT(change_adaptor())); connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
modules_.push_back(module); modules_.push_back(module);
} }
@ -2358,52 +2498,43 @@ void GuiPreferences::updateScreenFonts()
} }
docstring const GuiPreferences::browsebind(docstring const & file) const QString GuiPreferences::browsebind(QString const & file) const
{ {
return browseLibFile(from_ascii("bind"), file, from_ascii("bind"), return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
_("Choose bind file"),
FileFilterList(_("LyX bind files (*.bind)"))); FileFilterList(_("LyX bind files (*.bind)")));
} }
docstring const GuiPreferences::browseUI(docstring const & file) const QString GuiPreferences::browseUI(QString const & file) const
{ {
return browseLibFile(from_ascii("ui"), file, from_ascii("ui"), return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
_("Choose UI file"),
FileFilterList(_("LyX UI files (*.ui)"))); FileFilterList(_("LyX UI files (*.ui)")));
} }
docstring const GuiPreferences::browsekbmap(docstring const & file) const QString GuiPreferences::browsekbmap(QString const & file) const
{ {
return browseLibFile(from_ascii("kbd"), file, from_ascii("kmap"), return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
_("Choose keyboard map"),
FileFilterList(_("LyX keyboard maps (*.kmap)"))); FileFilterList(_("LyX keyboard maps (*.kmap)")));
} }
docstring const GuiPreferences::browsedict(docstring const & file) const QString GuiPreferences::browsedict(QString const & file) const
{ {
if (lyxrc.use_spell_lib) return browseFile(file, qt_("Choose personal dictionary"),
return browseFile(file, FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
_("Choose personal dictionary"),
FileFilterList(_("*.pws")));
else
return browseFile(file,
_("Choose personal dictionary"),
FileFilterList(_("*.ispell")));
} }
docstring const GuiPreferences::browse(docstring const & file, QString GuiPreferences::browse(QString const & file,
docstring const & title) const QString const & title) const
{ {
return browseFile(file, title, FileFilterList(), true); return browseFile(file, title, FileFilterList(), true);
} }
docstring const GuiPreferences::browsedir(docstring const & path, QString GuiPreferences::browsedir(QString const & path,
docstring const & title) const QString const & title) const
{ {
return browseDir(path, title); return browseDir(path, title);
} }

View File

@ -65,7 +65,7 @@ class PrefModule : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
PrefModule(docstring const & t, PrefModule(QString const & t,
GuiPreferences * form = 0, QWidget * parent = 0) GuiPreferences * form = 0, QWidget * parent = 0)
: QWidget(parent), title_(t), form_(form) : QWidget(parent), title_(t), form_(form)
{} {}
@ -73,10 +73,10 @@ public:
virtual void apply(LyXRC & rc) const = 0; virtual void apply(LyXRC & rc) const = 0;
virtual void update(LyXRC const & rc) = 0; virtual void update(LyXRC const & rc) = 0;
docstring const & title() const { return title_; } QString const & title() const { return title_; }
protected: protected:
docstring title_; QString title_;
GuiPreferences * form_; GuiPreferences * form_;
Q_SIGNALS: Q_SIGNALS:
@ -455,18 +455,16 @@ public:
bool isBufferDependent() const { return false; } bool isBufferDependent() const { return false; }
/// various file pickers /// various file pickers
docstring const browsebind(docstring const & file) const; QString browsebind(QString const & file) const;
docstring const browseUI(docstring const & file) const; QString browseUI(QString const & file) const;
docstring const browsekbmap(docstring const & file) const; QString browsekbmap(QString const & file) const;
docstring const browsedict(docstring const & file) const; QString browsedict(QString const & file) const;
/// general browse /// general browse
docstring const browse(docstring const & file, QString browse(QString const & file, QString const & title) const;
docstring const & title) const;
/// browse directory /// browse directory
docstring const browsedir(docstring const & path, QString browsedir(QString const & path, QString const & title) const;
docstring const & title) const;
/// set a color /// set a color
void setColor(ColorCode col, std::string const & hex); void setColor(ColorCode col, std::string const & hex);

View File

@ -40,7 +40,7 @@ GuiShowFile::GuiShowFile(GuiView & lv)
void GuiShowFile::updateContents() void GuiShowFile::updateContents()
{ {
setWindowTitle(toqstr(onlyFilename(filename_.absFilename()))); setWindowTitle(onlyFilename(toqstr(filename_.absFilename())));
QString contents = toqstr(filename_.fileContents("UTF-8")); QString contents = toqstr(filename_.fileContents("UTF-8"));
if (contents.isEmpty()) if (contents.isEmpty())

View File

@ -65,7 +65,7 @@ static string texFileFromList(string const & file, string const & type)
string classfile = token(allClasses, '\n', entries); string classfile = token(allClasses, '\n', entries);
int count = 0; int count = 0;
while ((!contains(classfile, file) || while ((!contains(classfile, file) ||
(onlyFilename(classfile) != file)) && (support::onlyFilename(classfile) != file)) &&
(++count < 1000)) { (++count < 1000)) {
classfile = token(allClasses, '\n', ++entries); classfile = token(allClasses, '\n', ++entries);
} }
@ -167,7 +167,7 @@ void GuiTexInfo::updateStyles(TexFileType type)
vector<string>::iterator it1 = data.begin(); vector<string>::iterator it1 = data.begin();
vector<string>::iterator end1 = data.end(); vector<string>::iterator end1 = data.end();
for (; it1 != end1; ++it1) for (; it1 != end1; ++it1)
*it1 = onlyFilename(*it1); *it1 = support::onlyFilename(*it1);
// sort on filename only (no path) // sort on filename only (no path)
sort(data.begin(), data.end()); sort(data.begin(), data.end());

View File

@ -1080,20 +1080,19 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
static FileName selectTemplateFile() static FileName selectTemplateFile()
{ {
FileDialog dlg(_("Select template file")); FileDialog dlg(qt_("Select template file"));
dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path)); dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
dlg.setButton1(_("Templates|#T#t"), from_utf8(lyxrc.template_path)); dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
FileDialog::Result result = FileDialog::Result result =
dlg.open(from_utf8(lyxrc.template_path), dlg.open(toqstr(lyxrc.template_path),
FileFilterList(_("LyX Documents (*.lyx)")), FileFilterList(_("LyX Documents (*.lyx)")));
docstring());
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return FileName(); return FileName();
if (result.second.empty()) if (result.second.isEmpty())
return FileName(); return FileName();
return FileName(to_utf8(result.second)); return FileName(fromqstr(result.second));
} }
@ -1140,20 +1139,18 @@ void GuiView::openDocument(string const & fname)
string filename; string filename;
if (fname.empty()) { if (fname.empty()) {
FileDialog dlg(_("Select document to open"), LFUN_FILE_OPEN); FileDialog dlg(qt_("Select document to open"), LFUN_FILE_OPEN);
dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path)); dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
dlg.setButton2(_("Examples|#E#e"), dlg.setButton2(qt_("Examples|#E#e"),
from_utf8(addPath(package().system_support().absFilename(), "examples"))); toqstr(addPath(package().system_support().absFilename(), "examples")));
FileDialog::Result result = FileDialog::Result result =
dlg.open(from_utf8(initpath), dlg.open(toqstr(initpath), FileFilterList(_("LyX Documents (*.lyx)")));
FileFilterList(_("LyX Documents (*.lyx)")),
docstring());
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return; return;
filename = to_utf8(result.second); filename = fromqstr(result.second);
// check selected filename // check selected filename
if (filename.empty()) { if (filename.empty()) {
@ -1274,10 +1271,10 @@ void GuiView::importDocument(string const & argument)
docstring const text = bformat(_("Select %1$s file to import"), docstring const text = bformat(_("Select %1$s file to import"),
formats.prettyName(format)); formats.prettyName(format));
FileDialog dlg(text, LFUN_BUFFER_IMPORT); FileDialog dlg(toqstr(text), LFUN_BUFFER_IMPORT);
dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path)); dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
dlg.setButton2(_("Examples|#E#e"), dlg.setButton2(qt_("Examples|#E#e"),
from_utf8(addPath(package().system_support().absFilename(), "examples"))); toqstr(addPath(package().system_support().absFilename(), "examples")));
docstring filter = formats.prettyName(format); docstring filter = formats.prettyName(format);
filter += " (*."; filter += " (*.";
@ -1286,14 +1283,12 @@ void GuiView::importDocument(string const & argument)
filter += ')'; filter += ')';
FileDialog::Result result = FileDialog::Result result =
dlg.open(from_utf8(initpath), dlg.open(toqstr(initpath), FileFilterList(filter));
FileFilterList(filter),
docstring());
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return; return;
filename = to_utf8(result.second); filename = fromqstr(result.second);
// check selected filename // check selected filename
if (filename.empty()) if (filename.empty())
@ -1395,22 +1390,21 @@ void GuiView::insertLyXFile(docstring const & fname)
initpath = trypath; initpath = trypath;
// FIXME UNICODE // FIXME UNICODE
FileDialog dlg(_("Select LyX document to insert"), LFUN_FILE_INSERT); FileDialog dlg(qt_("Select LyX document to insert"), LFUN_FILE_INSERT);
dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path)); dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
dlg.setButton2(_("Examples|#E#e"), dlg.setButton2(qt_("Examples|#E#e"),
from_utf8(addPath(package().system_support().absFilename(), toqstr(addPath(package().system_support().absFilename(),
"examples"))); "examples")));
FileDialog::Result result = FileDialog::Result result =
dlg.open(from_utf8(initpath), dlg.open(toqstr(initpath),
FileFilterList(_("LyX Documents (*.lyx)")), FileFilterList(_("LyX Documents (*.lyx)")));
docstring());
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return; return;
// FIXME UNICODE // FIXME UNICODE
filename.set(to_utf8(result.second)); filename.set(fromqstr(result.second));
// check selected filename // check selected filename
if (filename.empty()) { if (filename.empty()) {
@ -1438,17 +1432,17 @@ void GuiView::insertPlaintextFile(docstring const & fname,
return; return;
} }
FileDialog dlg(_("Select file to insert"), (asParagraph ? FileDialog dlg(qt_("Select file to insert"), (asParagraph ?
LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT)); LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
FileDialog::Result result = dlg.open(from_utf8(bv->buffer().filePath()), FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
FileFilterList(), docstring()); FileFilterList());
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return; return;
// FIXME UNICODE // FIXME UNICODE
filename.set(to_utf8(result.second)); filename.set(fromqstr(result.second));
// check selected filename // check selected filename
if (filename.empty()) { if (filename.empty()) {
@ -1475,10 +1469,10 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
/// No argument? Ask user through dialog. /// No argument? Ask user through dialog.
// FIXME UNICODE // FIXME UNICODE
FileDialog dlg(_("Choose a filename to save document as"), FileDialog dlg(qt_("Choose a filename to save document as"),
LFUN_BUFFER_WRITE_AS); LFUN_BUFFER_WRITE_AS);
dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path)); dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
dlg.setButton2(_("Templates|#T#t"), from_utf8(lyxrc.template_path)); dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
if (!isLyXFilename(fname.absFilename())) if (!isLyXFilename(fname.absFilename()))
fname.changeExtension(".lyx"); fname.changeExtension(".lyx");
@ -1486,14 +1480,14 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
FileFilterList const filter(_("LyX Documents (*.lyx)")); FileFilterList const filter(_("LyX Documents (*.lyx)"));
FileDialog::Result result = FileDialog::Result result =
dlg.save(from_utf8(fname.onlyPath().absFilename()), dlg.save(toqstr(fname.onlyPath().absFilename()),
filter, filter,
from_utf8(fname.onlyFileName())); toqstr(fname.onlyFileName()));
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return false; return false;
fname.set(to_utf8(result.second)); fname.set(fromqstr(result.second));
if (fname.empty()) if (fname.empty())
return false; return false;

View File

@ -27,54 +27,52 @@ using namespace lyx::support;
namespace lyx { namespace lyx {
/// return the Qt form of the label /// return the Qt form of the label
static docstring const getLabel(docstring const & ucs4str) static QString getLabel(QString const & qstr)
{ {
// FIXME UNICODE // FIXME UNICODE (or "qt-ify")
string str = to_utf8(ucs4str); string str = fromqstr(qstr);
string label; string label;
string sc = split(str, label, '|'); string sc = split(str, label, '|');
if (sc.length() < 2) if (sc.length() < 2)
return from_utf8(label); return toqstr(label);
size_t pos = label.find(sc[1]); size_t pos = label.find(sc[1]);
if (pos != string::npos) if (pos != string::npos)
label.insert(pos, 1, '&'); label.insert(pos, 1, '&');
return from_utf8(label); return toqstr(label);
} }
LyXFileDialog::LyXFileDialog(docstring const & t, LyXFileDialog::LyXFileDialog(QString const & title,
docstring const & p, QString const & path,
support::FileFilterList const & filters, support::FileFilterList const & filters,
FileDialog::Button const & b1, FileDialog::Button const & b1,
FileDialog::Button const & b2) FileDialog::Button const & b2)
// FIXME replace that with guiApp->currentView() // FIXME replace that with guiApp->currentView()
: QFileDialog(qApp->focusWidget(), : QFileDialog(qApp->focusWidget(), title, path, toqstr(filters.as_string()))
toqstr(t), toqstr(p), toqstr(filters.as_string()))
{ {
QString const path = toqstr(p);
QDir dir(path); QDir dir(path);
// FIXME: workaround for a bug in qt which makes LyX crash // FIXME: workaround for a bug in qt which makes LyX crash
// with hidden paths (bug 4513). Recheck with recent Qt versions. // with hidden paths (bug 4513). Recheck with recent Qt versions.
if (path.contains("/.")) if (path.contains("/."))
dir.setFilter(QDir::Hidden); dir.setFilter(QDir::Hidden);
setDirectory(dir); setDirectory(dir);
setWindowTitle(toqstr(t)); setWindowTitle(title);
QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>(); QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
if (!b1.first.empty()) { if (!b1.first.isEmpty()) {
b1_dir_ = b1.second; b1_dir_ = b1.second;
QToolButton * tb = new QToolButton(this); QToolButton * tb = new QToolButton(this);
connect(tb, SIGNAL(clicked()), this, SLOT(button1Clicked())); connect(tb, SIGNAL(clicked()), this, SLOT(button1Clicked()));
tb->setText(toqstr(getLabel(b1.first))); tb->setText(getLabel(b1.first));
layout.at(0)->addWidget(tb); layout.at(0)->addWidget(tb);
} }
if (!b2.first.empty()) { if (!b2.first.isEmpty()) {
b2_dir_ = b2.second; b2_dir_ = b2.second;
QToolButton * tb = new QToolButton(this); QToolButton * tb = new QToolButton(this);
connect(tb, SIGNAL(clicked()), this, SLOT(button2Clicked())); connect(tb, SIGNAL(clicked()), this, SLOT(button2Clicked()));
tb->setText(toqstr(getLabel(b2.first))); tb->setText(getLabel(b2.first));
layout.at(0)->addWidget(tb); layout.at(0)->addWidget(tb);
} }
} }
@ -82,13 +80,13 @@ LyXFileDialog::LyXFileDialog(docstring const & t,
void LyXFileDialog::button1Clicked() void LyXFileDialog::button1Clicked()
{ {
setDirectory(toqstr(b1_dir_)); setDirectory(b1_dir_);
} }
void LyXFileDialog::button2Clicked() void LyXFileDialog::button2Clicked()
{ {
setDirectory(toqstr(b2_dir_)); setDirectory(b2_dir_);
} }
} // namespace lyx } // namespace lyx

View File

@ -27,8 +27,8 @@ class LyXFileDialog : public QFileDialog
Q_OBJECT Q_OBJECT
public: public:
LyXFileDialog(docstring const & title, LyXFileDialog(QString const & title,
docstring const & path, QString const & path,
support::FileFilterList const & filters, support::FileFilterList const & filters,
FileDialog::Button const & b1, FileDialog::Button const & b1,
FileDialog::Button const & b2); FileDialog::Button const & b2);
@ -38,8 +38,8 @@ public Q_SLOTS:
void button2Clicked(); void button2Clicked();
private: private:
docstring b1_dir_; QString b1_dir_;
docstring b2_dir_; QString b2_dir_;
}; };
} // namespace lyx } // namespace lyx

View File

@ -206,103 +206,6 @@ vector<LanguagePair> const getLanguageData(bool character_dlg)
return langs; return langs;
} }
docstring browseFile(docstring const & filename, docstring const & title,
FileFilterList const & filters, bool save,
docstring const & label1, docstring const & dir1,
docstring const & label2, docstring const & dir2)
{
docstring lastPath = from_ascii(".");
if (!filename.empty())
lastPath = from_utf8(onlyPath(to_utf8(filename)));
FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
dlg.setButton1(label1, dir1);
dlg.setButton2(label2, dir2);
FileDialog::Result result;
if (save)
result = dlg.save(lastPath, filters,
from_utf8(onlyFilename(to_utf8(filename))));
else
result = dlg.open(lastPath, filters,
from_utf8(onlyFilename(to_utf8(filename))));
return result.second;
}
docstring browseRelFile(docstring const & filename, docstring const & refpath,
docstring const & title, FileFilterList const & filters, bool save,
docstring const & label1, docstring const & dir1,
docstring const & label2, docstring const & dir2)
{
docstring const fname = from_utf8(makeAbsPath(
to_utf8(filename), to_utf8(refpath)).absFilename());
docstring const outname = browseFile(fname, title, filters, save,
label1, dir1, label2, dir2);
docstring const reloutname = makeRelPath(outname, refpath);
if (prefixIs(reloutname, from_ascii("../")))
return outname;
else
return reloutname;
}
docstring browseLibFile(docstring const & dir, docstring const & name,
docstring const & ext, docstring const & title,
FileFilterList const & filters)
{
// FIXME UNICODE
docstring const label1 = _("System files|#S#s");
docstring const dir1 =
from_utf8(addName(package().system_support().absFilename(), to_utf8(dir)));
docstring const label2 = _("User files|#U#u");
docstring const dir2 =
from_utf8(addName(package().user_support().absFilename(), to_utf8(dir)));
docstring const result = browseFile(from_utf8(
libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()),
title, filters, false, dir1, dir2);
// remove the extension if it is the default one
docstring noextresult;
if (from_utf8(getExtension(to_utf8(result))) == ext)
noextresult = from_utf8(removeExtension(to_utf8(result)));
else
noextresult = result;
// remove the directory, if it is the default one
docstring const file = from_utf8(onlyFilename(to_utf8(noextresult)));
if (from_utf8(libFileSearch(to_utf8(dir), to_utf8(file), to_utf8(ext)).absFilename()) == result)
return file;
else
return noextresult;
}
docstring browseDir(docstring const & pathname, docstring const & title,
docstring const & label1, docstring const & dir1,
docstring const & label2, docstring const & dir2)
{
docstring lastPath = from_ascii(".");
if (!pathname.empty())
lastPath = from_utf8(onlyPath(to_utf8(pathname)));
FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
dlg.setButton1(label1, dir1);
dlg.setButton2(label2, dir2);
FileDialog::Result const result =
dlg.opendir(lastPath, from_utf8(onlyFilename(to_utf8(pathname))));
return result.second;
}
void rescanTexStyles() void rescanTexStyles()
{ {
// Run rescan in user lyx directory // Run rescan in user lyx directory
@ -343,4 +246,22 @@ void getTexFileList(string const & filename, vector<string> & list)
eliminate_duplicates(list); eliminate_duplicates(list);
} }
QString internalPath(const QString & str)
{
return toqstr(os::internal_path(fromqstr(str)));
}
QString onlyFilename(const QString & str)
{
return toqstr(support::onlyFilename(fromqstr(str)));
}
QString onlyPath(const QString & str)
{
return toqstr(support::onlyPath(fromqstr(str)));
}
} // namespace lyx } // namespace lyx

View File

@ -78,22 +78,6 @@ typedef std::pair<docstring, std::string> LanguagePair;
*/ */
std::vector<LanguagePair> const getLanguageData(bool character_dlg); std::vector<LanguagePair> const getLanguageData(bool character_dlg);
/** Launch a file dialog and return the chosen file.
filename: a suggested filename.
title: the title of the dialog.
pattern: *.ps etc.
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
*/
docstring browseFile(docstring const & filename,
docstring const & title,
support::FileFilterList const & filters,
bool save = false,
docstring const & label1 = docstring(),
docstring const & dir1 = docstring(),
docstring const & label2 = docstring(),
docstring const & dir2 = docstring());
/** Wrapper around browseFile which tries to provide a filename /** Wrapper around browseFile which tries to provide a filename
relative to relpath. If the relative path is of the form "foo.txt" relative to relpath. If the relative path is of the form "foo.txt"
or "bar/foo.txt", then it is returned as relative. OTOH, if it is or "bar/foo.txt", then it is returned as relative. OTOH, if it is
@ -111,31 +95,6 @@ docstring browseRelFile(docstring const & filename,
docstring const & dir2 = docstring()); docstring const & dir2 = docstring());
/** Wrapper around browseFile which tries to provide a filename
* relative to the user or system directory. The dir, name and ext
* parameters have the same meaning as in the
* support::LibFileSearch function.
*/
docstring browseLibFile(docstring const & dir,
docstring const & name,
docstring const & ext,
docstring const & title,
support::FileFilterList const & filters);
/** Launch a file dialog and return the chosen directory.
pathname: a suggested pathname.
title: the title of the dialog.
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
*/
docstring browseDir(docstring const & pathname,
docstring const & title,
docstring const & label1 = docstring(),
docstring const & dir1 = docstring(),
docstring const & label2 = docstring(),
docstring const & dir2 = docstring());
/** Build filelists of all availabe bst/cls/sty-files. Done through /** Build filelists of all availabe bst/cls/sty-files. Done through
* kpsewhich and an external script, saved in *Files.lst. * kpsewhich and an external script, saved in *Files.lst.
*/ */
@ -146,6 +105,11 @@ void rescanTexStyles();
*/ */
void getTexFileList(std::string const & filename, std::vector<std::string> & contents); void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
// wrapper around the docstring versions
QString internalPath(const QString &);
QString onlyFilename(const QString & str);
QString onlyPath(const QString & str);
} // namespace lyx } // namespace lyx
#endif // QTHELPERS_H #endif // QTHELPERS_H