Update variant actions when creating a new game in the same tab. Fixes #64.
[tagua/yd.git] / src / mainwindow.h
blob327ce34585acc5624f23cbc66a364cc755a98e80
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 MAINWINDOW_H
12 #define MAINWINDOW_H
14 #include <map>
15 #include <vector>
16 #include <KXmlGuiWindow>
17 #include <KUrl>
19 #include <QApplication>
20 #include <QMainWindow>
21 #include <QDir>
22 #include "boost/shared_ptr.hpp"
24 #include "ui.h"
25 #include "common.h"
26 #include "export.h"
28 class ChessTable;
29 class ICSConnection;
30 class Console;
31 class GameInfo;
32 class PositionInfo;
33 class Controller;
34 class QConnect;
35 class NewGame;
36 class EngineInfo;
37 class QDockWidget;
38 class TabWidget;
39 class QStackedWidget;
40 class QActionGroup;
41 class KAction;
42 class KIcon;
44 class TAGUA_EXPORT MainWindow : public KXmlGuiWindow {
45 Q_OBJECT
46 QDockWidget* movelist_dock;
47 QDockWidget* console_dock;
49 TabWidget* m_main;
50 QStackedWidget* m_movelist_stack;
51 boost::shared_ptr<ICSConnection> m_connection;
52 Console* console;
54 QMenu* m_engine_menu;
56 ChessTable* table();
57 KUrl m_url;
58 UI m_ui;
59 UI& ui() { return m_ui; }
60 void createTab(ChessTable*, const boost::shared_ptr<Controller>&,
61 const QString& label, int index = -1);
63 QDir m_iconDir;
64 std::vector<EngineInfo*> m_engines;
66 boost::shared_ptr<QConnect> quickConnectDialog;
67 NewGame* newGameDialog;
69 // QAction *mkAction(const QString& txt, QKeySequence shk, QObject *o,
70 // const char *sl, QString name, QObject *par = NULL);
71 void setupActions();
72 void setupEngineMenu();
73 KAction* addPromotionAction(const QString& name, const QString& text, const char* uiSlot);
74 KAction* installRegularAction(const QString& name, const KIcon& icon, const QString& text,
75 QObject* obj, const char* slot);
76 void updateVariantActions(bool unplug = true);
78 bool openFile(const QString&);
79 void saveFile(QFile&);
80 KUrl saveGame(const KUrl& url);
82 void readSettings();
83 void writeSettings();
84 public:
85 MainWindow(const QString& variant);
86 virtual ~MainWindow();
88 protected:
89 void closeEvent(QCloseEvent*);
90 void keyPressEvent(QKeyEvent*);
91 void keyReleaseEvent(QKeyEvent*);
92 private Q_SLOTS:
93 void changeTab(int);
94 void closeTab();
95 public Q_SLOTS:
96 void createConnection(const QString&, const QString&, const QString&,
97 quint16, const QString&, const QString&);
98 void destroyConnection();
99 void testConnect(); // DEBUG
100 void icsConnect();
101 void icsDisconnect();
102 // // void receivedCommand(const QString&);
104 void onEstablishConnection();
105 void onHostLookup();
106 void onConnectionError(int);
107 void onHostFound();
109 void sendLogin();
110 void sendBlankPassword();
111 void prompt();
112 void cleanupGame(const QString&, const QString&);
113 void cleanupGame();
115 void editPosition();
116 void setupGame(const GameInfo*, const PositionInfo&);
117 void setupPGN(const QString& s);
118 void setupExaminedGame(const GameInfo*, const PositionInfo&);
119 void setupObservedGame(const GameInfo*, const PositionInfo&);
120 void newGame();
121 bool newGame(const QString& var, AbstractPosition::Ptr, bool);
122 void loadGame();
123 void saveGame();
124 void saveGameAs();
125 void quit();
126 void flipView();
127 void toggleConsole();
128 void toggleMoveList();
130 void displayMessage(const QString& msg);
131 void displayErrorMessage(ErrorCode);
132 void flash();
134 // void prefHighlight();
135 void preferences();
136 void settingsChanged();
141 #endif // MAINWINDOW_H