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

« back to all changes in this revision

Viewing changes to src/panels/seti/workunit/kbssetitelescopepathwindow.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 <klocale.h>
 
22
 
 
23
#include <kbsboincmonitor.h>
 
24
 
 
25
#include <kbssetiprojectmonitor.h>
 
26
#include <kbssetisignalplot.h>
 
27
#include <setidata.h>
 
28
 
 
29
#include "kbssetitelescopepathwindow.h"
 
30
 
 
31
QDict<KBSSETITelescopePathWindow> KBSSETITelescopePathWindow::s_windows
 
32
  = QDict<KBSSETITelescopePathWindow>();
 
33
 
 
34
KBSSETITelescopePathWindow *KBSSETITelescopePathWindow::window(const QString &workunit)
 
35
{
 
36
  KBSSETITelescopePathWindow *out = s_windows.find(workunit);
 
37
  
 
38
  if(NULL == out) {
 
39
    out = new KBSSETITelescopePathWindow(workunit);
 
40
    s_windows.insert(workunit, out);
 
41
  }
 
42
  
 
43
  return out;
 
44
}
 
45
 
 
46
KBSSETITelescopePathWindow::KBSSETITelescopePathWindow(const QString &workunit,
 
47
                                                       QWidget *parent, const char *name)
 
48
                          : KBSStandardWindow(parent, name),
 
49
                            m_view(new KBSSETISignalPlot(this)), m_workunit(workunit)
 
50
{
 
51
  setCaption(i18n("Telescope Path - %1").arg(workunit));
 
52
  
 
53
  setCentralWidget(m_view);
 
54
  
 
55
  setupActions();
 
56
}
 
57
 
 
58
QString KBSSETITelescopePathWindow::workunit() const
 
59
{
 
60
  return m_workunit;
 
61
}
 
62
 
 
63
void KBSSETITelescopePathWindow::attachProjectMonitor(KBSSETIProjectMonitor *projectMonitor)
 
64
{
 
65
  if(m_projectMonitors.containsRef(projectMonitor)) return;
 
66
  
 
67
  m_projectMonitors.append(projectMonitor);
 
68
  
 
69
  if(m_projectMonitors.count() == 1) {
 
70
    connectProjectMonitor(projectMonitor);
 
71
    update();
 
72
  }
 
73
}
 
74
 
 
75
void KBSSETITelescopePathWindow::detachProjectMonitor()
 
76
{
 
77
  KBSSETIProjectMonitor *projectMonitor = m_projectMonitors.first();
 
78
  
 
79
  if(NULL != projectMonitor) {
 
80
    disconnectProjectMonitor();
 
81
    m_projectMonitors.removeRef(projectMonitor);
 
82
  }
 
83
  
 
84
  projectMonitor = m_projectMonitors.first();
 
85
    
 
86
  if(NULL != projectMonitor) {
 
87
    connectProjectMonitor(projectMonitor);
 
88
    update();
 
89
  } else {
 
90
    close();
 
91
    destroy();
 
92
      
 
93
    s_windows.remove(m_workunit);     
 
94
  }
 
95
}
 
96
 
 
97
QPixmap KBSSETITelescopePathWindow::pixmap()
 
98
{
 
99
  return m_view->pixmap();
 
100
}
 
101
 
 
102
void KBSSETITelescopePathWindow::update()
 
103
{
 
104
  KBSSETIProjectMonitor *projectMonitor = m_projectMonitors.first();
 
105
  if(NULL == projectMonitor) return;
 
106
  
 
107
  const SETIResult *result = projectMonitor->result(m_workunit);
 
108
  
 
109
  if(NULL != result)
 
110
    m_view->setData(result->workunit_header);
 
111
}
 
112
 
 
113
void KBSSETITelescopePathWindow::update(const QString &workunit)
 
114
{
 
115
  if(workunit == m_workunit) update();
 
116
}
 
117
 
 
118
void KBSSETITelescopePathWindow::connectProjectMonitor(KBSSETIProjectMonitor *projectMonitor)
 
119
{
 
120
  connect(projectMonitor, SIGNAL(updatedResult(const QString &)), this, SLOT(update(const QString &)));
 
121
  connect(projectMonitor, SIGNAL(destroyed()), this, SLOT(detachProjectMonitor()));
 
122
  
 
123
  KBSBOINCMonitor *boincMonitor = projectMonitor->boincMonitor();
 
124
  
 
125
  connect(boincMonitor, SIGNAL(stateUpdated()), this, SLOT(update()));
 
126
}
 
127
 
 
128
void KBSSETITelescopePathWindow::disconnectProjectMonitor()
 
129
{
 
130
  disconnect(this, SLOT(update(const QString &)));
 
131
  disconnect(this, SLOT(detachProjectMonitor()));
 
132
  disconnect(this, SLOT(update()));
 
133
}
 
134
 
 
135
#include "kbssetitelescopepathwindow.moc"