2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
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 two of the GNU General Public
10 License as published by the Free Software Foundation plus additions
11 that are listed in the file LICENSE.
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.
18 You should have received a copy of the GNU 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
23 Bacula® is a registered trademark of John Walker.
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.
34 * Kern Sibbald, February MMVII
41 restoreDialog::restoreDialog(Console *console)
46 m_console->notify(false); /* this should already be off */
49 connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
50 this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
51 connect(upButton, SIGNAL(pressed()), this, SLOT(upButtonPushed()));
52 connect(markButton, SIGNAL(pressed()), this, SLOT(markButtonPushed()));
53 connect(unmarkButton, SIGNAL(pressed()), this, SLOT(unmarkButtonPushed()));
54 setFont(m_console->get_font());
55 m_console->displayToPrompt();
58 titles << "Mark" << "File" << "Mode" << "User" << "Group" << "Size" << "Date";
59 fileWidget->setHeaderLabels(titles);
67 * Fill the fileWidget box with the contents of the current directory
69 void restoreDialog::fillDirectory()
71 char modes[20], user[20], group[20], size[20], date[30];
74 POOLMEM *file = get_pool_memory(PM_FNAME);
75 POOLMEM *path = get_pool_memory(PM_FNAME);
78 m_console->write_dir("dir");
79 QList<QTreeWidgetItem *> items;
81 while (m_console->read() > 0) {
82 char *p = m_console->msg();
84 strip_trailing_junk(p);
85 if (*p == '$' || !*p) {
89 skip_nonspaces(&p); /* permissions */
91 bstrncpy(modes, l, sizeof(modes));
93 skip_nonspaces(&p); /* link count */
97 skip_nonspaces(&p); /* user */
100 bstrncpy(user, l, sizeof(user));
102 skip_nonspaces(&p); /* group */
104 bstrncpy(group, l, sizeof(group));
107 skip_nonspaces(&p); /* size */
109 bstrncpy(size, l, sizeof(size));
112 skip_nonspaces(&p); /* date/time */
116 bstrncpy(date, l, sizeof(date));
119 bstrncpy(marked, "*", sizeof(marked));
122 bstrncpy(marked, " ", sizeof(marked));
124 split_path_and_filename(p, &path, &pnl, &file, &fnl);
126 item << marked << file << modes << user << group << size << date;
127 QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item);
128 ti->setTextAlignment(5, Qt::AlignRight); /* right align size */
132 fileWidget->insertTopLevelItems(0, items);
134 free_pool_memory(file);
135 free_pool_memory(path);
138 void restoreDialog::accept()
141 m_console->write("done");
143 m_console->notify(true);
144 mainWin->resetFocus();
148 void restoreDialog::reject()
151 m_console->write("quit");
152 mainWin->set_status("Canceled");
154 m_console->notify(true);
155 mainWin->resetFocus();
158 void restoreDialog::fileDoubleClicked(QTreeWidgetItem *item, int column)
161 if (column == 0) { /* mark/unmark */
162 if (item->text(0) == "*") {
163 bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
164 item->setText(0, " ");
166 bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
167 item->setText(0, "*");
169 m_console->write_dir(cmd);
170 if (m_console->read() > 0) {
171 strip_trailing_junk(m_console->msg());
172 statusLine->setText(m_console->msg());
174 m_console->displayToPrompt();
178 * Double clicking other than column 0 means to decend into
179 * the directory -- or nothing if it is not a directory.
181 if (item->text(1).endsWith("/")) {
182 cwd(item->text(1).toUtf8().data());
187 void restoreDialog::upButtonPushed()
193 void restoreDialog::markButtonPushed()
195 QList<QTreeWidgetItem *> items = fileWidget->selectedItems();
196 QTreeWidgetItem *item;
198 foreach (item, items) {
199 bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
200 item->setText(0, "*");
201 m_console->write_dir(cmd);
202 if (m_console->read() > 0) {
203 strip_trailing_junk(m_console->msg());
204 statusLine->setText(m_console->msg());
206 Dmsg1(100, "cmd=%s\n", cmd);
207 m_console->discardToPrompt();
211 void restoreDialog::unmarkButtonPushed()
213 QList<QTreeWidgetItem *> items = fileWidget->selectedItems();
214 QTreeWidgetItem *item;
216 foreach (item, items) {
217 bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
218 item->setText(0, " ");
219 m_console->write_dir(cmd);
220 if (m_console->read() > 0) {
221 strip_trailing_junk(m_console->msg());
222 statusLine->setText(m_console->msg());
224 Dmsg1(100, "cmd=%s\n", cmd);
225 m_console->discardToPrompt();
230 * Change current working directory
232 bool restoreDialog::cwd(const char *dir)
235 char cd_cmd[MAXSTRING];
237 bsnprintf(cd_cmd, sizeof(cd_cmd), "cd \"%s\"", dir);
238 Dmsg2(100, "dir=%s cmd=%s\n", dir, cd_cmd);
239 m_console->write_dir(cd_cmd);
241 if ((stat = m_console->read()) > 0) {
242 m_cwd = m_console->msg();
243 lineEdit->insert(m_cwd);
244 Dmsg2(000, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
246 Dmsg1(000, "stat=%d\n", stat);
247 QMessageBox::critical(this, "Error", "cd command failed", QMessageBox::Ok);
249 m_console->discardToPrompt();
250 return true; /* ***FIXME*** return real status */
254 * Return cwd when in tree restore mode
256 char *restoreDialog::get_cwd()
259 m_console->write_dir(".pwd");
260 Dmsg0(100, "send: .pwd\n");
261 if ((stat = m_console->read()) > 0) {
262 m_cwd = m_console->msg();
263 Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
265 Dmsg1(000, "stat=%d\n", stat);
266 QMessageBox::critical(this, "Error", ".pwd command failed", QMessageBox::Ok);
267 Dmsg1(000, "stat=%d\n", stat);
269 m_console->discardToPrompt();
270 return m_cwd.toUtf8().data();