added Servers tab;

refactored a bit to reduce the amount of copy-paste code;
improved the spacings
This commit is contained in:
fgerlits 2006-01-24 14:31:10 +00:00
parent 7b7bd4bb9b
commit 60e45ea3b1
5 changed files with 337 additions and 109 deletions

View file

@ -76,22 +76,8 @@ OptionsContainer :: setOptionItem(OptionItemString optionItem,
Ptr<const Glib::ustring>::Ref value)
throw (std::invalid_argument)
{
xmlpp::Node * targetNode = 0;
bool isAttribute = false; // text node or attr node
switch (optionItem) {
case outputPlayerDeviceName :
targetNode = getNode("outputPlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
case cuePlayerDeviceName :
targetNode = getNode("cuePlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
}
xmlpp::Node * targetNode = selectNode(optionItem, isAttribute);
if (isAttribute) {
xmlpp::Attribute * attr = dynamic_cast<xmlpp::Attribute*>(targetNode);
@ -120,22 +106,8 @@ Ptr<Glib::ustring>::Ref
OptionsContainer :: getOptionItem(OptionItemString optionItem)
throw (std::invalid_argument)
{
const xmlpp::Node * targetNode = 0;
bool isAttribute = false; // child text node or attr
switch (optionItem) {
case outputPlayerDeviceName :
targetNode = getNode("outputPlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
case cuePlayerDeviceName :
targetNode = getNode("cuePlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
}
bool isAttribute = false; // text node or attr node
const xmlpp::Node * targetNode = selectNode(optionItem, isAttribute);
if (isAttribute) {
const xmlpp::Attribute *
@ -159,6 +131,70 @@ OptionsContainer :: getOptionItem(OptionItemString optionItem)
}
/*------------------------------------------------------------------------------
* Find the node corresponding to an OptionItemString value.
*----------------------------------------------------------------------------*/
xmlpp::Node *
OptionsContainer :: selectNode(OptionItemString optionItem,
bool & isAttribute)
throw (std::invalid_argument)
{
xmlpp::Node * targetNode = 0;
switch (optionItem) {
case outputPlayerDeviceName :
targetNode = getNode("outputPlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
case cuePlayerDeviceName :
targetNode = getNode("cuePlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
case authenticationServer :
targetNode = getNode("authenticationClientFactory/"
"webAuthentication/location/@server");
isAttribute = true;
break;
case authenticationPort :
targetNode = getNode("authenticationClientFactory/"
"webAuthentication/location/@port");
isAttribute = true;
break;
case authenticationPath :
targetNode = getNode("authenticationClientFactory/"
"webAuthentication/location/@path");
isAttribute = true;
break;
case storageServer :
targetNode = getNode("storageClientFactory/"
"webStorage/location/@server");
isAttribute = true;
break;
case storagePort :
targetNode = getNode("storageClientFactory/"
"webStorage/location/@port");
isAttribute = true;
break;
case storagePath :
targetNode = getNode("storageClientFactory/"
"webStorage/location/@path");
isAttribute = true;
break;
}
return targetNode;
}
/*------------------------------------------------------------------------------
* Return the first node matching an XPath string.
*----------------------------------------------------------------------------*/

View file

@ -68,6 +68,25 @@ using namespace LiveSupport::Core;
*/
class OptionsContainer
{
public:
/**
* The list of string options one can set.
*
* These are options of type Glib::ustring; any string is accepted
* as value, no range checking is done.
*
* For the moment, this is the only kind of option supported.
*/
typedef enum { outputPlayerDeviceName,
cuePlayerDeviceName,
authenticationServer,
authenticationPort,
authenticationPath,
storageServer,
storagePort,
storagePath } OptionItemString;
private:
/**
* The XML document containing the options.
@ -91,6 +110,24 @@ class OptionsContainer
{
}
/**
* Find the node corresponding to an OptionItemString value.
*
* If there is no matching node, it returns a 0 pointer.
*
* @param optionItem the name of the item to find the node for
* @param isAttribute return parameter; is set to true if the
* node is an attribute, false if it's
* a CDATA text
* @return a pointer to the node found, or 0
* @exception std::invalid_argument thrown by getNode() [should
* never happen]
*/
xmlpp::Node *
selectNode(OptionItemString optionItem,
bool & isAttribute)
throw (std::invalid_argument);
/**
* Return the first node matching an XPath string.
*
@ -98,6 +135,7 @@ class OptionsContainer
*
* @param xPath the XPath of the node (from the root node)
* @return a pointer to the node found, or 0
* @exception std::invalid_argument if the XPath is not well formed
*/
xmlpp::Node *
getNode(const Glib::ustring & xPath)
@ -131,17 +169,6 @@ class OptionsContainer
return changed;
}
/**
* The list of string options one can set.
*
* These are options of type Glib::ustring; any string is accepted
* as value, no range checking is done.
*
* For the moment, this is the only kind of option supported.
*/
typedef enum { outputPlayerDeviceName,
cuePlayerDeviceName } OptionItemString;
/**
* Set a string type option.
*

View file

@ -89,11 +89,14 @@ OptionsWindow :: OptionsWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
// build up the notepad for the various sections
mainNotebook = Gtk::manage(new ScrolledNotebook);
Gtk::Box * soundSectionBox = constructSoundSection();
Gtk::Box * serversSectionBox = constructServersSection();
Gtk::Box * aboutSectionBox = constructAboutSection();
try {
mainNotebook->appendPage(*soundSectionBox,
*getResourceUstring("soundSectionLabel"));
mainNotebook->appendPage(*serversSectionBox,
*getResourceUstring("serversSectionLabel"));
mainNotebook->appendPage(*aboutSectionBox,
*getResourceUstring("aboutSectionLabel"));
@ -142,7 +145,7 @@ OptionsWindow :: OptionsWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
// show everything
set_name(windowName);
set_default_size(350, 300);
set_default_size(500, 400);
set_modal(false);
property_window_position().set_value(Gtk::WIN_POS_NONE);
@ -169,29 +172,24 @@ OptionsWindow :: onApplyButtonClicked(void) throw ()
Ptr<OptionsContainer>::Ref
optionsContainer = gLiveSupport->getOptionsContainer();
// check for changes in the Sound tab
Ptr<const Glib::ustring>::Ref
oldCueDevice = optionsContainer->getOptionItem(
OptionsContainer::cuePlayerDeviceName );
Ptr<const Glib::ustring>::Ref
newCueDevice(new Glib::ustring(cuePlayerEntry->get_text()));
StringEntryListType::const_iterator it;
for (it = stringEntryList.begin(); it != stringEntryList.end(); ++it) {
if (*oldCueDevice != *newCueDevice) {
optionsContainer->setOptionItem(
OptionsContainer::cuePlayerDeviceName,
newCueDevice );
OptionsContainer::OptionItemString optionItem = it->first;
EntryBin * entry = it->second;
Ptr<const Glib::ustring>::Ref
oldValue = optionsContainer->getOptionItem(optionItem);
Ptr<const Glib::ustring>::Ref
newValue(new Glib::ustring(entry->get_text()));
if (*oldValue != *newValue) {
try {
optionsContainer->setOptionItem(optionItem, newValue);
} catch (std::invalid_argument &e) {
// TODO: signal error
}
}
Ptr<const Glib::ustring>::Ref
oldOutputDevice = optionsContainer->getOptionItem(
OptionsContainer::outputPlayerDeviceName );
Ptr<const Glib::ustring>::Ref
newOutputDevice(new Glib::ustring(outputPlayerEntry->get_text()));
if (*oldOutputDevice != *newOutputDevice) {
optionsContainer->setOptionItem(
OptionsContainer::outputPlayerDeviceName,
newOutputDevice );
}
}
@ -222,32 +220,29 @@ OptionsWindow :: onCloseButtonClicked(bool needConfirm) throw ()
/*------------------------------------------------------------------------------
* Construct the "About" section.
* Create a new user entry field item.
*----------------------------------------------------------------------------*/
Gtk::VBox*
OptionsWindow :: constructAboutSection(void) throw ()
EntryBin *
OptionsWindow :: createEntry(OptionsContainer::OptionItemString optionItem)
throw ()
{
Glib::ustring aboutLabelContents;
aboutLabelContents.append(PACKAGE_NAME);
aboutLabelContents.append(" ");
aboutLabelContents.append(PACKAGE_VERSION);
aboutLabelContents.append("\n\n");
Ptr<OptionsContainer>::Ref optionsContainer
= gLiveSupport->getOptionsContainer();
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
EntryBin * entry = Gtk::manage(wf->createEntryBin());
try {
aboutLabelContents.append(*formatMessage("reportBugsToText",
PACKAGE_BUGREPORT ));
entry->set_text(*optionsContainer->getOptionItem(optionItem));
} catch (std::invalid_argument &e) {
// TODO: signal error
std::cerr << e.what() << std::endl;
std::exit(1);
// TODO: signal error?
entry->set_text("");
}
Gtk::Label * aboutLabel = Gtk::manage(
new Gtk::Label(aboutLabelContents) );
// make a new box and pack the components into it
Gtk::VBox * section = Gtk::manage(new Gtk::VBox);
section->pack_start(*aboutLabel, Gtk::PACK_SHRINK, 5);
stringEntryList.push_back(std::make_pair(optionItem, entry));
return section;
return entry;
}
@ -277,11 +272,11 @@ OptionsWindow :: constructSoundSection(void) throw ()
}
Gtk::Label * cuePlayerLabel = Gtk::manage(
new Gtk::Label(cuePlayerLabelContents) );
audioDeviceTable->attach(*cuePlayerLabel, 0, 1, 0, 1);
audioDeviceTable->attach(*cuePlayerLabel,
0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 5, 0);
cuePlayerEntry = Gtk::manage(wf->createEntryBin());
cuePlayerEntry->set_text(*optionsContainer->getOptionItem(
OptionsContainer::cuePlayerDeviceName ));
EntryBin * cuePlayerEntry = createEntry(
OptionsContainer::cuePlayerDeviceName);
audioDeviceTable->attach(*cuePlayerEntry, 1, 2, 0, 1);
// display the settings for the output player device
@ -296,11 +291,11 @@ OptionsWindow :: constructSoundSection(void) throw ()
}
Gtk::Label * outputPlayerLabel = Gtk::manage(
new Gtk::Label(outputPlayerLabelContents) );
audioDeviceTable->attach(*outputPlayerLabel, 0, 1, 1, 2);
audioDeviceTable->attach(*outputPlayerLabel,
0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 5, 0);
outputPlayerEntry = Gtk::manage(wf->createEntryBin());
outputPlayerEntry->set_text(*optionsContainer->getOptionItem(
OptionsContainer::outputPlayerDeviceName ));
EntryBin * outputPlayerEntry = createEntry(
OptionsContainer::outputPlayerDeviceName);
audioDeviceTable->attach(*outputPlayerEntry, 1, 2, 1, 2);
// make a new box and pack the components into it
@ -310,3 +305,143 @@ OptionsWindow :: constructSoundSection(void) throw ()
return section;
}
/*------------------------------------------------------------------------------
* Construct the "Servers" section.
*----------------------------------------------------------------------------*/
Gtk::VBox*
OptionsWindow :: constructServersSection(void) throw ()
{
Ptr<OptionsContainer>::Ref optionsContainer
= gLiveSupport->getOptionsContainer();
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
// the settings for the authentication server
Gtk::Table * authenticationTable = Gtk::manage(new Gtk::Table);
authenticationTable->set_row_spacings(5);
authenticationTable->set_col_spacings(5);
Gtk::Label * authenticationLabel;
Gtk::Label * authenticationServerLabel;
Gtk::Label * authenticationPortLabel;
Gtk::Label * authenticationPathLabel;
try {
authenticationLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("authenticationLabel") ));
authenticationServerLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("serverLabel") ));
authenticationPortLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("portLabel") ));
authenticationPathLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("pathLabel") ));
} catch (std::invalid_argument &e) {
// TODO: signal error
std::cerr << e.what() << std::endl;
std::exit(1);
}
authenticationTable->attach(*authenticationLabel,
0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 5, 0);
authenticationTable->attach(*authenticationServerLabel,
1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
authenticationTable->attach(*authenticationPortLabel,
1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
authenticationTable->attach(*authenticationPathLabel,
1, 2, 2, 3, Gtk::SHRINK, Gtk::SHRINK);
EntryBin * authenticationServerEntry = createEntry(
OptionsContainer::authenticationServer);
EntryBin * authenticationPortEntry = createEntry(
OptionsContainer::authenticationPort);
EntryBin * authenticationPathEntry = createEntry(
OptionsContainer::authenticationPath);
authenticationTable->attach(*authenticationServerEntry, 2, 3, 0, 1);
authenticationTable->attach(*authenticationPortEntry, 2, 3, 1, 2);
authenticationTable->attach(*authenticationPathEntry, 2, 3, 2, 3);
// the settings for the storage server
Gtk::Table * storageTable = Gtk::manage(new Gtk::Table);
storageTable->set_row_spacings(5);
storageTable->set_col_spacings(5);
Gtk::Label * storageLabel;
Gtk::Label * storageServerLabel;
Gtk::Label * storagePortLabel;
Gtk::Label * storagePathLabel;
try {
storageLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("storageLabel") ));
storageServerLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("serverLabel") ));
storagePortLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("portLabel") ));
storagePathLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("pathLabel") ));
} catch (std::invalid_argument &e) {
// TODO: signal error
std::cerr << e.what() << std::endl;
std::exit(1);
}
storageTable->attach(*storageLabel,
0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 5, 0);
storageTable->attach(*storageServerLabel,
1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
storageTable->attach(*storagePortLabel,
1, 2, 1, 2, Gtk::SHRINK, Gtk::SHRINK);
storageTable->attach(*storagePathLabel,
1, 2, 2, 3, Gtk::SHRINK, Gtk::SHRINK);
EntryBin * storageServerEntry = createEntry(
OptionsContainer::storageServer);
EntryBin * storagePortEntry = createEntry(
OptionsContainer::storagePort);
EntryBin * storagePathEntry = createEntry(
OptionsContainer::storagePath);
storageTable->attach(*storageServerEntry, 2, 3, 0, 1);
storageTable->attach(*storagePortEntry, 2, 3, 1, 2);
storageTable->attach(*storagePathEntry, 2, 3, 2, 3);
// make a new box and pack the components into it
Gtk::VBox * section = Gtk::manage(new Gtk::VBox);
section->pack_start(*authenticationTable, Gtk::PACK_SHRINK, 10);
section->pack_start(*storageTable, Gtk::PACK_SHRINK, 10);
return section;
}
/*------------------------------------------------------------------------------
* Construct the "About" section.
*----------------------------------------------------------------------------*/
Gtk::VBox*
OptionsWindow :: constructAboutSection(void) throw ()
{
Glib::ustring aboutLabelContents;
aboutLabelContents.append("\n\n");
aboutLabelContents.append(PACKAGE_NAME);
aboutLabelContents.append(" ");
aboutLabelContents.append(PACKAGE_VERSION);
aboutLabelContents.append("\n\n");
try {
aboutLabelContents.append(*formatMessage("reportBugsToText",
PACKAGE_BUGREPORT ));
} catch (std::invalid_argument &e) {
// TODO: signal error
std::cerr << e.what() << std::endl;
std::exit(1);
}
Gtk::Label * aboutLabel = Gtk::manage(
new Gtk::Label(aboutLabelContents) );
// make a new box and pack the components into it
Gtk::VBox * section = Gtk::manage(new Gtk::VBox);
section->pack_start(*aboutLabel, Gtk::PACK_SHRINK, 5);
return section;
}

View file

@ -120,14 +120,15 @@ class OptionsWindow : public WhiteWindow, public LocalizedObject
Gtk::Button * okButton;
/**
* The entry field for the cue player device's name.
* The type for the list of user entry fields of string type.
*/
EntryBin * cuePlayerEntry;
typedef std::vector<std::pair<OptionsContainer::OptionItemString,
EntryBin*> > StringEntryListType;
/**
* The entry field for the output player device's name.
* The list of user entry fields of string type.
*/
EntryBin * outputPlayerEntry;
StringEntryListType stringEntryList;
/**
* The gLiveSupport object, handling the logic of the application.
@ -140,12 +141,18 @@ class OptionsWindow : public WhiteWindow, public LocalizedObject
bool isChanged;
/**
* Construct the "About" section.
* Create a new user entry field item.
*
* @return a pointer to the new box (already Gtk::manage()'ed)
* This constructs [and Gtk::manage()s] the EntryBin, and
* sets its text to the current value of the option.
* The EntryBin is then added to the list of user entry fields.
*
* @param optionItem the name of the option item for this entry
* @return the newly created EntryBin
*/
Gtk::VBox*
constructAboutSection(void) throw ();
EntryBin *
createEntry(OptionsContainer::OptionItemString optionItem)
throw ();
/**
* Construct the "Sound" section.
@ -155,6 +162,22 @@ class OptionsWindow : public WhiteWindow, public LocalizedObject
Gtk::VBox*
constructSoundSection(void) throw ();
/**
* Construct the "Servers" section.
*
* @return a pointer to the new box (already Gtk::manage()'ed)
*/
Gtk::VBox*
constructServersSection(void) throw ();
/**
* Construct the "About" section.
*
* @return a pointer to the new box (already Gtk::manage()'ed)
*/
Gtk::VBox*
constructAboutSection(void) throw ();
protected:
/**

View file

@ -221,17 +221,24 @@ root:table
{
windowTitle:string { "LiveSupport Options Window" }
aboutSectionLabel:string { "About" }
soundSectionLabel:string { "Sound" }
serversSectionLabel:string { "Servers" }
aboutSectionLabel:string { "About" }
cancelButtonLabel:string { "Cancel" }
applyButtonLabel:string { "Apply" }
okButtonLabel:string { "OK" }
reportBugsToText:string { "Report bugs to: {0}" }
cueDeviceLabel:string { "Cue audio device:" }
outputDeviceLabel:string { "Live Mode audio device:" }
authenticationLabel:string { "Authentication server" }
storageLabel:string { "Storage server" }
serverLabel:string { "address:" }
portLabel:string { "port:" }
pathLabel:string { "path:" }
reportBugsToText:string { "Report bugs to: {0}" }
}
metadataTypes:table