~ubuntu-branches/ubuntu/karmic/kboincspy/karmic

« back to all changes in this revision

Viewing changes to src/kbscore/kbstasknode.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas
  • Date: 2005-03-31 12:33:43 UTC
  • Revision ID: james.westby@ubuntu.com-20050331123343-37fm35635duf506y
Tags: upstream-0.9.0
ImportĀ upstreamĀ versionĀ 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004 by Roberto Virga                                   *
 
3
 *   rvirga@users.sf.net                                                   *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
 
 
21
#include <math.h>
 
22
 
 
23
#include <klibloader.h>
 
24
#include <klocale.h>
 
25
#include <ktrader.h>
 
26
 
 
27
#include <kbsboincmonitor.h>
 
28
#include <kbspanelnode.h>
 
29
 
 
30
#include "kbstasknode.h"
 
31
 
 
32
KBSTaskNode::KBSTaskNode(unsigned num, const QString &workunit, KBSTreeNode *parent, const char *name)
 
33
           : KBSWorkunitNode(workunit, parent, name), m_num(num)
 
34
{
 
35
  addPlugins();
 
36
}
 
37
 
 
38
QString KBSTaskNode::name() const
 
39
{
 
40
  return KBSTaskNode::name(m_num, monitor());
 
41
}
 
42
 
 
43
QString KBSTaskNode::name(unsigned num, KBSBOINCMonitor *)
 
44
{
 
45
  return i18n("CPU %1").arg(num + 1);
 
46
}
 
47
 
 
48
int KBSTaskNode::task() const
 
49
{
 
50
  return m_task;
 
51
}
 
52
 
 
53
QString KBSTaskNode::result() const
 
54
{
 
55
  return m_result;
 
56
}
 
57
 
 
58
void KBSTaskNode::addPlugins()
 
59
{
 
60
  if(NULL == monitor() || project().isEmpty()) return;
 
61
  
 
62
  const BOINCClientState *state = monitor()->state();
 
63
  if(NULL == state) return;
 
64
  
 
65
  m_result = state->workunit[workunit()].result_name;
 
66
  if(m_result.isEmpty()) return;
 
67
  
 
68
  m_task = state->active_task_set.index(m_result);
 
69
  if(m_task < 0) return;
 
70
 
 
71
  QString constraints;
 
72
  KTrader::OfferList offers;
 
73
 
 
74
  constraints = "[X-KDE-Target] == 'Task' and '%1' in [X-KDE-Projects]";
 
75
  offers = KTrader::self()->query("KBSPanelNode", constraints.arg(project()));
 
76
 
 
77
  for(KTrader::OfferListIterator offer = offers.begin(); offer != offers.end(); ++offer)
 
78
  {
 
79
    const QString name = (*offer)->name();
 
80
    
 
81
    QStringList args = (*offer)->property("X-KDE-Arguments").toStringList();
 
82
    args.prepend(QString::number(m_task));
 
83
    
 
84
    KLibFactory *factory = KLibLoader::self()->factory((*offer)->library());
 
85
    if(NULL == factory) continue;
 
86
    
 
87
    insertChild(static_cast<KBSPanelNode*>(factory->create(this, name, "KBSPanelNode", args)));
 
88
  }
 
89
}
 
90
 
 
91
#include "kbstasknode.moc"