#include <QApplication>
#include <QProgressDialog>
#include <QVBoxLayout>
class MyQtWatcher : public SimpleSubjectWatcher
{
size_t nfiles;
double progress;
size_t index;
double refprogress;
QWidget* win;
QProgressDialog* qtprogress;
public:
MyQtWatcher(Subject * s, const char *comment = "", QWidget *w = NULL, QProgressDialog* p = NULL, size_t n = 1):
SimpleSubjectWatcher(s,comment),nfiles(n),progress(0),index(0),refprogress(0),win(w),qtprogress(p){}
void ShowIteration()
{
index++;
assert( index <= nfiles );
refprogress = progress;
}
void ShowProgress(Subject *, const Event &evt)
{
const ProgressEvent &pe = dynamic_cast<const ProgressEvent&>(evt);
progress = refprogress + (1. / (double)nfiles ) * pe.GetProgress();
std::cout << "Global Progress: " << progress << " per file progress " << pe.GetProgress() << std::endl;
int i = (int)(progress * 100 + 0.5);
qtprogress->setValue(i);
win->show();
}
virtual void ShowDataSet(Subject *caller, const Event &evt)
{
(void)caller;
(void)evt;
}
};
}
int main(int argc, char *argv[])
{
if( argc < 4 )
{
std::cerr << argv[0] << " remote_server port filename" << std::endl;
return 1;
}
QApplication a(argc, argv);
std::ostringstream error_log;
const char *remote = argv[1];
int portno = atoi(argv[2]);
const char *filename = argv[3];
QVBoxLayout* layout = new QVBoxLayout;
QWidget* win = new QWidget;
QProgressDialog* progress = new QProgressDialog("Sending data...", "Cancel", 0, 100);
progress->setWindowModality(Qt::WindowModal);
layout->addWidget(progress,Qt::AlignCenter);
win->setLayout(layout);
gdcm::MyQtWatcher w( &scu, "QtWatcher", win, progress );
{
std::cerr << "Could not InitializeConnection" << std::endl;
return 1;
}
filenames.push_back( filename );
{
std::cerr << "Could not GenerateFromFilenames" << std::endl;
return 1;
}
{
std::cerr << "Could not Start" << std::endl;
return 1;
}
{
std::cerr << "Could not Store" << std::endl;
std::cerr << "Error log is:" << std::endl;
std::cerr << error_log.str() << std::endl;
return 1;
}
{
std::cerr << "Could not Stop" << std::endl;
return 1;
}
win->show();
return a.exec();
}
std::vector< FilenameType > FilenamesType
Definition gdcmDirectory.h:49
PresentationContextGenerator.
Definition gdcmPresentationContextGenerator.h:54
bool GenerateFromFilenames(const Directory::FilenamesType &files)
PresentationContextArrayType const & GetPresentationContexts()
Definition gdcmPresentationContextGenerator.h:83
ServiceClassUser.
Definition gdcmServiceClassUser.h:37
void SetTimeout(double t)
set/get Timeout
void SetPresentationContexts(std::vector< PresentationContext > const &pcs)
Set the Presentation Context used for the Association.
bool SendStore(const char *filename)
Execute a C-STORE on file on disk, named filename.
bool StopAssociation()
Stop the running association.
void SetHostname(const char *hostname)
Set the name of the called hostname (hostname or IP address)
void SetPort(uint16_t port)
Set port of remote host (called application)
bool StartAssociation()
Start the association. Need to call SetPresentationContexts before.
bool InitializeConnection()
void SetCalledAETitle(const char *aetitle)
set called ae title
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
static void SetErrorStream(std::ostream &os)
Explicitly set the stream which receive Error messages: