summaryrefslogtreecommitdiff
path: root/noncore/net/mail/opiemail.cpp
blob: e35f5b6bc21b6c6c4186c625066c89e44f012c50 (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
#include <qmessagebox.h>
#include "settingsdialog.h"
#include "opiemail.h"
#include "editaccounts.h"
#include "composemail.h"
#include "smtpwrapper.h"
#include <qpe/qcopenvelope_qws.h>
#include <qaction.h>
#include <qapplication.h>

OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags )
    : MainWindow( parent, name, flags )
{
    settings = new Settings();

    folderView->populate( settings->getAccounts() );

    connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) );
    connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) );
//    connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) );
    connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) );
    // Added by Stefan Eilers to allow starting by addressbook..
    // copied from old mail2
#if !defined(QT_NO_COP)
    connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ),
             this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
#endif
}

void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
{
    // copied from old mail2
    if (msg == "writeMail(QString,QString)") {
        QDataStream stream(data,IO_ReadOnly);
        QString name, email;
        stream >> name >> email;
        // removing the whitespaces at beginning and end is needed!
        slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace());
    } else if (msg == "newMail()") {
        slotComposeMail();
    }
}

void OpieMail::slotwriteMail(const QString&name,const QString&email)
{
    ComposeMail compose( settings, this, 0 , true );
    if (!email.isEmpty()) {
        if (!name.isEmpty()) {
            compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
        } else {
            compose.setTo(email);
        }
    }
    compose.showMaximized();
    compose.slotAdjustColumns();
    compose.exec();
}

void OpieMail::slotComposeMail()
{
    qDebug( "Compose Mail" );
    slotwriteMail(0l,0l);
}

void OpieMail::slotSendQueued()
{
    qDebug( "Send Queued" );
    SMTPaccount *smtp = 0;

    QList<Account> list = settings->getAccounts();
    Account *it;
//    if (list.count()==1) {
        for ( it = list.first(); it; it = list.next() ) {
            if ( it->getType().compare( "SMTP" ) == 0 ) {
                smtp = static_cast<SMTPaccount *>(it);
                break;
            }
        }
//    }
    if (smtp) {
        SMTPwrapper * wrap = new SMTPwrapper(settings);
        if ( wrap->flushOutbox(smtp) ) {
            QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
        }
    }
}

void OpieMail::slotSearchMails()
{
    qDebug( "Search Mails" );
}

void OpieMail::slotEditSettings()
{
    SettingsDialog settingsDialog( this,  0, true );
    settingsDialog.showMaximized();
    settingsDialog.exec();
}

void OpieMail::slotEditAccounts()
{
    qDebug( "Edit Accounts" );
    EditAccounts eaDialog( settings, this, 0, true );
    eaDialog.showMaximized();
    eaDialog.slotAdjustColumns();
    eaDialog.exec();
    if ( settings ) delete settings;
    settings = new Settings();

    folderView->populate( settings->getAccounts() );
}