File: apps.c

package info (click to toggle)
gobject-introspection 1.86.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 72,464 kB
  • sloc: ansic: 562,805; python: 23,750; xml: 16,240; perl: 1,878; yacc: 1,720; sh: 1,139; lex: 513; cpp: 487; makefile: 197; javascript: 15; lisp: 1
file content (185 lines) | stat: -rw-r--r-- 4,701 bytes parent folder | download | duplicates (6)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <locale.h>
#include <stdlib.h>

static void
print (const gchar *str)
{
  g_print ("%s\n", str ? str : "nil");
}

static void
print_app_list (GList *list)
{
  while (list)
    {
      GAppInfo *info = list->data;
      print (g_app_info_get_id (info));
      list = g_list_delete_link (list, list);
      g_object_unref (info);
    }
}

static void
quit (gpointer user_data)
{
  g_print ("appinfo database changed.\n");
  exit (0);
}

int
main (int argc, char **argv)
{
  setlocale (LC_ALL, "");

  if (argv[1] == NULL || g_str_equal (argv[1], "--help"))
    g_print ("Usage:\n"
      "  apps --help\n"
      "  apps COMMAND [COMMAND_OPTIONS]\n"
      "\n"
      "COMMANDS:\n"
      "  list\n"
      "  search [--should-show-only] TEXT_TO_SEARCH\n"
      "  implementations INTERFACE_NAME\n"
      "  show-info DESKTOP_FILE\n"
      "  default-for-type MIME_TYPE\n"
      "  recommended-for-type MIME_TYPE\n"
      "  all-for-type MIME_TYPE\n"
      "  fallback-for-type MIME_TYPE\n"
      "  should-show DESKTOP_FILE\n"
      "  monitor\n"
      "\n"
      "Examples:\n"
      "  apps search --should-show-only ter\n"
      "  apps show-info org.gnome.Nautilus.desktop\n"
      "  apps default-for-type image/png\n"
      "\n");
  else if (g_str_equal (argv[1], "list"))
    {
      GList *all, *i;

      all = g_app_info_get_all ();
      for (i = all; i; i = i->next)
        g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n");
      g_list_free_full (all, g_object_unref);
    }
  else if (g_str_equal (argv[1], "search"))
    {
      gchar ***results;
      gboolean should_show_only;
      gint i, j;

      should_show_only = argc > 3 && g_str_equal (argv[2], "--should-show-only");
      results = g_desktop_app_info_search (argv[ should_show_only ? 3 : 2 ]);
      for (i = 0; results[i]; i++)
        {
          for (j = 0; results[i][j]; j++)
            {
              if (should_show_only)
                {
                  GDesktopAppInfo *info;
                  gboolean should_show;

                  info = g_desktop_app_info_new (results[i][j]);
                  if (info)
                    {
                      should_show = g_app_info_should_show (G_APP_INFO (info));
                      g_object_unref (info);
                      if (!should_show)
                        continue;
                    }
                }
              g_print ("%s%s", j ? " " : "", results[i][j]);
            }
          g_print ("\n");
          g_strfreev (results[i]);
        }
      g_free (results);
    }
  else if (g_str_equal (argv[1], "implementations"))
    {
      GList *results;

      results = g_desktop_app_info_get_implementations (argv[2]);
      print_app_list (results);
    }
  else if (g_str_equal (argv[1], "show-info"))
    {
      GAppInfo *info;

      info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
      if (info)
        {
          print (g_app_info_get_id (info));
          print (g_app_info_get_name (info));
          print (g_app_info_get_display_name (info));
          print (g_app_info_get_description (info));
          g_object_unref (info);
        }
    }
  else if (g_str_equal (argv[1], "default-for-type"))
    {
      GAppInfo *info;

      info = g_app_info_get_default_for_type (argv[2], FALSE);

      if (info)
        {
          print (g_app_info_get_id (info));
          g_object_unref (info);
        }
    }
  else if (g_str_equal (argv[1], "recommended-for-type"))
    {
      GList *list;

      list = g_app_info_get_recommended_for_type (argv[2]);
      print_app_list (list);
    }
  else if (g_str_equal (argv[1], "all-for-type"))
    {
      GList *list;

      list = g_app_info_get_all_for_type (argv[2]);
      print_app_list (list);
    }

  else if (g_str_equal (argv[1], "fallback-for-type"))
    {
      GList *list;

      list = g_app_info_get_fallback_for_type (argv[2]);
      print_app_list (list);
    }

  else if (g_str_equal (argv[1], "should-show"))
    {
      GAppInfo *info;

      info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
      if (info)
        {
          g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false");
          g_object_unref (info);
        }
    }

  else if (g_str_equal (argv[1], "monitor"))
    {
      GAppInfoMonitor *monitor;
      GAppInfo *info;

      monitor = g_app_info_monitor_get ();

      info = (GAppInfo *) g_desktop_app_info_new ("this-desktop-file-does-not-exist");
      g_assert (!info);

      g_signal_connect (monitor, "changed", G_CALLBACK (quit), NULL);

      while (1)
        g_main_context_iteration (NULL, TRUE);
    }

  return 0;
}