pactors.cpp
来自「磁盘管理工具,主要管理光盘信息和内容希望大家喜欢」· C++ 代码 · 共 715 行 · 第 1/2 页
CPP
715 行
//$Id: PActors.cpp,v 1.17 2006/06/06 22:02:03 markus Rel $//PROJECT : CDManager//SUBSYSTEM : Actors//REFERENCES ://TODO ://BUGS ://REVISION : $Revision: 1.17 $//AUTHOR : Markus Schwab//CREATED : 20.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 <gtkmm/stock.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 "Genres.h"#include "PMovies.h"#include "MovieList.h"#include "SaveCeleb.h"#include "StorageActor.h"#include "PActors.h"//-----------------------------------------------------------------------------/// Constructor: Creates a widget handling actors/// \param status: Statusbar to display status-messages/// \param menuSave: Menu-entry to save the database/// \param genres: Genres to use in actor-list/// \param movies: Reference to movie-page//-----------------------------------------------------------------------------PActors::PActors (Gtk::Statusbar& status, Glib::RefPtr<Gtk::Action> menuSave, const Genres& genres, PMovies& movies) : NBPage (status, menuSave), actors (genres), relActors ("actors"), movies (movies), actView (0) { TRACE9 ("PActors::PActors (Gtk::Statusbar&, Glib::RefPtr<Gtk::Action>, const Genres&, PMovies&)"); Gtk::ScrolledWindow* scrl (new Gtk::ScrolledWindow); scrl->set_shadow_type (Gtk::SHADOW_ETCHED_IN); scrl->add (actors); scrl->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); Glib::RefPtr<Gtk::TreeSelection> sel (actors.get_selection ()); sel->signal_changed ().connect (mem_fun (*this, &PActors::actorSelected)); actors.signalActorChanged.connect (mem_fun (*this, &PActors::actorChanged)); widget = scrl;}//-----------------------------------------------------------------------------/// Destructor//-----------------------------------------------------------------------------PActors::~PActors () {}//-----------------------------------------------------------------------------/// Callback after selecting an actor/// \param row: Selected row//-----------------------------------------------------------------------------void PActors::actorSelected () { TRACE9 ("PActords::actorSelected ()"); Check3 (actors.get_selection ()); Gtk::TreeIter s (actors.get_selection ()->get_selected ()); if (actView) { enableEdit ((s && (*s)->parent ()) ? OWNER_SELECTED : NONE_SELECTED); apMenus[NEW1]->set_sensitive (false); } else { enableEdit (s ? OWNER_SELECTED : NONE_SELECTED); if (s && (*s)->parent ()) apMenus[DELETE]->set_sensitive (false); }}//----------------------------------------------------------------------------/// Callback when changing an actor/// \param row: Changed line/// \param column: Changed column/// \param oldValue: Old value of the changed entry//-----------------------------------------------------------------------------void PActors::actorChanged (const Gtk::TreeIter& row, unsigned int column, Glib::ustring& oldValue) { TRACE9 ("PActors::actorChanged (const Gtk::TreeIter&, unsigned int, Glib::ustring&)"); Gtk::TreePath path (actors.get_model ()->get_path (row)); YGP::HEntity entity (actors.getEntityAt (row)); aUndo.push (Undo (Undo::CHANGED, ACTOR, column, entity, path, oldValue)); if (actView) changeAllEntries (entity, actors.getModel ()->children ().begin (), actors.getModel ()->children ().end ()); std::sort (aActors.begin (), aActors.end (), &Actor::compByName); apMenus[UNDO]->set_sensitive (); enableSave ();}//-----------------------------------------------------------------------------/// Adds a new actor to the list//-----------------------------------------------------------------------------void PActors::newActor () { HActor actor; actor.define (); Gtk::TreeModel::iterator i; if (actView) { Check3 (actors.get_selection ()->get_selected ()); i = actors.append (YGP::HEntity::cast (actor), actors.get_selection ()->get_selected ()); } else i = actors.append (YGP::HEntity::cast (actor)); aActors.insert (lower_bound (aActors.begin (), aActors.end (), actor, &Actor::compByName), actor); Gtk::TreePath path (actors.get_model ()->get_path (i)); actors.selectRow (i); aUndo.push (Undo (Undo::INSERT, ACTOR, 0, YGP::HEntity::cast (actor), path, "")); apMenus[UNDO]->set_sensitive (); enableSave ();}//-----------------------------------------------------------------------------/// Displays a dialog enabling to connect movies and actors//-----------------------------------------------------------------------------void PActors::actorPlaysInMovie () { TRACE9 ("PActors::actorPlaysInMovie ()"); Check3 (actors.get_selection ()); Gtk::TreeIter p (actors.get_selection ()->get_selected ()); Check3 (p); YGP::HEntity h (actors.getEntityAt (p)); HActor actor (HActor::castDynamic (h)); if (!actor.isDefined ()) { Check3 ((*p)->parent ()); p = (*p)->parent (); h = actors.getEntityAt (p); actor = HActor::castDynamic (h); } Check3 (actor.isDefined ()); TRACE9 ("void PActors::actorPlaysInMovie () - Found actor " << actor->getName ()); RelateMovie* dlg (relActors.isRelated (actor) ? RelateMovie::create (actor, relActors.getObjects (actor), movies.getMovieList ().getModel ()) : RelateMovie::create (actor, movies.getMovieList ().getModel ())); dlg->get_window ()->set_transient_for (actors.get_window ()); dlg->signalRelateMovies.connect (mem_fun (*this, &PActors::relateMovies));}//-----------------------------------------------------------------------------/// Relates movies with an actor/// \param actor: Actor, to which store movies/// \param movies: Movies, starring this actor//-----------------------------------------------------------------------------void PActors::relateMovies (const HActor& actor, const std::vector<HMovie>& movies) { TRACE9 ("PActors::relateMovies (const HActor&, const std::vector<HMovie>&)"); Check2 (actor.isDefined ()); Glib::RefPtr<Gtk::TreeStore> model (actors.getModel ()); Gtk::TreeIter i (actors.findEntity (YGP::HEntity::cast (actor))); Check3 (i); Gtk::TreePath path (model->get_path (i)); // Unrelate old movies and relate with newly selected ones YGP::Handle<RelUndo> hOldRel; hOldRel.define (); if (relActors.isRelated (actor)) hOldRel->setRelatedMovies (relActors.getObjects (actor)); aUndo.push (Undo (Undo::CHANGED, MOVIES, actor->getId (), YGP::HEntity::cast (hOldRel), path, "")); delRelation[YGP::HEntity::cast (hOldRel)] = YGP::HEntity::cast (actor); showMovies (actor, movies); apMenus[UNDO]->set_sensitive (); enableSave ();}//-----------------------------------------------------------------------------/// Shows the movies of a certain actor/// \param actor: Actor/// \param newMovies: Array with new movies//-----------------------------------------------------------------------------void PActors::showMovies (const HActor& actor, const std::vector<HMovie>& newMovies) { Glib::RefPtr<Gtk::TreeStore> model (actors.getModel ()); Gtk::TreeIter i (actors.findEntity (YGP::HEntity::cast (actor))); Check3 (i); // Unrelate old movies from actor; in view-by-movie mode this means also // remove the actors from the movies TRACE5 ("PActors::showMovies (HActor, std::vector<HMovie>) - Relate to " << newMovies.size () << " movies"); std::vector<Gtk::TreeIter> emptyMovies; if (relActors.isRelated (actor)) { if (actView) { for (std::vector<HMovie>::const_iterator m (relActors.getObjects (actor).begin ()); m != relActors.getObjects (actor).end (); ++m) { Gtk::TreeIter i (actors.findEntity (YGP::HEntity::cast (actor), 2)); Check2 (i); Check3 ((*i)->parent ()); Gtk::TreeIter parent ((*i)->parent ()); Check3 (parent); model->erase (i); // Check if parent of deleted actor has now no more childs; // If so, store this movie, to maybe remove it later from the list if (parent->children ().empty ()) emptyMovies.push_back (parent); } } else while ((*i)->children ().size ()) model->erase ((*i)->children ().begin ()); relActors.unrelateAll (actor); } // Then relate the new (undone) movies with actor; in view-by-movie mode // this means also showing the actor for the movies for (std::vector<HMovie>::const_iterator m (newMovies.begin ()); m != newMovies.end (); ++m) { relActors.relate (actor, *m); if (actView) { Gtk::TreeIter iter (*actors.findEntity (YGP::HEntity::cast (*m), 1)); if (!iter) iter = actors.append (YGP::HEntity::cast (*m)); Gtk::TreeRow row (*iter); actors.append (YGP::HEntity::cast (actor), row); actors.expand_row (model->get_path (row), true); } else actors.append (YGP::HEntity::cast (*m), *i); } if (actView) { // Remove all movies without actors for (std::vector<Gtk::TreeIter>::iterator i (emptyMovies.begin ()); i != emptyMovies.end (); ++i) if ((*i)->children ().empty ()) model->erase (*i); } else { // In view-by-actor mode the remove/append can be done in one step actors.selectRow (i); actors.expand_row (model->get_path (i), true); }}//-----------------------------------------------------------------------------/// Loads the actors from the database////// According to the available information the page of the notebook/// is created.//-----------------------------------------------------------------------------void PActors::PActors::loadData () { TRACE5 ("PActors::loadData ()"); if (!movies.isLoaded ()) movies.loadData (); try { YGP::StatusObject stat; StorageActor::loadActors (aActors, stat); TRACE9 ("PActors::loadData () - Actors: " << aActors.size ()); if (aActors.size ()) { std::sort (aActors.begin (), aActors.end (), &Actor::compByName); std::map<unsigned int, std::vector<unsigned int> > actorMovies; StorageActor::loadActorsInMovies (actorMovies); // Iterate over all actors for (std::vector<HActor>::const_iterator i (aActors.begin ()); i != aActors.end (); ++i) { Check3 (i->isDefined ()); Gtk::TreeModel::Row actor (actors.append (YGP::HEntity::cast (*i))); // Get the movies the actor played in std::map<unsigned int, std::vector<unsigned int> >::iterator iActor (actorMovies.find ((*i)->getId ())); if (iActor != actorMovies.end ()) { // Get movies to the movie-IDs std::vector<HMovie> movies; movies.reserve (iActor->second.size ()); for (std::vector<unsigned int>::iterator m (iActor->second.begin ()); m != iActor->second.end (); ++m) { HMovie movie (findMovie (*m)); if (movie.isDefined ()) movies.push_back (movie); else { Glib::ustring err (_("The database contains an invalid reference (%1) to a movie!")); err.replace (err.find ("%1"), 2, YGP::ANumeric::toString (*m)); throw std::invalid_argument (err); } } // Add the movies to the actor std::sort (movies.begin (), movies.end (), Movie::compByName); for (std::vector<HMovie>::iterator m (movies.begin ()); m != movies.end (); ++m) { Check (m->isDefined ()); actors.append (YGP::HEntity::cast (*m), actor); relActors.relate (*i, *m); } // end-for all movies for an actor actorMovies.erase (iActor); } // end-if director has actors for movies } // end-for all actors actors.expand_all (); } // endif actors available Glib::ustring msg (Glib::locale_to_utf8 (ngettext ("Loaded %1 actor", "Loaded %1 actors", aActors.size ()))); msg.replace (msg.find ("%1"), 2, YGP::ANumeric::toString (aActors.size ())); showStatus (msg); loaded = true; if (stat.getType () > YGP::StatusObject::UNDEFINED) { stat.generalize (_("Warnings loading actors!")); XGP::MessageDlg::create (stat); } } catch (std::exception& err) { Glib::ustring msg (_("Can't query the actors1!\n\nReason: %1")); msg.replace (msg.find ("%1"), 2, err.what ()); Gtk::MessageDialog dlg (msg, Gtk::MESSAGE_ERROR); dlg.run (); }}//-----------------------------------------------------------------------------/// Sets the focus to the actor-list//-----------------------------------------------------------------------------void PActors::getFocus () { actors.grab_focus ();}//-----------------------------------------------------------------------------/// Finds the movie with the passed id/// \param id: Id of movie to find/// \returns HMovie: Found movie (undefined, if not found)//-----------------------------------------------------------------------------HMovie PActors::findMovie (unsigned int id) const {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?