File indexing completed on 2024-09-15 03:43:52
0001 /* 0002 This file is part of the KDE games library 0003 SPDX-FileCopyrightText: 2001 Andreas Beckermann (b_mann@gmx.de) 0004 SPDX-FileCopyrightText: 2001 Martin Heni (kde at heni-online.de) 0005 0006 SPDX-License-Identifier: LGPL-2.0-only 0007 */ 0008 0009 // NAMING 0010 // please follow these naming rules if you add/change classes: 0011 // the main dialog is named KGameDialog and the base config widget 0012 // KGameDialogConfig. All config widgets are named KGameDialogXYZConfig (where 0013 // XYZ = the name of the config widget, like "general" or "network") and are 0014 // inherited from KGameDialogConfig. 0015 0016 #ifndef __KGAMEDIALOGCONFIG_H__ 0017 #define __KGAMEDIALOGCONFIG_H__ 0018 0019 // Qt 0020 #include <QWidget> 0021 0022 class KGame; 0023 class KPlayer; 0024 0025 class KGameDialogConfigPrivate; 0026 /** 0027 * \class KGameDialogConfig kgamedialogconfig.h <KGameDialogConfig> 0028 * 0029 * Base class for configuration widgets. 0030 * 0031 * You can inherit from this and implement @ref submitToKGame, @ref 0032 * setOwner and @ref setKGame to create your personal @ref KGame configuration widget :-) 0033 * @short Base class for configuration widgets 0034 * @author Andreas Beckermann <b_mann@gmx.de> 0035 */ 0036 class KGameDialogConfig : public QWidget 0037 { 0038 Q_OBJECT 0039 public: 0040 explicit KGameDialogConfig(QWidget *parent = nullptr); 0041 ~KGameDialogConfig() override; 0042 0043 /** 0044 * Called by @ref KGameDialog to submit all settings to the KGame 0045 * Object. 0046 * You have to replace this if you add your own widgets! 0047 * @param g A pointer to your KGame. 0048 * @param p A pointer to the player owning this dialog 0049 */ 0050 virtual void submitToKGame(KGame *g, KPlayer *p) = 0; 0051 0052 /** 0053 * The owner player of the dialog has been changed. The default 0054 * changes the pointer for owner so don't forget to call the 0055 * default implementation if you overwrite this! 0056 * 0057 * You can use this e.g. to change a line edit widget containing the 0058 * player name. 0059 * 0060 * Note: even NULL players are allowed! 0061 * @param p The new owner player of the dialog 0062 */ 0063 virtual void setOwner(KPlayer *p); 0064 0065 /** 0066 * The KGame object of the dialog has been changed. The default 0067 * implementation changes the pointer for game so don't forget to 0068 * call the default implementation if you overwrite this! 0069 * 0070 * You can use this e.g. to re-read the min/max player settings. 0071 * @param g The KGame object 0072 */ 0073 virtual void setKGame(KGame *g); 0074 0075 /** 0076 * The admin status has been changed. 0077 * If the KGame object of this config widget is the 0078 * admin the user is allowed to configure it. Otherwise most 0079 * widgets will have to be disabled. Note that you don't necessarily 0080 * need to deactivate all widget - e.g. the player name must be 0081 * configured by the player. Mainly the KGame configuration can be done 0082 * by the admin only. 0083 * 0084 * By default this does nothing. Changes the value for admin so 0085 * don't forget to call the default implementation in derived classes! 0086 * @param admin Whether the KGame object of this dialog can be 0087 * configured 0088 */ 0089 virtual void setAdmin(bool admin); 0090 0091 /** 0092 * A pointer to the KGame object that has been set by @ref setKGame. 0093 * 0094 * Note that NULL is allowed! 0095 * @return The KGame object assigned to this dialog 0096 */ 0097 KGame *game() const; 0098 0099 /** 0100 * A pointer to the KPlayer object that has been set by @ref 0101 * setOwner. 0102 * 0103 * Note that NULL is allowed! 0104 * @return The owner of the dialog 0105 */ 0106 KPlayer *owner() const; 0107 0108 /** 0109 * @return True if the owner is ADMIN otherwise FALSE. See also 0110 * @ref setAdmin 0111 */ 0112 bool admin() const; 0113 0114 protected: 0115 private: 0116 KGameDialogConfigPrivate *const d; 0117 }; 0118 0119 class KGameDialogNetworkConfigPrivate; 0120 /** 0121 * \class KGameDialogNetworkConfig kgamedialogconfig.h <KGameDialogConfig> 0122 */ 0123 class KGameDialogNetworkConfig : public KGameDialogConfig 0124 { 0125 Q_OBJECT 0126 public: 0127 explicit KGameDialogNetworkConfig(QWidget *parent = nullptr); 0128 ~KGameDialogNetworkConfig() override; 0129 0130 /** 0131 * Called by @ref KGameDialog to submit all settings to the KGame 0132 * Object. 0133 * You have to replace this if you add your own widgets! 0134 * @param g A pointer to your KGame. 0135 * @param p A pointer to the player owning this dialog 0136 */ 0137 void submitToKGame(KGame *g, KPlayer *p) override; 0138 0139 void setKGame(KGame *g) override; 0140 0141 /** 0142 * This sets the default port and host used in @ref KGameConnectDialog. 0143 * The user will be able to change these defaults! 0144 * 0145 * If you don't call this then host "localhost" and port "0" is used. 0146 * You are strongly encouraged to change at least the port! 0147 * @param port The default port to connect to / listen on 0148 * @param host The default host to connect to 0149 * @param server The default state. 0 For a server game, 1 to join a game 0150 */ 0151 void setDefaultNetworkInfo(const QString &host, unsigned short int port, bool server = true); 0152 0153 /** 0154 * Set service type that will be published or browsed for and game name that will be displayed in 0155 * server browser. Without this publishing and discovery of LAN servers will not be enabled. 0156 * @param name Game name. Important only for server mode. If not 0157 * set hostname will be used. In case of name conflict -2, -3 and so on will be added to name. 0158 * @param type Service type (something like _kwin4._tcp). It should be unique for application. 0159 */ 0160 void setDiscoveryInfo(const QString &type, const QString &name = QString()); 0161 0162 Q_SIGNALS: 0163 /** 0164 * This signal is emitted if the user changes the server type (client/server) 0165 * in the network configuration dialog. 0166 * 0167 * @param t type (0/1) of the connection 0168 */ 0169 void signalServerTypeChanged(int t); 0170 0171 protected: 0172 void setConnected(bool connected, bool master = false); 0173 0174 protected Q_SLOTS: 0175 void slotInitConnection(); 0176 void slotExitConnection(); 0177 void slotConnectionBroken(); 0178 0179 private: 0180 KGameDialogNetworkConfigPrivate *d; 0181 }; 0182 0183 #endif