added a default for the serial device (this should make life easier when you

upgrade from an earlier version); and added a gui for configuring it
This commit is contained in:
fgerlits 2007-02-02 12:39:33 +00:00
parent 738ecfd77b
commit 75c77d8a3a
7 changed files with 107 additions and 15 deletions

View File

@ -87,7 +87,8 @@ class OptionsContainer
storagePath,
schedulerServer,
schedulerPort,
schedulerPath } OptionItemString;
schedulerPath,
serialDeviceName } OptionItemString;
private:
@ -167,6 +168,23 @@ class OptionsContainer
getNode(const Glib::ustring & xPath)
throw (std::invalid_argument);
/**
* Create a node corresponding to an option item.
*
* So far, this is only implemented for serialDeviceName;
* for all other option items, it returns a 0 pointer.
* The XML element or attribute is created with a value of "".
*
* TODO: implement this properly; ideally, the paths would be read
* from the DTD of the default config file, and added to the current
* config file as needed.
*
* @param optionItem the option item to be created.
* @return a pointer to the node created, or 0.
*/
xmlpp::Node *
createNode(OptionItemString optionItem) throw ();
public:
/**

View File

@ -87,6 +87,10 @@ OptionsContainer :: setOptionItem(OptionItemString optionItem,
bool isAttribute = false; // text node or attr node
xmlpp::Node * targetNode = selectNode(optionItem, isAttribute);
if (!targetNode) {
targetNode = createNode(optionItem);
}
if (isAttribute) {
xmlpp::Attribute * attr = dynamic_cast<xmlpp::Attribute*>(targetNode);
if (attr != 0) {
@ -287,6 +291,11 @@ OptionsContainer :: selectNode(OptionItemString optionItem,
"schedulerDaemonXmlRpcClient/@xmlRpcUri");
isAttribute = true;
break;
case serialDeviceName :
targetNode = getNode("serialPort/@path");
isAttribute = true;
break;
}
return targetNode;
@ -337,6 +346,35 @@ OptionsContainer :: getNode(const Glib::ustring & xPath)
}
/*------------------------------------------------------------------------------
* Create the node corresponding to an OptionItemString value.
*----------------------------------------------------------------------------*/
xmlpp::Node *
OptionsContainer :: createNode(OptionItemString optionItem) throw ()
{
xmlpp::Element * rootNode = optionsDocument.get_root_node();
// only supports the serialDeviceName option item, for now
switch (optionItem) {
case serialDeviceName :
xmlpp::Element * element = dynamic_cast<xmlpp::Element*>(
getNode("serialPort"));
if (!element) {
element = rootNode->add_child("serialPort");
}
xmlpp::Node * attribute = dynamic_cast<xmlpp::Attribute*>(
getNode("serialPort/@path"));
if (!attribute) {
attribute = element->set_attribute("path", "");
}
return attribute;
default:
return 0;
}
}
/*------------------------------------------------------------------------------
* Save the options to a file.
*----------------------------------------------------------------------------*/

View File

@ -183,10 +183,14 @@ const std::string authenticationNotReachableKey =
const std::string localeNotAvailableKey = "localeNotAvailableMsg";
/*------------------------------------------------------------------------------
* The default serial device
* The name of the config element for the serial device
*----------------------------------------------------------------------------*/
const std::string serialPortConfigElementName = "serialPort";
/*------------------------------------------------------------------------------
* The default serial device
*----------------------------------------------------------------------------*/
const std::string serialPortDefaultDevice = "/dev/ttyS0";
}
/* =============================================== local function prototypes */
@ -405,12 +409,11 @@ GLiveSupport :: configure(const xmlpp::Element & element)
// read the serial port's file name
nodes = element.get_children(serialPortConfigElementName);
if (nodes.size() < 1) {
throw std::invalid_argument("no serial port element");
Ptr<const Glib::ustring>::Ref serialDevice(new const Glib::ustring(
serialPortDefaultDevice));
optionsContainer->setOptionItem(OptionsContainer::serialDeviceName,
serialDevice);
}
const xmlpp::Element* serialPortElement
= dynamic_cast<const xmlpp::Element*>(nodes.front());
serialDevice.reset(new std::string(serialPortElement->get_attribute("path")
->get_value() ));
}
@ -1805,6 +1808,9 @@ LiveSupport :: GLiveSupport ::
GLiveSupport :: writeToSerial(Ptr<const Glib::ustring>::Ref message)
throw ()
{
Ptr<const Glib::ustring>::Ref
serialDevice = optionsContainer->getOptionItem(
OptionsContainer::serialDeviceName);
try {
serialStream->Open(*serialDevice);
(*serialStream) << *message;

View File

@ -266,11 +266,6 @@ class GLiveSupport : public LocalizedConfigurable,
*/
Ptr<Glib::ustring>::Ref schedulerDaemonStopCommand;
/**
* The serial device.
*/
Ptr<std::string>::Ref serialDevice;
/**
* The serial stream object.
*/

View File

@ -60,6 +60,20 @@ RdsView :: RdsView (Ptr<GLiveSupport>::Ref gLiveSupport,
: LocalizedObject(bundle),
gLiveSupport(gLiveSupport)
{
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
Gtk::Label * deviceLabel;
try {
deviceLabel = Gtk::manage(new Gtk::Label(*getResourceUstring(
"deviceLabel" )));
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;
std::exit(1);
}
deviceEntryBin = Gtk::manage(wf->createEntryBin());
Gtk::Box * deviceBox = Gtk::manage(new Gtk::HBox());
deviceBox->pack_start(*deviceLabel, Gtk::PACK_SHRINK, 5);
deviceBox->pack_start(*deviceEntryBin, Gtk::PACK_EXPAND_WIDGET, 5);
Ptr<RdsEntry>::Ref psEntry(new RdsEntry(getBundle(), "PS", 8));
Ptr<RdsEntry>::Ref piEntry(new RdsEntry(getBundle(), "PI", 4));
Ptr<RdsEntry>::Ref rtEntry(new RdsEntry(getBundle(), "RT", 32));
@ -68,9 +82,10 @@ RdsView :: RdsView (Ptr<GLiveSupport>::Ref gLiveSupport,
rdsEntryList.push_back(piEntry);
rdsEntryList.push_back(rtEntry);
pack_start(*psEntry, Gtk::PACK_SHRINK, 10);
pack_start(*piEntry, Gtk::PACK_SHRINK, 0);
pack_start(*rtEntry, Gtk::PACK_SHRINK, 10);
pack_start(*deviceBox, Gtk::PACK_SHRINK, 5);
pack_start(*psEntry, Gtk::PACK_SHRINK, 5);
pack_start(*piEntry, Gtk::PACK_SHRINK, 5);
pack_start(*rtEntry, Gtk::PACK_SHRINK, 5);
reset();
}
@ -84,6 +99,16 @@ RdsView :: saveChanges(void) throw ()
{
bool touched = false;
Ptr<OptionsContainer>::Ref options = gLiveSupport->getOptionsContainer();
Ptr<const Glib::ustring>::Ref oldDevice = options->getOptionItem(
OptionsContainer::serialDeviceName);
Ptr<const Glib::ustring>::Ref newDevice(new const Glib::ustring(
deviceEntryBin->get_text() ));
if (*oldDevice != *newDevice) {
options->setOptionItem(OptionsContainer::serialDeviceName, newDevice);
touched = true;
}
RdsEntryListType::const_iterator it;
for (it = rdsEntryList.begin(); it != rdsEntryList.end(); ++it) {
Ptr<RdsEntry>::Ref rdsEntry = *it;
@ -100,6 +125,10 @@ RdsView :: saveChanges(void) throw ()
void
RdsView :: reset(void) throw ()
{
Ptr<OptionsContainer>::Ref options = gLiveSupport->getOptionsContainer();
deviceEntryBin->set_text(*options->getOptionItem(
OptionsContainer::serialDeviceName));
RdsEntryListType::const_iterator it;
for (it = rdsEntryList.begin(); it != rdsEntryList.end(); ++it) {
fillEntry(*it);

View File

@ -119,6 +119,11 @@ class RdsView : public Gtk::VBox,
*/
Ptr<GLiveSupport>::Ref gLiveSupport;
/**
* The entry field for the serial device.
*/
EntryBin * deviceEntryBin;
public:
/**

View File

@ -357,6 +357,7 @@ root:table
rdsView:table
{
deviceLabel:string { "Serial port: " }
PSrdsLabel:string { "Station name:" }
PIrdsLabel:string { "Station code:" }
RTrdsLabel:string { "Clip info:" }