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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include <fstream>
using namespace std;
#include <qinputdialog.h>
#include "mailinglists.h"
#include "preferences.h"
#include "globals.h"
#include "smtp.h"
MailingLists::MailingLists() : QDialog()
{
setCaption( "Kascade Mailing Lists" );
resize( 410, 250 );
setMinimumSize( 410, 250 );
highlight = -1;
Bexit = new QPushButton( this );
Bexit->setText( "Exit" );
Bremove = new QPushButton( this );
Bremove->setText( "Remove" );
Bsubscribe = new QPushButton( this );
Bsubscribe->setText( "Subscribe" );
Bunsubscribe = new QPushButton( this );
Bunsubscribe->setText( "Unsubscribe" );
LBmlists = new QListBox( this );
QObject::connect( Bexit, SIGNAL( clicked() ), this, SLOT( hide() ) );
QObject::connect( Bremove, SIGNAL( clicked() ), this, SLOT( removeItem() ) );
QObject::connect( Bsubscribe, SIGNAL( clicked() ), this, SLOT( subscribe() ) );
QObject::connect( Bunsubscribe, SIGNAL( clicked() ), this, SLOT( unsubscribe() ) );
}
void MailingLists::subscribe()
{
int index = LBmlists->currentItem();
if( index == -1 )
return;
string mlist = mlistv[2*index+1];
Smtp smtp;
smtp.sendMail( config->emailAddress(),
mlist,
"subscribe",
"" );
if( !smtp.success )
return;
string text = (const char *)(LBmlists->text( index ));
text[text.length()-1] = '+';
LBmlists->changeItem( text.c_str(), index );
save();
}
void MailingLists::unsubscribe()
{
int index = LBmlists->currentItem();
if( index == -1 )
return;
string mlist = mlistv[2*index+1];
Smtp smtp;
smtp.sendMail( config->emailAddress(),
mlist,
"unsubscribe",
"" );
if( !smtp.success )
return;
string text = (const char *)(LBmlists->text( index ));
text[text.length()-1] = '-';
LBmlists->changeItem( text.c_str(), index );
save();
}
void MailingLists::removeItem()
{
int index = LBmlists->currentItem();
if( index == -1 )
return;
LBmlists->removeItem( index );
mlistv.erase( mlistv.begin()+2*index, mlistv.begin()+2*index+2 );
save();
}
void MailingLists::addMlist( string name, string address )
{
mlistv.push_back( name + " -" );
mlistv.push_back( address );
update();
save();
}
void MailingLists::resizeEvent( QResizeEvent * )
{
int w = this->width(), h = this->height();
Bsubscribe->setGeometry( w-110, 10, 100, 25 );
Bunsubscribe->setGeometry( w-110, 40, 100, 25 );
Bremove->setGeometry( w-110, 80, 100, 25 );
Bexit->setGeometry( w-110, h-35, 100, 25 );
LBmlists->setGeometry( 10, 10, w-130, h-20 );
}
void MailingLists::update()
{
LBmlists->clear();
for( unsigned int n = 0; n < mlistv.size(); n += 2 )
LBmlists->insertItem( mlistv[n].c_str() );
show();
}
void MailingLists::load()
{
ifstream ifs;
string file = getenv( "HOME" );
file += "/.kascade/mailinglists";
ifs.open( file.c_str() );
if( !ifs.good() )
return;
ifs.unsetf( ios::skipws );
string mlist;
while( !ifs.eof() )
{
getline( ifs, mlist, '\n' );
if( mlist != "" )
mlistv.push_back( mlist );
}
ifs.close();
}
void MailingLists::save()
{
ofstream ofs;
string file = getenv( "HOME" );
file += "/.kascade/mailinglists";
ofs.open( file.c_str() );
for( unsigned int n = 0; n < mlistv.size(); )
ofs << mlistv[n++] << endl;
ofs.close();
}
|