QTfrontend/netserverslist.cpp
author nemo
Tue, 20 Sep 2011 13:27:07 -0400
changeset 5972 add1cae1add6
parent 4976 088d40d8aba2
permissions -rw-r--r--
Clear gstAnimation and reset Timer before entering death animation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
632
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 883
diff changeset
     2
 * Hedgewars, a free turn based strategy game
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 3236
diff changeset
     3
 * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
632
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
     4
 *
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
     8
 *
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    13
 *
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    17
 */
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    18
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    19
#include <QUdpSocket>
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    20
#include <QListWidget>
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    21
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    22
#include "netserverslist.h"
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    23
665
5c7bfc8bac6a Start move from custom widgets to custom models
unc0rr
parents: 664
diff changeset
    24
HWNetServersModel::HWNetServersModel(QObject* parent) :
5c7bfc8bac6a Start move from custom widgets to custom models
unc0rr
parents: 664
diff changeset
    25
  QAbstractTableModel(parent)
632
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    26
{
664
f0af2401f981 Fully implement www server list via model
unc0rr
parents: 632
diff changeset
    27
632
5e09ae25729f Half implement possibility for different backends of servers list
unc0rr
parents:
diff changeset
    28
}
665
5c7bfc8bac6a Start move from custom widgets to custom models
unc0rr
parents: 664
diff changeset
    29
5c7bfc8bac6a Start move from custom widgets to custom models
unc0rr
parents: 664
diff changeset
    30
void HWNetServersModel::updateList()
5c7bfc8bac6a Start move from custom widgets to custom models
unc0rr
parents: 664
diff changeset
    31
{
5c7bfc8bac6a Start move from custom widgets to custom models
unc0rr
parents: 664
diff changeset
    32
5c7bfc8bac6a Start move from custom widgets to custom models
unc0rr
parents: 664
diff changeset
    33
}
668
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    34
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    35
QVariant HWNetServersModel::headerData(int section,
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    36
            Qt::Orientation orientation, int role) const
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    37
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    38
    if (role != Qt::DisplayRole)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    39
        return QVariant();
668
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    40
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    41
    if (orientation == Qt::Horizontal)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    42
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    43
        switch (section)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    44
        {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    45
            case 0: return tr("Title");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    46
            case 1: return tr("IP");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    47
            case 2: return tr("Port");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    48
            default: return QVariant();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    49
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    50
    } else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    51
        return QString("%1").arg(section + 1);
668
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    52
}
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    53
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    54
int HWNetServersModel::rowCount(const QModelIndex &parent) const
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    55
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    56
    if (parent.isValid())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    57
        return 0;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    58
    else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    59
        return games.size();
668
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    60
}
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    61
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    62
int HWNetServersModel::columnCount(const QModelIndex & parent) const
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    63
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    64
    if (parent.isValid())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    65
        return 0;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    66
    else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 1066
diff changeset
    67
        return 3;
668
0d7683a66d61 - Share much code between models
unc0rr
parents: 665
diff changeset
    68
}