GuiChanges: provide feedback when there are no more changes

Remove FIXMEs: date and time localisation
This commit is contained in:
Guillaume Munch 2016-05-03 20:40:28 +01:00 committed by Richard Heck
parent 6d4e6aad24
commit 4154e088b0
7 changed files with 64 additions and 50 deletions

View File

@ -13,6 +13,7 @@
#include "Author.h" #include "Author.h"
#include "support/convert.h" #include "support/convert.h"
#include "support/gettext.h"
#include "support/lassert.h" #include "support/lassert.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -48,6 +49,15 @@ Author::Author(int buffer_id)
{} {}
docstring Author::nameAndEmail() const
{
if (email().empty())
return name();
else
return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email());
}
bool Author::valid() const bool Author::valid() const
{ {
//this cannot be equal if the buffer_id was produced by the hash function. //this cannot be equal if the buffer_id was produced by the hash function.

View File

@ -32,6 +32,8 @@ public:
/// ///
docstring email() const { return email_; } docstring email() const { return email_; }
/// ///
docstring nameAndEmail() const;
///
int bufferId() const { return buffer_id_; } int bufferId() const { return buffer_id_; }
/// ///
void setBufferId(int buffer_id) const { buffer_id_ = buffer_id; } void setBufferId(int buffer_id) const { buffer_id_ = buffer_id; }

View File

@ -67,6 +67,7 @@
#include "support/lassert.h" #include "support/lassert.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/lyxalgo.h" #include "support/lyxalgo.h"
#include "support/lyxtime.h"
#include "support/textutils.h" #include "support/textutils.h"
#include <sstream> #include <sstream>
@ -1900,13 +1901,11 @@ docstring Text::currentState(Cursor const & cur) const
Change change = par.lookupChange(cur.pos()); Change change = par.lookupChange(cur.pos());
if (change.changed()) { if (change.changed()) {
Author const & a = buf.params().authors().get(change.author); docstring const author =
os << _("Change: ") << a.name(); buf.params().authors().get(change.author).nameAndEmail();
if (!a.email().empty()) docstring const date = formatted_datetime(change.changetime);
os << " (" << a.email() << ")"; os << bformat(_("Changed by %1$s[[author]] on %2$s[[date]]. "),
// FIXME ctime is english, we should translate that author, date);
os << _(" at ") << ctime(&change.changetime);
os << " : ";
} }
// I think we should only show changes from the default // I think we should only show changes from the default

View File

@ -27,14 +27,13 @@
#include "FuncRequest.h" #include "FuncRequest.h"
#include "LyXRC.h" #include "LyXRC.h"
#include <QDateTime>
#include <QTextBrowser> #include <QTextBrowser>
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
using support::bformat;
using support::formatted_time;
GuiChanges::GuiChanges(GuiView & lv) GuiChanges::GuiChanges(GuiView & lv)
: GuiDialog(lv, "changes", qt_("Merge Changes")) : GuiDialog(lv, "changes", qt_("Merge Changes"))
@ -56,16 +55,29 @@ GuiChanges::GuiChanges(GuiView & lv)
void GuiChanges::updateContents() void GuiChanges::updateContents()
{ {
docstring text; bool const changesPresent = buffer().areChangesPresent();
docstring author = changeAuthor(); nextPB->setEnabled(changesPresent);
docstring date = changeDate(); previousPB->setEnabled(changesPresent);
changeTB->setEnabled(changesPresent);
if (!author.empty()) Change const & c = bufferview()->getCurrentChange();
text += bformat(_("Change by %1$s\n\n"), author); bool const changePresent = c.type != Change::UNCHANGED;
if (!date.empty()) rejectPB->setEnabled(changePresent);
text += bformat(_("Change made at %1$s\n"), date); acceptPB->setEnabled(changePresent);
changeTB->setPlainText(toqstr(text)); QString text;
if (changePresent) {
QString const author =
toqstr(buffer().params().authors().get(c.author).nameAndEmail());
if (!author.isEmpty())
text += qt_("Changed by %1\n\n").arg(author);
QString const date = QDateTime::fromTime_t(c.changetime)
.toString(Qt::DefaultLocaleLongDate);
if (!date.isEmpty())
text += qt_("Change made on %1\n").arg(date);
}
changeTB->setPlainText(text);
} }
@ -81,34 +93,6 @@ void GuiChanges::previousChange()
} }
docstring GuiChanges::changeDate() const
{
Change const & c = bufferview()->getCurrentChange();
if (c.type == Change::UNCHANGED)
return docstring();
// FIXME UNICODE
return from_utf8(formatted_time(c.changetime, lyxrc.date_insert_format));
}
docstring GuiChanges::changeAuthor() const
{
Change const & c = bufferview()->getCurrentChange();
if (c.type == Change::UNCHANGED)
return docstring();
Author const & a = buffer().params().authors().get(c.author);
docstring author = a.name();
if (!a.email().empty())
author += " (" + a.email() + ")";
return author;
}
void GuiChanges::acceptChange() void GuiChanges::acceptChange()
{ {
dispatch(FuncRequest(LFUN_CHANGE_ACCEPT)); dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));

View File

@ -15,6 +15,8 @@
#include "GuiDialog.h" #include "GuiDialog.h"
#include "ui_ChangesUi.h" #include "ui_ChangesUi.h"
#include "support/debug.h"
#include "support/docstring.h" #include "support/docstring.h"
@ -52,11 +54,6 @@ private:
bool isBufferDependent() const { return true; } bool isBufferDependent() const { return true; }
/// always true since dispatchParams() is empty /// always true since dispatchParams() is empty
bool canApply() const { return true; } bool canApply() const { return true; }
/// return date of change
docstring changeDate() const;
/// return author of change
docstring changeAuthor() const;
}; };
} // namespace frontend } // namespace frontend

View File

@ -40,6 +40,18 @@ string const formatted_time(time_t t, string const & fmt)
} }
docstring formatted_datetime(time_t t, string const & fmt)
{
QString qres;
if (fmt.empty())
qres = QLocale().toString(QDateTime::fromTime_t(t),
QLocale::ShortFormat);
else
qres = QLocale().toString(QDateTime::fromTime_t(t), toqstr(fmt));
return qstring_to_ucs4(qres);
}
time_t from_asctime_utc(string t) time_t from_asctime_utc(string t)
{ {
// Example for the format: "Sun Nov 6 10:39:39 2011\n" // Example for the format: "Sun Nov 6 10:39:39 2011\n"

View File

@ -16,6 +16,8 @@
#include <time.h> #include <time.h>
#include <string> #include <string>
#include "strfwd.h"
namespace lyx { namespace lyx {
namespace support { namespace support {
@ -25,9 +27,17 @@ time_t current_time();
/** Returns a locale-dependent formatting of the date /** Returns a locale-dependent formatting of the date
*  and time encoded in \c time. The \p fmt string *  and time encoded in \c time. The \p fmt string
* holds the formatting arguments of \c strftime. * holds the formatting arguments of \c strftime.
* Prefer the function formatted_datetime below.
*/ */
std::string const formatted_time(time_t t, std::string const & fmt); std::string const formatted_time(time_t t, std::string const & fmt);
/** Returns a locale-dependent formatting of the date and time encoded in \c t
* The \p fmt string holds the formatting arguments of QDateTime::toString().
* If fmt is empty then the formatting of the date and time is itself according
* to the locale.
*/
docstring formatted_datetime(time_t t, std::string const & fmt = "");
/** /**
* Inverse of asctime(gmtime()). * Inverse of asctime(gmtime()).
*/ */