]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDiskUsageWarningDialog.cc
restart qt4 porting
[duncan/yast2-qt4.git] / src / pkg / YQPkgDiskUsageWarningDialog.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgDiskUsageWarningDialog.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   Textdomain "packages-qt"
18
19 /-*/
20
21
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
24
25 #include <qapplication.h>
26 #include <qhbox.h>
27 #include <qlabel.h>
28 #include <qlayout.h>
29 #include <qpushbutton.h>
30 #include <qstyle.h>
31
32 #include "YQPkgDiskUsageWarningDialog.h"
33 #include "YQPkgDiskUsageList.h"
34 #include "QY2LayoutUtils.h"
35 #include "YQUI.h"
36 #include "YQi18n.h"
37
38
39 #define SPACING                 2       // between subwidgets
40 #define MARGIN                  4       // around the widget
41
42
43 YQPkgDiskUsageWarningDialog::YQPkgDiskUsageWarningDialog( QWidget *             parent,
44                                                           const QString &       message,
45                                                           int                   thresholdPercent,
46                                                           const QString &       acceptButtonLabel,
47                                                           const QString &       rejectButtonLabel )
48     : QDialog( parent )
49 {
50     // Dialog title
51     setCaption( _( "Disk Space Warning" ) );
52
53     // Enable dialog resizing even without window manager
54     setSizeGripEnabled( true );
55
56     // Layout for the dialog ( can't simply insert a QVBox )
57
58     QVBoxLayout * layout = new QVBoxLayout( this, MARGIN, SPACING );
59     CHECK_PTR( layout );
60
61
62     // HBox for icon and message
63
64     QHBox * hbox = new QHBox( this );
65     CHECK_PTR( hbox );
66     layout->addWidget( hbox );
67
68
69     // Icon
70
71     addHSpacing( 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
76     addHSpacing( hbox );
77
78     // Label for the message
79
80     QLabel * label = new QLabel( message, hbox );
81     CHECK_PTR( label );
82     label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
83
84
85     // Disk usage list
86
87     YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
88     CHECK_PTR( duList );
89
90     layout->addWidget( duList );
91
92
93     // Button box
94
95     hbox = new QHBox( this );
96     CHECK_PTR( hbox );
97     hbox->setSpacing( SPACING );
98     hbox->setMargin ( MARGIN  );
99     layout->addWidget( hbox );
100
101     addHStretch( hbox );
102
103
104     // Accept button - usually "OK" or "Continue"
105
106     QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
107     CHECK_PTR( button );
108
109
110     connect( button,    SIGNAL( clicked() ),
111              this,      SLOT  ( accept()  ) );
112
113     addHStretch( hbox );
114
115
116     if ( ! rejectButtonLabel.isEmpty() )
117     {
118         // Reject button ( if desired ) - usually "Cancel"
119
120         button = new QPushButton( rejectButtonLabel, hbox );
121         CHECK_PTR( button );
122
123         connect( button,        SIGNAL( clicked() ),
124                  this,          SLOT  ( reject()  ) );
125
126         addHStretch( hbox );
127     }
128
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.
132
133     button->setDefault( true );
134 }
135
136
137 bool
138 YQPkgDiskUsageWarningDialog::diskUsageWarning( const QString &  message,
139                                                int              thresholdPercent,
140                                                const QString &  acceptButtonLabel,
141                                                const QString &  rejectButtonLabel )
142 {
143     YQPkgDiskUsageWarningDialog dialog( 0,
144                                         message,
145                                         thresholdPercent,
146                                         acceptButtonLabel,
147                                         rejectButtonLabel );
148     YQUI::ui()->normalCursor();
149     dialog.exec();
150
151     return dialog.result() == QDialog::Accepted;
152 }
153
154
155
156
157 #include "YQPkgDiskUsageWarningDialog.moc"