~larsu/indicator-messages/set-status-return-value

« back to all changes in this revision

Viewing changes to src/im-application-list.c

  • Committer: Tarmac
  • Author(s): Lars Uebernickel
  • Date: 2013-09-09 14:32:02 UTC
  • mfrom: (375.2.6 use-gicon-serialize)
  • Revision ID: tarmac-20130909143202-iip1qcm9w2mcqq6w
Use g_icon_serialize() instead of g_icon_to_string().

Approved by Charles Kerr, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
  const gchar *accessible_name;
162
162
  const gchar *icon_name;
163
163
  GIcon * icon;
 
164
  GVariant *serialized_icon;
164
165
  GVariantBuilder builder;
165
166
  GVariant *state;
166
167
 
182
183
  g_variant_builder_init(&builder, G_VARIANT_TYPE_DICTIONARY);
183
184
 
184
185
  /* icon */
185
 
  g_variant_builder_open(&builder, G_VARIANT_TYPE_DICT_ENTRY);
186
 
  g_variant_builder_add_value(&builder, g_variant_new_string("icon"));
187
186
  icon = g_themed_icon_new_with_default_fallbacks(icon_name);
188
 
  g_variant_builder_add_value(&builder, g_variant_new_variant(g_icon_serialize(icon)));
 
187
  if ((serialized_icon = g_icon_serialize(icon)))
 
188
    {
 
189
      g_variant_builder_add (&builder, "{sv}", "icon", serialized_icon);
 
190
      g_variant_unref (serialized_icon);
 
191
    }
189
192
  g_object_unref(icon);
190
 
  g_variant_builder_close(&builder);
191
193
 
192
194
  /* accessible description */
193
195
  g_variant_builder_open(&builder, G_VARIANT_TYPE_DICT_ENTRY);
467
469
                                        G_TYPE_STRING,
468
470
                                        G_TYPE_STRING,
469
471
                                        G_TYPE_STRING,
470
 
                                        G_TYPE_STRING);
 
472
                                        G_TYPE_VARIANT);
471
473
 
472
474
  signals[SOURCE_CHANGED] = g_signal_new ("source-changed",
473
475
                                          IM_TYPE_APPLICATION_LIST,
503
505
                                         G_TYPE_NONE,
504
506
                                         10,
505
507
                                         G_TYPE_STRING,
506
 
                                         G_TYPE_STRING,
507
 
                                         G_TYPE_STRING,
508
 
                                         G_TYPE_STRING,
 
508
                                         G_TYPE_ICON,
 
509
                                         G_TYPE_STRING,
 
510
                                         G_TYPE_VARIANT,
509
511
                                         G_TYPE_STRING,
510
512
                                         G_TYPE_STRING,
511
513
                                         G_TYPE_STRING,
768
770
{
769
771
  const gchar *id;
770
772
  const gchar *label;
771
 
  const gchar *iconstr;
 
773
  GVariant *maybe_serialized_icon;
772
774
  guint32 count;
773
775
  gint64 time;
774
776
  const gchar *string;
775
777
  gboolean draws_attention;
 
778
  GVariant *serialized_icon = NULL;
776
779
  GVariant *state;
777
780
  GSimpleAction *action;
778
781
 
779
 
  g_variant_get (source, "(&s&s&sux&sb)",
780
 
                 &id, &label, &iconstr, &count, &time, &string, &draws_attention);
 
782
  g_variant_get (source, "(&s&s@avux&sb)",
 
783
                 &id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention);
 
784
 
 
785
  if (g_variant_n_children (maybe_serialized_icon) == 1)
 
786
    g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon);
781
787
 
782
788
  state = g_variant_new ("(uxsb)", count, time, string, draws_attention);
783
789
  action = g_simple_action_new_stateful (id, G_VARIANT_TYPE_BOOLEAN, state);
785
791
 
786
792
  g_action_map_add_action (G_ACTION_MAP(app->source_actions), G_ACTION (action));
787
793
 
788
 
  g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, iconstr);
 
794
  g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, serialized_icon);
789
795
 
790
796
  if (draws_attention)
791
797
    app->draws_attention = TRUE;
793
799
  im_application_list_update_draws_attention (app->list);
794
800
 
795
801
  g_object_unref (action);
 
802
  if (serialized_icon)
 
803
    g_variant_unref (serialized_icon);
 
804
  g_variant_unref (maybe_serialized_icon);
796
805
}
797
806
 
798
807
static void
801
810
{
802
811
  const gchar *id;
803
812
  const gchar *label;
804
 
  const gchar *iconstr;
 
813
  GVariant *maybe_serialized_icon;
805
814
  guint32 count;
806
815
  gint64 time;
807
816
  const gchar *string;
808
817
  gboolean draws_attention;
 
818
  GVariant *serialized_icon = NULL;
809
819
  gboolean visible;
810
820
 
811
 
  g_variant_get (source, "(&s&s&sux&sb)",
812
 
                 &id, &label, &iconstr, &count, &time, &string, &draws_attention);
 
821
  g_variant_get (source, "(&s&s@avux&sb)",
 
822
                 &id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention);
 
823
 
 
824
  if (g_variant_n_children (maybe_serialized_icon) == 1)
 
825
    g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon);
813
826
 
814
827
  g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), id,
815
828
                                      g_variant_new ("(uxsb)", count, time, string, draws_attention));
816
829
 
817
830
  visible = count > 0;
818
831
 
819
 
  g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, iconstr, visible);
 
832
  g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, serialized_icon, visible);
820
833
 
821
834
  app->draws_attention = visible && draws_attention;
822
835
  im_application_list_update_draws_attention (app->list);
 
836
 
 
837
  if (serialized_icon)
 
838
    g_variant_unref (serialized_icon);
 
839
  g_variant_unref (maybe_serialized_icon);
823
840
}
824
841
 
825
842
static void
853
870
    }
854
871
}
855
872
 
856
 
static gchar *
857
 
get_symbolic_app_icon_string (GIcon *icon)
 
873
static GIcon *
 
874
get_symbolic_app_icon (GAppInfo *info)
858
875
{
 
876
  GIcon *icon;
859
877
  const gchar * const *names;
860
878
  gchar *symbolic_name;
861
879
  GIcon *symbolic_icon;
862
 
  gchar *str;
 
880
 
 
881
  icon = g_app_info_get_icon (info);
 
882
  if (icon == NULL)
 
883
    return NULL;
863
884
 
864
885
  if (!G_IS_THEMED_ICON (icon))
865
 
    return NULL;
 
886
    return g_object_ref (icon);
866
887
 
867
888
  names = g_themed_icon_get_names (G_THEMED_ICON (icon));
868
889
  if (!names || !names[0])
869
 
    return NULL;
 
890
    return g_object_ref (icon);
 
891
 
 
892
  symbolic_name = g_strconcat (names[0], "-symbolic", NULL);
870
893
 
871
894
  symbolic_icon = g_themed_icon_new_from_names ((gchar **) names, -1);
872
 
 
873
 
  symbolic_name = g_strconcat (names[0], "-symbolic", NULL);
874
895
  g_themed_icon_prepend_name (G_THEMED_ICON (symbolic_icon), symbolic_name);
875
896
 
876
 
  str = g_icon_to_string (symbolic_icon);
877
 
 
878
897
  g_free (symbolic_name);
879
 
  g_object_unref (symbolic_icon);
880
 
  return str;
 
898
 
 
899
  return symbolic_icon;
881
900
}
882
901
 
883
902
static void
885
904
                                   GVariant    *message)
886
905
{
887
906
  const gchar *id;
888
 
  const gchar *iconstr;
 
907
  GVariant *maybe_serialized_icon;
889
908
  const gchar *title;
890
909
  const gchar *subtitle;
891
910
  const gchar *body;
892
911
  gint64 time;
893
912
  GVariantIter *action_iter;
894
913
  gboolean draws_attention;
 
914
  GVariant *serialized_icon = NULL;
895
915
  GSimpleAction *action;
896
916
  GIcon *app_icon;
897
 
  gchar *app_iconstr = NULL;
898
917
  GVariant *actions = NULL;
899
918
 
900
 
  g_variant_get (message, "(&s&s&s&s&sxaa{sv}b)",
901
 
                 &id, &iconstr, &title, &subtitle, &body, &time, &action_iter, &draws_attention);
 
919
  g_variant_get (message, "(&s@av&s&s&sxaa{sv}b)",
 
920
                 &id, &maybe_serialized_icon, &title, &subtitle, &body, &time, &action_iter, &draws_attention);
902
921
 
903
 
  app_icon = g_app_info_get_icon (G_APP_INFO (app->info));
904
 
  if (app_icon)
905
 
    app_iconstr = get_symbolic_app_icon_string (app_icon);
 
922
  if (g_variant_n_children (maybe_serialized_icon) == 1)
 
923
    serialized_icon = g_variant_get_child_value (maybe_serialized_icon, 0);
906
924
 
907
925
  action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN);
908
926
  g_object_set_qdata(G_OBJECT(action), message_action_draws_attention_quark(), GINT_TO_POINTER(draws_attention));
980
998
 
981
999
  im_application_list_update_draws_attention (app->list);
982
1000
 
 
1001
  app_icon = get_symbolic_app_icon (G_APP_INFO (app->info));
 
1002
 
983
1003
  g_signal_emit (app->list, signals[MESSAGE_ADDED], 0,
984
 
                 app->id, app_iconstr, id, iconstr, title,
 
1004
                 app->id, app_icon, id, serialized_icon, title,
985
1005
                 subtitle, body, actions, time, draws_attention);
986
1006
 
987
1007
  g_variant_iter_free (action_iter);
988
 
  g_free (app_iconstr);
989
1008
  g_object_unref (action);
 
1009
  if (serialized_icon)
 
1010
    g_variant_unref (serialized_icon);
 
1011
  g_variant_unref (maybe_serialized_icon);
 
1012
  g_object_unref (app_icon);
990
1013
}
991
1014
 
992
1015
static void