summaryrefslogtreecommitdiffstats
path: root/wifi/kwireless/propertytable.cpp
blob: 7c73b1c25b20d172c6befefb6e53670115b28903 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
  $ Author: Mirko Boehm $
  $ License: This code is licensed under the LGPL $
  $ Copyright: (C) 1996-2003, Mirko Boehm $
  $ Contact: Mirko Boehm <[email protected]>
         http://www.kde.org
         http://www.hackerbuero.org $
*/

#include <tqtable.h>
#include <tqcombobox.h>
#include <tqtimer.h>
#include <tqptrlist.h>
#include <tqtextstream.h>
#include <kdialogbase.h>
#include <klocale.h>
#include "propertytable.h"
#include "kwirelesswidget.h"

extern "C" {
#include <math.h>
}

PropertyTable::PropertyTable(TQWidget *parent, const char* name)
    : PropertyTableBase(parent, name)
{
}

PropertyTable::~PropertyTable()
{
}

PropertiesDialog::PropertiesDialog(TQWidget *parent, const char *name)
    : KDialogBase(parent, name, true,
                  i18n("Wireless Network Device Properties"),
                  KDialogBase::Ok, KDialogBase::Ok, true),
      wait(false)
{
    table = new PropertyTable(this);
    setMainWidget(table);
    table->table->setLeftMargin(0);
    table->table->setSorting(false);
    table->table->setReadOnly(true);
    adjustSize();
    timer = new TQTimer(this);
    connect(timer, TQT_SIGNAL(timeout()), TQT_SLOT(timeout()));
    timer->start(3000, false);
    connect(table->cbDeviceSelector, TQT_SIGNAL(activated(int)),
            TQT_SLOT(selected(int)));
}

void PropertiesDialog::update(TQPtrList<DeviceInfo> *_info)
{
    int selection = table->cbDeviceSelector->currentItem();

    if(wait) return;

    info = _info;
    DeviceInfo *device;
    TQPtrListIterator<DeviceInfo> it(*info);

    table->cbDeviceSelector->clear();

    while((device = it.current()) != 0)
    {
        ++it;
        table->cbDeviceSelector->insertItem(device->device());
    }

    if(selection > 0 && selection < table->cbDeviceSelector->count())
    {
        selected(selection);
    } else {
        if(table->cbDeviceSelector->count() == 0)
        {
            selected(-1);
        } else {
            selected(0);
        }
    }

    table->cbDeviceSelector->setEnabled(info->count()>1);

    wait = true;
}

void PropertiesDialog::timeout()
{
    wait = false;
}

void PropertiesDialog::selected(int index)
{
    DeviceInfo temp;
    DeviceInfo *device;
    int count;

    if(index < 0)
    {
        device = &temp;
    } else {
        device = info->at(index);
    }

    TQString fields[] =
        {
            i18n("Device:"),
            i18n("ESSID (network name):"),
            i18n("Link quality:"),
            i18n("Signal strength:"),
            i18n("Noise level:"),
            i18n("Bit rate:"),
            i18n("Encryption:")
        };
    const int NoOfFields = sizeof(fields)/sizeof(fields[0]);

    TQString values[] =
        {
            device->device(),
            device->essid(),
            device->qualityString(),
            device->signalString(),
            device->noiseString(),
            device->bitrateString(),
            device->encrString()
        };
    const int NoOfValues = sizeof(values)/sizeof(values[0]);

    if(table->table->numRows() == 0)
    {
        table->table->insertRows(0, NoOfFields);
        // HACK (make more rows visible than the default):
        resize(size().width(), (int)(1.8*size().height()));
    }

    for(count = 0; count<NoOfFields; ++count)
    {
       table->table->setText(count, 0, fields[count]);
    }

    for(count = 0; count<NoOfValues; ++count)
    {
        table->table->setText(count, 1, values[count]);
    }

    table->table->adjustColumn(0);
    table->table->adjustColumn(1);

}

#include "propertytable.moc"