1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDiskUsageWarningDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
25 #include <qapplication.h>
29 #include <qpushbutton.h>
32 #include "YQPkgDiskUsageWarningDialog.h"
33 #include "YQPkgDiskUsageList.h"
34 #include "QY2LayoutUtils.h"
39 #define SPACING 2 // between subwidgets
40 #define MARGIN 4 // around the widget
43 YQPkgDiskUsageWarningDialog::YQPkgDiskUsageWarningDialog( QWidget * parent,
44 const QString & message,
46 const QString & acceptButtonLabel,
47 const QString & rejectButtonLabel )
51 setCaption( _( "Disk Space Warning" ) );
53 // Enable dialog resizing even without window manager
54 setSizeGripEnabled( true );
56 // Layout for the dialog ( can't simply insert a QVBox )
58 QVBoxLayout * layout = new QVBoxLayout( this, MARGIN, SPACING );
62 // HBox for icon and message
64 QHBox * hbox = new QHBox( this );
66 layout->addWidget( hbox );
72 QLabel * iconLabel = new QLabel( hbox );
73 CHECK_PTR( iconLabel );
74 iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxWarning ) );
75 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
78 // Label for the message
80 QLabel * label = new QLabel( message, hbox );
82 label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
87 YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
90 layout->addWidget( duList );
95 hbox = new QHBox( this );
97 hbox->setSpacing( SPACING );
98 hbox->setMargin ( MARGIN );
99 layout->addWidget( hbox );
104 // Accept button - usually "OK" or "Continue"
106 QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
110 connect( button, SIGNAL( clicked() ),
111 this, SLOT ( accept() ) );
116 if ( ! rejectButtonLabel.isEmpty() )
118 // Reject button ( if desired ) - usually "Cancel"
120 button = new QPushButton( rejectButtonLabel, hbox );
123 connect( button, SIGNAL( clicked() ),
124 this, SLOT ( reject() ) );
129 // If there is only one button, it's safe to make that one ( the accept
130 // button ) the default. If there are two, better be safe than sorry and
131 // make the reject button the default.
133 button->setDefault( true );
138 YQPkgDiskUsageWarningDialog::diskUsageWarning( const QString & message,
139 int thresholdPercent,
140 const QString & acceptButtonLabel,
141 const QString & rejectButtonLabel )
143 YQPkgDiskUsageWarningDialog dialog( 0,
148 YQUI::ui()->normalCursor();
151 return dialog.result() == QDialog::Accepted;
157 #include "YQPkgDiskUsageWarningDialog.moc"