1 /***************************************************************************
2 * KSystemLog, a system log viewer tool *
3 * Copyright (C) 2007 by Nicolas Ternisien *
4 * nicolas.ternisien@gmail.com *
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. *
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. *
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 "statusBar.h"
25 #include <QPushButton>
32 #include <kcombobox.h>
34 #include <ksqueezedtextlabel.h>
38 namespace KSystemLog
{
40 class StatusBarPrivate
{
44 QLabel
* lineCountLabel
;
46 //KSqueezedTextLabel* messageLabel;
48 KComboBox
* messageList
;
50 QLabel
* lastModificationLabel
;
52 QPushButton
* toggleHistory
;
56 StatusBar::StatusBar(QWidget
* parent
) :
58 d(new StatusBarPrivate()) {
60 d
->lineCountLabel
= new QLabel("", this);
61 d
->lineCountLabel
->setAlignment(Qt::AlignLeft
| Qt::AlignVCenter
);
63 //TODO Set a vertical right border to separate each labels
65 d->lineCountLabel->setFrameStyle(QFrame::Box | QFrame::Sunken);
66 d->lineCountLabel->setLineWidth(2);
67 d->lineCountLabel->setMidLineWidth(2);
69 addPermanentWidget(d
->lineCountLabel
, 1);
72 d->toggleHistory = new QPushButton(this);
73 d->toggleHistory->setIcon(KIcon("view-history"));
74 d->toggleHistory->setFlat(true);
75 addPermanentWidget(d->toggleHistory, 0);
77 connect(d->toggleHistory, SIGNAL(clicked()), this, SLOT(toggleHistory()));
81 d->messageLabel = new KSqueezedTextLabel("", this);
82 d->messageLabel->setAlignment(Qt::AlignLeft);
83 d->messageLabel->setTextElideMode(Qt::ElideRight);
84 addPermanentWidget(d->messageLabel, 4);
86 d
->messageList
= new KComboBox(this);
87 d
->messageList
->setInsertPolicy(QComboBox::InsertAtTop
);
88 d
->messageList
->setMaxVisibleItems(5);
89 connect(d
->messageList
, SIGNAL(currentIndexChanged(int)), this, SLOT(selectLastHistory()));
91 //TODO Define a specifical palette (and make it works !)
92 QPalette
palette(d
->messageList
->palette());
93 palette
.setColor(QPalette::HighlightedText
, Qt::red
); //palette.color(QPalette::Base)
94 palette
.setColor(QPalette::Base
, Qt::red
); //palette.color(QPalette::Base)
95 palette
.setColor(QPalette::Text
, QColor(212, 140, 95)); //palette.color(QPalette::Base)
96 d
->messageList
->setPalette(palette
);
97 //d->messageList->repaint();
99 addPermanentWidget(d
->messageList
, 4);
101 d
->lastModificationLabel
= new QLabel("", this);
102 d
->lastModificationLabel
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
103 addPermanentWidget(d
->lastModificationLabel
, 1);
108 StatusBar::~StatusBar() {
109 //QLabels are automatically deleted by Qt
113 void StatusBar::changeLineCountMessage(const QString
& lineCountMessage
) {
114 d
->lineCountLabel
->setText(lineCountMessage
);
117 void StatusBar::changeLastModification(const QTime
& lastModification
) {
118 d
->lastModificationLabel
->setText(i18n("Last updated: %1.", KGlobal::locale()->formatTime(lastModification
, true, false) ));
121 void StatusBar::changeMessage(const QString
& message
) {
122 //d->messageLabel->setText(message);
123 d
->messageList
->insertItem(0, i18n("%1: %2", KGlobal::locale()->formatTime(QTime::currentTime(), true, false), message
));
125 //100 log history message max.
126 if (d
->messageList
->count() > 100) {
127 d
->messageList
->removeItem(d
->messageList
->count() -1);
132 void StatusBar::selectLastHistory() {
133 d
->messageList
->setCurrentIndex(0);
136 void StatusBar::toggleHistory() {
137 logDebug() << "Toggling History..." << endl
;
138 d
->messageList
->showPopup();
143 #include "statusBar.moc"