libyui-qt-pkg  2.45.27
YQPkgDescriptionDialog.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgDescriptionDialog.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #define YUILogComponent "qt-pkg"
43 #include "YUILog.h"
44 
45 #include <QApplication>
46 #include <QDesktopWidget>
47 #include <QHBoxLayout>
48 #include <QLabel>
49 #include <QPushButton>
50 #include <QSplitter>
51 #include <QStyle>
52 #include <QList>
53 #include <QBoxLayout>
54 
55 #include "YQPkgDescriptionDialog.h"
56 #include "YQPkgDescriptionView.h"
57 #include "YQPkgList.h"
58 #include "QY2LayoutUtils.h"
59 #include "YQi18n.h"
60 #include "YQUI.h"
61 #include "utf8.h"
62 
63 
64 #define SPACING 2 // between subwidgets
65 #define MARGIN 4 // around the widget
66 
67 
68 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
69  : QDialog( parent )
70 {
71  // Dialog title
72  setWindowTitle( _( "Package Description" ) );
73 
74  // Enable dialog resizing even without window manager
75  setSizeGripEnabled( true );
76 
77  // Layout for the dialog (can't simply insert a QVBox)
78 
79  QVBoxLayout * layout = new QVBoxLayout();
80  Q_CHECK_PTR( layout );
81  setLayout(layout);
82  layout->setMargin(MARGIN);
83  layout->setSpacing(SPACING);
84 
85 
86 
87  // VBox for splitter
88 
89  QSplitter * splitter = new QSplitter( Qt::Vertical, this );
90  Q_CHECK_PTR( splitter );
91  layout->addWidget( splitter );
92 
93  // Pkg list
94 
95  _pkgList = new YQPkgList( splitter );
96  Q_CHECK_PTR( _pkgList );
97  _pkgList->resize( _pkgList->width(), 80 );
98 
99 
100  // Description view
101 
102  _pkgDescription = new YQPkgDescriptionView( splitter );
103  Q_CHECK_PTR( _pkgDescription );
104  _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
105 
106  connect( _pkgList, SIGNAL( currentItemChanged ( ZyppSel ) ),
107  _pkgDescription, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
108 
109 
110  // Button box (to center the single button)
111 
112  QHBoxLayout * hbox = new QHBoxLayout();
113  Q_CHECK_PTR( hbox );
114  hbox->setSpacing( SPACING );
115  hbox->setMargin ( MARGIN );
116  layout->addLayout( hbox );
117 
118  // "OK" button
119 
120  QPushButton * button = new QPushButton( _( "&OK" ), this );
121  Q_CHECK_PTR( button );
122  hbox->addWidget(button);
123  button->setDefault( true );
124 
125  connect( button, SIGNAL( clicked() ),
126  this, SLOT ( accept() ) );
127 
128  hbox->addStretch();
129 
130 
131  filter( pkgName );
132 }
133 
134 
135 void
136 YQPkgDescriptionDialog::filter( const QString & qPkgName )
137 {
138  std::string pkgName( toUTF8( qPkgName ) );
139  YQUI::ui()->busyCursor();
140  _pkgList->clear();
141 
142 
143  // Search for pkgs with that name
144 
145  for ( ZyppPoolIterator it = zyppPkgBegin();
146  it != zyppPkgEnd();
147  ++it )
148  {
149  ZyppObj zyppObj = (*it)->theObj();
150 
151  if ( zyppObj && zyppObj->name() == pkgName )
152  _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
153  }
154 
155 #if FIXME
156  // Display description of the first pkg with that name
157 
158  YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
159 
160  if ( firstItem )
161  _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
162  else
163  _pkgDescription->clear();
164 #endif
165 
166  YQUI::ui()->normalCursor();
167 }
168 
169 
170 bool
172 {
173 #if FIXME
174  return _pkgList->childCount() == 0;
175 #else
176  return true;
177 #endif
178 }
179 
180 
181 QSize
183 {
184  QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
185  QSize size = QDialog::sizeHint();
186  size = size.boundedTo( QSize( available.width(), available.height() ) );
187 
188  return size;
189 }
190 
191 
192 void
194 {
195  YQPkgDescriptionDialog dialog( 0, pkgName );
196  dialog.exec();
197 }
198 
199 
200 
201 
Display the description of a ZyppObj derived object along with its name and summary.
YQPkgDescriptionDialog(QWidget *parent, const QString &pkgName)
Constructor: Creates a description dialog for all packages that match &#39;pkgName&#39;.
void addPkgItem(ZyppSel selectable, ZyppPkg zyppPkg)
Add a pkg to the list.
Definition: YQPkgList.cc:140
virtual QSize sizeHint() const
Returns the preferred size.
Display a list of zypp::Package objects.
Definition: YQPkgList.h:54
void clear()
Clears the tree-widgets content, resets the optimal column width values.
Definition: YQPkgList.cc:434
bool isEmpty() const
Returns &#39;true&#39; if the pkg list is empty.
void showDetailsIfVisible(ZyppSel selectable)
Show details for the specified package.
Pkg status and description as a standalone popup dialog.
ZyppSel selectable() const
Returns the original selectable within the package manager backend.
Definition: YQPkgObjList.h:454
static void showDescriptionDialog(const QString &pkgName)
Static convenience method: Post a description dialog for pkg &#39;pkgName&#39;.
void filter(const QString &pkgName)
Apply the filter criteria: Fill the pkg list with pkgs that match the specified package name...