File indexing completed on 2024-05-05 05:48:56

0001 /*
0002     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "loadingBar.h"
0008 
0009 #include <QApplication>
0010 #include <QHBoxLayout>
0011 #include <QLabel>
0012 #include <QProgressBar>
0013 #include <QPushButton>
0014 #include <QVBoxLayout>
0015 
0016 #include <KLocalizedString>
0017 LoadingBar::LoadingBar(QWidget *parent)
0018     : QWidget(parent)
0019 {
0020     auto widgetLayout = new QHBoxLayout(this);
0021 
0022     widgetLayout->addStretch();
0023 
0024     auto layout = new QVBoxLayout();
0025     widgetLayout->addLayout(layout);
0026 
0027     widgetLayout->addStretch();
0028 
0029     mLabel = new QLabel(i18n("Loading Progress..."), this);
0030     mLabel->setMinimumWidth(250);
0031     layout->addWidget(mLabel, 1, Qt::AlignBottom);
0032 
0033     mProgressBar = new QProgressBar(this);
0034     mProgressBar->setRange(0, 100);
0035     mProgressBar->setMinimumWidth(250);
0036     layout->addWidget(mProgressBar, 1, Qt::AlignCenter | Qt::AlignTop);
0037 }
0038 
0039 LoadingBar::~LoadingBar()
0040 {
0041 }
0042 
0043 QProgressBar *LoadingBar::progressBar() const
0044 {
0045     return mProgressBar;
0046 }
0047 
0048 void LoadingBar::startLoading(const LogMode &logMode, const LogFile &logFile, int fileIndex, int fileCount)
0049 {
0050     Q_EMIT displayed(true);
0051 
0052     mProgressBar->setValue(0);
0053 
0054     // Several files to load
0055     if (fileCount > 1 && fileIndex >= 1) {
0056         if (mFirstLoading) {
0057             mLabel->setText(i18np("Loading <b>%2</b>...<br /><i>%3</i> - (<b>%4</b>)",
0058                                   "Loading <b>%2</b>...<br /><i>%3</i> - (<b>%4</b>/%1 files)",
0059                                   fileCount,
0060                                   logMode.name(),
0061                                   logFile.url().toLocalFile(),
0062                                   fileIndex));
0063         } else {
0064             mLabel->setText(i18np("Reloading <b>%2</b>...<br /><i>%3</i> - (<b>%4</b>)",
0065                                   "Reloading <b>%2</b>...<br /><i>%3</i> - (<b>%4</b>/%1 files)",
0066                                   fileCount,
0067                                   logMode.name(),
0068                                   logFile.url().toLocalFile(),
0069                                   fileIndex));
0070         }
0071     }
0072     // Only one file
0073     else {
0074         if (mFirstLoading) {
0075             mLabel->setText(i18n("Loading <b>%1</b>...<br /><i>%2</i>", logMode.name(), logFile.url().toLocalFile()));
0076         } else {
0077             mLabel->setText(i18n("Reloading <b>%1</b>...<br /><i>%2</i>", logMode.name(), logFile.url().toLocalFile()));
0078         }
0079     }
0080 }
0081 
0082 void LoadingBar::endLoading()
0083 {
0084     Q_EMIT displayed(false);
0085 
0086     mProgressBar->setValue(100);
0087 
0088     // If the endLoading has been called one time, it means it has already been loaded
0089     mFirstLoading = false;
0090 }
0091 
0092 void LoadingBar::progressLoading()
0093 {
0094     mProgressBar->setValue(mProgressBar->value() + 1);
0095 
0096     // kapp->processEvents();
0097     qApp->processEvents();
0098 }
0099 
0100 #include "moc_loadingBar.cpp"