Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / network / GUIDialogAccessPoints.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIDialogAccessPoints.h"
22 #include "guilib/GUIKeyboardFactory.h"
23 #ifdef TARGET_POSIX
24 #include "linux/NetworkLinux.h"
25 #endif
26 #include "Application.h"
27 #include "FileItem.h"
28 #include "guilib/Key.h"
29 #include "guilib/LocalizeStrings.h"
30
31 #define CONTROL_ACCESS_POINTS 3
32
33 CGUIDialogAccessPoints::CGUIDialogAccessPoints(void)
34     : CGUIDialog(WINDOW_DIALOG_ACCESS_POINTS, "DialogAccessPoints.xml")
35 {
36   m_accessPoints = new CFileItemList;
37 }
38
39 CGUIDialogAccessPoints::~CGUIDialogAccessPoints(void)
40 {
41   delete m_accessPoints;
42 }
43
44 bool CGUIDialogAccessPoints::OnAction(const CAction &action)
45 {
46   if (action.GetID() == ACTION_SELECT_ITEM)
47   {
48     CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_ACCESS_POINTS);
49     OnMessage(msg);
50     int iItem = msg.GetParam1();
51
52     if (iItem == (int) m_aps.size())
53     {
54        m_selectedAPEssId = "";
55        if (CGUIKeyboardFactory::ShowAndGetInput(m_selectedAPEssId, g_localizeStrings.Get(789), false))
56        {
57          m_selectedAPEncMode = m_aps[iItem].getEncryptionMode();
58          m_wasItemSelected = true;
59          Close();
60          return true;
61        }
62     }
63     else
64     {
65        m_selectedAPEssId = m_aps[iItem].getEssId();
66        m_selectedAPEncMode = m_aps[iItem].getEncryptionMode();
67        m_wasItemSelected = true;
68        Close();
69        return true;
70     }
71   }
72
73   return CGUIDialog::OnAction(action);
74 }
75
76 void CGUIDialogAccessPoints::OnInitWindow()
77 {
78   m_wasItemSelected = false;
79
80   CGUIDialog::OnInitWindow();
81
82   CGUIMessage msgReset(GUI_MSG_LABEL_RESET, GetID(), CONTROL_ACCESS_POINTS);
83   OnMessage(msgReset);
84
85   m_accessPoints->Clear();
86
87   CStdString ifaceName(m_interfaceName);
88   CNetworkInterface* iface = g_application.getNetwork().GetInterfaceByName(ifaceName);
89   m_aps = iface->GetAccessPoints();
90
91   for (int i = 0; i < (int) m_aps.size(); i++)
92   {
93       CFileItemPtr item(new CFileItem(m_aps[i].getEssId()));
94
95       int q = m_aps[i].getQuality();
96       if (q <= 20) item->SetArt("thumb", "ap-signal1.png");
97       else if (q <= 40) item->SetArt("thumb", "ap-signal2.png");
98       else if (q <= 60) item->SetArt("thumb", "ap-signal3.png");
99       else if (q <= 80) item->SetArt("thumb", "ap-signal4.png");
100       else if (q <= 100) item->SetArt("thumb", "ap-signal5.png");
101
102       if (m_aps[i].getEncryptionMode() != ENC_NONE)
103          item->SetIconImage("ap-lock.png");
104
105       m_accessPoints->Add(item);
106   }
107
108   CFileItemPtr item(new CFileItem(g_localizeStrings.Get(1047)));
109   m_accessPoints->Add(item);
110
111   CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_ACCESS_POINTS, 0, 0, m_accessPoints);
112   OnMessage(msg);
113 }
114
115 void CGUIDialogAccessPoints::SetInterfaceName(CStdString interfaceName)
116 {
117   m_interfaceName = interfaceName;
118 }
119
120 CStdString CGUIDialogAccessPoints::GetSelectedAccessPointEssId()
121 {
122   return m_selectedAPEssId;
123 }
124
125 EncMode CGUIDialogAccessPoints::GetSelectedAccessPointEncMode()
126 {
127   return m_selectedAPEncMode;
128 }
129
130 bool CGUIDialogAccessPoints::WasItemSelected()
131 {
132   return m_wasItemSelected;
133 }