calls-application.c 3.91 KB
Newer Older
Mohammed Sadiq's avatar
Mohammed Sadiq committed
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
/* calls-application.c
 *
 * Copyright (C) 2018 Purism SPC
 * Copyright (C) 2018 Mohammed Sadiq <sadiq@sadiqpk.org>
 *
 * This file is part of Calls.
 *
 * Calls 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.
 *
 * Calls 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 Calls.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      Bob Ham <bob.ham@puri.sm>
 *      Mohammed Sadiq <sadiq@sadiqpk.org>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <glib/gi18n.h>

#define HANDY_USE_UNSTABLE_API
#include <handy.h>

#include "config.h"
#include "calls-new-call-header-bar.h"
#include "calls-history-header-bar.h"
#include "calls-history-box.h"
#include "calls-new-call-box.h"
#include "calls-encryption-indicator.h"
#include "calls-mm-provider.h"
Bob Ham's avatar
Bob Ham committed
40
#include "calls-ringer.h"
Mohammed Sadiq's avatar
Mohammed Sadiq committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "calls-call-window.h"
#include "calls-main-window.h"
#include "calls-application.h"

/**
 * SECTION: calls-application
 * @title: CallsApplication
 * @short_description: Base Application class
 * @include: "calls-application.h"
 */

struct _CallsApplication
{
  GtkApplication parent_instance;

  CallsProvider *provider;
Bob Ham's avatar
Bob Ham committed
57
  CallsRinger   *ringer;
Mohammed Sadiq's avatar
Mohammed Sadiq committed
58
59
60
61
62
63
};

G_DEFINE_TYPE (CallsApplication, calls_application, GTK_TYPE_APPLICATION)


static void
64
dispose (GObject *object)
Mohammed Sadiq's avatar
Mohammed Sadiq committed
65
66
67
{
  CallsApplication *self = (CallsApplication *)object;

Bob Ham's avatar
Bob Ham committed
68
  g_clear_object (&self->ringer);
Mohammed Sadiq's avatar
Mohammed Sadiq committed
69
70
71
72
73
74
75
76
77
78
79
80
81
  g_clear_object (&self->provider);

  G_OBJECT_CLASS (calls_application_parent_class)->finalize (object);
}

static void
startup (GApplication *application)
{
  CallsApplication *self = (CallsApplication *)application;
  g_autoptr(GError) error = NULL;

  G_APPLICATION_CLASS (calls_application_parent_class)->startup (application);

Bob Ham's avatar
Bob Ham committed
82
83
84
  g_set_prgname (APP_ID);
  g_set_application_name (_("Calls"));

85
  self->provider = CALLS_PROVIDER (calls_mm_provider_new ());
Mohammed Sadiq's avatar
Mohammed Sadiq committed
86
87
  g_assert (self->provider != NULL);

Bob Ham's avatar
Bob Ham committed
88
89
  self->ringer = calls_ringer_new (self->provider);
  g_assert (self->ringer != NULL);
Mohammed Sadiq's avatar
Mohammed Sadiq committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
}

static void
activate (GApplication *application)
{
  CallsApplication *self = (CallsApplication *)application;
  GtkApplication *app = (GtkApplication *)application;
  GtkWindow *window;

  g_assert (GTK_IS_APPLICATION (app));

  window = gtk_application_get_active_window (app);

  if (window == NULL)
    {
      /*
       * We don't track the memory created.  Ideally, we might have to.
       * But we assume that the application is closed by closing the
       * window.  In that case, GTK+ frees the resources right.
       */
      window = GTK_WINDOW (calls_main_window_new (app, self->provider));
111
      calls_call_window_new (app, self->provider);
Mohammed Sadiq's avatar
Mohammed Sadiq committed
112
113
114
115
116
117
118
119
120
121
122
    }

  gtk_window_present (window);
}

static void
calls_application_class_init (CallsApplicationClass *klass)
{
  GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

123
  object_class->dispose = dispose;
Mohammed Sadiq's avatar
Mohammed Sadiq committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

  application_class->startup = startup;
  application_class->activate = activate;

  g_type_ensure (CALLS_TYPE_ENCRYPTION_INDICATOR);
  g_type_ensure (CALLS_TYPE_HISTORY_BOX);
  g_type_ensure (CALLS_TYPE_HISTORY_HEADER_BAR);
  g_type_ensure (CALLS_TYPE_NEW_CALL_BOX);
  g_type_ensure (CALLS_TYPE_NEW_CALL_HEADER_BAR);
  g_type_ensure (HDY_TYPE_DIALER);
}

static void
calls_application_init (CallsApplication *self)
{
}

CallsApplication *
calls_application_new (void)
{
  return g_object_new (CALLS_TYPE_APPLICATION,
                       "application-id", APP_ID,
                       "flags", G_APPLICATION_FLAGS_NONE,
                       NULL);
}