]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/run.cpp
Center bat run window on screen
[bacula/bacula] / bacula / src / qt-console / run / run.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
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28  
29 /*
30  *  Run Dialog class
31  *
32  *   Kern Sibbald, February MMVII
33  *
34  */ 
35
36 #include "bat.h"
37 #include "run.h"
38
39
40 runPage::runPage()
41 {
42    init();
43    show();
44 }
45
46 runPage::runPage(const QString &defJob)
47 {
48    m_dockOnFirstUse = false;
49    init();
50    if (defJob != "")
51       jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
52    show();
53 }
54
55
56 runPage::runPage(const QString &defJob, const QString &level, 
57                  const QString &pool, const QString &storage,
58                  const QString &client, const QString &fileset)
59 {
60    m_dockOnFirstUse = false;
61    init();
62    jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
63    job_name_change(0);
64    filesetCombo->setCurrentIndex(filesetCombo->findText(fileset,
65                                                         Qt::MatchExactly));
66    levelCombo->setCurrentIndex(levelCombo->findText(level, Qt::MatchExactly));
67    clientCombo->setCurrentIndex(clientCombo->findText(client,Qt::MatchExactly));
68    poolCombo->setCurrentIndex(poolCombo->findText(pool, Qt::MatchExactly));
69
70    if (storage != "") {         // TODO: enable storage
71       storageCombo->setCurrentIndex(storageCombo->findText(storage, 
72                                                            Qt::MatchExactly));
73    }
74    show();
75 }
76
77
78 /*
79  * Setup all the combo boxes and display the dialog
80  */
81 void runPage::init()
82 {
83    QDateTime dt;
84    QDesktopWidget *desk = QApplication::desktop(); 
85    QRect scrn;
86
87    m_name = tr("Run");
88    pgInitialize();
89    setupUi(this);
90    /* Get screen rectangle */
91    scrn = desk->screenGeometry(desk->primaryScreen());
92    /* Position this window in the middle of the screen */
93    this->move((scrn.width()-this->width())/2, (scrn.height()-this->height())/2);
94    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
95    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
96    m_conn = m_console->notifyOff();
97
98    m_console->beginNewCommand(m_conn);
99    jobCombo->addItems(m_console->job_list);
100    filesetCombo->addItems(m_console->fileset_list);
101    levelCombo->addItems(m_console->level_list);
102    clientCombo->addItems(m_console->client_list);
103    poolCombo->addItems(m_console->pool_list);
104    storageCombo->addItems(m_console->storage_list);
105    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
106    dateTimeEdit->setDateTime(dt.currentDateTime());
107    /*printf("listing messages resources");  ***FIME ***
108    foreach(QString mes, m_console->messages_list) {
109       printf("%s\n", mes.toUtf8().data());
110    }*/
111    messagesCombo->addItems(m_console->messages_list);
112    messagesCombo->setEnabled(false);
113    job_name_change(0);
114    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
115    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
116    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
117
118    // find a way to place the new window at the cursor position
119    // or in the middle of the page
120 //   dockPage();
121    setCurrent();
122 }
123
124 void runPage::okButtonPushed()
125 {
126    this->hide();
127    QString cmd;
128    QTextStream(&cmd) << "run" << 
129       " job=\"" << jobCombo->currentText() << "\"" <<
130       " fileset=\"" << filesetCombo->currentText() << "\"" <<
131       " level=\"" << levelCombo->currentText() << "\"" <<
132       " client=\"" << clientCombo->currentText() << "\"" <<
133       " pool=\"" << poolCombo->currentText() << "\"" <<
134       " storage=\"" << storageCombo->currentText() << "\"" <<
135       " priority=\"" << prioritySpin->value() << "\""
136       " when=\"" << dateTimeEdit->dateTime().toString(mainWin->m_dtformat) << "\"";
137 #ifdef xxx
138       " messages=\"" << messagesCombo->currentText() << "\"";
139      /* FIXME when there is an option to modify the messages resoruce associated
140       * with a  job */
141 #endif
142    if (bootstrap->text() != "") {
143       cmd += " bootstrap=\"" + bootstrap->text() + "\""; 
144    }
145    cmd += " yes";
146
147    if (mainWin->m_commandDebug) {
148       Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
149    }
150
151    consoleCommand(cmd);
152    m_console->notify(m_conn, true);
153    closeStackPage();
154    mainWin->resetFocus();
155 }
156
157
158 void runPage::cancelButtonPushed()
159 {
160    mainWin->set_status(tr(" Canceled"));
161    this->hide();
162    m_console->notify(m_conn, true);
163    closeStackPage();
164    mainWin->resetFocus();
165 }
166
167 /*
168  * Called here when the jobname combo box is changed.
169  *  We load the default values for the new job in the
170  *  other combo boxes.
171  */
172 void runPage::job_name_change(int index)
173 {
174    job_defaults job_defs;
175
176    (void)index;
177    job_defs.job_name = jobCombo->currentText();
178    if (m_console->get_job_defaults(job_defs)) {
179       typeLabel->setText("<H3>"+job_defs.type+"</H3>");
180       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
181       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
182       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
183       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
184       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
185       messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
186    }
187 }