Advertisement
Guest User

tvout.c plugin

a guest
Sep 15th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.76 KB | None | 0 0
  1. #include "../include/configbutton.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct {
  6.     int     tvout_mode;
  7.     char    command[256];
  8. } INTERNAL;
  9.  
  10.  
  11. const char *label[32] = { "PAL, Main Layer", "PAL, HW Scaler", "NTSC, Main Layer", "NTSC, HW Scaler", "Disable TV-out", "Configure TV-out" };
  12.  
  13.  
  14. int activate(void *internal) {
  15.     INTERNAL *ip = internal;
  16.     system(ip->command);
  17.     /*switch (ip->tvout_mode) {
  18.         case 0:         // PAL, Layer 0
  19.             system("sudo -n /usr/pandora/scripts/op_tvout.sh -t pal -l 0");
  20.             break;
  21.         case 1:         // PAL, Layer 1
  22.             system("sudo -n /usr/pandora/scripts/op_tvout.sh -t pal -l 1");
  23.             break;
  24.         case 2:         // NTSC, Layer 0
  25.             system("sudo -n /usr/pandora/scripts/op_tvout.sh -t ntsc -l 0");
  26.             break;
  27.         case 3:         // NTSC, Layer 1
  28.             system("sudo -n /usr/pandora/scripts/op_tvout.sh -t ntsc -l 1");
  29.             break;
  30.         case 4:         // Disable
  31.             system("sudo -n /usr/pandora/scripts/op_tvout.sh -d");
  32.             break;
  33.         default:        // Configure
  34.             system("/usr/pandora/scripts/TVoutConfig.py &");
  35.             break;
  36.     }*/
  37.    
  38.     return 0;
  39. }
  40.  
  41.  
  42. int getinfo(PLUGIN_INFO *info) {
  43.     int i;
  44.     struct PLUGIN_SUBMENU *sub;
  45.     INTERNAL *internal;
  46.    
  47.     if (info->submenu == NULL) {
  48.         info->label = malloc(128);
  49.         //  Open TV-Out profile
  50.         FILE * file;
  51.         file = fopen("/etc/pandora/conf/tvout-profiles.conf", "r");
  52.         char buff[256];
  53.         if(file)
  54.         {
  55.             i = 0; int modeCount = 0;
  56.            while( fgets(buff, sizeof (buff), file) != NULL )
  57.             {
  58.                
  59.                 //  If an even line it's a labal
  60.                 if((i % 2) == 0)
  61.                 {
  62.                     sub = malloc(sizeof(struct PLUGIN_SUBMENU));
  63.                     sub->next = info->submenu;
  64.                     sub->icon_path = "/usr/share/icons/pandora/tvout.png";
  65.                     sub->visible = 1;
  66.                     sub->label = buff;
  67.                 }
  68.                 else    //  It's a command!
  69.                 {  
  70.                     internal = malloc(sizeof(INTERNAL));
  71.                     internal->tvout_mode = modeCount++;
  72.                     //  We now need to build the command
  73.                     char isEnabled[5];
  74.                     char region[4];
  75.                     char format[10];
  76.                     int layer;
  77.                     int x;
  78.                     int y;
  79.                     int width;
  80.                     int height;
  81.                     if(scanf ("%s %s %s %d %d %d %d %d",isEnabled,region,format,layer,x,y,width,height) > 0)
  82.                     {  
  83.                         char base[256];
  84.                         base = "sudo -n /usr/pandora/scripts/op_tvout.sh -";
  85.                         if(isEnabled == "True")
  86.                             isEnabled = "t";
  87.                         else
  88.                             isEnabled = "f";
  89.                         sprintf(internal->command, "%s%s %s -c %s -l %d",/* %d %d %d %d",*/base,isEnabled,region,format,layer);/*,x,y,width,height);      */              
  90.                     }
  91.                     sub->internal = internal;
  92.                     info->submenu = sub;
  93.                 }        
  94.                ++i;
  95.             }
  96.             fclose(file);
  97.         }
  98.         else    // Backup plan
  99.         {
  100.            for (i = 5; i >= 0; i--) {
  101.                     sub = malloc(sizeof(struct PLUGIN_SUBMENU));
  102.                     sub->next = info->submenu;
  103.                     sub->label = label[i];
  104.                     sub->icon_path = "/usr/share/icons/pandora/tvout.png";
  105.                     sub->visible = 1;
  106.                     internal = malloc(sizeof(INTERNAL));
  107.                     internal->tvout_mode = i;
  108.                     sub->internal = internal;
  109.                     info->submenu = sub;
  110.                 }        
  111.         }  
  112.     }
  113.  
  114.     info->label = "TV-out";
  115.     info->icon_path = "/usr/share/icons/pandora/tvout.png";
  116.    
  117.     info->sort_hint = 10;
  118.  
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement