23 #include <dcmtk/dcmnet/dimse.h> 25 #include <QMessageBox> 34 this->setupUi (
this );
36 treeWidget->setColumnWidth ( 1, 100 );
37 treeWidget->setColumnWidth ( 2, 100 );
38 treeWidget->setColumnWidth ( 3, 150 );
40 serverNameEdit->setEnabled (
false );
41 serverAetitleEdit->setEnabled (
false );
42 serverPortEdit->setEnabled (
false );
43 serverHostnameEdit->setEnabled (
false );
44 removeButton->setEnabled (
false );
45 echoButton->setEnabled (
false );
48 this->initConnections();
55 void QtDcmServersDicomSettingsWidget::initConnections()
57 QObject::connect ( treeWidget, &QTreeWidget::currentItemChanged,
59 QObject::connect ( serverNameEdit, &QLineEdit::textChanged,
61 QObject::connect ( serverHostnameEdit, &QLineEdit::textChanged,
63 QObject::connect ( serverAetitleEdit, &QLineEdit::textChanged,
65 QObject::connect ( serverPortEdit, &QLineEdit::textChanged,
67 QObject::connect ( addButton, &QPushButton::clicked,
69 QObject::connect ( removeButton, &QPushButton::clicked,
71 QObject::connect ( echoButton, &QPushButton::clicked,
80 for (
int i = 0; i < prefs->
servers().size(); i++ ) {
81 QTreeWidgetItem * item =
new QTreeWidgetItem ( treeWidget );
82 item->setText ( 0, prefs->
servers().at ( i ).name() );
83 item->setData ( 0, 1, QVariant ( prefs->
servers().at ( i ).name() ) );
85 item->setText ( 1, prefs->
servers().at ( i ).aetitle() );
86 item->setData ( 1, 1, QVariant ( prefs->
servers().at ( i ).aetitle() ) );
88 item->setText ( 2, prefs->
servers().at ( i ).port() );
89 item->setData ( 2, 1, QVariant ( prefs->
servers().at ( i ).port() ) );
91 item->setText ( 3, prefs->
servers().at ( i ).address() );
92 item->setData ( 3, 1, QVariant ( prefs->
servers().at ( i ).address() ) );
94 item->setData ( 4, 1, QVariant ( i ) );
101 QTreeWidgetItem * root = treeWidget->invisibleRootItem();
103 QList<QtDcmServer> servers;
104 for (
int i = 0; i < root->childCount() ; i++) {
106 server.
setName(root->child ( i )->data ( 0, 1 ).toString());
107 server.
setAetitle(root->child ( i )->data ( 1, 1 ).toString());
108 server.
setPort(root->child ( i )->data ( 2, 1 ).toString());
109 server.
setAddress(root->child ( i )->data ( 3, 1 ).toString());
119 QTreeWidgetItem * item =
new QTreeWidgetItem ( treeWidget );
126 item->setText ( 0, server.
name() );
127 item->setData ( 0, 1, QVariant ( server.
name() ) );
129 item->setText ( 1, server.
aetitle() );
130 item->setData ( 1, 1, QVariant ( server.
aetitle() ) );
132 item->setText ( 2, server.
port() );
133 item->setData ( 2, 1, QVariant ( server.
port().toInt() ) );
135 item->setText ( 3, server.
address() );
136 item->setData ( 3, 1, QVariant ( server.
address() ) );
138 item->setData ( 4, 1, QVariant ( prefs->
servers().size() - 1 ) );
145 QTreeWidgetItem * root = treeWidget->invisibleRootItem();
146 if (!treeWidget->currentItem()) {
150 const int index = root->indexOfChild ( treeWidget->currentItem());
151 QTreeWidgetItem * item = treeWidget->currentItem();
152 root->removeChild(item);
157 if ( root->childCount() == 0 ) {
158 echoButton->setEnabled (
false );
159 removeButton->setEnabled (
false );
165 echoButton->setEnabled (
true );
166 removeButton->setEnabled (
true );
167 serverNameEdit->setEnabled (
true );
168 serverAetitleEdit->setEnabled (
true );
169 serverPortEdit->setEnabled (
true );
170 serverHostnameEdit->setEnabled (
true );
171 serverNameEdit->setText ( current->data ( 0, 1 ).toString() );
172 serverAetitleEdit->setText ( current->data ( 1, 1 ).toString() );
173 serverPortEdit->setText ( current->data ( 2, 1 ).toString() );
174 serverHostnameEdit->setText ( current->data ( 3, 1 ).toString() );
179 QRegExp rexp (
"[A-Z0-9._-]{1,50}" );
180 QRegExpValidator * valid =
new QRegExpValidator ( rexp,
this );
181 serverAetitleEdit->setValidator ( valid );
182 treeWidget->currentItem()->setText ( 1, text );
183 treeWidget->currentItem()->setData ( 1, 1, QVariant ( text ) );
188 treeWidget->currentItem()->setText ( 3, text );
189 treeWidget->currentItem()->setData ( 3, 1, QVariant ( text ) );
194 treeWidget->currentItem()->setText ( 0, text );
195 treeWidget->currentItem()->setData ( 0, 1, QVariant ( text ) );
200 QIntValidator * valid =
new QIntValidator ( 1000, 100000,
this );
201 serverPortEdit->setValidator ( valid );
202 treeWidget->currentItem()->setText ( 2, text );
203 treeWidget->currentItem()->setData ( 2, 1, QVariant ( text ) );
208 if ( !treeWidget->currentItem() ) {
214 const QString aet = prefs->
aetitle();
215 const QString serverAet = treeWidget->currentItem()->data ( 1, 1 ).toString();
216 const QString hostname = prefs->
hostname();
217 const QString serverHostname = treeWidget->currentItem()->data ( 3, 1 ).toString();
218 const QString serverPort = treeWidget->currentItem()->data ( 2, 1 ).toString();
220 T_ASC_Network *net = 0;
222 OFCondition cond = ASC_initializeNetwork ( NET_REQUESTOR, 0, 30 , &net );
223 if ( cond != EC_Normal ) {
224 QMessageBox msgBox( QApplication::activeWindow() );
225 msgBox.setIcon ( QMessageBox::Critical );
226 msgBox.setText (
"Cannot initialize network" );
229 ASC_dropNetwork ( &net );
234 QTcpSocket * socket =
new QTcpSocket(
this);
235 socket->connectToHost(serverHostname, serverPort.toInt());
236 if (!socket->waitForConnected(1000)) {
237 QMessageBox msgBox( QApplication::activeWindow() );
238 msgBox.setIcon ( QMessageBox::Information );
239 msgBox.setText (
"Cannot connect to server " + serverHostname +
" on port " + serverPort +
" !" );
242 ASC_dropNetwork ( &net );
247 socket->disconnectFromHost();
250 T_ASC_Parameters *params;
252 cond = ASC_createAssociationParameters ( ¶ms, ASC_DEFAULTMAXPDU );
255 cond = ASC_setAPTitles ( params, aet.toUtf8().data(), serverAet.toUtf8().data(), NULL );
258 cond = ASC_setPresentationAddresses ( params, hostname.toUtf8().data(), QString ( serverHostname +
":" + serverPort ).toLatin1().data() );
261 const char* ts[] = { UID_LittleEndianImplicitTransferSyntax };
264 cond = ASC_addPresentationContext ( params, 1, UID_VerificationSOPClass, ts, 1 );
267 T_ASC_Association *assoc = 0;
269 if ( ASC_requestAssociation ( net, params, &assoc ).good() ) {
270 if ( ASC_countAcceptedPresentationContexts ( params ) == 1 ) {
272 DIC_US
id = assoc->nextMsgID++;
274 DcmDataset *sd = NULL;
276 DIMSE_echoUser ( assoc,
id, DIMSE_BLOCKING, 0, &status, &sd );
279 QMessageBox msgBox( QApplication::activeWindow() );
280 msgBox.setIcon ( QMessageBox::Information );
281 msgBox.setText (
"Echo request successful !" );
285 QMessageBox msgBox( QApplication::activeWindow() );
286 msgBox.setIcon ( QMessageBox::Critical );
287 msgBox.setText (
"Wrong presentation context, echo request failed" );
292 QMessageBox msgBox( QApplication::activeWindow() );
293 msgBox.setIcon ( QMessageBox::Critical );
294 msgBox.setText (
"Wrong dicom association, echo request failed" );
298 ASC_releaseAssociation ( assoc );
299 ASC_destroyAssociation ( &assoc );
300 ASC_dropNetwork ( &net );
QString port() const
PACS server port getter (QtDcm only ports between 1000 and 100000)
void setAetitle(QString _aetitle)
PACS AETitle setter.
static QtDcmPreferences * instance()
void setAddress(QString _server)
PACS server hostname setter.
QString aetitle() const
PACS AETitle getter.
QString name() const
Description name getter.
QList< QtDcmServer > servers() const
QtDcm server list getter.
void setPort(QString port)
PACS server port setter (QtDcm only ports between 1000 and 100000)
void setServers(const QList< QtDcmServer > &servers)
QtDcm server list setter.
QString aetitle() const
QtDcm local AETitle getter.
void setName(QString _name)
PACS Name setter.
QString address() const
PACS server hostname getter.
This class is a representation of a Dicom PACS server.
void addServer(const QtDcmServer &server)
Add server to the QList.
Class that manages the settings of QtDcm.
void removeServer(int index)
Remove server from the QList at position i.