From a94d74762810da6bf3491604eec37667b0470c35 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Tue, 7 Nov 2006 16:43:34 +0000 Subject: [PATCH] fixing #1930 --- .../include/LiveSupport/Widgets/Button.h | 2 +- .../LiveSupport/Widgets/WidgetFactory.h | 17 +- campcaster/src/modules/widgets/src/Button.cxx | 4 +- .../src/modules/widgets/src/WidgetFactory.cxx | 34 +- .../gLiveSupport/src/SearchWindow.cxx | 82 +++- .../products/gLiveSupport/src/SearchWindow.h | 431 +++++++++--------- .../src/products/gLiveSupport/var/root.txt | 3 + 7 files changed, 340 insertions(+), 233 deletions(-) diff --git a/campcaster/src/modules/widgets/include/LiveSupport/Widgets/Button.h b/campcaster/src/modules/widgets/include/LiveSupport/Widgets/Button.h index f7a8e0a10..6c4416d76 100644 --- a/campcaster/src/modules/widgets/include/LiveSupport/Widgets/Button.h +++ b/campcaster/src/modules/widgets/include/LiveSupport/Widgets/Button.h @@ -264,7 +264,7 @@ class Button : public Gtk::Button * @param child the widget that should be displayed inside the button. * @param buttonImages the images of the button */ - Button(Gtk::Widget * child, + Button(Gtk::Widget & child, Ptr::Ref buttonImages) throw (); /** diff --git a/campcaster/src/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h b/campcaster/src/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h index 83090dad6..77d414a65 100644 --- a/campcaster/src/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h +++ b/campcaster/src/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h @@ -228,7 +228,22 @@ class WidgetFactory : std::logic_error); /** - * Create and return a button. + * Create and return a generic button. + * It is the reponsibility of the caller to dispose of the created + * object properly. + * + * @param label the label shown inside the button. + * @param type the type of the button to create + * @return a button with the specified label. + */ + Button * + createButton( + Gtk::Widget & label, + WidgetConstants::ButtonType type = WidgetConstants::pushButton) + throw (); + + /** + * Create and return a button with a text label. * It is the reponsibility of the caller to dispose of the created * object properly. * diff --git a/campcaster/src/modules/widgets/src/Button.cxx b/campcaster/src/modules/widgets/src/Button.cxx index 7725007a3..ad2036ebe 100644 --- a/campcaster/src/modules/widgets/src/Button.cxx +++ b/campcaster/src/modules/widgets/src/Button.cxx @@ -78,7 +78,7 @@ Button :: Button(const Glib::ustring & label, /*------------------------------------------------------------------------------ * Constructor. *----------------------------------------------------------------------------*/ -Button :: Button(Gtk::Widget * child, +Button :: Button(Gtk::Widget & child, Ptr::Ref buttonImages) throw () : useSelected(false), @@ -88,7 +88,7 @@ Button :: Button(Gtk::Widget * child, state = passiveState; - this->child = Gtk::manage(child); + this->child = &child; this->child->set_parent(*this); } diff --git a/campcaster/src/modules/widgets/src/WidgetFactory.cxx b/campcaster/src/modules/widgets/src/WidgetFactory.cxx index 4df3a7766..29b104df1 100644 --- a/campcaster/src/modules/widgets/src/WidgetFactory.cxx +++ b/campcaster/src/modules/widgets/src/WidgetFactory.cxx @@ -401,7 +401,39 @@ WidgetFactory :: loadImage(const std::string imageName) /*------------------------------------------------------------------------------ - * Create a button + * Create a generic button. + *----------------------------------------------------------------------------*/ +Button * +WidgetFactory :: createButton(Gtk::Widget & label, + WidgetConstants::ButtonType type) throw () +{ + Button * button = 0; + + switch (type) { + case WidgetConstants::pushButton: + button = new Button(label, buttonImages); + break; + + case WidgetConstants::radioButton: + button = new Button(label, buttonImages); + button->setUseSelected(true); + break; + + case WidgetConstants::tabButton: + button = new Button(label, tabButtonImages); + button->setUseSelected(true); + break; + + default: + break; + } + + return button; +} + + +/*------------------------------------------------------------------------------ + * Create a text button. *----------------------------------------------------------------------------*/ Button * WidgetFactory :: createButton(const Glib::ustring & label, diff --git a/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx b/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx index 86f7678b8..e5addb4e9 100644 --- a/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx +++ b/campcaster/src/products/gLiveSupport/src/SearchWindow.cxx @@ -74,16 +74,6 @@ const std::string searchWhereRemoteKey = "searchWhereRemote"; *----------------------------------------------------------------------------*/ const int searchResultsSize = 10; -/*------------------------------------------------------------------------------ - * The label for the Backward button. - *----------------------------------------------------------------------------*/ -const Glib::ustring backwardButtonText = "⇧"; - -/*------------------------------------------------------------------------------ - * The label for the Forward button. - *----------------------------------------------------------------------------*/ -const Glib::ustring forwardButtonText = "⇩"; - } /* =============================================== local function prototypes */ @@ -383,21 +373,39 @@ SearchWindow :: constructSearchResultsView(void) throw () resultsWindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); resultsWindow->add(*searchResultsTreeView); - // create the page backward and forward buttons - backwardButton = Gtk::manage(wf->createButton(backwardButtonText)); - forwardButton = Gtk::manage(wf->createButton(forwardButtonText)); - + // create the paging toolbar + try { + backwardButton = Gtk::manage(wf->createButton( + *getResourceUstring("backwardButtonLabel"))); + forwardButton = Gtk::manage(wf->createButton( + *getResourceUstring("forwardButtonLabel"))); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + std::exit(1); + } backwardButton->signal_clicked().connect(sigc::mem_fun(*this, &SearchWindow::onBackwardButtonClicked)); forwardButton->signal_clicked().connect(sigc::mem_fun(*this, &SearchWindow::onForwardButtonClicked)); - updateBackwardAndForwardButtons(); + + Gtk::Box * pagingButtonBox = Gtk::manage(new Gtk::HButtonBox( + Gtk::BUTTONBOX_DEFAULT_STYLE, 5)); + pagingButtonBox->add(*backwardButton); + pagingButtonBox->add(*forwardButton); + + searchResultsCountLabel = Gtk::manage(new Gtk::Label()); + + Gtk::Box * pagingToolbar = Gtk::manage(new Gtk::HBox); + pagingToolbar->pack_start(*searchResultsCountLabel, + Gtk::PACK_EXPAND_WIDGET, 5); + pagingToolbar->pack_start(*pagingButtonBox, Gtk::PACK_SHRINK, 5); + + updatePagingToolbar(); // pack everything in a box Gtk::Box * view = Gtk::manage(new Gtk::VBox); - view->pack_start(*backwardButton, Gtk::PACK_SHRINK, 2); + view->pack_start(*pagingToolbar, Gtk::PACK_SHRINK, 5); view->pack_start(*resultsWindow, Gtk::PACK_EXPAND_WIDGET, 0); - view->pack_start(*forwardButton, Gtk::PACK_SHRINK, 2); return view; } @@ -539,7 +547,7 @@ SearchWindow :: displaySearchResults( { treeModel->clear(); searchResultsTreeView->set_model(treeModel); - updateBackwardAndForwardButtons(); + updatePagingToolbar(); Ptr::Ref widgetFactory = WidgetFactory::getInstance(); @@ -1088,7 +1096,7 @@ SearchWindow :: onSearchWhereChanged(void) throw () searchResultsTreeView->set_model(remoteSearchResults); } - updateBackwardAndForwardButtons(); + updatePagingToolbar(); } @@ -1264,18 +1272,48 @@ SearchWindow :: onForwardButtonClicked(void) throw () * Enable or disable the Backward and Forward buttons. *----------------------------------------------------------------------------*/ void -SearchWindow :: updateBackwardAndForwardButtons(void) throw () +SearchWindow :: updatePagingToolbar(void) throw () { Ptr::Ref criteria = getSearchCriteria(); if (criteria) { - int offset = criteria->getOffset(); - int count = getSearchResultsCount(); + int offset = criteria->getOffset(); + int count = getSearchResultsCount(); + int lastNumber = std::min(offset + getSearchResultsSize(), count); + + try { + if (count > 0) { + searchResultsCountLabel->set_text(*formatMessage( + "searchResultsCountLabel", + itoa(offset + 1), + itoa(lastNumber), + itoa(count) )); + } else { + searchResultsCountLabel->set_text(""); + } + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + std::exit(1); + } backwardButton->setDisabled(offset == 0); forwardButton->setDisabled(offset + getSearchResultsSize() >= count); } else { + searchResultsCountLabel->set_text(""); backwardButton->setDisabled(true); forwardButton->setDisabled(true); } } + +/*------------------------------------------------------------------------------ + * Convert an integer to a string. + *----------------------------------------------------------------------------*/ +Glib::ustring +SearchWindow :: itoa(int number) throw () +{ + std::ostringstream stream; + stream << number; + Glib::ustring string = stream.str(); + return string; +} + diff --git a/campcaster/src/products/gLiveSupport/src/SearchWindow.h b/campcaster/src/products/gLiveSupport/src/SearchWindow.h index 66156284b..eb9f63d33 100644 --- a/campcaster/src/products/gLiveSupport/src/SearchWindow.h +++ b/campcaster/src/products/gLiveSupport/src/SearchWindow.h @@ -149,6 +149,51 @@ class SearchWindow : public GuiWindow */ Ptr::Ref exportPlaylistWindow; + /** + * The tree model, as a GTK reference, for the local search results. + */ + Glib::RefPtr localSearchResults; + + /** + * The tree model, as a GTK reference, for the remote search results. + */ + Glib::RefPtr remoteSearchResults; + + /** + * The tree view showing the search results. + */ + ZebraTreeView * searchResultsTreeView; + + /** + * The label showing the number of search results. + */ + Gtk::Label * searchResultsCountLabel; + + /** + * The notebook for the various tabs in the window. + */ + ScrolledNotebook * searchInput; + + /** + * The transport token used when a remote search is pending. + */ + Ptr::Ref remoteSearchToken; + + /** + * The pop-up context menu for local audio clips. + */ + Gtk::Menu * audioClipContextMenu; + + /** + * The pop-up context menu for local playlists. + */ + Gtk::Menu * playlistContextMenu; + + /** + * The pop-up context menu for remote audio clips and playlists. + */ + Gtk::Menu * remoteContextMenu; + /** * Construct the "search where" box. * This contains a combo box, where the user can choose between @@ -230,51 +275,6 @@ class SearchWindow : public GuiWindow Gtk::Menu * constructRemoteContextMenu(void) throw (); - /** - * Event handler for the simple Search button getting clicked. - */ - void - onSimpleSearch(void) throw (); - - /** - * Event handler for the advanced Search button getting clicked. - */ - void - onAdvancedSearch(void) throw (); - - /** - * Event handler for changed selection in the Browse view. - */ - void - onBrowse(void) throw (); - - /** - * Do the searching (first set of results). - * Sets the offset to 0, and calls onSearch(). - * - * @param criteria the search criteria. - */ - void - onInitialSearch(Ptr::Ref criteria) throw (); - - /** - * Do the searching (after paging backward or forward). - * Sets the offset to the given value, and calls onSearch(). - * - * @param offset the new offset to use for this search. - */ - void - onContinuedSearch(int offset) throw (); - - /** - * Do the searching. - * Calls either localSearch() or remoteSearch(). - * - * @param criteria the search criteria. - */ - void - onSearch(Ptr::Ref criteria) throw (); - /** * Check the status of the "search where" input box. */ @@ -359,103 +359,65 @@ class SearchWindow : public GuiWindow throw (); /** - * Enable or disable the Backward and Forward buttons. + * Update the paging portion of the search results view. + * Prints the number of results, and enables or disables + * the Backward and Forward buttons. */ void - updateBackwardAndForwardButtons(void) throw (); + updatePagingToolbar(void) throw (); /** - * Signal handler for the mouse clicked on one of the entries. + * Display a (usually error) message in the search results tree view. * - * @param event the button event received + * @param messageKey the localization key for the message. + * @param treeModel the tree model to display the message in. */ void - onEntryClicked(GdkEventButton * event) throw (); - + displayMessage(const Glib::ustring & messageKey, + Glib::RefPtr treeModel) + throw (); + /** - * Signal handler for the user double-clicking, or pressing Enter - * on one of the entries. + * Display an error message which occurred during a search. * - * @param event the button event recieved + * @param error the error which occurred. + * @param treeModel the tree model to display the message in. */ void - onDoubleClick(const Gtk::TreeModel::Path & path, - const Gtk::TreeViewColumn * column) + displayError(const XmlRpcException & error, + Glib::RefPtr treeModel) + throw (); + + /** + * Display an error message which occurred during a local search. + * + * @param error the error which occurred. + */ + void + displayLocalSearchError(const XmlRpcException & error) + throw (); + + /** + * Display an error message which occurred during a remote search. + * + * @param error the error which occurred. + */ + void + displayRemoteSearchError(const XmlRpcException & error) throw (); /** - * Add a playable to the scratchpad. - */ - void - onAddToScratchpad(void) throw (); - - /** - * Signal handler for the "add to playlist" menu item selected from - * the entry context menu. - */ - virtual void - onAddToPlaylist(void) throw (); - - /** - * Add a playable to the live mode. - */ - void - onAddToLiveMode(void) throw (); - - /** - * Signal handler for the "edit playlist" menu item selected from - * the entry context menu. - */ - virtual void - onEditPlaylist(void) throw (); - - /** - * Signal handler for the "schedule playlist" menu item selected - * from the entry context menu. - */ - virtual void - onSchedulePlaylist(void) throw (); - - /** - * Signal handler for the "export playlist" menu item selected from - * the entry context menu. - */ - void - onExportPlaylist(void) throw (); - - /** - * Signal handler for "upload to hub" in the context menu. - */ - void - onUploadToHub(void) throw (); - - /** - * Signal handler for "download from hub" in the context menu. - */ - void - onDownloadFromHub(void) throw (); - - /** - * Event handler for a click on the Backward button. - */ - void - onBackwardButtonClicked(void) throw (); - - /** - * Event handler for a click on the Forward button. - */ - void - onForwardButtonClicked(void) throw (); - - /** - * Event handler called when the the window gets hidden. + * Convert an integer to a string. * - * This overrides GuiWindow::on_hide(), and closes the Export Playlist - * window, if it is still open. + * @param number the number to be converted. + * @return the string value of the number (in base 10). */ - virtual void - on_hide(void) throw (); - + static Glib::ustring + itoa(int number) throw (); + + + protected: + /** * The columns model needed by Gtk::TreeView. * Lists one clip per row. @@ -510,86 +472,6 @@ class SearchWindow : public GuiWindow */ ModelColumns modelColumns; - /** - * The tree model, as a GTK reference, for the local search results. - */ - Glib::RefPtr localSearchResults; - - /** - * The tree model, as a GTK reference, for the remote search results. - */ - Glib::RefPtr remoteSearchResults; - - /** - * The tree view showing the search results. - */ - ZebraTreeView * searchResultsTreeView; - - /** - * The notebook for the various tabs in the window. - */ - ScrolledNotebook * searchInput; - - /** - * The transport token used when a remote search is pending. - */ - Ptr::Ref remoteSearchToken; - - /** - * The pop-up context menu for local audio clips. - */ - Gtk::Menu * audioClipContextMenu; - - /** - * The pop-up context menu for local playlists. - */ - Gtk::Menu * playlistContextMenu; - - /** - * The pop-up context menu for remote audio clips and playlists. - */ - Gtk::Menu * remoteContextMenu; - - /** - * Display a (usually error) message in the search results tree view. - * - * @param messageKey the localization key for the message. - * @param treeModel the tree model to display the message in. - */ - void - displayMessage(const Glib::ustring & messageKey, - Glib::RefPtr treeModel) - throw (); - - /** - * Display an error message which occurred during a search. - * - * @param error the error which occurred. - * @param treeModel the tree model to display the message in. - */ - void - displayError(const XmlRpcException & error, - Glib::RefPtr treeModel) - throw (); - - /** - * Display an error message which occurred during a local search. - * - * @param error the error which occurred. - */ - void - displayLocalSearchError(const XmlRpcException & error) - throw (); - - /** - * Display an error message which occurred during a remote search. - * - * @param error the error which occurred. - */ - void - displayRemoteSearchError(const XmlRpcException & error) - throw (); - /** * Return the number of search results which can be displayed. * As currently implemented, this returns a constant 10. @@ -600,6 +482,143 @@ class SearchWindow : public GuiWindow int getSearchResultsSize(void) throw (); + /** + * Event handler for the simple Search button getting clicked. + */ + void + onSimpleSearch(void) throw (); + + /** + * Event handler for the advanced Search button getting clicked. + */ + void + onAdvancedSearch(void) throw (); + + /** + * Event handler for changed selection in the Browse view. + */ + void + onBrowse(void) throw (); + + /** + * Do the searching (first set of results). + * Sets the offset to 0, and calls onSearch(). + * + * @param criteria the search criteria. + */ + void + onInitialSearch(Ptr::Ref criteria) throw (); + + /** + * Do the searching (after paging backward or forward). + * Sets the offset to the given value, and calls onSearch(). + * + * @param offset the new offset to use for this search. + */ + void + onContinuedSearch(int offset) throw (); + + /** + * Do the searching. + * Calls either localSearch() or remoteSearch(). + * + * @param criteria the search criteria. + */ + void + onSearch(Ptr::Ref criteria) throw (); + + /** + * Signal handler for the mouse clicked on one of the entries. + * + * @param event the button event received + */ + void + onEntryClicked(GdkEventButton * event) throw (); + + /** + * Signal handler for the user double-clicking, or pressing Enter + * on one of the entries. + * + * @param event the button event recieved + */ + void + onDoubleClick(const Gtk::TreeModel::Path & path, + const Gtk::TreeViewColumn * column) + throw (); + + /** + * Add a playable to the scratchpad. + */ + void + onAddToScratchpad(void) throw (); + + /** + * Signal handler for the "add to playlist" menu item selected from + * the entry context menu. + */ + void + onAddToPlaylist(void) throw (); + + /** + * Add a playable to the live mode. + */ + void + onAddToLiveMode(void) throw (); + + /** + * Signal handler for the "edit playlist" menu item selected from + * the entry context menu. + */ + void + onEditPlaylist(void) throw (); + + /** + * Signal handler for the "schedule playlist" menu item selected + * from the entry context menu. + */ + void + onSchedulePlaylist(void) throw (); + + /** + * Signal handler for the "export playlist" menu item selected from + * the entry context menu. + */ + void + onExportPlaylist(void) throw (); + + /** + * Signal handler for "upload to hub" in the context menu. + */ + void + onUploadToHub(void) throw (); + + /** + * Signal handler for "download from hub" in the context menu. + */ + void + onDownloadFromHub(void) throw (); + + /** + * Event handler for a click on the Backward button. + */ + void + onBackwardButtonClicked(void) throw (); + + /** + * Event handler for a click on the Forward button. + */ + void + onForwardButtonClicked(void) throw (); + + /** + * Event handler called when the the window gets hidden. + * + * This overrides GuiWindow::on_hide(), and closes the Export Playlist + * window, if it is still open. + */ + virtual void + on_hide(void) throw (); + public: diff --git a/campcaster/src/products/gLiveSupport/var/root.txt b/campcaster/src/products/gLiveSupport/var/root.txt index 7f1ad7b14..a995b0e7d 100644 --- a/campcaster/src/products/gLiveSupport/var/root.txt +++ b/campcaster/src/products/gLiveSupport/var/root.txt @@ -200,6 +200,9 @@ root:table transportsTab:string { "Transfers" } searchButtonLabel:string { "Search" } + backwardButtonLabel:string { "⇦ Previous" } + forwardButtonLabel:string { "Next ⇨" } + searchResultsCountLabel:string { "{0}-{1} of {2} results" } typeColumnLabel:string { "Type" } titleColumnLabel:string { "Title" }