GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/socialtab.h Lines: 25 38 65.8 %
Date: 2021-03-17 Branches: 9 30 30.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2010  The Mana Developers
4
 *  Copyright (C) 2011-2019  The ManaPlus Developers
5
 *  Copyright (C) 2019-2021  Andrei Karas
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef GUI_WIDGETS_TABS_SOCIALTAB_H
24
#define GUI_WIDGETS_TABS_SOCIALTAB_H
25
26
#include "gui/windows/socialwindow.h"
27
28
#include "gui/windows/confirmdialog.h"
29
#include "gui/windows/textdialog.h"
30
31
#include "gui/widgets/avatarlistbox.h"
32
#include "gui/widgets/createwidget.h"
33
#include "gui/widgets/scrollarea.h"
34
35
#include "gui/widgets/tabs/tab.h"
36
37
#include "localconsts.h"
38
39
class AvatarListModel;
40
41
class SocialTab notfinal : public Tab
42
{
43
    public:
44
        A_DELETE_COPY(SocialTab)
45
46
        virtual void invite()
47
        {
48
        }
49
50
        virtual void leave()
51
        {
52
        }
53
54
        virtual void updateList()
55
        {
56
        }
57
58
        virtual void updateAvatar(const std::string &name A_UNUSED)
59
        {
60
        }
61
62
        virtual void resetDamage(const std::string &name A_UNUSED)
63
        {
64
        }
65
66
        virtual void selectIndex(const unsigned num A_UNUSED)
67
        {
68
        }
69
70
        virtual void buildCounter(const int online A_UNUSED,
71
                                  const int total A_UNUSED)
72
        {
73
        }
74
75
    protected:
76
        friend class SocialWindow;
77
78
5
        explicit SocialTab(const Widget2 *const widget) :
79
            Tab(widget),
80
            mInviteDialog(nullptr),
81
            mConfirmDialog(nullptr),
82
            mScroll(nullptr),
83
            mList(nullptr),
84
            mCounterString(),
85
20
            mMenuAction("menu")
86
        {
87
5
        }
88
89
5
        ~SocialTab() override
90
20
        {
91
            // Cleanup dialogs
92
5
            if (mInviteDialog != nullptr)
93
            {
94
                mInviteDialog->close();
95
                mInviteDialog->scheduleDelete();
96
                mInviteDialog = nullptr;
97
            }
98
99
5
            if (mConfirmDialog != nullptr)
100
            {
101
                mConfirmDialog->close();
102
                mConfirmDialog->scheduleDelete();
103
                mConfirmDialog = nullptr;
104
            }
105
5
        }
106
107
5
        void createControls(AvatarListModel *const listModel,
108
                            const Opaque showBackground)
109
        {
110
5
            CREATEWIDGETV(mList, AvatarListBox, this, listModel);
111
10
            mScroll = new ScrollArea(this, mList, showBackground,
112

25
                "social_background.xml");
113
114
5
            mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO);
115
5
            mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
116
5
        }
117
118
1
        void setCurrent() override final
119
        {
120
1
            updateCounter();
121
1
            updateMenu();
122
1
        }
123
124
        void updateCounter() const
125
        {
126



2
            if (socialWindow != nullptr)
127
1
                socialWindow->updateCounter(this, mCounterString);
128
        }
129
130
1
        void updateMenu() const
131
        {
132
1
            if (socialWindow != nullptr)
133
1
                socialWindow->updateMenu(this, mMenuAction);
134
1
        }
135
136
        TextDialog *mInviteDialog;
137
        ConfirmDialog *mConfirmDialog;
138
        ScrollArea *mScroll;
139
        AvatarListBox *mList;
140
        std::string mCounterString;
141
        std::string mMenuAction;
142
};
143
144
#endif  // GUI_WIDGETS_TABS_SOCIALTAB_H