On Thu, Jan 08, 2009 at 10:49:37PM +0100, Sebastian Kügler wrote: > > will do after this patch is in and/or I return from vacations next > > week :) > > Ok. Can you send me an updated patch I can commit directly then?
duh, forgot to attach it :| -- (Not so) Random fortune: 13:21 < propellerhead> Lo bueno de Obama es que se va poder ver perfecto teniendo a la Casa Blanca de fondo
Index: kdebase/workspace/plasma/applets/battery/battery.h =================================================================== --- kdebase/workspace/plasma/applets/battery/battery.h (revision 907430) +++ kdebase/workspace/plasma/applets/battery/battery.h (working copy) @@ -120,6 +120,8 @@ bool m_showMultipleBatteries; /* Should the battery charge information be shown on top? */ bool m_showBatteryString; + /* Should that info be percentage (true) or time (false)? */ + bool m_showRemainingTime; QSizeF m_size; int m_pixelSize; Plasma::Svg* m_theme; Index: kdebase/workspace/plasma/applets/battery/battery.cpp =================================================================== --- kdebase/workspace/plasma/applets/battery/battery.cpp (revision 907430) +++ kdebase/workspace/plasma/applets/battery/battery.cpp (working copy) @@ -87,6 +87,7 @@ m_firstRun(true), m_numOfBattery(0), m_acadapter_plugged(false), + m_showRemainingTime(true), m_remainingMSecs(0) { kDebug() << "Loading applet battery"; @@ -156,22 +157,26 @@ } else { setAspectRatioMode(Plasma::KeepAspectRatio); } + int minWidth; + int minHeight; if (constraints & (Plasma::FormFactorConstraint | Plasma::SizeConstraint)) { if (formFactor() == Plasma::Vertical) { if (!m_showMultipleBatteries) { - setMinimumHeight(qMax(m_textRect.height(), size().width())); + minHeight = qMax(m_textRect.height(), size().width()); } else { - setMinimumHeight(qMax(m_textRect.height(), size().width()*m_numOfBattery)); + minHeight = qMax(m_textRect.height(), size().width()*m_numOfBattery); } setMinimumWidth(0); + setMinimumHeight(minHeight); //kDebug() << "Vertical FormFactor"; } else if (formFactor() == Plasma::Horizontal) { if (!m_showMultipleBatteries) { - setMinimumWidth(qMax(m_textRect.width(), size().height())); + minWidth = qMax(m_textRect.width(), size().height()); } else { - setMinimumWidth(qMax(m_textRect.width(), size().height()*m_numOfBattery)); + minWidth = qMax(m_textRect.width(), size().height()*m_numOfBattery); } + setMinimumWidth(minWidth); setMinimumHeight(0); //kDebug() << "Horizontal FormFactor" << m_textRect.width() << contentsRect().height(); } else { @@ -217,6 +222,11 @@ connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); ui.showBatteryStringCheckBox->setChecked(m_showBatteryString ? Qt::Checked : Qt::Unchecked); + if (m_showRemainingTime) { + ui.showTimeRadioButton->setChecked(Qt::Checked); + } else { + ui.showPercentageRadioButton->setChecked(Qt::Checked); + } ui.showMultipleBatteriesCheckBox->setChecked(m_showMultipleBatteries ? Qt::Checked : Qt::Unchecked); } @@ -224,6 +234,16 @@ { KConfigGroup cg = config(); + if (m_showRemainingTime != ui.showTimeRadioButton->isChecked()) { + kDebug() << "config changed"; + m_showRemainingTime = !m_showRemainingTime; + cg.writeEntry("showRemainingTime", m_showRemainingTime); + kDebug() << m_showRemainingTime; + if (m_showBatteryString && m_showBatteryString == ui.showBatteryStringCheckBox->isChecked()) { + showLabel(m_showBatteryString); + } + } + if (m_showBatteryString != ui.showBatteryStringCheckBox->isChecked()) { m_showBatteryString = !m_showBatteryString; cg.writeEntry("showBatteryString", m_showBatteryString); @@ -491,13 +511,13 @@ if (m_numOfBattery && m_batteryLabel) { QHashIterator<QString, QHash<QString, QVariant > > battery_data(m_batteries_data); int bnum = 0; - int hours = m_remainingMSecs/1000/3600; - int minutes = qRound(m_remainingMSecs/60000) % 60; while (battery_data.hasNext()) { bnum++; battery_data.next(); QString state = battery_data.value()["State"].toString(); + m_remainingMSecs = battery_data.value()["Remaining msec"].toInt(); + kDebug() << "time left:" << m_remainingMSecs; if (state == "Discharging" && m_remainingMSecs > 0) { // FIXME: Somehow, m_extenderApplet is null here, so the label never becomes visible @@ -506,17 +526,7 @@ } // we don't have too much accuracy so only give hours and minutes - int msecs = hours * 1000 * 3600 + minutes * 60000; - batteryLabelText.append(i18n("Time remaining: <b>%1</b><br />", KGlobal::locale()->prettyFormatDuration(msecs))); - kDebug() << "hours:" << hours << "minutes:" << minutes; - /* might be useful for the tooltip - kDebug() << "hours:" << hours << "minutes:" << minutes; - QTime t = QTime(hours, minutes); - kDebug() << t; - KLocale tmpLocale(*KGlobal::locale()); - tmpLocale.setTimeFormat("%k:h %Mm remaining"); - kDebug() << tmpLocale.formatTime(t, false, true); // minutes, hours as duration - */ + batteryLabelText.append(i18n("Time remaining: <b>%1</b><br />", KGlobal::locale()->prettyFormatDuration(m_remainingMSecs))); } else { if (m_extenderApplet) { m_extenderApplet->showBatteryLabel(false); @@ -865,8 +875,20 @@ // Show the charge percentage with a box on top of the battery QString batteryLabel; if (battery_data.value()["Plugged in"].toBool()) { - batteryLabel = battery_data.value()["Percent"].toString(); - batteryLabel.append("%"); + kDebug() << m_showRemainingTime; + if (!m_showRemainingTime || m_remainingMSecs==0) { + batteryLabel = battery_data.value()["Percent"].toString(); + batteryLabel.append("%"); + } else { + m_remainingMSecs = battery_data.value()["Remaining msec"].toInt(); + int hours = m_remainingMSecs/1000/3600; + int minutes = qRound(m_remainingMSecs/60000) % 60; + QTime t = QTime(hours, minutes); + KLocale tmpLocale(*KGlobal::locale()); + tmpLocale.setTimeFormat("%k:%M"); + batteryLabel = tmpLocale.formatTime(t, false, true); // minutes, hours as duration + } + kDebug() << batteryLabel; paintLabel(p, corect, batteryLabel); } } Index: kdebase/workspace/plasma/applets/battery/batteryConfig.ui =================================================================== --- kdebase/workspace/plasma/applets/battery/batteryConfig.ui (revision 907430) +++ kdebase/workspace/plasma/applets/battery/batteryConfig.ui (working copy) @@ -6,7 +6,7 @@ <x>0</x> <y>0</y> <width>363</width> - <height>80</height> + <height>270</height> </rect> </property> <property name="windowTitle" > @@ -22,11 +22,70 @@ <string/> </property> <property name="text" > - <string>Show the percentage of &charge on the battery</string> + <string>Show charge &information</string> </property> </widget> </item> <item> + <layout class="QGridLayout" name="gridLayout" > + <item row="0" column="1" > + <widget class="QRadioButton" name="showPercentageRadioButton" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="text" > + <string>Show &percentage</string> + </property> + <property name="checked" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="0" column="0" > + <spacer name="horizontalSpacer" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0" > + <spacer name="horizontalSpacer_2" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="1" > + <widget class="QRadioButton" name="showTimeRadioButton" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="text" > + <string>Show remaining &time</string> + </property> + </widget> + </item> + </layout> + </item> + <item> <widget class="QCheckBox" name="showMultipleBatteriesCheckBox" > <property name="toolTip" > <string/> @@ -52,5 +111,38 @@ </layout> </widget> <resources/> - <connections/> + <connections> + <connection> + <sender>showBatteryStringCheckBox</sender> + <signal>toggled(bool)</signal> + <receiver>showPercentageRadioButton</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel" > + <x>181</x> + <y>20</y> + </hint> + <hint type="destinationlabel" > + <x>195</x> + <y>52</y> + </hint> + </hints> + </connection> + <connection> + <sender>showBatteryStringCheckBox</sender> + <signal>toggled(bool)</signal> + <receiver>showTimeRadioButton</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel" > + <x>181</x> + <y>20</y> + </hint> + <hint type="destinationlabel" > + <x>195</x> + <y>83</y> + </hint> + </hints> + </connection> + </connections> </ui>
_______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel