]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiChanges.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiChanges.cpp
index 56c917406e0ec8dc90e9983625c582afdf0a7a97..b8d12ceda17e81c9a1c90ae0591519ef766b6e9c 100644 (file)
 #include "FuncRequest.h"
 #include "LyXRC.h"
 
+#include <QDateTime>
 #include <QTextBrowser>
 
 
 namespace lyx {
 namespace frontend {
 
-using support::bformat;
 
 GuiChanges::GuiChanges(GuiView & lv)
        : GuiDialog(lv, "changes", qt_("Merge Changes"))
 {
        setupUi(this);
 
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
        connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
+       connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange()));
        connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
        connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
-       bc().setCancel(closePB);
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
        bc().addReadOnly(acceptPB);
        bc().addReadOnly(rejectPB);
 }
@@ -54,16 +56,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);
 }
 
 
@@ -73,31 +88,9 @@ void GuiChanges::nextChange()
 }
 
 
-docstring GuiChanges::changeDate() const
+void GuiChanges::previousChange()
 {
-       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;
+       dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
 }