Changed search to retry automatically couple of times before failing.
[jenirok] / src / gui / connectionselector.cpp
1 /*
2  * This file is part of Jenirok.
3  *
4  * Jenirok is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Jenirok is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Jenirok.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #include <QtCore/QList>
20 #include <QtCore/QVariant>
21 #include <QtCore/QDebug>
22 #include "connectionselector.h"
23 #include "connectionmanager.h"
24
25 ConnectionSelector::ConnectionSelector(QString const& text, QWidget* parent):
26 ButtonSelector(text, parent), loaded_(false), gprsIndex_(0)
27 {
28     addItems();
29 }
30
31 void ConnectionSelector::updateConnections()
32 {
33     loaded_ = true;
34
35     QVariant currentValue = value();
36
37     addItems();
38
39     ConnectionManager cm;
40
41     QList<ConnectionManager::Connection> connections;
42
43     if(cm.scanConnections(connections, ConnectionManager::GPRS) &&
44        connections.size() > 0)
45     {
46         changeItem(gprsIndex_, connections.at(0).name, "gprs");
47     }
48     else
49     {
50         qDebug() << "Unable to scan network connections";
51     }
52
53     selectByValue(currentValue);
54
55 }
56
57 void ConnectionSelector::setVisible(bool visible)
58 {
59     if(visible && !loaded_)
60     {
61         updateConnections();
62     }
63
64     ButtonSelector::setVisible(visible);
65 }
66
67 void ConnectionSelector::addItems()
68 {
69     clear();
70
71     addItem(tr("Use global setting"), "global");
72     addItem(tr("WLAN connection"), "wlan");
73     addItem(tr("GPRS connection"), "gprs");
74     addItem(tr("Any connection"), "any");
75
76     gprsIndex_ = 2;
77 }