aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation-gtk.c
blob: 9845fd39bbcc324cbb7b54ead5fede8d37c086a2 (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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
     This file is part of GNUnet.
     Copyright (C) 2010-2014 Christian Grothoff (and other contributing authors)

     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., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, 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;

/**
 * Should gnunet-conversation-gtk start in tray mode?
 */
static int tray_only;

/**
 * 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)
{
  return GNUNET_GTK_main_loop_get_object (ml, name);
}


/**
 * Updates the status icon to the image of the given name.
 * TODO: support animations.
 *
 * available icons:
 * gnunet-conversation-offline
 * gnunet-conversation-call-active
 * gnunet-conversation-call-on-hold
 * gnunet-conversation-gtk-tray-available
 * gnunet-conversation-gtk-tray-call-pending
 * gnunet-conversation-gtk-tray-call-ringing
 * gnunet-conversation-gtk-tray-call-incoming
 *
 * @param icon_name name of the icon to use
 */
void
GCG_set_status_icon (const char *icon_name)
{
  GtkImage *status_icon;

  status_icon = GTK_IMAGE (GCG_get_main_window_object
                           ("gnunet_conversation_gtk_status_icon"));
  gtk_image_set_from_icon_name (status_icon,
                                icon_name,
                                GTK_ICON_SIZE_BUTTON);
  GNUNET_GTK_tray_icon_change (icon_name,
                               NULL /* tooltip */);
}


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


/**
 * Task run on shutdown.
 *
 * @param cls unused
 * @param tc scheduler context, unused
 */
static void
shutdown_task (void *cls,
               const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GCG_EGOS_shutdown ();
  GCG_ZONES_shutdown ();
  GCG_PHONE_shutdown ();
  GCG_CONTACTS_shutdown ();
  GCG_IMPORT_shutdown ();
  GNUNET_GTK_tray_icon_destroy ();
  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
 * @param tc schedule context
 */
static void
run (void *cls,
     const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  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"));
  main_window = GNUNET_GTK_plug_me ("GNUNET_CONVERSATION_GTK_PLUG",
                                    main_window);
  gtk_window_maximize (GTK_WINDOW (main_window));
  if (NULL == getenv ("GNUNET_CONVERSATION_GTK_PLUG"))
    GNUNET_GTK_tray_icon_create (ml,
                                 GTK_WINDOW (main_window),
                                 "gnunet-gtk" /* FIXME: different icon? */,
                                 "gnunet-conversation-gtk");
  /* make GUI visible */
  if (! tray_only)
  {
    gtk_widget_show (main_window);
    gtk_window_present (GTK_WINDOW (main_window));
  }
  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                &shutdown_task,
                                NULL);
  if (NULL == ego_name)
    ego_name = GNUNET_strdup ("master-zone");
  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)
{
  static struct GNUNET_GETOPT_CommandLineOption options[] = {
    {'p', "phone", "LINE",
     gettext_noop ("sets the LINE to use for the phone"),
     1, &GNUNET_GETOPT_set_uint, &line},
    {'e', "ego", "ego",
     gettext_noop ("select ego to use"), 1,
     &GNUNET_GETOPT_set_string, &ego_name},
    {'t', "tray", NULL,
     gettext_noop ("start in tray mode"), 0,
     &GNUNET_GETOPT_set_one, &tray_only},
    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 */