summaryrefslogtreecommitdiffstats
path: root/kbugbuster/gui/cwbugdetails.cpp
blob: 252ae348285a318e541dd42f5c875bac54db7f88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
    cwbugdetails.cpp  -  Details of a bug report

    copyright   : (c) 2001 by Martijn Klingens
    email       : klingens@kde.org

    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <tqtextview.h>
#include <tqlineedit.h>
#include <tqcombobox.h>
#include <tqlabel.h>

#include "cwbugdetails.h"
#include "kbbprefs.h"
#include "bugsystem.h"
#include "bugserver.h"

#include <tdehtml_part.h>
#include <tdehtmlview.h>
#include <kdebug.h>
#include <tdeglobal.h>
#include <krun.h>

#include <tqlayout.h>
#include <tqpalette.h>

using namespace KBugBusterMainWindow;

CWBugDetails::CWBugDetails( TQWidget *parent , const char * name )
  : TQWidget( parent, name )
{
    TQBoxLayout *topLayout = new TQVBoxLayout( this );
    
    m_bugDesc = new TDEHTMLPart( this, "m_bugDesc" );
    connect( m_bugDesc->browserExtension(), TQT_SIGNAL( openURLRequest( const KURL &, const KParts::URLArgs & ) ),
             this, TQT_SLOT( handleOpenURLRequest( const KURL &, const KParts::URLArgs & ) ) );

    topLayout->addWidget( m_bugDesc->view() );
}

CWBugDetails::~CWBugDetails()
{
}

void CWBugDetails::setBug( const Bug &bug, const BugDetails &details )
{
    TQColorGroup cg = m_bugDesc->view()->palette().active();
    TQString text =
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"
        "<html><head><title></title></head>\n"
        "<style>";

    text.append(
        TQString( "table.helpT { text-align: center; font-family: Verdana; font-weight: normal; font-size: 11px; color: #404040; width: 100%; background-color: #fafafa; border: 1px #6699CC solid; border-collapse: collapse; border-spacing: 0px; }\n"
                 "td.helpHed { border-bottom: 2px solid #000000; border-left: 1px solid #000000; background-color: %1; text-align: center; text-indent: 5px; font-family: Verdana; font-weight: bold; font-size: 11px; color: %2; }\n"
                 "td.helpBod { border-bottom: 1px solid #9CF; border-top: 0px; border-left: 1px solid #9CF; border-right: 0px; text-align: center; text-indent: 10px; font-family: Verdana, sans-serif, Arial; font-weight: normal; font-size: 11px; color: #404040; background-color: #000000; }\n"
                 "table.sofT { text-align: center; font-family: Verdana; font-weight: normal; font-size: 11px; color: #404040; width: 100%; background-color: #fafafa; border: 1px #000000 solid; border-collapse: collapse; border-spacing: 0px; }\n"
                 "</style>\n" )
        .arg( cg.highlight().name() )
        .arg( cg.highlightedText().name() ) );

    text.append( "<body style=\"margin: 0px\">\n" );

    TQString highlightStyle = TQString( "background: %1; color: %2; " )
                                      .arg( cg.highlight().name() )
                                      .arg( cg.highlightedText().name() );
    TQString borderBottomStyle = TQString( "border-bottom: solid %1 1px; " )
                                         .arg( cg.foreground().name() );
    TQString borderTopStyle = TQString( "border-top: solid %1 1px; " )
                                      .arg( cg.foreground().name() );

    TQString submitter = bug.submitter().fullName( true );
    int age = details.age();
    text.append( "<div style=\"" + highlightStyle + "padding: 8px; float: left\">" );
    text.append( "<a href=\"" + BugSystem::self()->server()->bugLink( bug ).url()
                 + "\">" + i18n("Bug Report</a> from <b>%1</b> " )
                 .arg( submitter ) );
    int replies = details.parts().count() - 1;
    if ( replies >= 1 ) text += i18n( "(1 reply)", "(%n replies)", replies );
    text += "</div>";
    text += "<div style=\"" + highlightStyle + borderBottomStyle +
            " text-align: right; padding: 8px\">" +
            i18n( "1 day old", "%n days old", age ) + "</div>\n";

    text.append(
        TQString( "<div style=\"background: %1; color: %2; " +
                 borderBottomStyle +
                 "border-bottom: solid %3 1px; "
                 "padding: 4px\">"
                 "<table cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">" )
                 .arg( cg.background().name() )
                 .arg( cg.foreground().name() ) );
    text.append( textBugDetailsAttribute( details.version(), i18n("Version") ) );
    text.append( textBugDetailsAttribute( details.source(), i18n("Source") ) );
    text.append( textBugDetailsAttribute( details.compiler(), i18n("Compiler") ) );
    text.append( textBugDetailsAttribute( details.os(), i18n("OS") ) );
    text.append( "</table></div>\n" );

    BugDetailsPart::List bdp = details.parts();
    BugDetailsPart::List::ConstIterator it;
    bool firstHeader = true;

    for ( it = bdp.begin(); it != bdp.end(); ++it ) {
        if ( bdp.count() > 1 ) {
            text.append( "<div style=\"" + highlightStyle + "padding: 8px; float: left; " );
            if ( !firstHeader ) text += borderTopStyle;

            text.append( borderBottomStyle + "\">" );
            TQString sender = (*it).sender.fullName( true );
            TQString date = TDEGlobal::locale()->formatDateTime( (*it).date, false );
            BugDetailsPart::List::ConstIterator it2 = it;
            if ( ++it2 == bdp.end() )
                text.append( "<a href=\"" + BugSystem::self()->server()->bugLink( bug ).url()
                             + "\">" + i18n("Bug Report</a> from <b>%1</b>")
                             .arg( sender ) );
            else {
                text.append( "<a href=\"" + BugSystem::self()->server()->bugLink( bug ).url() + TQString("#c%1").arg( replies )
			     + "\">" + i18n("Reply #%1</a> from <b>%2</b>")
                             .arg( replies ).arg( sender ) );
                replies--;
            }
            text.append( "</div>\n" );
            text += "<div style=\"" + highlightStyle + borderBottomStyle;
            if ( !firstHeader ) text += borderTopStyle;
            text += "text-align: right; padding: 8px\">" + date + "</div>\n";
        
            firstHeader = false;
        }

        // Adding of <pre> tags is now done by BugDetailsJob::processNode. This
        // was breaking the display of attachments because they have <br/>\n
        // after each line -> two newlines with <pre>
        text.append( "<div style=\"padding: 8px\">" );
        text.append( (*it).text );
        text.append( "</div>\n" );
    }

    TQValueList<BugDetailsImpl::AttachmentDetails> atts = details.attachmentDetails();
    if ( atts.count() > 0 ) {
        text.append( "<table summary=\"Attachment data table\" class=\"sofT\" cellspacing=\"0\">" );
        text.append( TQString( "<tr> <td colspan=\"4\" class=\"helpHed\">%1</td> </tr>")
                     .arg( i18n( "Attachment List") ) );
        text.append( TQString("<tr> <td class=\"helpHed\">%1</td> <td class=\"helpHed\">%2</td> <td class=\"helpHed\">%3</td> <td class=\"helpHed\">%4</td> </tr>")
                     .arg( i18n("Description") )
                     .arg( i18n("Date") )
                     .arg( i18n("View") )
                     .arg( i18n("Edit") ) );
        TQValueList<BugDetailsImpl::AttachmentDetails>::iterator it;
        for ( it = atts.begin() ; it != atts.end() ; ++it ) {
            text.append( TQString("<tr><td>%1</td>").arg( (*it).description ) ) ;
            text.append( TQString("<td>%1</td>").arg( (*it).date ) );
            text.append( "<td><a href=\"" +
                         BugSystem::self()->server()->attachmentViewLink( (*it).id ).url() +
                         "\">" + i18n("View") + "</a></td>" );
            text.append( "<td><a href=\"" +
                         BugSystem::self()->server()->attachmentEditLink( (*it).id ).url() +
                         "\">" + i18n("Edit") + "</a></td>" );
            text.append( "</tr>" );
        }
    }

    text.append( "</body></html>" );

    //kdDebug() << "BEGIN OUTPUT" << text << "END OUTPUT" << endl;

    m_bugDesc->view()->setContentsPos(0,0);
    m_bugDesc->begin();
    m_bugDesc->write( text );
    m_bugDesc->end();

    if ( KBBPrefs::instance()->mDebugMode ) mSource = text;
}

void CWBugDetails::handleOpenURLRequest( const KURL &url, const KParts::URLArgs & )
{
    new KRun( url );
}

TQString CWBugDetails::textBugDetailsAttribute( const TQString &value,
                                               const TQString &name )
{
    TQString text = "";
    if ( !value.isEmpty() ) {
        text.append( "<tr><td style=\"width: 20%\"><b>" + name + "</b></td>"
                     "<td>" + value + "</td></tr>" );
    }
    return text;
}

TQString CWBugDetails::source() const
{
    return mSource;
}

TQString CWBugDetails::selectedText() const
{
    return m_bugDesc->selectedText();
}

#include "cwbugdetails.moc"