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)
51 m_poollist = new QStringList();
53 m_treeWidget = treeWidget; /* our medialist screen */
59 void MediaList::populateTree()
62 QTreeWidgetItem *mediatreeitem, *treeitem, *topItem;
64 m_treeWidget->clear();
65 m_treeWidget->setColumnCount(3);
66 topItem = new QTreeWidgetItem(m_treeWidget);
67 topItem->setText(0, "Pools");
68 topItem->setData(0, Qt::UserRole, 0);
69 topItem->setExpanded( true );
70 //topItem->setSizeHint(0,QSize(1050,50));
72 /* Start with a list of pools */
74 QString *scmd = new QString(".pools\n");
75 m_console->write_dir(scmd->toUtf8().data());
76 while ((stat=m_console->read()) > 0) {
77 m_poollist->append(m_console->msg());
79 for ( QStringList::Iterator poolitem = m_poollist->begin(); poolitem != m_poollist->end(); ++poolitem ) {
80 treeitem = new QTreeWidgetItem(topItem);
81 m_console->setTreeItem(treeitem);
82 poolitem->replace(QRegExp("\n"), "");
83 treeitem->setText(0, poolitem->toUtf8().data());
84 treeitem->setData(0, Qt::UserRole, 1);
85 treeitem->setExpanded( true );
87 /* iterate through the media in the pool */
88 QString *mcmd = new QString("sqlquery\n");
89 m_console->write_dir(mcmd->toUtf8().data());
90 while ((stat=m_console->read()) > 0) { }
91 QString *mcmd2 = new QString("select m.volumename, m.mediaid, m.mediatype from media m, pool p where p.name = '");
92 mcmd2->append(*poolitem);
93 mcmd2->append("';\n");
94 m_console->write_dir(mcmd2->toUtf8().data());
95 QString *mediaread = new QString();
96 while ((stat=m_console->read()) > 0) {
97 *mediaread += m_console->msg();
99 m_console->discardToPrompt();
100 QStringList sqllinelist = mediaread->split("\n");
101 /* a regex todetermine if mediareadline is a line of interest. */
102 QRegExp regex("^\\|.*\\|$");
104 QStringList *headerlist = new QStringList();
105 /* Iterate through lines retuned */
106 for ( QStringList::Iterator mediareadline = sqllinelist.begin(); mediareadline != sqllinelist.end(); ++mediareadline ) {
107 if ( regex.indexIn(*mediareadline) >= 0 ){
108 QStringList recorditemlist = mediareadline->split("|");
109 int recorditemcnter=0;
110 /* Iterate through items in the record */
111 for ( QStringList::Iterator mediarecorditem = recorditemlist.begin(); mediarecorditem != recorditemlist.end(); ++mediarecorditem ) {
112 QString trimmeditem = mediarecorditem->trimmed();
113 if( trimmeditem != "" ){
114 if ( recordcnter == 0 ){
115 headerlist->append(trimmeditem);
117 if ( recorditemcnter == 0 ){
118 mediatreeitem = new QTreeWidgetItem(treeitem);
120 mediatreeitem->setData(recorditemcnter, Qt::UserRole, 2);
121 mediatreeitem->setText(recorditemcnter, trimmeditem.toUtf8().data());
129 m_treeWidget->setHeaderLabels(*headerlist);
133 void MediaList::createConnections()
135 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
136 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
137 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
138 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
141 void MediaList::treeItemClicked(QTreeWidgetItem *item, int column)
143 int treedepth = item->data(column, Qt::UserRole).toInt();
144 QString text = item->text(0);
149 /* Can't figure out how to make a right button do this --- Qt::LeftButton, Qt::RightButton, Qt::MidButton */
151 QMenu *popup = new QMenu( m_treeWidget );
152 connect(popup->addAction("Edit Properties"), SIGNAL(triggered()), this, SLOT(editMedia()));
153 connect(popup->addAction("Show Jobs On Media"), SIGNAL(triggered()), this, SLOT(showJobs()));
154 popup->exec(QCursor::pos());
158 void MediaList::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
160 int treedepth = item->data(column, Qt::UserRole).toInt();
161 if (treedepth >= 0) {
165 void MediaList::editMedia()
167 MediaEdit* edit = new MediaEdit(m_console, m_popupmedia);
171 void MediaList::showJobs()
173 JobList* joblist = new JobList(m_console, m_popupmedia);