Advertisement
dsreyes1014

GtkTextView issue through struct

Aug 21st, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.23 KB | None | 0 0
  1. typedef struct _GtkPassedServerSwitchData {    
  2.     GtkWidget *text;
  3.     GtkWidget *window;  
  4. } GtkPassedServerSwitchData;
  5.  
  6. static void
  7. switch_pos_cb (GtkSwitch *sw, gpointer user_data)
  8. {  
  9.     GPid pid;
  10.     gboolean check;
  11.     gboolean check_pid;
  12.     FILE *get_pid;
  13.     gchar pid_string[16];
  14.     GtkWidget *window;
  15.         GtkPassedServerSwitchData *rdata;
  16.  
  17.     check = gtk_switch_get_active (sw);
  18.     pid = -2;
  19.     rdata = user_data;
  20.    
  21.  
  22.         gtk_text_view_set_editable (GTK_TEXT_VIEW (rdata -> text), FALSE);
  23.         gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (rdata -> text), TRUE);
  24.  
  25.     /* Here we get the `GPid pid` from the `get_pid` statement, which
  26.     uses the `pgrep` command to obtain the pid, and convert it to a gint
  27.     using the `g_ascii_strtoll ()` function. */
  28.     get_pid = popen ("pgrep jackd", "r");
  29.  
  30.     while (fgets (pid_string, sizeof (pid_string), get_pid) != NULL)
  31.     {
  32.         pid = atoi (pid_string);
  33.     }
  34.  
  35.     pclose (get_pid);
  36.    
  37.     /* Check if `GPid pid` exists. */
  38.     check_pid = kill (pid, 0);
  39.  
  40.     if (check == TRUE)
  41.     {                      
  42.         gtk_widget_set_tooltip_text (GTK_WIDGET (sw) , "Shutdown Server");
  43.        
  44.         /* If server isn't started yet, start it here when switch is
  45.         turned on. */
  46.         if (check_pid != 0)
  47.         {
  48.             //jack_server_init (sw, pid, rdata -> text, rdata -> window);
  49.         }
  50.     }
  51.     else
  52.     {  
  53.         gtk_widget_set_tooltip_text (GTK_WIDGET (sw) , "Start Server");
  54.         kill (pid, SIGTERM);   
  55.     }
  56. }  
  57.  
  58. void
  59. server_switch (GtkWidget *window,
  60.                GtkWidget *text,
  61.                GtkApplication *app,
  62.                GtkWidget *header_bar)
  63. {  
  64.     GtkWidget *jack_switch;
  65.     gchar result[10];
  66.     gint check_pid;
  67.     gboolean check;
  68.     FILE *cmd;
  69.     GPid pid;
  70.         GtkPassedServerSwitchData *pdata;
  71.    
  72.     pid = -2;
  73.     cmd = popen ("pgrep jackd", "r");
  74.     jack_switch = gtk_switch_new ();
  75.     check = gtk_switch_get_active (GTK_SWITCH (jack_switch));
  76.    
  77.         //pdata = (GtkPassedServerSwitchData *) g_malloc (sizeof (GtkPassedServerSwitchData));
  78.         pdata = g_slice_new0 (GtkPassedServerSwitchData);    
  79.         pdata -> window = window;
  80.         pdata -> text = text;
  81.  
  82.     /* Here we get the `GPid pid` from the `cmd` statement and convert
  83.     it to a gint using the `g_ascii_strtoll ()` function. */
  84.     while (fgets (result, sizeof (result), cmd) != NULL)
  85.     {
  86.         pid = g_ascii_strtoll (result, NULL, 10);
  87.     }
  88.    
  89.     pclose (cmd);
  90.  
  91.     /* Check to see if server is already started. If it is we call
  92.     `dsp_init ()` to create this program as a JACK client and obtain
  93.     cpu load. */
  94.     check_pid = kill (pid, 0);
  95.     if (check_pid == 0)
  96.     {
  97.         dsp_init (jack_switch, pid);
  98.     }
  99.  
  100.     gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), jack_switch);
  101.  
  102.     gtk_widget_set_valign (jack_switch, GTK_ALIGN_CENTER);
  103.    
  104.     gjackctl_settings (window, app, header_bar);
  105.     //connections (vbox);
  106.    
  107.    
  108.    
  109.     /* Initiate tooltip for `jack_switch` here or else it won't show when
  110.     app first starts. */
  111.     if (check == TRUE)
  112.     {  
  113.         gtk_widget_set_tooltip_text (GTK_WIDGET (jack_switch),
  114.                                      "Shutdown Server");
  115.     }
  116.     else
  117.     {
  118.         gtk_widget_set_tooltip_text (GTK_WIDGET (jack_switch),
  119.                                      "Start Server");  
  120.     }
  121.  
  122.     g_signal_connect (jack_switch,
  123.                       "notify::active",
  124.                       G_CALLBACK (switch_pos_cb),
  125.                       pdata);
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement