sc/inc/postit.hxx                       |    6 ++++--
 sc/source/core/data/postit.cxx          |   24 +++++++++++++++---------
 sc/source/filter/inc/commentsbuffer.hxx |    4 ++++
 sc/source/filter/oox/commentsbuffer.cxx |   17 +++++++++++++++--
 4 files changed, 38 insertions(+), 13 deletions(-)

New commits:
commit b6e0586379c52ece8a57e2b6118407ff27b7e7e9
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Tue Aug 13 05:58:51 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Aug 13 09:43:26 2024 +0200

    sc: comments loaded incorrectly in xlsx
    
    problem:
    1. when loading xlsx files, comments in that format does not store date,
    there for libreoffice loaded comments with current date and time.
    
    2. Author names were not loaded at all in xlsx, and by default
    name of user was used as author instead
    
    Change-Id: I7b1f7fcda01565a6ba131fbae72e7d86e5eaaf15
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171805
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx
index 5e7f6f81d16f..e5727de071b7 100644
--- a/sc/inc/postit.hxx
+++ b/sc/inc/postit.hxx
@@ -113,7 +113,7 @@ public:
     void SetAuthor( const OUString& rAuthor );
 
     /** Sets date and author from system settings. */
-    void                AutoStamp();
+    void AutoStamp(bool bCreate = true);
 
     /** Returns the pointer to the current outliner object, or null. */
     const OutlinerParaObject* GetOutlinerObject() const;
@@ -179,13 +179,15 @@ class GenerateNoteCaption
 public:
     virtual void Generate(SdrCaptionObj& rCaptionObj) = 0;
     virtual OUString GetSimpleText() const = 0;
+    virtual OUString GetAuthorName() const = 0;
     virtual ~GenerateNoteCaption() {};
 };
 
 class SC_DLLPUBLIC ScNoteUtil
 {
     static ScPostIt* InsertNote(ScDocument& rDoc, const ScAddress& rPos, 
ScNoteData&& rNoteData,
-                                bool bAlwaysCreateCaption, sal_uInt32 
nPostItId);
+                                bool bAlwaysCreateCaption, sal_uInt32 
nPostItId,
+                                bool bShouldAutoStamp = true);
 
     static ScNoteData CreateNoteData(ScDocument& rDoc, const ScAddress& rPos,
                                      const tools::Rectangle& rCaptionRect, 
bool bShown);
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index fa84f0212b81..695106ee5202 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -502,10 +502,15 @@ void ScPostIt::SetAuthor( const OUString& rAuthor )
     maNoteData.maAuthor = rAuthor;
 }
 
-void ScPostIt::AutoStamp()
+void ScPostIt::AutoStamp(bool bCreate)
 {
-    maNoteData.maDate = ScGlobal::getLocaleData().getDate( Date( Date::SYSTEM 
) ) + " " +
-        ScGlobal::getLocaleData().getTime(DateTime(DateTime::SYSTEM), false);
+    if (bCreate)
+    {
+        maNoteData.maDate = 
ScGlobal::getLocaleData().getDate(Date(Date::SYSTEM)) + " "
+                            + 
ScGlobal::getLocaleData().getTime(DateTime(DateTime::SYSTEM), false);
+    }
+    if (!maNoteData.maAuthor.isEmpty())
+        return;
     const OUString aAuthor = SvtUserOptions().GetFullName();
     maNoteData.maAuthor = !aAuthor.isEmpty() ? aAuthor : 
ScResId(STR_CHG_UNKNOWN_AUTHOR);
 }
@@ -854,8 +859,7 @@ rtl::Reference<SdrCaptionObj> ScNoteUtil::CreateTempCaption(
         else
         {
             aBuffer.append(pNote->GetAuthor()
-                + ", "
-                + pNote->GetDate());
+                           + (!pNote->GetDate().isEmpty() ? ", " + 
pNote->GetDate() : OUString()));
         }
         pNoteCaption = pNote->GetOrCreateCaption( rPos );
     }
@@ -983,17 +987,19 @@ ScPostIt* ScNoteUtil::CreateNoteFromGenerator(
     // simple text now to supply any queries for that which don't require
     // creation of a full Caption
     rInitData.maSimpleText = rInitData.mxGenerator->GetSimpleText();
-
-    return InsertNote(rDoc, rPos, std::move(aNoteData), 
/*bAlwaysCreateCaption*/false, 0/*nPostItId*/);
+    aNoteData.maAuthor = rInitData.mxGenerator->GetAuthorName();
+    return InsertNote(rDoc, rPos, std::move(aNoteData), 
/*bAlwaysCreateCaption*/ false,
+                      0 /*nPostItId*/, false /*bShouldAutoStamp*/);
 }
 
 ScPostIt* ScNoteUtil::InsertNote(ScDocument& rDoc, const ScAddress& rPos, 
ScNoteData&& rNoteData,
-                                 bool bAlwaysCreateCaption, sal_uInt32 
nPostItId)
+                                 bool bAlwaysCreateCaption, sal_uInt32 
nPostItId,
+                                 bool bShouldAutoStamp)
 {
     /*  Create the note and insert it into the document. If the note is
         visible, the caption object will be created automatically. */
     ScPostIt* pNote = new ScPostIt( rDoc, rPos, std::move(rNoteData), 
bAlwaysCreateCaption, nPostItId );
-    pNote->AutoStamp();
+    pNote->AutoStamp(bShouldAutoStamp);
     //insert takes ownership
     rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote));
     return pNote;
diff --git a/sc/source/filter/inc/commentsbuffer.hxx 
b/sc/source/filter/inc/commentsbuffer.hxx
index c30d6765d6f6..04baa15b0b7e 100644
--- a/sc/source/filter/inc/commentsbuffer.hxx
+++ b/sc/source/filter/inc/commentsbuffer.hxx
@@ -60,6 +60,8 @@ public:
     /** Finalizes the formatted string of the comment. */
     void                finalizeImport();
 
+    OUString getAuthorName();
+
 private:
     CommentModel        maModel;
 };
@@ -79,6 +81,8 @@ public:
     /** Finalizes the formatted string of all comments. */
     void                finalizeImport();
 
+    std::vector<OUString> getAuthors() const;
+
 private:
     typedef RefVector< Comment >                CommentVector;
 
diff --git a/sc/source/filter/oox/commentsbuffer.cxx 
b/sc/source/filter/oox/commentsbuffer.cxx
index 1f1f2dd2540c..adbac7c92461 100644
--- a/sc/source/filter/oox/commentsbuffer.cxx
+++ b/sc/source/filter/oox/commentsbuffer.cxx
@@ -154,9 +154,11 @@ namespace
         css::uno::Sequence<OUString> maPropertyNames;  /// import filter 
Caption object formatting property names
         css::uno::Sequence<css::uno::Any> maPropertyValues; /// import filter 
Caption object formatting property values
         std::shared_ptr<RichString> mxText;
+        OUString msAuthorName;
 
-        OOXGenerateNoteCaption(std::shared_ptr<RichString>& rText)
+        OOXGenerateNoteCaption(std::shared_ptr<RichString>& rText, const 
OUString& rAuthorName = "")
             : mxText(rText)
+            , msAuthorName(rAuthorName)
         {
         }
 
@@ -182,6 +184,8 @@ namespace
         {
             return mxText->getStringContent();
         }
+
+        virtual OUString GetAuthorName() const override { return msAuthorName; 
}
     };
 }
 
@@ -199,7 +203,7 @@ void Comment::finalizeImport()
         rtl::Reference<ScAnnotationsObj> xAnnos = 
static_cast<ScAnnotationsObj*>(pAnnosSupp->getAnnotations().get());
         ScDocShell* pDocShell = xAnnos->GetDocShell();
 
-        auto xGenerator = 
std::make_unique<OOXGenerateNoteCaption>(maModel.mxText);
+        auto xGenerator = 
std::make_unique<OOXGenerateNoteCaption>(maModel.mxText, getAuthorName());
 
         // Add shape formatting properties (autoFill, colHidden and rowHidden 
are dropped)
         // vvv TODO vvv TextFitToSize should be a drawing::TextFitToSizeType 
not bool
@@ -276,6 +280,13 @@ void Comment::finalizeImport()
     }
 }
 
+OUString Comment::getAuthorName()
+{
+    if (o3tl::make_unsigned(this->maModel.mnAuthorId) < 
getComments().getAuthors().size())
+        return getComments().getAuthors()[this->maModel.mnAuthorId];
+    return "";
+}
+
 // private --------------------------------------------------------------------
 
 CommentsBuffer::CommentsBuffer( const WorksheetHelper& rHelper ) :
@@ -288,6 +299,8 @@ void CommentsBuffer::appendAuthor( const OUString& rAuthor )
     maAuthors.push_back( rAuthor );
 }
 
+std::vector<OUString> CommentsBuffer::getAuthors() const { return maAuthors; }
+
 CommentRef CommentsBuffer::createComment()
 {
     CommentRef xComment = std::make_shared<Comment>( *this );

Reply via email to