diff --git a/kmnewiostatus.cpp b/kmnewiostatus.cpp new file mode 100644 index 000000000..228cc0906 --- /dev/null +++ b/kmnewiostatus.cpp @@ -0,0 +1,84 @@ +// KMIOStatus: base class impl. to show transmission state +// Author: Markus Wuebben +// This code is published under the GPL. + +#include +#include "kmnewiostatus.h" +#include "kmnewiostatus.moc" + +KMIOStatus::KMIOStatus(QWidget *parent, const char *name) + :QWidget(parent, name) { + + initMetaObject(); + +} + +void KMIOStatus::setHost(QString host) { + + _host = host; + update(); + +} + +QString KMIOStatus::host() { + + return _host; + +} + +void KMIOStatus::setTask(task type) { + + _task = type; + update(); // new task new text. Specified in update() + +} + +// Reimplement for your impl. +void KMIOStatus::update() { + +} + +KMIOStatus::task KMIOStatus::Task() { + + return _task; + +} + + +void KMIOStatus::transmissionCompleted() { + +} + +KMIOStatus::~KMIOStatus() { + +} + +void KMIOStatus::updateProgressBar(int,int) { + +} + +bool KMIOStatus::abortRequested() { + + return abortPressed; + +} + + +void KMIOStatus::abortPressed() { + + cout << "Abort requested...\n"; + abortPressedBool = true; + emit abort(); + +} + + + + + + + + + + + diff --git a/kmnewiostatus.h b/kmnewiostatus.h new file mode 100644 index 000000000..783d5e98a --- /dev/null +++ b/kmnewiostatus.h @@ -0,0 +1,70 @@ +// KMIOStatus: base class to show transmission state +// Author: Markus Wuebben +// This code is published under the GPL. + +#ifndef KMIO_H +#define KMIO_H + +#include +#include +#include +#include + +class KMIOStatus : public QWidget +{ + Q_OBJECT + public: + + /** Which kind of widget you want **/ + enum task { SEND, RETRIEVE } ; + + KMIOStatus(QWidget *parent = 0, const char *name = 0); + ~KMIOStatus(); + + + public slots: + + /** Check if abort was pressed **/ + bool abortRequested(); + + /**update the ProgressBar. index is current message, message is + number of all messages **/ + virtual void updateProgressBar(int index, int messages ); + + /** Set host to download or send to **/ + void setHost(QString); + + /** Get host to download from or send to **/ + QString host(); + + /** Set widget's task **/ + void setTask(task); + + /** Get widget`s task **/ + task Task(); + + /** Tell widget that the tranmission has been completed **/ + virtual void transmissionCompleted(); + + private slots: + virtual void abortPressed(); + + /** update the widget as you need to e.g setCaption **/ + virtual void update(); + + signals: + + /** Emitted when abort was pressed **/ + void abort(); + + protected: + + bool abortPressedBool; + QString _host; + task _task; + +}; + +#endif + + diff --git a/kmnewiostatuswdg.cpp b/kmnewiostatuswdg.cpp new file mode 100644 index 000000000..ad971513f --- /dev/null +++ b/kmnewiostatuswdg.cpp @@ -0,0 +1,90 @@ +#include +#include "kmnewiostatuswdg.h" +#include "kmnewiostatuswdg.moc" + +KMIOStatusWdg::KMIOStatusWdg(QWidget *parent, const char *name, + task type , QString host) + :KMIOStatus(parent,name) { + + + initMetaObject(); + abortPressedBool = false; + + setTask(type); + setHost(host); + + progressBar = new KProgress(this); + progressBar->setGeometry(35,45,200,30); + + abortBt = new QPushButton("Abort",this); + abortBt->resize(abortBt->sizeHint()); + abortBt->move(110,90); + connect(abortBt,SIGNAL(clicked()),this,SLOT(abortPressed())); + + msgLbl = new QLabel(this); + msgLbl->setGeometry(45,15,200,25); + msgLbl->setText("Preparing transmission..."); + setMaximumSize(270,140); + setMinimumSize(270,140); + + update(); + +} + +void KMIOStatusWdg::update() { + + if(Task() == SEND) + setCaption("Sending messages to " + host()); + else + if(Task() == RETRIEVE) + setCaption("Retrieving messages from " + host()); + + QWidget::update(); + +} + + +void KMIOStatusWdg::transmissionCompleted() { + + msgLbl->setText("Transmission completed..."); + +} + +KMIOStatusWdg::~KMIOStatusWdg() { + +} + +void KMIOStatusWdg::updateProgressBar(int index ,int of) { + + float value; + QString tmp; + + value = ((float)index/(float)of)*100; + if(Task() == RETRIEVE) + tmp.sprintf("Downloading message %i of %i",index,of); + else + if(Task() == SEND) + tmp.sprintf("Sending message %i of %i",index,of); + + msgLbl->setText(tmp); + progressBar->setValue((int)value); + +} + + + +void KMIOStatusWdg::abortPressed() { + + cout << "Abort requested...\n"; + msgLbl->setText("Aborting transmission...\n"); + abortPressedBool = true; + emit abort(); + +} + + + + + + + diff --git a/kmnewiostatuswdg.h b/kmnewiostatuswdg.h new file mode 100644 index 000000000..651005cd8 --- /dev/null +++ b/kmnewiostatuswdg.h @@ -0,0 +1,48 @@ +// KMIOStatusWdg: class to show transmission state +// Author: Markus Wuebben +// This code is published under the GPL. + +#ifndef KMIOWDG_H +#define KMIOWDG_H + +#include +#include +#include +#include +#include +#include "kmnewiostatus.h" + +class KMIOStatusWdg : public KMIOStatus +{ + Q_OBJECT + public: + + KMIOStatusWdg(QWidget *parent = 0, const char * name = 0, + task = 0, QString host = 0 ); + ~KMIOStatusWdg(); + + + public slots: + + /**update the ProgressBar. index is current message, message is + number of all messages **/ + void updateProgressBar(int index, int messages ); + + /** Tell widget that the tranmission has been completed **/ + void transmissionCompleted(); + + private slots: + void abortPressed(); + void update(); + + private: + + KProgress *progressBar; + QPushButton *abortBt; + QLabel *msgLbl; + +}; + +#endif + +