1 /*
2 Bacula(R) - The Network Backup Solution
3
4 Copyright (C) 2000-2020 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 * Run Dialog class
22 *
23 * Kern Sibbald, February MMVII
24 *
25 * $Id$
26 */
27
28 #include "bat.h"
29 #include "run.h"
30
31 /*
32 * Setup all the combo boxes and display the dialog
33 */
prunePage(const QString & volume,const QString & client)34 prunePage::prunePage(const QString &volume, const QString &client) : Pages()
35 {
36 QDateTime dt;
37
38 m_name = tr("Prune");
39 pgInitialize();
40 setupUi(this);
41 m_conn = m_console->notifyOff();
42
43 QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
44 if (mainWin->m_sqlDebug) {
45 Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
46 }
47 QStringList results, volumeList;
48 if (m_console->sql_cmd(query, results)) {
49 QString field;
50 QStringList fieldlist;
51 /* Iterate through the lines of results. */
52 foreach (QString resultline, results) {
53 fieldlist = resultline.split("\t");
54 volumeList.append(fieldlist[0]);
55 } /* foreach resultline */
56 } /* if results from query */
57
58 volumeCombo->addItem(tr("Any"));
59 volumeCombo->addItems(volumeList);
60 clientCombo->addItem(tr("Any"));
61 clientCombo->addItems(m_console->client_list);
62 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
63 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
64 filesRadioButton->setChecked(true);
65 if (clientCombo->findText(client, Qt::MatchExactly) != -1)
66 clientCombo->setCurrentIndex(clientCombo->findText(client, Qt::MatchExactly));
67 else
68 clientCombo->setCurrentIndex(0);
69 if (volumeCombo->findText(volume, Qt::MatchExactly) != -1)
70 volumeCombo->setCurrentIndex(volumeCombo->findText(volume, Qt::MatchExactly));
71 else
72 volumeCombo->setCurrentIndex(0);
73 connect(volumeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(volumeChanged()));
74 connect(clientCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(clientChanged()));
75
76 dockPage();
77 setCurrent();
78 this->show();
79 }
80
okButtonPushed()81 void prunePage::okButtonPushed()
82 {
83 this->hide();
84 QString cmd("prune");
85 if (filesRadioButton->isChecked()) {
86 cmd += " files";
87 }
88 if (jobsRadioButton->isChecked()) {
89 cmd += " jobs";
90 }
91 if (filesRadioButton->isChecked()) {
92 cmd += " volume";
93 }
94 if (volumeCombo->currentText() != tr("Any")) {
95 cmd += " volume=\"" + volumeCombo->currentText() + "\"";
96 }
97 if (clientCombo->currentText() != tr("Any")) {
98 cmd += " client=\"" + clientCombo->currentText() + "\"";
99 }
100 cmd += " yes";
101
102 if (mainWin->m_commandDebug) {
103 Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
104 }
105
106 consoleCommand(cmd);
107 m_console->notify(m_conn, true);
108 closeStackPage();
109 mainWin->resetFocus();
110 }
111
112
cancelButtonPushed()113 void prunePage::cancelButtonPushed()
114 {
115 mainWin->set_status(tr(" Canceled"));
116 this->hide();
117 m_console->notify(m_conn, true);
118 closeStackPage();
119 mainWin->resetFocus();
120 }
121
volumeChanged()122 void prunePage::volumeChanged()
123 {
124 if ((volumeCombo->currentText() == tr("Any")) && (clientCombo->currentText() == tr("Any"))) {
125 clientCombo->setCurrentIndex(1);
126 }
127 }
128
clientChanged()129 void prunePage::clientChanged()
130 {
131 if ((volumeCombo->currentText() == tr("Any")) && (clientCombo->currentText() == tr("Any"))) {
132 volumeCombo->setCurrentIndex(1);
133 }
134 }
135