1 /***************************************************************************
2  *   Copyright (C) 2008 by Max-Wilhelm Bruker   *
3  *   brukie@gmx.net   *
4  *                                                                         *
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  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef WINDOW_H
21 #define WINDOW_H
22 
23 #include "abstractclient.h"
24 #include "pb/response.pb.h"
25 
26 #include <QList>
27 #include <QMainWindow>
28 #include <QMessageBox>
29 #include <QProcess>
30 #include <QSystemTrayIcon>
31 #include <QtNetwork>
32 
33 class DlgConnect;
34 class DlgViewLog;
35 class GameReplay;
36 class HandlePublicServers;
37 class LocalClient;
38 class LocalServer;
39 class QThread;
40 class RemoteClient;
41 class ServerInfo_User;
42 class TabSupervisor;
43 class WndSets;
44 class DlgTipOfTheDay;
45 
46 class MainWindow : public QMainWindow
47 {
48     Q_OBJECT
49 public slots:
50     void actCheckCardUpdates();
51     void actCheckServerUpdates();
52 private slots:
53     void updateTabMenu(const QList<QMenu *> &newMenuList);
54     void statusChanged(ClientStatus _status);
55     void processConnectionClosedEvent(const Event_ConnectionClosed &event);
56     void processServerShutdownEvent(const Event_ServerShutdown &event);
57     void serverTimeout();
58     void loginError(Response::ResponseCode r, QString reasonStr, quint32 endTime, QList<QString> missingFeatures);
59     void registerError(Response::ResponseCode r, QString reasonStr, quint32 endTime);
60     void activateError();
61     void socketError(const QString &errorStr);
62     void protocolVersionMismatch(int localVersion, int remoteVersion);
63     void userInfoReceived(const ServerInfo_User &userInfo);
64     void registerAccepted();
65     void registerAcceptedNeedsActivate();
66     void activateAccepted();
67     void localGameEnded();
68     void pixmapCacheSizeChanged(int newSizeInMBs);
69     void notifyUserAboutUpdate();
70     void actConnect();
71     void actDisconnect();
72     void actSinglePlayer();
73     void actWatchReplay();
74     void actDeckEditor();
75     void actFullScreen(bool checked);
76     void actRegister();
77     void actSettings();
78     void actExit();
79     void actForgotPasswordRequest();
80     void actAbout();
81     void actTips();
82     void actUpdate();
83     void actViewLog();
84     void forgotPasswordSuccess();
85     void forgotPasswordError();
86     void promptForgotPasswordReset();
87     void iconActivated(QSystemTrayIcon::ActivationReason reason);
88     void promptForgotPasswordChallenge();
89     void showWindowIfHidden();
90 
91     void cardUpdateError(QProcess::ProcessError err);
92     void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus);
93     void refreshShortcuts();
94     void cardDatabaseLoadingFailed();
95     void cardDatabaseNewSetsFound(int numUnknownSets, QStringList unknownSetsNames);
96     void cardDatabaseAllNewSetsEnabled();
97 
98     void actOpenCustomFolder();
99     void actOpenCustomsetsFolder();
100     void actAddCustomSet();
101 
102     void actManageSets();
103     void actEditTokens();
104 
105     void startupConfigCheck();
106     void alertForcedOracleRun(const QString &version, bool isUpdate);
107 
108 private:
109     static const QString appName;
110     static const QStringList fileNameFilters;
111     void setClientStatusTitle();
112     void retranslateUi();
113     void createActions();
114     void createMenus();
115 
116     void createTrayIcon();
117     void createTrayActions();
118     int getNextCustomSetPrefix(QDir dataDir);
getCardUpdaterBinaryName()119     inline QString getCardUpdaterBinaryName()
120     {
121         return "oracle";
122     };
123     void exitCardDatabaseUpdate();
124 
125     QList<QMenu *> tabMenus;
126     QMenu *cockatriceMenu, *dbMenu, *helpMenu, *trayIconMenu;
127     QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
128         *aAbout, *aTips, *aCheckCardUpdates, *aRegister, *aUpdate, *aViewLog, *closeAction;
129     QAction *aManageSets, *aEditTokens, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet;
130     TabSupervisor *tabSupervisor;
131     WndSets *wndSets;
132     RemoteClient *client;
133     QThread *clientThread;
134     LocalServer *localServer;
135     bool bHasActivated, askedForDbUpdater;
136     QMessageBox serverShutdownMessageBox;
137     QProcess *cardUpdateProcess;
138     DlgViewLog *logviewDialog;
139     DlgConnect *dlgConnect;
140     GameReplay *replay;
141     DlgTipOfTheDay *tip;
142     QUrl connectTo;
143 
144 public:
145     explicit MainWindow(QWidget *parent = nullptr);
setConnectTo(QString url)146     void setConnectTo(QString url)
147     {
148         connectTo = QUrl(QString("cockatrice://%1").arg(url));
149     }
150     ~MainWindow() override;
151 
152 protected:
153     void closeEvent(QCloseEvent *event) override;
154     void changeEvent(QEvent *event) override;
155     QString extractInvalidUsernameMessage(QString &in);
156 };
157 
158 #endif
159