Remove debugging traces, now that PGN load/save works.
[tagua/yd.git] / src / controllers / abstract.h
blobe86ff5daf2b3c07b1fe07ea57b875c006197db46
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef CONTROLLER_H
12 #define CONTROLLER_H
14 #include <boost/enable_shared_from_this.hpp>
15 #include <QString>
16 #include <KUrl>
17 #include "common.h"
18 #include "entitytoken.h"
19 #include "fwd.h"
21 class ChessTable;
22 class UserEntity;
23 class Engine;
24 class PGN;
25 class ActionCollection;
26 class UI;
28 /**
29 * @b Controller is the base abstract class for all controllers in Tagua.
30 * Tagua can be used in different modes, such as game editing or position editing.
31 * Each mode corresponds to a concrete subclass of Controller, and defines its behaviour
32 * in response to user events (history navigation, move executions...).
33 * By default, events are routed to the user entity returned by the virtual function
34 * entity.
36 class Controller : public boost::enable_shared_from_this<Controller> {
37 protected:
38 ChessTable* m_view;
39 virtual boost::shared_ptr<UserEntity> entity() const = 0;
40 KUrl m_url;
41 public:
42 Controller(ChessTable* view);
43 virtual ~Controller();
45 /**
46 * Variant specific actions.
48 virtual ActionCollection* variantActions() const = 0;
50 /**
51 * Variant associated to the controller.
53 virtual QString variant() const = 0;
55 /**
56 * Terminate activity, create another controller and delegate everything to it.
57 * @return The delegate controller, or simply @b this if controller does not need
58 * to be terminated.
60 virtual boost::shared_ptr<Controller> end() { return shared_from_this(); }
62 /**
63 * Detach from resources without disposing them.
65 virtual void detach() { }
67 /**
68 * Clear board. Undefined for almost all controllers.
69 * @return Whether the action has been successfully executed.
71 virtual bool clearBoard() { return false; }
73 /**
74 * Set starting position on the board. Undefined for almost all controllers.
75 * @return Whether the action has been successfully executed.
77 virtual bool setStartingPosition() { return false; }
79 /**
80 * Set a position on the board. Undefined for almost all controllers.
81 * @param fen The position to be set, in FEN notation.
82 * @return Whether the action has been successfully executed.
84 virtual bool setFEN(const QString&) { return false; }
86 /**
87 * Get a FEN string representing the current position on the board.
89 virtual QString fen() { return ""; }
91 /**
92 * @return current position, or a null shared_ptr if no current position
93 * concept is defined for this controller.
95 virtual PositionPtr currentPosition() const { return PositionPtr(); }
97 /**
98 * Change turn. Used for example in edit position mode.
100 virtual void setTurn(int) { }
103 * Forward a movelist undo call.
105 virtual bool undo();
108 * Forward a movelist redo call.
110 virtual bool redo();
113 * Forward a movelist truncate call.
115 virtual bool truncate();
118 * Forward a movelist promote variation call.
120 virtual bool promoteVariation();
123 * Navigate back in history.
125 virtual bool back();
128 * Navigate forward in history.
130 virtual bool forward();
133 * Warp to the beginning of the history.
135 virtual void gotoFirst();
138 * Warp to the end of the history.
140 virtual void gotoLast();
143 * Save game.
145 virtual QString save();
148 * Load game from a PGN.
150 virtual void loadPGN(const PGN&);
153 * Create a CTRL Action.
154 * @sa UI::createCtrlAction
156 virtual void createCtrlAction() { }
159 * Destroy a CTRL Action.
160 * @sa UI::createCtrlAction.
162 virtual void destroyCtrlAction() { };
165 * Let an engine play as player @a side.
166 * @return a token which uniquely identifies the engine entity
167 * and can be used to remove it from the entity list.
169 virtual EntityToken addPlayingEngine(int /*side*/, const boost::shared_ptr<Engine>&) { return EntityToken(); }
172 * Remove an entity from the controller list.
174 virtual void removeEntity(const EntityToken&) { }
176 virtual void reloadSettings() = 0;
179 * Set owning user interface.
180 * Used to setup callbacks towards the main window, like action state
181 * change notifications.
183 virtual void setUI(UI& ui) = 0;
186 * Called whenever a controller becomes active in the main window.
188 virtual void activate() = 0;
191 * Each controller has an associated URL that will be used for saving
192 * its content.
193 * @return The URL associated with this controller.
195 virtual KUrl url() const;
198 * Set this controller's URL.
199 * @sa url()
201 virtual void setUrl(const KUrl& url);
205 #endif