1 #include "networkprofile.h"
2 #include <QtCore/QStringList>
3 #include <QtCore/QSettings>
4 #include <QtCore/QDebug> //Debug pro informace
5 #include <QtGui/QStandardItemModel>
6 #include <QtGui/QItemSelectionModel>
7 #include <QtCore/QTimer>
8 #include "networkdialogdialog.h"
10 using namespace QtMobility;
12 Get setting pointer and create network class.
13 Connect all signal from networkclass to slot
14 and gets name of network
16 NetWorkProfile::NetWorkProfile(QWidget *parent, QSettings *sett) :
20 p_networkcl = new QSystemNetworkInfo(this);
21 timer = new QTimer(this);
22 connect(timer,SIGNAL(timeout()),this,SLOT(ChangeInCellLocation()));
23 timer->start(10000);//each 10 seconds shot
24 connect(p_networkcl,SIGNAL(networkNameChanged(QSystemNetworkInfo::NetworkMode,QString)),this,SLOT(ChangeInWifiName(QSystemNetworkInfo::NetworkMode, QString )));
25 qDebug()<< "ziskam id============================";
26 CellLocation = QString::number(p_networkcl->locationAreaCode());
27 qDebug()<< "==================" << CellLocation;
28 WifiName = p_networkcl->networkName(QSystemNetworkInfo::WlanMode);
29 qDebug()<< "==================" << WifiName;
30 model_of_CellId = NULL;
31 model_of_WifiIf = NULL;
37 \param list_of_profiles_nf names of profiles
39 void NetWorkProfile::SetProfilenames(QStringList list_of_profiles_nf)
41 list_of_profiles = list_of_profiles_nf;
45 Slot for name of deleted profile
46 \param list_of_profiles_nf names of profiles
48 void NetWorkProfile::DeletedProfile(QString name)
50 if(name == profile_Currently)
55 gets model and create selection models
57 void NetWorkProfile::createModels(QStandardItemModel * cellM, QStandardItemModel * wifiM)
59 if((cellM == NULL) || (wifiM == NULL)){
60 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "jeden je null" ;
62 model_of_CellId = cellM;
63 selModel_CellId = new QItemSelectionModel(model_of_CellId);
64 model_of_WifiIf = wifiM;
65 selModel_WifiIf = new QItemSelectionModel(model_of_WifiIf);
66 SetProfile();;//set profile
70 /** ChangeInCellLocation.
71 Slot for change in location
72 \param list_of_profiles_nf names of profiles
74 void NetWorkProfile::ChangeInCellLocation()
76 CellLocation = QString::number(p_networkcl->locationAreaCode());
77 WifiName = p_networkcl->networkName(QSystemNetworkInfo::WlanMode);
78 qDebug()<< "=====změna v id lov" << CellLocation;
83 Slot for change in wifi name
84 \param list_of_profiles_nf names of profiles
86 void NetWorkProfile::ChangeInWifiName(QSystemNetworkInfo::NetworkMode mode, QString name )
88 qDebug()<< "změna ve jménu" << name;
90 if(mode == QSystemNetworkInfo::WlanMode)
92 qDebug()<< "změna ve jménu wifi" << name;
99 Set profile based of name of wifi or location id
100 Find rule in tables and set profile
102 void NetWorkProfile::SetProfile()
104 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "kontrola zda jsou profily null";
105 if((model_of_CellId == NULL) || (model_of_WifiIf == NULL)) return;
106 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "bude se ted nastavovoat nový profil";
107 profile_Currently = QString("");
108 QString str = QString("");
110 if(!WifiName.isEmpty())
113 str = FindWifiNameInModel(WifiName);
114 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "nalezlo to profil pro wifi sit? " << str;
117 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "";
118 str = FindIDLocInModel(CellLocation);
119 profile_Currently = str;
120 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "profil na ic loc " << profile_Currently;
121 emit s_network_profile(profile_Currently);
124 profile_Currently = str;
125 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "profil na wifi name " << profile_Currently;
126 emit s_network_profile(profile_Currently);
131 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "wifi neni " ;
132 str = FindIDLocInModel(CellLocation);
133 profile_Currently = str;
134 emit s_network_profile(profile_Currently);
137 emit s_network_profile(profile_Currently);
140 /** FindIDLocInModel.
141 Find id location and return name of profile
142 \param IDCell location id
144 QString NetWorkProfile::FindIDLocInModel(QString IDCell)
146 QString name = QString("");
147 QList<QStandardItem *> list_of_idcell;
149 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Bude hledat modelu wifi site " ;
151 //labels << tr("Name") << tr("Wifi name") << tr("Profile");
152 list_of_idcell = model_of_CellId->findItems(IDCell, Qt::MatchExactly , 1);
154 if(list_of_idcell.empty())
156 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "nic nanasel " ;
160 name = model_of_CellId->item(list_of_idcell.at(0)->row(),2)->data(Qt::DisplayRole).toString();
161 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "nasel ho " << name;
166 /** FindWifiNameInModel.
167 Find profile in table based in wifiname
168 \param WifiNam name of wifi
170 QString NetWorkProfile::FindWifiNameInModel(QString WifiNam)
172 QString name = QString("");
173 QList<QStandardItem *> list_of_wifiname;
175 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "Bude hledat modelu wifi site " ;
176 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "pocet radku v modelu wifi " << model_of_WifiIf->rowCount();
177 //labels << tr("Name") << tr("Wifi name") << tr("Profile");
178 list_of_wifiname = model_of_WifiIf->findItems(WifiNam, Qt::MatchExactly , 1); //fing wifi name in 1 colum
179 if(list_of_wifiname.empty())
184 name = model_of_WifiIf->item(list_of_wifiname.at(0)->row(),2)->data(Qt::DisplayRole).toString();
185 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "nasel ho " << name;
190 //===========================================================================
192 For dialog for modifi calendars and profiles
194 void NetWorkProfile::ShowDialog()
196 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "dialog " ;
197 NetWorkdialogDialog dialog(this, settings);
198 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "ma setings " ;
199 dialog.SetViews(model_of_CellId,selModel_CellId,model_of_WifiIf,selModel_WifiIf);
200 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "modely " ;
201 dialog.SetIDWIFInames(CellLocation, WifiName);
202 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "lokaci a wifi " ;
203 dialog.SetProfilenames(list_of_profiles);
204 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "prily " ;
205 connect(&dialog,SIGNAL(s_change_model()),this,SLOT(ChangeInModel()));
207 //qDebug()<< "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "konec " ;
208 disconnect(&dialog,SIGNAL(s_change_model()),this,SLOT(ChangeInModel()));
212 Slot for change in model table
214 void NetWorkProfile::ChangeInModel()