┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/viewpropsprogressinfo.cpp
blob: 680a852fcad56b1e9cc67ff257c5b59512a60391 (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
/***************************************************************************
 *   Copyright (C) 2006 by Peter Penz                                      *
 *   [email protected]                                                     *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "viewpropsprogressinfo.h"
#include "viewpropsapplier.h"
#include "viewproperties.h"

#include <QLabel>
#include <QProgressBar>
#include <QTimer>
#include <QVBoxLayout>

#include <kdirsize.h>
#include <klocale.h>
#include <kurl.h>
#include <kio/jobclasses.h>

ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent,
                                             const KUrl& dir,
                                             const ViewProperties* viewProps) :
    KDialog(parent),
    m_dirCount(0),
    m_applyCount(0),
    m_dir(dir),
    m_viewProps(viewProps),
    m_label(0),
    m_progressBar(0),
    m_dirSizeJob(0),
    m_timer(0)
{
    setCaption(i18n("Applying view properties"));
    setButtons(KDialog::Cancel);

    QWidget* main = new QWidget();
    QVBoxLayout* topLayout = new QVBoxLayout();

    m_label = new QLabel(i18n("Counting folders: %1", 0), main);
    m_progressBar = new QProgressBar(main);

    topLayout->addWidget(m_label);
    topLayout->addWidget(m_progressBar);

    main->setLayout(topLayout);
    setMainWidget(main);

    ViewPropsApplier* applier = new ViewPropsApplier(dir);
    connect(applier, SIGNAL(progress(const KUrl&, int)),
            this, SLOT(countDirs(const KUrl&, int)));
    connect(applier, SIGNAL(completed()),
            this, SLOT(applyViewProperties()));

    // TODO: use KDirSize job instead. Current issue: the signal
    // 'result' is not emitted with kdelibs 2006-12-05.

    /*m_dirSizeJob = KDirSize::dirSizeJob(dir);
    connect(m_dirSizeJob, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_timer = new QTimer(this);
    connect(m_timer, SIGNAL(timeout()),
            this, SLOT(updateDirCounter()));
    m_timer->start(300);*/
}

ViewPropsProgressInfo::~ViewPropsProgressInfo()
{
}

void ViewPropsProgressInfo::countDirs(const KUrl& /*dir*/, int count)
{
    m_dirCount += count;
    m_label->setText(i18n("Counting folders: %1", m_dirCount));
}

/*void ViewPropsProgressInfo::updateDirCounter()
{
    const int subdirs = m_dirSizeJob->totalSubdirs();
    m_label->setText(i18n("Counting folders: %1", subdirs));
}

void ViewPropsProgressInfo::slotResult(KJob*)
{
    QTimer::singleShot(0, this, SLOT(applyViewProperties()));
}*/

void ViewPropsProgressInfo::applyViewProperties()
{
    //m_timer->stop();
    //const int subdirs = m_dirSizeJob->totalSubdirs();
    //m_label->setText(i18n("Folders: %1", subdirs));
    //m_progressBar->setMaximum(subdirs);

    m_label->setText(i18n("Folders: %1", m_dirCount));
    m_progressBar->setMaximum(m_dirCount);

    ViewPropsApplier* applier = new ViewPropsApplier(m_dir, m_viewProps);
    connect(applier, SIGNAL(progress(const KUrl&, int)),
            this, SLOT(showProgress(const KUrl&, int)));
    connect(applier, SIGNAL(completed()),
            this, SLOT(close()));
}

void ViewPropsProgressInfo::showProgress(const KUrl& url, int count)
{
    m_applyCount += count;
    m_progressBar->setValue(m_applyCount);
}

#include "viewpropsprogressinfo.moc"