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"
41 #include "mediaedit/mediaedit.h"
42 #include "joblist/joblist.h"
46 MediaList::MediaList(QStackedWidget *parent, Console *console)
49 parent->addWidget(this);
50 poollist = new QStringList();
52 m_treeWidget = treeWidget; /* our medialist screen */
58 void MediaList::populateTree()
61 QTreeWidgetItem *mediatreeitem, *treeitem, *topItem;
63 m_treeWidget->clear();
64 m_treeWidget->setColumnCount(3);
65 topItem = new QTreeWidgetItem(m_treeWidget);
66 topItem->setText(0, "Pools");
67 topItem->setData(0, Qt::UserRole, 0);
68 topItem->setExpanded( true );
69 //topItem->setSizeHint(0,QSize(1050,50));
71 /* Start with a list of pools */
73 QString *scmd = new QString(".pools\n");
74 m_console->write_dir(scmd->toUtf8().data());
75 while ((stat=m_console->read()) > 0) {
76 poollist->append(m_console->msg());
78 for ( QStringList::Iterator poolitem = poollist->begin(); poolitem != poollist->end(); ++poolitem ) {
79 treeitem = new QTreeWidgetItem(topItem);
80 m_console->setTreeItem(treeitem);
81 poolitem->replace(QRegExp("\n"), "");
82 treeitem->setText(0, poolitem->toUtf8().data());
83 treeitem->setData(0, Qt::UserRole, 1);
84 treeitem->setExpanded( true );
86 /* iterate through the media in the pool */
87 QString *mcmd = new QString("sqlquery\n");
88 m_console->write_dir(mcmd->toUtf8().data());
89 while ((stat=m_console->read()) > 0) { }
90 QString *mcmd2 = new QString("select m.volumename, m.mediaid, m.mediatype from media m, pool p where p.name = '");
91 mcmd2->append(*poolitem);
92 mcmd2->append("';\n");
93 m_console->write_dir(mcmd2->toUtf8().data());
94 QString *mediaread = new QString();
95 while ((stat=m_console->read()) > 0) {
96 *mediaread += m_console->msg();
98 m_console->discardToPrompt();
99 QStringList sqllinelist = mediaread->split("\n");
100 /* a regex todetermine if mediareadline is a line of interest. */
101 QRegExp regex("^\\|.*\\|$");
103 QStringList *headerlist = new QStringList();
104 /* Iterate through lines retuned */
105 for ( QStringList::Iterator mediareadline = sqllinelist.begin(); mediareadline != sqllinelist.end(); ++mediareadline ) {
106 if ( regex.indexIn(*mediareadline) >= 0 ){
107 QStringList recorditemlist = mediareadline->split("|");
108 int recorditemcnter=0;
109 /* Iterate through items in the record */
110 for ( QStringList::Iterator mediarecorditem = recorditemlist.begin(); mediarecorditem != recorditemlist.end(); ++mediarecorditem ) {
111 QString trimmeditem = mediarecorditem->trimmed();
112 if( trimmeditem != "" ){
113 if ( recordcnter == 0 ){
114 headerlist->append(trimmeditem);
116 if ( recorditemcnter == 0 ){
117 mediatreeitem = new QTreeWidgetItem(treeitem);
119 mediatreeitem->setData(recorditemcnter, Qt::UserRole, 2);
120 mediatreeitem->setText(recorditemcnter, trimmeditem.toUtf8().data());
128 m_treeWidget->setHeaderLabels(*headerlist);
132 void MediaList::createConnections()
134 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
135 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
136 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
137 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
140 void MediaList::treeItemClicked(QTreeWidgetItem *item, int column)
142 int treedepth = item->data(column, Qt::UserRole).toInt();
143 QString text = item->text(0);
148 /* Can't figure out how to make a right button do this her Qt::LeftButton, Qt::RightButton, Qt::MidButton */
150 QMenu *popup = new QMenu( m_treeWidget );
151 connect(popup->addAction("Edit Properties"), SIGNAL(triggered()), this, SLOT(editMedia()));
152 connect(popup->addAction("Show Jobs On Media"), SIGNAL(triggered()), this, SLOT(showJobs()));
153 popup->exec(QCursor::pos());
157 void MediaList::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
159 int treedepth = item->data(column, Qt::UserRole).toInt();
160 if (treedepth >= 0) {
164 void MediaList::editMedia()
166 MediaEdit* edit = new MediaEdit(m_console, popupmedia);
170 void MediaList::showJobs()
172 JobList* joblist = new JobList(m_console, popupmedia);