KDE/kdebase/workspace/plasma/generic/applets/devicenotifier
Jacopo De Simoi
wilderkde at gmail.com
Sun Apr 11 16:13:57 CEST 2010
SVN commit 1113686 by jacopods:
Show error messages inside the applet instead of using Plasma::MessageBox
As soon as a patch in solid is accepted, the notifier will be able to react to
errors triggered by other applications, hence errors will be shown also when
triggered from other applications (e.g. dolphin).
Feedback is welcome!
CCMAIL:plasma-devel at kde.org
M +7 -1 devicenotifier.cpp
M +69 -9 notifierdialog.cpp
M +20 -0 notifierdialog.h
--- trunk/KDE/kdebase/workspace/plasma/generic/applets/devicenotifier/devicenotifier.cpp #1113685:1113686
@@ -158,6 +158,7 @@
} else {
m_dialog->collapseDevices();
}
+ changeNotifierIcon();
}
void DeviceNotifier::dataUpdated(const QString &udi, Plasma::DataEngine::Data data)
@@ -445,7 +446,12 @@
void DeviceNotifier::showErrorMessage(const QString &message)
{
- showMessage(KIcon("dialog-error"), message, ButtonOk);
+ m_dialog->showStatusBarMessage(message);
+ emit activate();
+ showPopup(NOTIFICATION_TIMEOUT);
+ changeNotifierIcon("dialog-error");
+ update();
+ QTimer::singleShot(NOTIFICATION_TIMEOUT, m_dialog, SLOT(resetNotifierIcon()));
}
bool DeviceNotifier::areThereHiddenDevices()
--- trunk/KDE/kdebase/workspace/plasma/generic/applets/devicenotifier/notifierdialog.cpp #1113685:1113686
@@ -462,8 +462,8 @@
m_widget->installEventFilter(this);
m_widget->setFocusPolicy(Qt::ClickFocus);
- QGraphicsLinearLayout *l_layout = new QGraphicsLinearLayout(Qt::Vertical, m_widget);
- l_layout->setSpacing(0);
+ m_mainLayout = new QGraphicsLinearLayout(Qt::Vertical, m_widget);
+ m_mainLayout->setSpacing(0);
Plasma::IconWidget *icon = new Plasma::IconWidget(m_widget);
icon->setIcon(KIcon("emblem-mounted"));
@@ -486,7 +486,7 @@
QGraphicsWidget *titleWidget = new QGraphicsWidget();
titleWidget->setLayout(l_layout2);
- l_layout->addItem(titleWidget);
+ m_mainLayout->addItem(titleWidget);
m_devicesScrollWidget = new Plasma::ScrollWidget(m_widget);
QGraphicsWidget *devicesWidget = new QGraphicsWidget(m_devicesScrollWidget);
@@ -496,7 +496,7 @@
m_deviceLayout->setContentsMargins(0, 0, 0, 8);
devicesWidget->setLayout(m_deviceLayout);
- l_layout->addItem(m_devicesScrollWidget);
+ m_mainLayout->addItem(m_devicesScrollWidget);
m_itemBackground = new Plasma::ItemBackground(devicesWidget);
m_selectedItemBackground = new Plasma::ItemBackground(devicesWidget);
@@ -506,17 +506,72 @@
connect(m_itemBackground, SIGNAL(animationStep(qreal)), this, SLOT(itemBackgroundMoving(qreal)));
connect(m_selectedItemBackground, SIGNAL(animationStep(qreal)), this, SLOT(itemBackgroundMoving(qreal)));
+ m_statusWidget = new QGraphicsWidget();
+ QGraphicsLinearLayout *statusLayout = new QGraphicsLinearLayout(Qt::Vertical, m_statusWidget);
+
+ m_statusWidget->setLayout(statusLayout);
+ Plasma::Separator *statusSeparator = new Plasma::Separator();
+ statusSeparator->setOrientation(Qt::Horizontal);
+ statusSeparator->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
+ statusLayout->addItem(statusSeparator);
+
+ m_statusText = new Plasma::Label();
+ m_statusText->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
+
+ Plasma::IconWidget *closeButton = new Plasma::IconWidget();
+ closeButton->setSvg("widgets/configuration-icons", "close");
+ closeButton->setMaximumSize(closeButton->sizeFromIconSize(KIconLoader::SizeSmall/2));
+ closeButton->setMinimumSize(closeButton->maximumSize());
+
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(dismissStatusBar()));
+
+ QGraphicsLinearLayout *labelLayout = new QGraphicsLinearLayout(Qt::Horizontal);
+ Plasma::IconWidget *infoIcon = new Plasma::IconWidget();
+ infoIcon->setIcon("preferences-desktop-notification");
+ infoIcon->setMaximumSize(infoIcon->sizeFromIconSize(KIconLoader::SizeSmall));
+ infoIcon->setMinimumSize(infoIcon->sizeFromIconSize(KIconLoader::SizeSmall));
+
+ labelLayout->addItem(infoIcon);
+ labelLayout->setAlignment(infoIcon, Qt::AlignVCenter);
+ labelLayout->addItem(m_statusText);
+ labelLayout->setAlignment(m_statusText, Qt::AlignVCenter);
+ labelLayout->addItem(closeButton);
+ labelLayout->setAlignment(closeButton, Qt::AlignVCenter);
+
+ statusLayout->addItem(labelLayout);
+
devicesWidget->adjustSize();
updateMainLabelText();
- m_widget->setLayout(l_layout);
+ m_widget->setLayout(m_mainLayout);
m_widget->setMinimumSize(250, 300);
}
+void NotifierDialog::dismissStatusBar()
+{
+ m_statusWidget->hide();
+ m_mainLayout->removeItem(m_statusWidget);
+}
+
+void NotifierDialog::showStatusBarMessage(const QString & message)
+{
+ m_statusText->setText(message);
+ m_statusText->adjustSize();
+ m_statusWidget->adjustSize();
+ m_mainLayout->addItem(m_statusWidget);
+ m_statusWidget->show();
+}
+
void NotifierDialog::storageTeardownDone(Solid::ErrorType error, QVariant errorData, const QString & udi)
{
+ DeviceItem* devItem = itemForUdi(udi);
+ if (!devItem) {
+ return;
+ }
+
+
if (error && errorData.isValid()) {
- m_notifier->showErrorMessage(i18n("Could not unmount the device.\nOne or more files on this device are open within an application."));
+ m_notifier->showErrorMessage(i18n("Could not unmount device %1.\nOne or more files on this device are open within an application.", devItem->name()));
} else {
m_notifier->changeNotifierIcon("dialog-ok");
m_notifier->update();
@@ -526,7 +581,7 @@
//show the message only one time
disconnect(sender(), SIGNAL(teardownDone(Solid::ErrorType, QVariant, const QString &)),
this, SLOT(storageTeardownDone(Solid::ErrorType, QVariant, const QString &)));
- itemForUdi(udi)->setState(DeviceItem::Idle);
+ devItem->setState(DeviceItem::Idle);
}
@@ -549,8 +604,13 @@
void NotifierDialog::storageSetupDone(Solid::ErrorType error, QVariant errorData, const QString &udi)
{
+ DeviceItem *devItem = itemForUdi(udi);
+ if (!devItem) {
+ return;
+ }
+
if (error && errorData.isValid()) {
- m_notifier->showErrorMessage(i18n("Cannot mount the disc."));
+ m_notifier->showErrorMessage(i18n("Could not mount device %1.", devItem->name()));
} else {
m_notifier->changeNotifierIcon("dialog-ok");
m_notifier->update();
@@ -560,7 +620,7 @@
//show the message only one time
disconnect(sender(), SIGNAL(setupDone(Solid::ErrorType, QVariant, const QString &)),
this, SLOT(storageSetupDone(Solid::ErrorType, QVariant, const QString &)));
- itemForUdi(udi)->setState(DeviceItem::Idle);
+ devItem->setState(DeviceItem::Idle);
}
DeviceItem *NotifierDialog::itemForUdi(const QString &udi) const
--- trunk/KDE/kdebase/workspace/plasma/generic/applets/devicenotifier/notifierdialog.h #1113685:1113686
@@ -167,6 +167,12 @@
**/
void setMenuActionsAt(QPointF scenePos);
+ /**
+ * Shows a message in the notifier status bar
+ * @param message the message to show
+ */
+ void showStatusBarMessage(const QString & message);
+
signals:
/**
* Emitted when a devices has been selected
@@ -277,6 +283,12 @@
void updateColors();
+ /**
+ * @internal dismiss the status bar
+ **/
+
+ void dismissStatusBar();
+
private :
/**
* @internal build the dialog depending where it is
@@ -335,6 +347,8 @@
/// The graphics widget which displays the panel
QGraphicsWidget *m_widget;
+ QGraphicsLinearLayout *m_mainLayout;
+
///The layout handling the devices inside the scroll widget
QGraphicsLinearLayout *m_deviceLayout;
@@ -351,6 +365,12 @@
///The ScrollWidget managing the view
Plasma::ScrollWidget *m_devicesScrollWidget;
+ // The graphics widget which displays status messages
+ QGraphicsWidget *m_statusWidget;
+
+ // Status label
+ Plasma::Label *m_statusText;
+
///The context menu action that allows to show all the devices
QAction *m_showAll;
More information about the Plasma-devel
mailing list