Kaydet (Commit) f2afe318 authored tarafından Miklos Vajna's avatar Miklos Vajna

gtktiledviewer: specify author name when calling initializeForRendering()

Open two views, and type into both of them when a Writer doc with
redlining enabled is open: the manage changes dialog now shows how the
correct author is used when creating the redline items.

Change-Id: I48fb90301bfcc04b06d5be5544324ca76fe7b3d7
üst cb9362fa
...@@ -75,10 +75,12 @@ GtkWidget* lok_doc_view_new_from_user_profile (const gchar* ...@@ -75,10 +75,12 @@ GtkWidget* lok_doc_view_new_from_user_profile (const gchar*
/** /**
* lok_doc_view_new_from_widget: * lok_doc_view_new_from_widget:
* @pDocView: The #LOKDocView instance * @pDocView: The #LOKDocView instance
* @pRenderingArguments: (nullable): lok::Document::initializeForRendering() arguments.
* *
* Returns: (transfer none): The #LOKDocView widget instance. * Returns: (transfer none): The #LOKDocView widget instance.
*/ */
GtkWidget* lok_doc_view_new_from_widget (LOKDocView* pDocView); GtkWidget* lok_doc_view_new_from_widget (LOKDocView* pDocView,
const gchar* pRenderingArguments);
/** /**
* lok_doc_view_open_document: * lok_doc_view_open_document:
......
...@@ -136,7 +136,10 @@ public: ...@@ -136,7 +136,10 @@ public:
std::shared_ptr<TiledRowColumnBar> m_pRowBar; std::shared_ptr<TiledRowColumnBar> m_pRowBar;
std::shared_ptr<TiledRowColumnBar> m_pColumnBar; std::shared_ptr<TiledRowColumnBar> m_pColumnBar;
std::shared_ptr<TiledCornerButton> m_pCornerButton; std::shared_ptr<TiledCornerButton> m_pCornerButton;
/// Author string, used for comment insertion.
std::string m_aAuthor; std::string m_aAuthor;
/// Rendering arguments, which are the same for all views.
boost::property_tree::ptree m_aRenderingArguments;
TiledWindow() TiledWindow()
: m_pDocView(nullptr), : m_pDocView(nullptr),
...@@ -174,8 +177,6 @@ public: ...@@ -174,8 +177,6 @@ public:
m_pFindbarLabel(nullptr), m_pFindbarLabel(nullptr),
m_bFindAll(false) m_bFindAll(false)
{ {
struct passwd* pPasswd = getpwuid(getuid());
m_aAuthor = std::string(pPasswd->pw_gecos);
} }
}; };
...@@ -198,6 +199,14 @@ static TiledWindow& lcl_getTiledWindow(GtkWidget* pWidget) ...@@ -198,6 +199,14 @@ static TiledWindow& lcl_getTiledWindow(GtkWidget* pWidget)
return g_aWindows[pToplevel]; return g_aWindows[pToplevel];
} }
/// Generate an author string for multiple views.
static std::string getNextAuthor()
{
static int nCounter = 0;
struct passwd* pPasswd = getpwuid(getuid());
return std::string(pPasswd->pw_gecos) + " #" + std::to_string(++nCounter);
}
TiledRowColumnBar::TiledRowColumnBar(TiledBarType eType) TiledRowColumnBar::TiledRowColumnBar(TiledBarType eType)
: m_pDrawingArea(gtk_drawing_area_new()), : m_pDrawingArea(gtk_drawing_area_new()),
m_nSizePixel(0), m_nSizePixel(0),
...@@ -841,9 +850,19 @@ static void registerSelectorHandlers(TiledWindow& rWindow) ...@@ -841,9 +850,19 @@ static void registerSelectorHandlers(TiledWindow& rWindow)
static void createView(GtkWidget* pButton, gpointer /*pItem*/) static void createView(GtkWidget* pButton, gpointer /*pItem*/)
{ {
TiledWindow& rWindow = lcl_getTiledWindow(pButton); TiledWindow& rWindow = lcl_getTiledWindow(pButton);
GtkWidget* pDocView = lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView));
boost::property_tree::ptree aTree = rWindow.m_aRenderingArguments;
std::string aAuthor = getNextAuthor();
aTree.put(boost::property_tree::ptree::path_type(".uno:Author/type", '/'), "string");
aTree.put(boost::property_tree::ptree::path_type(".uno:Author/value", '/'), aAuthor);
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
std::string aArguments = aStream.str();
GtkWidget* pDocView = lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView), aArguments.c_str());
TiledWindow& rNewWindow = setupWidgetAndCreateWindow(pDocView); TiledWindow& rNewWindow = setupWidgetAndCreateWindow(pDocView);
rNewWindow.m_aAuthor = aAuthor;
// Hide the unused progress bar. // Hide the unused progress bar.
gtk_widget_show_all(rNewWindow.m_pStatusBar); gtk_widget_show_all(rNewWindow.m_pStatusBar);
gtk_widget_hide(rNewWindow.m_pProgressBar); gtk_widget_hide(rNewWindow.m_pProgressBar);
...@@ -866,7 +885,7 @@ static void createModelAndView(const char* pLOPath, const char* pDocPath, const ...@@ -866,7 +885,7 @@ static void createModelAndView(const char* pLOPath, const char* pDocPath, const
const gchar* pUserProfile = aUserProfile.empty() ? nullptr : aUserProfile.c_str(); const gchar* pUserProfile = aUserProfile.empty() ? nullptr : aUserProfile.c_str();
GtkWidget* pDocView = lok_doc_view_new_from_user_profile(pLOPath, pUserProfile, nullptr, nullptr); GtkWidget* pDocView = lok_doc_view_new_from_user_profile(pLOPath, pUserProfile, nullptr, nullptr);
setupWidgetAndCreateWindow(pDocView); TiledWindow& rWindow = setupWidgetAndCreateWindow(pDocView);
boost::property_tree::ptree aTree; boost::property_tree::ptree aTree;
for (size_t i = 0; i < rArguments.size(); ++i) for (size_t i = 0; i < rArguments.size(); ++i)
...@@ -892,6 +911,13 @@ static void createModelAndView(const char* pLOPath, const char* pDocPath, const ...@@ -892,6 +911,13 @@ static void createModelAndView(const char* pLOPath, const char* pDocPath, const
} }
} }
// Save rendering arguments for views which are created later.
rWindow.m_aRenderingArguments = aTree;
rWindow.m_aAuthor = getNextAuthor();
aTree.put(boost::property_tree::ptree::path_type(".uno:Author/type", '/'), "string");
aTree.put(boost::property_tree::ptree::path_type(".uno:Author/value", '/'), rWindow.m_aAuthor);
std::stringstream aStream; std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree); boost::property_tree::write_json(aStream, aTree);
std::string aArguments = aStream.str(); std::string aArguments = aStream.str();
......
...@@ -3016,7 +3016,8 @@ lok_doc_view_new_from_user_profile (const gchar* pPath, const gchar* pUserProfil ...@@ -3016,7 +3016,8 @@ lok_doc_view_new_from_user_profile (const gchar* pPath, const gchar* pUserProfil
nullptr)); nullptr));
} }
SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOKDocView) SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOKDocView,
const gchar* pRenderingArguments)
{ {
LOKDocViewPrivate& pOldPriv = getPrivate(pOldLOKDocView); LOKDocViewPrivate& pOldPriv = getPrivate(pOldLOKDocView);
GtkWidget* pNewDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/nullptr, /*error=*/nullptr, GtkWidget* pNewDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/nullptr, /*error=*/nullptr,
...@@ -3034,7 +3035,7 @@ SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOK ...@@ -3034,7 +3035,7 @@ SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOK
// Store the view id only later in postDocumentLoad(), as // Store the view id only later in postDocumentLoad(), as
// initializeForRendering() changes the id in Impress. // initializeForRendering() changes the id in Impress.
pDocument->pClass->createView(pDocument); pDocument->pClass->createView(pDocument);
pNewPriv->m_aRenderingArguments = pOldPriv->m_aRenderingArguments; pNewPriv->m_aRenderingArguments = pRenderingArguments;
postDocumentLoad(pNewDocView); postDocumentLoad(pNewDocView);
return pNewDocView; return pNewDocView;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment