Commit e22aa0a4 authored by Christian Hergert's avatar Christian Hergert

dep-updater: add new interface for updating dependencies

This gives us an interface that plugins can implement to update
dependencies. The omnibar will activate this command instead of
the flatpak-specific backend.

This should allow plugins for other languages such as NodeJS or
Pip to provide an updater in a similar fashion.
parent fc8c1424
/* ide-dependency-updater.c
*
* Copyright © 2017 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "ide-dependency-updater"
#include "ide-dependency-updater.h"
G_DEFINE_INTERFACE (IdeDependencyUpdater, ide_dependency_updater, IDE_TYPE_OBJECT)
static void
ide_dependency_updater_real_update_async (IdeDependencyUpdater *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_task_report_new_error (self,
callback,
user_data,
ide_dependency_updater_real_update_async,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"update_async is not supported");
}
static gboolean
ide_dependency_updater_real_update_finish (IdeDependencyUpdater *self,
GAsyncResult *result,
GError **error)
{
g_assert (IDE_IS_DEPENDENCY_UPDATER (self));
g_assert (G_IS_TASK (result));
return g_task_propagate_boolean (G_TASK (result), error);
}
static void
ide_dependency_updater_default_init (IdeDependencyUpdaterInterface *iface)
{
iface->update_async = ide_dependency_updater_real_update_async;
iface->update_finish = ide_dependency_updater_real_update_finish;
}
void
ide_dependency_updater_update_async (IdeDependencyUpdater *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (IDE_IS_DEPENDENCY_UPDATER (self));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
IDE_DEPENDENCY_UPDATER_GET_IFACE (self)->update_async (self, cancellable, callback, user_data);
}
gboolean
ide_dependency_updater_update_finish (IdeDependencyUpdater *self,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (IDE_IS_DEPENDENCY_UPDATER (self), FALSE);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
return IDE_DEPENDENCY_UPDATER_GET_IFACE (self)->update_finish (self, result, error);
}
/* ide-dependency-updater.h
*
* Copyright © 2017 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "ide-object.h"
G_BEGIN_DECLS
#define IDE_TYPE_DEPENDENCY_UPDATER (ide_dependency_updater_get_type ())
G_DECLARE_INTERFACE (IdeDependencyUpdater, ide_dependency_updater, IDE, DEPENDENCY_UPDATER, IdeObject)
struct _IdeDependencyUpdaterInterface
{
GTypeInterface parent;
void (*update_async) (IdeDependencyUpdater *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*update_finish) (IdeDependencyUpdater *self,
GAsyncResult *result,
GError **error);
};
void ide_dependency_updater_update_async (IdeDependencyUpdater *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean ide_dependency_updater_update_finish (IdeDependencyUpdater *self,
GAsyncResult *result,
GError **error);
G_END_DECLS
......@@ -16,6 +16,7 @@ buildsystem_headers = [
'ide-configuration-manager.h',
'ide-configuration-provider.h',
'ide-configuration.h',
'ide-dependency-updater.h',
'ide-environment-variable.h',
'ide-environment.h',
]
......@@ -37,6 +38,7 @@ buildsystem_sources = [
'ide-configuration-manager.c',
'ide-configuration-provider.c',
'ide-configuration.c',
'ide-dependency-updater.c',
'ide-environment-variable.c',
'ide-environment.c',
]
......
......@@ -62,6 +62,7 @@ G_BEGIN_DECLS
#include "buildsystem/ide-configuration-manager.h"
#include "buildsystem/ide-configuration.h"
#include "buildsystem/ide-configuration-provider.h"
#include "buildsystem/ide-dependency-updater.h"
#include "buildsystem/ide-environment-variable.h"
#include "buildsystem/ide-environment.h"
#include "debugger/ide-debug-manager.h"
......
......@@ -194,7 +194,7 @@
<object class="GtkButton">
<property name="focus-on-click">false</property>
<property name="valign">baseline</property>
<property name="action-name">flatpak.update-dependencies</property>
<property name="action-name">win.update-dependencies</property>
<property name="tooltip-text" translatable="yes">Update project dependencies</property>
<property name="visible">true</property>
<style>
......
......@@ -20,12 +20,15 @@
#include <dazzle.h>
#include <glib/gi18n.h>
#include <libpeas/peas.h>
#include <libpeas/peas-autocleanups.h>
#include <unistd.h>
#include "ide-debug.h"
#include "application/ide-application.h"
#include "buffers/ide-buffer-manager.h"
#include "buildsystem/ide-dependency-updater.h"
#include "vcs/ide-vcs.h"
#include "workbench/ide-workbench.h"
#include "workbench/ide-workbench-header-bar.h"
......@@ -232,6 +235,71 @@ ide_workbench_actions_inspector (GSimpleAction *action,
gtk_window_set_interactive_debugging (TRUE);
}
static void
ide_workbench_actions_update_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
IdeDependencyUpdater *updater = (IdeDependencyUpdater *)object;
g_autoptr(IdeWorkbench) self = user_data;
g_autoptr(GError) error = NULL;
IdeContext *context;
g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (IDE_IS_WORKBENCH (self));
context = ide_workbench_get_context (self);
if (!ide_dependency_updater_update_finish (updater, result, &error))
ide_context_warning (context, "%s", error->message);
}
static void
ide_workbench_actions_update_dependencies_cb (PeasExtensionSet *set,
PeasPluginInfo *plugin_info,
PeasExtension *exten,
gpointer user_data)
{
IdeDependencyUpdater *updater = (IdeDependencyUpdater *)exten;
IdeWorkbench *self = user_data;
g_assert (PEAS_IS_EXTENSION_SET (set));
g_assert (plugin_info != NULL);
g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
g_assert (IDE_IS_WORKBENCH (self));
ide_dependency_updater_update_async (updater,
NULL,
ide_workbench_actions_update_cb,
g_object_ref (self));
}
static void
ide_workbench_actions_update_dependencies (GSimpleAction *action,
GVariant *variant,
gpointer user_data)
{
g_autoptr(PeasExtensionSet) set = NULL;
IdeWorkbench *self = user_data;
IdeContext *context;
g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (IDE_IS_WORKBENCH (self));
context = ide_workbench_get_context (self);
if (context == NULL)
return;
set = peas_extension_set_new (peas_engine_get_default (),
IDE_TYPE_DEPENDENCY_UPDATER,
"context", context,
NULL);
peas_extension_set_foreach (set,
ide_workbench_actions_update_dependencies_cb,
self);
}
void
ide_workbench_actions_init (IdeWorkbench *self)
{
......@@ -244,6 +312,7 @@ ide_workbench_actions_init (IdeWorkbench *self)
{ "save-all-quit", ide_workbench_actions_save_all_quit },
{ "counters", ide_workbench_actions_counters },
{ "inspector", ide_workbench_actions_inspector },
{ "update-dependencies", ide_workbench_actions_update_dependencies },
};
g_action_map_add_action_entries (G_ACTION_MAP (self), actions, G_N_ELEMENTS (actions), self);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment