blob: 2e9cbd609c47895c892006db64dcd983896b58e2 [file] [log] [blame]
Robert Bieberc2721442010-07-15 21:39:09 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "newprojectdialog.h"
23#include "ui_newprojectdialog.h"
Robert Bieber025147e2010-07-16 20:47:23 +000024#include "targetdata.h"
Robert Bieberc2721442010-07-15 21:39:09 +000025
26#include <QSettings>
27#include <QFileDialog>
28#include <QDir>
29
30NewProjectDialog::NewProjectDialog(QWidget *parent) :
31 QDialog(parent),
32 ui(new Ui::NewProjectDialog)
33{
34 ui->setupUi(this);
35
36 /* Getting the default directory from the application settings */
37 QSettings settings;
38 settings.beginGroup("NewProjectDialog");
39
40 ui->locationBox->setText(settings.value("defaultDir",
41 QDir::home().absolutePath())
42 .toString());
43
44 settings.endGroup();
45
Robert Bieber025147e2010-07-16 20:47:23 +000046 /* Populating the target box */
47 TargetData targets;
48 for(int i = 0; i < targets.count(); i++)
49 {
50 ui->targetBox->insertItem(i, QIcon(), targets.name(i), targets.id(i));
51 }
Robert Bieber4a469962010-07-17 00:35:54 +000052 targetChange(0);
Robert Bieber025147e2010-07-16 20:47:23 +000053
Robert Bieber4a469962010-07-17 00:35:54 +000054 /* Connecting the browse button and target box */
Robert Bieberc2721442010-07-15 21:39:09 +000055 QObject::connect(ui->browseButton, SIGNAL(clicked()),
56 this, SLOT(browse()));
Robert Bieber4a469962010-07-17 00:35:54 +000057 QObject::connect(ui->targetBox, SIGNAL(currentIndexChanged(int)),
58 this, SLOT(targetChange(int)));
Robert Bieberc2721442010-07-15 21:39:09 +000059}
60
61NewProjectDialog::~NewProjectDialog()
62{
63 delete ui;
64}
65
66void NewProjectDialog::accept()
67{
68 status.name = ui->nameBox->text();
69 status.path = ui->locationBox->text();
Robert Bieber025147e2010-07-16 20:47:23 +000070 status.target = ui->targetBox->itemData(ui->targetBox->currentIndex())
71 .toString();
Robert Bieberc2721442010-07-15 21:39:09 +000072 status.sbs = ui->sbsBox->isChecked();
73 status.wps = ui->wpsBox->isChecked();
74 status.fms = ui->fmsBox->isChecked();
75 status.rsbs = ui->rsbsBox->isChecked();
76 status.rwps = ui->rwpsBox->isChecked();
77 status.rfms = ui->rfmsBox->isChecked();
78
79 QSettings settings;
80 settings.beginGroup("NewProjectDialog");
81
82 settings.setValue("defaultDir", ui->locationBox->text());
83
84 settings.endGroup();
85
86 QDialog::accept();
87}
88
89void NewProjectDialog::reject()
90{
91 ui->nameBox->setText(status.name);
92 ui->locationBox->setText(status.path);
Robert Bieber025147e2010-07-16 20:47:23 +000093 ui->targetBox->setCurrentIndex(0);
Robert Bieberc2721442010-07-15 21:39:09 +000094 ui->sbsBox->setChecked(status.sbs);
95 ui->wpsBox->setChecked(status.wps);
96 ui->fmsBox->setChecked(status.fms);
97 ui->rsbsBox->setChecked(status.rsbs);
98 ui->rwpsBox->setChecked(status.rwps);
99 ui->rfmsBox->setChecked(status.rfms);
100
101 QSettings settings;
102 settings.beginGroup("NewProjectDialog");
103
104 ui->locationBox->setText(settings.value("defaultDir",
105 QDir::home().absolutePath())
106 .toString());
107
108 settings.endGroup();
109
110 QDialog::reject();
111}
112
113void NewProjectDialog::browse()
114{
115 QString path;
116 path = QFileDialog::getExistingDirectory(this, "New Project Location",
117 ui->locationBox->text());
118 ui->locationBox->setText(path);
119}
Robert Bieber4a469962010-07-17 00:35:54 +0000120
121void NewProjectDialog::targetChange(int target)
122{
123 TargetData targets;
124
125 if(targets.fm(target))
126 {
127 ui->fmsBox->setEnabled(true);
128 ui->rfmsBox->setEnabled(true);
129 }
130 else
131 {
132 ui->fmsBox->setChecked(false);
133 ui->rfmsBox->setChecked(false);
134
135 ui->fmsBox->setEnabled(false);
136 ui->rfmsBox->setEnabled(false);
137 }
138
139 if(targets.remoteDepth(target) == TargetData::None)
140 {
141 ui->rwpsBox->setChecked(false);
142 ui->rsbsBox->setChecked(false);
143 ui->rfmsBox->setChecked(false);
144
145 ui->rsbsBox->setEnabled(false);
146 ui->rwpsBox->setEnabled(false);
147 ui->rfmsBox->setEnabled(false);
148 }
149 else
150 {
151 ui->rsbsBox->setEnabled(true);
152 ui->rwpsBox->setEnabled(true);
153 if(targets.fm(target))
154 ui->rfmsBox->setEnabled(true);
155 }
156
157}