File: answer_buttons_callback.C

package info (click to toggle)
peruser 4b33-10
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,944 kB
  • ctags: 1,064
  • sloc: cpp: 22,397; perl: 2,733; makefile: 345; sh: 335
file content (99 lines) | stat: -rw-r--r-- 1,978 bytes parent folder | download | duplicates (2)
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
#include <unistd.h>
#include <signal.h>
#include <string.h>

#include <X11/Xlib.h>
#include <gdk/gdkx.h>

#include "nptext.h"

void answer_buttons_callback( GtkWidget *widget, gpointer data )
{
   NP_Text *text = ( NP_Text *)data;

   if ( text->compose_pid || text->text == NULL )
   {
      text->show_message( "There is no message currently loaded." );
      return;
   }
   
   if ( text->header )
   {
      text->show_message( "News Peruser will not let you create a Follow-Up\n"
                          "or Reply to a header-only message." );
      return;
   }

   if ( !strcmp( text->server, "Folders" ))
   {
      text->show_message( "You cannot respond to articles in Folders." );
      return;
   }

   int what = ( int)gtk_object_get_data( GTK_OBJECT( widget ), "what" );

   char *type = NULL;

   switch( what )
   {
   case 0:
      type = "reply";
      break;

   case 1:
      type = "follow-up";
      break;

   case 2:
      type = "both";
      break;

   case 3:
      type = "cancel";
      break;

   case 4:
      type = "supersede";
      break;

   case 5:
      type = "edit";
      break;
   }

   if ( what == 3 || what == 4 )
   {
      if ( text->text != NULL &&
           ( strstr( text->text, "Control:" ) ||
             strstr( text->text, "Supersedes:" )))
      {
         text->show_message( "You cannot cancel or supersede a cancel or\n"
                             "supersede message." );
         return;
      }
   }

   switch( text->compose_pid = fork() )
      {
      case -1:
         perror( "fork" );
         return;
         break;

      case 0:
         close( ConnectionNumber( gdk_display ));

         char buffer[ 32 ];
         snprintf( buffer, sizeof buffer, "%d", text->offset );
         execlp( "npcompose", "npcompose", text->server, text->group,
                 type, buffer, NULL );
         perror( "execlp" );
         _exit( 1 );
         break;

      default:
         break;
      }

   return;
}