1
/* ide-mingw-device-provider.c
3
* Copyright (C) 2015 Christian Hergert <christian@hergert.me>
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.
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.
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/>.
19
#include <glib/gi18n.h>
21
#include "ide-context.h"
22
#include "ide-mingw-device.h"
23
#include "ide-mingw-device-provider.h"
25
struct _IdeMingwDeviceProvider
27
IdeDeviceProvider parent_instance;
30
G_DEFINE_TYPE (IdeMingwDeviceProvider, ide_mingw_device_provider, IDE_TYPE_DEVICE_PROVIDER)
33
ide_mingw_device_provider_discover_worker (GTask *task,
34
gpointer source_object,
36
GCancellable *cancellable)
38
IdeMingwDeviceProvider *self = source_object;
42
g_assert (G_IS_TASK (task));
43
g_assert (IDE_IS_MINGW_DEVICE_PROVIDER (self));
45
devices = g_ptr_array_new_with_free_func (g_object_unref);
47
context = ide_object_get_context (IDE_OBJECT (self));
49
g_assert (IDE_IS_CONTEXT (context));
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!
58
if (g_file_test ("/usr/bin/x86_64-w64-mingw32-gcc", G_FILE_TEST_EXISTS))
62
/* add 64-bit mingw device */
63
device = ide_mingw_device_new (context,
65
"local-x86_64-w64-mingw32",
66
"x86_64-w64-mingw32");
67
g_ptr_array_add (devices, device);
70
if (g_file_test ("/usr/bin/i686-w64-mingw32-gcc", G_FILE_TEST_EXISTS))
74
/* add 32-bit mingw device */
75
device = ide_mingw_device_new (context,
77
"local-i686-w64-mingw32",
79
g_ptr_array_add (devices, device);
82
g_task_return_pointer (task, devices, (GDestroyNotify)g_ptr_array_unref);
84
ide_object_release (IDE_OBJECT (self));
88
load_cb (GObject *object,
92
IdeMingwDeviceProvider *self = (IdeMingwDeviceProvider *)object;
93
GTask *task = (GTask *)result;
94
g_autoptr(GPtrArray) devices = NULL;
97
g_assert (IDE_IS_MINGW_DEVICE_PROVIDER (self));
98
g_assert (G_IS_TASK (task));
100
devices = g_task_propagate_pointer (task, NULL);
104
for (i = 0; i < devices->len; i++)
108
device = g_ptr_array_index (devices, i);
109
ide_device_provider_device_added (IDE_DEVICE_PROVIDER (self), device);
115
ide_mingw_device_provider_constructed (GObject *object)
117
IdeMingwDeviceProvider *self = (IdeMingwDeviceProvider *)object;
118
g_autoptr(GTask) task = NULL;
120
g_assert (IDE_IS_MINGW_DEVICE_PROVIDER (self));
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);
128
ide_mingw_device_provider_class_init (IdeMingwDeviceProviderClass *klass)
130
GObjectClass *object_class = G_OBJECT_CLASS (klass);
132
object_class->constructed = ide_mingw_device_provider_constructed;
136
ide_mingw_device_provider_init (IdeMingwDeviceProvider *self)