summaryrefslogtreecommitdiff
path: root/shell/launcher-grid.c
blob: 916722d51432402066f4bf642570d6936f921aca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Copyright (C) 2013 Collabora Ltd.
 *
 * Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
 */

#include "launcher-grid.h"

#include <gtk/gtk.h>

#include "app-launcher.h"
#include "shell-app-system.h"
#include "egg-flow-box.h"

static void
child_activated_cb (GtkWidget *grid,
    GtkWidget *widget,
    GtkWidget *scrolled_window)
{
  AppLauncher *app = APP_LAUNCHER (widget);

  app_launcher_activate (app);

  /* A menu item has been activated so let's hide the menu */
  gtk_widget_hide (gtk_widget_get_parent (scrolled_window));
}

static void
destroy_widget (GtkWidget *widget,
    gpointer data)
{
  gtk_widget_destroy (widget);
}

static void
installed_changed_cb (ShellAppSystem *app_system, GtkWidget *grid)
{
  GHashTable *entries = shell_app_system_get_entries (app_system);
  GHashTableIter iter;
  gpointer key, value;

  /* Remove all children first */
  gtk_container_foreach (GTK_CONTAINER (grid), destroy_widget, NULL);

  g_hash_table_iter_init (&iter, entries);
  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      GDesktopAppInfo *info = G_DESKTOP_APP_INFO (value);
      GtkWidget *app = app_launcher_new_from_desktop_info (info);

      gtk_container_add (GTK_CONTAINER (grid), app);
    }

gtk_widget_show_all (grid);
}

GtkWidget *
launcher_grid_new (void)
{
  GtkWidget *scrolled_window;
  GtkWidget *grid;
  ShellAppSystem *app_system;

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);

  grid = egg_flow_box_new ();
  egg_flow_box_set_homogeneous (EGG_FLOW_BOX (grid), TRUE);
  g_signal_connect (grid, "child-activated",
      G_CALLBACK (child_activated_cb), scrolled_window);

  gtk_container_add (GTK_CONTAINER (scrolled_window), grid);

  app_system = shell_app_system_get_default ();
  g_signal_connect (app_system, "installed-changed",
      G_CALLBACK (installed_changed_cb), grid);
  installed_changed_cb (app_system, grid);

  gtk_widget_show_all (scrolled_window);

  return scrolled_window;
}