Proof-reading - fixed one usage of the i18n plural form (it wasn't doing before,...
[kdeadmin.git] / ksystemlog / src / detailDialog.cpp
blob59e708e1b22fa35e98b5af78cfbc69c4330a1b3c
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 "detailDialog.h"
24 //Qt includes
26 #include <kiconloader.h>
27 #include <klocale.h>
29 #include "logViewWidget.h"
30 #include "logViewWidgetItem.h"
31 #include "logLine.h"
33 #include "logging.h"
35 DetailDialog::DetailDialog(QWidget* parent) :
36 QDialog(parent),
37 logViewWidget(NULL) {
39 setupUi(this);
41 previous->setText(i18n("&Previous"));
42 previous->setIcon(KIcon("arrow-up"));
43 connect(previous, SIGNAL(clicked()), this, SLOT(previousItem()));
45 next->setText(i18n("&Next"));
46 next->setIcon(KIcon("arrow-down"));
47 connect(next, SIGNAL(clicked()), this, SLOT(nextItem()));
49 closeButton->setText(KStandardGuiItem::close().text());
50 closeButton->setIcon(KStandardGuiItem::close().icon());
51 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
55 DetailDialog::~DetailDialog() {
59 void DetailDialog::selectionChanged(LogViewWidget* logViewWidget) {
60 this->logViewWidget=logViewWidget;
62 updateDetails();
65 //TODO Try to find a method that reload (an resize) correctly the content of the detail dialog
66 void DetailDialog::updateDetails() {
67 //logDebug() << "Updating Detail Dialog..." << endl;
69 //Get the current-last item selected
70 LogViewWidgetItem* item=logViewWidget->lastSelectedItem();
71 if (item==NULL) {
72 logDebug() << "No item found." << endl;
73 return;
76 icon->setPixmap(DesktopIcon(item->logLine()->logLevel()->icon()));
78 header->setText(item->logLine()->formattedText());
80 message->setText(item->logLine()->logItems().last());
82 if (logViewWidget->topLevelItem(logViewWidget->indexOfTopLevelItem(item) - 1)==NULL)
83 previous->setEnabled(false);
84 else
85 previous->setEnabled(true);
87 if (logViewWidget->topLevelItem(logViewWidget->indexOfTopLevelItem(item) + 1 )==NULL)
88 next->setEnabled(false);
89 else
90 next->setEnabled(true);
93 header->adjustSize();
94 this->adjustSize();
98 void DetailDialog::moveToItem(int direction) {
99 if (direction < 0)
100 logDebug() << "Go to previous item..." << endl;
101 else
102 logDebug() << "Go to next item..." << endl;
104 //Get the current-last item selected
105 LogViewWidgetItem* item=logViewWidget->lastSelectedItem();
106 if (item==NULL) {
107 logDebug() << "No item found." << endl;
108 return;
111 QTreeWidgetItem* destinationItem = logViewWidget->topLevelItem( logViewWidget->indexOfTopLevelItem(item) + direction );
112 if (destinationItem==NULL) {
113 if (direction < 0)
114 logDebug() << "No previous item found." << endl;
115 else
116 logDebug() << "No next item found." << endl;
117 return;
120 logViewWidget->setItemSelected(item, false);
121 logViewWidget->setItemSelected(destinationItem, true);
122 logViewWidget->scrollToItem(destinationItem);
124 updateDetails();
127 void DetailDialog::previousItem() {
128 moveToItem(-1);
131 void DetailDialog::nextItem() {
132 moveToItem(1);
135 #include "detailDialog.moc"