~ubuntu-branches/debian/stretch/gnome-builder/stretch

« back to all changes in this revision

Viewing changes to libide/mingw/ide-mingw-device-provider.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2015-10-11 12:38:45 UTC
  • Revision ID: package-import@ubuntu.com-20151011123845-a0hvkz01se0p1p5a
Tags: upstream-3.16.3
ImportĀ upstreamĀ versionĀ 3.16.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ide-mingw-device-provider.c
 
2
 *
 
3
 * Copyright (C) 2015 Christian Hergert <christian@hergert.me>
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation, either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <glib/gi18n.h>
 
20
 
 
21
#include "ide-context.h"
 
22
#include "ide-mingw-device.h"
 
23
#include "ide-mingw-device-provider.h"
 
24
 
 
25
struct _IdeMingwDeviceProvider
 
26
{
 
27
  IdeDeviceProvider parent_instance;
 
28
};
 
29
 
 
30
G_DEFINE_TYPE (IdeMingwDeviceProvider, ide_mingw_device_provider, IDE_TYPE_DEVICE_PROVIDER)
 
31
 
 
32
static void
 
33
ide_mingw_device_provider_discover_worker (GTask        *task,
 
34
                                           gpointer      source_object,
 
35
                                           gpointer      task_data,
 
36
                                           GCancellable *cancellable)
 
37
{
 
38
  IdeMingwDeviceProvider *self = source_object;
 
39
  GPtrArray *devices;
 
40
  IdeContext *context;
 
41
 
 
42
  g_assert (G_IS_TASK (task));
 
43
  g_assert (IDE_IS_MINGW_DEVICE_PROVIDER (self));
 
44
 
 
45
  devices = g_ptr_array_new_with_free_func (g_object_unref);
 
46
 
 
47
  context = ide_object_get_context (IDE_OBJECT (self));
 
48
 
 
49
  g_assert (IDE_IS_CONTEXT (context));
 
50
 
 
51
  /*
 
52
   * FIXME:
 
53
   *
 
54
   * I'm almost certain this is not the proper way to check for mingw support.
 
55
   * Someone that knows how this works, please fix this up!
 
56
   */
 
57
 
 
58
  if (g_file_test ("/usr/bin/x86_64-w64-mingw32-gcc", G_FILE_TEST_EXISTS))
 
59
    {
 
60
      IdeDevice *device;
 
61
 
 
62
      /* add 64-bit mingw device */
 
63
      device = ide_mingw_device_new (context,
 
64
                                     _("MinGW (64-bit)"),
 
65
                                     "local-x86_64-w64-mingw32",
 
66
                                     "x86_64-w64-mingw32");
 
67
      g_ptr_array_add (devices, device);
 
68
    }
 
69
 
 
70
  if (g_file_test ("/usr/bin/i686-w64-mingw32-gcc", G_FILE_TEST_EXISTS))
 
71
    {
 
72
      IdeDevice *device;
 
73
 
 
74
      /* add 32-bit mingw device */
 
75
      device = ide_mingw_device_new (context,
 
76
                                     _("MinGW (32-bit)"),
 
77
                                     "local-i686-w64-mingw32",
 
78
                                     "i686-w64-mingw32");
 
79
      g_ptr_array_add (devices, device);
 
80
    }
 
81
 
 
82
  g_task_return_pointer (task, devices, (GDestroyNotify)g_ptr_array_unref);
 
83
 
 
84
  ide_object_release (IDE_OBJECT (self));
 
85
}
 
86
 
 
87
static void
 
88
load_cb (GObject      *object,
 
89
         GAsyncResult *result,
 
90
         gpointer      user_data)
 
91
{
 
92
  IdeMingwDeviceProvider *self = (IdeMingwDeviceProvider *)object;
 
93
  GTask *task = (GTask *)result;
 
94
  g_autoptr(GPtrArray) devices = NULL;
 
95
  gsize i;
 
96
 
 
97
  g_assert (IDE_IS_MINGW_DEVICE_PROVIDER (self));
 
98
  g_assert (G_IS_TASK (task));
 
99
 
 
100
  devices = g_task_propagate_pointer (task, NULL);
 
101
 
 
102
  if (devices)
 
103
    {
 
104
      for (i = 0; i < devices->len; i++)
 
105
        {
 
106
          IdeDevice *device;
 
107
 
 
108
          device = g_ptr_array_index (devices, i);
 
109
          ide_device_provider_device_added (IDE_DEVICE_PROVIDER (self), device);
 
110
        }
 
111
    }
 
112
}
 
113
 
 
114
static void
 
115
ide_mingw_device_provider_constructed (GObject *object)
 
116
{
 
117
  IdeMingwDeviceProvider *self = (IdeMingwDeviceProvider *)object;
 
118
  g_autoptr(GTask) task = NULL;
 
119
 
 
120
  g_assert (IDE_IS_MINGW_DEVICE_PROVIDER (self));
 
121
 
 
122
  ide_object_hold (IDE_OBJECT (self));
 
123
  task = g_task_new (self, NULL, load_cb, NULL);
 
124
  g_task_run_in_thread (task, ide_mingw_device_provider_discover_worker);
 
125
}
 
126
 
 
127
static void
 
128
ide_mingw_device_provider_class_init (IdeMingwDeviceProviderClass *klass)
 
129
{
 
130
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
131
 
 
132
  object_class->constructed = ide_mingw_device_provider_constructed;
 
133
}
 
134
 
 
135
static void
 
136
ide_mingw_device_provider_init (IdeMingwDeviceProvider *self)
 
137
{
 
138
}