File: save_button_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 (61 lines) | stat: -rw-r--r-- 1,377 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
#include <signal.h>
#include <unistd.h>

#include "npconfig.h"

void save_button_callback( GtkWidget *widget, gpointer data )
{
   NP_Config *config = ( NP_Config *)data;

   if ( config->general.save() )
      config->general.print_error();

   if ( config->subscription.save() )
      config->subscription.print_error();

   if ( config->folders_f.save() )
      config->folders_f.print_error();

   int total = config->deleted.get_total();
   if ( total < 0 )
      config->deleted.print_error();
   else
      if ( total )
         for( int i = 0; i < total; ++i )
         {
            char *filename = ( char *)config->deleted[ i ];
            if ( filename == NULL )
            {
               config->deleted.print_error();
               continue;
            }
            
            config->remove_files( filename );
         }
   
   if ( config->deleted.clear())
   {
      config->deleted.print_error();
      return;
   }
   
   config->dirty = 0;

   char buffer[ 1024 ];
   snprintf( buffer, sizeof buffer, "%s/.npcollections:pid", config->home );
   FILE *file;
   if (( file = fopen( buffer, "r" )) != NULL )
   {
      char *result = fgets( buffer, sizeof buffer, file );
      fclose( file );

      if ( result == NULL )
         return;
      
      pid_t pid = atoi( buffer );
      if ( pid )
         kill( pid, SIGUSR1 );
   }
   
   return;
}