Skip to content
This repository was archived by the owner on Feb 2, 2019. It is now read-only.

Commit e043635

Browse files
committed
Installed apps model - track removed packages
1 parent c34c74f commit e043635

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/orninstalledappsmodel.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
OrnInstalledAppsModel::OrnInstalledAppsModel(QObject *parent) :
77
QAbstractListModel(parent)
88
{
9-
connect(OrnZypp::instance(), &OrnZypp::installedAppsReady,
9+
auto ornZypp = OrnZypp::instance();
10+
connect(ornZypp, &OrnZypp::installedAppsReady,
1011
this, &OrnInstalledAppsModel::onInstalledAppsReady);
12+
connect(ornZypp, &OrnZypp::packageRemoved,
13+
this, &OrnInstalledAppsModel::onPackageRemoved);
1114
this->reset();
1215
}
1316

@@ -32,6 +35,22 @@ void OrnInstalledAppsModel::onInstalledAppsReady(const OrnZypp::AppList &apps)
3235
this->endResetModel();
3336
}
3437

38+
void OrnInstalledAppsModel::onPackageRemoved(const QString &packageId)
39+
{
40+
auto name = packageId.section(QChar(';'), 0, 0);
41+
auto size = mData.size();
42+
for (OrnZypp::AppList::size_type i = 0; i < size; ++i)
43+
{
44+
if (mData[i].name == name)
45+
{
46+
this->beginRemoveRows(QModelIndex(), i, i);
47+
mData.removeAt(i);
48+
this->endInsertRows();
49+
return;
50+
}
51+
}
52+
}
53+
3554
int OrnInstalledAppsModel::rowCount(const QModelIndex &parent) const
3655
{
3756
return !parent.isValid() ? mData.size() : 0;
@@ -65,6 +84,10 @@ QVariant OrnInstalledAppsModel::data(const QModelIndex &index, int role) const
6584
case UpdateAvailableRole:
6685
// Return int to make it easier to parse
6786
return (int)!app.updateId.isEmpty();
87+
case PackageIdRole:
88+
return app.packageId;
89+
case UpdateIdRole:
90+
return app.updateId;
6891
default:
6992
return QVariant();
7093
}
@@ -79,6 +102,8 @@ QHash<int, QByteArray> OrnInstalledAppsModel::roleNames() const
79102
{ AuthorRole, "appAuthor" },
80103
{ IconRole, "appIconSource" },
81104
{ SectionRole, "section" },
82-
{ UpdateAvailableRole, "updateAvailable" }
105+
{ UpdateAvailableRole, "updateAvailable" },
106+
{ PackageIdRole, "packageId" },
107+
{ UpdateIdRole, "updateId" },
83108
};
84109
}

src/orninstalledappsmodel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class OrnInstalledAppsModel : public QAbstractListModel
2020
IconRole,
2121
SortRole,
2222
SectionRole,
23-
UpdateAvailableRole
23+
UpdateAvailableRole,
24+
PackageIdRole,
25+
UpdateIdRole
2426
};
2527
Q_ENUM(Roles)
2628

@@ -31,6 +33,7 @@ public slots:
3133

3234
private slots:
3335
void onInstalledAppsReady(const OrnZypp::AppList &apps);
36+
void onPackageRemoved(const QString &packageId);
3437

3538
private:
3639
OrnZypp::AppList mData;

src/ornzypp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void OrnZypp::removePackage(const QString &packageId)
324324
}
325325
emit this->packageRemoved(packageId);
326326
});
327-
qDebug() << "Removing package" << packageId << "with" << t << "method installPackage()";
327+
qDebug() << "Removing package" << packageId << "with" << t << "method removePackage()";
328328
t->removePackage(packageId);
329329
}
330330

@@ -547,6 +547,7 @@ void OrnZypp::pInstalledApps()
547547
idParts[1],
548548
this->packageRepo(name).mid(repoNamePrefixLength),
549549
icon,
550+
id,
550551
// The update package id or an empty string
551552
mUpdates.value(name)
552553
};

src/ornzypp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class OrnZypp : public QObject
4545
QString version;
4646
QString author;
4747
QString icon;
48+
QString packageId;
4849
QString updateId;
4950
};
5051

0 commit comments

Comments
 (0)