]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mediaedit/mediaedit.cpp
Added delete and purge options in medialist. Shorten headings to get more to
[bacula/bacula] / bacula / src / qt-console / mediaedit / mediaedit.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 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 plus additions
11    that are listed 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 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.
27 */
28 /*
29  *   Version $Id: batstack.h 4230 2007-02-21 20:07:37Z kerns $
30  *
31  *   Dirk Bartley, March 2007
32  */
33  
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
36 #include <QMessageBox>
37 #include "bat.h"
38 #include "mediaedit.h"
39
40 /*
41  * A constructor 
42  */
43 MediaEdit::MediaEdit(Console *console, QString &mediaId)
44 {
45    m_console = console;
46    m_console->notify(false);
47    m_pool = "";
48    m_status = "";
49    m_slot = 0;
50
51
52    setupUi(this);
53
54    /* The media's pool */
55    poolCombo->addItems(console->pool_list);
56
57    /* The media's Status */
58    QStringList statusList = (QStringList() << "Full" << "Append" << "Error" << "Purged" << "Recycled");
59    statusCombo->addItems(statusList);
60
61    /* Set up the query for the default values */
62    QStringList FieldList = (QStringList()
63       << "Media.VolumeName" << "Pool.Name" << "Media.VolStatus" << "Media.Slot" );
64    QStringList AsList = (QStringList()
65       << "VolumeName" << "PoolName" << "Status" << "Slot" );
66    int i = 0;
67    QString query("SELECT ");
68    foreach (QString field, FieldList) {
69       if (i != 0) {
70          query += ", ";
71       }
72       query += field + " AS " + AsList[i];
73       i += 1;
74    }
75    query += " FROM Media, Pool WHERE Media.PoolId=Pool.PoolId";
76    query += " AND Media.MediaId='" + mediaId + "'";
77    query += " ORDER BY Pool.Name";
78
79    /* FIXME Make this a user configurable logging action and dont use printf */
80    //printf("MediaList query cmd : %s\n",query.toUtf8().data());
81    QStringList results;
82    if (m_console->sql_cmd(query, results)) {
83       QString field;
84       QStringList fieldlist;
85
86       /* Iterate through the lines of results, there should only be one. */
87       foreach (QString resultline, results) {
88          fieldlist = resultline.split("\t");
89          i = 0;
90
91          /* Iterate through fields in the record */
92          foreach (field, fieldlist) {
93             field = field.trimmed();  /* strip leading & trailing spaces */
94             if (i == 0) {
95                m_mediaName = field;
96                volumeLabel->setText(QString("Volume : %1").arg(m_mediaName));
97             } else if (i == 1) {
98                m_pool = field;
99             } else if (i == 2) {
100                m_status = field;
101             } else if (i == 3) {
102                bool ok;
103                m_slot = field.toInt(&ok, 10);
104                if (!ok){ m_slot = 0; }
105             }
106             i++;
107          } /* foreach field */
108       } /* foreach resultline */
109    } /* if results from query */
110
111    if (m_mediaName != "") {
112       int index;
113       /* default value for pool */
114       index = poolCombo->findText(m_pool, Qt::MatchExactly);
115       if (index != -1) {
116          poolCombo->setCurrentIndex(index);
117       }
118
119       /* default value for status */
120       index = statusCombo->findText(m_status, Qt::MatchExactly);
121       if (index != -1) {
122          statusCombo->setCurrentIndex(index);
123       }
124       slotSpin->setValue(m_slot);
125
126       this->show();
127    } else {
128       QMessageBox::warning(this, "No Volume name", "No Volume name given",
129                            QMessageBox::Ok, QMessageBox::Ok);
130       return;
131    }
132
133 }
134
135 /*
136  * Function to handle updating the record
137  */
138 void MediaEdit::accept()
139 {
140    QString scmd;
141    this->hide();
142    bool docmd = false;
143    scmd = QString("update volume=\"%1\"")
144                   .arg(m_mediaName);
145    if (m_pool != poolCombo->currentText()) {
146        scmd += " pool=\"" + poolCombo->currentText() + "\"";
147        docmd = true;
148    }
149    if (m_status != statusCombo->currentText()) {
150        scmd += " volstatus=\"" + statusCombo->currentText() + "\"";
151        docmd = true;
152    }
153    if (m_slot != slotSpin->value()) {
154        scmd += " slot=" + QString().setNum(slotSpin->value());
155        docmd = true;
156    }
157    if (docmd) {
158       /* FIXME Make this a user configurable logging action and dont use printf */
159       //printf("sending command : %s\n",scmd.toUtf8().data());
160       m_console->write_dir(scmd.toUtf8().data());
161       m_console->displayToPrompt();
162       m_console->notify(true);
163     }
164    delete this;
165    mainWin->resetFocus();
166 }
167
168 void MediaEdit::reject()
169 {
170    this->hide();
171    m_console->notify(true);
172    delete this;
173    mainWin->resetFocus();
174 }