2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation plus additions
11 that are listed in the file LICENSE.
13 This program is distributed in the hope that it will be useful, but
14 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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Version $Id: batstack.h 4230 2007-02-21 20:07:37Z kerns $
31 * Dirk Bartley, March 2007
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
36 #include <QMessageBox>
38 #include "mediaedit.h"
44 MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId)
47 m_name = "Media Edit";
48 pgInitialize(parentWidget);
49 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
50 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge-edit.svg")));
55 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
56 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
58 connect(retentionSpin, SIGNAL(valueChanged(int)), this, SLOT(retentionChanged()));
59 connect(useDurationSpin, SIGNAL(valueChanged(int)), this, SLOT(useDurationChanged()));
60 connect(retentionRadio, SIGNAL(pressed()), this, SLOT(retentionRadioPressed()));
61 connect(useDurationRadio, SIGNAL(pressed()), this, SLOT(useDurationRadioPressed()));
67 if (!m_console->preventInUseConnect())
70 /* The media's pool */
71 poolCombo->addItems(m_console->pool_list);
73 /* The media's Status */
74 QStringList statusList = (QStringList() << "Full" << "Used" << "Append" << "Error" << "Purged" << "Recycled");
75 statusCombo->addItems(statusList);
77 /* Set up the query for the default values */
78 QStringList FieldList = (QStringList()
79 << "Media.VolumeName" << "Pool.Name" << "Media.VolStatus" << "Media.Slot"
80 << "Media.VolRetention" << "Media.VolUseDuration");
81 QStringList AsList = (QStringList()
82 << "VolumeName" << "PoolName" << "Status" << "Slot"
83 << "Retention" << "UseDuration");
85 QString query("SELECT ");
86 foreach (QString field, FieldList) {
90 query += field + " AS " + AsList[i];
93 query += " FROM Media, Pool WHERE Media.PoolId=Pool.PoolId";
94 query += " AND Media.MediaId='" + mediaId + "'";
95 query += " ORDER BY Pool.Name";
97 if (mainWin->m_sqlDebug) {
98 Pmsg1(000, "MediaList query cmd : %s\n",query.toUtf8().data());
101 if (m_console->sql_cmd(query, results)) {
103 QStringList fieldlist;
105 /* Iterate through the lines of results, there should only be one. */
106 foreach (QString resultline, results) {
107 fieldlist = resultline.split("\t");
110 /* Iterate through fields in the record */
111 foreach (field, fieldlist) {
112 field = field.trimmed(); /* strip leading & trailing spaces */
116 volumeLabel->setText(QString("Volume : %1").arg(m_mediaName));
122 m_slot = field.toInt(&ok, 10);
123 if (!ok){ m_slot = 0; }
125 m_retention = field.toLong(&ok, 10);
126 if (!ok){ m_retention = 0; }
128 m_useDuration = field.toLong(&ok, 10);
129 if (!ok){ m_useDuration = 0; }
132 } /* foreach field */
133 } /* foreach resultline */
134 } /* if results from query */
136 if (m_mediaName != "") {
138 /* default value for pool */
139 index = poolCombo->findText(m_pool, Qt::MatchExactly);
141 poolCombo->setCurrentIndex(index);
144 /* default value for status */
145 index = statusCombo->findText(m_status, Qt::MatchExactly);
147 statusCombo->setCurrentIndex(index);
149 slotSpin->setValue(m_slot);
150 retentionSpin->setValue(m_retention);
151 useDurationSpin->setValue(m_useDuration);
155 QMessageBox::warning(this, "No Volume name", "No Volume name given",
156 QMessageBox::Ok, QMessageBox::Ok);
162 * Function to handle updating the record then closing the page
164 void MediaEdit::okButtonPushed()
166 //update volume=xxx slots MaxVolJobs=nnn MaxVolBytes=nnn Recycle=yes|no
167 // enabled=n recyclepool=zzz
168 // done pool=yyy volstatus=xxx slot=nnn VolUse=ddd VolRetention=ddd
172 scmd = QString("update volume=\"%1\"")
174 if (m_pool != poolCombo->currentText()) {
175 scmd += " pool=\"" + poolCombo->currentText() + "\"";
178 if (m_status != statusCombo->currentText()) {
179 scmd += " volstatus=\"" + statusCombo->currentText() + "\"";
182 if (m_slot != slotSpin->value()) {
183 scmd += " slot=" + QString().setNum(slotSpin->value());
186 if (m_retention != retentionSpin->value()) {
187 scmd += " VolRetention=" + QString().setNum(retentionSpin->value());
190 if (m_useDuration != useDurationSpin->value()) {
191 scmd += " VolUse=" + QString().setNum(useDurationSpin->value());
195 if (mainWin->m_commandDebug) {
196 Pmsg1(000, "sending command : %s\n",scmd.toUtf8().data());
198 consoleCommand(scmd);
203 /* close if cancel */
204 void MediaEdit::cancelButtonPushed()
210 * Slot for user changed retention
212 void MediaEdit::retentionChanged()
214 retentionRadio->setChecked(true);
215 setSpins(retentionSpin->value());
219 * Slot for user changed the use duration
221 void MediaEdit::useDurationChanged()
223 useDurationRadio->setChecked(true);
224 setSpins(useDurationSpin->value());
228 * Set the 5 duration spins from a known duration value
230 void MediaEdit::setSpins(int value)
232 int years, days, hours, minutes, seconds, left;
234 years = abs(value / 31536000);
235 left = value - years * 31536000;
236 days = abs(left / 86400);
237 left = left - days * 86400;
238 hours = abs(left / 3600);
239 left = left - hours * 3600;
240 minutes = abs(left / 60);
241 seconds = left - minutes * 60;
243 yearsSpin->setValue(years);
244 daysSpin->setValue(days);
245 hoursSpin->setValue(hours);
246 minutesSpin->setValue(minutes);
247 secondsSpin->setValue(seconds);
252 * This slot is called any time any one of the 5 duration spins a changed.
254 void MediaEdit::durationChanged()
257 if (secondsSpin->value() == -1) {
258 secondsSpin->setValue(59);
259 minutesSpin->setValue(minutesSpin->value()-1);
261 if (minutesSpin->value() == -1) {
262 minutesSpin->setValue(59);
263 hoursSpin->setValue(hoursSpin->value()-1);
265 if (hoursSpin->value() == -1) {
266 hoursSpin->setValue(23);
267 daysSpin->setValue(daysSpin->value()-1);
269 if (daysSpin->value() == -1) {
270 daysSpin->setValue(364);
271 yearsSpin->setValue(yearsSpin->value()-1);
273 if (yearsSpin->value() == -1) {
274 yearsSpin->setValue(0);
277 if (secondsSpin->value() == 60) {
278 secondsSpin->setValue(0);
279 minutesSpin->setValue(minutesSpin->value()+1);
281 if (minutesSpin->value() == 60) {
282 minutesSpin->setValue(0);
283 hoursSpin->setValue(hoursSpin->value()+1);
285 if (hoursSpin->value() == 24) {
286 hoursSpin->setValue(0);
287 daysSpin->setValue(daysSpin->value()+1);
289 if (daysSpin->value() == 365) {
290 daysSpin->setValue(0);
291 yearsSpin->setValue(yearsSpin->value()+1);
294 if (retentionRadio->isChecked()) {
296 retention = secondsSpin->value() + minutesSpin->value() * 60 +
297 hoursSpin->value() * 3600 + daysSpin->value() * 86400 +
298 yearsSpin->value() * 31536000;
299 disconnect(retentionSpin, SIGNAL(valueChanged(int)), this, SLOT(retentionChanged()));
300 retentionSpin->setValue(retention);
301 connect(retentionSpin, SIGNAL(valueChanged(int)), this, SLOT(retentionChanged()));
303 if (useDurationRadio->isChecked()) {
305 useDuration = secondsSpin->value() + minutesSpin->value() * 60 +
306 hoursSpin->value() * 3600 + daysSpin->value() * 86400 +
307 yearsSpin->value() * 31536000;
308 disconnect(useDurationSpin, SIGNAL(valueChanged(int)), this, SLOT(useDurationChanged()));
309 useDurationSpin->setValue(useDuration);
310 connect(useDurationSpin, SIGNAL(valueChanged(int)), this, SLOT(useDurationChanged()));
314 /* Connect the spins */
315 void MediaEdit::connectSpins()
317 connect(secondsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
318 connect(minutesSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
319 connect(hoursSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
320 connect(daysSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
321 connect(yearsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
324 /* disconnect spins so that we can set the value of other spin from changed duration spin */
325 void MediaEdit::disconnectSpins()
327 disconnect(secondsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
328 disconnect(minutesSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
329 disconnect(hoursSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
330 disconnect(daysSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
331 disconnect(yearsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
334 /* slot for setting spins when retention radio checked */
335 void MediaEdit::retentionRadioPressed()
337 setSpins(retentionSpin->value());
340 /* slot for setting spins when duration radio checked */
341 void MediaEdit::useDurationRadioPressed()
343 setSpins(useDurationSpin->value());