]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDescriptionDialog.cc
more porting and make files use qt3support one by one
[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 QT3_SUPPORT 1
22
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
25
26 #include <qapplication.h>
27 #include <qdesktopwidget.h>
28 #include <q3hbox.h>
29 #include <qlabel.h>
30 #include <qlayout.h>
31 #include <qpushbutton.h>
32 #include <qsplitter.h>
33 #include <qstyle.h>
34 #include <q3valuelist.h>
35 //Added by qt3to4:
36 #include <q3boxlayout.h>
37
38 #include "YQPkgDescriptionDialog.h"
39 #include "YQPkgDescriptionView.h"
40 #include "YQPkgList.h"
41 #include "QY2LayoutUtils.h"
42 #include "YQi18n.h"
43 #include "YQUI.h"
44
45
46 #define SPACING                 2       // between subwidgets
47 #define MARGIN                  4       // around the widget
48
49
50 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
51     : QDialog( parent )
52 {
53     // Dialog title
54     setCaption( _( "Package Description" ) );
55
56     // Enable dialog resizing even without window manager
57     setSizeGripEnabled( true );
58
59     // Layout for the dialog (can't simply insert a QVBox)
60
61     Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
62     Q_CHECK_PTR( layout );
63
64
65     // VBox for splitter
66
67     QSplitter * splitter = new QSplitter( Qt::Vertical, this );
68     Q_CHECK_PTR( splitter );
69     layout->addWidget( splitter );
70     splitter->setMargin( MARGIN );
71
72
73     // Pkg list
74
75     _pkgList = new YQPkgList( splitter );
76     Q_CHECK_PTR( _pkgList );
77     _pkgList->resize( _pkgList->width(), 80 );
78
79
80     // Description view
81
82     _pkgDescription = new YQPkgDescriptionView( splitter );
83     Q_CHECK_PTR( _pkgDescription );
84     _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
85
86     connect( _pkgList,          SIGNAL( currentItemChanged    ( ZyppSel ) ),
87              _pkgDescription,   SLOT  ( showDetailsIfVisible( ZyppSel ) ) );
88
89
90     // Button box (to center the single button)
91
92     Q3HBox * hbox = new Q3HBox( this );
93     Q_CHECK_PTR( hbox );
94     hbox->setSpacing( SPACING );
95     hbox->setMargin ( MARGIN  );
96     layout->addWidget( hbox );
97
98     addHStretch( hbox );
99
100
101     // "OK" button
102
103     QPushButton * button = new QPushButton( _( "&OK" ), hbox );
104     Q_CHECK_PTR( button );
105     button->setDefault( true );
106
107     connect( button,    SIGNAL( clicked() ),
108              this,      SLOT  ( accept()  ) );
109
110     addHStretch( hbox );
111
112
113     filter( pkgName );
114 }
115
116
117 void
118 YQPkgDescriptionDialog::filter( const QString & qPkgName )
119 {
120     std::string pkgName( (const char *) qPkgName );
121     YQUI::ui()->busyCursor();
122     _pkgList->clear();
123
124
125     // Search for pkgs with that name
126
127     for ( ZyppPoolIterator it = zyppPkgBegin();
128           it != zyppPkgEnd();
129           ++it )
130     {
131         ZyppObj zyppObj = (*it)->theObj();
132
133         if ( zyppObj && zyppObj->name() == pkgName )
134             _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
135     }
136
137 #if FIXME
138     // Display description of the first pkg with that name
139
140     YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
141
142     if ( firstItem )
143         _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
144     else
145         _pkgDescription->clear();
146 #endif
147
148     YQUI::ui()->normalCursor();
149 }
150
151
152 bool
153 YQPkgDescriptionDialog::isEmpty() const
154 {
155 #if FIXME
156     return _pkgList->childCount() == 0;
157 #else
158     return true;
159 #endif
160 }
161
162
163 QSize
164 YQPkgDescriptionDialog::sizeHint() const
165 {
166     QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
167     QSize size = QDialog::sizeHint();
168     size = size.boundedTo( QSize( available.width(), available.height() ) );
169
170     return size;
171 }
172
173
174 void
175 YQPkgDescriptionDialog::showDescriptionDialog( const QString & pkgName )
176 {
177     YQPkgDescriptionDialog dialog( 0, pkgName );
178     dialog.exec();
179 }
180
181
182
183
184 #include "YQPkgDescriptionDialog.moc"