libyui-qt-pkg  2.44.7
 All Classes Functions Variables Enumerations
YQPkgDiskUsageWarningDialog.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgDiskUsageWarningDialog.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  Textdomain "qt-pkg"
39 
40 /-*/
41 
42 #define YUILogComponent "qt-pkg"
43 #include "YUILog.h"
44 
45 #include <QApplication>
46 #include <QLabel>
47 #include <QLayout>
48 #include <QPushButton>
49 #include <QStyle>
50 #include <QBoxLayout>
51 
52 #include "YQPkgDiskUsageWarningDialog.h"
53 #include "YQPkgDiskUsageList.h"
54 #include "QY2LayoutUtils.h"
55 #include "YQUI.h"
56 #include "YQi18n.h"
57 
58 
59 #define SPACING 2 // between subwidgets
60 #define MARGIN 4 // around the widget
61 
62 
64  const QString & message,
65  int thresholdPercent,
66  const QString & acceptButtonLabel,
67  const QString & rejectButtonLabel )
68  : QDialog( parent )
69 {
70  // Dialog title
71  setWindowTitle( _( "Disk Space Warning" ) );
72 
73  // Enable dialog resizing even without window manager
74  setSizeGripEnabled( true );
75 
76  // Layout for the dialog ( can't simply insert a QVBox )
77 
78  QVBoxLayout * layout = new QVBoxLayout();
79  Q_CHECK_PTR( layout );
80  layout->setSpacing( SPACING );
81  layout->setMargin ( MARGIN );
82  setLayout(layout);
83 
84  // HBox for icon and message
85  QHBoxLayout * hbox = new QHBoxLayout();
86  Q_CHECK_PTR( hbox );
87  layout->addLayout( hbox );
88 
89 
90  // Icon
91 
92  //addHSpacing( hbox );
93  QLabel * iconLabel = new QLabel( this );
94  Q_CHECK_PTR( iconLabel );
95  hbox->addWidget(iconLabel);
96 #ifdef FIXME
97  iconLabel->setPixmap( QApplication::style().stylePixmap( QStyle::SP_MessageBoxWarning ) );
98 #endif
99  iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
100 
101  // Label for the message
102 
103  QLabel * label = new QLabel( message, this);
104  Q_CHECK_PTR( label );
105  hbox->addWidget(label);
106  label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
107  label->setTextFormat( Qt::RichText );
108  label->setWordWrap( true );
109 
110 
111  // Disk usage list
112 
113  YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
114  Q_CHECK_PTR( duList );
115  layout->addWidget( duList );
116 
117 
118  // Button box
119 
120  hbox = new QHBoxLayout();
121  Q_CHECK_PTR( hbox );
122  hbox->setSpacing( SPACING );
123  hbox->setMargin ( MARGIN );
124  layout->addLayout( hbox );
125 
126  //addHStretch( hbox );
127 
128 
129  // Accept button - usually "OK" or "Continue"
130 
131  QPushButton * button = new QPushButton( acceptButtonLabel, this );
132  Q_CHECK_PTR( button );
133  hbox->addWidget(button);
134 
135  connect( button, SIGNAL( clicked() ),
136  this, SLOT ( accept() ) );
137 
138  //addHStretch( hbox );
139 
140 
141  if ( ! rejectButtonLabel.isEmpty() )
142  {
143  // Reject button ( if desired ) - usually "Cancel"
144 
145  button = new QPushButton( rejectButtonLabel, this );
146  Q_CHECK_PTR( button );
147  hbox->addWidget(button);
148 
149  connect( button, SIGNAL( clicked() ),
150  this, SLOT ( reject() ) );
151 
152  //addHStretch( hbox );
153  }
154 
155  // If there is only one button, it's safe to make that one ( the accept
156  // button ) the default. If there are two, better be safe than sorry and
157  // make the reject button the default.
158 
159  button->setDefault( true );
160 }
161 
162 
163 bool
165  int thresholdPercent,
166  const QString & acceptButtonLabel,
167  const QString & rejectButtonLabel )
168 {
169  YQPkgDiskUsageWarningDialog dialog( 0,
170  message,
171  thresholdPercent,
172  acceptButtonLabel,
173  rejectButtonLabel );
174  YQUI::ui()->normalCursor();
175  dialog.exec();
176 
177  return dialog.result() == QDialog::Accepted;
178 }
179 
180 
181 
182 
183 #include "YQPkgDiskUsageWarningDialog.moc"
YQPkgDiskUsageWarningDialog(QWidget *parent, const QString &message, int thresholdPercent, const QString &acceptButtonLabel, const QString &rejectButtonLabel=QString::null)
Constructor: Creates a disk usage warning dialog with text 'message' on top, a list of partitions tha...
Warning dialog about partitions that are getting full or overflowing.
static bool diskUsageWarning(const QString &message, int thresholdPercent, const QString &acceptButtonLabel, const QString &rejectButtonLabel=QString::null)
Static convenience method: Post a disk usage warning with text 'message', a list of partitions that a...
List of disk usage of all attached partitions.