File: sendreceivedialog.cpp

package info (click to toggle)
aethera 0.9.3-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,588 kB
  • ctags: 7,282
  • sloc: cpp: 64,544; sh: 9,913; perl: 1,756; makefile: 1,680; python: 258
file content (230 lines) | stat: -rw-r--r-- 6,125 bytes parent folder | download
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 * This file is part of Magellan <http://www.kAlliance.org/Magellan>
 *
 * Copyright (c) 1998-2000 Teodor Mihai <teddy@ireland.com>
 * Copyright (c) 1998-2000 Laur Ivan <laur.ivan@ul.ie>
 * Copyright (c) 1999-2000 Virgil Palanciuc <vv@ulise.cs.pub.ro>
 *
 * Requires the Qt widget libraries, available at no cost at
 * http://www.troll.no/
 *
 * Also requires the KDE libraries, available at no cost at
 * http://www.kde.org/
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal 
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR    
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include <qlayout.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qtextview.h>
#include <qcheckbox.h>
#include <qprogressbar.h>
#include <qstringlist.h>
#include <qtimer.h>

#include <kconfig.h>
#include <kiconloader.h>
#include <khtmlview.h>
#include <khtml_part.h>

#include <clientrmi.h>
#include <sendreceivedialog.h>

#include <stdio.h>

extern KConfig *GlobalConfig;

SendReceiveDialog::SendReceiveDialog(QWidget *parent, const char *name):SendReceiveDialogBase(parent, name)
{
	logView=new KHTMLPart(this);
	logView->autoloadImages(true);
	logView->view()->setGeometry(QRect(10, 140, 471, 141));
	logView->show();

	pinToggleButton->setPixmap(BarIcon("pin-blue-off"));
	connect(pinToggleButton, SIGNAL(toggled(bool)), this, SLOT(setPinPixmap(bool)));
		
	sendLabel->setText(QString::null);
	receiveLabel->setText(QString::null);
	
	pop3InProgress=false;
	smtpInProgress=false;
}

void SendReceiveDialog::start()
{
	smtpInProgress=true;
	pop3InProgress=true;
	
	clearLog();
	GlobalConfig->setGroup("Receive Options");
	if (GlobalConfig->readEntry("Display progress") != "No")
		show();
}

void SendReceiveDialog::end()
{
	if(smtpInProgress || pop3InProgress) return;
	
  if(dontShowCheckbox->isChecked())
  {
    GlobalConfig->setGroup("Receive Options");
    GlobalConfig->writeEntry("Display progress", "No");
  }

  if (!pinToggleButton->isOn())
	QTimer::singleShot(1500, this, SLOT(hide()));
}

void SendReceiveDialog::showProgress(const QString &message)
{
  QStringList info=QStringList::split(":", message);

  if(info[0]=="pop3")
  {
    if(info[1]=="task")
    {
      appendInfo(QString("Receiving mail on account ")+info[2]);
    }
    else if(info[1]=="connect")
    {
      receiveLabel->setText("Connecting to server...");
      receiveProgressBar->setProgress(0);
    }
    else if(info[1]=="list")
    {
      receiveLabel->setText("Receiving list of messages...");
    }
    else if(info[1]=="messages")
    {
      receiveProgressBar->setTotalSteps(info[2].toInt());

    }
    else if(info[1]=="nomessages")
    {
      receiveLabel->setText("There are no new messages on the server");
    }
    else if(info[1]=="dl")
    {
      receiveLabel->setText(QString("Downloading message ")+info[2]+"/"+info[4]);
      receiveProgressBar->setProgress(info[2].toInt());
    }
    else if(info[1]=="sync")
    {
      receiveLabel->setText("Checking for messages to delete...");
    }
    else if(info[1]=="completed")
    {
      appendInfo("Receive completed");
      receiveLabel->setText("Download complete");
      receiveProgressBar->setProgress(0);
			pop3InProgress=false;
      end();
    }
    else if(info[1]=="err")
    {
      appendError(QString("Received failed with the error: ")+info[2]);
      receiveLabel->setText("Connection failed");
      receiveProgressBar->setProgress(0);
			pop3InProgress=false;
      end();
    }
  }
  else if(info[0]=="smtp")
  {
    if(info[1]=="task")
    {
      appendInfo(QString("Sending mail on account ")+info[2]);
    }
		else if(info[1]=="sending")
		{
			sendProgressBar->setTotalSteps(info[3].toInt());
			sendProgressBar->setProgress(info[2].toInt()-1);
		}
    else if(info[1]=="sent")
    {
      sendProgressBar->setTotalSteps(info[3].toInt());
      sendProgressBar->setProgress(info[2].toInt());
    }
    else if(info[1]=="err")
    {
      appendError(QString("Send failed with the error: ")+info[2]);
			smtpInProgress=false;
			end();
    }
    else if(info[1]=="done")
    {
      appendInfo("Send completed");
			smtpInProgress=false;
			end();
    }
  }
}

void SendReceiveDialog::hideProgress()
{
  hide();
}

void SendReceiveDialog::stopDelivery()
{
  ClientRMI::ref()->stopPOP3Delivery();
}

void SendReceiveDialog::appendInfo(const QString &message)
{
	return appendString(message, "progress-ok.png");
}

void SendReceiveDialog::appendError(const QString &message)
{
	return appendString(message, "progress-error.png");
}

void SendReceiveDialog::appendString(const QString &message, const QString &image)
{
	log.append(QString("<table>") +
				"<tr>" +
						"<td valign=\"top\"><img src=\"" + image + "\"></td>" +
						"<td valign=\"top\">" + message + "</td>" +
				"</tr>" +
			"</table>" +
			"<br>");

	writeLog();	
}

void SendReceiveDialog::clearLog()
{
	log="";
}

void SendReceiveDialog::writeLog()
{
	logView->begin();
	logView->write((const char *)(QString("<html><body>") + log + "</body></html>"));
	logView->end();
}

void SendReceiveDialog::setPinPixmap(bool isOn)
{
	if(isOn) pinToggleButton->setPixmap(BarIcon("pin-blue-on"));
	else 	pinToggleButton->setPixmap(BarIcon("pin-blue-off"));
}