~dbusmenu-team/libdbusmenu/trunk.16.04

« back to all changes in this revision

Viewing changes to libdbusmenu-glib/server.c

Syncing up to the group properties branch so our tests pass

Show diffs side-by-side

added added

removed removed

Lines of Context:
438
438
                        GList * iter;
439
439
                        for (iter = properties; iter != NULL; iter = g_list_next(iter)) {
440
440
                                gchar * property = (gchar *)iter->data;
441
 
                                menuitem_property_changed(priv->root, property, g_variant_new_string("deadvalue"), DBUSMENU_SERVER(obj));
 
441
                                menuitem_property_changed(priv->root, property, NULL, DBUSMENU_SERVER(obj));
442
442
                        }
443
443
                        g_list_free(properties);
444
444
 
680
680
                        prop_idle_prop_t * iprop = &g_array_index(iitem->array, prop_idle_prop_t, j);
681
681
 
682
682
                        g_free(iprop->property);
683
 
                        g_variant_unref(iprop->variant);
 
683
 
 
684
                        if (iprop->variant != NULL) {
 
685
                                g_variant_unref(iprop->variant);
 
686
                        }
684
687
                }
685
688
 
686
689
                g_array_free(iitem->array, TRUE);
708
711
 
709
712
        int i, j;
710
713
        GVariantBuilder itembuilder;
711
 
        g_variant_builder_init(&itembuilder, G_VARIANT_TYPE_ARRAY);
 
714
        gboolean item_init = FALSE;
 
715
 
 
716
        GVariantBuilder removeitembuilder;
 
717
        gboolean removeitem_init = FALSE;
712
718
 
713
719
        for (i = 0; i < priv->prop_array->len; i++) {
714
720
                prop_idle_item_t * iitem = &g_array_index(priv->prop_array, prop_idle_item_t, i);
715
721
 
716
 
                GVariantBuilder tuplebuilder;
717
 
                g_variant_builder_init(&tuplebuilder, G_VARIANT_TYPE_TUPLE);
718
 
 
719
 
                g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(iitem->id));
720
 
 
721
722
                GVariantBuilder dictbuilder;
722
 
                g_variant_builder_init(&dictbuilder, G_VARIANT_TYPE_DICTIONARY);
 
723
                gboolean dictinit = FALSE;
 
724
 
 
725
                GVariantBuilder removedictbuilder;
 
726
                gboolean removedictinit = FALSE;
723
727
                
 
728
                /* Go throught each item and see if it should go in the removal list
 
729
                   or the additive list. */
724
730
                for (j = 0; j < iitem->array->len; j++) {
725
731
                        prop_idle_prop_t * iprop = &g_array_index(iitem->array, prop_idle_prop_t, j);
726
732
 
727
 
                        GVariant * entry = g_variant_new_dict_entry(g_variant_new_string(iprop->property),
728
 
                                                                    g_variant_new_variant(iprop->variant));
729
 
 
730
 
                        g_variant_builder_add_value(&dictbuilder, entry);
731
 
                }
732
 
 
733
 
                g_variant_builder_add_value(&tuplebuilder, g_variant_builder_end(&dictbuilder));
734
 
 
735
 
                g_variant_builder_add_value(&itembuilder, g_variant_builder_end(&tuplebuilder));
736
 
        }
737
 
 
738
 
        GVariant * megadata = g_variant_builder_end(&itembuilder);
 
733
                        if (iprop->variant != NULL) {
 
734
                                if (!dictinit) {
 
735
                                        g_variant_builder_init(&dictbuilder, G_VARIANT_TYPE_DICTIONARY);
 
736
                                        dictinit = TRUE;
 
737
                                }
 
738
 
 
739
                                GVariant * entry = g_variant_new_dict_entry(g_variant_new_string(iprop->property),
 
740
                                                                            g_variant_new_variant(iprop->variant));
 
741
 
 
742
                                g_variant_builder_add_value(&dictbuilder, entry);
 
743
                        } else {
 
744
                                if (!removedictinit) {
 
745
                                        g_variant_builder_init(&removedictbuilder, G_VARIANT_TYPE_ARRAY);
 
746
                                        removedictinit = TRUE;
 
747
                                }
 
748
 
 
749
                                g_variant_builder_add_value(&removedictbuilder, g_variant_new_string(iprop->property));
 
750
                        }
 
751
                }
 
752
 
 
753
                /* If we've got new values that are real values we need to add that
 
754
                   to the list of items to send the value of */
 
755
                if (dictinit) {
 
756
                        GVariantBuilder tuplebuilder;
 
757
                        g_variant_builder_init(&tuplebuilder, G_VARIANT_TYPE_TUPLE);
 
758
 
 
759
                        g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(iitem->id));
 
760
                        g_variant_builder_add_value(&tuplebuilder, g_variant_builder_end(&dictbuilder));
 
761
 
 
762
                        if (!item_init) {
 
763
                                g_variant_builder_init(&itembuilder, G_VARIANT_TYPE_ARRAY);
 
764
                                item_init = TRUE;
 
765
                        }
 
766
 
 
767
                        g_variant_builder_add_value(&itembuilder, g_variant_builder_end(&tuplebuilder));
 
768
                }
 
769
 
 
770
                /* If we've got properties that have been removed then we need to add
 
771
                   them to the list of removed items */
 
772
                if (removedictinit) {
 
773
                        GVariantBuilder tuplebuilder;
 
774
                        g_variant_builder_init(&tuplebuilder, G_VARIANT_TYPE_TUPLE);
 
775
 
 
776
                        g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(iitem->id));
 
777
                        g_variant_builder_add_value(&tuplebuilder, g_variant_builder_end(&removedictbuilder));
 
778
 
 
779
                        if (!removeitem_init) {
 
780
                                g_variant_builder_init(&removeitembuilder, G_VARIANT_TYPE_ARRAY);
 
781
                                removeitem_init = TRUE;
 
782
                        }
 
783
 
 
784
                        g_variant_builder_add_value(&removeitembuilder, g_variant_builder_end(&tuplebuilder));
 
785
                }
 
786
        }
 
787
 
 
788
        GVariant * megadata[2];
 
789
 
 
790
        if (item_init) {
 
791
                megadata[0] = g_variant_builder_end(&itembuilder);
 
792
        } else {
 
793
                GError * error = NULL;
 
794
                megadata[0] = g_variant_parse(G_VARIANT_TYPE("a(ia{sv})"), "[ ]", NULL, NULL, &error);
 
795
 
 
796
                if (error != NULL) {
 
797
                        g_warning("Unable to parse '[ ]' as a 'a(ia{sv})': %s", error->message);
 
798
                        g_error_free(error);
 
799
                }
 
800
        }
 
801
 
 
802
        if (removeitem_init) {
 
803
                megadata[1] = g_variant_builder_end(&removeitembuilder);
 
804
        } else {
 
805
                GError * error = NULL;
 
806
                megadata[1] = g_variant_parse(G_VARIANT_TYPE("a(ia(s))"), "[ ]", NULL, NULL, &error);
 
807
 
 
808
                if (error != NULL) {
 
809
                        g_warning("Unable to parse '[ ]' as a 'a(ia(s))': %s", error->message);
 
810
                        g_error_free(error);
 
811
                }
 
812
        }
739
813
 
740
814
        if (priv->dbusobject != NULL && priv->bus != NULL) {
741
815
                g_dbus_connection_emit_signal(priv->bus,
743
817
                                              priv->dbusobject,
744
818
                                              DBUSMENU_INTERFACE,
745
819
                                              "ItemPropertiesUpdated",
746
 
                                              g_variant_new_tuple(&megadata, 1),
 
820
                                              g_variant_new_tuple(megadata, 2),
747
821
                                              NULL);
748
822
        } else {
749
 
                g_variant_unref(megadata);
 
823
                g_variant_unref(megadata[0]);
 
824
                g_variant_unref(megadata[1]);
750
825
        }
751
826
 
752
827
        /* Clean everything up */
808
883
                }
809
884
        }
810
885
 
 
886
        /* If it's the default value we want to treat it like a clearing
 
887
           of the value so that it doesn't get sent over dbus and waste
 
888
           bandwidth */
 
889
        if (dbusmenu_menuitem_property_is_default(mi, property)) {
 
890
                variant = NULL;
 
891
        }
 
892
 
811
893
        /* If so, we need to swap the value */
812
894
        if (prop != NULL) {
813
895
                g_variant_unref(prop->variant);
820
902
 
821
903
                g_array_append_val(properties, myprop);
822
904
        }
823
 
        g_variant_ref(variant);
 
905
        if (variant != NULL) {
 
906
                g_variant_ref_sink(variant);
 
907
        }
824
908
 
825
909
        /* Check to see if the idle is already queued, and queue it
826
910
           if not. */
974
1058
        g_variant_builder_add_value(&tuplebuilder, g_variant_new_uint32(revision));
975
1059
        g_variant_builder_add_value(&tuplebuilder, items);
976
1060
 
 
1061
        GVariant * retval = g_variant_builder_end(&tuplebuilder);
 
1062
        // g_debug("Sending layout type: %s", g_variant_get_type_string(retval));
977
1063
        g_dbus_method_invocation_return_value(invocation,
978
 
                                              g_variant_builder_end(&tuplebuilder));
 
1064
                                              retval);
979
1065
        return;
980
1066
}
981
1067
 
1280
1366
                event_data->variant = g_variant_get_variant(event_data->variant);
1281
1367
        }
1282
1368
 
1283
 
        g_variant_ref(event_data->variant);
 
1369
        g_variant_ref_sink(event_data->variant);
1284
1370
 
1285
1371
        g_timeout_add(0, event_local_handler, event_data);
1286
1372