]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/relabel/relabel.cpp
Backport from BEE
[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 many
7    others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    Bacula® is a registered trademark of Kern Sibbald.
15 */
16
17 /*
18  *  Label Dialog class
19  *
20  *   Kern Sibbald, February MMVII
21  *
22  */
23
24 #include "bat.h"
25 #include "relabel.h"
26 #include <QMessageBox>
27
28 /*
29  * An overload of the constructor to have a default storage show in the
30  * combobox on start.  Used from context sensitive in storage class.
31  */
32 relabelDialog::relabelDialog(Console *console, QString &fromVolume)
33 {
34    m_console = console;
35    m_fromVolume = fromVolume;
36    m_conn = m_console->notifyOff();
37    setupUi(this);
38    storageCombo->addItems(console->storage_list);
39    poolCombo->addItems(console->pool_list);
40    volumeName->setText(fromVolume);
41    QString fromText(tr("From Volume : "));
42    fromText += fromVolume;
43    fromLabel->setText(fromText);
44    QStringList defFields;
45    if (getDefs(defFields) >= 1) {
46       poolCombo->setCurrentIndex(poolCombo->findText(defFields[1], Qt::MatchExactly));
47       storageCombo->setCurrentIndex(storageCombo->findText(defFields[0], Qt::MatchExactly));
48    }
49    this->show();
50 }
51
52 /*
53  * Use an sql statment to get some defaults
54  */
55 int relabelDialog::getDefs(QStringList &fieldlist)
56 {
57    QString job, client, fileset;
58    QString query("");
59    query = "SELECT MediaType AS MediaType, Pool.Name AS PoolName"
60    " FROM Media"
61    " LEFT OUTER JOIN Pool ON Media.PoolId = Pool.PoolId"
62    " WHERE VolumeName = \'" + m_fromVolume  + "\'";
63    if (mainWin->m_sqlDebug) { Pmsg1(000, "query = %s\n", query.toUtf8().data()); }
64    QStringList results;
65    if (m_console->sql_cmd(query, results)) {
66       QString field;
67       /* Iterate through the lines of results, there should only be one. */
68       foreach (QString resultline, results) {
69          fieldlist = resultline.split("\t");
70       } /* foreach resultline */
71    } /* if results from query */
72    return results.count();
73 }
74
75 void relabelDialog::accept()
76 {
77    QString scmd;
78    if (volumeName->text().toUtf8().data()[0] == 0) {
79       QMessageBox::warning(this, tr("No Volume name"), tr("No Volume name given"),
80                            QMessageBox::Ok, QMessageBox::Ok);
81       return;
82    }
83    if (m_fromVolume == volumeName->text().toUtf8()) {
84       QMessageBox::warning(this, tr("New name must be different"),
85                            tr("New name must be different"),
86                            QMessageBox::Ok, QMessageBox::Ok);
87       return;
88    }
89
90    this->hide();
91    scmd = QString("relabel storage=\"%1\" oldvolume=\"%2\" volume=\"%3\" pool=\"%4\" slot=%5")
92                   .arg(storageCombo->currentText())
93                   .arg(m_fromVolume)
94                   .arg(volumeName->text())
95                   .arg(poolCombo->currentText())
96                   .arg(slotSpin->value());
97    if (mainWin->m_commandDebug) {
98       Pmsg1(000, "sending command : %s\n",scmd.toUtf8().data());
99    }
100    m_console->write_dir(scmd.toUtf8().data());
101    m_console->displayToPrompt(m_conn);
102    m_console->notify(m_conn, true);
103    delete this;
104    mainWin->resetFocus();
105 }
106
107 void relabelDialog::reject()
108 {
109    this->hide();
110    m_console->notify(m_conn, true);
111    delete this;
112    mainWin->resetFocus();
113 }