2 #include "mainwindow.h"
3 #include "ui_mainwindow.h"
4 #include "profildialog.h"
5 #include "controlclass.h"
8 #include <QtCore/QDebug> //Debug pro informace
9 #include <QtGui/QMessageBox>
10 #include <QtGui/QListWidgetItem>
11 #include <QtGui/QCloseEvent>
12 #include <QMaemo5ValueButton>
13 #include <QMaemo5ListPickSelector>
14 #include <QMaemo5InformationBox>
15 #include <QtCore/QStringList>
16 #include <QtGui/QStandardItemModel>
17 #include "timedprofildialog.h"
18 #include <QtDBus/QDBusInterface>
19 const char name[] = "N9Profile";
21 Setup ui and create new object for item model and maemo5
24 MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) :
25 QMainWindow(parent, flags),
26 ui(new Ui::MainWindow),
27 p_cnt_class(new ControlClass(this)),
28 p_set_Profile_button(NULL),
29 p_list_pick_profile(NULL),
30 p_model_profile_names(NULL),
31 p_Timed_Profile_button(NULL),
32 p_Calendar_Profile_button(NULL),
33 connectionInterface(new QDBusInterface("org.freedesktop.Notifications",
34 "/org/freedesktop/Notifications",
35 "org.freedesktop.Notifications",
36 QDBusConnection::systemBus(),this))
43 void MainWindow::sendNotif(QString name_of_profile)
46 qDebug() << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "profil pro zlutou";
47 if (!connectionInterface->isValid()) {
48 qWarning() << "Cannotct conect to D-BUS";
51 qDebug() << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "zobrazi ho ?";
52 connectionInterface->call(QLatin1String("SystemNoteInfoprint"),QVariant(name_of_profile));
55 ui->statusBar->showMessage(name_of_profile);
58 /** createMermoButtons()
59 Create maemo 5 buttons and model
61 void MainWindow::createMermoButtons()
63 p_model_profile_names = new QStandardItemModel(this);//model for maemo 5 button
65 p_set_Profile_button = new QMaemo5ValueButton(tr("Default profile"), this);
66 p_set_Profile_button->setValueLayout(QMaemo5ValueButton::ValueBesideText);
67 p_list_pick_profile = new QMaemo5ListPickSelector();
68 p_list_pick_profile->setModel(p_model_profile_names);
69 p_set_Profile_button->setPickSelector(p_list_pick_profile);
70 ui->verticalLayout_2->addWidget(p_set_Profile_button);
72 //connect signal when user select profil to slot
73 connect(p_list_pick_profile,SIGNAL(selected(QString)),this,SLOT(SetDeafaultProfile(QString)));
75 p_Timed_Profile_button = new QMaemo5ValueButton(tr("Timed profile"), this);
76 p_Timed_Profile_button->setValueLayout(QMaemo5ValueButton::ValueBesideText);
77 //when user click on Timed profile button
78 connect(p_Timed_Profile_button,SIGNAL(clicked()),this,SLOT(SetTimedProfile()));
81 p_Calendar_Profile_button = new QMaemo5ValueButton(tr("Calendar profiles"), this);
82 p_Calendar_Profile_button->setValueLayout(QMaemo5ValueButton::ValueBesideText);
83 connect(p_Calendar_Profile_button,SIGNAL(clicked()),this, SLOT(SetCalendarProfiles()));
84 ui->verticalLayout_2->addWidget(p_Calendar_Profile_button);
87 p_IDWifi_Profile_button = new QMaemo5ValueButton(tr("Network profile"), this);
88 p_IDWifi_Profile_button->setValueLayout(QMaemo5ValueButton::ValueBesideText);
89 connect(p_IDWifi_Profile_button,SIGNAL(clicked()),this, SLOT(SetNetworkProfile()));
90 ui->verticalLayout_2->addWidget(p_IDWifi_Profile_button);
92 ui->verticalLayout_2->addWidget(p_Timed_Profile_button);
96 Delete the UI and the control class
98 MainWindow::~MainWindow()
105 Used to create and initialize the control class.
107 void MainWindow::Init()
110 //connec signal when user sets timed profile or when timed profile ends
111 connect(this,SIGNAL(s_hide_show()),p_cnt_class,SLOT(ShowHide()));
112 connect(p_cnt_class,SIGNAL(s_timed_profile_name(QString)),this,SLOT(SetTimedProfilename(QString)));
113 connect(p_cnt_class,SIGNAL(s_calendar_profile_name(QString)),this,SLOT(SetCalendarProfilename(QString)));
114 connect(p_cnt_class,SIGNAL(s_network_profile_name(QString)),this,SLOT(SetMetworkProfilename(QString)));
115 connect(p_cnt_class,SIGNAL(s_profile_now(QString)),this,SLOT(sendNotif(QString)));
117 connect(this,SIGNAL(s_aboutToEnd()),p_cnt_class->GetProfileDB(),SLOT(SaveProfilesToXml())); //save xml berofe end
118 //signal when profiles are changed (add profile, delete profile)
119 connect(p_cnt_class->GetProfileDB()->GetProfileManager(),SIGNAL(s_profiles_name_change(QStringList)),this,SLOT(changeInProfiles(QStringList)));
120 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "init controll class";
121 p_cnt_class->Init(&settings);
123 // changeInProfiles(p_cnt_class->GetProfileDB()->GetProfilesNames());//get profiles names and sets them
126 /** changeInProfiles();.
127 Slot for signal when new profile is created or deleted
128 \param Profiles_Names list of profile names
130 void MainWindow::changeInProfiles(QStringList Profiles_Names)
132 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "set profile names to listwidgetview ";
133 ui->listWidgetProfiles->clear();//clear view
134 ui->listWidgetProfiles->addItems(Profiles_Names);//set names
136 p_model_profile_names->clear();//clear model for maemo buttons
138 for (int i = 0; i < Profiles_Names.size(); ++i){ //add
139 p_model_profile_names->appendRow(new QStandardItem(Profiles_Names.at(i)));
140 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "pridavam ted: " << Profiles_Names.at(i);
142 setNewIndexDeafaultProfile();
146 /** setNewIndexDeafaultProfile();.
147 Method for setting index in list pick
149 void MainWindow::setNewIndexDeafaultProfile()
151 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "select index";
152 QList<QStandardItem *> list_of_items;
153 //get defult name,MatchExactly and find in model
154 list_of_items = p_model_profile_names->findItems(p_cnt_class->GetDefaultProfile(), Qt::MatchExactly, 0);//find in 1.
155 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "size of list is: " << list_of_items.count();
156 if(!list_of_items.empty()){
157 //set list pick index
158 p_list_pick_profile->setCurrentIndex(list_of_items.at(0)->row());
159 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "item in list pick selected:" ;
163 /** on_listWidgetProfiles_itemClicked
164 Slot for signal when user click on item in QListWidget
165 and show dialog to update profile
166 \param item item in list widget
168 void MainWindow::on_listWidgetProfiles_itemClicked(QListWidgetItem* item)
171 ProfileDB* db = p_cnt_class->GetProfileDB();// get profile DB;
173 msgBox.setIcon(QMessageBox::Information);
174 msgBox.setText(tr("Delete or modify profile?"));
175 msgBox.setEscapeButton(QMessageBox::Cancel);
176 QPushButton *CancelButton = msgBox.addButton(QMessageBox::Cancel);
177 QPushButton *DeleteButton = msgBox.addButton(tr("Delete"), QMessageBox::ActionRole);
178 QPushButton *modifyButton = msgBox.addButton(tr("Modify"),QMessageBox::DestructiveRole);
182 if (msgBox.clickedButton() == DeleteButton) {
183 if(item->text() == p_list_pick_profile->currentValueText()){
184 QMaemo5InformationBox::information(this, tr("You cannot delete deafult profile"), QMaemo5InformationBox::DefaultTimeout);
186 //qDebug() << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "bude se namaaz";
187 db->GetProfileManager()->DeleteProfile(item->text());
189 } else if (msgBox.clickedButton() == modifyButton) {
190 profil = new Profil(item->text()); //create profil and sets name
192 if(!db->GetProfileManager()->GetProfile(profil))//
197 ProfilDialog dialog(db->GetProfileManager()->GetProfilesNames(),this, profil,db->GetSoundFilesManager()->GetModel()); //
199 int result = dialog.exec();
203 //qDebug() << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "OK update profile";
205 db->GetProfileManager()->UpdateProfile(profil);
208 }else if (msgBox.clickedButton() == CancelButton) {
213 /** on_ButtonNewProfile_clicked();.
214 Serves as a slot for the button to create a new profile.
215 Creates a new profile and forward links.
217 void MainWindow::on_ButtonNewProfile_clicked()
219 ProfileDB* db = p_cnt_class->GetProfileDB();
220 Profil * profil = new Profil("");//new profiel
221 ProfilDialog dialog(db->GetProfileManager()->GetProfilesNames(),this, profil,db->GetSoundFilesManager()->GetModel()); //dostane profil, jmena profilu a model
223 int result = dialog.exec();
227 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "save profile";
228 db->GetProfileManager()->CreateProfile(profil);
234 Slot for signal when user click on button for timed profile
236 void MainWindow::SetTimedProfile()
238 p_cnt_class->SetTimeProfile();
241 /** SetTimedProfilename
242 Slot for signal when set profile
243 \param profile_name name of profile
245 void MainWindow::SetTimedProfilename(QString profile_name)
247 p_Timed_Profile_button->setValueText(profile_name);
250 /** SetCalendarProfiles
251 Slot for signal when user click on button for calendar profile
253 void MainWindow::SetCalendarProfiles()
255 p_cnt_class->SetCalendar();
258 /** SetNetworkProfile
259 Slot for signal when user click on button for network profile
261 void MainWindow::SetNetworkProfile()
263 p_cnt_class->SetNetwork();
264 //=======================================
267 /** SetCalendarProfilename
268 Slot for signal when calendar object select profile
269 \param profile_name name of profile
271 void MainWindow::SetCalendarProfilename(QString profile_name)
273 p_Calendar_Profile_button->setValueText(profile_name);
276 /** SetDeafaultProfile(QString profile_name)
277 Slot for signal when user choose profile name from QMaemoButton
278 \param profile_name name of profile
280 void MainWindow::SetDeafaultProfile(QString profile_name)
282 p_cnt_class->SetDefaultProfile(profile_name);
285 /** SetMetworkProfilename(QString profile_name)
286 Slot for signal when network object select profile
287 \param profile_name name of profile
289 void MainWindow::SetMetworkProfilename(QString profile_name )
291 p_IDWifi_Profile_button->setValueText(profile_name);
294 //======================================================================================
295 /** closeEvent(QCloseEvent *event)
296 Slot for close event.
297 It will call method maybeQuit()
299 void MainWindow::closeEvent(QCloseEvent *event)
306 void MainWindow::on_actionExit_triggered()
310 QCoreApplication::quit();
317 Method for show QMessageBox before
318 It will ask user if he want to quit.
320 bool MainWindow::maybeQuit()
322 QMessageBox::StandardButton ret;
323 ret = QMessageBox::warning(this, tr("Application"),
324 tr("Program will end.\n"
325 "Do you want to quit?"),
326 QMessageBox::Ok | QMessageBox::Cancel);
328 case QMessageBox::Ok:
331 case QMessageBox::Cancel:
340 int MainWindow::top_application()
347 //================================================================================
348 /** \brief changeEvent
353 void MainWindow::changeEvent(QEvent *e)
355 QMainWindow::changeEvent(e);
357 case QEvent::LanguageChange:
358 ui->retranslateUi(this);
365 /** \brief on_actionAboutQT_triggered
370 void MainWindow::on_actionAboutQT_triggered()
372 QMessageBox::aboutQt(this);
375 /** \brief on_actionAbout_triggered
380 void MainWindow::on_actionAbout_triggered()
382 QString str = QString("");
383 str.append(tr("This program can create mobile profiles and set them. "));
384 str.append(tr("Program will change only general profil in N900. "));
385 str.append(tr("When you first start N9Profil it will create two profile from N900, general a silent. "));
386 str.append(tr("You can set default profile, timed profile for "));
387 str.append(tr("period of time or you can set profiles based on desctriptions "));
388 str.append(tr("in events in calendar. "));
389 str.append(tr("Timed profile have bigger priority, then calendar and calendar then default profile. "));
390 QMessageBox::about(this,tr("About N9Profil"), str);
393 void MainWindow::on_pushButtonPhonenum_clicked()
395 p_cnt_class->SetTelNum();