]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/medialist/medialist.cpp
dhb I have the issue of m_medialist and m_brestore resolved. The only one
[bacula/bacula] / bacula / src / qt-console / medialist / medialist.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
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.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28  
29 /*
30  *   Version $Id: medialist.cpp 4230 2007-02-21 20:07:37Z kerns $
31  *
32  *  MediaList Class
33  *
34  *   Kern Sibbald, January MMVI
35  *
36  */ 
37
38 #include <QAbstractEventDispatcher>
39 #include "bat.h"
40 #include "medialist.h"
41 #include "mediaedit/mediaedit.h"
42 #include "joblist/joblist.h"
43 #include <QMenu>
44 //#include <QSize>
45
46 MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem *treeItem)
47 {
48    setupUi(this);
49    m_parent=parent;
50 //   AddTostack();
51    m_poollist = new QStringList();
52
53    m_treeWidget = treeWidget;   /* our Storage Tree Tree Widget */
54    m_console = console;
55    m_treeItem = treeItem;
56    createConnections();
57    m_popupmedia="";
58    m_populated=false;
59 }
60
61 void MediaList::populateTree()
62 {
63    int stat;
64    QTreeWidgetItem *mediatreeitem, *treeitem, *topItem;
65
66    m_treeWidget->clear();
67    m_treeWidget->setColumnCount(3);
68    topItem = new QTreeWidgetItem(m_treeWidget);
69    topItem->setText(0, "Pools");
70    topItem->setData(0, Qt::UserRole, 0);
71    topItem->setExpanded( true );
72    //topItem->setSizeHint(0,QSize(1050,50));
73
74    /* Start with a list of pools */
75    m_poollist->clear();
76    QString *scmd = new QString(".pools\n");
77    m_console->write_dir(scmd->toUtf8().data());
78    while ((stat=m_console->read()) > 0) {
79       m_poollist->append(m_console->msg());
80    }
81    for ( QStringList::Iterator poolitem = m_poollist->begin(); poolitem != m_poollist->end(); ++poolitem ) {
82       treeitem = new QTreeWidgetItem(topItem);
83       //m_console->setTreeItem(treeitem);
84       poolitem->replace(QRegExp("\n"), "");
85       treeitem->setText(0, poolitem->toUtf8().data());
86       treeitem->setData(0, Qt::UserRole, 1);
87       treeitem->setExpanded( true );
88
89       /* iterate through the media in the pool */
90       QString *mcmd = new QString("sqlquery\n");
91       m_console->write_dir(mcmd->toUtf8().data());
92       while ((stat=m_console->read()) > 0) { }
93       QString *mcmd2 = new QString("select m.volumename, m.mediaid, m.mediatype from media m, pool p where p.name = '");
94       mcmd2->append(*poolitem);
95       mcmd2->append("';\n");
96       m_console->write_dir(mcmd2->toUtf8().data());
97       QString *mediaread = new QString();
98       while ((stat=m_console->read()) > 0) {
99          *mediaread += m_console->msg();
100       }
101       m_console->discardToPrompt();
102       QStringList sqllinelist = mediaread->split("\n");
103       /* a regex todetermine if mediareadline is a line of interest. */
104       QRegExp regex("^\\|.*\\|$");
105       int recordcnter=0;
106       QStringList *headerlist = new QStringList();
107       /* Iterate through lines retuned */
108       for ( QStringList::Iterator mediareadline = sqllinelist.begin(); mediareadline != sqllinelist.end(); ++mediareadline ) {
109          if ( regex.indexIn(*mediareadline) >= 0 ){
110             QStringList recorditemlist = mediareadline->split("|");
111             int recorditemcnter=0;
112             /* Iterate through items in the record */
113             for ( QStringList::Iterator mediarecorditem = recorditemlist.begin(); mediarecorditem != recorditemlist.end(); ++mediarecorditem ) {
114                QString trimmeditem = mediarecorditem->trimmed();
115                if( trimmeditem != "" ){
116                   if ( recordcnter == 0 ){
117                      headerlist->append(trimmeditem);
118                   } else {
119                      if ( recorditemcnter == 0 ){
120                         mediatreeitem = new QTreeWidgetItem(treeitem);
121                      }
122                      mediatreeitem->setData(recorditemcnter, Qt::UserRole, 2);
123                      mediatreeitem->setText(recorditemcnter, trimmeditem.toUtf8().data());
124                   }
125                   recorditemcnter+=1;
126                }
127             }
128             recordcnter+=1;
129          }
130       }
131       m_treeWidget->setHeaderLabels(*headerlist);
132    }
133 }
134
135 void MediaList::createConnections()
136 {
137    connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
138                 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
139    connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
140                 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
141 }
142
143 void MediaList::treeItemClicked(QTreeWidgetItem *item, int column)
144 {
145    int treedepth = item->data(column, Qt::UserRole).toInt();
146    QString text = item->text(0);
147    switch (treedepth){
148       case 1:
149          break;
150       case 2:
151          /* Can't figure out how to make a right button do this --- Qt::LeftButton, Qt::RightButton, Qt::MidButton */
152          m_popupmedia = text;
153          QMenu *popup = new QMenu( m_treeWidget );
154          connect(popup->addAction("Edit Properties"), SIGNAL(triggered()), this, SLOT(editMedia()));
155          connect(popup->addAction("Show Jobs On Media"), SIGNAL(triggered()), this, SLOT(showJobs()));
156          popup->exec(QCursor::pos());
157    }
158 }
159
160 void MediaList::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
161 {
162    int treedepth = item->data(column, Qt::UserRole).toInt();
163    if (treedepth >= 0) {
164    }
165 }
166
167 void MediaList::editMedia()
168 {
169    MediaEdit* edit = new MediaEdit(m_console, m_popupmedia);
170    edit->show();
171 }
172
173 void MediaList::showJobs()
174 {
175    JobList* joblist = new JobList(m_console, m_popupmedia);
176    joblist->show();
177 }
178
179 void MediaList::PgSeltreeWidgetClicked()
180 {
181    printf("PgSeltreeWidgetClicked\n");
182    if( ! m_populated ){
183       populateTree();
184       m_populated=true;
185    }
186 }
187
188 void MediaList::PgSeltreeWidgetDoubleClicked()
189 {
190    printf("PgSeltreeWidgetDoubleClicked\n");
191    populateTree();
192 }