]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/restore/restore.cpp
Add smartctl call to bacula-sd.conf as an example of getting
[bacula/bacula] / bacula / src / qt-console / restore / restore.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2007 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 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.
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 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 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.
27 */
28  
29 /*
30  *   Version $Id$
31  *
32  *  Restore Class 
33  *
34  *   Kern Sibbald, February MMVI
35  *
36  */ 
37
38 #include "bat.h"
39 #include "restore.h"
40
41
42 prerestoreDialog::prerestoreDialog(Console *console)
43 {
44    m_console = console;               /* keep compiler quiet */
45    setupUi(this);
46    jobCombo->addItems(console->job_list);
47    filesetCombo->addItems(console->fileset_list);
48    clientCombo->addItems(console->client_list);
49    poolCombo->addItems(console->pool_list);
50    storageCombo->addItems(console->storage_list);
51    job_name_change(0);
52    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
53
54    this->show();
55 }
56
57 void prerestoreDialog::accept()
58 {
59    QString cmd;
60
61    this->hide();
62    
63    cmd = QString(
64          "restore select current fileset=\"%1\" client=\"%2\" pool=\"%3\" "
65              "storage=\"%4\"\n")
66              .arg(filesetCombo->currentText())
67              .arg(clientCombo->currentText())
68              .arg(poolCombo->currentText())
69              .arg(storageCombo->currentText());
70
71    m_console->write(cmd);
72    m_console->display_text(cmd);
73    new restoreDialog(m_console);
74    delete this;
75 }
76
77
78 void prerestoreDialog::reject()
79 {
80    mainWin->set_status("Canceled");
81    this->hide();
82    delete this;
83 }
84
85
86 void prerestoreDialog::job_name_change(int index)
87 {
88    job_defaults job_defs;
89
90    (void)index;
91    job_defs.job_name = jobCombo->currentText();
92    if (m_console->get_job_defaults(job_defs)) {
93       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
94       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
95       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
96       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
97    }
98 }
99
100 restoreDialog::restoreDialog(Console *console)
101 {
102    m_console = console;
103    setupUi(this);
104    connect(fileWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), 
105            this, SLOT(fileDoubleClicked(QTreeWidgetItem *, int)));
106    setFont(m_console->get_font());
107    fillDirectory("/home/kern/bacula/k");
108    this->show();
109 }
110
111 /*
112  * Fill the CList box with files at path
113  */
114 void restoreDialog::fillDirectory(const char *dir)
115 {
116    char pathbuf[MAXSTRING];
117    char modes[20], user[20], group[20], size[20], date[30];
118    char marked[10];
119    int pnl, fnl;
120    POOLMEM *file = get_pool_memory(PM_FNAME);
121    POOLMEM *path = get_pool_memory(PM_FNAME);
122
123    m_console->setEnabled(false);
124    m_fname = dir;
125
126
127    m_console->displayToPrompt();
128    bsnprintf(pathbuf, sizeof(pathbuf), "cd %s", dir);
129    Dmsg1(100, "%s\n", pathbuf);
130
131    QStringList titles;
132    titles << "Mark" << "File" << "Mode" << "User" << "Group" << "Size" << "Date";
133    fileWidget->setHeaderLabels(titles);
134
135    m_console->write(pathbuf);
136    m_console->display_text(pathbuf);
137    m_console->displayToPrompt();
138
139    m_console-> write_dir("dir");
140    m_console->display_text("dir");
141
142    QList<QTreeWidgetItem *> items;
143    QStringList item;
144    while (m_console->read() > 0) {
145       char *p = m_console->msg();
146       char *l;
147       strip_trailing_junk(p);
148       if (*p == '$') {
149          break;
150       }
151       if (!*p) {
152          continue;
153       }
154       l = p;
155       skip_nonspaces(&p);             /* permissions */
156       *p++ = 0;
157       bstrncpy(modes, l, sizeof(modes));
158       skip_spaces(&p);
159       skip_nonspaces(&p);             /* link count */
160       *p++ = 0;
161       skip_spaces(&p);
162       l = p;
163       skip_nonspaces(&p);             /* user */
164       *p++ = 0;
165       skip_spaces(&p);
166       bstrncpy(user, l, sizeof(user));
167       l = p;
168       skip_nonspaces(&p);             /* group */
169       *p++ = 0;
170       bstrncpy(group, l, sizeof(group));
171       skip_spaces(&p);
172       l = p;
173       skip_nonspaces(&p);             /* size */
174       *p++ = 0;
175       bstrncpy(size, l, sizeof(size));
176       skip_spaces(&p);
177       l = p;
178       skip_nonspaces(&p);             /* date/time */
179       skip_spaces(&p);
180       skip_nonspaces(&p);
181       *p++ = 0;
182       bstrncpy(date, l, sizeof(date));
183       skip_spaces(&p);
184       if (*p == '*') {
185          bstrncpy(marked, "x", sizeof(marked));
186          p++;
187       } else {
188          bstrncpy(marked, " ", sizeof(marked));
189       }
190       split_path_and_filename(p, &path, &pnl, &file, &fnl);
191       item.clear();
192       item << "" << file << modes << user << group << size << date;
193       QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item);
194       ti->setTextAlignment(5, Qt::AlignRight); /* right align size */
195       items.append(ti);
196    }
197    fileWidget->clear();
198    fileWidget->insertTopLevelItems(0, items);
199
200    m_console->setEnabled(true);
201    free_pool_memory(file);
202    free_pool_memory(path);
203 }
204
205 void restoreDialog::accept()
206 {
207    this->hide();
208    m_console->write("done");
209    delete this;
210 }
211
212
213 void restoreDialog::reject()
214 {
215    this->hide();
216    m_console->write("quit");
217    mainWin->set_status("Canceled");
218    delete this;
219 }
220
221 void restoreDialog::fileDoubleClicked(QTreeWidgetItem *item, int column)
222 {
223    printf("Text=%s column=%d\n", item->text(1).toUtf8().data(), column);
224 }