summaryrefslogtreecommitdiffstats
path: root/src/mixminion.ui.h
blob: 5b783393a3ba138160c3d925794b5510c38bb192 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/***************************************************************************
 ** $Id: mixminion.ui.h,v 1.9 2008/07/31 19:56:26 hoganrobert Exp $
 *   Copyright (C) 2006 - 2008 Robert Hogan                                *
 *   [email protected]                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/

#include <tqregexp.h>
#include <tqtimer.h>

#include <kprocio.h>
#include <tdemessagebox.h>
#include <kprogress.h>
#include <kdebug.h>

#include <cstdlib>

#include "torkconfig.h"


KProgressDialog* progressDialog;
TQString output;

void MixMinionClient::init()
{
}

void MixMinionClient::send_clicked()
{

    if (toAddress->text().isEmpty()){
        KMessageBox::information (this, i18n("Emails are usually sent to someone!"), "Umm.");
        return;
    }
    output = "";
    mailLayout->setEnabled(false);

    KProcIO* mixminionproc = new KProcIO();
    mixminionproc->setUseShell(TRUE);

	TQString curpath = (TQString) getenv("PATH");
	mixminionproc->setEnvironment("PATH",curpath + ":/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin");

    mixminionproc->setEnvironment("http_proxy",TQString("%1:%2").arg(TorkConfig::konqHttpProxy())
                                  .arg(TorkConfig::konqHttpProxyPort()));
    mixminionproc->setEnvironment("https_proxy",TQString("%1:%2").arg(TorkConfig::konqHttpsProxy())
                                  .arg(TorkConfig::konqHttpsProxyPort()));

    *mixminionproc << "printf '" << messageBody->text() <<"' | mixminion  send -t " << toAddress->text() 
                << " --subject '" << subject->text() << "'";

 	connect( mixminionproc, SIGNAL(processExited(TDEProcess *)),
 			SLOT(mixminionprocExited(TDEProcess *)) );
	connect( mixminionproc, SIGNAL(readReady(KProcIO *)),
		SLOT(receivedMixminionOutput(KProcIO *)) );

    progressDialog = new KProgressDialog( this, "progress_dialog", TQString::null, "Sending Anonymous Mail Message..", false );

    progressDialog->setPlainCaption( i18n( "Sending Anonymous Mail Message.." ) );

    progressDialog->progressBar()->setTotalSteps( 00 );
    progressDialog->progressBar()->setPercentageVisible( false );

    progressDialog->setMinimumDuration( 500 );
    progressDialog->show();
    TQTimer* timer = new TQTimer( this );
    connect( timer, SIGNAL( timeout() ), this, SLOT( slotProg() ) );

    timer->start( 200, FALSE );

	mixminionproc->start(KProcIO::NotifyOnExit,KProcIO::All);

}

void MixMinionClient::slotProg()
{

    if (progressDialog)
        progressDialog->progressBar()->setProgress(progressDialog->progressBar()->progress() + 4 );
}

void MixMinionClient::receivedMixminionOutput(KProcIO *mixminionproc)
{

    int pos;
    TQString item2;
	while ((mixminionproc) && ((pos = (mixminionproc->readln(item2,true))) != -1)) {
            item2.replace(TQRegExp("^[^#]+\\]"),"");
            progressDialog->setLabel( item2.stripWhiteSpace());
            progressDialog->progressBar()->setProgress(progressDialog->progressBar()->progress() + 4 );
            output += item2;
            output.append("<br>");
            mixminionproc->ackRead();
    }
}


void MixMinionClient::mixminionprocExited(TDEProcess *proc)
{
    TQString caption;
    TQString message;
    delete progressDialog;
    progressDialog = 0;

    if (proc->exitStatus() == 0){
        caption = i18n("Email Successfully Dispatched!");
        message = i18n("<p>%1<br>").arg(output);
    }else{
        caption = i18n("There was a problem!");
        message = i18n("<p>%1<br>").arg(output);

    }

    KMessageBox::information (this, message, caption);

    delete this;
}