README
[n9profile] / networkdialogedit.cpp
1 #include "networkdialogedit.h"
2 #include "ui_networkdialogedit.h"
3 #include <QtCore/QStringList>
4 #include <QtCore/QDebug> //Debug pro informace
5 #include <QtGui/QItemSelectionModel>
6 #include <QtGui/QStandardItemModel>
7 #include <QMaemo5InformationBox>
8 #include <QMaemo5ValueButton>
9 #include <QMaemo5ListPickSelector>
10 #include <QMaemo5InformationBox>
11 #include <QtGui/QMessageBox>
12
13 /** Constructor.
14   set title for dialog
15 */
16 NetWorkDialogEdit::NetWorkDialogEdit(QWidget *parent) :
17         QDialog(parent),
18         ui(new Ui::NetWorkDialogEdit)
19 {
20     ui->setupUi(this);
21     setWindowTitle(tr("Set profile forNetwork"));
22     selectedProfile = QString("");
23 }
24
25 /** Destructor.
26 */
27 NetWorkDialogEdit::~NetWorkDialogEdit()
28 {
29     delete ui;
30 }
31
32 void NetWorkDialogEdit::changeEvent(QEvent *e)
33 {
34     QDialog::changeEvent(e);
35     switch (e->type()) {
36     case QEvent::LanguageChange:
37         ui->retranslateUi(this);
38         break;
39     default:
40         break;
41     }
42 }
43
44 /** SetProfilenames.
45   Store profile names and create maemo button for show this names
46   \param list_of_profiles_nf list of profile names
47 */
48 void  NetWorkDialogEdit::SetProfilenames(QStringList list_of_profiles_nf)
49 {
50     list_of_profiles = list_of_profiles_nf;
51
52     p_model_profile_names = new QStandardItemModel(this);//model for maemo 5 button
53
54     foreach(QString profile, list_of_profiles )
55     {
56         p_model_profile_names->appendRow(new QStandardItem(profile));
57     }
58
59     p_set_Profile_button = new QMaemo5ValueButton(tr("Choose profile for Network:"), this);
60     p_set_Profile_button->setValueLayout(QMaemo5ValueButton::ValueBesideText);
61     p_list_pick_profile = new QMaemo5ListPickSelector();
62     p_list_pick_profile->setModel(p_model_profile_names);
63     p_set_Profile_button->setPickSelector(p_list_pick_profile);
64     ui->verticalLayout->addWidget(p_set_Profile_button);
65     connect(p_list_pick_profile,SIGNAL(selected(QString)),this,SLOT(SelectedName(QString)));
66 }
67
68 /** SelectedName.
69   Slot for change in list pick
70   \param name name of profile
71 */
72 void NetWorkDialogEdit::SelectedName(QString name)
73 {
74     selectedProfile = name;
75 }
76
77 /** SetNameOfLabel.
78 Set text for label
79   \param id name of network
80   \param name text for label
81 */
82 void  NetWorkDialogEdit::SetNameOfLabel(QString id, QString name )
83 {
84     ui->label->setText(name + id);
85 }
86
87 /** GetNameProfile.
88 Return name of selected profile
89
90 */
91 QString NetWorkDialogEdit::GetNameProfile()
92 {
93     return selectedProfile;
94 }
95
96 /** GetNameOfRule.
97 Return nameo of rule
98 */
99 QString NetWorkDialogEdit::GetNameOfRule()
100 {
101     return ui->lineEditNameOfrule->text();
102 }
103
104 /** SetNameOfLabel.
105 set namo of rule
106   \param name text for label
107 */
108 void NetWorkDialogEdit::SetNameOfRule(QString name)
109 {
110     ui->lineEditNameOfrule->setText(name);
111 }
112
113 /** accept()
114 Slot for signal when user click on save button.
115 Check is everyting is OK
116 */
117 void NetWorkDialogEdit::accept()
118 {
119     if(selectedProfile.isEmpty())
120     {
121         QMaemo5InformationBox::information(this, tr("Select profile for network"), QMaemo5InformationBox::DefaultTimeout);
122         return;
123     }
124
125     if(ui->lineEditNameOfrule->text().isEmpty())
126     {
127         QMaemo5InformationBox::information(this, tr("Please fill name"), QMaemo5InformationBox::DefaultTimeout);
128         return;
129     }
130
131     done(QDialog::Accepted);
132 }