2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-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.
30 * Version $Id: medialist.cpp 4230 2007-02-21 20:07:37Z kerns $
34 * Kern Sibbald, January MMVI
38 #include <QAbstractEventDispatcher>
40 #include "medialist.h"
42 MediaList::MediaList(QStackedWidget *parent)
45 parent->addWidget(this);
46 poollist = new QStringList();
48 m_treeWidget = treeWidget; /* our medialist screen */
51 void MediaList::DoDisplay(Console *console)
54 QTreeWidgetItem *mediatreeitem, *treeitem, *topItem;
58 m_treeWidget->clear();
59 m_treeWidget->setColumnCount(3);
60 topItem = new QTreeWidgetItem(m_treeWidget);
61 topItem->setText(0, "Pools");
63 /* Start with a list of pools */
65 QString *scmd = new QString(".pools\n");
66 m_console->write_dir(scmd->toUtf8().data());
67 while ((stat=m_console->read()) > 0) {
68 poollist->append(m_console->msg());
70 for ( QStringList::Iterator poolitem = poollist->begin(); poolitem != poollist->end(); ++poolitem ) {
71 treeitem = new QTreeWidgetItem(topItem);
72 m_console->setTreeItem(treeitem);
73 poolitem->replace(QRegExp("\n"), "");
74 treeitem->setText(0, poolitem->toUtf8().data());
76 /* iterate through the media in the pool */
77 QString *mcmd = new QString("sqlquery\n");
78 m_console->write_dir(mcmd->toUtf8().data());
79 while ((stat=m_console->read()) > 0) { }
80 QString *mcmd2 = new QString("select m.volumename, m.mediaid, m.mediatype from media m, pool p where p.name = '");
81 mcmd2->append(*poolitem);
82 mcmd2->append("';\n");
83 m_console->write_dir(mcmd2->toUtf8().data());
84 QString *mediaread = new QString();
85 while ((stat=m_console->read()) > 0) {
86 *mediaread += m_console->msg();
88 QStringList sqllinelist = mediaread->split("\n");
89 QRegExp regex("^\\|.*\\|$");
91 QStringList *headerlist = new QStringList();
92 /* Iterate through lines retuned */
93 for ( QStringList::Iterator mediareadline = sqllinelist.begin(); mediareadline != sqllinelist.end(); ++mediareadline ) {
94 if ( regex.indexIn(*mediareadline) >= 0 ){
95 QStringList recorditemlist = mediareadline->split("|");
96 int recorditemcnter=0;
97 /* Iterate through items in the record */
98 for ( QStringList::Iterator mediarecorditem = recorditemlist.begin(); mediarecorditem != recorditemlist.end(); ++mediarecorditem ) {
99 QString trimmeditem = mediarecorditem->trimmed();
100 if( trimmeditem != "" ){
101 if ( recordcnter == 0 ){
102 headerlist->append(trimmeditem);
104 if ( recorditemcnter == 0 ){
105 mediatreeitem = new QTreeWidgetItem(treeitem);
107 mediatreeitem->setText(recorditemcnter, trimmeditem.toUtf8().data());
115 m_treeWidget->setHeaderLabels(*headerlist);