]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/tray-monitor/restorewizard.cpp
Add restore wizard to the tray monitor.
[bacula/bacula] / bacula / src / qt-console / tray-monitor / restorewizard.cpp
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 #include "restorewizard.h"
20 #include "ui_restorewizard.h"
21 #include "filesmodel.h"
22 #include "task.h"
23 #include <QStandardItemModel>
24
25 RestoreWizard::RestoreWizard(RESMON *r, QWidget *parent) :
26     QWizard(parent),
27     res(r),
28     ui(new Ui::RestoreWizard),
29     jobs_model(new QStandardItemModel),
30     src_files_model(new FileSourceModel),
31     dest_files_model(new FileDestModel)
32 {
33     ui->setupUi(this);
34
35     connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(pageChanged(int)));
36
37     ui->RestWizBackupSelectPage->setModel(jobs_model);
38     ui->RestWiFileSelectionPage->setModels(src_files_model, dest_files_model);
39     connect(ui->RestWiFileSelectionPage, SIGNAL(currentFileChanged()), this, SLOT(fillFilePage()));
40     ui->RestWizAdvancedOptionsPage->setModel(dest_files_model);
41     ui->RestWizAdvancedOptionsPage->setResmon(res);
42
43 }
44
45 void RestoreWizard::pageChanged(int index)
46 {
47     switch(index) {
48     case RW_CLIENT_PAGE:
49         ui->RestWizClientPage->setClients(res->clients);
50         break;
51     case RW_JOB_PAGE:
52         fillJobPage();
53         break;
54     case RW_FILE_PAGE:
55         fillFilePage();
56         break;
57     case RW_ADVANCEDOPTIONS_PAGE:
58         fillOptionsPage();
59         break;
60     default:
61         qDebug( "pageChanged default: %d", index );
62         break;
63     }
64 }
65 RestoreWizard::~RestoreWizard()
66 {
67     delete ui;
68 }
69
70 void RestoreWizard::fillJobPage()
71 {
72     task *t = new task();
73     connect(t, SIGNAL(done(task*)), ui->RestWizBackupSelectPage, SLOT(optimizeSize()), Qt::QueuedConnection);
74     connect(t, SIGNAL(done(task*)), t, SLOT(deleteLater()));
75
76     t->init(res, TASK_LIST_CLIENT_JOBS);
77
78     int idx = field("currentClient").toInt();
79     char *p = (char*) res->clients->get(idx);
80     POOL_MEM info;
81     pm_strcpy(info, p);
82     t->arg = info.c_str();
83     t->model = jobs_model;
84     res->wrk->queue(t);
85 }
86
87 void RestoreWizard::fillFilePage()
88 {
89     task *t = new task();
90     connect(t, SIGNAL(done(task*)), t, SLOT(deleteLater()));
91
92     t->init(res, TASK_LIST_JOB_FILES);
93
94     const char *p = field("currentJob").toString().toUtf8();
95     POOL_MEM info;
96     pm_strcpy(info, p);
97     t->arg = info.c_str();
98
99     t->pathId = field("currentFile").toULongLong();
100     t->model = src_files_model;
101
102     res->wrk->queue(t);
103 }
104
105 void RestoreWizard::fillOptionsPage()
106 {
107     ui->RestWizAdvancedOptionsPage->setClients(res->clients);
108
109     task *t = new task();
110     connect(t, SIGNAL(done(task *)), ui->RestWizAdvancedOptionsPage, SLOT(fill_defaults(task *)), Qt::QueuedConnection);
111     connect(t, SIGNAL(done(task*)), t, SLOT(deleteLater()));
112
113     const char *p = "RestoreFile";/*field("currentJob").toString().toStdString().c_str();*/
114     POOL_MEM info;
115     pm_strcpy(info, p);
116     res->mutex->lock();
117     bfree_and_null(res->defaults.job);
118     res->defaults.job = bstrdup(info.c_str());
119     res->mutex->unlock();
120
121     t->init(res, TASK_DEFAULTS);
122     res->wrk->queue(t);
123 }