summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-12-09 01:05:53 (UTC)
committer harlekin <harlekin>2003-12-09 01:05:53 (UTC)
commit6142ad15ac50090b95bb5d80116c1750ffc515de (patch) (side-by-side diff)
tree177b72b44446824d6faa13e140ab95a25c931b81
parente372949ac776a7d986cac91b2ff1a5022040d43b (diff)
downloadopie-6142ad15ac50090b95bb5d80116c1750ffc515de.zip
opie-6142ad15ac50090b95bb5d80116c1750ffc515de.tar.gz
opie-6142ad15ac50090b95bb5d80116c1750ffc515de.tar.bz2
beginning of a view mail part
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/mail.pro4
-rw-r--r--noncore/net/mail/mainwindow.cpp8
-rw-r--r--noncore/net/mail/viewmail.cpp216
-rw-r--r--noncore/net/mail/viewmail.h75
-rw-r--r--noncore/net/mail/viewmailbase.cpp75
-rw-r--r--noncore/net/mail/viewmailbase.h36
6 files changed, 413 insertions, 1 deletions
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index 2142cdc..3ae1ddc 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -5,12 +5,14 @@ HEADERS = defines.h \
settings.h \
editaccounts.h \
mailwrapper.h \
composemail.h \
accountview.h \
mainwindow.h \
+ viewmail.h \
+ viewmailbase.h \
opiemail.h \
imapwrapper.h
SOURCES = main.cpp \
opiemail.cpp \
mainwindow.cpp \
@@ -18,12 +20,14 @@ SOURCES = main.cpp \
composemail.cpp \
mailwrapper.cpp \
imapwrapper.cpp \
addresspicker.cpp \
editaccounts.cpp \
logindialog.cpp \
+ viewmail.cpp \
+ viewmailbase.cpp \
settings.cpp
INTERFACES = editaccountsui.ui \
selectmailtypeui.ui \
imapconfigui.ui \
pop3configui.ui \
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index 6f054cc..6e8f4d3 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -3,12 +3,13 @@
#include <qheader.h>
#include <qtimer.h>
#include "defines.h"
#include "mainwindow.h"
+#include "viewmail.h"
MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
: QMainWindow( parent, name, flags )
{
setCaption( tr( "Opie-Mail" ) );
setToolBarsMovable( false );
@@ -135,13 +136,18 @@ void MainWindow::displayMail(QListViewItem*item)
{
if (!item) return;
qDebug("View mail");
RecMail mail = ((MailListViewItem*)item)->data();
QString body = folderView->fetchBody(mail);
- qDebug(body);
+ ViewMail readMail( this );
+ readMail.setMailInfo( mail.getFrom(), "", mail.getSubject(), "", "", body );
+ readMail.showMaximized();
+ readMail.exec();
+
+ qDebug(body );
}
void MailListViewItem::showEntry()
{
setText(0,mail_data.getSubject());
setText(1,mail_data.getFrom());
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
new file mode 100644
index 0000000..b648b34
--- a/dev/null
+++ b/noncore/net/mail/viewmail.cpp
@@ -0,0 +1,216 @@
+#include <qtextbrowser.h>
+#include <qmessagebox.h>
+#include <qaction.h>
+#include <qapplication.h>
+
+//#include "mailfactory.h"
+//#include "composer.h"
+#include "viewmail.h"
+
+AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore)
+ : QListViewItem(parent), _attachItemStore(attachItemStore)
+{
+ setText(0, _attachItemStore.mimeType());
+ setText(1, _attachItemStore.fileName());
+ setText(2, _attachItemStore.description());
+}
+
+AttachItem::AttachItem(QListViewItem *parent, AttachItemStore &attachItemStore)
+ : QListViewItem(parent), _attachItemStore(attachItemStore)
+{
+ setText(0, _attachItemStore.mimeType());
+ setText(1, _attachItemStore.fileName());
+ setText(2, _attachItemStore.description());
+}
+
+void ViewMail::setMailInfo( const QString & from, const QString & to, const QString & subject, const QString & cc, const QString & bcc, const QString & bodytext ) {
+
+m_mail[0] = from;
+m_mail[1] = to;
+m_mail[2] = subject;
+m_mail[3] = cc;
+m_mail[4] = bcc;
+m_mail[5] = bodytext;
+
+setText();
+
+}
+
+
+ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
+ : ViewMailBase(parent, name, fl), _inLoop(false)
+{
+ _gotBody = false;
+
+ connect(reply, SIGNAL(activated()), SLOT(slotReply()));
+ connect(forward, SIGNAL(activated()), SLOT(slotForward()));
+
+ attachments->setEnabled(_gotBody);
+
+// _handler->iUid("FETCH", QString("%1 (BODY[1])").arg(mail.uid()));
+// connect(_handler, SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPUid(IMAPResponse &)));
+}
+
+void ViewMail::setText()
+{
+
+ setCaption( caption().arg( m_mail[0] ) );
+
+ _mailHtml = tr(
+ "<html><body>"
+ "<div align=center><b>%1</b></div>"
+ "<b>From:</b> %2<br>"
+ "<b>To:</b> %3<br>"
+ "%4"
+ "%5"
+ "<b>Date:</b> %6<hr>"
+ "<font face=fixed>%7</font>")
+ .arg( deHtml( m_mail[2] ) )
+ .arg( deHtml( m_mail[0] ) )
+ .arg( deHtml( m_mail[1] ) )
+ .arg( tr("<b>Cc:</b> %1<br>").arg( deHtml( m_mail[3] ) ) )
+ .arg( tr("<b>Bcc:</b> %1<br>").arg( deHtml( m_mail[4] ) ) )
+ .arg( tr("(no date)" ) )
+ .arg("%1");
+ browser->setText( QString(_mailHtml) + deHtml( m_mail[5] ) );
+}
+
+
+
+ViewMail::~ViewMail()
+{
+ hide();
+}
+
+void ViewMail::hide()
+{
+ QWidget::hide();
+
+ if (_inLoop) {
+ _inLoop = false;
+ qApp->exit_loop();
+ }
+}
+
+void ViewMail::exec()
+{
+ show();
+
+ if (!_inLoop) {
+ _inLoop = true;
+ qApp->enter_loop();
+ }
+}
+
+QString ViewMail::deHtml(const QString &string)
+{
+ QString string_ = string;
+ string_.replace(QRegExp("&"), "&amp;");
+ string_.replace(QRegExp("<"), "&lt;");
+ string_.replace(QRegExp(">"), "&gt;");
+ string_.replace(QRegExp("\\n"), "<br>");
+ return string_;
+}
+
+void ViewMail::slotReply()
+{
+ if (!_gotBody) {
+ QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
+ return;
+ }
+
+ QString rtext;
+// rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
+// .arg(_mail.envelope().from()[0].toString())
+// .arg(_mail.envelope().mailDate());
+
+// QString text = _mail.bodyPart(1).data();
+// QStringList lines = QStringList::split(QRegExp("\\n"), text);
+ QStringList::Iterator it;
+// for (it = lines.begin(); it != lines.end(); it++) {
+// rtext += "> " + *it + "\n";
+// }
+ rtext += "\n";
+
+ QString prefix;
+// if (_mail.envelope().subject().find(QRegExp("^Re: *$")) != -1) prefix = "";
+// else prefix = "Re: "; // no i18n on purpose
+
+// SendMail sendMail;
+// sendMail.setTo(_mail.envelope().from()[0].toString());
+// sendMail.setSubject(prefix + _mail.envelope().subject());
+// sendMail.setInReplyTo(_mail.envelope().messageId());
+// sendMail.setMessage(rtext);
+
+// Composer composer(this, 0, true);
+// composer.setSendMail(sendMail);
+// composer.showMaximized();
+// composer.exec();
+}
+
+void ViewMail::slotForward()
+{
+ if (!_gotBody) {
+ QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok"));
+ return;
+ }
+
+ QString ftext;
+/* ftext += QString("\n----- Forwarded message from %1 -----\n\n")
+ .arg(_mail.envelope().from()[0].toString());
+ if (!_mail.envelope().mailDate().isNull())
+ ftext += QString("Date: %1\n")
+ .arg(_mail.envelope().mailDate());
+ if (!_mail.envelope().from()[0].toString().isNull())
+ ftext += QString("From: %1\n")
+ .arg(_mail.envelope().from()[0].toString());
+ if (!_mail.envelope().to().toString().isNull())
+ ftext += QString("To: %1\n")
+ .arg(_mail.envelope().to().toString());
+ if (!_mail.envelope().cc().toString().isNull())
+ ftext += QString("Cc: %1\n")
+ .arg(_mail.envelope().cc().toString());
+ if (!_mail.envelope().bcc().toString().isNull())
+ ftext += QString("Bcc: %1\n")
+ .arg(_mail.envelope().bcc().toString());
+ if (!_mail.envelope().subject().isNull())
+ ftext += QString("Subject: %1\n")
+ .arg(_mail.envelope().subject());
+
+ ftext += QString("\n%1\n")
+ .arg(_mail.bodyPart(1).data());
+
+ ftext += QString("----- End forwarded message -----\n");
+*/
+/*
+ SendMail sendMail;
+ sendMail.setSubject("Fwd: " + _mail.envelope().subject());
+ sendMail.setMessage(ftext);
+
+ Composer composer(this, 0, true);
+ composer.setSendMail(sendMail);
+ composer.showMaximized();
+ composer.exec();
+*/
+}
+
+/*
+void ViewMail::slotIMAPUid(IMAPResponse &response)
+{
+ disconnect(_handler, SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPUid(IMAPResponse &)));
+
+ if (response.statusResponse().status() == IMAPResponseEnums::OK) {
+ QValueList<IMAPResponseBodyPart> bodyParts;
+ bodyParts.append(response.FETCH()[0].bodyPart(0));
+ _mail.setBodyParts(bodyParts);
+
+ browser->setText(QString(_mailHtml).arg(deHtml(response.FETCH()[0].bodyPart(0).data())));
+
+// fillList(response.FETCH()[0].bodyStructure());
+
+ _gotBody = true;
+ } else {
+ QMessageBox::warning(this, tr("Error"), tr("<p>I was unable to retrieve the mail from the server. You can try again later or give up.</p>"), tr("Ok"));
+ }
+}
+*/
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h
new file mode 100644
index 0000000..9d3c6e4
--- a/dev/null
+++ b/noncore/net/mail/viewmail.h
@@ -0,0 +1,75 @@
+#ifndef VIEWMAIL_H
+#define VIEWMAIL_H
+
+#include <qlistview.h>
+#include <qmap.h>
+
+#include "viewmailbase.h"
+//#include "imapresponse.h"
+//#include "mailtable.h"
+
+class AttachItemStore
+{
+public:
+ void setMimeType(QString mimeType) { _mimeType = mimeType; }
+ QString mimeType() { return _mimeType; }
+ void setFileName(QString fileName) { _fileName = fileName; }
+ QString fileName() { return _fileName; }
+ void setDescription(QString description) { _description = description; }
+ QString description() { return _description; }
+ void setPartNum(QString partNum) { _partNum = partNum; }
+ QString partNum() { return _partNum; }
+
+private:
+ QString _mimeType, _fileName, _description, _partNum;
+
+};
+
+class AttachItem : public QListViewItem
+{
+public:
+ AttachItem(QListView *parent, AttachItemStore &attachment);
+ AttachItem(QListViewItem *parent, AttachItemStore &attachment);
+
+ AttachItemStore attachItemStore() { return _attachItemStore; }
+
+private:
+ AttachItemStore _attachItemStore;
+
+};
+
+class ViewMail : public ViewMailBase
+{
+ Q_OBJECT
+
+public:
+ ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal);
+ ~ViewMail();
+
+ void hide();
+ void exec();
+ static QString appName() { return QString::fromLatin1("mail"); }
+ void setMailInfo( const QString & from, const QString & to, const QString & subject, const QString & cc, const QString & bcc, const QString & bodytext );
+
+protected:
+// void fillList(IMAPResponseBODYSTRUCTURE &structure);
+ QString deHtml(const QString &string);
+
+protected slots:
+ void slotReply();
+ void slotForward();
+ void setText();
+
+// void slotIMAPUid(IMAPResponse &response);
+
+private:
+ bool _inLoop;
+// IMAPResponseFETCH _mail;
+// IMAPHandler *_handler;
+ QString _mailHtml;
+ bool _gotBody;
+ QMap <int,QString> m_mail;
+
+};
+
+#endif
diff --git a/noncore/net/mail/viewmailbase.cpp b/noncore/net/mail/viewmailbase.cpp
new file mode 100644
index 0000000..197a665
--- a/dev/null
+++ b/noncore/net/mail/viewmailbase.cpp
@@ -0,0 +1,75 @@
+#include <qtextbrowser.h>
+#include <qlistview.h>
+#include <qaction.h>
+#include <qlabel.h>
+#include <qvbox.h>
+#include <qpopupmenu.h>
+
+#include <qpe/qpetoolbar.h>
+#include <qmenubar.h>
+#include <qpe/resource.h>
+
+#include "viewmailbase.h"
+//#include "opendiag.h"
+
+ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl)
+ : QMainWindow(parent, name, fl)
+{
+ setCaption(tr("E-Mail by %1"));
+ setToolBarsMovable(false);
+
+ toolbar = new QToolBar(this);
+ menubar = new QMenuBar( toolbar );
+ mailmenu = new QPopupMenu( menubar );
+ menubar->insertItem( tr( "Mail" ), mailmenu );
+
+ toolbar->setHorizontalStretchable(true);
+ addToolBar(toolbar);
+
+ QLabel *spacer = new QLabel(toolbar);
+ spacer->setBackgroundMode(QWidget::PaletteButton);
+ toolbar->setStretchableWidget(spacer);
+
+ reply = new QAction(tr("Reply"), QIconSet(Resource::loadPixmap("mail/reply")), 0, 0, this);
+ reply->addTo(toolbar);
+ reply->addTo(mailmenu);
+
+ forward = new QAction(tr("Forward"), QIconSet(Resource::loadPixmap("mail/forward")), 0, 0, this);
+ forward->addTo(toolbar);
+ forward->addTo(mailmenu);
+
+ attachbutton = new QAction(tr("Attachments"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true);
+ attachbutton->addTo(toolbar);
+ attachbutton->addTo(mailmenu);
+ connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool)));
+
+ deleteMail = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this);
+ deleteMail->addTo(toolbar);
+ deleteMail->addTo(mailmenu);
+
+ QVBox *view = new QVBox(this);
+ setCentralWidget(view);
+
+ attachments = new QListView(view);
+ attachments->setMinimumHeight(90);
+ attachments->setMaximumHeight(90);
+ attachments->setAllColumnsShowFocus(true);
+ attachments->addColumn("Mime Type", 100);
+ attachments->addColumn("Filename", 100);
+ attachments->addColumn("Description", 100);
+ attachments->hide();
+
+ browser = new QTextBrowser(view);
+
+// openDiag = new OpenDiag(view);
+// openDiag->hide();
+
+}
+
+void ViewMailBase::slotChangeAttachview(bool state)
+{
+ if (state) attachments->show();
+ else attachments->hide();
+}
+
+
diff --git a/noncore/net/mail/viewmailbase.h b/noncore/net/mail/viewmailbase.h
new file mode 100644
index 0000000..898522e
--- a/dev/null
+++ b/noncore/net/mail/viewmailbase.h
@@ -0,0 +1,36 @@
+#ifndef VIEWMAILBASE_H
+#define VIEWMAILBASE_H
+
+#include <qmainwindow.h>
+
+class QAction;
+class OpenDiag;
+class QListView;
+class QToolBar;
+class QTextBrowser;
+class QMenuBar;
+class QPopupMenu;
+
+class ViewMailBase : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ ViewMailBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
+
+protected:
+ QAction *reply, *forward, *attachbutton, *deleteMail;
+ QListView *attachments;
+ QToolBar *toolbar;
+ QTextBrowser *browser;
+ OpenDiag *openDiag;
+ QMenuBar *menubar;
+ QPopupMenu *mailmenu;
+
+protected slots:
+ void slotChangeAttachview(bool state);
+
+};
+
+#endif
+