File indexing completed on 2022-09-27 16:24:30

0001 /***************************************************************************
0002  *   Copyright (C) 2009-2010 by Daniel Nicoletti                           *
0003  *   dantti12@gmail.com                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; see the file COPYING. If not, write to       *
0017  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0018  *   Boston, MA 02110-1301, USA.                                           *
0019  ***************************************************************************/
0020 
0021 #include "TransactionHistory.h"
0022 
0023 #include "TransactionFilterModel.h"
0024 #include "TransactionModel.h"
0025 
0026 #include <PkIcons.h>
0027 #include <PkStrings.h>
0028 
0029 #include <Daemon>
0030 
0031 #include <QMenu>
0032 #include <KMessageBox>
0033 #include <KLocalizedString>
0034 #include <KFormat>
0035 
0036 #include <QLoggingCategory>
0037 
0038 TransactionHistory::TransactionHistory(QWidget *parent)
0039  : QWidget(parent)
0040 {
0041     setupUi(this);
0042 
0043     m_transactionModel = new TransactionModel(this);
0044     m_proxyModel = new TransactionFilterModel(this);
0045     m_proxyModel->setSourceModel(m_transactionModel);
0046     m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
0047     m_proxyModel->setFilterKeyColumn(-1);
0048     treeView->setModel(m_proxyModel);
0049     treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
0050 
0051     // Get the data
0052     refreshList();
0053 }
0054 
0055 TransactionHistory::~TransactionHistory()
0056 {
0057 }
0058 
0059 void TransactionHistory::setFilterRegExp(const QString &regexp)
0060 {
0061     m_proxyModel->setFilterRegExp(regexp);
0062 }
0063 
0064 void TransactionHistory::on_treeView_customContextMenuRequested(const QPoint &pos)
0065 {
0066     auto menu = new QMenu(this);
0067     QAction *action = menu->addAction(i18n("Refresh transactions list"));
0068     connect(action, &QAction::triggered, this, &TransactionHistory::refreshList);
0069     menu->exec(treeView->viewport()->mapToGlobal(pos));
0070     delete menu;
0071 }
0072 
0073 void TransactionHistory::refreshList()
0074 {
0075     // Refresh transaction list
0076     m_transactionModel->clear();
0077     Transaction *transaction = Daemon::getOldTransactions(0);
0078     connect(transaction, &Transaction::transaction, m_transactionModel, &TransactionModel::addTransaction);
0079 
0080     // Refresh time
0081     QString text;
0082     uint time = Daemon::global()->getTimeSinceAction(Transaction::RoleRefreshCache) * 1000;
0083     text = i18n("Time since last cache refresh: %1", KFormat().formatSpelloutDuration(time));
0084     timeCacheLabel->setText(text);
0085 }
0086 
0087 #include "moc_TransactionHistory.cpp"