]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDescriptionDialog.cc
restart qt4 porting
[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
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
24
25 #include <qapplication.h>
26 #include <qhbox.h>
27 #include <qlabel.h>
28 #include <qlayout.h>
29 #include <qpushbutton.h>
30 #include <qsplitter.h>
31 #include <qstyle.h>
32 #include <qvaluelist.h>
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     setCaption( _( "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, MARGIN, SPACING );
58     CHECK_PTR( layout );
59
60
61     // VBox for splitter
62
63     QSplitter * splitter = new QSplitter( QSplitter::Vertical, this );
64     CHECK_PTR( splitter );
65     layout->addWidget( splitter );
66     splitter->setMargin( MARGIN );
67
68
69     // Pkg list
70
71     _pkgList = new YQPkgList( splitter );
72     CHECK_PTR( _pkgList );
73     _pkgList->resize( _pkgList->width(), 80 );
74
75     
76     // Description view
77
78     _pkgDescription = new YQPkgDescriptionView( splitter );
79     CHECK_PTR( _pkgDescription );
80     _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
81
82     connect( _pkgList,          SIGNAL( selectionChanged    ( ZyppSel ) ),
83              _pkgDescription,   SLOT  ( showDetailsIfVisible( ZyppSel ) ) );
84
85
86     // Button box (to center the single button)
87
88     QHBox * hbox = new QHBox( this );
89     CHECK_PTR( hbox );
90     hbox->setSpacing( SPACING );
91     hbox->setMargin ( MARGIN  );
92     layout->addWidget( hbox );
93
94     addHStretch( hbox );
95
96
97     // "OK" button
98
99     QPushButton * button = new QPushButton( _( "&OK" ), hbox );
100     CHECK_PTR( button );
101     button->setDefault( true );
102
103     connect( button,    SIGNAL( clicked() ),
104              this,      SLOT  ( accept()  ) );
105
106     addHStretch( hbox );
107
108
109     filter( pkgName );
110 }
111
112
113 void
114 YQPkgDescriptionDialog::filter( const QString & qPkgName )
115 {
116     std::string pkgName( (const char *) qPkgName );
117     YQUI::ui()->busyCursor();
118     _pkgList->clear();
119
120
121     // Search for pkgs with that name
122
123     for ( ZyppPoolIterator it = zyppPkgBegin();
124           it != zyppPkgEnd();
125           ++it )
126     {
127         ZyppObj zyppObj = (*it)->theObj();
128
129         if ( zyppObj && zyppObj->name() == pkgName )
130             _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
131     }
132
133
134     // Display description of the first pkg with that name
135
136     YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
137
138     if ( firstItem )
139         _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
140     else
141         _pkgDescription->clear();
142
143     YQUI::ui()->normalCursor();
144 }
145
146
147 bool
148 YQPkgDescriptionDialog::isEmpty() const
149 {
150     return _pkgList->firstChild() == 0;
151 }
152
153
154 QSize
155 YQPkgDescriptionDialog::sizeHint() const
156 {
157     QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
158     QSize size = QDialog::sizeHint();
159     size = size.boundedTo( QSize( available.width(), available.height() ) );
160
161     return size;
162 }
163
164
165 void
166 YQPkgDescriptionDialog::showDescriptionDialog( const QString & pkgName )
167 {
168     YQPkgDescriptionDialog dialog( 0, pkgName );
169     dialog.exec();
170 }
171
172
173
174
175 #include "YQPkgDescriptionDialog.moc"