67
67
class ChessPlugin: public QObject, public PsiPlugin, public OptionAccessor, public ActiveTabAccessor, public MenuAccessor, public ApplicationInfoAccessor,
68
public ToolbarIconAccessor, public IconFactoryAccessor, public StanzaSender, public AccountInfoAccessor, public StanzaFilter,
69
public PluginInfoProvider, public EventCreator, public ContactInfoAccessor, public PopupAccessor, public SoundAccessor
68
public ToolbarIconAccessor, public IconFactoryAccessor, public StanzaSender, public AccountInfoAccessor, public StanzaFilter,
69
public PluginInfoProvider, public EventCreator, public ContactInfoAccessor, public PopupAccessor, public SoundAccessor
73
Q_PLUGIN_METADATA(IID "com.psi-plus.ChessPlugin")
72
75
Q_INTERFACES(PsiPlugin AccountInfoAccessor OptionAccessor ActiveTabAccessor MenuAccessor StanzaFilter ContactInfoAccessor SoundAccessor
73
ToolbarIconAccessor IconFactoryAccessor StanzaSender ApplicationInfoAccessor PluginInfoProvider EventCreator PopupAccessor)
76
ToolbarIconAccessor IconFactoryAccessor StanzaSender ApplicationInfoAccessor PluginInfoProvider EventCreator PopupAccessor)
77
80
virtual QString name() const;
78
81
virtual QString shortName() const;
79
82
virtual QString version() const;
80
virtual QWidget* options();
83
virtual QWidget* options();
81
84
virtual bool enable();
82
virtual bool disable();
83
virtual void applyOptions();
84
virtual void restoreOptions();
85
virtual void optionChanged(const QString& /*option*/){};
86
virtual void setAccountInfoAccessingHost(AccountInfoAccessingHost* host);
87
virtual void setOptionAccessingHost(OptionAccessingHost* host);
88
virtual void setActiveTabAccessingHost(ActiveTabAccessingHost* host);
89
virtual void setIconFactoryAccessingHost(IconFactoryAccessingHost* host);
90
virtual void setStanzaSendingHost(StanzaSendingHost *host);
85
virtual bool disable();
86
virtual void applyOptions();
87
virtual void restoreOptions();
88
virtual void optionChanged(const QString& /*option*/){};
89
virtual void setAccountInfoAccessingHost(AccountInfoAccessingHost* host);
90
virtual void setOptionAccessingHost(OptionAccessingHost* host);
91
virtual void setActiveTabAccessingHost(ActiveTabAccessingHost* host);
92
virtual void setIconFactoryAccessingHost(IconFactoryAccessingHost* host);
93
virtual void setStanzaSendingHost(StanzaSendingHost *host);
91
94
virtual QList < QVariantHash > getButtonParam();
92
95
virtual QAction* getAction(QObject* , int , const QString& ) { return 0; };
93
96
virtual QList < QVariantHash > getAccountMenuParam();
94
97
virtual QList < QVariantHash > getContactMenuParam();
95
98
virtual QAction* getContactAction(QObject* , int , const QString& ) { return 0; };
96
99
virtual QAction* getAccountAction(QObject* , int ) { return 0; };
97
virtual void setApplicationInfoAccessingHost(ApplicationInfoAccessingHost* host);
98
virtual bool incomingStanza(int account, const QDomElement& xml);
100
virtual void setApplicationInfoAccessingHost(ApplicationInfoAccessingHost* host);
101
virtual bool incomingStanza(int account, const QDomElement& xml);
99
102
virtual bool outgoingStanza(int account, QDomElement& xml);
100
103
virtual void setEventCreatingHost(EventCreatingHost *host);
101
104
virtual void setContactInfoAccessingHost(ContactInfoAccessingHost* host);
102
105
virtual QString pluginInfo();
103
106
virtual void setPopupAccessingHost(PopupAccessingHost* host);
104
107
virtual void setSoundAccessingHost(SoundAccessingHost* host);
108
virtual QPixmap icon() const;
107
111
void closeBoardEvent();
141
OptionAccessingHost* psiOptions;
145
OptionAccessingHost* psiOptions;
142
146
AccountInfoAccessingHost *accInfoHost;
143
ActiveTabAccessingHost* activeTab;
147
ActiveTabAccessingHost* activeTab;
144
148
IconFactoryAccessingHost *icoHost;
145
ApplicationInfoAccessingHost* appInfo;
146
StanzaSendingHost *stanzaSender;
149
ApplicationInfoAccessingHost* appInfo;
150
StanzaSendingHost *stanzaSender;
147
151
EventCreatingHost *psiEvent;
148
152
ContactInfoAccessingHost* contactInfo;
149
153
PopupAccessingHost* popup;
150
154
SoundAccessingHost* sound_;
158
QString soundStart, soundFinish, soundMove, soundError;
159
bool DndDisable, DefSoundSettings, enableSound;
162
QString soundStart, soundFinish, soundMove, soundError;
163
bool DndDisable, DefSoundSettings, enableSound;
163
167
QList<Request> requests;
164
168
QList<Request> invites;
165
169
Request currentGame_;
168
173
Q_EXPORT_PLUGIN(ChessPlugin);
170
176
ChessPlugin::ChessPlugin()
218
224
requests.clear();
222
228
QFile file(":/chessplugin/figures/Black queen 2d.png");
223
229
if(file.open(QIODevice::ReadOnly)) {
224
230
QByteArray ico = file.readAll();
225
231
icoHost->addIcon("chessplugin/chess", ico);
228
soundStart = psiOptions->getPluginOption(soundStartConst, QVariant(soundStart)).toString();
229
soundFinish = psiOptions->getPluginOption(soundFinishConst, QVariant(soundFinish)).toString();
230
soundMove = psiOptions->getPluginOption(soundMoveConst, QVariant(soundMove)).toString();
231
soundError = psiOptions->getPluginOption(soundErrorConst, QVariant(soundError)).toString();
232
DndDisable = psiOptions->getPluginOption(constDndDisable, QVariant(DndDisable)).toBool();
233
DefSoundSettings = psiOptions->getPluginOption(constDefSoundSettings, QVariant(DefSoundSettings)).toBool();
234
soundStart = psiOptions->getPluginOption(soundStartConst, QVariant(soundStart)).toString();
235
soundFinish = psiOptions->getPluginOption(soundFinishConst, QVariant(soundFinish)).toString();
236
soundMove = psiOptions->getPluginOption(soundMoveConst, QVariant(soundMove)).toString();
237
soundError = psiOptions->getPluginOption(soundErrorConst, QVariant(soundError)).toString();
238
DndDisable = psiOptions->getPluginOption(constDndDisable, QVariant(DndDisable)).toBool();
239
DefSoundSettings = psiOptions->getPluginOption(constDefSoundSettings, QVariant(DefSoundSettings)).toBool();
237
243
bool ChessPlugin::disable() {
467
474
//Этот метод вызывается, когда вы принимаете приглашение
468
475
void ChessPlugin::accept() {
469
stanzaSender->sendStanza(currentGame_.account, QString("<iq type=\"result\" to=\"%1\" id=\"%2\"><create xmlns=\"games:board\" type=\"chess\" id=\"%3\"/></iq>")
470
.arg(currentGame_.jid)
471
.arg(currentGame_.requestId)
472
.arg(currentGame_.chessId));
476
stanzaSender->sendStanza(currentGame_.account,
477
QString("<iq type=\"result\" to=\"%1\" id=\"%2\"><create xmlns=\"games:board\" type=\"chess\" id=\"%3\"/></iq>")
478
.arg(currentGame_.jid)
479
.arg(currentGame_.requestId)
480
.arg(currentGame_.chessId));
476
484
//Этот метод вызывается, когда вы отказываетесь от игры
477
485
void ChessPlugin::reject() {
478
stanzaSender->sendStanza(currentGame_.account, QString("<iq type=\"error\" to=\"%1\" id=\"%2\"></iq>")
479
.arg(currentGame_.jid)
480
.arg(currentGame_.requestId));
486
stanzaSender->sendStanza(currentGame_.account,
487
QString("<iq type=\"error\" to=\"%1\" id=\"%2\"></iq>")
488
.arg(currentGame_.jid)
489
.arg(currentGame_.requestId));
484
493
// Этот метод вызывается, когда вы закрыли доску.
485
494
void ChessPlugin::closeBoardEvent() {
486
stanzaSender->sendStanza(currentGame_.account, QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><close xmlns=\"games:board\" id=\"%3\" type=\"chess\"></close></iq>")
487
.arg(currentGame_.jid)
489
.arg(currentGame_.chessId));
495
stanzaSender->sendStanza(currentGame_.account,
496
QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><close xmlns=\"games:board\" id=\"%3\" type=\"chess\"></close></iq>")
497
.arg(currentGame_.jid)
499
.arg(currentGame_.chessId));
491
501
if((DefSoundSettings || psiOptions->getGlobalOption("options.ui.notifications.sounds.enable").toBool()) && enableSound)
492
502
playSound(soundFinish);
541
551
// Вы отправляете вашему сопернику сохраненную партию
542
552
void ChessPlugin::load(const QString& settings) {
543
stanzaSender->sendStanza(currentGame_.account, QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><load xmlns=\"games:board\" id=\"%3\" type=\"chess\">%4</load></iq>")
544
.arg(currentGame_.jid)
546
.arg(currentGame_.chessId)
553
stanzaSender->sendStanza(currentGame_.account,
554
QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><load xmlns=\"games:board\" id=\"%3\" type=\"chess\">%4</load></iq>")
555
.arg(currentGame_.jid)
557
.arg(currentGame_.chessId)
551
562
void ChessPlugin::move(int oldX, int oldY, int newX, int newY, const QString& figure) {
552
563
QString stanza = QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><turn xmlns=\"games:board\" type=\"chess\" id=\"%7\"><move pos=\"%3,%4;%5,%6\">")
553
.arg(currentGame_.jid)
555
.arg(QString::number(oldX))
556
.arg(QString::number(oldY))
557
.arg(QString::number(newX))
558
.arg(QString::number(newY))
559
.arg(currentGame_.chessId);
564
.arg(currentGame_.jid)
566
.arg(QString::number(oldX))
567
.arg(QString::number(oldY))
568
.arg(QString::number(newX))
569
.arg(QString::number(newY))
570
.arg(currentGame_.chessId);
560
571
if(!figure.isEmpty())
561
572
stanza += QString("<promotion>%1</promotion>").arg(figure);
562
573
stanza += "</move></turn></iq>";
568
579
// Вы согласились с ходом
569
580
void ChessPlugin::moveAccepted() {
570
stanzaSender->sendStanza(currentGame_.account, QString("<iq type=\"result\" to=\"%1\" id=\"%2\"><turn type=\"chess\" id=\"%3\" xmlns=\"games:board\"/></iq>")
571
.arg(currentGame_.jid)
573
.arg(currentGame_.chessId));
581
stanzaSender->sendStanza(currentGame_.account,
582
QString("<iq type=\"result\" to=\"%1\" id=\"%2\"><turn type=\"chess\" id=\"%3\" xmlns=\"games:board\"/></iq>")
583
.arg(currentGame_.jid)
585
.arg(currentGame_.chessId));
576
588
void ChessPlugin::youLose() {
577
589
if(theEnd_) return;
578
stanzaSender->sendStanza(currentGame_.account, QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><turn xmlns=\"games:board\" type=\"chess\" id=\"%3\"><resign/></turn></iq>")
579
.arg(currentGame_.jid)
581
.arg(currentGame_.chessId));
590
stanzaSender->sendStanza(currentGame_.account,
591
QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><turn xmlns=\"games:board\" type=\"chess\" id=\"%3\"><resign/></turn></iq>")
592
.arg(currentGame_.jid)
594
.arg(currentGame_.chessId));
582
595
board->youLose();
584
597
QMessageBox::information(board, tr("Chess Plugin"),
585
tr("You Lose."), QMessageBox::Ok);
598
tr("You Lose."), QMessageBox::Ok);
588
601
void ChessPlugin::youWin() {
594
607
QMessageBox::information(board, tr("Chess Plugin"),
595
tr("You Win!"), QMessageBox::Ok);
608
tr("You Win!"), QMessageBox::Ok);
598
611
void ChessPlugin::draw() {
600
stanzaSender->sendStanza(currentGame_.account, QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><turn xmlns=\"games:board\" type=\"chess\" id=\"%3\"><draw/></turn></iq>")
601
.arg(currentGame_.jid)
603
.arg(currentGame_.chessId));
613
stanzaSender->sendStanza(currentGame_.account,
614
QString("<iq type=\"set\" to=\"%1\" id=\"%2\"><turn xmlns=\"games:board\" type=\"chess\" id=\"%3\"><draw/></turn></iq>")
615
.arg(currentGame_.jid)
617
.arg(currentGame_.chessId));
604
618
if((DefSoundSettings || psiOptions->getGlobalOption("options.ui.notifications.sounds.enable").toBool()) && enableSound)
605
619
playSound(soundStart);
606
620
board->youDraw();
608
622
QMessageBox::information(board, tr("Chess Plugin"),
609
tr("Draw!"), QMessageBox::Ok);
623
tr("Draw!"), QMessageBox::Ok);
842
858
QString ChessPlugin::pluginInfo() {
843
return tr("Author: ") + "Dealer_WeARE\n"
844
+ tr("Email: ") + "wadealer@gmail.com\n\n"
845
+ trUtf8("This plugin allows you to play chess with your friends.\n"
846
"The plugin is compatible with a similar plugin for Tkabber.\n"
847
"For sending commands, normal messages are used, so this plugin will always work wherever you are able to log in."
848
"To invite a friend for a game, you can use contact menu item or the button on the toolbar in a chat window.");
859
return tr("Author: ") + "Dealer_WeARE\n"
860
+ tr("Email: ") + "wadealer@gmail.com\n\n"
861
+ trUtf8("This plugin allows you to play chess with your friends.\n"
862
"The plugin is compatible with a similar plugin for Tkabber.\n"
863
"For sending commands, normal messages are used, so this plugin will always work wherever you are able to log in."
864
"To invite a friend for a game, you can use contact menu item or the button on the toolbar in a chat window.");
867
QPixmap ChessPlugin::icon() const
869
return QPixmap(":/chessplugin/chess.png");
852
872
#include "chessplugin.moc"