]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mediaedit/mediaedit.cpp
This commit puts prefences for debuggin output and prefences for the joblist
[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    setupUi(this);
52
53    if (!m_console->preventInUseConnect())
54        return;
55
56    /* The media's pool */
57    poolCombo->addItems(console->pool_list);
58
59    /* The media's Status */
60    QStringList statusList = (QStringList() << "Full" << "Used" << "Append" << "Error" << "Purged" << "Recycled");
61    statusCombo->addItems(statusList);
62
63    /* Set up the query for the default values */
64    QStringList FieldList = (QStringList()
65       << "Media.VolumeName" << "Pool.Name" << "Media.VolStatus" << "Media.Slot" );
66    QStringList AsList = (QStringList()
67       << "VolumeName" << "PoolName" << "Status" << "Slot" );
68    int i = 0;
69    QString query("SELECT ");
70    foreach (QString field, FieldList) {
71       if (i != 0) {
72          query += ", ";
73       }
74       query += field + " AS " + AsList[i];
75       i += 1;
76    }
77    query += " FROM Media, Pool WHERE Media.PoolId=Pool.PoolId";
78    query += " AND Media.MediaId='" + mediaId + "'";
79    query += " ORDER BY Pool.Name";
80
81    if (mainWin->m_sqlDebug) {
82       Pmsg1(000, "MediaList query cmd : %s\n",query.toUtf8().data());
83    }
84    QStringList results;
85    if (m_console->sql_cmd(query, results)) {
86       QString field;
87       QStringList fieldlist;
88
89       /* Iterate through the lines of results, there should only be one. */
90       foreach (QString resultline, results) {
91          fieldlist = resultline.split("\t");
92          i = 0;
93
94          /* Iterate through fields in the record */
95          foreach (field, fieldlist) {
96             field = field.trimmed();  /* strip leading & trailing spaces */
97             if (i == 0) {
98                m_mediaName = field;
99                volumeLabel->setText(QString("Volume : %1").arg(m_mediaName));
100             } else if (i == 1) {
101                m_pool = field;
102             } else if (i == 2) {
103                m_status = field;
104             } else if (i == 3) {
105                bool ok;
106                m_slot = field.toInt(&ok, 10);
107                if (!ok){ m_slot = 0; }
108             }
109             i++;
110          } /* foreach field */
111       } /* foreach resultline */
112    } /* if results from query */
113
114    if (m_mediaName != "") {
115       int index;
116       /* default value for pool */
117       index = poolCombo->findText(m_pool, Qt::MatchExactly);
118       if (index != -1) {
119          poolCombo->setCurrentIndex(index);
120       }
121
122       /* default value for status */
123       index = statusCombo->findText(m_status, Qt::MatchExactly);
124       if (index != -1) {
125          statusCombo->setCurrentIndex(index);
126       }
127       slotSpin->setValue(m_slot);
128
129       this->show();
130    } else {
131       QMessageBox::warning(this, "No Volume name", "No Volume name given",
132                            QMessageBox::Ok, QMessageBox::Ok);
133       return;
134    }
135
136 }
137
138 /*
139  * Function to handle updating the record
140  */
141 void MediaEdit::accept()
142 {
143    QString scmd;
144    this->hide();
145    bool docmd = false;
146    scmd = QString("update volume=\"%1\"")
147                   .arg(m_mediaName);
148    if (m_pool != poolCombo->currentText()) {
149        scmd += " pool=\"" + poolCombo->currentText() + "\"";
150        docmd = true;
151    }
152    if (m_status != statusCombo->currentText()) {
153        scmd += " volstatus=\"" + statusCombo->currentText() + "\"";
154        docmd = true;
155    }
156    if (m_slot != slotSpin->value()) {
157        scmd += " slot=" + QString().setNum(slotSpin->value());
158        docmd = true;
159    }
160    if (docmd) {
161       if (mainWin->m_commandDebug) {
162          Pmsg1(000, "sending command : %s\n",scmd.toUtf8().data());
163       }
164       m_console->write_dir(scmd.toUtf8().data());
165       m_console->displayToPrompt();
166       m_console->notify(true);
167     }
168    delete this;
169    mainWin->resetFocus();
170 }
171
172 void MediaEdit::reject()
173 {
174    this->hide();
175    m_console->notify(true);
176    delete this;
177    mainWin->resetFocus();
178 }