Complete rewrite. Does not work yet.
[irwi] / src / settingsdlg.cpp
1 #include "settingsdlg.h"
2 #include "advsettingsdlg.h"
3 #include "selectremotedlg.h"
4 #include "aboutdlg.h"
5 #include "iengine.h"
6 #include "iremote.h"
7
8 #include <QHBoxLayout>
9 #include <QVBoxLayout>
10 #include <QWidget>
11 #include <QDialog>
12 #include <QPushButton>
13 #include <QSettings>
14 #include <QLabel>
15 #include <QDebug>
16
17 SettingsDlg::SettingsDlg(QWidget *parent, IEngine *engine)
18     : QDialog(parent)
19     , engine(engine)
20 {
21     layout = new QVBoxLayout(this);
22     btnLayout = new QHBoxLayout(this);
23     remoteNameLayout = new QHBoxLayout(this);
24     
25     QSettings settings(this);
26     advSettingsBtn = new QPushButton(tr("Advanced"), this);
27     selectRemoteBtn = new QPushButton(tr("Select remote"), this);
28     aboutBtn = new QPushButton(tr("About"), this);
29
30     rateUpBtn = new QPushButton(
31             QIcon(settings.value("rateUpIcon",
32             "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
33                 toString()),
34             "", this);
35     rateDownBtn = new QPushButton(
36             QIcon(settings.value("rateDownIcon",
37             "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
38                 toString()),
39             "", this);
40     rateUpBtn->setMaximumSize(72, 72);
41     rateDownBtn->setMaximumSize(72, 72);
42
43     btnLayout->addWidget(advSettingsBtn);
44     btnLayout->addWidget(selectRemoteBtn);
45     btnLayout->addWidget(aboutBtn);
46
47     connect(advSettingsBtn, SIGNAL(clicked()),
48             this, SLOT(showAdvSettingsDlg()));
49     connect(selectRemoteBtn, SIGNAL(clicked()),
50             this, SLOT(showSelectRemoteDlg()));
51     connect(aboutBtn, SIGNAL(clicked()),
52             this, SLOT(showAboutDlg()));
53
54     remoteNameLabel = new QLabel(
55             settings.value("remoteName", 
56             tr("<no remote selected>")).toString(), this);
57     remoteNameLayout->addWidget(new QLabel(tr("Remote name: "), this));
58     remoteNameLayout->addWidget(remoteNameLabel);
59     remoteNameLayout->addWidget(rateUpBtn);
60     remoteNameLayout->addWidget(rateDownBtn);
61
62     layout->addLayout(remoteNameLayout);
63     layout->addLayout(btnLayout);
64     this->setLayout(layout);
65
66     updateRemoteName();
67
68     connect(engine->remote(), SIGNAL(ratingChanged(int)),
69             this, SLOT(setRating(int)));
70     engine->remote()->updateRating();
71 }
72
73 SettingsDlg::~SettingsDlg()
74 {
75     delete advSettingsBtn;
76     delete selectRemoteBtn;
77     delete aboutBtn;
78     delete rateUpBtn;
79     delete rateDownBtn;
80     delete remoteNameLabel;
81     delete remoteNameLayout;
82     delete btnLayout;
83     delete layout;
84 }
85
86 void SettingsDlg::showAdvSettingsDlg()
87 {
88     AdvSettingsDlg dlg(this, engine);
89     dlg.exec();
90     updateRemoteName();
91 }
92
93 void SettingsDlg::showSelectRemoteDlg()
94 {
95     SelectRemoteDlg dlg(this, engine);
96     connect(&dlg, SIGNAL(remoteDownloaded()), 
97             this, SLOT(updateRemoteName()));
98     dlg.exec();
99 }
100
101 void SettingsDlg::showAboutDlg()
102 {
103     AboutDlg dlg(this);
104     dlg.exec();
105 }
106
107 void SettingsDlg::updateRemoteName()
108 {
109     QSettings settings(this);
110     remoteNameLabel->setText(settings.value("remoteName", 
111             tr("Select remote")).toString());
112 }
113
114 void SettingsDlg::setRating(int rating)
115 {
116     qDebug() << rating;
117 }
118
119