summaryrefslogtreecommitdiff
path: root/setup.c
blob: c69dbc4374ccc9c9625236f4886708328904471e (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * sndctl  -  a plugin for the Video Disk Recorder
 *        file: setup.c
 * description: management of setup configuration
 *
 *      author: Thomas Hildebrandt <toxym@web.de>
 *
 * inspired by and reengineered from 'avolctl'
 * thanks to Martin Prochnow <nordlichtl@martins-kabuff.de>
 */

#include "defaults.h"
#include "setup.h"
#include "soundset.h"

/*********************************************************
 * member functions for class cSetupSndctl
 *********************************************************/

/*
 * constructor
 */
cSetupSndctl::cSetupSndctl(){
  dsyslog( "sndctl (cSetupSndctl::cSetupSndctl): cSetupSndctl created" );

  // create all possible setup items with default values
  items[SNDCTL_SETUP_MENUNAME] = tr( SNDCTL_DEFAULT_MENUNAME );
  items[SNDCTL_SETUP_HIDEMAINMENUENTRY] = SNDCTL_DEFAULT_HIDEMAINMENUENTRY;
  items[SNDCTL_SETUP_DEFAULT_SSET] = SNDCTL_DEFAULT_DEFAULT_SSET;
  items[SNDCTL_SETUP_INIT_VOLUME] = SNDCTL_DEFAULT_INIT_VOLUME;
  items[SNDCTL_SETUP_DD_AUTO_SWITCH] = SNDCTL_DEFAULT_DD_AUTO_SWITCH;
  items[SNDCTL_SETUP_DD_AUTO_SSET] = SNDCTL_DEFAULT_DD_AUTO_SSET;
  items[SNDCTL_SETUP_SOUNDFLASH] = SNDCTL_DEFAULT_SOUNDFLASH;
  items[SNDCTL_SETUP_SOUNDFLASH_DELTA] = SNDCTL_DEFAULT_SOUNDFLASH_DELTA;
  items[SNDCTL_SETUP_SOUNDFLASH_VOL] = SNDCTL_DEFAULT_SOUNDFLASH_VOL;
  items[SNDCTL_SETUP_SOUNDFLASH_TIME] = SNDCTL_DEFAULT_SOUNDFLASH_TIME;
  items[SNDCTL_SETUP_MUTE_ON_END] = SNDCTL_DEFAULT_MUTE_ON_END;
}

/*
 * returns a setup value
 */
string cSetupSndctl::Get( string Name ){
  if( items.find( Name ) != items.end())
    return items[Name];

  // default return value is NULL
  return NULL;
}

/*
 * returns a setup value as bool
 */
bool cSetupSndctl::GetBool( string Name ){
  return ( Get( Name ) == "yes" ) ? true : false;
}

/*
 * returns a setup value as integer
 */
int cSetupSndctl::GetInt( string Name ){
  return atoi( Get( Name ).c_str());
}

/*
 * set a setup value
 */
bool cSetupSndctl::Set( string Name, string Value, cSoundMan *Soundman ){
  bool         result;
  cSoundSet    *sset;
  unsigned int div;

  dsyslog( "sndctl (cSetupSndctl::Set): Receiving parameter '%s' with value '%s'.", Name.c_str(), Value.c_str() );

  // save this parameter
  parameters.push_back( Name );

  // lets assume the worst case ;-)
  result = false;

  // first check for a general option
  if( result = (items.find( Name ) != items.end())){
    // save this item
    items[Name] = Value;

    // take special care for SNDCTL_DEFAULT_DD_AUTO_SSET
    if( Name == SNDCTL_SETUP_DEFAULT_SSET &&
        items[SNDCTL_SETUP_DD_AUTO_SSET].empty())
      items[SNDCTL_SETUP_DD_AUTO_SSET] = Value;
  }

  // assuming this value belongs to a soundset
  // we need a '_' in 'Name' to deal with this
  else if(( div = Name.find_first_of( '_' )) != string::npos ){
    // get sound set for this ID (it's up to the first '_')
    sset = Soundman->GetSoundSet( Name.substr( 0, div ));

    // set value
    result = sset->Set( Name.substr( div + 1 ), Value );
  }

  // nothing of all, that's bad
  return result;
}

/*
 * store all setup values
 */
bool cSetupSndctl::Store( cPluginSndctl *Plugin ){
  vector<string>::iterator it;

  // first, remove all parameters
  for( it = parameters.begin(); it != parameters.end(); it++ ){
    dsyslog( "sndctl (cSetupSndctl::Store): Removing: %s", (*it).c_str());
    Plugin->Store( *it, string() );
  }

  // store all general settings
  Plugin->Store( string( SNDCTL_SETUP_MENUNAME ), Get( SNDCTL_SETUP_MENUNAME ));
  Plugin->Store( string( SNDCTL_SETUP_HIDEMAINMENUENTRY ), Get( SNDCTL_SETUP_HIDEMAINMENUENTRY ));
  Plugin->Store( string( SNDCTL_SETUP_DEFAULT_SSET ), Get( SNDCTL_SETUP_DEFAULT_SSET ));
  Plugin->Store( string( SNDCTL_SETUP_INIT_VOLUME ), Get( SNDCTL_SETUP_INIT_VOLUME ));
  Plugin->Store( string( SNDCTL_SETUP_DD_AUTO_SWITCH ), Get( SNDCTL_SETUP_DD_AUTO_SWITCH ));
  Plugin->Store( string( SNDCTL_SETUP_DD_AUTO_SSET ), Get( SNDCTL_SETUP_DD_AUTO_SSET ));
  Plugin->Store( string( SNDCTL_SETUP_SOUNDFLASH ), Get( SNDCTL_SETUP_SOUNDFLASH ));
  Plugin->Store( string( SNDCTL_SETUP_SOUNDFLASH_DELTA ), Get( SNDCTL_SETUP_SOUNDFLASH_DELTA ));
  Plugin->Store( string( SNDCTL_SETUP_SOUNDFLASH_VOL ), Get( SNDCTL_SETUP_SOUNDFLASH_VOL ));
  Plugin->Store( string( SNDCTL_SETUP_SOUNDFLASH_TIME ), Get( SNDCTL_SETUP_SOUNDFLASH_TIME ));
  Plugin->Store( string( SNDCTL_SETUP_MUTE_ON_END ), Get( SNDCTL_SETUP_MUTE_ON_END ));

  // store all settings from all soundsets
  Plugin->GetSoundManager()->Store( Plugin );

  return true;
}