1 /***************************************************************************
2 DIA_dmx.cpp - description
3 -------------------
4 Indexer progress dialog
5
6 copyright : (C) 2005 by mean
7 email : fixounet@free.fr
8 ***************************************************************************/
9
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18 #include <math.h>
19
20 #include <QApplication>
21
22 #include "T_index_pg.h"
23 #include "ADM_default.h"
24 #include "DIA_idx_pg.h"
25 #include "ADM_vidMisc.h"
26 #include "ADM_toolkitQt.h"
27
28 extern void UI_purge( void );
29
setupUi(QDialog * Dialog)30 void Ui_iDialog::setupUi(QDialog *Dialog)
31 {
32 Dialog->setObjectName(QString::fromUtf8("Dialog"));
33 verticalLayout = new QWidget(Dialog);
34 verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
35 verticalLayout->setGeometry(QRect(9, 9, 215, 89));
36 vboxLayout = new QVBoxLayout(verticalLayout);
37 vboxLayout->setSpacing(6);
38 vboxLayout->setMargin(0);
39 vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
40 labelTimeLeft = new QLabel(verticalLayout);
41 labelTimeLeft->setObjectName(QString::fromUtf8("labelTimeLeft"));
42 vboxLayout->addWidget(labelTimeLeft);
43
44 labelImages = new QLabel(verticalLayout);
45 labelImages->setObjectName(QString::fromUtf8("labelImages"));
46 vboxLayout->addWidget(labelImages);
47
48 progressBar = new QProgressBar(verticalLayout);
49 progressBar->setObjectName(QString::fromUtf8("progressBar"));
50 progressBar->setValue(0);
51 progressBar->setOrientation(Qt::Horizontal);
52
53 vboxLayout->addWidget(progressBar);
54
55 QSize size(236, 111);
56 size = size.expandedTo(Dialog->minimumSizeHint());
57 Dialog->resize(size);
58
59 QMetaObject::connectSlotsByName(Dialog);
60 }
61
retranslateUi(QDialog * Dialog)62 void Ui_iDialog::retranslateUi(QDialog *Dialog)
63 {
64 Dialog->setWindowTitle(QApplication::translate("Dialog", "Indexing", 0));
65 labelTimeLeft->setText(QApplication::translate("Dialog", "Time Left : Infinity", 0));
66 labelImages->setText(QApplication::translate("Dialog", "# Images :", 0));
67
68 Q_UNUSED(Dialog);
69 }
70
71 static Ui_indexingDialog *dialog=NULL;
72
73 #if 0
74 static gint on_destroy_abort(GtkObject * object, gpointer user_data)
75 {
76 DIA_progressIndexing *pf;
77
78 UNUSED_ARG(object);
79 UNUSED_ARG(user_data);
80
81 pf=(Ui_indexingDialog *)user_data;
82 if(!GUI_Confirmation_HIG(QT_TRANSLATE_NOOP("indexing","Continue indexing"),QT_TRANSLATE_NOOP("indexing","Abort Requested"),QT_TRANSLATE_NOOP("indexing","Do you want to abort indexing ?")))
83 {
84 // pf->abortRequest();
85 abted=1;
86 }
87
88 return TRUE;
89
90 };
91 #endif
92
DIA_progressIndexing(const char * name)93 DIA_progressIndexing::DIA_progressIndexing(const char *name)
94 {
95 dialog=new Ui_indexingDialog(qtLastRegisteredDialog(), name);
96 qtRegisterDialog(dialog);
97 clock.reset();
98 aborted=0;
99 _nextUpdate=0;
100 dialog->show();
101 UI_purge();
102
103 }
~DIA_progressIndexing()104 DIA_progressIndexing::~DIA_progressIndexing()
105 {
106 ADM_assert(dialog);
107 qtUnregisterDialog(dialog);
108 delete dialog;
109 dialog=NULL;
110 }
isAborted(void)111 uint8_t DIA_progressIndexing::isAborted(void)
112 {
113 ADM_assert(dialog);
114 return dialog->abted;
115 }
abortRequest(void)116 uint8_t DIA_progressIndexing::abortRequest(void)
117 {
118 ADM_assert(dialog);
119 aborted=1;
120 dialog->abted=1;
121 return 1;
122 }
update(uint32_t done,uint32_t total,uint32_t nbImage,uint32_t hh,uint32_t mm,uint32_t ss)123 uint8_t DIA_progressIndexing::update(uint32_t done,uint32_t total, uint32_t nbImage, uint32_t hh, uint32_t mm, uint32_t ss)
124 {
125 uint32_t tim;
126 #define GUI_UPDATE_RATE 1000
127
128 tim=clock.getElapsedMS();
129 if(tim>_nextUpdate)
130 {
131 char string[256];
132 double f;
133 uint32_t tom,zhh,zmm,zss,zmms;
134
135 _nextUpdate=tim+GUI_UPDATE_RATE;
136 sprintf(string,"%02d:%02d:%02d",hh,mm,ss);
137 dialog->setTime(string);
138
139
140 sprintf(string,QT_TRANSLATE_NOOP("indexing","# Images :%0" PRIu32),nbImage);
141 dialog->setImage(string);
142
143 f=done;
144 f/=total;
145
146 dialog->setPercent(f);
147
148 /* compute ETL */
149 // Do a simple relation between % and time
150 // Elapsed time =total time*percent
151 if(f<0.01) return 1;
152 f=tim/f;
153 // Tom is total time
154 tom=(uint32_t)floor(f);
155 if(tim>tom) return 1;
156 tom=tom-tim;
157 ms2time(tom,&zhh,&zmm,&zss,&zmms);
158 sprintf(string,QT_TRANSLATE_NOOP("indexing","Time Left :%02d:%02d:%02d"),zhh,zmm,zss);
159 dialog->setETA(string);
160 UI_purge();
161 }
162 return 1;
163 }
164 //****************************** CLASS ***********************
Ui_indexingDialog(QWidget * parent,const char * name)165 Ui_indexingDialog::Ui_indexingDialog(QWidget *parent, const char *name) : QDialog(parent)
166 {
167 abted=0;
168 ui.setupUi(this);
169 }
~Ui_indexingDialog()170 Ui_indexingDialog::~Ui_indexingDialog()
171 {
172
173 }
setTime(const char * f)174 void Ui_indexingDialog::setTime(const char *f)
175 {
176 //printf("Time:%s\n",f);
177 }
setImage(const char * f)178 void Ui_indexingDialog::setImage(const char *f)
179 {
180 dialog->ui.labelImages->setText(QString::fromUtf8(f));
181 }
182
setETA(const char * f)183 void Ui_indexingDialog::setETA(const char *f)
184 {
185 // printf("Eta:%s\n",f);
186 dialog->ui.labelTimeLeft->setText(QString::fromUtf8(f));
187 }
setPercent(float f)188 void Ui_indexingDialog::setPercent(float f)
189 {
190 dialog->ui.progressBar->setValue((int)(100.*f));
191
192 }
193
194
195
196 // EOF
197