1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDiskUsageWarningDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
24 #include <QApplication>
27 #include <QPushButton>
31 #include "YQPkgDiskUsageWarningDialog.h"
32 #include "YQPkgDiskUsageList.h"
33 #include "QY2LayoutUtils.h"
38 #define SPACING 2 // between subwidgets
39 #define MARGIN 4 // around the widget
42 YQPkgDiskUsageWarningDialog::YQPkgDiskUsageWarningDialog( QWidget * parent,
43 const QString & message,
45 const QString & acceptButtonLabel,
46 const QString & rejectButtonLabel )
50 setWindowTitle( _( "Disk Space Warning" ) );
52 // Enable dialog resizing even without window manager
53 setSizeGripEnabled( true );
55 // Layout for the dialog ( can't simply insert a QVBox )
57 QVBoxLayout * layout = new QVBoxLayout( this );
58 layout->setSpacing( SPACING );
59 layout->setMargin ( MARGIN );
60 Q_CHECK_PTR( layout );
63 // HBox for icon and message
64 QHBoxLayout * hbox = new QHBoxLayout( this );
66 layout->addLayout( hbox );
71 //addHSpacing( hbox );
72 QLabel * iconLabel = new QLabel( this );
73 Q_CHECK_PTR( iconLabel );
74 hbox->addWidget(iconLabel);
76 iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxWarning ) );
78 iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
80 // Label for the message
82 QLabel * label = new QLabel( message, this);
84 hbox->addWidget(label);
85 label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
90 YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
91 Q_CHECK_PTR( duList );
93 layout->addWidget( duList );
98 hbox = new QHBoxLayout( this );
100 hbox->setSpacing( SPACING );
101 hbox->setMargin ( MARGIN );
102 layout->addLayout( hbox );
104 //addHStretch( hbox );
107 // Accept button - usually "OK" or "Continue"
109 QPushButton * button = new QPushButton( acceptButtonLabel, this );
110 Q_CHECK_PTR( button );
111 hbox->addWidget(button);
113 connect( button, SIGNAL( clicked() ),
114 this, SLOT ( accept() ) );
116 //addHStretch( hbox );
119 if ( ! rejectButtonLabel.isEmpty() )
121 // Reject button ( if desired ) - usually "Cancel"
123 button = new QPushButton( rejectButtonLabel, this );
124 Q_CHECK_PTR( button );
125 hbox->addWidget(button);
127 connect( button, SIGNAL( clicked() ),
128 this, SLOT ( reject() ) );
130 //addHStretch( hbox );
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"