~ubuntu-branches/ubuntu/dapper/ksystemlog/dapper

« back to all changes in this revision

Viewing changes to ksystemlog/src/detailDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-07-07 16:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20050707160000-a104d769ph3yfkg4
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 by Nicolas Ternisien                               *
 
3
 *   nicolas.ternisien@gmail.com                                           *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
 
 
21
//Qt includes
 
22
#include <qlayout.h>
 
23
#include <qtooltip.h>
 
24
#include <qwhatsthis.h>
 
25
 
 
26
//KDE includes
 
27
#include <kstdguiitem.h>
 
28
#include <ktextedit.h>
 
29
#include <kguiitem.h>
 
30
#include <kpushbutton.h>
 
31
#include <klocale.h>
 
32
#include <kdebug.h>
 
33
 
 
34
//Project includes
 
35
#include "parentLogLine.h"
 
36
 
 
37
#include "detailDialog.h"
 
38
 
 
39
DetailDialog::DetailDialog(View* v, QWidget *parent, const char *name) :
 
40
        //KDialogBase(parent, name, false, i18n("Log Line Details"), 0 /*KDialogBase::Ok*/),
 
41
        DetailDialogBase(parent, name, false, 0),
 
42
        view(v),
 
43
        currentLine(NULL) {
 
44
        
 
45
        
 
46
        previous->setText(i18n("&Previous"));
 
47
        connect(previous, SIGNAL(clicked()), this, SLOT(previousItem()));
 
48
        
 
49
        next->setText(i18n("&Next"));
 
50
        connect(next, SIGNAL(clicked()), this, SLOT(nextItem()));
 
51
        
 
52
        //close->setText(KStdGuiItem::close().text());
 
53
        //close->setIcon(KStdGuiItem::close().iconSet());
 
54
        connect(closeButton, SIGNAL(clicked()), this, SLOT(closeDetails()));
 
55
        
 
56
        updateDetails();
 
57
        
 
58
        /* This code has been replaced by a pretty drawing of the Detail Dialog with Qt Designer
 
59
        
 
60
        setMinimumHeight(200);
 
61
        setMinimumWidth(450);
 
62
        
 
63
        QWhatsThis::add(this, i18n("This dialog displays detailed information about the currently selected log line."));
 
64
        
 
65
        QWidget* widget=new QWidget(this);
 
66
        
 
67
        QVBoxLayout* mainLayout = new QVBoxLayout(widget, 0, 10);
 
68
 
 
69
        QHBoxLayout* l1 = new QHBoxLayout(0, 0, 5);
 
70
 
 
71
        icon=new QLabel(widget);
 
72
        //icon->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
 
73
        l1->addWidget(icon, 0, Qt::AlignVCenter);
 
74
 
 
75
        //header=new KActiveLabel(widget, "header");
 
76
        header=new QLabel(widget, "header");
 
77
        //header->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum) );
 
78
        //header->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum ) );
 
79
        l1->addWidget(header, 0, Qt::AlignVCenter || Qt::AlignHCenter);
 
80
        
 
81
        mainLayout->addLayout(l1);
 
82
 
 
83
        message=new QTextEdit(widget);
 
84
        message->setReadOnly(true);
 
85
        //message->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum) );
 
86
        //message->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
 
87
        //message->setMinimumHeight(40);
 
88
        //message->setMinimumHeight(60);
 
89
        //message->setMinimumWidth(400);
 
90
        
 
91
        mainLayout->addWidget(message);
 
92
        
 
93
        QHBoxLayout* buttons=new QHBoxLayout(0, 0, 10);
 
94
        
 
95
        
 
96
        previous=new QPushButton(KStdGuiItem::back().iconSet(), i18n("&Previous"), widget);
 
97
        connect(previous, SIGNAL(clicked()), this, SLOT(previousItem()));
 
98
        //1=Stretch factor (ratio between object in the QHBoxLayout)
 
99
        buttons->addWidget(previous, 1, Qt::AlignRight);
 
100
        
 
101
        QToolTip::add(previous, i18n("Move to the previous line"));
 
102
        QWhatsThis::add(previous, i18n("Moves to the previous line. This button is deactivated if there is no previous log line."));
 
103
 
 
104
        buttons->setStretchFactor(previous, 1);
 
105
        next=new QPushButton(KStdGuiItem::forward().iconSet(), i18n("&Next"), widget);
 
106
        connect(next, SIGNAL(clicked()), this, SLOT(nextItem()));
 
107
        //1=Stretch factor (ratio between object in the QHBoxLayout)
 
108
        buttons->addWidget(next, 1, Qt::AlignLeft);
 
109
        
 
110
        
 
111
        QToolTip::add(next, i18n("Move to the next line"));
 
112
        QWhatsThis::add(next, i18n("Moves to the next line. This button is deactivated if there is no next log line."));
 
113
        
 
114
        
 
115
        QPushButton* close=new QPushButton(KStdGuiItem::close().iconSet(), KStdGuiItem::close().text(), widget);
 
116
        connect(close, SIGNAL(clicked()), this, SLOT(closeDetails()));
 
117
        buttons->addWidget(close, 0, Qt::AlignRight);
 
118
 
 
119
        QToolTip::add(next, i18n("Close the Detail dialog."));
 
120
        QWhatsThis::add(next, i18n("Closes this Detail dialog."));
 
121
        
 
122
        mainLayout->addLayout(buttons);
 
123
 
 
124
        this->setMainWidget(widget);
 
125
        
 
126
        //TODO Try to find a better solution (if it exists!)
 
127
        //resize(500, 200);
 
128
        */
 
129
 
 
130
}
 
131
 
 
132
DetailDialog::~DetailDialog() {
 
133
 
 
134
}
 
135
 
 
136
void DetailDialog::setView(View* view) {
 
137
        this->view=view;
 
138
        updateDetails();
 
139
}
 
140
 
 
141
void DetailDialog::selectionChanged() {
 
142
        updateDetails();
 
143
}
 
144
 
 
145
//TODO Try to find a method that reload (an resize) correctly the content of the detail dialog
 
146
void DetailDialog::updateDetails() {
 
147
        //Get the current-last item selected
 
148
        currentLine=view->getLastSelectedItem();
 
149
        if (currentLine==NULL) {
 
150
                //If no item are selected and the dialog is still open, we try to select the first
 
151
                //item of the list.
 
152
                currentLine=static_cast<LogListItem*> (view->getLogList()->firstChild());
 
153
                if (currentLine==NULL) {
 
154
                        close();
 
155
 
 
156
                        return;
 
157
                }
 
158
                
 
159
                
 
160
        }
 
161
        
 
162
        LogLine* logLine=currentLine->getLogLine();
 
163
        
 
164
        //Special case if this is a ParentLogLine (Group By feature)
 
165
        if (logLine->isParentLogLine()) {
 
166
                icon->setPixmap(DesktopIcon(GROUP_BY_ICON));
 
167
                header->setText(currentLine->getFormattedText());
 
168
                message->setText("");
 
169
        }
 
170
        //Normal Log Line
 
171
        else {
 
172
                icon->setPixmap(DesktopIcon(logLine->getLogLevel()->icon));
 
173
                
 
174
                header->setText(currentLine->getFormattedText());
 
175
                
 
176
                message->setText(logLine->getItemList().last());
 
177
        }
 
178
        
 
179
                
 
180
        if (currentLine->itemAbove()==NULL)
 
181
                previous->setEnabled(false);
 
182
        else
 
183
                previous->setEnabled(true);
 
184
        
 
185
 
 
186
        if (currentLine->itemBelow()==NULL)
 
187
                next->setEnabled(false);
 
188
        else
 
189
                next->setEnabled(true);
 
190
                
 
191
                
 
192
        header->adjustSize();
 
193
        this->adjustSize();
 
194
}
 
195
 
 
196
void DetailDialog::previousItem() {
 
197
        //This case should not occurs
 
198
        if (currentLine==NULL)
 
199
                return;
 
200
                
 
201
        //This case should not occurs
 
202
        if (currentLine->itemAbove()==NULL) {
 
203
                close();
 
204
                return;
 
205
        }
 
206
                
 
207
        currentLine->setSelected(false);
 
208
        currentLine->repaint();
 
209
        currentLine=static_cast<LogListItem*> (currentLine->itemAbove());
 
210
        currentLine->setSelected(true);
 
211
        currentLine->repaint();
 
212
        
 
213
        
 
214
        updateDetails();
 
215
}
 
216
 
 
217
void DetailDialog::closeDetails() {
 
218
        this->close();
 
219
}
 
220
 
 
221
void DetailDialog::nextItem() {
 
222
        //This case should not occurs
 
223
        if (currentLine==NULL)
 
224
                return;
 
225
        
 
226
        //This case should not occurs
 
227
        if (currentLine->itemBelow()==NULL) {
 
228
                close();
 
229
                return;
 
230
        }
 
231
                
 
232
        currentLine->setSelected(false);
 
233
        currentLine->repaint();
 
234
        currentLine=static_cast<LogListItem*> (currentLine->itemBelow());
 
235
        currentLine->setSelected(true);
 
236
        currentLine->repaint();
 
237
        
 
238
        updateDetails();
 
239
 
 
240
}
 
241
 
 
242
#include "detailDialog.moc"