rewrote Cancel and Save behavior in SimplePlaylistMgmtWindow

This commit is contained in:
fgerlits 2005-07-20 17:55:05 +00:00
parent b297754948
commit 128f8034b8
5 changed files with 179 additions and 79 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.59 $ Version : $Revision: 1.60 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -443,6 +443,7 @@ LiveSupport :: GLiveSupport ::
GLiveSupport :: logout(void) throw () GLiveSupport :: logout(void) throw ()
{ {
if (sessionId.get() != 0) { if (sessionId.get() != 0) {
cancelEditedPlaylist();
stopCueAudio(); stopCueAudio();
storeScratchpadContents(); storeScratchpadContents();
scratchpadContents->clear(); scratchpadContents->clear();
@ -700,24 +701,19 @@ GLiveSupport :: addToPlaylist(Ptr<const UniqueId>::Ref id)
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Save the currently edited playlist in storage * Save the currently edited playlist in storage
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
Ptr<Playlist>::Ref void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: savePlaylist(void) GLiveSupport :: savePlaylist(void)
throw (XmlRpcException) throw (XmlRpcException)
{ {
Ptr<Playlist>::Ref playlist;
if (editedPlaylist) { if (editedPlaylist) {
if (editedPlaylist->isLocked()) { if (editedPlaylist->isLocked()) {
editedPlaylist->deleteSavedCopy(); editedPlaylist->deleteSavedCopy();
storage->savePlaylist(sessionId, editedPlaylist); storage->savePlaylist(sessionId, editedPlaylist);
playlist = storage->getPlaylist(sessionId, editedPlaylist->getId()); addToScratchpad(editedPlaylist); // update with new version
addToScratchpad(playlist);
} }
editedPlaylist.reset(); editedPlaylist.reset();
} }
return playlist;
} }

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.43 $ Version : $Revision: 1.44 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -102,7 +102,7 @@ class MasterPanelWindow;
* respective documentation. * respective documentation.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.43 $ * @version $Revision: 1.44 $
* @see LocalizedObject#getBundle(const xmlpp::Element &) * @see LocalizedObject#getBundle(const xmlpp::Element &)
* @see AuthenticationClientFactory * @see AuthenticationClientFactory
* @see StorageClientFactory * @see StorageClientFactory
@ -547,13 +547,14 @@ class GLiveSupport : public LocalizedConfigurable,
* Save the currently edited playlist in storage. * Save the currently edited playlist in storage.
* This call has to be preceeded by a call to openPlaylistForEditing() * This call has to be preceeded by a call to openPlaylistForEditing()
* or addToPlaylist(). * or addToPlaylist().
* After this call, the playlist is no longer being edited. If you
* want to continue editing, open the playlist for editing again.
* *
* @return the audio clip that was saved.
* @exception XmlRpcException on upload failures. * @exception XmlRpcException on upload failures.
* @see #openPlaylistForEditing * @see #openPlaylistForEditing
* @see #addToPlaylist * @see #addToPlaylist
*/ */
Ptr<Playlist>::Ref void
savePlaylist(void) throw (XmlRpcException); savePlaylist(void) throw (XmlRpcException);
/** /**

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.21 $ Version : $Revision: 1.22 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -69,7 +69,8 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
Colors::White, Colors::White,
WidgetFactory::getInstance()->getWhiteWindowCorners()), WidgetFactory::getInstance()->getWhiteWindowCorners()),
LocalizedObject(bundle), LocalizedObject(bundle),
gLiveSupport(gLiveSupport) gLiveSupport(gLiveSupport),
isPlaylistModified(false)
{ {
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance(); Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
@ -128,6 +129,23 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
entriesView->signalCellEdited().connect(sigc::mem_fun( entriesView->signalCellEdited().connect(sigc::mem_fun(
*this, &SimplePlaylistManagementWindow::onFadeInfoEdited )); *this, &SimplePlaylistManagementWindow::onFadeInfoEdited ));
// construct the "lock fades" check button
Ptr<Glib::ustring>::Ref lockFadesCheckButtonLabel;
try {
lockFadesCheckButtonLabel = getResourceUstring(
"lockFadesCheckButtonLabel");
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;
std::exit(1);
}
Gtk::CheckButton * lockFadesCheckButton = Gtk::manage(new Gtk::CheckButton(
*lockFadesCheckButtonLabel ));
lockFadesCheckButton->set_active(true);
areFadesLocked = true;
lockFadesCheckButton->signal_toggled().connect(sigc::mem_fun(
*this,
&SimplePlaylistManagementWindow::onLockFadesCheckButtonClicked ));
// set up the layout // set up the layout
Gtk::VBox * mainBox = Gtk::manage(new Gtk::VBox); Gtk::VBox * mainBox = Gtk::manage(new Gtk::VBox);
@ -142,6 +160,8 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
mainBox->pack_start(*entriesScrolledWindow, Gtk::PACK_EXPAND_WIDGET, 5); mainBox->pack_start(*entriesScrolledWindow, Gtk::PACK_EXPAND_WIDGET, 5);
mainBox->pack_start(*lockFadesCheckButton, Gtk::PACK_SHRINK, 5);
Gtk::ButtonBox * buttonBox = Gtk::manage(new Gtk::HButtonBox( Gtk::ButtonBox * buttonBox = Gtk::manage(new Gtk::HButtonBox(
Gtk::BUTTONBOX_END, 5)); Gtk::BUTTONBOX_END, 5));
buttonBox->pack_start(*saveButton); buttonBox->pack_start(*saveButton);
@ -218,16 +238,15 @@ SimplePlaylistManagementWindow :: savePlaylist (void) throw ()
playlist->setTitle(title); playlist->setTitle(title);
gLiveSupport->savePlaylist(); gLiveSupport->savePlaylist();
gLiveSupport->openPlaylistForEditing(playlist->getId());
isPlaylistModified = false;
Ptr<Glib::ustring>::Ref statusText = formatMessage( Ptr<Glib::ustring>::Ref statusText = formatMessage(
"playlistSavedMsg", "playlistSavedMsg",
*playlist->getTitle()); *playlist->getTitle());
statusBar->set_text(*statusText); statusBar->set_text(*statusText);
// clean the entry fields
nameEntry->set_text("");
entriesModel->clear();
return true; return true;
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
statusBar->set_text(e.what()); statusBar->set_text(e.what());
return false; return false;
@ -236,50 +255,81 @@ SimplePlaylistManagementWindow :: savePlaylist (void) throw ()
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Event handler for the save button getting clicked. * Signal handler for the save button getting clicked.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
SimplePlaylistManagementWindow :: onSaveButtonClicked (void) throw () SimplePlaylistManagementWindow :: onSaveButtonClicked(void) throw ()
{ {
savePlaylist(); savePlaylist();
} }
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Event handler for the close button getting clicked. * Cancel the edited playlist (no questions asked).
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
SimplePlaylistManagementWindow :: onCloseButtonClicked (void) throw () SimplePlaylistManagementWindow :: cancelPlaylist(void) throw ()
{
gLiveSupport->cancelEditedPlaylist();
closeWindow();
}
/*------------------------------------------------------------------------------
* Signal handler for the close button getting clicked.
*----------------------------------------------------------------------------*/
void
SimplePlaylistManagementWindow :: onCloseButtonClicked(void) throw ()
{ {
if (gLiveSupport->getEditedPlaylist()) { if (gLiveSupport->getEditedPlaylist()) {
DialogWindow::ButtonType result = dialogWindow->run(); if (!isPlaylistModified) {
switch (result) { cancelPlaylist();
case DialogWindow::noButton: } else {
gLiveSupport->cancelEditedPlaylist(); DialogWindow::ButtonType result = dialogWindow->run();
statusBar->set_text(""); switch (result) {
nameEntry->set_text(""); case DialogWindow::noButton: cancelPlaylist();
entriesModel->clear(); break;
break;
case DialogWindow::yesButton: case DialogWindow::yesButton: if (savePlaylist()) {
if (savePlaylist()) { closeWindow();
statusBar->set_text(""); }
break; break;
} else {
return;
}
case DialogWindow::cancelButton: case DialogWindow::cancelButton: break;
return;
default : // can happen if window is closed default : break;
return; // with Alt-F4 -- treated as cancel // can happen if window is closed
} // with Alt-F4 -- treated as cancel
} }
} }
}
/*------------------------------------------------------------------------------
* Clean and close the window.
*----------------------------------------------------------------------------*/
void
SimplePlaylistManagementWindow :: closeWindow(void) throw ()
{
statusBar->set_text("");
nameEntry->set_text("");
entriesModel->clear();
isPlaylistModified = false;
hide(); hide();
} }
/*------------------------------------------------------------------------------
* Signal handler for the "lock fades" check button toggled.
*----------------------------------------------------------------------------*/
void
SimplePlaylistManagementWindow :: onLockFadesCheckButtonClicked(void)
throw ()
{
areFadesLocked = !areFadesLocked;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Show the contents of the currently edited playlist. * Show the contents of the currently edited playlist.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -349,8 +399,13 @@ SimplePlaylistManagementWindow :: onFadeInfoEdited(
std::vector<int> rowNumberVector = path.get_indices(); std::vector<int> rowNumberVector = path.get_indices();
int rowNumber = rowNumberVector.at(0); int rowNumber = rowNumberVector.at(0);
Ptr<time_duration>::Ref newTime(new time_duration( Ptr<time_duration>::Ref newTime;
duration_from_string(newText) )); try {
newTime.reset(new time_duration(duration_from_string(newText)));
} catch (boost::bad_lexical_cast &e) {
showContents(); // bad time format; restore previous state
return;
}
Ptr<Playlist>::Ref playlist = gLiveSupport->getEditedPlaylist(); Ptr<Playlist>::Ref playlist = gLiveSupport->getEditedPlaylist();
Playlist::const_iterator iter = playlist->begin(); Playlist::const_iterator iter = playlist->begin();
@ -363,16 +418,14 @@ SimplePlaylistManagementWindow :: onFadeInfoEdited(
switch (columnId) { switch (columnId) {
case fadeInColumnId : case fadeInColumnId :
setFadeIn(playlistElement, newTime); setFadeIn(playlistElement, newTime);
if (iter != playlist->begin()) { if (areFadesLocked && iter-- != playlist->begin()) {
--iter;
Ptr<PlaylistElement>::Ref prevPlaylistElement = iter->second; Ptr<PlaylistElement>::Ref prevPlaylistElement = iter->second;
setFadeOut(prevPlaylistElement, newTime); setFadeOut(prevPlaylistElement, newTime);
} }
break; break;
case fadeOutColumnId : case fadeOutColumnId :
setFadeOut(playlistElement, newTime); setFadeOut(playlistElement, newTime);
++iter; if (areFadesLocked && ++iter != playlist->end()) {
if (iter != playlist->end()) {
Ptr<PlaylistElement>::Ref nextPlaylistElement = iter->second; Ptr<PlaylistElement>::Ref nextPlaylistElement = iter->second;
setFadeIn(nextPlaylistElement, newTime); setFadeIn(nextPlaylistElement, newTime);
} }
@ -392,22 +445,26 @@ SimplePlaylistManagementWindow :: onFadeInfoEdited(
* Auxilliary function: set the fade in of a playlist element. * Auxilliary function: set the fade in of a playlist element.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
GLiveSupport :: setFadeIn(Ptr<PlaylistElement>::Ref playlistElement, SimplePlaylistManagementWindow :: setFadeIn(
Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeIn) Ptr<time_duration>::Ref newFadeIn)
throw() throw()
{ {
Ptr<FadeInfo>::Ref oldFadeInfo = playlistElement->getFadeInfo(); Ptr<FadeInfo>::Ref oldFadeInfo = playlistElement->getFadeInfo();
Ptr<time_duration>::Ref oldFadeOut; Ptr<time_duration>::Ref oldFadeOut;
if (oldFadeInfo) { if (oldFadeInfo) {
oldFadeOut = oldFadeInfo->getFadeOut(); if (*oldFadeInfo->getFadeIn() == *newFadeIn) {
return;
}
oldFadeOut = oldFadeInfo->getFadeOut();
} else { } else {
oldFadeOut.reset(new time_duration(0,0,0,0)); oldFadeOut.reset(new time_duration(0,0,0,0));
} }
Ptr<FadeInfo>::Ref newFadeInfo(new FadeInfo( Ptr<FadeInfo>::Ref newFadeInfo(new FadeInfo(
newFadeIn, oldFadeOut )); newFadeIn, oldFadeOut ));
if (isLengthOkay(playlistElement, newFadeInfo)) { if (isLengthOkay(playlistElement, newFadeInfo)) {
playlistElement->setFadeInfo(newFadeInfo); playlistElement->setFadeInfo(newFadeInfo);
isPlaylistModified = true;
} }
} }
@ -416,13 +473,17 @@ GLiveSupport :: setFadeIn(Ptr<PlaylistElement>::Ref playlistElement,
* Auxilliary function: set the fade out of a playlist element. * Auxilliary function: set the fade out of a playlist element.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
GLiveSupport :: setFadeOut(Ptr<PlaylistElement>::Ref playlistElement, SimplePlaylistManagementWindow :: setFadeOut(
Ptr<time_duration>::Ref newFadeOut) Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeOut)
throw() throw()
{ {
Ptr<FadeInfo>::Ref oldFadeInfo = playlistElement->getFadeInfo(); Ptr<FadeInfo>::Ref oldFadeInfo = playlistElement->getFadeInfo();
Ptr<time_duration>::Ref oldFadeIn; Ptr<time_duration>::Ref oldFadeIn;
if (oldFadeInfo) { if (oldFadeInfo) {
if (*oldFadeInfo->getFadeOut() == *newFadeOut) {
return;
}
oldFadeIn = oldFadeInfo->getFadeIn(); oldFadeIn = oldFadeInfo->getFadeIn();
} else { } else {
oldFadeIn.reset(new time_duration(0,0,0,0)); oldFadeIn.reset(new time_duration(0,0,0,0));
@ -431,6 +492,7 @@ GLiveSupport :: setFadeOut(Ptr<PlaylistElement>::Ref playlistElement,
oldFadeIn, newFadeOut )); oldFadeIn, newFadeOut ));
if (isLengthOkay(playlistElement, newFadeInfo)) { if (isLengthOkay(playlistElement, newFadeInfo)) {
playlistElement->setFadeInfo(newFadeInfo); playlistElement->setFadeInfo(newFadeInfo);
isPlaylistModified = true;
} }
} }
@ -439,12 +501,13 @@ GLiveSupport :: setFadeOut(Ptr<PlaylistElement>::Ref playlistElement,
* Auxilliary function: check that fades are not longer than the whole clip. * Auxilliary function: check that fades are not longer than the whole clip.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
inline bool inline bool
GLiveSupport :: isLengthOkay(Ptr<PlaylistElement>::Ref playlistElement, SimplePlaylistManagementWindow :: isLengthOkay(
Ptr<FadeInfo>::Ref newFadeInfo) Ptr<PlaylistElement>::Ref playlistElement,
Ptr<FadeInfo>::Ref newFadeInfo)
throw() throw()
{ {
time_duration totalFades = *newFadeInfo->getFadeIn() time_duration totalFades = *newFadeInfo->getFadeIn()
+ *newFadeInfo->getFadeOut(); + *newFadeInfo->getFadeOut();
return (totalFades < *playlistElement->getPlayable()->getPlaylength()); return (totalFades <= *playlistElement->getPlayable()->getPlaylength());
} }

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.10 $ Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -81,13 +81,14 @@ using namespace LiveSupport::Widgets;
* | | +-- entry2 ----------------------------+ | | * | | +-- entry2 ----------------------------+ | |
* | | ... | | * | | ... | |
* | +------------------------------------------+ | * | +------------------------------------------+ |
* | +- lock fades checkbox -+ |
* | +- save button -+ +- close button -+ | * | +- save button -+ +- close button -+ |
* | +-- status bar ----------------------------+ | * | +-- status bar ----------------------------+ |
* +----------------------------------------------+ * +----------------------------------------------+
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.10 $ * @version $Revision: 1.11 $
*/ */
class SimplePlaylistManagementWindow : public WhiteWindow, class SimplePlaylistManagementWindow : public WhiteWindow,
public LocalizedObject public LocalizedObject
@ -108,6 +109,46 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
int columnId, int columnId,
const Glib::ustring & newText) throw(); const Glib::ustring & newText) throw();
/**
* Set the fade in of a playlist element.
*/
void
setFadeIn(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeIn) throw();
/**
* Set the fade out of a playlist element.
*/
void
setFadeOut(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeOut) throw();
/**
* Check that fades are not longer than the whole clip.
*
* @return true if (fadeIn + fadeOut <= playlength).
*/
bool
isLengthOkay(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<FadeInfo>::Ref newFadeInfo) throw();
/**
* Cancel the edited playlist.
* Cancel the edited playlist in GLiveSupport, and close the window.
*
* @see GLiveSupport::cancelEditedPlaylist()
* @see closeWindow()
*/
void
cancelPlaylist(void) throw();
/**
* Clean and close the window.
* Set all widgets to empty and close the window.
*/
void
closeWindow(void) throw();
protected: protected:
@ -116,7 +157,7 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
* Lists one playlist entry per row. * Lists one playlist entry per row.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.10 $ * @version $Revision: 1.11 $
*/ */
class ModelColumns : public ZebraTreeModelColumnRecord class ModelColumns : public ZebraTreeModelColumnRecord
{ {
@ -221,6 +262,18 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
*/ */
Ptr<DialogWindow>::Ref dialogWindow; Ptr<DialogWindow>::Ref dialogWindow;
/**
* A flag set to true when the edited playlist is modified.
*/
bool isPlaylistModified;
/**
* A flag controlled by the "lock fades" check button.
* This determines whether the fade-out of a clip is assumed to
* be equal to the fade-in of the next clip.
*/
bool areFadesLocked;
/** /**
* Save the edited playlist. * Save the edited playlist.
* *
@ -241,6 +294,12 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
virtual void virtual void
onCloseButtonClicked(void) throw (); onCloseButtonClicked(void) throw ();
/**
* Signal handler for the "lock fades" check button toggled.
*/
virtual void
onLockFadesCheckButtonClicked(void) throw ();
public: public:
/** /**
@ -273,27 +332,6 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
/* ====================================================== function prototypes */ /* ====================================================== function prototypes */
/**
* Auxilliary function: set the fade in of a playlist element.
*/
void
setFadeIn(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeIn) throw();
/**
* Auxilliary function: set the fade out of a playlist element.
*/
void
setFadeOut(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<time_duration>::Ref newFadeOut) throw();
/**
* Auxilliary function: check that fades are not longer than
* the whole clip.
*/
bool
isLengthOkay(Ptr<PlaylistElement>::Ref playlistElement,
Ptr<FadeInfo>::Ref newFadeInfo) throw();
} // namespace GLiveSupport } // namespace GLiveSupport
} // namespace LiveSupport } // namespace LiveSupport

View file

@ -117,6 +117,8 @@ root:table
nameLabel:string { "Name" } nameLabel:string { "Name" }
saveButtonLabel:string { "Save" } saveButtonLabel:string { "Save" }
closeButtonLabel:string { "Close" } closeButtonLabel:string { "Close" }
lockFadesCheckButtonLabel:string
{ "Lock fade-out to following fade-in" }
statusBar:string { "status bar" } statusBar:string { "status bar" }
playlistSavedMsg:string { "Saved playlist ''{0}''." } playlistSavedMsg:string { "Saved playlist ''{0}''." }
savePlaylistDialogMsg:string { "Do you want to save the playlist?" } savePlaylistDialogMsg:string { "Do you want to save the playlist?" }