simplify build requires
[duncan/yast2-qt4.git] / src / pkg / YQPkgDescriptionDialog.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgDescriptionDialog.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
23
24 #include <QApplication>
25 #include <QDesktopWidget>
26 #include <QHBoxLayout>
27 #include <QLabel>
28 #include <QPushButton>
29 #include <QSplitter>
30 #include <QStyle>
31 #include <QList>
32 #include <QBoxLayout>
33
34 #include "YQPkgDescriptionDialog.h"
35 #include "YQPkgDescriptionView.h"
36 #include "YQPkgList.h"
37 #include "QY2LayoutUtils.h"
38 #include "YQi18n.h"
39 #include "YQUI.h"
40
41
42 #define SPACING                 2       // between subwidgets
43 #define MARGIN                  4       // around the widget
44
45
46 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
47     : QDialog( parent )
48 {
49     // Dialog title
50     setWindowTitle( _( "Package Description" ) );
51
52     // Enable dialog resizing even without window manager
53     setSizeGripEnabled( true );
54
55     // Layout for the dialog (can't simply insert a QVBox)
56
57     QVBoxLayout * layout = new QVBoxLayout( this );
58     layout->setMargin(MARGIN);
59     layout->setSpacing(SPACING);
60     Q_CHECK_PTR( layout );
61
62
63     // VBox for splitter
64
65     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
66     Q_CHECK_PTR( splitter );
67     layout->addWidget( splitter );
68
69     // Pkg list
70
71     _pkgList = new YQPkgList( splitter );
72     Q_CHECK_PTR( _pkgList );
73     _pkgList->resize( _pkgList->width(), 80 );
74
75
76     // Description view
77
78     _pkgDescription = new YQPkgDescriptionView( splitter );
79     Q_CHECK_PTR( _pkgDescription );
80     _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
81
82     connect( _pkgList,          SIGNAL( currentItemChanged    ( ZyppSel ) ),
83              _pkgDescription,   SLOT  ( showDetailsIfVisible( ZyppSel ) ) );
84
85
86     // Button box (to center the single button)
87
88     QHBoxLayout * hbox = new QHBoxLayout( this );
89     Q_CHECK_PTR( hbox );
90     hbox->setSpacing( SPACING );
91     hbox->setMargin ( MARGIN  );
92     layout->addLayout( hbox );
93
94     // "OK" button
95
96     QPushButton * button = new QPushButton( _( "&OK" ), this );
97     Q_CHECK_PTR( button );
98     hbox->addWidget(button);
99     button->setDefault( true );
100
101     connect( button,    SIGNAL( clicked() ),
102              this,      SLOT  ( accept()  ) );
103
104     hbox->addStretch();
105
106
107     filter( pkgName );
108 }
109
110
111 void
112 YQPkgDescriptionDialog::filter( const QString & qPkgName )
113 {
114     std::string pkgName( qPrintable(qPkgName) );
115     YQUI::ui()->busyCursor();
116     _pkgList->clear();
117
118
119     // Search for pkgs with that name
120
121     for ( ZyppPoolIterator it = zyppPkgBegin();
122           it != zyppPkgEnd();
123           ++it )
124     {
125         ZyppObj zyppObj = (*it)->theObj();
126
127         if ( zyppObj && zyppObj->name() == pkgName )
128             _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
129     }
130
131 #if FIXME
132     // Display description of the first pkg with that name
133
134     YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
135
136     if ( firstItem )
137         _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
138     else
139         _pkgDescription->clear();
140 #endif
141
142     YQUI::ui()->normalCursor();
143 }
144
145
146 bool
147 YQPkgDescriptionDialog::isEmpty() const
148 {
149 #if FIXME
150     return _pkgList->childCount() == 0;
151 #else
152     return true;
153 #endif
154 }
155
156
157 QSize
158 YQPkgDescriptionDialog::sizeHint() const
159 {
160     QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
161     QSize size = QDialog::sizeHint();
162     size = size.boundedTo( QSize( available.width(), available.height() ) );
163
164     return size;
165 }
166
167
168 void
169 YQPkgDescriptionDialog::showDescriptionDialog( const QString & pkgName )
170 {
171     YQPkgDescriptionDialog dialog( 0, pkgName );
172     dialog.exec();
173 }
174
175
176
177
178 #include "YQPkgDescriptionDialog.moc"