memspyui/ui/hb/src/memspyprocessview.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * 
       
    16 */
       
    17 
       
    18 #include "memspyprocessview.h"
       
    19 
       
    20 #include <QVariantMap>
       
    21 
       
    22 #include "viewmanager.h"
       
    23 
       
    24 MemSpyProcessModel::MemSpyProcessModel(EngineWrapper &engine, QObject *parent) :
       
    25 	QAbstractListModel(parent),
       
    26 	mEngine(engine),
       
    27 	mProcesses(engine.getProcesses())
       
    28 {
       
    29     mPriorityMap.insert(EPriorityLow, tr("[L]"));
       
    30     mPriorityMap.insert(EPriorityBackground, tr("[B]"));
       
    31     mPriorityMap.insert(EPriorityForeground, tr("[F]"));
       
    32     mPriorityMap.insert(EPriorityHigh, tr("[H]"));
       
    33     mPriorityMap.insert(EPriorityWindowServer, tr("[WS]"));
       
    34     mPriorityMap.insert(EPriorityFileServer, tr("[FS]"));
       
    35     mPriorityMap.insert(EPriorityRealTimeServer, tr("[RTS]"));
       
    36     mPriorityMap.insert(EPrioritySupervisor, tr("[SUP]"));
       
    37 }
       
    38 
       
    39 MemSpyProcessModel::~MemSpyProcessModel()
       
    40 {
       
    41 	qDeleteAll(mProcesses);
       
    42 }
       
    43 	
       
    44 int MemSpyProcessModel::rowCount(const QModelIndex &parent) const
       
    45 {
       
    46 	Q_UNUSED(parent);
       
    47 	return mProcesses.count();
       
    48 }
       
    49 	
       
    50 QVariant MemSpyProcessModel::data(const QModelIndex &index, int role) const
       
    51 {
       
    52 	if (role == Qt::DisplayRole) {
       
    53 	    const MemSpyProcess* process = mProcesses.at(index.row());
       
    54 	    
       
    55 		QStringList lines;
       
    56 		lines << process->name();
       
    57 		
       
    58 		lines << (process->isDead() ? 
       
    59 		    process->exitInfo() :
       
    60 		    QString("%1, %2 thr, %3").
       
    61                 arg(process->sid(), 0, 16).
       
    62                 arg(process->threadCount()).
       
    63                 arg(mPriorityMap.value(process->priority(), tr("[?]"))));
       
    64 		
       
    65 		return lines;
       
    66 	}
       
    67 	
       
    68 	if (role == Qt::UserRole)
       
    69 		return mProcesses.at(index.row())->id();
       
    70 	
       
    71 	return QVariant();
       
    72 }
       
    73 
       
    74 void MemSpyProcessModel::refresh()
       
    75 {
       
    76     beginResetModel();
       
    77     QList<MemSpyProcess*> data = mEngine.getProcesses();
       
    78     qDeleteAll(mProcesses);
       
    79     mProcesses = data;
       
    80     endResetModel();
       
    81 }
       
    82 	
       
    83 
       
    84 void MemSpyProcessView::initialize(const QVariantMap& params)
       
    85 {
       
    86 	setTitle(tr("Processes"));
       
    87 	MemSpyView::initialize(params);
       
    88 	
       
    89 	mModel = new MemSpyProcessModel(mEngine, this);
       
    90 	mListView.setModel(mModel);
       
    91 	
       
    92 	connect(&mListView, SIGNAL(activated(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
       
    93 }
       
    94 
       
    95 void MemSpyProcessView::itemClicked(const QModelIndex& index)
       
    96 {
       
    97 	QVariantMap map;
       
    98 	map.insert("pid", index.data(Qt::UserRole));
       
    99 	map.insert("pname", index.data(Qt::DisplayRole).toStringList().at(0));
       
   100     mViewManager.showView(ThreadView, map);
       
   101 }
       
   102 
       
   103 void MemSpyProcessView::refresh()
       
   104 { 
       
   105     mModel->refresh(); 
       
   106 }
       
   107