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