aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation-gtk.c
blob: 7350d4a240278b47da2d8f50af77b29fddabc03d (plain) (blame)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
     This file is part of GNUnet.
     Copyright (C) 2010-2014 GNUnet e.V.

     GNUnet 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, or (at your
     option) any later version.

     GNUnet 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 GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     Boston, MA 02110-1301, USA.
*/

/**
 * @file src/conversation/gnunet-conversation-gtk.c
 * @brief Main function of gnunet-conversation-gtk
 * @author yids
 * @author hark
 * @author Christian Grothoff
 */
#include "gnunet-conversation-gtk.h"
#include "gnunet-conversation-gtk_contacts.h"
#include "gnunet-conversation-gtk_egos.h"
#include "gnunet-conversation-gtk_history.h"
#include "gnunet-conversation-gtk_import.h"
#include "gnunet-conversation-gtk_phone.h"
#include "gnunet-conversation-gtk_zones.h"


/**
 * Handle to our main loop.
 */
static struct GNUNET_GTK_MainLoop *ml;

/**
 * Our configuration.
 */
static struct GNUNET_CONFIGURATION_Handle *cfg;

/**
 * Desired phone line.
 */
static unsigned int line;

/**
 * Ego the user wants to use.
 */
static char *ego_name;


/**
 * Get an object from the main window.
 *
 * @param name name of the object
 * @return NULL on error
 */
GObject *
GCG_get_main_window_object (const char *name)
{
  if (NULL == ml)
    return NULL;
  return GNUNET_GTK_main_loop_get_object (ml, name);
}


/**
 * Get our configuration.
 *
 * @return configuration handle
 */
const struct GNUNET_CONFIGURATION_Handle *
GCG_get_configuration ()
{
  return cfg;
}


/**
 * Task run on shutdown.
 *
 * @param cls unused
 */
static void
shutdown_task (void *cls)
{
  GCG_EGOS_shutdown ();
  GCG_ZONES_shutdown ();
  GCG_PHONE_shutdown ();
  GCG_CONTACTS_shutdown ();
  GCG_IMPORT_shutdown ();
  GNUNET_GTK_main_loop_quit (ml);
  ml = NULL;
}


/**
 * Callback invoked if the application is supposed to exit.
 *
 * @param object
 * @param user_data unused
 */
void
gnunet_conversation_gtk_quit_cb (GObject *object, gpointer user_data)
{
  GNUNET_SCHEDULER_shutdown ();
}


/**
 * Actual main function run right after GNUnet's scheduler
 * is initialized.  Initializes up GTK and Glade.
 *
 * @param cls NULL
 */
static void
run (void *cls)
{
  GtkWidget *main_window;

  ml = cls;
  if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
    return;
  cfg = GNUNET_CONFIGURATION_dup (GNUNET_GTK_main_loop_get_configuration (ml));
  if (0 != line)
    GNUNET_CONFIGURATION_set_value_number (cfg, "CONVERSATION", "LINE", line);
  GNUNET_GTK_set_icon_search_path ();
  GNUNET_GTK_setup_nls ();
  /* setup main window */
  main_window = GTK_WIDGET (
    GCG_get_main_window_object ("gnunet_conversation_gtk_main_window"));
  gtk_window_maximize (GTK_WINDOW (main_window));
  /* make GUI visible */
  gtk_widget_show (main_window);
  gtk_window_present (GTK_WINDOW (main_window));
  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
  GCG_HISTORY_init ();
  GCG_ZONES_init (ego_name);
  GCG_EGOS_init (ego_name);
  GCG_IMPORT_init ();
  GCG_CONTACTS_init ();
  GCG_PHONE_init ();
  if (NULL != ego_name)
  {
    GNUNET_free (ego_name);
    ego_name = NULL;
  }
}


/**
 * Main function of gnunet-conversation-gtk.
 *
 * @param argc number of arguments
 * @param argv arguments
 * @return 0 on success
 */
int
main (int argc, char *const *argv)
{
  struct GNUNET_GETOPT_CommandLineOption options[] =
    {GNUNET_GETOPT_option_uint ('p',
                                "phone",
                                "LINE",
                                gettext_noop (
                                  "sets the LINE to use for the phone"),
                                &line),
     GNUNET_GETOPT_option_string ('e',
                                  "ego",
                                  "EGO",
                                  gettext_noop ("select ego to use"),
                                  &ego_name),
     GNUNET_GETOPT_OPTION_END};
  int ret;

  if (GNUNET_OK !=
      GNUNET_GTK_main_loop_start ("gnunet-conversation-gtk",
                                  "GTK GUI for conversation",
                                  argc,
                                  argv,
                                  options,
                                  "gnunet_conversation_gtk_main_window.glade",
                                  &run))
    ret = 1;
  else
    ret = 0;
  if (NULL != cfg)
  {
    GNUNET_CONFIGURATION_destroy (cfg);
    cfg = NULL;
  }
  return ret;
}


/* end of gnunet-conversation-gtk.c */