pmovies.cpp

来自「磁盘管理工具,主要管理光盘信息和内容希望大家喜欢」· C++ 代码 · 共 767 行 · 第 1/2 页

CPP
767
字号
//$Id: PMovies.cpp,v 1.17 2006/06/06 22:02:03 markus Rel $//PROJECT     : CDManager//SUBSYSTEM   : Movies//REFERENCES  ://TODO        ://BUGS        ://REVISION    : $Revision: 1.17 $//AUTHOR      : Markus Schwab//CREATED     : 22.01.2006//COPYRIGHT   : Copyright (C) 2006// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.#include <cdmgr-cfg.h>#include <sstream>#include <unistd.h>#include <gtkmm/main.h>#include <gtkmm/menu.h>#include <gtkmm/stock.h>#include <gtkmm/uimanager.h>#include <gtkmm/statusbar.h>#include <gtkmm/radioaction.h>#include <gtkmm/messagedialog.h>#include <gtkmm/scrolledwindow.h>#include <YGP/Check.h>#include <YGP/Trace.h>#include <YGP/ANumeric.h>#include <YGP/StatusObj.h>#include <XGP/MessageDlg.h>#include "LangImg.h"#include "SaveCeleb.h"#include "StorageMovie.h"#include "PMovies.h"//-----------------------------------------------------------------------------/// Constructor: Creates a widget handling movies/// \param status: Statusbar to display status-messages/// \param menuSave: Menu-entry to save the database/// \param genres: Genres to use in actor-list//-----------------------------------------------------------------------------PMovies::PMovies (Gtk::Statusbar& status, Glib::RefPtr<Gtk::Action> menuSave, const Genres& genres)   : NBPage (status, menuSave), imgLang (NULL), movies (genres), relMovies ("movies"){   TRACE9 ("PMovies::PMovies (Gtk::Statusbar&, Glib::RefPtr<Gtk::Action>, const Genres&)");   Gtk::ScrolledWindow* scrlMovies (new Gtk::ScrolledWindow);   scrlMovies->set_shadow_type (Gtk::SHADOW_ETCHED_IN);   scrlMovies->add (movies);   scrlMovies->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);   movies.signalOwnerChanged.connect (mem_fun (*this, &PMovies::directorChanged));   movies.signalObjectChanged.connect (mem_fun (*this, &PMovies::movieChanged));   Check3 (movies.get_selection ());   movies.get_selection ()->signal_changed ().connect (mem_fun (*this, &PMovies::movieSelected));   widget = scrlMovies;}//-----------------------------------------------------------------------------/// Destructor//-----------------------------------------------------------------------------PMovies::~PMovies () {}//-----------------------------------------------------------------------------/// Adds a new direcotor to the list//-----------------------------------------------------------------------------void PMovies::newDirector () {   TRACE5 ("void PMovies::newDirector ()");   HDirector director;   director.define ();   directors.push_back (director);   Gtk::TreeModel::iterator i (movies.append (director));   Gtk::TreePath path (movies.getModel ()->get_path (i));   movies.selectRow (i);   movies.set_cursor (path);   aUndo.push (Undo (Undo::INSERT, DIRECTOR, 0, YGP::HEntity::cast (director), path, ""));   apMenus[UNDO]->set_sensitive ();   enableSave ();}//-----------------------------------------------------------------------------/// Adds a new movie to the first selected director//-----------------------------------------------------------------------------void PMovies::newMovie () {   TRACE5 ("void PMovies::newMovie ()");   Glib::RefPtr<Gtk::TreeSelection> movieSel (movies.get_selection ()); Check3 (movieSel);   Gtk::TreeIter p (movieSel->get_selected ()); Check3 (p);   if ((*p)->parent ())      p = ((*p)->parent ());   TRACE9 ("void PMovies::newMovie () - Founding director " << movies.getDirectorAt (p)->getName ());   HMovie movie;   movie.define ();   Gtk::TreeIter i (movies.append (movie, *p));   Gtk::TreePath path (movies.getModel ()->get_path (i));   movies.expand_row (path, false);   movies.selectRow (i);   HDirector director;   director = movies.getDirectorAt (p);   relMovies.relate (director, movie);   aUndo.push (Undo (Undo::INSERT, MOVIE, 0, YGP::HEntity::cast (movie), path, ""));   apMenus[UNDO]->set_sensitive ();   enableSave ();}//-----------------------------------------------------------------------------/// Callback after selecting a movie/// \param row: Selected row//-----------------------------------------------------------------------------void PMovies::movieSelected () {   TRACE9 ("PMovies::movieSelected ()");   Check3 (movies.get_selection ());   Gtk::TreeIter s (movies.get_selection ()->get_selected ());   enableEdit (s ? OWNER_SELECTED : NONE_SELECTED);}//----------------------------------------------------------------------------/// Callback when changing a director/// \param row: Changed line/// \param column: Changed column/// \param oldValue: Old value of the changed entry//-----------------------------------------------------------------------------void PMovies::directorChanged (const Gtk::TreeIter& row, unsigned int column, Glib::ustring& oldValue) {   TRACE9 ("PDirectors::directorChanged (const Gtk::TreeIter&, unsigned int, Glib::ustring&)\n\t- " << column << '/' << oldValue);   Gtk::TreePath path (movies.getModel ()->get_path (row));   aUndo.push (Undo (Undo::CHANGED, DIRECTOR, column,		     YGP::HEntity::cast (movies.getCelebrityAt (row)), path, oldValue));   enableSave ();   apMenus[UNDO]->set_sensitive ();}//----------------------------------------------------------------------------/// Callback when changing a movie/// \param row: Changed line/// \param column: Changed column/// \param oldValue: Old value of the changed entry//-----------------------------------------------------------------------------void PMovies::movieChanged (const Gtk::TreeIter& row, unsigned int column, Glib::ustring& oldValue) {   TRACE9 ("PMovies::movieChanged (const Gtk::TreeIter&, unsigned int, Glib::ustring&)\n\t- " << column << '/' << oldValue);   Gtk::TreePath path (movies.getModel ()->get_path (row));   aUndo.push (Undo (Undo::CHANGED, MOVIE, column, movies.getObjectAt (row), path, oldValue));   apMenus[UNDO]->set_sensitive ();   enableSave ();}//-----------------------------------------------------------------------------/// Adds the menu-entries for the language-menu to the passed string/// \param menu: String, where to add the language-entries to/// \param grpAction: Actiongroup to use//-----------------------------------------------------------------------------void PMovies::addLanguageMenus (Glib::ustring& menu, Glib::RefPtr<Gtk::ActionGroup> grpAction) {   TRACE9 ("PMovies::addLanguageMenus (Glib::ustring&)");   menu += "<menuitem action='Orig'/>";   Gtk::RadioButtonGroup grpLang;   grpAction->add (Gtk::RadioAction::create (grpLang, "Orig", _("_Original name")),		   Gtk::AccelKey ("<ctl>0"),		   bind (mem_fun (*this, &PMovies::changeLanguage), ""));   char accel[7];   strcpy (accel, "<ctl>1");   for (std::map<std::string, Language>::const_iterator i (Language::begin ());	i != Language::end (); ++i) {      TRACE9 ("PMovies::PMovies (Options&) - Adding language " << i->first);      menu += "<menuitem action='" + i->first + "'/>";      Glib::RefPtr<Gtk::RadioAction> act	 (Gtk::RadioAction::create (grpLang, i->first, i->second.getInternational ()));      if (accel[5] <= '9') {	 grpAction->add (act, Gtk::AccelKey (accel),			 bind (mem_fun (*this, &PMovies::changeLanguage), i->first));	 ++accel[5];      }      else	 grpAction->add (act, bind (mem_fun (*this, &PMovies::changeLanguage), i->first));      if (i->first == Movie::currLang)	 act->set_active ();   }}//-----------------------------------------------------------------------------/// Setting the page-specific menu/// \param ui: User-interface string holding menus/// \param grpActions: Added actions//-----------------------------------------------------------------------------void PMovies::addMenu (Glib::ustring& ui, Glib::RefPtr<Gtk::ActionGroup> grpAction) {   TRACE9 ("PMovies::addMenu (Glib::ustring&, Glib::RefPtr<Gtk::ActionGroup>");   Check3 (!imgLang);   imgLang = new LanguageImg (Movie::currLang.c_str ());   imgLang->show ();   imgLang->signal_clicked ().connect (mem_fun (*this, &PMovies::selectLanguage));   statusbar.pack_end (*imgLang, Gtk::PACK_SHRINK, 5);   ui += ("<menuitem action='MUndo'/>"	  "<separator/>"	  "<menuitem action='NDirector'/>"	  "<menuitem action='NMovie'/>"	  "<separator/>"	  "<menuitem action='MDelete'/>"	  "</placeholder></menu>"	  "<placeholder name='Other'><menu action='Lang'>");   grpAction->add (apMenus[UNDO] = Gtk::Action::create ("MUndo", Gtk::Stock::UNDO),		   Gtk::AccelKey (_("<ctl>Z")),		   mem_fun (*this, &PMovies::undo));   grpAction->add (apMenus[NEW1] = Gtk::Action::create ("NDirector", Gtk::Stock::NEW,							_("New _director")),		   Gtk::AccelKey (_("<ctl>N")),		   mem_fun (*this, &PMovies::newDirector));   grpAction->add (apMenus[NEW2] = Gtk::Action::create ("NMovie", _("_New movie")),		   Gtk::AccelKey (_("<ctl><alt>N")),		   mem_fun (*this, &PMovies::newMovie));   grpAction->add (apMenus[DELETE] = Gtk::Action::create ("MDelete", Gtk::Stock::DELETE, _("_Delete")),		   Gtk::AccelKey (_("<ctl>Delete")),		   mem_fun (*this, &PMovies::deleteSelection));   grpAction->add (Gtk::Action::create ("Lang", _("_Language")));   addLanguageMenus (ui, grpAction);   ui += "</menu></placeholder>";   apMenus[UNDO]->set_sensitive (false);   movieSelected ();}//-----------------------------------------------------------------------------/// Removes page-related menus//-----------------------------------------------------------------------------void PMovies::removeMenu () {   TRACE9 ("PMovies::removeMenu ()");   if (imgLang) {      statusbar.remove (*imgLang);      delete imgLang;      imgLang = NULL;   }}//-----------------------------------------------------------------------------/// Callback after selecting menu to set the language in which the/// movies are displayed/// \param lang: Lanuage in which the movies should be displayed//-----------------------------------------------------------------------------void PMovies::changeLanguage (const std::string& lang) {   Check3 (lang.empty () || (lang.size () == 2));   TRACE1 ("PMovies::changeLanguage (const std::string&) - " << lang);   if (lang != Movie::currLang)      setLanguage (lang);}//-----------------------------------------------------------------------------/// Changes the language in which the movies are displayed/// \param lang: Lanuage in which the movies should be displayed//-----------------------------------------------------------------------------void PMovies::setLanguage (const std::string& lang) {   TRACE9 ("PMovies::setLanguage (const std::string&) - " << lang);   Movie::currLang = lang;   if ((lang.size () == 2) && !loadedLangs[lang])      loadData (lang);   movies.update (lang);   imgLang->update (lang.c_str ());}//-----------------------------------------------------------------------------/// Callback to select the language in which to display the movies//-----------------------------------------------------------------------------void PMovies::selectLanguage () {   TRACE9 ("PMovies::selectLanguage ()");   Glib::RefPtr<Gtk::UIManager> mgrUI (Gtk::UIManager::create ());   Glib::RefPtr<Gtk::ActionGroup> grpAction (Gtk::ActionGroup::create ());   Glib::ustring ui ("<ui><popup name='PopupLang'>");   addLanguageMenus (ui, grpAction);   ui += "</popup></ui>";   mgrUI->insert_action_group (grpAction);   mgrUI->add_ui_from_string (ui);   Gtk::Menu* popup (dynamic_cast<Gtk::Menu*> (mgrUI->get_widget ("/PopupLang")));   popup->popup (0, gtk_get_current_event_time ());}//-----------------------------------------------------------------------------/// Sets the focus to the movie-list//-----------------------------------------------------------------------------void PMovies::getFocus () {   movies.grab_focus ();}//-----------------------------------------------------------------------------/// Finds the movie with the passed id/// \param directors: Vector of known directors/// \param relMovies: Relation of above directors to their movies/// \param id: Id of movie to find/// \returns HMovie: Found movie (undefined, if not found)//-----------------------------------------------------------------------------HMovie PMovies::findMovie (const std::vector<HDirector>& directors,			   const YGP::Relation1_N<HDirector, HMovie>& relMovies,			   unsigned int id) {   for (std::vector<HDirector>::const_iterator d (directors.begin ());	d != directors.end (); ++d) {      Check3 (d->isDefined ());      const std::vector<HMovie>& movies (relMovies.getObjects (*d));      for (std::vector<HMovie>::const_iterator m (movies.begin ()); m != movies.end (); ++m) {	 Check3 (m->isDefined ());	 if ((*m)->getId () == id)	    return *m;      }   }   HMovie m;   return m;}//-----------------------------------------------------------------------------/// Loads the movies from the database.//-----------------------------------------------------------------------------void PMovies::loadData () {   TRACE9 ("PMovies::loadData ()");   try {      YGP::StatusObject stat;      StorageMovie::loadDirectors (directors, stat);      std::sort (directors.begin (), directors.end (), &Director::compByName);      std::map<unsigned int, std::vector<HMovie> > aMovies;      unsigned int cMovies (StorageMovie::loadMovies (aMovies, stat));      TRACE8 ("PMovies::loadData () - Found " << cMovies << " movies");      for (std::vector<HDirector>::const_iterator i (directors.begin ());	   i != directors.end (); ++i) {	 Check3 (i->isDefined ());	 Gtk::TreeModel::Row director (movies.append (*i));	 std::map<unsigned int, std::vector<HMovie> >::iterator iMovie	    (aMovies.find ((*i)->getId ()));	 if (iMovie != aMovies.end ()) {	    for (std::vector<HMovie>::iterator m (iMovie->second.begin ());		 m != iMovie->second.end (); ++m) {	       movies.append (*m, director);	       relMovies.relate (*i, *m);	    } // end-for all movies for a director	    aMovies.erase (iMovie);	 } // end-if director has movies      } // end-for all directors

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?