1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDiskUsageWarningDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
26 #include <qapplication.h>
30 #include <qpushbutton.h>
33 #include <q3boxlayout.h>
35 #include "YQPkgDiskUsageWarningDialog.h"
36 #include "YQPkgDiskUsageList.h"
37 #include "QY2LayoutUtils.h"
42 #define SPACING 2 // between subwidgets
43 #define MARGIN 4 // around the widget
46 YQPkgDiskUsageWarningDialog::YQPkgDiskUsageWarningDialog( QWidget * parent,
47 const QString & message,
49 const QString & acceptButtonLabel,
50 const QString & rejectButtonLabel )
54 setCaption( _( "Disk Space Warning" ) );
56 // Enable dialog resizing even without window manager
57 setSizeGripEnabled( true );
59 // Layout for the dialog ( can't simply insert a QVBox )
61 Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
62 Q_CHECK_PTR( layout );
65 // HBox for icon and message
67 Q3HBox * hbox = new Q3HBox( this );
69 layout->addWidget( hbox );
75 QLabel * iconLabel = new QLabel( hbox );
76 Q_CHECK_PTR( iconLabel );
78 iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxWarning ) );
80 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
83 // Label for the message
85 QLabel * label = new QLabel( message, hbox );
87 label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
92 YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
93 Q_CHECK_PTR( duList );
95 layout->addWidget( duList );
100 hbox = new Q3HBox( this );
102 hbox->setSpacing( SPACING );
103 hbox->setMargin ( MARGIN );
104 layout->addWidget( hbox );
109 // Accept button - usually "OK" or "Continue"
111 QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
112 Q_CHECK_PTR( button );
115 connect( button, SIGNAL( clicked() ),
116 this, SLOT ( accept() ) );
121 if ( ! rejectButtonLabel.isEmpty() )
123 // Reject button ( if desired ) - usually "Cancel"
125 button = new QPushButton( rejectButtonLabel, hbox );
126 Q_CHECK_PTR( button );
128 connect( button, SIGNAL( clicked() ),
129 this, SLOT ( reject() ) );
134 // If there is only one button, it's safe to make that one ( the accept
135 // button ) the default. If there are two, better be safe than sorry and
136 // make the reject button the default.
138 button->setDefault( true );
143 YQPkgDiskUsageWarningDialog::diskUsageWarning( const QString & message,
144 int thresholdPercent,
145 const QString & acceptButtonLabel,
146 const QString & rejectButtonLabel )
148 YQPkgDiskUsageWarningDialog dialog( 0,
153 YQUI::ui()->normalCursor();
156 return dialog.result() == QDialog::Accepted;
162 #include "YQPkgDiskUsageWarningDialog.moc"