summaryrefslogtreecommitdiffstats
path: root/clients/tde/src/app/views/instrumentview.cpp
blob: e9f3f5102f0075de6cb065272c6b1d7eafed0da1 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//Author:    Timothy Pearson <kb9vqf@pearsoncomputing.net>, (C) 2012
//Copyright: See COPYING file that comes with this distribution

#include "instrumentview.h"

#include <tqtimer.h>

#include <klibloader.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmdimainfrm.h>

namespace RemoteLab {

InstrumentView::InstrumentView(const TQString &library, TQWidget *parentWidget, const char *name, WFlags f)
	: KMdiChildView(parentWidget, name, f)
	, m_libraryName(library)
	, m_instrumentPart( 0 )
	, m_fixedSize( false )
	, m_canary( NULL )
{
	m_mainForm = dynamic_cast<KMdiMainFrm*>(parentWidget);
	init();
}

InstrumentView::InstrumentView(const TQString &library, const TQString &caption, TQWidget *parentWidget, const char *name, WFlags f)
	: KMdiChildView(caption, parentWidget, name, f)
	, m_libraryName(library)
	, m_instrumentPart( 0 )
	, m_fixedSize( false )
	, m_canary( NULL )
{
	m_mainForm = dynamic_cast<KMdiMainFrm*>(parentWidget);
	init();
}

InstrumentView::~InstrumentView() {
	if (m_canary) {
		*m_canary = true;
	}
}

void InstrumentView::init() {
	KLibFactory *factory = KLibLoader::self()->factory(m_libraryName.ascii());
	
	if (!factory) {
		KMessageBox::error( this, i18n("TDE could not find the %1 Part, or the Remote Laboratory Communications Analyzer Part could not be started. Did you make install?").arg(m_libraryName) );
		TQTimer::singleShot(0, this, SLOT(close()));
	}
	else {
		m_instrumentPart = (InstrumentPart *)factory->create(TQT_TQOBJECT(this), "part", "KParts::RemoteInstrumentPart");
		m_instrumentPart->setMDIMainForm(m_mainForm);
		setIcon(SmallIcon(m_libraryName));
		connect(m_instrumentPart, SIGNAL(statusMessageSet(const TQString&)), this, SLOT(setStatusMessage(const TQString&)));
		connect(m_instrumentPart, SIGNAL(usingFixedSizeChanged(bool)), this, SLOT(setUsingFixedSize(bool)));
		TQWidget *childPartWidget = m_instrumentPart->widget();
		if (childPartWidget) {
			childPartWidget->installEventFilter(this);
		}
	}
}

bool InstrumentView::eventFilter(TQObject *o, TQEvent *e) {
	TQWidget *childPartWidget = m_instrumentPart->widget();
	if (childPartWidget) {
		if (o == childPartWidget) {
			if ((e->type() == TQEvent::Resize) || (e->type() == TQEvent::LayoutHint)) {
				setChildSizeData();
			}
		}
	}

	// Allow event processing by other routines
	return FALSE;
}

void InstrumentView::setChildSizeData() {
	if (m_instrumentPart) {
		TQWidget *childPartWidget = m_instrumentPart->widget();
		if (childPartWidget) {
			if (m_fixedSize) {
				setFixedSize(childPartWidget->sizeHint());
			}
			else {
				TQSize minimumSizeHint;
				if (childPartWidget->layout()) {
					minimumSizeHint = childPartWidget->layout()->minimumSize();
				}
				else {
					minimumSizeHint = childPartWidget->minimumSize();
				}
				setMinimumSize(minimumSizeHint.width(), minimumSizeHint.height());
				resize(childPartWidget->size());
			}
		}
	}
}

void InstrumentView::setUsingFixedSize(bool fixed) {
	m_fixedSize = fixed;
	if (!fixed) {
		setMinimumSize(0, 0);
		setMaximumSize(TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX);
	}
	setChildSizeData();
}

void InstrumentView::resizeEvent(TQResizeEvent *) {
	setChildSizeData();
}

TQPtrList<KAction> InstrumentView::menuActionList() {
	if (m_instrumentPart) {
		return m_instrumentPart->menuActionList();
	}
	else {
		return TQPtrList<KAction>();
	}
}

void InstrumentView::setStatusMessage(const TQString& message) {
	emit(statusMessageSet(message));
}

bool InstrumentView::queryExit() {
	if (!m_instrumentPart) {	// apparently std::exit() still calls this function, and abort() causes a crash..
		return true;
	}

	m_instrumentPart->closeURL();
	return true;
}

void InstrumentView::closeConnections() {
	queryExit();
}

void InstrumentView::connectServer(TQString server) {
	if (!m_canary) {
		m_canary = new bool;
		*m_canary = false;
	}
	bool* canary = m_canary;

	if (m_instrumentPart) {
		if (m_instrumentPart->openURL(KURL(server))) {		// This can call processEvents, therefore this object may not exist when it returns!
			if (*canary == true) {
				delete canary;
				return;
			}
			TQTimer::singleShot(0, this, SLOT(close()));
		}
	}

	delete m_canary;
	m_canary = NULL;
}

/**********************************************
  SESSION MANAGEMENT
 **********************************************/

void InstrumentView::saveProperties( KConfig *config ) {
}

void InstrumentView::readProperties( KConfig *config ) {
}

} //namespace RemoteLab