1 /*
2 * Cantata
3 *
4 * Copyright (c) 2011-2020 Craig Drummond <craig.p.drummond@gmail.com>
5 *
6 * ----
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #include "remotedevicepropertiesdialog.h"
25 #include "devicepropertieswidget.h"
26 #include "remotedevicepropertieswidget.h"
27 #include "models/devicesmodel.h"
28 #include "support/messagebox.h"
29 #include "support/icon.h"
30 #include <QTabWidget>
31 #include <QStyle>
32 #include <QIcon>
33
RemoteDevicePropertiesDialog(QWidget * parent)34 RemoteDevicePropertiesDialog::RemoteDevicePropertiesDialog(QWidget *parent)
35 : Dialog(parent)
36 , isCreate(false)
37 {
38 setButtons(Ok|Cancel);
39 setCaption(tr("Device Properties"));
40 setAttribute(Qt::WA_DeleteOnClose);
41 setWindowModality(Qt::WindowModal);
42 tab=new QTabWidget(this);
43 remoteProp=new RemoteDevicePropertiesWidget(tab);
44 devProp=new DevicePropertiesWidget(tab);
45 int margin=style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
46 if (margin<1) {
47 margin=6;
48 }
49 devProp->layout()->setContentsMargins(margin, margin, margin, margin);
50 tab->addTab(remoteProp, tr("Connection"));
51 tab->addTab(devProp, tr("Music Library"));
52 setMainWidget(tab);
53 }
54
show(const DeviceOptions & opts,const RemoteFsDevice::Details & det,int props,int disabledProps,bool create,bool isConnected)55 void RemoteDevicePropertiesDialog::show(const DeviceOptions &opts, const RemoteFsDevice::Details &det, int props, int disabledProps, bool create, bool isConnected)
56 {
57 isCreate=create;
58 if (isCreate) {
59 setCaption(tr("Add Device"));
60 }
61
62 if (create) {
63 devProp->setVisible(false);
64 } else {
65 tab->setCurrentIndex(isConnected ? 1 : 0);
66 }
67 devProp->setEnabled(!create && isConnected);
68 devProp->showRemoteConnectionNote(!isConnected);
69 devProp->update(QString(), opts, QList<DeviceStorage>(), props, disabledProps);
70 remoteProp->update(det, create, isConnected);
71 connect(devProp, SIGNAL(updated()), SLOT(enableOkButton()));
72 connect(remoteProp, SIGNAL(updated()), SLOT(enableOkButton()));
73 Dialog::show();
74 enableButtonOk(false);
75 }
76
enableOkButton()77 void RemoteDevicePropertiesDialog::enableOkButton()
78 {
79 bool useDevProp=devProp->isEnabled();
80 enableButtonOk(remoteProp->isSaveable() && (!useDevProp || devProp->isSaveable()) &&
81 (isCreate || remoteProp->isModified() || !useDevProp || devProp->isModified()));
82 }
83
slotButtonClicked(int button)84 void RemoteDevicePropertiesDialog::slotButtonClicked(int button)
85 {
86 switch (button) {
87 case Ok: {
88 RemoteFsDevice::Details d=remoteProp->details();
89 if (d.name!=remoteProp->origDetails().name && DevicesModel::self()->device(RemoteFsDevice::createUdi(d.name))) {
90 MessageBox::error(this, tr("A remote device named '%1' already exists!\n\nPlease choose a different name.").arg(d.name));
91 } else {
92 emit updatedSettings(devProp->settings(), remoteProp->details());
93 accept();
94 }
95 break;
96 }
97 case Cancel:
98 emit cancelled();
99 reject();
100 break;
101 default:
102 Dialog::slotButtonClicked(button);
103 break;
104 }
105 }
106
107 #include "moc_remotedevicepropertiesdialog.cpp"
108