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