| 1 |
/* dvbcut |
| 2 |
Copyright (c) 2005 Sven Over <[email protected]> |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id$ */ |
| 20 |
|
| 21 |
#ifndef _GNU_SOURCE |
| 22 |
#define _GNU_SOURCE |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <cstdio> |
| 26 |
#include <cstdarg> |
| 27 |
#include <cstdlib> |
| 28 |
|
| 29 |
#include <qprogressbar.h> |
| 30 |
#include <qtextbrowser.h> |
| 31 |
#include <qpushbutton.h> |
| 32 |
#include <qapplication.h> |
| 33 |
#include <QCloseEvent> |
| 34 |
#include "progresswindow.h" |
| 35 |
|
| 36 |
progresswindow::progresswindow(QWidget *parent) |
| 37 |
:QDialog(parent), logoutput(), |
| 38 |
cancelwasclicked(false), waitingforclose(false) |
| 39 |
{ |
| 40 |
ui = new Ui::progresswindowbase(); |
| 41 |
ui->setupUi(this); |
| 42 |
setModal(true); |
| 43 |
|
| 44 |
fc_head.setFontWeight(QFont::Bold); |
| 45 |
fc_head.setFontUnderline(true); |
| 46 |
|
| 47 |
fc_warn.setForeground(Qt::red); |
| 48 |
|
| 49 |
fc_error.setFontWeight(QFont::Bold); |
| 50 |
fc_error.setForeground(Qt::red); |
| 51 |
fc_error.setFontUnderline(true); |
| 52 |
|
| 53 |
QPalette palette; |
| 54 |
palette.setColor(ui->cancelbutton->backgroundRole(), QColor( 255,0,0 )); |
| 55 |
ui->cancelbutton->setPalette(palette); |
| 56 |
|
| 57 |
show(); |
| 58 |
qApp->processEvents(); |
| 59 |
} |
| 60 |
|
| 61 |
progresswindow::~progresswindow() |
| 62 |
{ |
| 63 |
delete ui; |
| 64 |
} |
| 65 |
|
| 66 |
void progresswindow::closeEvent(QCloseEvent *e) |
| 67 |
{ |
| 68 |
if (waitingforclose) |
| 69 |
e->accept(); |
| 70 |
else |
| 71 |
e->ignore(); |
| 72 |
} |
| 73 |
|
| 74 |
void progresswindow::finish() |
| 75 |
{ |
| 76 |
ui->cancelbutton->setEnabled(false); |
| 77 |
waitingforclose=true; |
| 78 |
ui->cancelbutton->setText( tr( "Close" ) ); |
| 79 |
|
| 80 |
QPalette palette; |
| 81 |
palette.setColor(ui->cancelbutton->backgroundRole(), QColor( 0,255,0 )); |
| 82 |
ui->cancelbutton->setPalette(palette); |
| 83 |
|
| 84 |
ui->cancelbutton->setEnabled(true); |
| 85 |
exec(); |
| 86 |
} |
| 87 |
|
| 88 |
void progresswindow::setprogress(int permille) |
| 89 |
{ |
| 90 |
if (permille==currentprogress) |
| 91 |
return; |
| 92 |
currentprogress=permille; |
| 93 |
ui->progressbar->setValue(permille); |
| 94 |
qApp->processEvents(); |
| 95 |
} |
| 96 |
|
| 97 |
void progresswindow::printmsg(const QString &str, const QTextCharFormat &format) |
| 98 |
{ |
| 99 |
ui->logbrowser->setCurrentCharFormat(format); |
| 100 |
ui->logbrowser->append(str); |
| 101 |
qApp->processEvents(); |
| 102 |
} |
| 103 |
|
| 104 |
void progresswindow::print(const QString &str) |
| 105 |
{ |
| 106 |
printmsg(str, fc_normal); |
| 107 |
} |
| 108 |
|
| 109 |
void progresswindow::printheading(const QString &str) |
| 110 |
{ |
| 111 |
printmsg(str, fc_head); |
| 112 |
} |
| 113 |
|
| 114 |
void progresswindow::printinfo(const QString &str) |
| 115 |
{ |
| 116 |
printmsg(str, fc_info); |
| 117 |
} |
| 118 |
|
| 119 |
void progresswindow::printerror(const QString &str) |
| 120 |
{ |
| 121 |
printmsg(str, fc_error); |
| 122 |
} |
| 123 |
|
| 124 |
void progresswindow::printwarning(const QString &str) |
| 125 |
{ |
| 126 |
printmsg(str, fc_warn); |
| 127 |
} |
| 128 |
|
| 129 |
void progresswindow::clickedcancel() |
| 130 |
{ |
| 131 |
if ((cancelwasclicked==false) && (waitingforclose==false)) { |
| 132 |
// button function is cancel |
| 133 |
cancelwasclicked=true; |
| 134 |
ui->cancelbutton->setEnabled(false); |
| 135 |
qApp->processEvents(); |
| 136 |
ui->cancelbutton->setText( tr( "Close" ) ); |
| 137 |
|
| 138 |
QPalette palette; |
| 139 |
palette.setColor(ui->cancelbutton->backgroundRole(), QColor( 0,255,0 )); |
| 140 |
ui->cancelbutton->setPalette(palette); |
| 141 |
|
| 142 |
ui->cancelbutton->setEnabled(true); |
| 143 |
} else { |
| 144 |
// button function is close |
| 145 |
close(); |
| 146 |
} |
| 147 |
} |