Advertisement
Guest User

ponymix

a guest
Nov 19th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.04 KB | None | 0 0
  1. diff --git a/ponymix.cc b/ponymix.cc
  2. index dfe29ec..283be34 100644
  3. --- a/ponymix.cc
  4. +++ b/ponymix.cc
  5. @@ -52,6 +52,7 @@ struct Color {
  6.  
  7.  static enum DeviceType opt_devtype;
  8.  static bool opt_listrestrict;
  9. +static bool shirt;
  10.  static const char* opt_action;
  11.  static const char* opt_device;
  12.  static const char* opt_card;
  13. @@ -109,7 +110,7 @@ static Device* string_to_device_or_die(PulseClient& ponymix,
  14.    return device;
  15.  }
  16.  
  17. -static void Print(const Device& device, bool shirt) {
  18. +static void Print(const Device& device) {
  19.    if (shirt) {
  20.      printf("%s\t%d\t%s\t%s\n",
  21.             type_to_string(device.Type()),
  22. @@ -153,7 +154,7 @@ static void Print(const Device& device, bool shirt) {
  23.           color.reset);
  24.  }
  25.  
  26. -static void Print(const Card& card, bool shirt) {
  27. +static void Print(const Card& card) {
  28.    if (shirt) {
  29.      printf("%s\n", card.Name().c_str());
  30.      return;
  31. @@ -170,7 +171,7 @@ static void Print(const Card& card, bool shirt) {
  32.           card.ActiveProfile().name.c_str());
  33.  }
  34.  
  35. -static void Print(const Profile& profile, bool active, bool shirt) {
  36. +static void Print(const Profile& profile, bool active) {
  37.    if (shirt) {
  38.      printf("%s\n", profile.name.c_str());
  39.      return;
  40. @@ -190,48 +191,32 @@ static void Print(const Profile& profile, bool active, bool shirt) {
  41.  
  42.  static int ShowDefaults(PulseClient& ponymix, int, char*[]) {
  43.    const auto& info = ponymix.GetDefaults();
  44. -  Print(*ponymix.GetSink(info.sink), false);
  45. -  Print(*ponymix.GetSource(info.source), false);
  46. +  Print(*ponymix.GetSink(info.sink));
  47. +  Print(*ponymix.GetSource(info.source));
  48.    return 0;
  49.  }
  50.  
  51. -static int list_devices(PulseClient& ponymix, bool shirt) {
  52. +static int List(PulseClient& ponymix, int, char*[]) {
  53.    if (opt_listrestrict) {
  54. -    for (const auto& d : ponymix.GetDevices(opt_devtype)) Print(d, shirt);
  55. +    for (const auto& d : ponymix.GetDevices(opt_devtype)) Print(d);
  56.      return 0;
  57.    }
  58.  
  59. -  for (const auto& s : ponymix.GetSinks()) Print(s, shirt);
  60. -  for (const auto& s : ponymix.GetSources()) Print(s, shirt);
  61. -  for (const auto& s : ponymix.GetSinkInputs()) Print(s, shirt);
  62. -  for (const auto& s : ponymix.GetSourceOutputs()) Print(s, shirt);
  63. +  for (const auto& s : ponymix.GetSinks()) Print(s);
  64. +  for (const auto& s : ponymix.GetSources()) Print(s);
  65. +  for (const auto& s : ponymix.GetSinkInputs()) Print(s);
  66. +  for (const auto& s : ponymix.GetSourceOutputs()) Print(s);
  67.  
  68.    return 0;
  69.  }
  70.  
  71. -static int List(PulseClient& ponymix, int, char*[]) {
  72. -  return list_devices(ponymix, false);
  73. -}
  74. -
  75. -static int ListShort(PulseClient& ponymix, int, char*[]) {
  76. -  return list_devices(ponymix, true);
  77. -}
  78. -
  79. -static int list_cards(PulseClient& ponymix, bool shirt) {
  80. +static int ListCards(PulseClient& ponymix, int, char*[]) {
  81.    const auto& cards = ponymix.GetCards();
  82. -  for (const auto& c : cards) Print(c, shirt);
  83. +  for (const auto& c : cards) Print(c);
  84.  
  85.    return 0;
  86.  }
  87.  
  88. -static int ListCards(PulseClient& ponymix, int, char*[]) {
  89. -  return list_cards(ponymix, false);
  90. -}
  91. -
  92. -static int ListCardsShort(PulseClient& ponymix, int, char*[]) {
  93. -  return list_cards(ponymix, true);
  94. -}
  95. -
  96.  static Card* resolve_active_card_or_die(PulseClient& ponymix) {
  97.    Card* card;
  98.    if (opt_card == nullptr) {
  99. @@ -248,24 +233,13 @@ static Card* resolve_active_card_or_die(PulseClient& ponymix) {
  100.    return card;
  101.  }
  102.  
  103. -static int list_profiles(PulseClient& ponymix, bool shirt) {
  104. +static int ListProfiles(PulseClient& ponymix, int, char*[]) {
  105.    auto card = resolve_active_card_or_die(ponymix);
  106.  
  107.    const auto& profiles = card->Profiles();
  108. -  for (const auto& p : profiles) Print(p,
  109. -                                       p.name == card->ActiveProfile().name,
  110. -                                       shirt);
  111. -
  112. -  return 0;
  113. -}
  114. +  for (const auto& p : profiles) Print(p, p.name == card->ActiveProfile().name);
  115.  
  116. -static int ListProfiles(PulseClient& ponymix, int, char*[]) {
  117. -  return list_profiles(ponymix, false);
  118. -}
  119. -
  120. -static int ListProfilesShort(PulseClient& ponymix, int, char*[]) {
  121. -  return list_profiles(ponymix, true);
  122. -}
  123. +  return 0;}
  124.  
  125.  static int GetVolume(PulseClient& ponymix, int, char*[]) {
  126.    auto device = string_to_device_or_die(ponymix, opt_device, opt_devtype);
  127. @@ -428,11 +402,8 @@ static const std::pair<const string, const Command>& string_to_command(
  128.      // command name            function         arg min  arg max
  129.      { "defaults",            { ShowDefaults,        { 0, 0 } } },
  130.      { "list",                { List,                { 0, 0 } } },
  131. -    { "list-short",          { ListShort,           { 0, 0 } } },
  132.      { "list-cards",          { ListCards,           { 0, 0 } } },
  133. -    { "list-cards-short",    { ListCardsShort,      { 0, 0 } } },
  134.      { "list-profiles",       { ListProfiles,        { 0, 0 } } },
  135. -    { "list-profiles-short", { ListProfilesShort,   { 0, 0 } } },
  136.      { "get-volume",          { GetVolume,           { 0, 0 } } },
  137.      { "set-volume",          { SetVolume,           { 1, 1 } } },
  138.      { "get-balance",         { GetBalance,          { 0, 0 } } },
  139. @@ -501,6 +472,7 @@ static void usage() {
  140.          " -t, --devtype TYPE      device type\n"
  141.          " -N, --notify            use libnotify to announce volume changes\n"
  142.          "     --max-volume VALUE  use VALUE as max volume\n"
  143. +        "     --short             output brief lists\n"
  144.          "     --source            alias to -t source\n"
  145.          "     --input             alais to -t source\n"
  146.          "     --sink              alias to -t sink\n"
  147. @@ -513,9 +485,7 @@ static void usage() {
  148.          "  defaults               list default devices (default command)\n"
  149.          "  set-default            set default device by ID\n"
  150.          "  list                   list available devices\n"
  151. -        "  list-short             list available devices (short form)\n"
  152.          "  list-cards             list available cards\n"
  153. -        "  list-cards-short       list available cards (short form)\n"
  154.          "  get-volume             get volume for device\n"
  155.          "  set-volume VALUE       set volume for device\n"
  156.          "  get-balance            get balance for device\n"
  157. @@ -533,8 +503,6 @@ static void usage() {
  158.  
  159.    fputs("\nCard Commands:\n"
  160.          "  list-profiles          list available profiles for a card\n"
  161. -        "  list-profiles-short    list available profiles for a card"
  162. -                                  "(short form)\n"
  163.          "  get-profile            get active profile for card\n"
  164.          "  set-profile PROFILE    set profile for a card\n", stdout);
  165.  
  166. @@ -586,6 +554,7 @@ bool parse_options(int argc, char** argv) {
  167.      { "sink-input",     no_argument,       0, 0x104 },
  168.      { "source-output",  no_argument,       0, 0x105 },
  169.      { "max-volume",     required_argument, 0, 0x106 },
  170. +    { "short",          no_argument,       0, 0x107 },
  171.      { 0, 0, 0, 0 },
  172.    };
  173.  
  174. @@ -639,6 +608,9 @@ bool parse_options(int argc, char** argv) {
  175.          return false;
  176.        }
  177.        break;
  178. +    case 0x107:
  179. +      shirt = true;
  180. +      break;
  181.      default:
  182.        return false;
  183.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement