summaryrefslogtreecommitdiffstats
path: root/src/svnfrontend/stopdlg.cpp
blob: e67d126ce091f5778ceba3d388b216e230cc9af3 (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
210
211
212
213
214
215
216
/***************************************************************************
 *   Copyright (C) 2005-2007 by Rajko Albrecht                             *
 *   ral@alwins-world.de                                                   *
 *                                                                         *
 *   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 "stopdlg.h"
#include "ccontextlistener.h"
#include "tdesvnsettings.h"
#include "stringhelper.h"

#include <kapplication.h>
#include <klocale.h>
#include <twin.h>
#include <tqtimer.h>
#include <tqpushbutton.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqwidgetlist.h>
#include <kprogress.h>
#include <kdebug.h>
#include <ktextbrowser.h>

StopDlg::StopDlg(TQObject*listener,TQWidget *parent, const char *name,const TQString&caption,const TQString&text)
 : KDialogBase(KDialogBase::Plain,caption,KDialogBase::Cancel, KDialogBase::Cancel,parent, name,true)
    ,m_Context(listener),m_MinDuration(1000),mCancelled(false),mShown(false),m_BarShown(false),
    cstack(0)
{
    KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
    m_lastLogLines = 0;
    m_lastLog = "";

    mShowTimer = new TQTimer(this);
    m_StopTick.start();
    showButton(KDialogBase::Close, false);
    mCancelText = actionButton(KDialogBase::Cancel)->text();

    TQFrame* mainWidget = plainPage();
    tqlayout = new TQVBoxLayout(mainWidget, 10);
    mLabel = new TQLabel(text, mainWidget);
    tqlayout->addWidget(mLabel);
    m_ProgressBar=new KProgress(15,mainWidget);
    m_ProgressBar->setCenterIndicator (false);
    m_ProgressBar->setTextEnabled(false);
    tqlayout->addWidget(m_ProgressBar);
    m_NetBar = new KProgress(15,mainWidget);
    tqlayout->addWidget(m_NetBar);

    mWait = false;
    m_LogWindow = 0;

    connect(mShowTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotAutoShow()));
    if (m_Context) {
        connect(m_Context,TQT_SIGNAL(tickProgress()),this,TQT_SLOT(slotTick()));
        connect(m_Context,TQT_SIGNAL(waitShow(bool)),this,TQT_SLOT(slotWait(bool)));
        connect(m_Context,TQT_SIGNAL(netProgress(long long int, long long int)),
                this,TQT_SLOT(slotNetProgres(long long int, long long int)));
        connect(this,TQT_SIGNAL(sigCancel(bool)),m_Context,TQT_SLOT(setCanceled(bool)));
    }
    mShowTimer->start(m_MinDuration, true);
    setMinimumSize(280,160);
    adjustSize();
}

void StopDlg::showEvent( TQShowEvent*)
{
    cstack = new CursorStack(TQt::BusyCursor);
}

void StopDlg::hideEvent(TQHideEvent*)
{
    delete cstack; cstack = 0;
}

void StopDlg::slotWait(bool how)
{
    mWait = how;
    if (mShown && mWait) {
        hide();
        mShown = false;
    }
}

StopDlg::~StopDlg()
{
    delete cstack;
}

void StopDlg::slotAutoShow()
{
    bool hasDialogs = false;
    TQWidget * w = TQT_TQWIDGET(kapp->activeModalWidget());
    if (w && w!=this && w!=parentWidget() ) {
        hasDialogs = true;
    }
    if (hasDialogs) {
        kdDebug()<<"Hide me! (" << caption() << ")" << endl;
        hide();
    }
    if (mShown||mWait||hasDialogs) {
        if (mWait) {
            //kdDebug() << "Waiting for show"<<endl;
            mShowTimer->start(m_MinDuration, true);
        }
        mShowTimer->start(m_MinDuration, true);
        return;
    }
    m_ProgressBar->hide();
    m_NetBar->hide();
    m_BarShown=false;
    m_netBarShown=false;
    show();
    kapp->processEvents();
    mShown = true;
    mShowTimer->start(m_MinDuration, true);
}

void StopDlg::slotCancel()
{
    mCancelled = true;
    emit sigCancel(true);
}

bool StopDlg::cancelld()
{
    return mCancelled;
}

void StopDlg::slotTick()
{
    if (m_StopTick.elapsed()>500) {
        if (!m_BarShown) {
            m_ProgressBar->show();
            m_BarShown=true;
        }
        if (m_ProgressBar->progress()==15) {
            m_ProgressBar->reset();
        } else {
            m_ProgressBar->setProgress(m_ProgressBar->progress()+1);
        }
        m_StopTick.restart();
        kapp->processEvents();
    }
}

void StopDlg::slotExtraMessage(const TQString&msg)
{
    ++m_lastLogLines;
    if (!m_LogWindow) {
        TQFrame* mainWidget = plainPage();
        m_LogWindow = new KTextBrowser(mainWidget);
        tqlayout->addWidget(m_LogWindow);
        m_LogWindow->show();
        resize( TQSize(500, 400).expandedTo(tqminimumSizeHint()) );
    }
    if (m_lastLogLines >= Kdesvnsettings::self()->cmdline_log_minline() &&
        isHidden() ) {
        slotAutoShow();
    }
    m_LogWindow->append(msg);
    kapp->processEvents();
}

void StopDlg::slotNetProgres(long long int current, long long int max)
{
    if (m_StopTick.elapsed()>300||(m_BarShown&&!m_netBarShown)) {
        if (!m_netBarShown) {
            m_NetBar->show();
            m_netBarShown=true;
        }
        TQString s1 = helpers::ByteToString()(current);
        if (max > -1 && max != m_NetBar->totalSteps()) {
            TQString s2 = helpers::ByteToString()(max);
            m_NetBar->setFormat(i18n("%1 of %2").tqarg(s1).tqarg(s2));
            m_NetBar->setTotalSteps(max);
        }
        if (max == -1) {
            m_NetBar->setFormat(i18n("%1 transferred.").tqarg(s1));
            m_NetBar->setTotalSteps(current+1);
        }
        m_NetBar->setValue(current);
        m_StopTick.restart();
        kapp->processEvents();
    }
}

StopSimpleDlg::StopSimpleDlg(TQWidget *parent, const char *name,const TQString&caption,const TQString&text)
    : StopDlg(0,parent,name,caption,text),cancelld(false)
{
    connect(this,TQT_SIGNAL(sigCancel(bool)),this,TQT_SLOT(slotSimpleCancel(bool)));
}

void StopSimpleDlg::slotSimpleCancel(bool how)
{
    cancelld = how;
}

void StopSimpleDlg::makeCancel()
{
    slotSimpleCancel(true);
}

#include "stopdlg.moc"