fixed the "do you want to save?" dialog in the SimplePlaylistMgmtWindow

This commit is contained in:
fgerlits 2005-07-01 20:55:11 +00:00
parent c9e0aa62ce
commit 387b64e0a5
8 changed files with 76 additions and 35 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.16 $ Version : $Revision: 1.17 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -104,8 +104,7 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
entriesView->appendColumn(*getResourceUstring("lengthColumnLabel"), entriesView->appendColumn(*getResourceUstring("lengthColumnLabel"),
modelColumns.lengthColumn, 120); modelColumns.lengthColumn, 120);
statusBar = Gtk::manage(new Gtk::Label( statusBar = Gtk::manage(new Gtk::Label(""));
*getResourceUstring("statusBar")));
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
std::exit(1); std::exit(1);
@ -156,13 +155,14 @@ SimplePlaylistManagementWindow :: SimplePlaylistManagementWindow (
Ptr<Glib::ustring>::Ref confirmationMessage; Ptr<Glib::ustring>::Ref confirmationMessage;
try { try {
confirmationMessage.reset(new Glib::ustring( confirmationMessage.reset(new Glib::ustring(
*getResourceUstring("sureToExitMsg") )); *getResourceUstring("savePlaylistDialogMsg") ));
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
std::exit(1); std::exit(1);
} }
dialogWindow.reset(new DialogWindow(confirmationMessage, dialogWindow.reset(new DialogWindow(confirmationMessage,
DialogWindow::cancelButton |
DialogWindow::noButton | DialogWindow::noButton |
DialogWindow::yesButton, DialogWindow::yesButton,
gLiveSupport->getBundle() )); gLiveSupport->getBundle() ));
@ -179,26 +179,27 @@ SimplePlaylistManagementWindow :: ~SimplePlaylistManagementWindow (void)
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Event handler for the save button getting clicked. * Save the edited playlist.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void bool
SimplePlaylistManagementWindow :: onSaveButtonClicked (void) throw () SimplePlaylistManagementWindow :: savePlaylist (void) throw ()
{ {
try { try {
Ptr<const Glib::ustring>::Ref title; Ptr<Playlist>::Ref playlist
Ptr<Playlist>::Ref playlist; = gLiveSupport->getEditedPlaylist();
title.reset(new Glib::ustring(nameEntry->get_text()));
// TODO: check for empty title and display "are you sure?" message
playlist = gLiveSupport->getEditedPlaylist();
if (!playlist) { if (!playlist) {
return; return false;
}
Ptr<const Glib::ustring>::Ref title(new Glib::ustring(
nameEntry->get_text()));
if (*title == "") {
statusBar->set_text(*getResourceUstring("emptyTitleErrorMsg"));
return false;
} }
playlist->setTitle(title); playlist->setTitle(title);
gLiveSupport->savePlaylist();
playlist = gLiveSupport->savePlaylist();
Ptr<Glib::ustring>::Ref statusText = formatMessage( Ptr<Glib::ustring>::Ref statusText = formatMessage(
"playlistSavedMsg", "playlistSavedMsg",
@ -208,34 +209,56 @@ SimplePlaylistManagementWindow :: onSaveButtonClicked (void) throw ()
// clean the entry fields // clean the entry fields
nameEntry->set_text(""); nameEntry->set_text("");
entriesModel->clear(); entriesModel->clear();
return true;
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
statusBar->set_text(e.what()); statusBar->set_text(e.what());
return false;
} }
} }
/*------------------------------------------------------------------------------
* Event handler for the save button getting clicked.
*----------------------------------------------------------------------------*/
void
SimplePlaylistManagementWindow :: onSaveButtonClicked (void) throw ()
{
savePlaylist();
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Event handler for the close button getting clicked. * Event handler for the close button getting clicked.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
SimplePlaylistManagementWindow :: onCloseButtonClicked (void) throw () SimplePlaylistManagementWindow :: onCloseButtonClicked (void) throw ()
{ {
// TODO: only ask if playlist has been modified if (gLiveSupport->getEditedPlaylist()) {
DialogWindow::ButtonType result = dialogWindow->run(); DialogWindow::ButtonType result = dialogWindow->run();
switch (result) { switch (result) {
case DialogWindow::noButton: case DialogWindow::noButton:
return;
case DialogWindow::yesButton:
gLiveSupport->cancelEditedPlaylist(); gLiveSupport->cancelEditedPlaylist();
hide(); statusBar->set_text("");
nameEntry->set_text("");
entriesModel->clear();
break; break;
default: std::cerr << "Error: DialogWindow returned " << result case DialogWindow::yesButton:
<< "; " << DialogWindow::noButton << " or " if (savePlaylist()) {
<< DialogWindow::yesButton << " is expected." statusBar->set_text("");
<< std::endl; break;
} else {
return;
} }
case DialogWindow::cancelButton:
return;
default : // can happen if window is closed
return; // with Alt-F4 -- treated as cancel
}
}
hide();
} }

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -87,7 +87,7 @@ using namespace LiveSupport::Widgets;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.6 $ * @version $Revision: 1.7 $
*/ */
class SimplePlaylistManagementWindow : public WhiteWindow, class SimplePlaylistManagementWindow : public WhiteWindow,
public LocalizedObject public LocalizedObject
@ -100,7 +100,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.6 $ * @version $Revision: 1.7 $
*/ */
class ModelColumns : public ZebraTreeModelColumnRecord class ModelColumns : public ZebraTreeModelColumnRecord
{ {
@ -193,6 +193,14 @@ class SimplePlaylistManagementWindow : public WhiteWindow,
*/ */
Ptr<DialogWindow>::Ref dialogWindow; Ptr<DialogWindow>::Ref dialogWindow;
/**
* Save the edited playlist.
*
* @return true if the playlist was saved successully.
*/
virtual bool
savePlaylist(void) throw ();
/** /**
* Signal handler for the save button clicked. * Signal handler for the save button clicked.
*/ */

View file

@ -110,6 +110,8 @@ es:table
closeButtonLabel:string { "cerrar" } closeButtonLabel:string { "cerrar" }
statusBar:string { "barra de estatus" } statusBar:string { "barra de estatus" }
playlistSavedMsg:string { "lista de reproducción guardada {0}" } playlistSavedMsg:string { "lista de reproducción guardada {0}" }
savePlaylistDialogMsg:string { "*** translate me ***" }
emptyTitleErrorMsg:string { "*** translate me ***" }
} }
schedulerWindow:table schedulerWindow:table

View file

@ -115,7 +115,8 @@ hu:table
closeButtonLabel:string { "bezár" } closeButtonLabel:string { "bezár" }
statusBar:string { "állapotsor" } statusBar:string { "állapotsor" }
playlistSavedMessage:string { "a {0} műsor elmentve" } playlistSavedMessage:string { "a {0} műsor elmentve" }
sureToExitMsg:string { "Biztos, hogy nem akarja elmenteni a műsort?" } savePlaylistDialogMsg:string { "El szeretné menteni a műsort?" }
emptyTitleErrorMsg:string { "Kérem, adjon meg egy címet!" }
} }
schedulerWindow:table schedulerWindow:table

View file

@ -110,6 +110,8 @@ nl:table
closeButtonLabel:string { "sluiten" } closeButtonLabel:string { "sluiten" }
statusBar:string { "status balk" } statusBar:string { "status balk" }
playlistSavedMsg:string { "playlist {0} opgeslagen" } playlistSavedMsg:string { "playlist {0} opgeslagen" }
savePlaylistDialogMsg:string { "*** translate me ***" }
emptyTitleErrorMsg:string { "*** translate me ***" }
} }
schedulerWindow:table schedulerWindow:table

View file

@ -116,7 +116,8 @@ root:table
closeButtonLabel:string { "close" } closeButtonLabel:string { "close" }
statusBar:string { "status bar" } statusBar:string { "status bar" }
playlistSavedMsg:string { "saved playlist {0}" } playlistSavedMsg:string { "saved playlist {0}" }
sureToExitMsg:string { "Do you want to exit without saving?" } savePlaylistDialogMsg:string { "Would you like to save the playlist?" }
emptyTitleErrorMsg:string { "Please enter a title." }
} }
schedulerWindow:table schedulerWindow:table

View file

@ -110,6 +110,8 @@ sr_CS:table
closeButtonLabel:string { "zatvori" } closeButtonLabel:string { "zatvori" }
statusBar:string { "status bar" } statusBar:string { "status bar" }
playlistSavedMsg:string { "sačuvana plej lista {0}" } playlistSavedMsg:string { "sačuvana plej lista {0}" }
savePlaylistDialogMsg:string { "*** translate me ***" }
emptyTitleErrorMsg:string { "*** translate me ***" }
} }
schedulerWindow:table schedulerWindow:table

View file

@ -109,6 +109,8 @@ sr_CS_CYRILLIC:table
closeButtonLabel:string { "затвори" } closeButtonLabel:string { "затвори" }
statusBar:string { "статус бар" } statusBar:string { "статус бар" }
playlistSavedMsg:string { "сачувана плеј листа {0}" } playlistSavedMsg:string { "сачувана плеј листа {0}" }
savePlaylistDialogMsg:string { "*** translate me ***" }
emptyTitleErrorMsg:string { "*** translate me ***" }
} }
schedulerWindow:table schedulerWindow:table