summaryrefslogtreecommitdiffstats
path: root/klinkstatus/src/ui/resultview.cpp
blob: 32c9e5276a2b4ae9152a3078ae7cd18ed3c7b5d4 (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
//
// C++ Implementation: resultlinkview
//
// Description:
//
//
// Author: Paulo Moura Guedes <moura@kdewebdev.org>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "resultview.h"
#include "../engine/linkstatus.h"

#include <tqpainter.h>
#include <tqcolor.h>

#include <klocale.h>
#include <kurl.h>
#include <kiconloader.h>

const TQString ResultView::URL_LABEL = "URL";
const TQString ResultView::STATUS_LABEL = "Status";
const TQString ResultView::MARKUP_LABEL = "Markup";
const TQString ResultView::LINK_LABEL_LABEL = "Label";


// ******************************* ResultView ********************************

ResultView::ResultView()
        : col_status_(-1),
        col_label_(-1),
        col_url_(-1),
        col_markup_(-1),
        sub_menu_(0),
        cell_tip_(0)
{}


ResultView::~ResultView()
{}

void ResultView::setColumns(TQStringList const& columns)
{
    Q_ASSERT(columns.size() != 0);
    
    columns_.clear();
    for(uint i = 0; i != columns.size(); ++i)
    {
        if(columns[i] == ResultView::URL_LABEL)
        {
            col_url_ = i + 1;
        }
        else if(columns[i] == ResultView::STATUS_LABEL)
        {
            col_status_ = i + 1;
        }
        else if(columns[i] == ResultView::MARKUP_LABEL)
        {
            col_markup_ = i + 1;
        }
        else if(columns[i] == ResultView::LINK_LABEL_LABEL)
        {
            col_label_ = i + 1;
        }

        columns_.push_back(columns[i]);
    }
    number_of_columns_ = columns.size();
}

bool ResultView::displayableWithtqStatus(LinktqStatus const* ls, tqStatus const& status)
{
    if(status == ResultView::good)
    {
        return 
                ls->status() == LinktqStatus::SUCCESSFULL ||
                ls->status() == LinktqStatus::HTTP_REDIRECTION;
    }
    else if(status == ResultView::bad)
    {
        return 
                ls->status() == LinktqStatus::BROKEN ||
                ls->status() == LinktqStatus::HTTP_CLIENT_ERROR ||
                ls->status() == LinktqStatus::HTTP_SERVER_ERROR;
    }
    else if(status == ResultView::malformed)
    {
        return ls->status() == LinktqStatus::MALFORMED;
    }
    else if(status == ResultView::undetermined)
    {
        return 
                ls->status() == LinktqStatus::UNDETERMINED ||
                ls->status() == LinktqStatus::TIMEOUT ||
                ls->status() == LinktqStatus::NOT_SUPPORTED;
    }
    else
        return true;
}


// ******************************* ResultViewItem *****************************

ResultViewItem::ResultViewItem(LinktqStatus const* linkstatus, int column_index)
        : ls_((LinktqStatus*)linkstatus), column_index_(column_index)
{
    Q_ASSERT(ls_);
    Q_ASSERT(column_index_ > 0);
}

ResultViewItem::~ResultViewItem()
{}

void ResultViewItem::setColumnIndex(int i)
{
    Q_ASSERT(i > 0);
    column_index_ = i;
}

int ResultViewItem::columnIndex() const
{
    return column_index_;
}

LinktqStatus const* ResultViewItem::linktqStatus() const
{
    Q_ASSERT(ls_);
    return ls_;
}

TQColor const& ResultViewItem::textStatusColor() const
{
    if(linktqStatus()->errorOccurred())
    {
        //kdDebug(23100) <<  "ERROR: " << linkStatus()->error() << ": " << linktqStatus()->absoluteUrl().prettyURL() << endl;
        if(linktqStatus()->error() == i18n( "Javascript not supported" ))
            return TQt::lightGray;
        else
            return TQt::red;
    }

    else if(linktqStatus()->absoluteUrl().hasRef())
        return TQt::blue;

    else if(!linktqStatus()->absoluteUrl().protocol().startsWith("http"))
        return TQt::darkGreen;

    else
    {
        TQString status_code(TQString::number(linktqStatus()->httpHeader().statusCode()));

        if(status_code[0] == '0')
        {
            kdWarning(23100) <<  "status code == 0: " << endl;
            kdWarning(23100) <<  linktqStatus()->toString() << endl;
            kdWarning(23100) <<  linktqStatus()->httpHeader().toString() << endl;
        }
        //Q_ASSERT(status_code[0] != '0');

        if(status_code[0] == '5')
            return TQt::darkMagenta;

        else if(status_code[0] == '4')
            return TQt::red;

        else if(status_code[0] == '3')
            return TQt::blue;

        else if(status_code[0] == '2')
            return TQt::darkGreen;

        else
            return TQt::red;
    }
}