Commit eb2dfc6f authored by Andrew den Exter's avatar Andrew den Exter Committed by Bea Lam

Fix the over agressive progress feedback and package id resolution never ending.

parent b33dd4a4
......@@ -70,10 +70,13 @@
/* D-Bus signal names */
#define PACKAGEKIT_TRANSACTION_PACKAGE "Package"
#define PACKAGEKIT_TRANSACTION_ITEMPROGRESS "ItemProgress"
#define PACKAGEKIT_TRANSACTION_ERRORCODE "ErrorCode"
#define PACKAGEKIT_TRANSACTION_FINISHED "Finished"
/* D-Bus property names */
#define PACKAGEKIT_TRANSACTION_PERCENTAGE "Percentage"
#define PACKAGEKIT_TRANSACTION_STATUS "Status"
/* D-Bus service */
#define USB_MODED_SERVICE "com.meego.usb_moded"
#define USB_MODED_PATH "/com/meego/usb_moded"
......@@ -87,6 +90,15 @@
#define USB_MODED_CONFIG_IP "ip"
#define USB_MODED_CONFIG_INTERFACE "interface"
#define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
#define DBUS_PROPERTIES_CHANGED "PropertiesChanged"
enum TransactionStatus {
TransactionRemoving = 6,
TransactionDownloading = 8,
TransactionInstalling = 9
};
static QMap<QString,QString>
enumerate_network_interfaces()
{
......@@ -138,6 +150,7 @@ DeveloperModeSettings::DeveloperModeSettings(QObject *parent)
, m_remoteLoginEnabled(false) // TODO: Read (from password manager?)
, m_workerStatus(Idle)
, m_workerProgress(PROGRESS_INDETERMINATE)
, m_transactionStatus(0)
{
int uid = getdef_num("UID_MIN", -1);
struct passwd *pwd;
......@@ -333,9 +346,12 @@ QDBusPendingCallWatcher *DeveloperModeSettings::resolvePackageId(const QString &
connectTransactionSignal(
PACKAGEKIT_TRANSACTION_PACKAGE,
SLOT(transactionPackage(uint,QString)));
connectPropertiesChanged();
connectTransactionSignal(
PACKAGEKIT_TRANSACTION_FINISHED,
SLOT(transactionItemProgress(QString,uint,uint)));
SLOT(transactionFinished(uint,uint)));
return packageKitTransactionCall(
m_packageKitTransaction,
......@@ -345,9 +361,8 @@ QDBusPendingCallWatcher *DeveloperModeSettings::resolvePackageId(const QString &
QDBusPendingCallWatcher *DeveloperModeSettings::installPackage(const QString &packageId)
{
connectTransactionSignal(
PACKAGEKIT_TRANSACTION_ITEMPROGRESS,
SLOT(transactionItemProgress(QString,uint,uint)));
connectPropertiesChanged();
connectTransactionSignal(
PACKAGEKIT_TRANSACTION_FINISHED,
SLOT(transactionFinished(uint,uint)));
......@@ -359,9 +374,8 @@ QDBusPendingCallWatcher *DeveloperModeSettings::installPackage(const QString &pa
QDBusPendingCallWatcher *DeveloperModeSettings::removePackage(const QString &packageId)
{
connectTransactionSignal(
PACKAGEKIT_TRANSACTION_ITEMPROGRESS,
SLOT(transactionItemProgress(QString,uint,uint)));
connectPropertiesChanged();
connectTransactionSignal(
PACKAGEKIT_TRANSACTION_FINISHED,
SLOT(transactionFinished(uint,uint)));
......@@ -384,6 +398,17 @@ void DeveloperModeSettings::connectTransactionSignal(const QString &name, const
slot);
}
void DeveloperModeSettings::connectPropertiesChanged()
{
QDBusConnection::systemBus().connect(
PACKAGEKIT_SERVICE,
m_packageKitTransaction.path(),
DBUS_PROPERTIES_INTERFACE,
DBUS_PROPERTIES_CHANGED,
this,
SLOT(transactionPropertiesChanged(QString,QVariantMap,QStringList)));
}
void DeveloperModeSettings::executePackageKitCommand(
QDBusPendingCallWatcher *(DeveloperModeSettings::*command)(const QString &),
const QString &argument)
......@@ -451,12 +476,39 @@ void DeveloperModeSettings::transactionPackage(uint, const QString &packageId)
}
}
void DeveloperModeSettings::transactionItemProgress(const QString &, uint, uint progress)
void DeveloperModeSettings::transactionPropertiesChanged(
const QString &interface, const QVariantMap &changed, const QStringList &)
{
// Ignore package and status. Progress will proceed from 0 to 100 multiple times.
if (m_workerProgress != int(progress)) {
m_workerProgress = progress;
emit workerProgressChanged();
qDebug() << "properties changed" << interface << changed;
if (interface != PACKAGEKIT_TRANSACTION_INTERFACE) {
return;
}
auto it = changed.find(PACKAGEKIT_TRANSACTION_STATUS);
if (it != changed.end()) {
m_transactionStatus = it->toInt();
}
it = changed.find(PACKAGEKIT_TRANSACTION_PERCENTAGE);
if (it != changed.end()) {
switch (m_transactionStatus) {
case TransactionRemoving:
case TransactionDownloading:
case TransactionInstalling: {
int progress = it->toInt();
if (progress > 100) {
progress = PROGRESS_INDETERMINATE;
}
if (m_workerProgress != progress) {
m_workerProgress = progress;
emit workerProgressChanged();
}
break;
}
default:
break;
}
}
}
......
......@@ -120,6 +120,7 @@ private slots:
void transactionItemProgress(const QString &package, uint status, uint progress);
void transactionErrorCode(uint code, const QString &message);
void transactionFinished(uint exit, uint runtime);
void transactionPropertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated);
private:
QDBusPendingCallWatcher *resolvePackageId(const QString &packageName);
......@@ -127,6 +128,7 @@ private:
QDBusPendingCallWatcher *removePackage(const QString &packageId);
void connectTransactionSignal(const QString &name, const char *slot);
void connectPropertiesChanged();
void executePackageKitCommand(
QDBusPendingCallWatcher *(DeveloperModeSettings::*command)(const QString &),
......@@ -147,6 +149,8 @@ private:
bool m_remoteLoginEnabled;
DeveloperModeSettings::Status m_workerStatus;
int m_workerProgress;
int m_transactionStatus;
};
Q_DECLARE_METATYPE(DeveloperModeSettings::Status);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment