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->setEnabled(false);
48 connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
49 this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
50 connect(upButton, SIGNAL(pressed()), this, SLOT(upButtonPushed()));
51 connect(markButton, SIGNAL(pressed()), this, SLOT(markButtonPushed()));
52 connect(unmarkButton, SIGNAL(pressed()), this, SLOT(unmarkButtonPushed()));
53 setFont(m_console->get_font());
54 m_console->displayToPrompt();
57 titles << "Mark" << "File" << "Mode" << "User" << "Group" << "Size" << "Date";
58 fileWidget->setHeaderLabels(titles);
66 * Fill the fileWidget box with the contents of the current directory
68 void restoreDialog::fillDirectory()
70 char modes[20], user[20], group[20], size[20], date[30];
73 POOLMEM *file = get_pool_memory(PM_FNAME);
74 POOLMEM *path = get_pool_memory(PM_FNAME);
77 m_console->write_dir("dir");
78 QList<QTreeWidgetItem *> items;
80 while (m_console->read() > 0) {
81 char *p = m_console->msg();
83 strip_trailing_junk(p);
84 if (*p == '$' || !*p) {
88 skip_nonspaces(&p); /* permissions */
90 bstrncpy(modes, l, sizeof(modes));
92 skip_nonspaces(&p); /* link count */
96 skip_nonspaces(&p); /* user */
99 bstrncpy(user, l, sizeof(user));
101 skip_nonspaces(&p); /* group */
103 bstrncpy(group, l, sizeof(group));
106 skip_nonspaces(&p); /* size */
108 bstrncpy(size, l, sizeof(size));
111 skip_nonspaces(&p); /* date/time */
115 bstrncpy(date, l, sizeof(date));
118 bstrncpy(marked, "*", sizeof(marked));
121 bstrncpy(marked, " ", sizeof(marked));
123 split_path_and_filename(p, &path, &pnl, &file, &fnl);
125 item << "" << file << modes << user << group << size << date;
126 QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item);
127 ti->setTextAlignment(5, Qt::AlignRight); /* right align size */
131 fileWidget->insertTopLevelItems(0, items);
133 free_pool_memory(file);
134 free_pool_memory(path);
137 void restoreDialog::accept()
140 m_console->write("done");
142 m_console->setEnabled(true);
143 mainWin->resetFocus();
147 void restoreDialog::reject()
150 m_console->write("quit");
151 mainWin->set_status("Canceled");
153 m_console->setEnabled(true);
154 mainWin->resetFocus();
157 void restoreDialog::fileDoubleClicked(QTreeWidgetItem *item, int column)
160 if (column == 0) { /* mark/unmark */
161 if (item->text(0) == "*") {
162 bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"\n", item->text(1).toUtf8().data());
163 item->setText(0, " ");
165 bsnprintf(cmd, sizeof(cmd), "mark \"%s\"\n", item->text(1).toUtf8().data());
166 item->setText(0, "*");
168 m_console->write(cmd);
169 m_console->displayToPrompt();
173 * Double clicking other than column 0 means to decend into
174 * the directory -- or nothing if it is not a directory.
176 if (item->text(1).endsWith("/")) {
177 cwd(item->text(1).toUtf8().data());
182 void restoreDialog::upButtonPushed()
188 void restoreDialog::markButtonPushed()
190 QList<QTreeWidgetItem *> items = fileWidget->selectedItems();
191 QTreeWidgetItem *item;
193 foreach (item, items) {
194 Dmsg1(000, "item=%s\n", item->text(1).toUtf8().data());
195 if (item->text(0) == " ") {
196 bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
197 item->setText(0, "*");
198 m_console->write(cmd);
199 Dmsg1(000, "cmd=%s\n", cmd);
200 m_console->displayToPrompt();
205 void restoreDialog::unmarkButtonPushed()
207 QList<QTreeWidgetItem *> items = fileWidget->selectedItems();
208 QTreeWidgetItem *item;
210 foreach (item, items) {
211 if (item->text(0) == "*") {
212 bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
213 item->setText(0, " ");
214 m_console->write(cmd);
215 Dmsg1(000, "cmd=%s\n", cmd);
216 m_console->displayToPrompt();
222 * Change current working directory
224 bool restoreDialog::cwd(const char *dir)
227 char cd_cmd[MAXSTRING];
229 bsnprintf(cd_cmd, sizeof(cd_cmd), "cd \"%s\"\n", dir);
230 Dmsg2(100, "dir=%s cmd=%s\n", dir, cd_cmd);
231 m_console->write_dir(cd_cmd);
232 if ((stat = m_console->read()) > 0) {
233 m_cwd = m_console->msg();
234 Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
236 Dmsg1(000, "stat=%d\n", stat);
238 m_console->discardToPrompt();
240 lineEdit->insert(m_cwd);
241 return true; /* ***FIXME*** return real status */
245 * Return cwd when in tree restore mode
247 char *restoreDialog::get_cwd()
250 m_console->write_dir(".pwd");
251 Dmsg0(100, "send: .pwd\n");
252 if ((stat = m_console->read()) > 0) {
253 m_cwd = m_console->msg();
254 Dmsg2(100, "cwd=%s msg=%s\n", m_cwd.toUtf8().data(), m_console->msg());
256 Dmsg1(000, "stat=%d\n", stat);
258 m_console->displayToPrompt();
259 return m_cwd.toUtf8().data();