2 #include <QtCore/QSettings>
3 #include "controlclass.h"
5 #include <QtCore/QDebug> //Debug pro informace
6 #include "timeprofile.h"
7 #include "calendatprofile.h"
8 #include "networkprofile.h"
9 #include "telephonenumprofile.h"
12 Set pointers to NULL and create new profile db
14 ControlClass::ControlClass(QWidget *parent) :
18 p_profile_db = new ProfileDB(this); //create new db
23 ControlClass::~ControlClass()
28 Used to initialize and connect slot and signals
29 \param setting reference to the setting class
31 void ControlClass::Init( QSettings *setting )
35 p_time_profile = new TimeProfile(this,setting); //create class for setting timed profile
36 connect(p_profile_db->GetProfileManager(),SIGNAL(s_profiles_name_change(QStringList)),p_time_profile,SLOT(ChangeInProfles(QStringList)));
37 p_calendar_profile = new CalendarProfile(this, settings);
38 connect(p_profile_db->GetProfileManager(),SIGNAL(s_profile_update(QString)),this,SLOT(ChangeInProfile(QString)));
39 connect(p_profile_db->GetProfileManager(),SIGNAL(s_profiles_name_change(QStringList)),p_calendar_profile,SLOT(setProfiles(QStringList)));
40 connect(p_time_profile,SIGNAL(s_set_timed_profile(QString)),this,SLOT(ChangeTimedProfile(QString)));
41 connect(p_calendar_profile,SIGNAL(s_calendar_profile(QString)),this,SLOT(ChangeCalendarProfile(QString)));
42 p_network_profile = new NetWorkProfile(this,setting);
43 connect(p_network_profile,SIGNAL(s_network_profile(QString)),this,SLOT(ChangeNetworkProfile(QString)));
44 connect(p_profile_db->GetProfileManager(),SIGNAL(s_profiles_name_change(QStringList)),p_network_profile,SLOT(SetProfilenames(QStringList)));
45 connect(p_profile_db->GetProfileManager(),SIGNAL(s_profile_delete(QString)),p_network_profile,SLOT(DeletedProfile(QString)));
46 p_telenum_profil = new TelephoneNumProfile(this);
47 connect(p_profile_db->GetProfileManager(),SIGNAL(s_profiles_name_change(QStringList)),p_telenum_profil,SLOT(SetProfilenames(QStringList)));
48 connect(p_telenum_profil,SIGNAL(s_telnum_profile(QString)),this,SLOT(ChangeTelNumProfile(QString)));
49 qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "create new db";
51 settings->beginGroup("ControlClass");
52 default_profile = settings->value("DefaultProfile", "general").toString(); //set default profile
55 //for signal when profile is changed (update profile)
57 p_profile_db->Init();//init db
59 p_calendar_profile->Init();
60 p_network_profile->createModels(p_profile_db->GetRulesManager()->GetCellIDModel(),p_profile_db->GetRulesManager()->GetWiFiModel());
61 p_telenum_profil->createModels(p_profile_db->GetRulesManager()->GetTelNumModel());
62 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Deafult Profile: " << default_profile;
65 /** ChangeTeNulProfile
66 Slot for signal from class for tel num profil to set
67 \param profile_name name of profile
69 void ControlClass::ChangeTelNumProfile(QString profile_name)
71 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Timer set";
72 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "name of timed profile:" << profile_name;
73 telnum_profile = profile_name;
74 //emit s_timed_profile_name(timer_profile); //signal for MainWindow
79 /** ChangeTimedProfile
80 Slot for signal from class for timed profil to set
81 \param profile_name name of profile
83 void ControlClass::ChangeTimedProfile(QString profile_name)
85 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Timer set";
86 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "name of timed profile:" << profile_name;
87 timer_profile = profile_name;
88 emit s_timed_profile_name(timer_profile); //signal for MainWindow
92 /** ChangeNetworkProfile
93 Slot for signal from class for network profil to set
95 void ControlClass::ChangeNetworkProfile(QString profile_name)
97 network_profile = profile_name;
98 emit s_network_profile_name(network_profile);
102 /** ChangeCalendarProfile
103 Slot for signal from class for caledar profil to set
104 \param profile_name name of profile
106 void ControlClass::ChangeCalendarProfile(QString profile_name)
108 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Calendar set";
109 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "name of calendar profile:" << profile_name;
110 calendar_profile = profile_name;
111 emit s_calendar_profile_name(calendar_profile);
116 /** SetDefaultProfile(QString profile).
117 Method for setting default profile
118 \param profile name of profile
120 void ControlClass::SetDefaultProfile(QString profile)
122 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "profil default: " << profile;
123 //not to set same profile
124 if(profile != default_profile){
126 settings->beginGroup("ControlClass");
127 settings->setValue("DefaultProfile", profile);
128 settings->endGroup();
129 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "default profile will be set: " << profile;
130 default_profile = profile;
138 void ControlClass::SetTelNum()
140 p_telenum_profil->ShowDialog();
147 void ControlClass::SetNetwork()
149 p_network_profile->ShowDialog();
155 void ControlClass::SetCalendar()
157 p_calendar_profile->ShowDialog();
161 Call time profile class to show dialog to set timed profile
163 void ControlClass::SetTimeProfile()
165 p_time_profile->SetTimer(p_profile_db->GetProfileManager()->GetProfilesNames());
170 This method will chosse profile from default_profile, timer_profile and calendar_profile
173 void ControlClass::ChooseProfile()
175 // QString textShow = tr("Current profile is: ");
176 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " timer profile empty " << timer_profile.isEmpty();
177 if(!telnum_profile.isEmpty()){
178 if(telnum_profile != actual_set_profile){
179 p_profile_db->GetProfileManager()->SetProfile(telnum_profile);
180 actual_set_profile = telnum_profile;
181 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "time profile waill be set now";
183 } else if(!timer_profile.isEmpty()){
184 if(timer_profile != actual_set_profile){
185 if(telnum_profile.isEmpty()){
186 emit s_profile_now(QObject::tr("Timer profile: ") + timer_profile);
188 p_profile_db->GetProfileManager()->SetProfile(timer_profile);
189 actual_set_profile = timer_profile;
190 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "time profile waill be set now";
192 }else if(!network_profile.isEmpty())
194 if(network_profile != actual_set_profile)
196 if(telnum_profile.isEmpty()){
197 emit s_profile_now(QObject::tr("Network profile: ") + network_profile);
199 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "network profile will be set";
200 p_profile_db->GetProfileManager()->SetProfile(network_profile);
201 actual_set_profile = network_profile;
204 else if(!calendar_profile.isEmpty())
206 if(calendar_profile != actual_set_profile) {
207 if(telnum_profile.isEmpty()){
208 emit s_profile_now(QObject::tr("Calendar profile: ") + calendar_profile);
210 p_profile_db->GetProfileManager()->SetProfile(calendar_profile);
211 actual_set_profile = calendar_profile;
215 if(default_profile != actual_set_profile) {
216 if(telnum_profile.isEmpty()){
217 emit s_profile_now(QObject::tr("Default profile: ") + default_profile);
219 ////qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "deafult profile will be set";
220 p_profile_db->GetProfileManager()->SetProfile(default_profile);
221 actual_set_profile = default_profile;
226 //====================================================================
229 Slot for change in profile
230 \param profile name of profile
232 void ControlClass::ChangeInProfile(QString profile)
234 if(actual_set_profile == profile ) p_profile_db->GetProfileManager()->SetProfile(profile);
237 Returns the object reference for the database
238 \returns pointer to ProfileDB
240 ProfileDB * ControlClass::GetProfileDB()
245 /** GetDefaultProfile()
246 Returns the name of default profile
247 \returns name of default profile
249 QString ControlClass::GetDefaultProfile()
251 return default_profile;
254 /** GetTimedProfile()
255 Returns the name of timed profile
256 \returns name of timed profile
258 QString ControlClass::GetTimedProfile()
260 return timer_profile;
263 /** GetCalendarProfile()
264 Returns the name of calendar profile
265 \returns name of calendar profile
267 QString ControlClass::GetCalendarProfile()
269 return calendar_profile;