summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/viewmail.cpp40
-rw-r--r--noncore/net/mail/viewmail.h9
-rw-r--r--noncore/net/mail/viewmailbase.cpp18
-rw-r--r--noncore/net/mail/viewmailbase.h2
4 files changed, 57 insertions, 12 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index d2f1584..a64a168 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -189,214 +189,250 @@ void ViewMail::setBody(const RecBodyP&body )
{
curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
}
}
}
void ViewMail::slotShowHtml( bool state )
{
m_showHtml = state;
setText();
}
void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int )
{
if (!item )
return;
if ( ( ( AttachItem* )item )->Partnumber() == -1 )
{
setText();
return;
}
QPopupMenu *menu = new QPopupMenu();
int ret=0;
if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" )
{
menu->insertItem( tr( "Show Text" ), 1 );
}
if (item->text(0).left(6)=="image/") {
menu->insertItem(tr("Display image preview"),2);
}
menu->insertItem( tr( "Save Attachment" ), 0 );
menu->insertSeparator(1);
ret = menu->exec( point, 0 );
switch(ret)
{
case 0:
{
MimeTypes types;
types.insert( "all", "*" );
QString str = OFileDialog::getSaveFileName( 1,
"/", item->text( 2 ) , types, 0 );
if( !str.isEmpty() )
{
encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
if (content)
{
QFile output(str);
output.open(IO_WriteOnly);
output.writeBlock(content->Content(),content->Length());
output.close();
delete content;
}
}
}
break ;
case 2:
{
- QString tmpfile = "/tmp/opiemail-image";
+ QString tmpfile = QString("/tmp/opiemail-image-%1").arg(_icounter++);
encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
- if (content) {
+ if (content && content->Length()) {
QFile output(tmpfile);
output.open(IO_WriteOnly);
output.writeBlock(content->Content(),content->Length());
output.close();
delete content;
+ if (!m_PicsInline) {
MailImageDlg iview("");
iview.setName(tmpfile);
QPEApplication::execDialog(&iview);
+ } else {
+ if (!m_lastdlg) {
+ m_lastdlg=new Opie::MM::OImageScrollView("",browser->parentWidget(),false);
+ m_lastdlg->setAutoScale(true);
+ }
+ //m_lastdlg->setImage("");
+ m_lastdlg->setImage(tmpfile);
+ browser->hide();
+ m_lastdlg->show();
+ }
output.remove();
+ } else {
+ QMessageBox::critical(this, tr("Reading attachment"), tr("Could not read content of attachment"));
}
}
break;
case 1:
if ( ( ( AttachItem* )item )->Partnumber() == -1 )
{
setText();
}
else
{
if ( m_recMail->Wrapper() != 0l )
{ // make sure that there is a wrapper , even after delete or simular actions
browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) );
}
}
break;
}
delete menu;
}
void ViewMail::setMail(const RecMailP&mail )
{
m_recMail = mail;
m_mail[0] = mail->getFrom();
m_mail[1] = mail->getSubject();
m_mail[3] = mail->getStringDate();
m_mail[4] = mail->Msgid();
m_mail2[0] = mail->To();
m_mail2[1] = mail->CC();
m_mail2[2] = mail->Bcc();
setCaption(tr("E-Mail by %1").arg( m_mail[0] ) );
setText();
}
ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
: ViewMailBase(parent, name, fl), _inLoop(false)
{
m_gotBody = false;
deleted = false;
connect( reply, SIGNAL(activated()), SLOT(slotReply()));
connect( forward, SIGNAL(activated()), SLOT(slotForward()));
connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) );
connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) );
+ connect( showPicsInline, SIGNAL( toggled(bool) ), SLOT( slotImageInline(bool) ) );
attachments->setEnabled(m_gotBody);
connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) );
+ m_lastdlg = 0;
+ _icounter = 0;
readConfig();
attachments->setSorting(-1);
}
+void ViewMail::slotImageInline(bool how)
+{
+ Config cfg( "mail" );
+ cfg.writeEntry( "showPicsInline", how);
+ m_PicsInline = how;
+ if (m_lastdlg&&!how) {
+ browser->show();
+ m_lastdlg->hide();
+ m_lastdlg->reparent(0,QPoint(0,0),false);
+ delete m_lastdlg;
+ m_lastdlg = 0;
+ }
+}
+
void ViewMail::readConfig()
{
Config cfg( "mail" );
cfg.setGroup( "Settings" );
m_showHtml = cfg.readBoolEntry( "showHtml", false );
+ m_PicsInline = cfg.readBoolEntry( "showPicsInline", true );
+ showPicsInline->setOn(m_PicsInline);
showHtml->setOn( m_showHtml );
}
void ViewMail::setText()
{
QString toString;
QString ccString;
QString bccString;
QString mailHtml;
+ if (m_lastdlg) {
+ m_lastdlg->hide();
+ }
+ browser->show();
for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it )
{
toString += (*it);
}
for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it )
{
ccString += (*it);
}
for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it )
{
bccString += (*it);
}
browser->setTextFormat(Qt::RichText);
mailHtml = "<html><body>"
"<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>"
"<div align=left><b>" + deHtml(m_mail[1]) + "</b></div>"
"</td></tr><tr bgcolor=\"#EEEEE6\"><td>"
"<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>"
"<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" +
tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>"
"<b>" + tr( "Date" ) + ": </b> " + m_mail[3] +
"</td></tr></table>";
if ( !m_showHtml ) {
browser->setText( mailHtml+"<font face=fixed>" + QStyleSheet::convertFromPlainText(m_mail[2]) + "</font></body></html>" );
} else {
browser->setText(mailHtml+m_mail[2].simplifyWhiteSpace()+"</html>");
}
// remove later in favor of a real handling
m_gotBody = true;
}
ViewMail::~ViewMail()
{
m_recMail->Wrapper()->cleanMimeCache();
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 &aString)
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h
index 297836b..f5033f0 100644
--- a/noncore/net/mail/viewmail.h
+++ b/noncore/net/mail/viewmail.h
@@ -1,86 +1,93 @@
#ifndef VIEWMAIL_H
#define VIEWMAIL_H
#include "viewmailbase.h"
#include <libmailwrapper/mailtypes.h>
#include <opie2/odialog.h>
#include <qlistview.h>
#include <qmap.h>
#include <qstringlist.h>
#include <qvaluelist.h>
+class MailImageDlg;
+
namespace Opie { namespace MM { class OImageScrollView; } }
class AttachItem : public QListViewItem
{
public:
AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
const QString&fsize,int num,const QValueList<int>&path);
AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
const QString&fsize,int num,const QValueList<int>&path);
int Partnumber() { return _partNum; }
bool isParentof(const QValueList<int>&path);
private:
int _partNum;
/* needed for a better display of attachments */
QValueList<int> _path;
};
class ViewMail : public ViewMailBase
{
Q_OBJECT
public:
ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
~ViewMail();
void hide();
void exec();
void setMail(const RecMailP&mail );
void setBody(const RecBodyP&body);
bool deleted;
protected:
QString deHtml(const QString &string);
AttachItem* searchParent(const QValueList<int>&path);
AttachItem* lastChild(AttachItem*parent);
+ Opie::MM::OImageScrollView*m_lastdlg;
+
protected slots:
void slotReply();
void slotForward();
void setText();
void slotItemClicked( QListViewItem * item , const QPoint & point, int c );
void slotDeleteMail( );
void slotShowHtml( bool );
+ void slotImageInline(bool);
private:
void readConfig();
bool _inLoop;
QString m_mailHtml;
bool m_gotBody;
RecBodyP m_body;
RecMailP m_recMail;
- bool m_showHtml;
+ bool m_showHtml:1;
+ bool m_PicsInline:1;
+ unsigned int _icounter;
// 0 from 1 subject 2 bodytext 3 date
QMap <int,QString> m_mail;
// 0 to 1 cc 2 bcc
QMap <int,QStringList> m_mail2;
};
class MailImageDlg:public Opie::Ui::ODialog
{
Q_OBJECT
public:
MailImageDlg(const QString&,QWidget *parent = 0, const char *name = 0, bool modal = true, WFlags f = 0);
~MailImageDlg();
void setName(const QString&);
protected:
Opie::MM::OImageScrollView*m_imageview;
};
#endif
diff --git a/noncore/net/mail/viewmailbase.cpp b/noncore/net/mail/viewmailbase.cpp
index 49a0e6a..65ad0d6 100644
--- a/noncore/net/mail/viewmailbase.cpp
+++ b/noncore/net/mail/viewmailbase.cpp
@@ -1,90 +1,92 @@
#include <qtextbrowser.h>
#include <qlistview.h>
#include <qaction.h>
#include <qlabel.h>
#include <qvbox.h>
#include <qtoolbar.h>
+#include <qlayout.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 view"));
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)));
showHtml = new QAction( tr( "Show Html" ), QIconSet( Resource::loadPixmap( "mail/html" ) ), 0, 0, this, 0, true );
showHtml->addTo( toolbar );
showHtml->addTo( mailmenu );
+ showPicsInline= new QAction(tr("Show image preview inline"), QIconSet(Resource::loadPixmap("pixmap")), 0, 0, this);
+ showPicsInline->setToggleAction(true);
+ showPicsInline->addTo(toolbar);
+ showPicsInline->addTo(mailmenu);
+
deleteMail = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("trash")), 0, 0, this);
deleteMail->addTo(toolbar);
deleteMail->addTo(mailmenu);
QVBox *view = new QVBox(this);
+ view->setSpacing(1);
+ view->setMargin(0);
setCentralWidget(view);
attachments = new QListView(view);
attachments->setMinimumHeight(90);
attachments->setMaximumHeight(90);
attachments->setAllColumnsShowFocus(true);
attachments->addColumn("Mime Type", 60);
attachments->addColumn(tr("Description"), 100);
attachments->addColumn(tr("Filename"), 80);
attachments->addColumn(tr("Size"), 80);
attachments->setSorting(-1);
- attachments->hide();
- //header = new QTextBrowser(view);
browser = new QTextBrowser(view);
-
-// openDiag = new OpenDiag(view);
-// openDiag->hide();
-
+ adjustSize();
+ attachments->hide();
}
void ViewMailBase::slotChangeAttachview(bool state)
{
if (state) attachments->show();
else attachments->hide();
}
void ViewMailBase::keyPressEvent ( QKeyEvent * e )
{
if( e->key()==Qt::Key_Escape ) {
close();
e->accept();
return;
}
QWidget::keyPressEvent(e);
}
diff --git a/noncore/net/mail/viewmailbase.h b/noncore/net/mail/viewmailbase.h
index 583b1f6..59179a4 100644
--- a/noncore/net/mail/viewmailbase.h
+++ b/noncore/net/mail/viewmailbase.h
@@ -1,38 +1,38 @@
#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, *showHtml;
+ QAction *reply, *forward, *attachbutton, *deleteMail, *showHtml,*showPicsInline;
QListView *attachments;
QToolBar *toolbar;
QTextBrowser *browser;//,*header;
OpenDiag *openDiag;
QMenuBar *menubar;
QPopupMenu *mailmenu;
protected slots:
void slotChangeAttachview(bool state);
virtual void keyPressEvent ( QKeyEvent * e );
};
#endif