Bump version to 24.04.3.4
[LibreOffice.git] / libreofficekit / qa / gtktiledviewer / gtv-comments-sidebar.cxx
blobf63e77fd16e425f2c8ce8da279ddacf2e8a70e00
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <gtk/gtk.h>
12 #include <iostream>
14 #include "gtv-application-window.hxx"
15 #include "gtv-helpers.hxx"
16 #include "gtv-comments-sidebar.hxx"
18 #include <LibreOfficeKit/LibreOfficeKitGtk.h>
20 #include <boost/property_tree/json_parser.hpp>
22 #ifdef __GNUC__
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wunused-function"
25 #endif
26 #if defined __clang__
27 #if __has_warning("-Wdeprecated-volatile")
28 #pragma clang diagnostic ignored "-Wdeprecated-volatile"
29 #endif
30 #endif
31 G_DEFINE_TYPE(GtvCommentsSidebar, gtv_comments_sidebar, GTK_TYPE_BOX);
32 #ifdef __GNUC__
33 #pragma GCC diagnostic pop
34 #endif
36 void
37 gtv_comments_sidebar_view_annotations(GtvCommentsSidebar* sidebar)
39 GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(sidebar)));
41 LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview));
42 char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:ViewAnnotations");
43 g_info("lok::Document::getCommandValues(%s) : %s", ".uno:ViewAnnotations", pValues);
44 std::stringstream aStream(pValues);
45 free(pValues);
47 // empty the comments grid
48 GtvGtkWrapper<GList> children(gtk_container_get_children(GTK_CONTAINER(sidebar->commentsgrid)),
49 [](GList* l)
51 g_list_free(l);
52 });
53 GList* iter;
54 for (iter = children.get(); iter != nullptr; iter = g_list_next(iter))
55 gtk_widget_destroy(GTK_WIDGET(iter->data));
56 boost::property_tree::ptree aTree;
57 boost::property_tree::read_json(aStream, aTree);
58 try
60 for (const boost::property_tree::ptree::value_type& rValue : aTree.get_child("comments"))
62 GtkWidget* pCommentBox = GtvHelpers::createCommentBox(rValue.second);
63 gtk_container_add(GTK_CONTAINER(sidebar->commentsgrid), pCommentBox);
65 gtk_widget_show_all(sidebar->scrolledwindow);
67 catch(boost::property_tree::ptree_bad_path& rException)
69 std::cerr << "CommentsSidebar::unoViewAnnotations: failed to get comments" << rException.what() << std::endl;
73 static void
74 gtv_comments_sidebar_view_annotations_cb(GtkWidget* pWidget, gpointer)
76 GtvCommentsSidebar* sidebar = GTV_COMMENTS_SIDEBAR(pWidget);
77 gtv_comments_sidebar_view_annotations(sidebar);
80 static void
81 gtv_comments_sidebar_init(GtvCommentsSidebar* sidebar)
83 sidebar->scrolledwindow = gtk_scrolled_window_new(nullptr, nullptr);
84 gtk_widget_set_vexpand(sidebar->scrolledwindow, true);
85 sidebar->commentsgrid = gtk_grid_new();
86 g_object_set(sidebar->commentsgrid, "orientation", GTK_ORIENTATION_VERTICAL, nullptr);
88 sidebar->viewannotationsButton = gtk_button_new_with_label(".uno:ViewAnnotations");
89 // Hack to make sidebar grid wide enough to not need any horizontal scrollbar
90 gtk_widget_set_margin_start(sidebar->viewannotationsButton, 20);
91 gtk_widget_set_margin_end(sidebar->viewannotationsButton, 20);
92 gtk_container_add(GTK_CONTAINER(sidebar), sidebar->viewannotationsButton);
93 g_signal_connect_swapped(sidebar->viewannotationsButton, "clicked", G_CALLBACK(gtv_comments_sidebar_view_annotations_cb), sidebar);
95 gtk_container_add(GTK_CONTAINER(sidebar), sidebar->scrolledwindow);
96 gtk_container_add(GTK_CONTAINER(sidebar->scrolledwindow), sidebar->commentsgrid);
98 gtk_widget_show_all(GTK_WIDGET(sidebar));
101 static void
102 gtv_comments_sidebar_class_init(GtvCommentsSidebarClass* /*klass*/)
106 GtkWidget*
107 gtv_comments_sidebar_new()
109 return GTK_WIDGET(g_object_new(GTV_TYPE_COMMENTS_SIDEBAR,
110 "orientation", GTK_ORIENTATION_VERTICAL,
111 nullptr));
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */