2002-03-01 18:47:56 +00:00
|
|
|
/**
|
2002-03-11 22:47:41 +00:00
|
|
|
* \file qt2/Alert_pimpl.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-01 18:47:56 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-03-01 18:47:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <qmessagebox.h>
|
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include "ui/QAskForTextDialog.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-12-18 23:26:21 +00:00
|
|
|
#include "gettext.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-03-01 18:47:56 +00:00
|
|
|
#include <algorithm>
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-03-01 18:47:56 +00:00
|
|
|
#include "Alert.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
#include "Alert_pimpl.h"
|
|
|
|
|
2003-03-30 20:25:44 +00:00
|
|
|
#include "support/BoostFormat.h"
|
2002-12-18 14:24:32 +00:00
|
|
|
#include "gettext.h"
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-03-01 18:47:56 +00:00
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
|
|
|
|
2003-03-29 07:09:13 +00:00
|
|
|
int prompt_pimpl(string const & tit, string const & question,
|
2003-04-27 16:40:50 +00:00
|
|
|
int default_button, int cancel_button,
|
2003-03-29 07:09:13 +00:00
|
|
|
string const & b1, string const & b2, string const & b3)
|
2002-03-01 18:47:56 +00:00
|
|
|
{
|
2003-03-29 07:09:13 +00:00
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
boost::format fmt(_("LyX: %1$s"));
|
|
|
|
fmt % tit;
|
|
|
|
string const title = fmt.str();
|
|
|
|
#else
|
|
|
|
string const title = _("LyX: ") + tit;
|
|
|
|
#endif
|
2002-03-01 18:47:56 +00:00
|
|
|
|
2003-04-27 16:40:50 +00:00
|
|
|
int res = QMessageBox::information(0, toqstr(title), toqstr(formatted(question)),
|
2003-03-29 07:09:13 +00:00
|
|
|
toqstr(b1), toqstr(b2), b3.empty() ? QString::null : toqstr(b3),
|
2003-04-27 16:40:50 +00:00
|
|
|
default_button, cancel_button);
|
|
|
|
|
|
|
|
// Qt bug: can return -1 on cancel or WM close, despite the docs.
|
|
|
|
if (res == -1)
|
|
|
|
res = cancel_button;
|
|
|
|
return res;
|
2002-03-01 18:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-29 09:02:08 +00:00
|
|
|
void warning_pimpl(string const & tit, string const & message)
|
|
|
|
{
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
boost::format fmt(_("LyX: %1$s"));
|
|
|
|
fmt % tit;
|
|
|
|
string const title = fmt.str();
|
|
|
|
#else
|
|
|
|
string const title = _("LyX: ") + tit;
|
|
|
|
#endif
|
|
|
|
QMessageBox::warning(0, toqstr(title), toqstr(formatted(message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void error_pimpl(string const & tit, string const & message)
|
|
|
|
{
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
boost::format fmt(_("LyX: %1$s"));
|
|
|
|
fmt % tit;
|
|
|
|
string const title = fmt.str();
|
|
|
|
#else
|
|
|
|
string const title = _("LyX: ") + tit;
|
|
|
|
#endif
|
|
|
|
QMessageBox::critical(0, toqstr(title), toqstr(formatted(message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void information_pimpl(string const & tit, string const & message)
|
|
|
|
{
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
boost::format fmt(_("LyX: %1$s"));
|
|
|
|
fmt % tit;
|
|
|
|
string const title = fmt.str();
|
|
|
|
#else
|
|
|
|
string const title = _("LyX: ") + tit;
|
|
|
|
#endif
|
|
|
|
QMessageBox::information(0, toqstr(title), toqstr(formatted(message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
pair<bool, string> const
|
|
|
|
askForText_pimpl(string const & msg, string const & dflt)
|
2002-03-01 18:47:56 +00:00
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
#if USE_BOOST_FORMAT
|
2002-12-18 23:26:21 +00:00
|
|
|
boost::format fmt(_("LyX: %1$s"));
|
2002-11-27 10:30:28 +00:00
|
|
|
fmt % msg;
|
|
|
|
string const title = fmt.str();
|
|
|
|
#else
|
2002-12-18 14:24:32 +00:00
|
|
|
string const title = _("LyX: ") + msg;
|
2002-11-27 10:30:28 +00:00
|
|
|
#endif
|
2002-12-17 20:37:13 +00:00
|
|
|
QAskForTextDialog d(0, toqstr(title), true);
|
2002-03-01 18:47:56 +00:00
|
|
|
// less than ideal !
|
2002-12-17 20:37:13 +00:00
|
|
|
d.askLA->setText(toqstr('&' + msg));
|
|
|
|
d.askLE->setText(toqstr(dflt));
|
2002-09-11 17:42:45 +00:00
|
|
|
d.askLE->setFocus();
|
2002-03-01 18:47:56 +00:00
|
|
|
int ret = d.exec();
|
|
|
|
|
|
|
|
d.hide();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-03-01 18:47:56 +00:00
|
|
|
if (ret)
|
2002-12-17 20:37:13 +00:00
|
|
|
return make_pair<bool, string>(true, fromqstr(d.askLE->text()));
|
2002-03-01 18:47:56 +00:00
|
|
|
else
|
|
|
|
return make_pair<bool, string>(false, string());
|
|
|
|
}
|