Advertisement
Guest User

Untitled

a guest
Oct 18th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(sscanf (buff,"%s %s %s %d %d %d %d %d",isEnabled,region,format,&layer,&x,&y,&width,&height) > 0)
  82.                     {  
  83.             char base[256];
  84.             char* pBase = base;
  85.             pBase = "sudo -n /usr/pandora/scripts/op_tvout.sh -";
  86.             if(isEnabled == "True")
  87.             {
  88.                             isEnabled[0] = 't';
  89.             }
  90.             else
  91.             {
  92.                             isEnabled[0] = 'f';
  93.             }
  94.             isEnabled[1] = '\0';
  95.             sprintf(internal->command, "%s%s %s -c %s -l %d",/* %d %d %d %d",*/base,isEnabled,region,format,layer);/*,x,y,width,height);      */              
  96.                     }
  97.                     sub->internal = internal;
  98.                     info->submenu = sub;
  99.                 }        
  100.                ++i;
  101.             }
  102.             fclose(file);
  103.         }
  104.         else    // Backup plan
  105.         {
  106.            for (i = 5; i >= 0; i--) {
  107.                     sub = malloc(sizeof(struct PLUGIN_SUBMENU));
  108.                     sub->next = info->submenu;
  109.                     sub->label = label[i];
  110.                     sub->icon_path = "/usr/share/icons/pandora/tvout.png";
  111.                     sub->visible = 1;
  112.                     internal = malloc(sizeof(INTERNAL));
  113.                     internal->tvout_mode = i;
  114.                     sub->internal = internal;
  115.                     info->submenu = sub;
  116.                 }        
  117.         }  
  118.     }
  119.  
  120.     info->label = "TV-out";
  121.     info->icon_path = "/usr/share/icons/pandora/tvout.png";
  122.    
  123.     info->sort_hint = 10;
  124.  
  125.     return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement