summaryrefslogtreecommitdiff
path: root/src/core/meta-close-dialog.c
blob: e45e2e5462652df4cce1c8bd0876bb6c7b3b48a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

/*
 * Copyright (C) 2016 Red Hat
 *
 * 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 2 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/>.
 *
 * Author: Carlos Garnacho <carlosg@gnome.org>
 */

#include "config.h"

#include "core/window-private.h"
#include "meta/meta-close-dialog.h"
#include "meta/meta-enum-types.h"

enum
{
  RESPONSE,
  N_SIGNALS
};

guint dialog_signals[N_SIGNALS] = { 0 };

static GQuark quark_visible = 0;

G_DEFINE_INTERFACE (MetaCloseDialog, meta_close_dialog, G_TYPE_OBJECT)

static void
meta_close_dialog_default_init (MetaCloseDialogInterface *iface)
{
  g_object_interface_install_property (iface,
                                       g_param_spec_object ("window",
                                                            "Window",
                                                            "Window",
                                                            META_TYPE_WINDOW,
                                                            G_PARAM_READWRITE |
                                                            G_PARAM_CONSTRUCT_ONLY));
  dialog_signals[RESPONSE] =
    g_signal_new ("response",
                  G_TYPE_FROM_INTERFACE (iface),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  0,
                  NULL, NULL, NULL,
                  G_TYPE_NONE, 1, META_TYPE_CLOSE_DIALOG_RESPONSE);

  quark_visible = g_quark_from_static_string ("meta-close-dialog-visible");
}

/**
 * meta_close_dialog_show:
 * @dialog: a #MetaCloseDialog
 *
 * Shows the close dialog.
 **/
void
meta_close_dialog_show (MetaCloseDialog *dialog)
{
  MetaCloseDialogInterface *iface;

  g_return_if_fail (META_IS_CLOSE_DIALOG (dialog));

  iface = META_CLOSE_DIALOG_GET_IFACE (dialog);
  iface->show (dialog);
  g_object_set_qdata (G_OBJECT (dialog), quark_visible, GINT_TO_POINTER (TRUE));
}

/**
 * meta_close_dialog_hide:
 * @dialog: a #MetaCloseDialog
 *
 * Hides the close dialog.
 **/
void
meta_close_dialog_hide (MetaCloseDialog *dialog)
{
  MetaCloseDialogInterface *iface;

  g_return_if_fail (META_IS_CLOSE_DIALOG (dialog));

  iface = META_CLOSE_DIALOG_GET_IFACE (dialog);
  iface->hide (dialog);
  g_object_steal_qdata (G_OBJECT (dialog), quark_visible);
}

/**
 * meta_close_dialog_response:
 * @dialog: a #MetaCloseDialog
 * @response: a #MetaCloseDialogResponse
 *
 * Responds and closes the dialog. To be called by #MetaCloseDialog
 * implementations.
 **/
void
meta_close_dialog_response (MetaCloseDialog        *dialog,
                            MetaCloseDialogResponse response)
{
  g_signal_emit (dialog, dialog_signals[RESPONSE], 0, response);
  meta_close_dialog_hide (dialog);
}

/**
 * meta_close_dialog_is_visible:
 * @dialog: a #MetaCloseDialog
 *
 * Returns whether @dialog is currently visible.
 *
 * Returns: #TRUE if @dialog is visible.
 **/
gboolean
meta_close_dialog_is_visible (MetaCloseDialog *dialog)
{
  return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (dialog),
                                              quark_visible));
}

/**
 * meta_close_dialog_focus:
 * @dialog: a #MetaCloseDialog
 *
 * Call whenever @dialog should receive keyboard focus,
 * usually when the window would.
 **/
void
meta_close_dialog_focus (MetaCloseDialog *dialog)
{
  MetaCloseDialogInterface *iface;

  g_return_if_fail (META_IS_CLOSE_DIALOG (dialog));

  iface = META_CLOSE_DIALOG_GET_IFACE (dialog);
  if (iface->focus)
    iface->focus (dialog);
}