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(directoryWidget, SIGNAL(
52 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
53 this, SLOT(directoryItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
54 connect(upButton, SIGNAL(pressed()), this, SLOT(upButtonPushed()));
55 connect(markButton, SIGNAL(pressed()), this, SLOT(markButtonPushed()));
56 connect(unmarkButton, SIGNAL(pressed()), this, SLOT(unmarkButtonPushed()));
57 setFont(m_console->get_font());
58 m_console->displayToPrompt();
61 titles << "Mark" << "File" << "Mode" << "User" << "Group" << "Size" << "Date";
62 fileWidget->setHeaderLabels(titles);
70 * Fill the fileWidget box with the contents of the current directory
72 void restoreDialog::fillDirectory()
74 char modes[20], user[20], group[20], size[20], date[30];
77 POOLMEM *file = get_pool_memory(PM_FNAME);
78 POOLMEM *path = get_pool_memory(PM_FNAME);
81 m_console->write_dir("dir");
82 QList<QTreeWidgetItem *> treeItemList;
84 while (m_console->read() > 0) {
85 char *p = m_console->msg();
87 strip_trailing_junk(p);
88 if (*p == '$' || !*p) {
92 skip_nonspaces(&p); /* permissions */
94 bstrncpy(modes, l, sizeof(modes));
96 skip_nonspaces(&p); /* link count */
100 skip_nonspaces(&p); /* user */
103 bstrncpy(user, l, sizeof(user));
105 skip_nonspaces(&p); /* group */
107 bstrncpy(group, l, sizeof(group));
110 skip_nonspaces(&p); /* size */
112 bstrncpy(size, l, sizeof(size));
115 skip_nonspaces(&p); /* date/time */
119 bstrncpy(date, l, sizeof(date));
122 bstrncpy(marked, "*", sizeof(marked));
125 bstrncpy(marked, " ", sizeof(marked));
127 split_path_and_filename(p, &path, &pnl, &file, &fnl);
129 item << marked << file << modes << user << group << size << date;
130 if (item[1].endsWith("/")) {
131 addDirectory(item[1]);
133 QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item);
134 ti->setTextAlignment(5, Qt::AlignRight); /* right align size */
135 treeItemList.append(ti);
138 fileWidget->insertTopLevelItems(0, treeItemList);
139 for (int i=0; i<7; i++) {
140 fileWidget->resizeColumnToContents(i);
143 free_pool_memory(file);
144 free_pool_memory(path);
148 * Function called from fill directory when a directory is found to see if this
149 * directory exists in the directory pane and then add it to the directory pane
151 void restoreDialog::addDirectory(QString &newdir)
155 /* if this is the base dir, strip off the leading "/" */
159 fullpath = m_cwd + newdir;
161 /* is it already existent ?? */
162 if (!m_dirPaths.contains(fullpath)) {
163 QTreeWidgetItem *item = NULL;
164 if (m_dirPaths.empty()) {
165 /* this is the base widget */
166 item = new QTreeWidgetItem(directoryWidget);
167 item->setText(0, newdir.toUtf8().data());
169 QTreeWidgetItem *parent = m_dirPaths.value(m_cwd);
171 /* new directories to add */
172 item = new QTreeWidgetItem(parent);
173 item->setText(0, newdir.toUtf8().data());
174 directoryWidget->expandItem(parent);
177 /* insert into both forward and reverse hash */
178 m_dirPaths.insert(fullpath, item);
179 m_dirTreeItems.insert(item, fullpath);
184 * Executed when the tree item in the directory pane is changed. This will
185 * allow us to populate the file pane and make this the cwd.
187 void restoreDialog::directoryItemChanged(QTreeWidgetItem *currentitem,
188 QTreeWidgetItem * /*previousitem*/)
190 QString fullpath = m_dirTreeItems.value(currentitem);
192 cwd(fullpath.toUtf8().data());
197 void restoreDialog::accept()
200 m_console->write("done");
201 m_console->notify(true);
203 mainWin->resetFocus();
207 void restoreDialog::reject()
210 m_console->write("quit");
211 mainWin->set_status("Canceled");
213 m_console->notify(true);
214 mainWin->resetFocus();
217 void restoreDialog::fileDoubleClicked(QTreeWidgetItem *item, int column)
220 if (column == 0) { /* mark/unmark */
221 if (item->text(0) == "*") {
222 bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
223 item->setText(0, " ");
225 bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
226 item->setText(0, "*");
228 m_console->write_dir(cmd);
229 if (m_console->read() > 0) {
230 strip_trailing_junk(m_console->msg());
231 statusLine->setText(m_console->msg());
233 m_console->displayToPrompt();
237 * Double clicking other than column 0 means to decend into
238 * the directory -- or nothing if it is not a directory.
240 if (item->text(1).endsWith("/")) {
241 QString fullpath = m_cwd + item->text(1);
242 QTreeWidgetItem *item = m_dirPaths.value(fullpath);
244 directoryWidget->setCurrentItem(item);
250 * If up button pushed, making the parent tree widget current will call fill
253 void restoreDialog::upButtonPushed()
256 QTreeWidgetItem *item = m_dirPaths.value(m_cwd);
258 directoryWidget->setCurrentItem(item);
263 * Mark selected items
265 void restoreDialog::markButtonPushed()
267 QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
268 QTreeWidgetItem *item;
270 foreach (item, treeItemList) {
271 bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
272 item->setText(0, "*");
273 m_console->write_dir(cmd);
274 if (m_console->read() > 0) {
275 strip_trailing_junk(m_console->msg());
276 statusLine->setText(m_console->msg());
278 Dmsg1(100, "cmd=%s\n", cmd);
279 m_console->discardToPrompt();
284 * Unmark selected items
286 void restoreDialog::unmarkButtonPushed()
288 QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems();
289 QTreeWidgetItem *item;
291 foreach (item, treeItemList) {
292 bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
293 item->setText(0, " ");
294 m_console->write_dir(cmd);
295 if (m_console->read() > 0) {
296 strip_trailing_junk(m_console->msg());
297 statusLine->setText(m_console->msg());
299 Dmsg1(100, "cmd=%s\n", cmd);
300 m_console->discardToPrompt();
305 * Change current working directory
307 bool restoreDialog::cwd(const char *dir)
310 char cd_cmd[MAXSTRING];
312 bsnprintf(cd_cmd, sizeof(cd_cmd), "cd \"%s\"", dir);
313 Dmsg2(100, "dir=%s cmd=%s\n", dir, cd_cmd);
314 m_console->write_dir(cd_cmd);
316 if ((stat = m_console->read()) > 0) {
317 m_cwd = m_console->msg();
318 lineEdit->insert(m_cwd);
319 Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
321 Dmsg1(000, "stat=%d\n", stat);
322 QMessageBox::critical(this, "Error", "cd command failed", QMessageBox::Ok);
324 m_console->discardToPrompt();
325 return true; /* ***FIXME*** return real status */
329 * Return cwd when in tree restore mode
331 char *restoreDialog::get_cwd()
334 m_console->write_dir(".pwd");
335 Dmsg0(100, "send: .pwd\n");
336 if ((stat = m_console->read()) > 0) {
337 m_cwd = m_console->msg();
338 Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
340 Dmsg1(000, "stat=%d\n", stat);
341 QMessageBox::critical(this, "Error", ".pwd command failed", QMessageBox::Ok);
342 Dmsg1(000, "stat=%d\n", stat);
344 m_console->discardToPrompt();
345 return m_cwd.toUtf8().data();