]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/prune.cpp
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / qt-console / run / prune.cpp
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20  
21 /*
22  *  Run Dialog class
23  *
24  *   Kern Sibbald, February MMVII
25  *
26  *  $Id$
27  */ 
28
29 #include "bat.h"
30 #include "run.h"
31
32 /*
33  * Setup all the combo boxes and display the dialog
34  */
35 prunePage::prunePage(const QString &volume, const QString &client) : Pages()
36 {
37    QDateTime dt;
38
39    m_name = tr("Prune");
40    pgInitialize();
41    setupUi(this);
42    m_conn = m_console->notifyOff();
43
44    QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
45    if (mainWin->m_sqlDebug) {
46       Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
47    }
48    QStringList results, volumeList;
49    if (m_console->sql_cmd(query, results)) {
50       QString field;
51       QStringList fieldlist;
52       /* Iterate through the lines of results. */
53       foreach (QString resultline, results) {
54          fieldlist = resultline.split("\t");
55          volumeList.append(fieldlist[0]);
56       } /* foreach resultline */
57    } /* if results from query */
58
59    volumeCombo->addItem(tr("Any"));
60    volumeCombo->addItems(volumeList);
61    clientCombo->addItem(tr("Any"));
62    clientCombo->addItems(m_console->client_list);
63    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
64    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
65    filesRadioButton->setChecked(true);
66    if (clientCombo->findText(client, Qt::MatchExactly) != -1)
67       clientCombo->setCurrentIndex(clientCombo->findText(client, Qt::MatchExactly));
68    else
69       clientCombo->setCurrentIndex(0);
70    if (volumeCombo->findText(volume, Qt::MatchExactly) != -1)
71       volumeCombo->setCurrentIndex(volumeCombo->findText(volume, Qt::MatchExactly));
72    else
73       volumeCombo->setCurrentIndex(0);
74    connect(volumeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(volumeChanged()));
75    connect(clientCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(clientChanged()));
76
77    dockPage();
78    setCurrent();
79    this->show();
80 }
81
82 void prunePage::okButtonPushed()
83 {
84    this->hide();
85    QString cmd("prune");
86    if (filesRadioButton->isChecked()) {
87       cmd += " files";
88    }
89    if (jobsRadioButton->isChecked()) {
90       cmd += " jobs";
91    }
92    if (filesRadioButton->isChecked()) {
93       cmd += " volume";
94    }
95    if (volumeCombo->currentText() != tr("Any")) {
96       cmd += " volume=\"" + volumeCombo->currentText() + "\"";
97    }
98    if (clientCombo->currentText() != tr("Any")) {
99       cmd += " client=\"" + clientCombo->currentText() + "\"";
100    }
101    cmd += " yes";
102
103    if (mainWin->m_commandDebug) {
104       Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
105    }
106
107    consoleCommand(cmd);
108    m_console->notify(m_conn, true);
109    closeStackPage();
110    mainWin->resetFocus();
111 }
112
113
114 void prunePage::cancelButtonPushed()
115 {
116    mainWin->set_status(tr(" Canceled"));
117    this->hide();
118    m_console->notify(m_conn, true);
119    closeStackPage();
120    mainWin->resetFocus();
121 }
122
123 void prunePage::volumeChanged()
124 {
125    if ((volumeCombo->currentText() == tr("Any")) && (clientCombo->currentText() == tr("Any"))) {
126       clientCombo->setCurrentIndex(1);
127    }
128 }
129
130 void prunePage::clientChanged()
131 {
132    if ((volumeCombo->currentText() == tr("Any")) && (clientCombo->currentText() == tr("Any"))) {
133       volumeCombo->setCurrentIndex(1);
134    }
135 }