]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgDiskUsageWarningDialog.cc
restoring the green - do not set the style by default though
[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 #define QT3_SUPPORT 1
22
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
25
26 #include <qapplication.h>
27 #include <q3hbox.h>
28 #include <qlabel.h>
29 #include <qlayout.h>
30 #include <qpushbutton.h>
31 #include <qstyle.h>
32 //Added by qt3to4:
33 #include <q3boxlayout.h>
34
35 #include "YQPkgDiskUsageWarningDialog.h"
36 #include "YQPkgDiskUsageList.h"
37 #include "QY2LayoutUtils.h"
38 #include "YQUI.h"
39 #include "YQi18n.h"
40
41
42 #define SPACING                 2       // between subwidgets
43 #define MARGIN                  4       // around the widget
44
45
46 YQPkgDiskUsageWarningDialog::YQPkgDiskUsageWarningDialog( QWidget *             parent,
47                                                           const QString &       message,
48                                                           int                   thresholdPercent,
49                                                           const QString &       acceptButtonLabel,
50                                                           const QString &       rejectButtonLabel )
51     : QDialog( parent )
52 {
53     // Dialog title
54     setCaption( _( "Disk Space Warning" ) );
55
56     // Enable dialog resizing even without window manager
57     setSizeGripEnabled( true );
58
59     // Layout for the dialog ( can't simply insert a QVBox )
60
61     Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
62     Q_CHECK_PTR( layout );
63
64
65     // HBox for icon and message
66
67     Q3HBox * hbox = new Q3HBox( this );
68     Q_CHECK_PTR( hbox );
69     layout->addWidget( hbox );
70
71
72     // Icon
73
74     addHSpacing( hbox );
75     QLabel * iconLabel = new QLabel( hbox );
76     Q_CHECK_PTR( iconLabel );
77 #ifdef FIXME
78     iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxWarning ) );
79 #endif
80     iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
81     addHSpacing( hbox );
82
83     // Label for the message
84
85     QLabel * label = new QLabel( message, hbox );
86     Q_CHECK_PTR( label );
87     label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
88
89
90     // Disk usage list
91
92     YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
93     Q_CHECK_PTR( duList );
94
95     layout->addWidget( duList );
96
97
98     // Button box
99
100     hbox = new Q3HBox( this );
101     Q_CHECK_PTR( hbox );
102     hbox->setSpacing( SPACING );
103     hbox->setMargin ( MARGIN  );
104     layout->addWidget( hbox );
105
106     addHStretch( hbox );
107
108
109     // Accept button - usually "OK" or "Continue"
110
111     QPushButton * button = new QPushButton( acceptButtonLabel, hbox );
112     Q_CHECK_PTR( button );
113
114
115     connect( button,    SIGNAL( clicked() ),
116              this,      SLOT  ( accept()  ) );
117
118     addHStretch( hbox );
119
120
121     if ( ! rejectButtonLabel.isEmpty() )
122     {
123         // Reject button ( if desired ) - usually "Cancel"
124
125         button = new QPushButton( rejectButtonLabel, hbox );
126         Q_CHECK_PTR( button );
127
128         connect( button,        SIGNAL( clicked() ),
129                  this,          SLOT  ( reject()  ) );
130
131         addHStretch( hbox );
132     }
133
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.
137
138     button->setDefault( true );
139 }
140
141
142 bool
143 YQPkgDiskUsageWarningDialog::diskUsageWarning( const QString &  message,
144                                                int              thresholdPercent,
145                                                const QString &  acceptButtonLabel,
146                                                const QString &  rejectButtonLabel )
147 {
148     YQPkgDiskUsageWarningDialog dialog( 0,
149                                         message,
150                                         thresholdPercent,
151                                         acceptButtonLabel,
152                                         rejectButtonLabel );
153     YQUI::ui()->normalCursor();
154     dialog.exec();
155
156     return dialog.result() == QDialog::Accepted;
157 }
158
159
160
161
162 #include "YQPkgDiskUsageWarningDialog.moc"