~ps-jenkins/indicator-messages/trusty-proposed

« back to all changes in this revision

Viewing changes to src/im-menu.c

  • Committer: CI bot
  • Author(s): Lars Uebernickel
  • Date: 2014-04-08 16:24:48 UTC
  • mfrom: (406.1.3 trunk)
  • Revision ID: ps-jenkins@lists.canonical.com-20140408162448-axqvlz58imgl8tuz
desktop menu: sort applications like specified

Default chat client, default email client, and the other applications sorted by alphabet. Fixes: 1216833

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
  g_menu_append_section (priv->menu, NULL, section);
177
177
}
178
178
 
 
179
/*
 
180
 * Inserts @item into @menu by comparing its
 
181
 * "x-messaging-menu-sort-string" with those found in existing menu
 
182
 * items between positions @first and @last.
 
183
 *
 
184
 * If @last is negative, it is counted from the end of @menu.
 
185
 */
179
186
void
180
 
im_menu_insert_section (ImMenu      *menu,
181
 
                        const gchar *sort_string,
182
 
                        const gchar *namespace,
183
 
                        GMenuModel  *section)
 
187
im_menu_insert_item_sorted (ImMenu    *menu,
 
188
                            GMenuItem *item,
 
189
                            gint       first,
 
190
                            gint       last)
184
191
{
185
 
  int position;
186
192
  ImMenuPrivate *priv;
187
 
  GMenuItem *item;
 
193
  gint position = first;
 
194
  gchar *sort_string;
188
195
 
189
196
  g_return_if_fail (IM_IS_MENU (menu));
190
 
  g_return_if_fail (G_IS_MENU_MODEL (section));
 
197
  g_return_if_fail (G_IS_MENU_ITEM (item));
191
198
 
192
199
  priv = im_menu_get_instance_private (menu);
193
200
 
194
 
  for (position = 1; position < g_menu_model_get_n_items(G_MENU_MODEL (priv->menu)) - 1; position++)
 
201
  if (last < 0)
 
202
    last = g_menu_model_get_n_items (G_MENU_MODEL (priv->menu)) + last;
 
203
 
 
204
  g_return_if_fail (first <= last);
 
205
 
 
206
  if (g_menu_item_get_attribute (item, "x-messaging-menu-sort-string", "s", &sort_string))
195
207
    {
196
 
      gchar *item_sort;
197
 
 
198
 
      if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
 
208
      while (position < last)
199
209
        {
200
 
          gint cmp;
201
 
 
202
 
          cmp = g_utf8_collate(sort_string, item_sort);
203
 
          g_free (item_sort);
204
 
          if (cmp < 0)
205
 
            break;
 
210
          gchar *item_sort;
 
211
 
 
212
          if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
 
213
            {
 
214
              gint cmp;
 
215
 
 
216
              cmp = g_utf8_collate(sort_string, item_sort);
 
217
              g_free (item_sort);
 
218
              if (cmp < 0)
 
219
                break;
 
220
            }
 
221
 
 
222
          position++;
206
223
        }
207
224
    }
208
225
 
209
 
  item = g_menu_item_new_section (NULL, section);
210
 
  g_menu_item_set_attribute (item, "x-messaging-menu-sort-string", "s", sort_string);
211
 
 
212
 
  if (namespace)
213
 
    g_menu_item_set_attribute (item, "action-namespace", "s", namespace);
214
 
 
215
226
  g_menu_insert_item (priv->menu, position, item);
216
 
 
217
 
  g_object_unref (item);
218
227
}