Error fixes
[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     QString selectedRemote = settings.value("remoteName", "").toString();
62     if (selectedRemote == "")
63     {
64         remoteNameLabel->setText(tr("No remote selected"));
65         enableRateBtns(false);
66     }
67     else
68     {
69         changeRemote();
70     }
71
72     layout->addLayout(remoteNameLayout);
73     layout->addLayout(btnLayout);
74     this->setLayout(layout);
75 }
76
77 SettingsDlg::~SettingsDlg()
78 {
79     delete layout;
80     delete btnLayout;
81     delete remoteNameLayout;
82     delete advSettingsBtn;
83     delete selectRemoteBtn;
84     delete rateUpBtn;
85     delete rateDownBtn;
86     delete aboutBtn;
87     delete remoteNameLabel;
88     delete ratingLabel;
89     if (remote)
90     {
91         delete remote;
92     }
93 }
94
95 void SettingsDlg::showAdvSettingsDlg()
96 {
97     AdvSettingsDlg dlg(this);
98     dlg.exec();
99 }
100
101 void SettingsDlg::showSelectRemoteDlg()
102 {
103     SelectRemoteDlg dlg(this);
104     changeRemote();
105     dlg.exec();
106 }
107
108 void SettingsDlg::showAboutDlg()
109 {
110     AboutDlg dlg(this);
111     dlg.exec();
112 }
113
114 void SettingsDlg::changeRemote()
115 {
116     if (remote)
117     {
118         delete remote;
119     }
120     remote = new Remote(settings.value("remoteName", "").toString());
121     connect(remote, SIGNAL(infoUpdated()),
122             this, SLOT(updateRemoteInfo()));
123     remote->updateInfo();
124     enableRateBtns();
125 }
126
127 void SettingsDlg::updateRemoteInfo()
128 {
129     remoteNameLabel->setText(remote->mfg() + " " + remote->name());
130     ratingLabel->setText(tr("Rating") + ": " + remote->rating());
131 }
132
133 void SettingsDlg::rateUpClicked()
134 {
135     remote->sendRating(Rating::Up);
136     enableRateBtns(false);
137 }
138
139 void SettingsDlg::rateDownClicked()
140 {
141     remote->sendRating(Rating::Down);
142     enableRateBtns(false);
143 }
144
145 void SettingsDlg::enableRateBtns(bool enable)
146 {
147     rateUpBtn->setEnabled(enable);
148     rateDownBtn->setEnabled(enable);
149 }
150
151