fix
[irwi] / src / settingsdlg.cpp
1 #include "settingsdlg.h"
2 #include "advsettingsdlg.h"
3 #include "selectremotedlg.h"
4 #include "aboutdlg.h"
5 #include "remote.h"
6
7 #include <QHBoxLayout>
8 #include <QVBoxLayout>
9 #include <QWidget>
10 #include <QDialog>
11 #include <QPushButton>
12 #include <QLabel>
13 #include <QDebug>
14
15 SettingsDlg::SettingsDlg(QWidget *parent)
16     : QDialog(parent)
17     , remote(NULL)
18 {
19     layout = new QVBoxLayout(this);
20     btnLayout = new QHBoxLayout(this);
21     remoteNameLayout = new QHBoxLayout(this);
22     
23     advSettingsBtn = new QPushButton(tr("Advanced"), this);
24     selectRemoteBtn = new QPushButton(tr("Select remote"), this);
25     aboutBtn = new QPushButton(tr("About"), this);
26     rateUpBtn = new QPushButton(
27             QIcon(settings.value("rateUpIcon",
28                 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
29                 toString()),
30             "", this);
31     rateDownBtn = new QPushButton(
32             QIcon(settings.value("rateDownIcon",
33                 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
34                 toString()),
35             "", this);
36     rateUpBtn->setMaximumSize(72, 72);
37     rateDownBtn->setMaximumSize(72, 72);
38
39     btnLayout->addWidget(advSettingsBtn);
40     btnLayout->addWidget(selectRemoteBtn);
41     btnLayout->addWidget(aboutBtn);
42
43     remoteNameLabel = new QLabel(this);
44     ratingLabel = new QLabel(this);
45     remoteNameLayout->addWidget(remoteNameLabel);
46     remoteNameLayout->addWidget(ratingLabel);
47     remoteNameLayout->addWidget(rateUpBtn);
48     remoteNameLayout->addWidget(rateDownBtn);
49
50     connect(advSettingsBtn, SIGNAL(clicked()),
51             this, SLOT(showAdvSettingsDlg()));
52     connect(selectRemoteBtn, SIGNAL(clicked()),
53             this, SLOT(showSelectRemoteDlg()));
54     connect(aboutBtn, SIGNAL(clicked()),
55             this, SLOT(showAboutDlg()));
56     connect(rateUpBtn, SIGNAL(clicked()),
57             this, SLOT(rateUpClicked()));
58     connect(rateDownBtn, SIGNAL(clicked()),
59             this, SLOT(rateDownClicked()));
60  
61     layout->addLayout(remoteNameLayout);
62     layout->addLayout(btnLayout);
63     this->setLayout(layout);
64
65     changeRemote();
66 }
67
68 SettingsDlg::~SettingsDlg()
69 {
70     delete advSettingsBtn;
71     delete selectRemoteBtn;
72     delete rateUpBtn;
73     delete rateDownBtn;
74     delete aboutBtn;
75     delete remoteNameLabel;
76     delete ratingLabel;
77     delete btnLayout;
78     delete remoteNameLayout;
79     delete layout;
80     if (remote) {
81         delete remote;
82     }
83 }
84
85 void SettingsDlg::showAdvSettingsDlg()
86 {
87     AdvSettingsDlg dlg(this);
88     dlg.exec();
89 }
90
91 void SettingsDlg::showSelectRemoteDlg()
92 {
93     SelectRemoteDlg dlg(this);
94     changeRemote();
95     dlg.exec();
96 }
97
98 void SettingsDlg::showAboutDlg()
99 {
100     AboutDlg dlg(this);
101     dlg.exec();
102 }
103
104 void SettingsDlg::changeRemote()
105 {
106     QString selectedRemote = settings.value("remoteName", "").toString();
107     if (selectedRemote == "") {
108         remoteNameLabel->setText("No remote selected");
109         enableRateBtns(false);
110     } else {
111         if (remote) {
112             delete remote;
113         }
114         remote = new Remote(selectedRemote);
115         connect(remote, SIGNAL(infoUpdated()),
116                 this, SLOT(updateRemoteInfo()));
117         remote->updateInfo();
118         enableRateBtns();
119     }
120 }
121
122 void SettingsDlg::updateRemoteInfo()
123 {
124     remoteNameLabel->setText(remote->mfg() + " " + remote->name());
125     ratingLabel->setText(tr("Rating") + ": " + remote->rating());
126 }
127
128 void SettingsDlg::rateUpClicked()
129 {
130     remote->sendRating(Rating::Up);
131     enableRateBtns(false);
132 }
133
134 void SettingsDlg::rateDownClicked()
135 {
136     remote->sendRating(Rating::Down);
137     enableRateBtns(false);
138 }
139
140 void SettingsDlg::enableRateBtns(bool enable)
141 {
142     rateUpBtn->setEnabled(enable);
143     rateDownBtn->setEnabled(enable);
144 }
145
146