]> git.lyx.org Git - features.git/commitdiff
GuiChanges: provide feedback when there are no more changes
authorGuillaume Munch <gm@lyx.org>
Tue, 3 May 2016 19:40:28 +0000 (20:40 +0100)
committerRichard Heck <rgheck@lyx.org>
Wed, 15 Jun 2016 21:32:53 +0000 (22:32 +0100)
Remove FIXMEs: date and time localisation

src/Author.cpp
src/Author.h
src/Text.cpp
src/frontends/qt4/GuiChanges.cpp
src/frontends/qt4/GuiChanges.h
src/support/lyxtime.cpp
src/support/lyxtime.h

index bd9d12d06a87b23e7c351296d9d7e45acf7b235a..03025a38aa9910f8695039fa6b3d56a497f31c4f 100644 (file)
@@ -13,6 +13,7 @@
 #include "Author.h"
 
 #include "support/convert.h"
+#include "support/gettext.h"
 #include "support/lassert.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
 {
        //this cannot be equal if the buffer_id was produced by the hash function.
index 6915318531802f2eea40536bc50ac0227ef984d9..108a701e825300144ede07a05a032d6e36040e8e 100644 (file)
@@ -32,6 +32,8 @@ public:
        ///
        docstring email() const { return email_; }
        ///
+       docstring nameAndEmail() const;
+       ///
        int bufferId() const { return buffer_id_; }
        ///
        void setBufferId(int buffer_id) const { buffer_id_ = buffer_id; }
index f6c1d392e5ab171ee114289b3e4918d3db20d3b5..416a67bf0db29dfe42fc30e93e519d97fec2cb03 100644 (file)
@@ -67,6 +67,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
+#include "support/lyxtime.h"
 #include "support/textutils.h"
 
 #include <sstream>
@@ -1900,13 +1901,11 @@ docstring Text::currentState(Cursor const & cur) const
        Change change = par.lookupChange(cur.pos());
 
        if (change.changed()) {
-               Author const & a = buf.params().authors().get(change.author);
-               os << _("Change: ") << a.name();
-               if (!a.email().empty())
-                       os << " (" << a.email() << ")";
-               // FIXME ctime is english, we should translate that
-               os << _(" at ") << ctime(&change.changetime);
-               os << " : ";
+               docstring const author =
+                       buf.params().authors().get(change.author).nameAndEmail();
+               docstring const date = formatted_datetime(change.changetime);
+               os << bformat(_("Changed by %1$s[[author]] on %2$s[[date]]. "),
+                             author, date);
        }
 
        // I think we should only show changes from the default
index a27d24f5808bc96255a3d2a5b807c1ab59eed11f..c168d3591bf2f43f2e6446cbd10376705b4d3d1a 100644 (file)
 #include "FuncRequest.h"
 #include "LyXRC.h"
 
+#include <QDateTime>
 #include <QTextBrowser>
 
 
 namespace lyx {
 namespace frontend {
 
-using support::bformat;
-using support::formatted_time;
 
 GuiChanges::GuiChanges(GuiView & lv)
        : GuiDialog(lv, "changes", qt_("Merge Changes"))
@@ -56,16 +55,29 @@ GuiChanges::GuiChanges(GuiView & lv)
 
 void GuiChanges::updateContents()
 {
-       docstring text;
-       docstring author = changeAuthor();
-       docstring date = changeDate();
+       bool const changesPresent = buffer().areChangesPresent();
+       nextPB->setEnabled(changesPresent);
+       previousPB->setEnabled(changesPresent);
+       changeTB->setEnabled(changesPresent);
 
-       if (!author.empty())
-               text += bformat(_("Change by %1$s\n\n"), author);
-       if (!date.empty())
-               text += bformat(_("Change made at %1$s\n"), date);
-
-       changeTB->setPlainText(toqstr(text));
+       Change const & c = bufferview()->getCurrentChange();
+       bool const changePresent = c.type != Change::UNCHANGED;
+       rejectPB->setEnabled(changePresent);
+       acceptPB->setEnabled(changePresent);
+
+       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()
 {
        dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
index 344f5e56070d313ab251e528305f4c7e5074643d..1096e6293afcd884160d37dc27dfbb2306c080de 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "GuiDialog.h"
 #include "ui_ChangesUi.h"
+
+#include "support/debug.h"
 #include "support/docstring.h"
 
 
@@ -52,11 +54,6 @@ private:
        bool isBufferDependent() const { return true; }
        /// always true since dispatchParams() is empty
        bool canApply() const { return true; }
-
-       /// return date of change
-       docstring changeDate() const;
-       /// return author of change
-       docstring changeAuthor() const;
 };
 
 } // namespace frontend
index 3150825d753f80c3dd95ae15b6147b5c4a8d5114..5415ac4eeb034057234b363d3931d7d004ca40ba 100644 (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)
 {
        // Example for the format: "Sun Nov  6 10:39:39 2011\n"
index 74586cf7de947264ed07a2beb7cc57486c6bfe5a..8fa58733fb6eb044d13c33b8ee05c48dea7b7341 100644 (file)
@@ -16,6 +16,8 @@
 #include <time.h>
 #include <string>
 
+#include "strfwd.h"
+
 
 namespace lyx {
 namespace support {
@@ -25,9 +27,17 @@ time_t current_time();
 /** Returns a locale-dependent formatting of the date
  *  and time encoded in \c time. The \p fmt string
  *  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);
 
+/** 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()).
  */