diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-07-13 13:30:25 +0530 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2017-07-13 13:30:25 +0530 |
commit | bda4a05e7c9210cd7ad3ea45344019b020292d7b (patch) | |
tree | 03a044e7115b789f90155d96467a3985a0100c8f | |
parent | cc2ae182cc4f36862a6709832da92fb46fa04ddc (diff) |
enable comments callbacks
Change-Id: I3d08561ac594ff6c59ec37479ac4ee108f05648f
6 files changed, 104 insertions, 51 deletions
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx index 398b61d118e6..82d87702f6e0 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx @@ -325,7 +325,7 @@ static void setupDocView(LOKDocView* pDocView) g_signal_connect(pDocView, "address-changed", G_CALLBACK(lokdocview_addressChanged), nullptr); g_signal_connect(pDocView, "formula-changed", G_CALLBACK(lokdocview_formulaChanged), nullptr); g_signal_connect(pDocView, "password-required", G_CALLBACK(lokdocview_passwordRequired), nullptr); -// g_signal_connect(pDocView, "comment", G_CALLBACK(lokdocview_commentCallback), nullptr); + g_signal_connect(pDocView, "comment", G_CALLBACK(lokdocview_commentCallback), nullptr); g_signal_connect(pDocView, "configure-event", G_CALLBACK(lokdocview_configureEvent), nullptr); } diff --git a/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.cxx b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.cxx index 50e8e67efa81..8d5017728e1e 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.cxx @@ -19,55 +19,9 @@ #include <map> #include <boost/property_tree/json_parser.hpp> -#include <boost/optional.hpp> G_DEFINE_TYPE(GtvCommentsSidebar, gtv_comments_sidebar, GTK_TYPE_BOX); -static GtkWidget* -gtv_comments_sidebar_create_comment_box(const boost::property_tree::ptree& aComment) -{ - GtkWidget* pCommentVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1); - gchar *id = g_strndup(aComment.get<std::string>("id").c_str(), 20); - g_object_set_data_full(G_OBJECT(pCommentVBox), "id", id, g_free); - - // Set background if its a reply comment - if (aComment.get("parent", -1) > 0) - { - GtkStyleContext* pStyleContext = gtk_widget_get_style_context(pCommentVBox); - GtkCssProvider* pCssProvider = gtk_css_provider_get_default(); - gtk_style_context_add_class(pStyleContext, "commentbox"); - gtk_style_context_add_provider(pStyleContext, GTK_STYLE_PROVIDER(pCssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - gtk_css_provider_load_from_data(pCssProvider, ".commentbox {background-color: lightgreen;}", -1, nullptr); - } - - GtkWidget* pCommentText = gtk_label_new(aComment.get<std::string>("text").c_str()); - GtkWidget* pCommentAuthor = gtk_label_new(aComment.get<std::string>("author").c_str()); - GtkWidget* pCommentDate = gtk_label_new(aComment.get<std::string>("dateTime").c_str()); - GtkWidget* pControlsHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - GtkWidget* pEditButton = gtk_button_new_with_label("Edit"); - GtkWidget* pReplyButton = gtk_button_new_with_label("Reply"); - GtkWidget* pDeleteButton = gtk_button_new_with_label("Delete"); - g_signal_connect(G_OBJECT(pEditButton), "clicked", G_CALLBACK(editButtonClicked), pCommentVBox); - g_signal_connect(G_OBJECT(pReplyButton), "clicked", G_CALLBACK(replyButtonClicked), pCommentVBox); - g_signal_connect(G_OBJECT(pDeleteButton), "clicked", G_CALLBACK(deleteCommentButtonClicked), pCommentVBox); - - gtk_container_add(GTK_CONTAINER(pControlsHBox), pEditButton); - gtk_container_add(GTK_CONTAINER(pControlsHBox), pReplyButton); - gtk_container_add(GTK_CONTAINER(pControlsHBox), pDeleteButton); - GtkWidget* pCommentSeparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); - - gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentText); - gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentAuthor); - gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentDate); - gtk_container_add(GTK_CONTAINER(pCommentVBox), pControlsHBox); - gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentSeparator); - - gtk_label_set_line_wrap(GTK_LABEL(pCommentText), TRUE); - gtk_label_set_max_width_chars(GTK_LABEL(pCommentText), 35); - - return pCommentVBox; -} - void gtv_comments_sidebar_view_annotations(GtvCommentsSidebar* sidebar) { @@ -92,7 +46,7 @@ gtv_comments_sidebar_view_annotations(GtvCommentsSidebar* sidebar) { for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments")) { - GtkWidget* pCommentBox = gtv_comments_sidebar_create_comment_box(rValue.second); + GtkWidget* pCommentBox = createCommentBox(rValue.second); gtk_container_add(GTK_CONTAINER(sidebar->commentsgrid), pCommentBox); } gtk_widget_show_all(sidebar->scrolledwindow); diff --git a/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.hxx b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.hxx index a1de2a500aae..faa90436d812 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-comments-sidebar.hxx @@ -12,8 +12,6 @@ #include <gtk/gtk.h> -#include <boost/property_tree/json_parser.hpp> - G_BEGIN_DECLS struct _GtvCommentsSidebar diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx index e5996893c1e4..40be20a8200c 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx @@ -92,4 +92,48 @@ std::string getNextAuthor() return std::string(pPasswd->pw_gecos) + " #" + std::to_string(++nCounter); } +GtkWidget* createCommentBox(const boost::property_tree::ptree& aComment) +{ + GtkWidget* pCommentVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1); + gchar *id = g_strndup(aComment.get<std::string>("id").c_str(), 20); + g_object_set_data_full(G_OBJECT(pCommentVBox), "id", id, g_free); + + // Set background if its a reply comment + if (aComment.get("parent", -1) > 0) + { + GtkStyleContext* pStyleContext = gtk_widget_get_style_context(pCommentVBox); + GtkCssProvider* pCssProvider = gtk_css_provider_get_default(); + gtk_style_context_add_class(pStyleContext, "commentbox"); + gtk_style_context_add_provider(pStyleContext, GTK_STYLE_PROVIDER(pCssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + gtk_css_provider_load_from_data(pCssProvider, ".commentbox {background-color: lightgreen;}", -1, nullptr); + } + + GtkWidget* pCommentText = gtk_label_new(aComment.get<std::string>("text").c_str()); + GtkWidget* pCommentAuthor = gtk_label_new(aComment.get<std::string>("author").c_str()); + GtkWidget* pCommentDate = gtk_label_new(aComment.get<std::string>("dateTime").c_str()); + GtkWidget* pControlsHBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + GtkWidget* pEditButton = gtk_button_new_with_label("Edit"); + GtkWidget* pReplyButton = gtk_button_new_with_label("Reply"); + GtkWidget* pDeleteButton = gtk_button_new_with_label("Delete"); + g_signal_connect(G_OBJECT(pEditButton), "clicked", G_CALLBACK(editButtonClicked), pCommentVBox); + g_signal_connect(G_OBJECT(pReplyButton), "clicked", G_CALLBACK(replyButtonClicked), pCommentVBox); + g_signal_connect(G_OBJECT(pDeleteButton), "clicked", G_CALLBACK(deleteCommentButtonClicked), pCommentVBox); + + gtk_container_add(GTK_CONTAINER(pControlsHBox), pEditButton); + gtk_container_add(GTK_CONTAINER(pControlsHBox), pReplyButton); + gtk_container_add(GTK_CONTAINER(pControlsHBox), pDeleteButton); + GtkWidget* pCommentSeparator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); + + gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentText); + gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentAuthor); + gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentDate); + gtk_container_add(GTK_CONTAINER(pCommentVBox), pControlsHBox); + gtk_container_add(GTK_CONTAINER(pCommentVBox), pCommentSeparator); + + gtk_label_set_line_wrap(GTK_LABEL(pCommentText), TRUE); + gtk_label_set_max_width_chars(GTK_LABEL(pCommentText), 35); + + return pCommentVBox; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx index cb26c811f236..594f121acb53 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx @@ -12,9 +12,13 @@ #include <gtk/gtk.h> +#include <gtv-signal-handlers.hxx> + #include <map> #include <string> +#include <boost/property_tree/json_parser.hpp> + void userPromptDialog(GtkWindow* pWindow, const std::string& aTitle, std::map<std::string, std::string>& aEntries); void clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection); @@ -22,6 +26,8 @@ void clipboardSetHtml(GtkClipboard* pClipboard, const char* pSelection); /// Generate an author string for multiple views. std::string getNextAuthor(); +GtkWidget* createCommentBox(const boost::property_tree::ptree& aComment); + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx index 6ec9629b956e..9217cce37f66 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx @@ -13,6 +13,7 @@ #include <gtv-helpers.hxx> #include <gtv-signal-handlers.hxx> #include <gtv-calc-header-bar.hxx> +#include <gtv-comments-sidebar.hxx> #include <boost/property_tree/json_parser.hpp> #include <boost/optional.hpp> @@ -218,7 +219,57 @@ void lokdocview_passwordRequired(LOKDocView* pDocView, char* pUrl, gboolean bMod gtk_widget_destroy(pPasswordDialog); } -void lokdocview_commentCallback(LOKDocView* pDocView, gchar* pComment, gpointer); +void lokdocview_commentCallback(LOKDocView* pDocView, gchar* pComment, gpointer) +{ + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))); + + std::stringstream aStream(pComment); + boost::property_tree::ptree aRoot; + boost::property_tree::read_json(aStream, aRoot); + boost::property_tree::ptree aComment = aRoot.get_child("comment"); + GtvCommentsSidebar* sidebar = GTV_COMMENTS_SIDEBAR(window->commentssidebar); + GtkWidget* pCommentsGrid = sidebar->commentsgrid; + GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pCommentsGrid)); + GtkWidget* pSelf = nullptr; + GtkWidget* pParent = nullptr; + for (GList* l = pChildren; l != nullptr; l = l->next) + { + gchar *id = static_cast<gchar*>(g_object_get_data(G_OBJECT(l->data), "id")); + + if (g_strcmp0(id, aComment.get<std::string>("id").c_str()) == 0) + pSelf = GTK_WIDGET(l->data); + + // There is no 'parent' in Remove callbacks + if (g_strcmp0(id, aComment.get("parent", std::string("0")).c_str()) == 0) + pParent = GTK_WIDGET(l->data); + } + + if (aComment.get<std::string>("action") == "Remove") + { + if (pSelf) + gtk_widget_destroy(pSelf); + else + g_warning("Can't find the comment to remove in the list !!"); + } + else if (aComment.get<std::string>("action") == "Add" || aComment.get<std::string>("action") == "Modify") + { + GtkWidget* pCommentBox = createCommentBox(aComment); + if (pSelf != nullptr || pParent != nullptr) + { + gtk_grid_insert_next_to(GTK_GRID(pCommentsGrid), pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM); + gtk_grid_attach_next_to(GTK_GRID(pCommentsGrid), pCommentBox, pSelf != nullptr ? pSelf : pParent, GTK_POS_BOTTOM, 1, 1); + } + else + gtk_container_add(GTK_CONTAINER(pCommentsGrid), pCommentBox); + + gtk_widget_show_all(pCommentBox); + + // We added the widget already below the existing one, so destroy the + // already existing one now + if (pSelf) + gtk_widget_destroy(pSelf); + } +} gboolean lokdocview_configureEvent(GtkWidget* pWidget, GdkEventConfigure* /*pEvent*/, gpointer /*pData*/) { |