[Libreoffice-commits] core.git: 2 commits - libreofficekit/qa

Pranav Kant pranavk at collabora.com
Wed Jun 15 18:05:57 UTC 2016


 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |  122 +++++++++++++++++++-
 1 file changed, 118 insertions(+), 4 deletions(-)

New commits:
commit 57857add9cc33aa2493118a1563bfdbe27f98675
Author: Pranav Kant <pranavk at collabora.com>
Date:   Tue Jun 7 22:36:26 2016 +0530

    gtktiledviewer: add a UNO command debugger
    
    ... to fire desired UNO commands from a dialog. Helpful when you
    need to check some arbitrary UNO commands not supported via UI
    yet.
    
    Change-Id: I55df75ef235f5eb6922c50619610caf1c88241fb

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 6f2a823..7a261be 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -390,6 +390,112 @@ static void lcl_registerToolItem(TiledWindow& rWindow, GtkToolItem* pItem, const
 
 const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 };
 
+static void iterateUnoParams(GtkWidget* pWidget, gpointer userdata)
+{
+    boost::property_tree::ptree *pTree = static_cast<boost::property_tree::ptree*>(userdata);
+
+    GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pWidget));
+    GList* pIt;
+    guint i = 0;
+    const gchar* unoParam[3];
+    for (pIt = pChildren, i = 0; pIt != nullptr && i < 3; pIt = pIt->next, i++)
+    {
+        unoParam[i] = gtk_entry_get_text(GTK_ENTRY(pIt->data));
+    }
+
+    pTree->put(boost::property_tree::ptree::path_type(g_strconcat(unoParam[1], "/", "type", nullptr), '/'), unoParam[0]);
+    pTree->put(boost::property_tree::ptree::path_type(g_strconcat(unoParam[1], "/", "value", nullptr), '/'), unoParam[2]);
+}
+
+static void removeUnoParam(GtkWidget* pWidget, gpointer userdata)
+{
+    GtkWidget* pParamAreaBox = GTK_WIDGET(userdata);
+    GtkWidget* pParamContainer = gtk_widget_get_parent(pWidget);
+
+    gtk_container_remove(GTK_CONTAINER(pParamAreaBox), pParamContainer);
+}
+
+static void addMoreUnoParam(GtkWidget* /*pWidget*/, gpointer userdata)
+{
+    GtkWidget* pUnoParamAreaBox = GTK_WIDGET(userdata);
+
+    GtkWidget* pParamContainer = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_box_pack_start(GTK_BOX(pUnoParamAreaBox), pParamContainer, TRUE, TRUE, 2);
+
+    GtkWidget* pTypeEntry = gtk_entry_new();
+    gtk_box_pack_start(GTK_BOX(pParamContainer), pTypeEntry, TRUE, TRUE, 2);
+    gtk_entry_set_placeholder_text(GTK_ENTRY(pTypeEntry), "Param type (Eg. boolean, string etc.)");
+
+    GtkWidget* pNameEntry = gtk_entry_new();
+    gtk_box_pack_start(GTK_BOX(pParamContainer), pNameEntry, TRUE, TRUE, 2);
+    gtk_entry_set_placeholder_text(GTK_ENTRY(pNameEntry), "Param name");
+
+    GtkWidget* pValueEntry = gtk_entry_new();
+    gtk_box_pack_start(GTK_BOX(pParamContainer), pValueEntry, TRUE, TRUE, 2);
+    gtk_entry_set_placeholder_text(GTK_ENTRY(pValueEntry), "Param value");
+
+    GtkWidget* pRemoveButton = gtk_button_new_from_icon_name("list-remove-symbolic", GTK_ICON_SIZE_BUTTON);
+    g_signal_connect(pRemoveButton, "clicked", G_CALLBACK(removeUnoParam), pUnoParamAreaBox);
+    gtk_box_pack_start(GTK_BOX(pParamContainer), pRemoveButton, TRUE, TRUE, 2);
+
+    gtk_widget_show_all(pUnoParamAreaBox);
+}
+
+static void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */)
+{
+    TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+    LOKDocView* pDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
+
+    GtkWidget* pUnoCmdDialog = gtk_dialog_new_with_buttons ("Execute UNO command",
+                                                            GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET(pDocView))),
+                                                            GTK_DIALOG_MODAL,
+                                                            "Execute",
+                                                            GTK_RESPONSE_OK,
+                                                            nullptr);
+    g_object_set(G_OBJECT(pUnoCmdDialog), "resizable", FALSE, nullptr);
+    GtkWidget* pDialogMessageArea = gtk_dialog_get_content_area (GTK_DIALOG (pUnoCmdDialog));
+    GtkWidget* pUnoCmdAreaBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pUnoCmdAreaBox, TRUE, TRUE, 2);
+
+    GtkWidget* pUnoCmdLabel = gtk_label_new("Enter UNO command");
+    gtk_box_pack_start(GTK_BOX(pUnoCmdAreaBox), pUnoCmdLabel, TRUE, TRUE, 2);
+
+    GtkWidget* pUnoCmdEntry = gtk_entry_new ();
+    gtk_box_pack_start(GTK_BOX(pUnoCmdAreaBox), pUnoCmdEntry, TRUE, TRUE, 2);
+    gtk_entry_set_placeholder_text(GTK_ENTRY(pUnoCmdEntry), "UNO command (Eg. Bold, Italic etc.)");
+
+    GtkWidget* pUnoParamAreaBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+    gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pUnoParamAreaBox, TRUE, TRUE, 2);
+
+    GtkWidget* pAddMoreButton = gtk_button_new_with_label("Add UNO parameter");
+    gtk_box_pack_start(GTK_BOX(pDialogMessageArea), pAddMoreButton, TRUE, TRUE, 2);
+    g_signal_connect(G_OBJECT(pAddMoreButton), "clicked", G_CALLBACK(addMoreUnoParam), pUnoParamAreaBox);
+
+    gtk_widget_show_all(pUnoCmdDialog);
+
+    gint res = gtk_dialog_run (GTK_DIALOG(pUnoCmdDialog));
+    switch (res)
+    {
+    case GTK_RESPONSE_OK:
+    {
+        const gchar* sUnoCmd = g_strconcat(".uno:", gtk_entry_get_text(GTK_ENTRY(pUnoCmdEntry)), nullptr);
+
+        boost::property_tree::ptree aTree;
+        gtk_container_foreach(GTK_CONTAINER(pUnoParamAreaBox), iterateUnoParams, &aTree);
+
+        std::stringstream aStream;
+        boost::property_tree::write_json(aStream, aTree);
+        std::string aArguments = aStream.str();
+
+        g_info("Generated UNO command: %s %s", sUnoCmd, aArguments.c_str());
+
+        lok_doc_view_post_command(pDocView, sUnoCmd, (aArguments.empty() ? nullptr : aArguments.c_str()), false);
+    }
+        break;
+    }
+
+    gtk_widget_destroy(pUnoCmdDialog);
+}
 
 /// Get the visible area of the scrolled window
 static void getVisibleAreaTwips(GtkWidget* pDocView, GdkRectangle* pArea)
@@ -1201,6 +1307,13 @@ static GtkWidget* createWindow(TiledWindow& rWindow)
     gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pEnableEditing, -1);
     g_signal_connect(G_OBJECT(pEnableEditing), "toggled", G_CALLBACK(toggleEditing), nullptr);
 
+    // UNO command dialog debugger
+    GtkToolItem* pUnoCmdDebugger = gtk_tool_button_new(nullptr, nullptr);
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pUnoCmdDebugger), "dialog-question-symbolic");
+    gtk_tool_item_set_tooltip_text(pUnoCmdDebugger, "UNO Command Debugger");
+    gtk_toolbar_insert(GTK_TOOLBAR(pUpperToolbar), pUnoCmdDebugger, -1);
+    g_signal_connect(G_OBJECT(pUnoCmdDebugger), "clicked", G_CALLBACK(unoCommandDebugger), nullptr);
+
     static bool bViewCallback = getenv("LOK_VIEW_CALLBACK");
     if (bViewCallback)
     {
commit 93803d86b97f9dc0e2fc003b9a19036e525a41f0
Author: Pranav Kant <pranavk at collabora.com>
Date:   Tue May 31 22:43:19 2016 +0530

    gtktiledviewer: Fix runtime gtk warnings
    
    Not all buttons are toggle buttons.
    
    Change-Id: I6cddc619f3f760e447ea3ffea07f776e03cdaab9

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 380bc04..6f2a823 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -789,13 +789,11 @@ static void signalCommand(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pD
     {
         std::string aKey = aPayload.substr(0, nPosition);
         std::string aValue = aPayload.substr(nPosition + 1);
-
         if (rWindow.m_aCommandNameToolItems.find(aKey) != rWindow.m_aCommandNameToolItems.end())
         {
             GtkToolItem* pItem = rWindow.m_aCommandNameToolItems[aKey];
-            gboolean bEdit = aValue == "true";
-            if (GTK_IS_TOGGLE_TOOL_BUTTON(pItem))
-            {
+            if (aValue == "true" || aValue == "false") {
+                gboolean bEdit = aValue == "true";
                 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit)
                 {
                     // Avoid invoking lok_doc_view_post_command().
@@ -803,6 +801,9 @@ static void signalCommand(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pD
                     gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pItem), bEdit);
                     rWindow.m_bToolItemBroadcast = true;
                 }
+            } else if (aValue == "enabled" || aValue == "disabled") {
+                gboolean bSensitive = aValue == "enabled";
+                gtk_widget_set_sensitive(GTK_WIDGET(pItem), bSensitive);
             }
         }
     }


More information about the Libreoffice-commits mailing list