1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/***************************************************************************
* Copyright (C) 2009-2010 by Daniel Nicoletti *
* dantti12@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; see the file COPYING. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "TransactionModel.h"
#include <KUser>
#include <KGlobal>
#include <KLocalizedString>
#include <KDebug>
#include <PkIcons.h>
#include <PkStrings.h>
using namespace PackageKit;
TransactionModel::TransactionModel(QObject *parent)
: QStandardItemModel(parent)
{
setSortRole(Qt::DisplayRole);
clear();
}
void TransactionModel::clear()
{
QStandardItemModel::clear();
setHorizontalHeaderItem(0, new QStandardItem(i18n("Date")));
setHorizontalHeaderItem(1, new QStandardItem(i18n("Action")));
setHorizontalHeaderItem(2, new QStandardItem(i18n("Details")));
setHorizontalHeaderItem(3, new QStandardItem(i18nc("Machine user who issued the transaction", "Username")));
setHorizontalHeaderItem(4, new QStandardItem(i18n("Application")));
}
void TransactionModel::addTransaction(PackageKit::Transaction *trans)
{
QStandardItem *dateI = new QStandardItem;
QStandardItem *roleI = new QStandardItem;
QStandardItem *detailsI = new QStandardItem;
QStandardItem *userI = new QStandardItem;
QStandardItem *appI = new QStandardItem;
dateI->setText(KGlobal::locale()->formatDate(trans->timespec().date()));
// this is for the filterSort model
dateI->setData(trans->timespec(), Qt::UserRole);
dateI->setEditable(false);
roleI->setText(PkStrings::actionPast(trans->role()));
roleI->setIcon(PkIcons::actionIcon(trans->role()));
roleI->setEditable(false);
detailsI->setText(getDetailsLocalized(trans->data()));
detailsI->setEditable(false);
KUser user(trans->uid());
QString display;
if (!user.property(KUser::FullName).toString().isEmpty()) {
display = user.property(KUser::FullName).toString() + " (" + user.loginName() + ')';
} else {
display = user.loginName();
}
userI->setText(display);
userI->setEditable(false);
appI->setText(trans->cmdline());
appI->setEditable(false);
QList<QStandardItem *> line;
line << dateI << roleI << detailsI << userI << appI;
appendRow(line);
delete trans;
}
QString TransactionModel::getDetailsLocalized(const QString &data) const
{
QStringList lines = data.split('\n');
QStringList ret;
QString text;
text = getTypeLine(lines, Transaction::StatusInstall);
if (!text.isNull()) {
ret << text;
}
text = getTypeLine(lines, Transaction::StatusRemove);
if (!text.isNull()) {
ret << text;
}
text = getTypeLine(lines, Transaction::StatusUpdate);
if (!text.isNull()) {
ret << text;
}
return ret.join("\n");
}
QString TransactionModel::getTypeLine(const QStringList &lines, Transaction::Status status) const
{
QStringList text;
foreach(const QString &line, lines) {
QStringList sections = line.split('\t');
if (sections.size() > 1) {
switch (status) {
case Transaction::StatusInstall:
if (sections.at(0) != "installing") {
continue;
}
break;
case Transaction::StatusRemove:
if (sections.at(0) != "removing") {
continue;
}
break;
case Transaction::StatusUpdate:
if (sections.at(0) != "updating") {
continue;
}
break;
default:
continue;
}
QStringList packageData = sections.at(1).split(';');
if (packageData.size()) {
text << packageData.at(0);
}
}
}
if (text.size()) {
// TODO make the status BOLD
return PkStrings::statusPast(status) + ": " + text.join(", ");
} else {
return QString();
}
}
|