]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/prune.cpp
Create a prune page. Populate it from medialist and clients.
[bacula/bacula] / bacula / src / qt-console / run / prune.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-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 /*
30  *  Run Dialog class
31  *
32  *   Kern Sibbald, February MMVII
33  *
34  *  $Id: prune.cpp 4856 2007-05-20 15:28:43Z bartleyd2 $
35  */ 
36
37 #include "bat.h"
38 #include "run.h"
39
40 /*
41  * Setup all the combo boxes and display the dialog
42  */
43 prunePage::prunePage(const QString &volume, const QString &client)
44 {
45    QDateTime dt;
46
47    m_name = "Prune";
48    pgInitialize();
49    setupUi(this);
50    m_console->notify(false);
51
52    QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
53    if (mainWin->m_sqlDebug) {
54       Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
55    }
56    QStringList results, volumeList;
57    if (m_console->sql_cmd(query, results)) {
58       QString field;
59       QStringList fieldlist;
60       /* Iterate through the lines of results. */
61       foreach (QString resultline, results) {
62          fieldlist = resultline.split("\t");
63          volumeList.append(fieldlist[0]);
64       } /* foreach resultline */
65    } /* if results from query */
66
67    volumeCombo->addItem("Any");
68    volumeCombo->addItems(volumeList);
69    clientCombo->addItem("Any");
70    clientCombo->addItems(m_console->client_list);
71    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
72    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
73    filesCheckBox->setCheckState(Qt::Checked);
74    jobsCheckBox->setCheckState(Qt::Checked);
75    volumeCheckBox->setCheckState(Qt::Checked);
76    connect(filesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkStateChanged()));
77    connect(jobsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkStateChanged()));
78    connect(volumeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkStateChanged()));
79    if (clientCombo->findText(client, Qt::MatchExactly) != -1)
80       clientCombo->setCurrentIndex(clientCombo->findText(client, Qt::MatchExactly));
81    else
82       clientCombo->setCurrentIndex(0);
83    if (volumeCombo->findText(volume, Qt::MatchExactly) != -1)
84       volumeCombo->setCurrentIndex(volumeCombo->findText(volume, Qt::MatchExactly));
85    else
86       volumeCombo->setCurrentIndex(0);
87    connect(volumeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(volumeChanged()));
88    connect(clientCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(clientChanged()));
89
90    dockPage();
91    setCurrent();
92    this->show();
93 }
94
95 void prunePage::okButtonPushed()
96 {
97    this->hide();
98    QString cmd("prune");
99    if (filesCheckBox->checkState() == Qt::Checked) {
100       cmd += " files";
101    }
102    if (jobsCheckBox->checkState() == Qt::Checked) {
103       cmd += " jobs";
104    }
105    if (filesCheckBox->checkState() == Qt::Checked) {
106       cmd += " volume";
107    }
108    if (volumeCombo->currentText() != "Any") {
109       cmd += " volume=\"" + volumeCombo->currentText() + "\"";
110    }
111    if (clientCombo->currentText() != "Any") {
112       cmd += " client=\"" + clientCombo->currentText() + "\"";
113    }
114    cmd += " yes";
115
116    if (mainWin->m_commandDebug) {
117       Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
118    }
119
120    consoleCommand(cmd);
121    m_console->notify(true);
122    closeStackPage();
123    mainWin->resetFocus();
124 }
125
126
127 void prunePage::cancelButtonPushed()
128 {
129    mainWin->set_status(" Canceled");
130    this->hide();
131    m_console->notify(true);
132    closeStackPage();
133    mainWin->resetFocus();
134 }
135
136 void prunePage::checkStateChanged()
137 {
138    if ((filesCheckBox->checkState() == Qt::Unchecked) &&
139        (jobsCheckBox->checkState() == Qt::Unchecked) &&
140        (volumeCheckBox->checkState() == Qt::Unchecked)) {
141       filesCheckBox->setCheckState(Qt::Checked);
142    }
143 }
144
145 void prunePage::volumeChanged()
146 {
147    if ((volumeCombo->currentText() == "Any") && (clientCombo->currentText() == "Any")) {
148       clientCombo->setCurrentIndex(1);
149    }
150 }
151
152 void prunePage::clientChanged()
153 {
154    if ((volumeCombo->currentText() == "Any") && (clientCombo->currentText() == "Any")) {
155       volumeCombo->setCurrentIndex(1);
156    }
157 }