picking up branches/tmp/sh/qt4-port/, merging it with trunk
[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 <qdesktopwidget.h>
27 #include <q3hbox.h>
28 #include <qlabel.h>
29 #include <qlayout.h>
30 #include <qpushbutton.h>
31 #include <qsplitter.h>
32 #include <qstyle.h>
33 #include <q3valuelist.h>
34 //Added by qt3to4:
35 #include <q3boxlayout.h>
36
37 #include "YQPkgDescriptionDialog.h"
38 #include "YQPkgDescriptionView.h"
39 #include "YQPkgList.h"
40 #include "QY2LayoutUtils.h"
41 #include "YQi18n.h"
42 #include "YQUI.h"
43
44
45 #define SPACING                 2       // between subwidgets
46 #define MARGIN                  4       // around the widget
47
48
49 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
50     : QDialog( parent )
51 {
52     // Dialog title
53     setCaption( _( "Package Description" ) );
54
55     // Enable dialog resizing even without window manager
56     setSizeGripEnabled( true );
57
58     // Layout for the dialog (can't simply insert a QVBox)
59
60     Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
61     Q_CHECK_PTR( layout );
62
63
64     // VBox for splitter
65
66     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
67     Q_CHECK_PTR( splitter );
68     layout->addWidget( splitter );
69     splitter->setMargin( MARGIN );
70
71
72     // Pkg list
73
74     _pkgList = new YQPkgList( splitter );
75     Q_CHECK_PTR( _pkgList );
76     _pkgList->resize( _pkgList->width(), 80 );
77
78     
79     // Description view
80
81     _pkgDescription = new YQPkgDescriptionView( splitter );
82     Q_CHECK_PTR( _pkgDescription );
83     _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
84
85     connect( _pkgList,          SIGNAL( selectionChanged    ( ZyppSel ) ),
86              _pkgDescription,   SLOT  ( showDetailsIfVisible( ZyppSel ) ) );
87
88
89     // Button box (to center the single button)
90
91     Q3HBox * hbox = new Q3HBox( this );
92     Q_CHECK_PTR( hbox );
93     hbox->setSpacing( SPACING );
94     hbox->setMargin ( MARGIN  );
95     layout->addWidget( hbox );
96
97     addHStretch( hbox );
98
99
100     // "OK" button
101
102     QPushButton * button = new QPushButton( _( "&OK" ), hbox );
103     Q_CHECK_PTR( button );
104     button->setDefault( true );
105
106     connect( button,    SIGNAL( clicked() ),
107              this,      SLOT  ( accept()  ) );
108
109     addHStretch( hbox );
110
111
112     filter( pkgName );
113 }
114
115
116 void
117 YQPkgDescriptionDialog::filter( const QString & qPkgName )
118 {
119     std::string pkgName( (const char *) qPkgName );
120     YQUI::ui()->busyCursor();
121     _pkgList->clear();
122
123
124     // Search for pkgs with that name
125
126     for ( ZyppPoolIterator it = zyppPkgBegin();
127           it != zyppPkgEnd();
128           ++it )
129     {
130         ZyppObj zyppObj = (*it)->theObj();
131
132         if ( zyppObj && zyppObj->name() == pkgName )
133             _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
134     }
135
136
137     // Display description of the first pkg with that name
138
139     YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
140
141     if ( firstItem )
142         _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
143     else
144         _pkgDescription->clear();
145
146     YQUI::ui()->normalCursor();
147 }
148
149
150 bool
151 YQPkgDescriptionDialog::isEmpty() const
152 {
153     return _pkgList->firstChild() == 0;
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"