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 <q3boxlayout.h>
34 #include "YQPkgDiskUsageWarningDialog.h"
35 #include "YQPkgDiskUsageList.h"
36 #include "QY2LayoutUtils.h"
41 #define SPACING 2 // between subwidgets
42 #define MARGIN 4 // around the widget
45 YQPkgDiskUsageWarningDialog::YQPkgDiskUsageWarningDialog( QWidget * parent,
46 const QString & message,
48 const QString & acceptButtonLabel,
49 const QString & rejectButtonLabel )
53 setCaption( _( "Disk Space Warning" ) );
55 // Enable dialog resizing even without window manager
56 setSizeGripEnabled( true );
58 // Layout for the dialog ( can't simply insert a QVBox )
60 Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
61 Q_CHECK_PTR( layout );
64 // HBox for icon and message
66 Q3HBox * hbox = new Q3HBox( this );
68 layout->addWidget( hbox );
74 QLabel * iconLabel = new QLabel( hbox );
75 Q_CHECK_PTR( iconLabel );
77 iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxWarning ) );
79 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
82 // Label for the message
84 QLabel * label = new QLabel( message, hbox );
86 label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
91 YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
92 Q_CHECK_PTR( duList );
94 layout->addWidget( duList );
99 hbox = new Q3HBox( this );
101 hbox->setSpacing( SPACING );
102 hbox->setMargin ( MARGIN );
103 layout->addWidget( hbox );
108 // Accept button - usually "OK" or "Continue"
110 QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
111 Q_CHECK_PTR( button );
114 connect( button, SIGNAL( clicked() ),
115 this, SLOT ( accept() ) );
120 if ( ! rejectButtonLabel.isEmpty() )
122 // Reject button ( if desired ) - usually "Cancel"
124 button = new QPushButton( rejectButtonLabel, hbox );
125 Q_CHECK_PTR( button );
127 connect( button, SIGNAL( clicked() ),
128 this, SLOT ( reject() ) );
133 // If there is only one button, it's safe to make that one ( the accept
134 // button ) the default. If there are two, better be safe than sorry and
135 // make the reject button the default.
137 button->setDefault( true );
142 YQPkgDiskUsageWarningDialog::diskUsageWarning( const QString & message,
143 int thresholdPercent,
144 const QString & acceptButtonLabel,
145 const QString & rejectButtonLabel )
147 YQPkgDiskUsageWarningDialog dialog( 0,
152 YQUI::ui()->normalCursor();
155 return dialog.result() == QDialog::Accepted;
161 #include "YQPkgDiskUsageWarningDialog.moc"