summaryrefslogtreecommitdiffstats
path: root/src/dolphinstatusbar.cpp
blob: cfa5fb419ed04110462085b2cf531c0b937171dc (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
/***************************************************************************
 *   Copyright (C) 2006 by Peter Penz                                      *
 *   peter.penz@gmx.at                                                     *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include "dolphinstatusbar.h"
#include <kprogress.h>
#include <qlabel.h>
#include <qtimer.h>
#include <kiconloader.h>

#include "dolphinview.h"
#include "statusbarmessagelabel.h"
#include "statusbarspaceinfo.h"

DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
    QHBox(parent),
    m_messageLabel(0),
    m_spaceInfo(0),
    m_progressBar(0),
    m_progress(100)
{
    m_messageLabel = new StatusBarMessageLabel(this);
    m_messageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);

    m_spaceInfo = new StatusBarSpaceInfo(this);
    m_spaceInfo->setURL(parent->url());

    m_progressText = new QLabel(this);
    m_progressText->hide();

    m_progressBar = new KProgress(this);
    m_progressBar->hide();

    m_progressTimer = new QTimer(this);
    connect(m_progressTimer, SIGNAL(timeout()),
            this, SLOT(slotProgressTimer()));

    const QSize size(m_progressBar->sizeHint());
    m_progressBar->setMaximumWidth(size.width());
    setMinimumHeight(size.height());
    m_messageLabel->setMinimumTextHeight(size.height());

    connect(parent, SIGNAL(signalURLChanged(const KURL&)),
            this, SLOT(slotURLChanged(const KURL&)));
}


DolphinStatusBar::~DolphinStatusBar()
{
}

void DolphinStatusBar::setMessage(const QString& msg,
                                  Type type)
{
    m_messageLabel->setText(msg);
    if (msg.isEmpty() || (msg == m_defaultText)) {
        type = Default;
    }
    m_messageLabel->setType(type);

    if ((type == Error) && (m_progress < 100)) {
        // If an error message is shown during a progress is ongoing,
        // the (never finishing) progress information should be hidden immediately
        // (invoking 'setProgress(100)' only leads to a delayed hiding).
        m_progressBar->hide();
        m_progressText->hide();
        setProgress(100);
    }
}

DolphinStatusBar::Type DolphinStatusBar::type() const
{
    return m_messageLabel->type();
}

QString DolphinStatusBar::message() const
{
    return m_messageLabel->text();
}

void DolphinStatusBar::setProgressText(const QString& text)
{
    m_progressText->setText(text);
}

QString DolphinStatusBar::progressText() const
{
    return m_progressText->text();
}

void DolphinStatusBar::setProgress(int percent)
{
    if (percent < 0) {
        percent = 0;
    }
    else if (percent > 100) {
        percent = 100;
    }

    m_progress = percent;
    m_progressBar->setProgress(m_progress);
    m_progressTimer->start(300, true);

    const QString msg(m_messageLabel->text());
    if (msg.isEmpty() || (msg == m_defaultText)) {
        if (percent == 0) {
            m_messageLabel->setText(QString::null);
            m_messageLabel->setType(Default);
        }
        else if (percent == 100) {
            m_messageLabel->setText(m_defaultText);
        }
    }
}

void DolphinStatusBar::clear()
{
    // TODO: check for timeout, so that it's prevented that
    // a message is cleared too early.
    m_messageLabel->setText(m_defaultText);
    m_messageLabel->setType(Default);
}

void DolphinStatusBar::setDefaultText(const QString& text)
{
    m_defaultText = text;
}

void DolphinStatusBar::slotProgressTimer()
{
    if (m_progress < 100) {
        // progress should be shown
        m_progressBar->show();
        m_progressText->show();
        m_spaceInfo->hide();
    }
    else {
        // progress should not be shown anymore
        m_progressBar->hide();
        m_progressText->hide();
        m_spaceInfo->show();
    }
}

void DolphinStatusBar::slotURLChanged(const KURL& url)
{
    m_spaceInfo->setURL(url);
}

#include "dolphinstatusbar.moc"