Fixed mainwidget.cpp
[irwi] / src / settingsdlg.cpp
1 #include "settingsdlg.h"
2 #include "advsettingsdlg.h"
3 #include "selectremotedlg.h"
4 #include "aboutdlg.h"
5
6 #include <QHBoxLayout>
7 #include <QVBoxLayout>
8 #include <QWidget>
9 #include <QDialog>
10 #include <QPushButton>
11 #include <QSettings>
12 #include <QLabel>
13
14 SettingsDlg::SettingsDlg(QWidget *parent)
15     : QDialog(parent)
16 {
17     layout = new QVBoxLayout(this);
18     btnLayout = new QHBoxLayout(this);
19     remoteNameLayout = new QHBoxLayout(this);
20     
21     QSettings settings(this);
22     advSettingsBtn = new QPushButton(tr("Advanced"), this);
23     selectRemoteBtn = new QPushButton(tr("Select remote"), this);
24     aboutBtn = new QPushButton(tr("About"), this);
25
26     btnLayout->addWidget(advSettingsBtn);
27     btnLayout->addWidget(selectRemoteBtn);
28     btnLayout->addWidget(aboutBtn);
29
30     connect(advSettingsBtn, SIGNAL(clicked()),
31             this, SLOT(showAdvSettingsDlg()));
32     connect(selectRemoteBtn, SIGNAL(clicked()),
33             this, SLOT(showSelectRemoteDlg()));
34     connect(aboutBtn, SIGNAL(clicked()),
35             this, SLOT(showAboutDlg()));
36
37     remoteNameLabel = new QLabel(
38                 settings.value("remoteName", 
39                 tr("<no remote selected>")).toString(), this);
40     remoteNameLayout->addWidget(new QLabel(tr("Remote name: "), this));
41     remoteNameLayout->addWidget(remoteNameLabel);
42
43     layout->addLayout(remoteNameLayout);
44     layout->addLayout(btnLayout);
45     this->setLayout(layout);
46
47     updateRemoteName();
48 }
49
50 SettingsDlg::~SettingsDlg()
51 {
52     delete advSettingsBtn;
53     delete selectRemoteBtn;
54     delete aboutBtn;
55     delete remoteNameLabel;
56     delete remoteNameLayout;
57     delete btnLayout;
58     delete layout;
59 }
60
61 void SettingsDlg::showAdvSettingsDlg()
62 {
63     AdvSettingsDlg dlg(this);
64     dlg.exec();
65 }
66
67 void SettingsDlg::showSelectRemoteDlg()
68 {
69     SelectRemoteDlg dlg(this);
70     connect(&dlg, SIGNAL(remoteDownloaded()), 
71             this, SLOT(updateRemoteName()));
72     dlg.exec();
73 }
74
75 void SettingsDlg::showAboutDlg()
76 {
77     AboutDlg dlg(this);
78     dlg.exec();
79 }
80
81 void SettingsDlg::updateRemoteName()
82 {
83     QSettings settings(this);
84     remoteNameLabel->setText(settings.value("remoteName", 
85                 tr("Select remote")).toString());
86 }
87
88