GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/socialtab.h Lines: 25 38 65.8 %
Date: 2017-11-29 Branches: 10 32 31.3 %

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

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



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