+ QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
+ thisitem->setIcon(0, QIcon(QString::fromUtf8(":images/browse.png")));
+ m_populated = false;
+ m_closeable = false;
+ m_current = NULL;
+ RestoreList->setAcceptDrops(true);
+}
+
+// Populate client table and job associated
+void bRestore::setClient()
+{
+ // Select the same client, don't touch
+ if (m_client == ClientList->currentText()) {
+ return;
+ }
+ m_client = ClientList->currentText();
+ FileList->clearContents();
+ FileRevisions->clearContents();
+ JobList->clear();
+ JobList->setEnabled(true);
+ LocationEntry->clear();
+ m_path = "";
+ m_pathid = 0;
+
+ if (ClientList->currentIndex() < 1) {
+ JobList->setEnabled(false);
+ return;
+ }
+
+ JobList->addItem("Job list for " + m_client);
+
+ QString jobQuery =
+ "SELECT Job.Jobid AS JobId, Job.StartTime AS StartTime,"
+ " Job.Level AS Level,"
+ " Job.Name AS Name"
+ " FROM Job JOIN Client USING (ClientId)"
+ " WHERE"
+ " Job.JobStatus IN ('T','W') AND Job.Type='B' AND"
+ " Client.Name='" + m_client + "' ORDER BY StartTime DESC" ;
+
+ QString job;
+ QStringList results;
+ QStringList fieldlist;
+ if (m_console->sql_cmd(jobQuery, results)) {
+ /* Iterate through the record returned from the query */
+ foreach (QString resultline, results) {
+ // 0 1 2 3
+ // JobId, StartTime, Level, Name
+ fieldlist = resultline.split("\t");
+ job = fieldlist[1] + " " + fieldlist[3] + "(" + fieldlist[2] + ") " + fieldlist[0];
+ JobList->addItem(job, QVariant(fieldlist[0])); // set also private value
+ }
+ }
+}
+
+// Compute job associated and update the job cache if needed
+void bRestore::setJob()
+{
+ if (JobList->currentIndex() < 1) {
+ FileList->clearContents();
+ FileList->setRowCount(0);
+ FileRevisions->clearContents();
+ FileRevisions->setRowCount(0);
+ return ;
+ }
+ QStringList results;
+ QVariant tmp = JobList->itemData(JobList->currentIndex(), Qt::UserRole);
+
+ m_jobids = tmp.toString();
+ QString cmd = ".bvfs_get_jobids jobid=" + m_jobids;
+ if (MergeChk->checkState() == Qt::Checked) {
+ cmd.append(" all");
+ }
+
+ m_console->dir_cmd(cmd, results);
+
+ if (results.size() < 1) {
+ FileList->clearContents();
+ FileList->setRowCount(0);
+ FileRevisions->clearContents();
+ FileRevisions->setRowCount(0);
+ return;
+ }
+
+ // TODO: Can take some time if the job contains many dirs
+ m_jobids = results.at(0);
+ cmd = ".bvfs_update jobid=" + m_jobids;
+ m_console->dir_cmd(cmd, results);
+
+ Pmsg1(0, "jobids=%s\n", m_jobids.toLocal8Bit().constData());
+
+ displayFiles(m_pathid, QString(""));
+ Pmsg0(000, "update done\n");
+}
+
+extern int decode_stat(char *buf, struct stat *statp, int32_t *LinkFI);
+
+// refresh button with a filter or limit/offset change
+void bRestore::refreshView()
+{
+ displayFiles(m_pathid, m_path);
+}
+
+void bRestore::displayFiles(int64_t pathid, QString path)
+{
+ QString arg;
+ QStringList results;
+ QStringList fieldlist;
+ struct stat statp;
+ int32_t LinkFI;
+ int nb = 0;
+ int row = 0;
+ Freeze frz_lst(*FileList); /* disable updating*/
+ Freeze frz_rev(*FileRevisions); /* disable updating*/
+ FileList->clearContents();
+ FileRevisions->clearContents();
+ FileRevisions->setRowCount(0);
+
+ // If we provide pathid, use it (path can be altered by encoding conversion)
+ if (pathid > 0) {
+ arg = " pathid=" + QString().setNum(pathid);
+
+ // Choose .. update current path to parent dir
+ if (path == "..") {
+ if (m_path == "/") {
+ m_path = "";
+ } else {
+ m_path.remove(QRegExp("[^/]+/$"));
+ }
+
+ } else if (path == "/" && m_path == "") {
+ m_path += path;
+
+ } else if (path != "/" && path != ".") {
+ m_path += path;
+ }
+ } else {
+ m_path = path;
+ arg = " path=\"" + m_path + "\"";
+ }
+
+ // If a filter is set, add it to the current query
+ if (FilterEntry->text() != "") {
+ QString tmp = FilterEntry->text();
+ tmp.replace("\"", "."); // basic escape of "
+ arg += " pattern=\"" + tmp + "\"";
+ }
+
+ LocationEntry->setText(m_path);
+ QString offset = QString().setNum(Offset1Spin->value());
+ QString limit=QString().setNum(Offset2Spin->value() - Offset1Spin->value());
+ QString q = ".bvfs_lsdir jobid=" + m_jobids + arg
+ + " limit=" + limit + " offset=" + offset ;
+ if (mainWin->m_miscDebug) qDebug() << q;
+ if (m_console->dir_cmd(q, results)) {
+ nb = results.size();
+ FileList->setRowCount(nb);
+ foreach (QString resultline, results) {
+ int col=0;
+ //PathId, FilenameId, fileid, jobid, lstat, path
+ fieldlist = resultline.split("\t");
+ TableItemFormatter item(*FileList, row++);
+ item.setFileType(col++, QString("folder")); // folder or file
+ item.setTextFld(col++, fieldlist.at(5)); // path
+ decode_stat(fieldlist.at(4).toLocal8Bit().data(),
+ &statp, &LinkFI);
+ item.setBytesFld(col++, QString().setNum(statp.st_size));
+ item.setDateFld(col++, statp.st_mtime); // date
+ fieldlist.replace(3, m_jobids); // use current jobids selection
+ // keep original info on the first cel that is never empty
+ item.widget(1)->setData(Qt::UserRole, fieldlist.join("\t"));
+ }
+ }
+
+ results.clear();
+ q = ".bvfs_lsfiles jobid=" + m_jobids + arg
+ + " limit=" + limit + " offset=" + offset ;
+ if (m_console->dir_cmd(q, results)) {
+ FileList->setRowCount(results.size() + nb);
+ foreach (QString resultline, results) {
+ int col=1; // skip icon
+ //PathId, FilenameId, fileid, jobid, lstat, name
+ fieldlist = resultline.split("\t");
+ TableItemFormatter item(*FileList, row++);
+ item.setTextFld(col++, fieldlist.at(5)); // name
+ decode_stat(fieldlist.at(4).toLocal8Bit().data(),
+ &statp, &LinkFI);
+ item.setBytesFld(col++, QString().setNum(statp.st_size));
+ item.setDateFld(col++, statp.st_mtime);
+ // keep original info on the first cel that is never empty
+ item.widget(1)->setData(Qt::UserRole, fieldlist.join("\t")); // keep info
+ }
+ }
+ FileList->verticalHeader()->hide();
+ FileList->resizeColumnsToContents();
+ FileList->resizeRowsToContents();
+ FileList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+}
+
+void bRestore::PgSeltreeWidgetClicked()
+{
+ if(!m_populated) {
+ setupPage();
+ }
+ if (!isOnceDocked()) {
+ dockPage();
+ }
+}
+
+// Display all versions of a file for this client
+void bRestore::displayFileVersion(QString pathid, QString fnid,
+ QString client, QString filename)
+{
+ int row=0;
+ struct stat statp;
+ int32_t LinkFI;
+ Freeze frz_rev(*FileRevisions); /* disable updating*/
+ FileRevisions->clearContents();
+
+ QString q = ".bvfs_versions jobid=" + m_jobids +
+ " pathid=" + pathid +
+ " fnid=" + fnid +
+ " client=" + client;
+
+ if (VersionsChk->checkState() == Qt::Checked) {
+ q.append(" versions");
+ }
+
+ QStringList results;
+ QStringList fieldlist;
+ QString tmp;
+ if (m_console->dir_cmd(q, results)) {
+ FileRevisions->setRowCount(results.size());
+ foreach (QString resultline, results) {
+ int col=0;
+ // 0 1 2 3 4 5 6 7
+ //PathId, FilenameId, fileid, jobid, lstat, Md5, VolName, Inchanger
+ fieldlist = resultline.split("\t");
+ TableItemFormatter item(*FileRevisions, row++);
+ item.setInChanger(col++, fieldlist.at(7)); // inchanger
+ item.setTextFld(col++, fieldlist.at(6)); // Volume
+ item.setNumericFld(col++, fieldlist.at(3)); // JobId
+ decode_stat(fieldlist.at(4).toLocal8Bit().data(),
+ &statp, &LinkFI);
+ item.setBytesFld(col++, QString().setNum(statp.st_size)); // size
+ item.setDateFld(col++, statp.st_mtime); // date
+ item.setTextFld(col++, fieldlist.at(5)); // chksum
+
+ // Adjust the fieldlist for drag&drop
+ fieldlist.removeLast(); // inchanger
+ fieldlist.removeLast(); // volname
+ fieldlist.removeLast(); // md5
+ fieldlist << m_path + filename;
+
+ // keep original info on the first cel that is never empty
+ item.widget(1)->setData(Qt::UserRole, fieldlist.join("\t"));
+ }
+ }
+ FileRevisions->verticalHeader()->hide();
+ FileRevisions->resizeColumnsToContents();
+ FileRevisions->resizeRowsToContents();
+ FileRevisions->setEditTriggers(QAbstractItemView::NoEditTriggers);
+}
+
+void bRestore::showInfoForFile(QTableWidgetItem *widget)
+{
+ m_current = widget;
+ QTableWidgetItem *first = FileList->item(widget->row(), 1);
+ QStringList lst = first->data(Qt::UserRole).toString().split("\t");
+ if (lst.at(1) == "0") { // no filenameid, should be a path
+ displayFiles(lst.at(0).toLongLong(), lst.at(5));
+ } else {
+ displayFileVersion(lst.at(0), lst.at(1), m_client, lst.at(5));
+ }
+}
+
+void bRestore::applyLocation()
+{
+ displayFiles(0, LocationEntry->text());
+}
+
+void bRestore::clearVersions(QTableWidgetItem *item)
+{
+ if (item != m_current) {
+ FileRevisions->clearContents();
+ FileRevisions->setRowCount(0);
+ }
+ m_current = item ;
+}
+
+void bRestore::clearRestoreList()
+{
+ RestoreList->clearContents();
+ RestoreList->setRowCount(0);
+}
+
+void bRestore::runRestore()
+{
+ bRunRestore *r = new bRunRestore(this);
+ r->setVisible(true);
+}
+
+void bRestore::setupPage()
+{
+ ClientList->addItem("Client list");
+ ClientList->addItems(m_console->client_list);
+ connect(ClientList, SIGNAL(currentIndexChanged(int)), this, SLOT(setClient()));
+ connect(JobList, SIGNAL(currentIndexChanged(int)), this, SLOT(setJob()));
+ connect(FileList, SIGNAL(itemClicked(QTableWidgetItem*)),
+ this, SLOT(clearVersions(QTableWidgetItem *)));
+ connect(FileList, SIGNAL(itemDoubleClicked(QTableWidgetItem*)),
+ this, SLOT(showInfoForFile(QTableWidgetItem *)));
+ connect(LocationBp, SIGNAL(pressed()), this, SLOT(applyLocation()));
+ connect(MergeChk, SIGNAL(clicked()), this, SLOT(setJob()));
+ connect(ClearBp, SIGNAL(clicked()), this, SLOT(clearRestoreList()));
+ connect(RestoreBp, SIGNAL(clicked()), this, SLOT(runRestore()));
+ connect(FilterBp, SIGNAL(clicked()), this, SLOT(refreshView()));
+ m_populated = true;