Proof-reading - fixed one usage of the i18n plural form (it wasn't doing before,...
[kdeadmin.git] / ksystemlog / src / lib / loadingBar.cpp
blob89614731b966a3bebf4fa1e7076b4183cf51728b
1 /***************************************************************************
2 * KSystemLog, a system log viewer tool *
3 * Copyright (C) 2007 by Nicolas Ternisien *
4 * nicolas.ternisien@gmail.com *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
22 #include "loadingBar.h"
24 #include <QWidget>
25 #include <QPushButton>
26 #include <QLabel>
27 #include <QProgressBar>
28 #include <QVBoxLayout>
29 #include <QHBoxLayout>
31 #include <klocale.h>
32 #include <kapplication.h>
33 #include <kiconloader.h>
35 class LoadingBarPrivate {
36 public:
37 //Attributes managing the position in the files loading of each log
38 int fileCount;
39 int currentFileIndex;
41 bool firstLoading;
43 QLabel* label;
45 QProgressBar* progressBar;
49 LoadingBar::LoadingBar(QWidget* parent) :
50 QWidget(parent),
51 d(new LoadingBarPrivate())
54 d->firstLoading = true;
56 QHBoxLayout* widgetLayout = new QHBoxLayout();
57 setLayout(widgetLayout);
59 widgetLayout->addStretch();
61 QVBoxLayout* layout = new QVBoxLayout();
62 widgetLayout->addLayout(layout);
64 widgetLayout->addStretch();
66 d->label = new QLabel(i18n("Loading Progress..."));
67 d->label->setMinimumWidth(250);
68 layout->addWidget(d->label, 1, Qt::AlignBottom);
70 d->progressBar = new QProgressBar();
71 d->progressBar->setRange(0, 100);
72 d->progressBar->setMinimumWidth(250);
73 layout->addWidget(d->progressBar, 1, Qt::AlignCenter | Qt::AlignTop);
77 LoadingBar::~LoadingBar() {
78 delete d;
82 QProgressBar* LoadingBar::progressBar() {
83 return d->progressBar;
86 void LoadingBar::startLoading(const LogMode& logMode, const LogFile& logFile, int fileIndex, int fileCount) {
87 emit displayed(true);
89 d->progressBar->setValue(0);
91 //Several files to load
92 if (fileCount>1 && fileIndex>=1) {
93 if (d->firstLoading)
94 d->label->setText(i18np("Loading <b>%2</b>...<br /><i>%3</i>",
95 "Loading <b>%2</b>...<br /><i>%3</i> - (<b>%4</b>/%1 files)",
96 fileCount, logMode.name(), logFile.url().path(), fileIndex));
97 else
98 d->label->setText(i18np("Reloading <b>%2</b>...<br /><i>%3</i>",
99 "Reloading <b>%2</b>...<br /><i>%3</i> - (<b>%4</b>/%1 files)",
100 fileCount, logMode.name(), logFile.url().path(), fileIndex));
102 //Only one file
103 else {
104 if (d->firstLoading)
105 d->label->setText(i18n("Loading <b>%1</b>...<br /><i>%2</i>", logMode.name(), logFile.url().path()));
106 else
107 d->label->setText(i18n("Reloading <b>%1</b>...<br /><i>%2</i>", logMode.name(), logFile.url().path()));
112 void LoadingBar::endLoading() {
113 emit displayed(false);
115 d->progressBar->setValue(100);
117 //If the endLoading has been called one time, it means it has already been loaded
118 d->firstLoading=false;
122 void LoadingBar::progressLoading() {
123 d->progressBar->setValue( d->progressBar->value() + 1 );
125 kapp->processEvents();
128 #include "loadingBar.moc"