libyui-qt-pkg  2.45.28
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  iconLabel->setPixmap( YQUI::ui()->loadIcon( "dialog-warning" ).pixmap(64) );
97  iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); // hor/vert
98 
99  // Label for the message
100 
101  QLabel * label = new QLabel( message, this);
102  Q_CHECK_PTR( label );
103  hbox->addWidget(label);
104  label->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
105  label->setTextFormat( Qt::RichText );
106  label->setWordWrap( true );
107 
108 
109  // Disk usage list
110 
111  YQPkgDiskUsageList * duList = new YQPkgDiskUsageList( this, thresholdPercent );
112  Q_CHECK_PTR( duList );
113  layout->addWidget( duList );
114 
115 
116  // Button box
117 
118  hbox = new QHBoxLayout();
119  Q_CHECK_PTR( hbox );
120  hbox->setSpacing( SPACING );
121  hbox->setMargin ( MARGIN );
122  layout->addLayout( hbox );
123 
124  //addHStretch( hbox );
125 
126 
127  // Accept button - usually "OK" or "Continue"
128 
129  QPushButton * button = new QPushButton( acceptButtonLabel, this );
130  Q_CHECK_PTR( button );
131  hbox->addWidget(button);
132 
133  connect( button, SIGNAL( clicked() ),
134  this, SLOT ( accept() ) );
135 
136  //addHStretch( hbox );
137 
138 
139  if ( ! rejectButtonLabel.isEmpty() )
140  {
141  // Reject button ( if desired ) - usually "Cancel"
142 
143  button = new QPushButton( rejectButtonLabel, this );
144  Q_CHECK_PTR( button );
145  hbox->addWidget(button);
146 
147  connect( button, SIGNAL( clicked() ),
148  this, SLOT ( reject() ) );
149 
150  //addHStretch( hbox );
151  }
152 
153  // If there is only one button, it's safe to make that one ( the accept
154  // button ) the default. If there are two, better be safe than sorry and
155  // make the reject button the default.
156 
157  button->setDefault( true );
158 }
159 
160 
161 bool
163  int thresholdPercent,
164  const QString & acceptButtonLabel,
165  const QString & rejectButtonLabel )
166 {
167  YQPkgDiskUsageWarningDialog dialog( 0,
168  message,
169  thresholdPercent,
170  acceptButtonLabel,
171  rejectButtonLabel );
172  YQUI::ui()->normalCursor();
173  dialog.exec();
174 
175  return dialog.result() == QDialog::Accepted;
176 }
177 
178 
179 
180 
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 &#39;message&#39; 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 &#39;message&#39;, a list of partitions that a...
List of disk usage of all attached partitions.