]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/relabel/relabel.cpp
remove QFormLayout, and use QGridLayout instead
[bacula/bacula] / bacula / src / qt-console / relabel / relabel.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
5
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 and included
11    in the file LICENSE.
12
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.
17
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
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
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.
27 */
28  
29 /*
30  *  Label Dialog class
31  *
32  *   Kern Sibbald, February MMVII
33  *
34  */ 
35
36 #include "bat.h"
37 #include "relabel.h"
38 #include <QMessageBox>
39
40 /*
41  * An overload of the constructor to have a default storage show in the
42  * combobox on start.  Used from context sensitive in storage class.
43  */
44 relabelDialog::relabelDialog(Console *console, QString &fromVolume)
45 {
46    m_console = console;
47    m_fromVolume = fromVolume;
48    m_conn = m_console->notifyOff();
49    setupUi(this);
50    storageCombo->addItems(console->storage_list);
51    poolCombo->addItems(console->pool_list);
52    volumeName->setText(fromVolume);
53    QString fromText(tr("From Volume : "));
54    fromText += fromVolume;
55    fromLabel->setText(fromText);
56    QStringList defFields;
57    if (getDefs(defFields) >= 1) {
58       poolCombo->setCurrentIndex(poolCombo->findText(defFields[1], Qt::MatchExactly));
59       storageCombo->setCurrentIndex(storageCombo->findText(defFields[0], Qt::MatchExactly));
60    }
61    this->show();
62 }
63
64 /*
65  * Use an sql statment to get some defaults
66  */
67 int relabelDialog::getDefs(QStringList &fieldlist)
68 {
69    QString job, client, fileset;
70    QString query("");
71    query = "SELECT MediaType AS MediaType, Pool.Name AS PoolName"
72    " FROM Media"
73    " LEFT OUTER JOIN Pool ON Media.PoolId = Pool.PoolId"
74    " WHERE VolumeName = \'" + m_fromVolume  + "\'";
75    if (mainWin->m_sqlDebug) { Pmsg1(000, "query = %s\n", query.toUtf8().data()); }
76    QStringList results;
77    if (m_console->sql_cmd(query, results)) {
78       QString field;
79       /* Iterate through the lines of results, there should only be one. */
80       foreach (QString resultline, results) {
81          fieldlist = resultline.split("\t");
82       } /* foreach resultline */
83    } /* if results from query */
84    return results.count();
85 }
86
87 void relabelDialog::accept()
88 {
89    QString scmd;
90    if (volumeName->text().toUtf8().data()[0] == 0) {
91       QMessageBox::warning(this, tr("No Volume name"), tr("No Volume name given"),
92                            QMessageBox::Ok, QMessageBox::Ok);
93       return;
94    }
95    if (m_fromVolume == volumeName->text().toUtf8()) {
96       QMessageBox::warning(this, tr("New name must be different"), 
97                            tr("New name must be different"),
98                            QMessageBox::Ok, QMessageBox::Ok);
99       return;
100    }
101
102    this->hide();
103    scmd = QString("relabel storage=\"%1\" oldvolume=\"%2\" volume=\"%3\" pool=\"%4\" slot=%5")
104                   .arg(storageCombo->currentText())
105                   .arg(m_fromVolume)
106                   .arg(volumeName->text())
107                   .arg(poolCombo->currentText())
108                   .arg(slotSpin->value());
109    if (mainWin->m_commandDebug) {
110       Pmsg1(000, "sending command : %s\n",scmd.toUtf8().data());
111    }
112    m_console->write_dir(scmd.toUtf8().data());
113    m_console->displayToPrompt(m_conn);
114    m_console->notify(m_conn, true);
115    delete this;
116    mainWin->resetFocus();
117 }
118
119 void relabelDialog::reject()
120 {
121    this->hide();
122    m_console->notify(m_conn, true);
123    delete this;
124    mainWin->resetFocus();
125 }