~khurshid-alam/unity-control-center/sharing-panel

« back to all changes in this revision

Viewing changes to panels/sharing/cc-remote-login-helper.c

  • Committer: Khurshid Alam
  • Date: 2018-03-12 14:06:28 UTC
  • Revision ID: khurshid.alam@linuxmail.org-20180312140628-rsnrcib4gttusg2w
Import sharing panel from gnome-control-center
This commit imports sharing panel from gnome-control-center and removes old screen-sharing panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Intel, Inc
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
17
 *
 
18
 * Author: Thomas Wood <thomas.wood@intel.com>
 
19
 *
 
20
 */
 
21
 
 
22
#include <gio/gio.h>
 
23
 
 
24
#ifndef SSHD_SERVICE
 
25
#define SSHD_SERVICE "sshd.service"
 
26
#endif
 
27
 
 
28
static const gchar *service_list[] = { SSHD_SERVICE, NULL };
 
29
 
 
30
static gint
 
31
enable_ssh_service ()
 
32
{
 
33
  GDBusConnection *connection;
 
34
  GError *error = NULL;
 
35
  GVariant *temp_variant;
 
36
 
 
37
  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
 
38
  if (!connection)
 
39
    {
 
40
      g_critical ("Error connecting to D-Bus system bus: %s", error->message);
 
41
      g_clear_error (&error);
 
42
      return 1;
 
43
    }
 
44
 
 
45
  temp_variant = g_dbus_connection_call_sync (connection,
 
46
                                              "org.freedesktop.systemd1",
 
47
                                              "/org/freedesktop/systemd1",
 
48
                                              "org.freedesktop.systemd1.Manager",
 
49
                                              "StartUnit",
 
50
                                              g_variant_new ("(ss)",
 
51
                                                             SSHD_SERVICE,
 
52
                                                             "replace"),
 
53
                                              (GVariantType *) "(o)",
 
54
                                              G_DBUS_CALL_FLAGS_NONE,
 
55
                                              -1,
 
56
                                              NULL,
 
57
                                              &error);
 
58
 
 
59
  if (!temp_variant)
 
60
    {
 
61
      g_critical ("Error starting " SSHD_SERVICE ": %s", error->message);
 
62
      g_clear_error (&error);
 
63
      return 1;
 
64
    }
 
65
 
 
66
  g_variant_unref (temp_variant);
 
67
 
 
68
  temp_variant = g_dbus_connection_call_sync (connection,
 
69
                                              "org.freedesktop.systemd1",
 
70
                                              "/org/freedesktop/systemd1",
 
71
                                              "org.freedesktop.systemd1.Manager",
 
72
                                              "EnableUnitFiles",
 
73
                                              g_variant_new ("(^asbb)",
 
74
                                                             service_list,
 
75
                                                             FALSE, FALSE),
 
76
                                              (GVariantType *) "(ba(sss))",
 
77
                                              G_DBUS_CALL_FLAGS_NONE,
 
78
                                              -1,
 
79
                                              NULL,
 
80
                                              &error);
 
81
 
 
82
  if (!temp_variant)
 
83
    {
 
84
      g_critical ("Error enabling " SSHD_SERVICE ": %s", error->message);
 
85
      g_clear_error (&error);
 
86
      return 1;
 
87
    }
 
88
 
 
89
  g_variant_unref (temp_variant);
 
90
 
 
91
  return 0;
 
92
}
 
93
 
 
94
static gint
 
95
disable_ssh_service ()
 
96
{
 
97
  GDBusConnection *connection;
 
98
  GError *error = NULL;
 
99
  GVariant *temp_variant;
 
100
 
 
101
  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
 
102
  if (!connection)
 
103
    {
 
104
      g_critical ("Error connecting to D-Bus system bus: %s", error->message);
 
105
      g_clear_error (&error);
 
106
      return 1;
 
107
    }
 
108
 
 
109
  temp_variant = g_dbus_connection_call_sync (connection,
 
110
                                              "org.freedesktop.systemd1",
 
111
                                              "/org/freedesktop/systemd1",
 
112
                                              "org.freedesktop.systemd1.Manager",
 
113
                                              "StopUnit",
 
114
                                              g_variant_new ("(ss)", SSHD_SERVICE, "replace"),
 
115
                                              (GVariantType *) "(o)",
 
116
                                              G_DBUS_CALL_FLAGS_NONE,
 
117
                                              -1,
 
118
                                              NULL,
 
119
                                              &error);
 
120
  if (!temp_variant)
 
121
    {
 
122
      g_critical ("Error stopping " SSHD_SERVICE ": %s", error->message);
 
123
      g_clear_error (&error);
 
124
      return 1;
 
125
    }
 
126
 
 
127
  g_variant_unref (temp_variant);
 
128
 
 
129
  temp_variant = g_dbus_connection_call_sync (connection,
 
130
                                              "org.freedesktop.systemd1",
 
131
                                              "/org/freedesktop/systemd1",
 
132
                                              "org.freedesktop.systemd1.Manager",
 
133
                                              "DisableUnitFiles",
 
134
                                              g_variant_new ("(^asb)", service_list, FALSE,
 
135
                                                             FALSE),
 
136
                                              (GVariantType *) "(a(sss))",
 
137
                                              G_DBUS_CALL_FLAGS_NONE,
 
138
                                              -1,
 
139
                                              NULL,
 
140
                                              &error);
 
141
 
 
142
  if (!temp_variant)
 
143
    {
 
144
      g_critical ("Error disabling " SSHD_SERVICE ": %s", error->message);
 
145
      g_clear_error (&error);
 
146
      return 1;
 
147
    }
 
148
 
 
149
  g_variant_unref (temp_variant);
 
150
 
 
151
  return 0;
 
152
}
 
153
 
 
154
int
 
155
main (int    argc,
 
156
      char **argv)
 
157
{
 
158
  if (argc < 2)
 
159
    return 1;
 
160
 
 
161
  if (argv[1] == NULL)
 
162
    return 1;
 
163
 
 
164
  if (g_str_equal (argv[1], "enable"))
 
165
    return enable_ssh_service ();
 
166
  else if (g_str_equal (argv[1], "disable"))
 
167
    return disable_ssh_service ();
 
168
 
 
169
  return 1;
 
170
}