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  */
estimatePage()34 estimatePage::estimatePage() : Pages()
35 {
36    QDateTime dt;
37 
38    m_name = tr("Estimate");
39    pgInitialize();
40    setupUi(this);
41    m_conn = m_console->notifyOff();
42 
43    m_console->beginNewCommand(m_conn);
44    jobCombo->addItems(m_console->job_list);
45    filesetCombo->addItems(m_console->fileset_list);
46    levelCombo->addItems(m_console->level_list);
47    clientCombo->addItems(m_console->client_list);
48    job_name_change(0);
49    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
50    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
51    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
52    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
53    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/estimate-job.png")));
54 
55    dockPage();
56    setCurrent();
57    this->show();
58    m_aButtonPushed = false;
59 }
60 
okButtonPushed()61 void estimatePage::okButtonPushed()
62 {
63    if (m_aButtonPushed) return;
64    m_aButtonPushed = true;
65    this->hide();
66    QString cmd;
67    QTextStream(&cmd) << "estimate" <<
68       " job=\"" << jobCombo->currentText() << "\"" <<
69       " fileset=\"" << filesetCombo->currentText() << "\"" <<
70       " level=\"" << levelCombo->currentText() << "\"" <<
71       " client=\"" << clientCombo->currentText() << "\"";
72    if (listingCheckBox->checkState() == Qt::Checked) {
73       cmd += " listing";
74    }
75 
76    if (mainWin->m_commandDebug) {
77       Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
78    }
79 
80    consoleCommand(cmd, m_conn, true, true);
81    m_console->notify(m_conn, true);
82    closeStackPage();
83    mainWin->resetFocus();
84 }
85 
86 
cancelButtonPushed()87 void estimatePage::cancelButtonPushed()
88 {
89    if (m_aButtonPushed) return;
90    m_aButtonPushed = true;
91    mainWin->set_status(" Canceled");
92    this->hide();
93    m_console->notify(m_conn, true);
94    closeStackPage();
95    mainWin->resetFocus();
96 }
97 
98 /*
99  * Called here when the jobname combo box is changed.
100  *  We load the default values for the new job in the
101  *  other combo boxes.
102  */
job_name_change(int index)103 void estimatePage::job_name_change(int index)
104 {
105    job_defaults job_defs;
106 
107    (void)index;
108    job_defs.job_name = jobCombo->currentText();
109    if (m_console->get_job_defaults(m_conn, job_defs)) {
110       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
111       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
112       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
113    }
114 }
115