Commit 0394cf8d authored by Christian Hergert's avatar Christian Hergert

transfers: move transfer manager to IdeApplication

Instead of controlling the transfer manager at the IdeContext
level, this uses IdeApplication as the owning instance. This is
useful because it allows us to use it from preferences without
having a context accessible.
parent a21393a3
......@@ -42,6 +42,8 @@ struct _IdeApplication
PeasPluginInfo *tool;
gchar **tool_arguments;
IdeTransferManager *transfer_manager;
PeasPluginInfo *worker;
IdeWorkerManager *worker_manager;
......
......@@ -384,6 +384,8 @@ ide_application_startup (GApplication *application)
if ((self->mode == IDE_APPLICATION_MODE_PRIMARY) || (self->mode == IDE_APPLICATION_MODE_TESTS))
{
self->transfer_manager = g_object_new (IDE_TYPE_TRANSFER_MANAGER, NULL);
ide_application_make_skeleton_dirs (self);
ide_language_defaults_init_async (NULL, ide_application_language_defaults_cb, NULL);
ide_application_register_settings (self);
......@@ -429,6 +431,8 @@ ide_application_shutdown (GApplication *application)
if (self->worker_manager != NULL)
ide_worker_manager_shutdown (self->worker_manager);
g_clear_object (&self->transfer_manager);
if (G_APPLICATION_CLASS (ide_application_parent_class)->shutdown)
G_APPLICATION_CLASS (ide_application_parent_class)->shutdown (application);
......@@ -821,3 +825,21 @@ ide_application_add_reaper (IdeApplication *self,
g_ptr_array_add (self->reapers, g_object_ref (reaper));
}
/**
* ide_application_get_transfer_manager:
* @self: a #IdeApplication
*
* Gets the transfer manager for the application.
*
* Returns: (transfer none): An #IdeTransferManager
*
* Since: 3.28
*/
IdeTransferManager *
ide_application_get_transfer_manager (IdeApplication *self)
{
g_return_val_if_fail (IDE_IS_APPLICATION (self), NULL);
return self->transfer_manager;
}
......@@ -22,6 +22,7 @@
#include <gtk/gtk.h>
#include "projects/ide-recent-projects.h"
#include "transfers/ide-transfer-manager.h"
G_BEGIN_DECLS
......@@ -43,6 +44,7 @@ GThread *ide_application_get_main_thread (void);
IdeApplicationMode ide_application_get_mode (IdeApplication *self);
IdeApplication *ide_application_new (void);
GDateTime *ide_application_get_started_at (IdeApplication *self);
IdeTransferManager *ide_application_get_transfer_manager (IdeApplication *self);
IdeRecentProjects *ide_application_get_recent_projects (IdeApplication *self);
void ide_application_show_projects_window (IdeApplication *self);
const gchar *ide_application_get_keybindings_mode (IdeApplication *self);
......
......@@ -23,6 +23,7 @@
#include "ide-context.h"
#include "ide-debug.h"
#include "application/ide-application.h"
#include "buildsystem/ide-build-stage-transfer.h"
#include "buildsystem/ide-build-pipeline.h"
#include "transfers/ide-transfer-manager.h"
......@@ -75,7 +76,6 @@ ide_build_stage_transfer_execute_async (IdeBuildStage *stage,
IdeBuildStageTransfer *self = (IdeBuildStageTransfer *)stage;
g_autoptr(GTask) task = NULL;
IdeTransferManager *transfer_manager;
IdeContext *context;
IDE_ENTRY;
......@@ -111,8 +111,7 @@ ide_build_stage_transfer_execute_async (IdeBuildStage *stage,
}
}
context = ide_object_get_context (IDE_OBJECT (self));
transfer_manager = ide_context_get_transfer_manager (context);
transfer_manager = ide_application_get_transfer_manager (IDE_APPLICATION_DEFAULT);
ide_transfer_manager_execute_async (transfer_manager,
self->transfer,
......
......@@ -78,7 +78,6 @@ struct _IdeContext
IdeRuntimeManager *runtime_manager;
IdeSearchEngine *search_engine;
IdeSourceSnippetsManager *snippets_manager;
IdeTransferManager *transfer_manager;
IdeProject *project;
GFile *project_file;
gchar *root_build_dir;
......@@ -535,7 +534,6 @@ ide_context_finalize (GObject *object)
g_clear_object (&self->project_file);
g_clear_object (&self->recent_manager);
g_clear_object (&self->runtime_manager);
g_clear_object (&self->transfer_manager);
g_clear_object (&self->unsaved_files);
g_clear_object (&self->vcs);
......@@ -819,10 +817,6 @@ ide_context_init (IdeContext *self)
"context", self,
NULL);
self->transfer_manager = g_object_new (IDE_TYPE_TRANSFER_MANAGER,
"context", self,
NULL);
self->unsaved_files = g_object_new (IDE_TYPE_UNSAVED_FILES,
"context", self,
NULL);
......@@ -2294,21 +2288,6 @@ ide_context_get_run_manager (IdeContext *self)
return self->run_manager;
}
/**
* ide_context_get_transfer_manager:
*
* Gets the #IdeTransferManager for the context.
*
* Returns: (transfer none): An #IdeTransferManager.
*/
IdeTransferManager *
ide_context_get_transfer_manager (IdeContext *self)
{
g_return_val_if_fail (IDE_IS_CONTEXT (self), NULL);
return self->transfer_manager;
}
/**
* ide_context_get_diagnostics_manager:
*
......
......@@ -47,7 +47,6 @@ IdeSettings *ide_context_get_settings (IdeContext
const gchar *schema_id,
const gchar *relative_path);
IdeSourceSnippetsManager *ide_context_get_snippets_manager (IdeContext *self);
IdeTransferManager *ide_context_get_transfer_manager (IdeContext *self);
IdeUnsavedFiles *ide_context_get_unsaved_files (IdeContext *self);
IdeVcs *ide_context_get_vcs (IdeContext *self);
const gchar *ide_context_get_root_build_dir (IdeContext *self);
......
......@@ -22,6 +22,7 @@
#include "ide-debug.h"
#include "application/ide-application.h"
#include "transfers/ide-transfer-button.h"
#include "transfers/ide-transfer-manager.h"
#include "util/ide-gtk.h"
......@@ -141,7 +142,6 @@ ide_transfer_button_clicked (GtkButton *button)
IdeTransferButton *self = (IdeTransferButton *)button;
IdeTransferButtonPrivate *priv = ide_transfer_button_get_instance_private (self);
IdeTransferManager *transfer_manager;
IdeContext *context;
IDE_ENTRY;
......@@ -150,15 +150,10 @@ ide_transfer_button_clicked (GtkButton *button)
if (priv->transfer == NULL)
return;
context = ide_widget_get_context (GTK_WIDGET (self));
if (context == NULL)
return;
dzl_progress_button_set_show_progress (DZL_PROGRESS_BUTTON (self), TRUE);
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
transfer_manager = ide_context_get_transfer_manager (context);
transfer_manager = ide_application_get_transfer_manager (IDE_APPLICATION_DEFAULT);
/* TODO: Cancellable state */
g_clear_object (&priv->cancellable);
......
......@@ -24,8 +24,6 @@
#include "transfers/ide-transfer.h"
#include "transfers/ide-transfer-manager.h"
#define DEFAULT_MAX_ACTIVE 1
struct _IdeTransferManager
{
GObject parent_instance;
......@@ -34,8 +32,8 @@ struct _IdeTransferManager
static void list_model_iface_init (GListModelInterface *iface);
G_DEFINE_TYPE_EXTENDED (IdeTransferManager, ide_transfer_manager, IDE_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init))
G_DEFINE_TYPE_WITH_CODE (IdeTransferManager, ide_transfer_manager, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init))
enum {
PROP_0,
......
......@@ -26,7 +26,7 @@ G_BEGIN_DECLS
#define IDE_TYPE_TRANSFER_MANAGER (ide_transfer_manager_get_type())
G_DECLARE_FINAL_TYPE (IdeTransferManager, ide_transfer_manager, IDE, TRANSFER_MANAGER, IdeObject)
G_DECLARE_FINAL_TYPE (IdeTransferManager, ide_transfer_manager, IDE, TRANSFER_MANAGER, GObject)
gdouble ide_transfer_manager_get_progress (IdeTransferManager *self);
gboolean ide_transfer_manager_get_has_active (IdeTransferManager *self);
......
......@@ -21,8 +21,8 @@
#include <dazzle.h>
#include "ide-debug.h"
#include "ide-context.h"
#include "application/ide-application.h"
#include "transfers/ide-transfer.h"
#include "transfers/ide-transfer-manager.h"
#include "transfers/ide-transfer-row.h"
......@@ -89,37 +89,31 @@ static void
ide_transfers_button_update_visibility (IdeTransfersButton *self)
{
IdeTransferManager *transfer_manager;
IdeContext *context;
gboolean visible = FALSE;
gboolean visible;
IDE_ENTRY;
g_assert (IDE_IS_TRANSFERS_BUTTON (self));
if (NULL != (context = ide_widget_get_context (GTK_WIDGET (self))) &&
NULL != (transfer_manager = ide_context_get_transfer_manager (context)))
visible = !!g_list_model_get_n_items (G_LIST_MODEL (transfer_manager));
dzl_progress_menu_button_reset_theatrics (DZL_PROGRESS_MENU_BUTTON (self));
transfer_manager = ide_application_get_transfer_manager (IDE_APPLICATION_DEFAULT);
visible = g_list_model_get_n_items (G_LIST_MODEL (transfer_manager)) > 0;
gtk_widget_set_visible (GTK_WIDGET (self), visible);
IDE_EXIT;
}
static void
ide_transfers_button_context_set (GtkWidget *widget,
IdeContext *context)
ide_transfers_button_constructed (GObject *object)
{
IdeTransfersButton *self = (IdeTransfersButton *)widget;
IdeTransfersButton *self = (IdeTransfersButton *)object;
IdeTransferManager *transfer_manager;
g_assert (IDE_IS_TRANSFERS_BUTTON (self));
g_assert (!context || IDE_IS_CONTEXT (context));
if (context == NULL)
return;
G_OBJECT_CLASS (ide_transfers_button_parent_class)->constructed (object);
transfer_manager = ide_context_get_transfer_manager (context);
transfer_manager = ide_application_get_transfer_manager (IDE_APPLICATION_DEFAULT);
g_object_bind_property (transfer_manager, "progress",
self, "progress",
......@@ -147,21 +141,22 @@ ide_transfers_button_clear (GSimpleAction *action,
{
IdeTransfersButton *self = user_data;
IdeTransferManager *transfer_manager;
IdeContext *context;
g_assert (G_IS_SIMPLE_ACTION (action));
gtk_popover_popdown (self->popover);
if (NULL != (context = ide_widget_get_context (GTK_WIDGET (self))) &&
NULL != (transfer_manager = ide_context_get_transfer_manager (context)))
ide_transfer_manager_clear (transfer_manager);
transfer_manager = ide_application_get_transfer_manager (IDE_APPLICATION_DEFAULT);
ide_transfer_manager_clear (transfer_manager);
}
static void
ide_transfers_button_class_init (IdeTransfersButtonClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = ide_transfers_button_constructed;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/ide-transfers-button.ui");
gtk_widget_class_bind_template_child (widget_class, IdeTransfersButton, list_box);
......@@ -178,9 +173,6 @@ ide_transfers_button_init (IdeTransfersButton *self)
gtk_widget_init_template (GTK_WIDGET (self));
ide_widget_set_context_handler (GTK_WIDGET (self),
ide_transfers_button_context_set);
actions = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (actions),
entries,
......
......@@ -300,7 +300,6 @@ gbp_flatpak_runtime_provider_locate_sdk_cb (GObject *object,
IdeTransferManager *transfer_manager;
InstallRuntime *install;
GCancellable *cancellable;
IdeContext *context;
gboolean sdk_matches_runtime = FALSE;
IDE_ENTRY;
......@@ -319,8 +318,7 @@ gbp_flatpak_runtime_provider_locate_sdk_cb (GObject *object,
g_assert (self != NULL);
g_assert (GBP_IS_FLATPAK_RUNTIME_PROVIDER (self));
context = ide_object_get_context (IDE_OBJECT (self->manager));
transfer_manager = ide_context_get_transfer_manager (context);
transfer_manager = ide_application_get_transfer_manager (IDE_APPLICATION_DEFAULT);
if (!gbp_flatpak_application_addin_locate_sdk_finish (app_addin,
result,
......
......@@ -179,7 +179,6 @@ gbp_flatpak_workbench_addin_install_flatpak_builder (GSimpleAction *action,
GbpFlatpakWorkbenchAddin *self = user_data;
g_autoptr(IdePkconTransfer) transfer = NULL;
IdeTransferManager *manager;
IdeContext *context;
static const gchar *packages[] = {
"flatpak-builder",
......@@ -192,8 +191,7 @@ gbp_flatpak_workbench_addin_install_flatpak_builder (GSimpleAction *action,
g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
transfer = ide_pkcon_transfer_new (packages);
context = ide_workbench_get_context (self->workbench);
manager = ide_context_get_transfer_manager (context);
manager = ide_application_get_transfer_manager (IDE_APPLICATION_DEFAULT);
g_simple_action_set_enabled (action, FALSE);
......
......@@ -148,15 +148,13 @@ class HtmlWorkbenchAddin(GObject.Object, Ide.WorkbenchAddin):
def install_docutils(self):
transfer = Ide.PkconTransfer(packages=['python3-docutils'])
context = self.workbench.get_context()
manager = context.get_transfer_manager()
manager = Gio.Application.get_default().get_transfer_manager()
manager.execute_async(transfer, None, self.docutils_installed, None)
def install_sphinx(self):
transfer = Ide.PkconTransfer(packages=['python3-sphinx'])
context = self.workbench.get_context()
manager = context.get_transfer_manager()
manager = Gio.Application.get_default().get_transfer_manager()
manager.execute_async(transfer, None, self.sphinx_installed, None)
......
......@@ -217,13 +217,10 @@ class RustupApplicationAddin(GObject.Object, Ide.ApplicationAddin):
RustupApplicationAddin.instance.check_rustup()
workbench.connect('notify::is-active', is_active)
# call us if a transfer completes (could be the active_transfer)
workbench.get_context().get_transfer_manager().connect('transfer-completed', self.transfer_completed)
workbench.get_context().get_transfer_manager().connect('transfer-failed', self.transfer_failed)
transfer_manager = Gio.Application.get_default().get_transfer_manager()
transfer_manager.connect('transfer-completed', self.transfer_completed)
transfer_manager.connect('transfer-failed', self.transfer_failed)
self.workbenches.add(workbench)
# add the current transfer to the new workbench
# CJH: This isn't right, so we'll punt on this until we have application level transfers
# if self.active_transfer:
# workbench.get_context().get_transfer_manager().execute_async(self.active_transfer, None, None)
def transfer_completed(self, transfer_manager, transfer):
# reset the active transfer on completion, ensures that new workbenches dont get an old transfer
......@@ -240,13 +237,8 @@ class RustupApplicationAddin(GObject.Object, Ide.ApplicationAddin):
def run_transfer(self, transfer):
self.active_transfer = transfer
self.notify('busy')
# run it in all transfer managers
# TODO: This isn't really correct, but we need to move transfer manager to
# IdeApplication.get_transfer_manager()
for workbench in self.workbenches:
context = workbench.get_context()
transfers = context.get_transfer_manager()
transfers.execute_async(transfer)
transfer_manager = Gio.Application.get_default().get_transfer_manager()
transfer_manager.execute_async(transfer)
def install(self):
self.run_transfer(RustupInstaller(mode=_MODE_INSTALL))
......
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