1 /* gbp-git-progress.c
2 *
3 * Copyright 2019 Christian Hergert <chergert@redhat.com>
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 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #define G_LOG_DOMAIN "gbp-git-progress"
22
23 #include "gbp-git-progress.h"
24
25 struct _GbpGitProgress
26 {
27 IpcGitProgressSkeleton parent_instance;
28 IdeNotification *notif;
29 guint withdraw : 1;
30 };
31
G_DEFINE_FINAL_TYPE(GbpGitProgress,gbp_git_progress,IPC_TYPE_GIT_PROGRESS_SKELETON)32 G_DEFINE_FINAL_TYPE (GbpGitProgress, gbp_git_progress, IPC_TYPE_GIT_PROGRESS_SKELETON)
33
34 IpcGitProgress *
35 gbp_git_progress_new (GDBusConnection *connection,
36 IdeNotification *notif,
37 GCancellable *cancellable,
38 GError **error)
39 {
40 g_autofree gchar *guid = NULL;
41 g_autofree gchar *path = NULL;
42 g_autoptr(GbpGitProgress) ret = NULL;
43
44 g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
45 g_return_val_if_fail (!notif || IDE_IS_NOTIFICATION (notif), NULL);
46 g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
47
48 ret = g_object_new (GBP_TYPE_GIT_PROGRESS, NULL);
49
50 if (notif != NULL)
51 {
52 ret->notif = g_object_ref (notif);
53 ide_notification_set_has_progress (notif, TRUE);
54 ide_notification_set_icon_name (notif, "builder-vcs-git-symbolic");
55 }
56
57 guid = g_dbus_generate_guid ();
58 path = g_strdup_printf ("/org/gnome/Builder/Git/Progress/%s", guid);
59
60 if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (ret),
61 connection,
62 path,
63 error))
64 {
65 if (notif != NULL)
66 {
67 g_object_bind_property (ret, "fraction", notif, "progress", 0);
68 g_object_bind_property (ret, "message", notif, "body", 0);
69 }
70
71 return IPC_GIT_PROGRESS (g_steal_pointer (&ret));
72 }
73
74 return NULL;
75 }
76
77 static void
gbp_git_progress_finalize(GObject * object)78 gbp_git_progress_finalize (GObject *object)
79 {
80 GbpGitProgress *self = (GbpGitProgress *)object;
81
82 if (self->notif)
83 {
84 if (self->withdraw)
85 ide_notification_withdraw (self->notif);
86 g_clear_object (&self->notif);
87 }
88
89 G_OBJECT_CLASS (gbp_git_progress_parent_class)->finalize (object);
90 }
91
92 static void
gbp_git_progress_class_init(GbpGitProgressClass * klass)93 gbp_git_progress_class_init (GbpGitProgressClass *klass)
94 {
95 GObjectClass *object_class = G_OBJECT_CLASS (klass);
96
97 object_class->finalize = gbp_git_progress_finalize;
98 }
99
100 static void
gbp_git_progress_init(GbpGitProgress * self)101 gbp_git_progress_init (GbpGitProgress *self)
102 {
103 }
104
105 void
gbp_git_progress_set_withdraw(GbpGitProgress * self,gboolean withdraw)106 gbp_git_progress_set_withdraw (GbpGitProgress *self,
107 gboolean withdraw)
108 {
109 g_return_if_fail (GBP_IS_GIT_PROGRESS (self));
110
111 self->withdraw = !!withdraw;
112 }
113