]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/run.cpp
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / qt-console / run / run.cpp
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2016 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  */ 
26
27 #include "bat.h"
28 #include "run.h"
29
30
31 runPage::runPage() : Pages()
32 {
33    init();
34    show();
35 }
36
37 runPage::runPage(const QString &defJob) : Pages()
38 {
39    m_dockOnFirstUse = false;
40    init();
41    if (defJob != "")
42       jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
43    show();
44 }
45
46
47 runPage::runPage(const QString &defJob, const QString &level, 
48                  const QString &pool, const QString &storage,
49                  const QString &client, const QString &fileset)
50    : Pages()
51 {
52    m_dockOnFirstUse = false;
53    init();
54    jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
55    job_name_change(0);
56    filesetCombo->setCurrentIndex(filesetCombo->findText(fileset,
57                                                         Qt::MatchExactly));
58    levelCombo->setCurrentIndex(levelCombo->findText(level, Qt::MatchExactly));
59    clientCombo->setCurrentIndex(clientCombo->findText(client,Qt::MatchExactly));
60    poolCombo->setCurrentIndex(poolCombo->findText(pool, Qt::MatchExactly));
61
62    if (storage != "") {         // TODO: enable storage
63       storageCombo->setCurrentIndex(storageCombo->findText(storage, 
64                                                            Qt::MatchExactly));
65    }
66    show();
67 }
68
69
70 /*
71  * Setup all the combo boxes and display the dialog
72  */
73 void runPage::init()
74 {
75    QDateTime dt;
76    QDesktopWidget *desk = QApplication::desktop(); 
77    QRect scrn;
78
79    m_name = tr("Run");
80    pgInitialize();
81    setupUi(this);
82    /* Get screen rectangle */
83    scrn = desk->screenGeometry(desk->primaryScreen());
84    /* Position this window in the middle of the screen */
85    this->move((scrn.width()-this->width())/2, (scrn.height()-this->height())/2);
86    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
87    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
88    m_conn = m_console->notifyOff();
89
90    m_console->beginNewCommand(m_conn);
91    jobCombo->addItems(m_console->job_list);
92    filesetCombo->addItems(m_console->fileset_list);
93    levelCombo->addItems(m_console->level_list);
94    clientCombo->addItems(m_console->client_list);
95    poolCombo->addItems(m_console->pool_list);
96    storageCombo->addItems(m_console->storage_list);
97    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
98    dateTimeEdit->setDateTime(dt.currentDateTime());
99    /*printf("listing messages resources");  ***FIME ***
100    foreach(QString mes, m_console->messages_list) {
101       printf("%s\n", mes.toUtf8().data());
102    }*/
103    messagesCombo->addItems(m_console->messages_list);
104    messagesCombo->setEnabled(false);
105    job_name_change(0);
106    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
107    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
108    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
109
110    // find a way to place the new window at the cursor position
111    // or in the middle of the page
112 //   dockPage();
113    setCurrent();
114 }
115
116 void runPage::okButtonPushed()
117 {
118    this->hide();
119    QString cmd;
120    QTextStream(&cmd) << "run" << 
121       " job=\"" << jobCombo->currentText() << "\"" <<
122       " fileset=\"" << filesetCombo->currentText() << "\"" <<
123       " level=\"" << levelCombo->currentText() << "\"" <<
124       " client=\"" << clientCombo->currentText() << "\"" <<
125       " pool=\"" << poolCombo->currentText() << "\"" <<
126       " storage=\"" << storageCombo->currentText() << "\"" <<
127       " priority=\"" << prioritySpin->value() << "\""
128       " when=\"" << dateTimeEdit->dateTime().toString(mainWin->m_dtformat) << "\"";
129 #ifdef xxx
130       " messages=\"" << messagesCombo->currentText() << "\"";
131      /* FIXME when there is an option to modify the messages resoruce associated
132       * with a  job */
133 #endif
134    if (bootstrap->text() != "") {
135       cmd += " bootstrap=\"" + bootstrap->text() + "\""; 
136    }
137    cmd += " yes";
138
139    if (mainWin->m_commandDebug) {
140       Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
141    }
142
143    consoleCommand(cmd);
144    m_console->notify(m_conn, true);
145    closeStackPage();
146    mainWin->resetFocus();
147 }
148
149
150 void runPage::cancelButtonPushed()
151 {
152    mainWin->set_status(tr(" Canceled"));
153    this->hide();
154    m_console->notify(m_conn, true);
155    closeStackPage();
156    mainWin->resetFocus();
157 }
158
159 /*
160  * Called here when the jobname combo box is changed.
161  *  We load the default values for the new job in the
162  *  other combo boxes.
163  */
164 void runPage::job_name_change(int index)
165 {
166    job_defaults job_defs;
167
168    (void)index;
169    job_defs.job_name = jobCombo->currentText();
170    if (m_console->get_job_defaults(job_defs)) {
171       QString cmd;
172       typeLabel->setText("<H3>"+job_defs.type+"</H3>");
173       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
174       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
175       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
176       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
177       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
178       messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
179       m_console->level_list.clear();
180       cmd = ".levels " + job_defs.type;
181       m_console->dir_cmd(cmd, m_console->level_list);
182       levelCombo->clear();
183       levelCombo->addItems(m_console->level_list);
184       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, 0 /*Qt::MatchExactly*/));
185    }
186 }