[go: up one dir, main page]

File: main.c

package info (click to toggle)
linpopup 0.9.3.pre4-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 440 kB
  • ctags: 151
  • sloc: ansic: 2,102; sh: 197; makefile: 171
file content (238 lines) | stat: -rw-r--r-- 7,095 bytes parent folder | download
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
/* LinPopUp - A Linux enhanced port of Winpopup, running over Samba.
 * By Jean-Marc Jacquet <littleigloo@chez.com>  
 * Copyright (C) 1998 Little Igloo Org  http://www.chez.com/littleigloo
 *
 *
 * 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,#include <gdk/gdkx.h>
 * 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, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>
#include "protos.h"
#include "pixmaps/icon_256.xpm"
#include "pixmaps/icon_16.xpm"

#include <gdk/gdkx.h>		// Only used by the iconify_window function just below...



void
iconify_window (GtkWidget * widget, GtkWidget * this_window)
{
  /* -- is there a better method to do this? Let me know ... -- */
  XIconifyWindow (GDK_WINDOW_XDISPLAY (window->window),
       GDK_WINDOW_XWINDOW (window->window), DefaultScreen (GDK_DISPLAY ()));
  gdk_flush ();
}



void
deiconify_window (GtkWidget * this_window)
{
  gdk_window_raise (this_window->window);
  gdk_window_show (this_window->window);
  gdk_flush ();
}



void
main_quit (GtkWidget * widget, int *data)
{
  gtk_timeout_remove (check_for_new_message_timeout);
  gtk_main_quit ();
}



int
main (int argc, char *argv[])
{
  GtkWidget *vbox;
  GtkWidget *text;
  GtkWidget *toolbar;
  GtkWidget *table;
  GdkPixmap *icon_pixmap;
  GdkBitmap *icon_mask;


#ifdef DEBUG
  int f;
  char buf[50];

  debug_log = fopen ("/tmp/linpopup.log", "a+");
  fprintf (debug_log, "\n==NEW==\n");
  for (f = 0; f <= argc; f++)
    {
      sprintf (buf, "Arg[%i] : %s \n", f, argv[f]);
      fprintf (debug_log, buf);
    }
  fprintf (debug_log, "=======\n");
#endif

  if (argc > 3)
    trap_message (argc, argv);

#ifdef DEBUG
  fprintf (debug_log, ">>> MSG NOT TRAPPED <<<\n");
  fclose (debug_log);
#endif


  if (argc > 1)
    {
      if (strstr (argv[1], "info"))
	{
	  char buf[1024];
	  static struct utsname uname_buf;
	  uname (&uname_buf);
	  printf ("\n%s", many_version_infos (buf));
	  printf ("\nMessages are kept in %s", DATA_FILE);
	  printf ("\nGTK+   : %i.%i.%u", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
	  printf ("\nKernel : %s", uname_buf.release);
	  printf ("\nHost   : %s", uname_buf.nodename);
	  printf ("\nCPU    : %s", uname_buf.machine);

	  printf ("\n\n");
	  exit (0);
	}

      if (strstr (argv[1], "help"))
	{
	  char buf[1024];
	  printf ("\n%s", many_version_infos (buf));
	  printf ("\nTo obtain help, type :\n %% man linpopup\n Or launch LinPopUp in a Xsession and choose the help menu.\n\n");
	  exit (0);
	}
    }


  /* -- gtk initialisation -- */
  gtk_set_locale ();
  gtk_init (&argc, &argv);


  /* -- Load user preferences, see custom.c -- */
  rc_init ();


  /* -- here comes the main window -- */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize (GTK_WIDGET (window), 425, 400);
  gtk_window_set_title (GTK_WINDOW (window), "LinPopUp");
  gtk_container_border_width (GTK_CONTAINER (window), 0);
  gtk_widget_realize (window);

  gtk_signal_connect (GTK_OBJECT (window), "delete_event", (GtkSignalFunc) main_quit, NULL);
  gtk_signal_connect (GTK_OBJECT (window), "destroy", (GtkSignalFunc) main_quit, NULL);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show (vbox);

  /* -- create the menu (MENU.C) -- */
  create_main_menu (vbox);

  /* -- create toolbar widget, and marking it for further retrieval -- */
  toolbar = create_toolbar (window, vbox);
  gtk_object_set_data (GTK_OBJECT (window), "toolbar", toolbar);




/*   { */
/* #include <gtk/gtk.h> */
/* GtkWidget *viewport, *label; */
/*       viewport = gtk_viewport_new (NULL, NULL); */
/*       gtk_widget_set_usize (viewport, 425, 50); */
/*       gtk_viewport_set_shadow_type (GTK_VIEWPORT(viewport), GTK_SHADOW_OUT); */
/*       gtk_widget_show(viewport); */

/*       label = gtk_label_new ("a really long \nlabel that won't fit"); */
/*       gtk_container_add (GTK_CONTAINER(viewport), label); */
/*       gtk_widget_show (label); */
/* gtk_box_pack_start (GTK_BOX (vbox), viewport, FALSE, TRUE, 1); */

/*   } */


  /* -- create text widget, and marking it for further retrieval -- */
  text = create_text (vbox);
  gtk_object_set_data (GTK_OBJECT (window), "text", text);

  /* -- create statusbar (4 cols  in a table) -- */
  {
    int f;
    for (f = 0; f < 4; f++)
      {
	main_statusbar[f] = gtk_statusbar_new ();
	gtk_widget_show (main_statusbar[f]);
	main_context_id[f] = gtk_statusbar_get_context_id (GTK_STATUSBAR (main_statusbar[f]), " ");
	main_message_id[f] = gtk_statusbar_push (GTK_STATUSBAR (main_statusbar[f]), main_context_id[f], " ");
      }
  }

  table = gtk_table_new (1, 6, TRUE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 1);

  gtk_table_attach (GTK_TABLE (table), main_statusbar[0], 0, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
  gtk_table_attach (GTK_TABLE (table), main_statusbar[1], 2, 3, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
  gtk_table_attach (GTK_TABLE (table), main_statusbar[2], 3, 5, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
  gtk_table_attach (GTK_TABLE (table), main_statusbar[3], 5, 6, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);

  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 1);
  gtk_widget_show (table);


  /* -- set icon pixmap -- */
  if (user_rc.hcolors)
    icon_pixmap = gdk_pixmap_create_from_xpm_d (window->window, &icon_mask, &window->style->bg[GTK_STATE_NORMAL], icon_256);
  else
    icon_pixmap = gdk_pixmap_create_from_xpm_d (window->window, &icon_mask, &window->style->bg[GTK_STATE_NORMAL], icon_16);
  gdk_window_set_icon (window->window, NULL, icon_pixmap, icon_mask);

  /* -- show the main window -- */
  gtk_widget_show (window);


  /* -- initialisation -- */
  processing_new_message = FALSE;
  is_it_a_reply = FALSE;

  total_number_of_messages = count_total_number_of_messages ();
  if ((new_messages = are_there_new_messages_in_data_file ()))
    show_message (first_new_message);
  else if (total_number_of_messages)
    show_message (total_number_of_messages);
  else
    show_no_message ();

  /* -- minimise the window if required -- */
  if ((argc > 1) && (strstr (argv[1], "min")) && (!new_messages))
    iconify_window (NULL, window);

  /* -- start the check_for_new_message timeout -- */
  if (user_rc.message_check_interval)
    check_for_new_message_timeout = gtk_timeout_add (user_rc.message_check_interval, check_for_new_message, NULL);

  /* -- main loop -- */
  gtk_main ();

  return 0;
}