]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/select/select.cpp
Backport from BEE
[bacula/bacula] / bacula / src / qt-console / select / select.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from many
7    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    Bacula® is a registered trademark of Kern Sibbald.
15 */
16
17 /*
18  *  Select dialog class
19  *
20  *   Kern Sibbald, March MMVII
21  *
22  */
23
24 #include "bat.h"
25 #include "select.h"
26
27 /*
28  * Read the items for the selection
29  */
30 selectDialog::selectDialog(Console *console, int conn) : QDialog()
31 {
32    m_conn = conn;
33    QDateTime dt;
34    int stat;
35    QListWidgetItem *item;
36    int row = 0;
37
38    m_console = console;
39    m_console->notify(m_conn, false);
40    setupUi(this);
41    connect(listBox, SIGNAL(currentRowChanged(int)), this, SLOT(index_change(int)));
42    setAttribute(Qt::WA_DeleteOnClose);
43    m_console->read(m_conn);                 /* get title */
44    labelWidget->setText(m_console->msg(m_conn));
45    while ((stat=m_console->read(m_conn)) > 0) {
46       item = new QListWidgetItem;
47       item->setText(m_console->msg(m_conn));
48       listBox->insertItem(row++, item);
49    }
50    m_console->displayToPrompt(m_conn);
51    this->show();
52 }
53
54 void selectDialog::accept()
55 {
56    char cmd[100];
57
58    this->hide();
59    bsnprintf(cmd, sizeof(cmd), "%d", m_index+1);
60    m_console->write_dir(m_conn, cmd);
61    m_console->displayToPrompt(m_conn);
62    this->close();
63    mainWin->resetFocus();
64    m_console->displayToPrompt(m_conn);
65    m_console->notify(m_conn, true);
66 }
67
68
69 void selectDialog::reject()
70 {
71    this->hide();
72    mainWin->set_status(tr(" Canceled"));
73    this->close();
74    mainWin->resetFocus();
75    m_console->beginNewCommand(m_conn);
76    m_console->notify(m_conn, true);
77 }
78
79 /*
80  * Called here when the jobname combo box is changed.
81  *  We load the default values for the new job in the
82  *  other combo boxes.
83  */
84 void selectDialog::index_change(int index)
85 {
86    m_index = index;
87 }
88
89 /*
90  * Handle yesno PopUp when Bacula asks a yes/no question.
91  */
92 /*
93  * Read the items for the selection
94  */
95 yesnoPopUp::yesnoPopUp(Console *console, int conn)  : QDialog()
96 {
97    QMessageBox msgBox;
98
99    setAttribute(Qt::WA_DeleteOnClose);
100    console->read(conn);                 /* get yesno question */
101    msgBox.setWindowTitle(tr("Bat Question"));
102    msgBox.setText(console->msg(conn));
103    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
104    console->displayToPrompt(conn);
105    switch (msgBox.exec()) {
106    case QMessageBox::Yes:
107       console->write_dir(conn, "yes");
108       break;
109    case QMessageBox::No:
110       console->write_dir(conn, "no");
111       break;
112    }
113    console->displayToPrompt(conn);
114    mainWin->resetFocus();
115 }