summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-12-14 00:20:38 (UTC)
committer harlekin <harlekin>2003-12-14 00:20:38 (UTC)
commitff2b84787e454f8a11aaef7a4ce18941ac0d28fd (patch) (side-by-side diff)
tree44bf51f9a3935542cdcfa5dafcc212e4f01ee8ce
parentb0a71314013a3367767526b68928a7168b4ad460 (diff)
downloadopie-ff2b84787e454f8a11aaef7a4ce18941ac0d28fd.zip
opie-ff2b84787e454f8a11aaef7a4ce18941ac0d28fd.tar.gz
opie-ff2b84787e454f8a11aaef7a4ce18941ac0d28fd.tar.bz2
deleting of mails working
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp26
-rw-r--r--noncore/net/mail/accountview.h6
-rw-r--r--noncore/net/mail/mainwindow.cpp29
-rw-r--r--noncore/net/mail/mainwindow.h4
-rw-r--r--noncore/net/mail/viewmail.cpp8
-rw-r--r--noncore/net/mail/viewmail.h3
6 files changed, 64 insertions, 12 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 1069b9f..ac4f0e0 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -40,119 +40,131 @@ RecBody POP3viewItem::fetchBody( const RecMail &mail )
IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
: AccountViewItem( parent )
{
account = a;
wrapper = AbstractMail::getWrapper( account );
setPixmap( 0, PIXMAP_IMAPFOLDER );
setText( 0, account->getAccountName() );
setOpen( true );
}
IMAPviewItem::~IMAPviewItem()
{
delete wrapper;
}
AbstractMail *IMAPviewItem::getWrapper()
{
return wrapper;
}
void IMAPviewItem::refresh(QList<RecMail>&)
{
QList<Folder> *folders = wrapper->listFolders();
-
+
QListViewItem *child = firstChild();
while ( child ) {
QListViewItem *tmp = child;
child = child->nextSibling();
delete tmp;
}
-
+
Folder *it;
for ( it = folders->first(); it; it = folders->next() ) {
(void) new IMAPfolderItem( it, this );
}
}
RecBody IMAPviewItem::fetchBody(const RecMail&)
{
return RecBody();
}
-IMAPfolderItem::~IMAPfolderItem()
+IMAPfolderItem::~IMAPfolderItem()
{
delete folder;
}
IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent )
: AccountViewItem( parent )
{
folder = folderInit;
imap = parent;
setPixmap( 0, PIXMAP_IMAPFOLDER );
setText( 0, folder->getDisplayName() );
}
-void IMAPfolderItem::refresh(QList<RecMail>&target)
+void IMAPfolderItem::refresh(QList<RecMail>&target)
{
imap->getWrapper()->listMessages( folder->getName(),target );
}
RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
{
return imap->getWrapper()->fetchBody(aMail);
}
/**
* Generic stuff
*/
AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
: QListView( parent, name, flags )
{
connect( this, SIGNAL( clicked( QListViewItem * ) ),
SLOT( refresh( QListViewItem * ) ) );
}
void AccountView::populate( QList<Account> list )
{
clear();
-
+
Account *it;
for ( it = list.first(); it; it = list.next() ) {
if ( it->getType().compare( "IMAP" ) == 0 ) {
IMAPaccount *imap = static_cast<IMAPaccount *>(it);
qDebug( "added IMAP " + imap->getAccountName() );
(void) new IMAPviewItem( imap, this );
} else if ( it->getType().compare( "POP3" ) == 0 ) {
POP3account *pop3 = static_cast<POP3account *>(it);
qDebug( "added POP3 " + pop3->getAccountName() );
(void) new POP3viewItem( pop3, this );
}
}
}
void AccountView::refresh(QListViewItem *item) {
+
qDebug("AccountView refresh...");
- if ( item ) {
+ if ( item ) {
+ m_currentItem = item;
QList<RecMail> headerlist;
headerlist.setAutoDelete(true);
AccountViewItem *view = static_cast<AccountViewItem *>(item);
view->refresh(headerlist);
emit refreshMailview(&headerlist);
}
}
+void AccountView::refreshCurrent()
+{
+ if ( !m_currentItem ) return;
+ QList<RecMail> headerlist;
+ headerlist.setAutoDelete(true);
+ AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
+ view->refresh(headerlist);
+ emit refreshMailview(&headerlist);
+}
+
void AccountView::refreshAll()
{
-
+
}
RecBody AccountView::fetchBody(const RecMail&aMail)
{
QListViewItem*item = selectedItem ();
if (!item) return RecBody();
AccountViewItem *view = static_cast<AccountViewItem *>(item);
return view->fetchBody(aMail);
}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 83d49af..cdc87ce 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -56,30 +56,34 @@ class IMAPfolderItem : public AccountViewItem
public:
IMAPfolderItem( Folder *folder, IMAPviewItem *parent );
~IMAPfolderItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
private:
Folder *folder;
IMAPviewItem *imap;
};
class AccountView : public QListView
{
Q_OBJECT
public:
AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
void populate( QList<Account> list );
RecBody fetchBody(const RecMail&aMail);
public slots:
void refreshAll();
void refresh(QListViewItem *item);
+ void refreshCurrent();
signals:
- void refreshMailview(QList<RecMail>*);
+ void refreshMailview(QList<RecMail>*);
+
+private:
+ QListViewItem* m_currentItem;
};
#endif
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index 8ef7ddd..c410829 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -39,153 +39,176 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
composeMail->addTo( mailMenu );
sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED,
0, 0, this );
sendQueued->addTo( toolBar );
sendQueued->addTo( mailMenu );
syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC,
0, 0, this );
syncFolders->addTo( toolBar );
syncFolders->addTo( mailMenu );
showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS,
0, 0, this, 0, true );
showFolders->addTo( toolBar );
showFolders->addTo( mailMenu );
connect(showFolders, SIGNAL( toggled( bool ) ),
SLOT( slotShowFolders( bool ) ) );
searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS,
0, 0, this );
searchMails->addTo( toolBar );
searchMails->addTo( mailMenu );
+ deleteMails = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this);
+ deleteMails->addTo( toolBar );
+ deleteMails->addTo( mailMenu );
+ connect( deleteMails, SIGNAL( activated() ),
+ SLOT( slotDeleteMail() ) );
editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS,
0, 0, this );
editSettings->addTo( settingsMenu );
editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS,
0, 0, this );
editAccounts->addTo( settingsMenu );
QWidget *view = new QWidget( this );
setCentralWidget( view );
layout = new QBoxLayout ( view, QBoxLayout::LeftToRight );
folderView = new AccountView( view );
folderView->header()->hide();
folderView->addColumn( tr( "Mailbox" ) );
folderView->hide();
layout->addWidget( folderView );
mailView = new QListView( view );
mailView->addColumn( tr( "" ) );
mailView->addColumn( tr( "Subject" ),QListView::Manual );
mailView->addColumn( tr( "Sender" ),QListView::Manual );
mailView->addColumn( tr( "Date" ));
mailView->setAllColumnsShowFocus(true);
mailView->setSorting(-1);
layout->addWidget( mailView );
layout->setStretchFactor( folderView, 1 );
layout->setStretchFactor( mailView, 2 );
slotAdjustLayout();
connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this,
SLOT( displayMail( QListViewItem * ) ) );
- connect(folderView,SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*)));
+ connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*)));
QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) );
}
void MainWindow::slotAdjustLayout() {
QWidget *d = QApplication::desktop();
if ( d->width() < d->height() ) {
layout->setDirection( QBoxLayout::TopToBottom );
} else {
layout->setDirection( QBoxLayout::LeftToRight );
}
delete d;
}
void MainWindow::slotAdjustColumns()
{
bool hidden = folderView->isHidden();
if ( hidden ) folderView->show();
folderView->setColumnWidth( 0, folderView->visibleWidth() );
if ( hidden ) folderView->hide();
mailView->setColumnWidth( 0, 10 );
mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 );
mailView->setColumnWidth( 2, 80 );
mailView->setColumnWidth( 3, 50 );
}
void MainWindow::slotShowFolders( bool show )
{
- qDebug( "Show Folders" );
+ qDebug( "Show Folders" );
if ( show && folderView->isHidden() ) {
qDebug( "-> showing" );
folderView->show();
} else if ( !show && !folderView->isHidden() ) {
qDebug( "-> hiding" );
folderView->hide();
}
}
void MainWindow::refreshMailView(QList<RecMail>*list)
{
MailListViewItem*item = 0;
mailView->clear();
for (unsigned int i = 0; i < list->count();++i) {
item = new MailListViewItem(mailView,item);
item->storeData(*(list->at(i)));
item->showEntry();
}
}
void MainWindow::displayMail(QListViewItem*item)
{
+
+ m_currentItem = item;
+
if (!item) return;
RecMail mail = ((MailListViewItem*)item)->data();
RecBody body = folderView->fetchBody(mail);
ViewMail readMail( this );
readMail.setBody( body );
readMail.setMail( mail );
readMail.showMaximized();
readMail.exec();
- ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgunseen") );
+
+ if ( readMail.deleted ) {
+ folderView->refreshCurrent();
+ } else {
+ ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgunseen") );
+ }
}
+void MainWindow::slotDeleteMail()
+{
+ if (!m_currentItem) return;
+ RecMail mail = ((MailListViewItem*)m_currentItem)->data();
+ mail.Wrapper()->deleteMail( mail );
+ folderView->refreshCurrent();
+}
+
+
+
MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item )
:QListViewItem(parent,item),mail_data()
{
}
void MailListViewItem::showEntry()
{
if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) {
setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgunseen") );
} else {
setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgnew") );
}
setText(1,mail_data.getSubject());
setText(2,mail_data.getFrom());
setText(3,mail_data.getDate());
}
void MailListViewItem::storeData(const RecMail&data)
{
mail_data = data;
}
const RecMail& MailListViewItem::data()const
{
diff --git a/noncore/net/mail/mainwindow.h b/noncore/net/mail/mainwindow.h
index 6c1cda0..8641510 100644
--- a/noncore/net/mail/mainwindow.h
+++ b/noncore/net/mail/mainwindow.h
@@ -5,38 +5,40 @@
#include <qlistview.h>
#include <qaction.h>
#include <qtoolbar.h>
#include <qmenubar.h>
#include "accountview.h"
class RecMail;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
public slots:
void slotAdjustColumns();
protected slots:
virtual void slotShowFolders( bool show );
virtual void refreshMailView(QList<RecMail>*);
virtual void displayMail(QListViewItem*);
+ virtual void slotDeleteMail();
void slotAdjustLayout();
protected:
QToolBar *toolBar;
QMenuBar *menuBar;
QPopupMenu *mailMenu, *settingsMenu;
- QAction *composeMail, *sendQueued, *showFolders, *searchMails,
+ QAction *composeMail, *sendQueued, *showFolders, *searchMails, *deleteMails,
*editSettings, *editAccounts, *syncFolders;
AccountView *folderView;
QListView *mailView;
+ QListViewItem* m_currentItem;
QBoxLayout *layout;
};
#endif
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 42707e3..163ffb7 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -1,37 +1,38 @@
#include <qtextbrowser.h>
#include <qmessagebox.h>
#include <qtextstream.h>
#include <qaction.h>
#include <qpopupmenu.h>
#include <qapplication.h>
#include <opie/ofiledialog.h>
#include "settings.h"
#include "composemail.h"
#include "viewmail.h"
#include "abstractmail.h"
+#include "accountview.h"
AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num)
: QListViewItem(parent,after),_partNum(num)
{
setText(0, mime);
setText(1, file);
setText(2, desc);
}
void ViewMail::setBody( RecBody body ) {
m_body = body;
m_mail[2] = body.Bodytext();
attachbutton->setEnabled(body.Parts().count()>0);
attachments->setEnabled(body.Parts().count()>0);
if (body.Parts().count()==0) {
return;
}
AttachItem * curItem=0;
QString type=body.Description().Type()+"/"+body.Description().Subtype();
QString desc;
double s = body.Description().Size();
int w;
w=0;
@@ -148,48 +149,49 @@ void ViewMail::setMail( RecMail mail ) {
m_recMail = mail;
m_mail[0] = mail.getFrom();
m_mail[1] = mail.getSubject();
m_mail[3] = mail.getDate();
m_mail[4] = mail.Msgid();
m_mail2[0] = mail.To();
m_mail2[1] = mail.CC();
m_mail2[2] = mail.Bcc();
setText();
}
ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
: ViewMailBase(parent, name, fl), _inLoop(false)
{
m_gotBody = false;
connect(reply, SIGNAL(activated()), SLOT(slotReply()));
connect(forward, SIGNAL(activated()), SLOT(slotForward()));
+ connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) );
attachments->setEnabled(m_gotBody);
connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) );
}
void ViewMail::setText()
{
QString toString;
QString ccString;
QString bccString;
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);
}
setCaption( caption().arg( m_mail[0] ) );
@@ -294,24 +296,30 @@ void ViewMail::slotForward()
.arg( m_mail[0] );
if (!m_mail[3].isNull())
ftext += QString("Date: %1\n")
.arg( m_mail[3] );
if (!m_mail[0].isNull())
ftext += QString("From: %1\n")
.arg( m_mail[0] );
if (!m_mail[1].isNull())
ftext += QString("Subject: %1\n")
.arg( m_mail[1] );
ftext += QString("\n%1\n")
.arg( m_mail[2]);
ftext += QString("----- End forwarded message -----\n");
Settings *settings = new Settings();
ComposeMail composer( settings ,this, 0, true);
composer.setSubject( "Fwd: " + m_mail[1] );
composer.setMessage( ftext );
composer.showMaximized();
composer.exec();
}
+void ViewMail::slotDeleteMail( )
+{
+ m_recMail.Wrapper()->deleteMail( m_recMail );
+ hide();
+ deleted = true;
+}
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h
index bc12da1..765464c 100644
--- a/noncore/net/mail/viewmail.h
+++ b/noncore/net/mail/viewmail.h
@@ -9,49 +9,52 @@
#include "mailtypes.h"
class AttachItem : public QListViewItem
{
public:
AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num);
int Partnumber() { return _partNum; }
private:
int _partNum;
};
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();
void setMail( RecMail mail );
void setBody( RecBody body );
+ bool deleted;
protected:
QString deHtml(const QString &string);
protected slots:
void slotReply();
void slotForward();
void setText();
void slotItemClicked( QListViewItem * item , const QPoint & point, int c );
+ void slotDeleteMail( );
+
private:
bool _inLoop;
QString m_mailHtml;
bool m_gotBody;
RecBody m_body;
RecMail m_recMail;
// 0 from 1 subject 2 bodytext 3 date
QMap <int,QString> m_mail;
// 0 to 1 cc 2 bcc
QMap <int,QStringList> m_mail2;
};
#endif