00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <boost/regex.hpp>
00022
00023 #include "../paradialog.h"
00024 #include "../widgets/dropdownselector.h"
00025 #include "../widgets/textrenderer.h"
00026 #include "../gameoptions.h"
00027 #include "../dlg_box.h"
00028
00029 class MailOptionsDialog : public ASC_PG_Dialog {
00030 typedef map<ASCString,ASCString> ClientSetups;
00031 ClientSetups clientSetups;
00032 map<int,ASCString> clientSetupIndex;
00033
00034 PG_LineEdit* command;
00035 DropDownSelector* dds;
00036
00037 bool cannedConfigSelected( ) {
00038 int index = dds->GetSelectedItemIndex();
00039 if ( clientSetupIndex.find(index) != clientSetupIndex.end() ) {
00040 command->SetText( clientSetupIndex[index]);
00041 return true;
00042 } else
00043 return false;
00044 }
00045
00046 bool ok() {
00047 CGameOptions::Instance()->mailProgram = command->GetText();
00048 CGameOptions::Instance()->setChanged();
00049 QuitModal();
00050 return true;
00051 }
00052
00053 bool cancel() {
00054 QuitModal();
00055 return true;
00056 }
00057
00058
00059 public:
00060 MailOptionsDialog() : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 600, 350), "Email Options")
00061 {
00062 StandardButtonDirection( Horizontal );
00063 if ( exist("email.clients")) {
00064 tnfilestream stream ( "email.clients", tnstream::reading);
00065 bool finished = false;
00066 while ( !finished) {
00067 ASCString line;
00068 finished = !stream.readTextString(line, false);
00069
00070 if ( line.find('#') != 0 ) {
00071
00072
00073 boost::smatch what;
00074 static boost::regex parser( "([^:]+):\\s*(\\S.*)");
00075 if( boost::regex_match( line, what, parser)) {
00076 ASCString client;
00077 client.assign( what[1].first, what[1].second );
00078
00079 ASCString command;
00080 command.assign( what[2].first, what[2].second );
00081
00082 clientSetups[client] = command;
00083 }
00084 }
00085 }
00086 }
00087
00088 if ( clientSetups.size() > 0 ) {
00089 dds = new DropDownSelector( this, PG_Rect( 10, 30, Width() / 2 , 20));
00090 dds->AddItem("-- default configurations --");
00091 int counter = 1;
00092 for ( ClientSetups::iterator i = clientSetups.begin(); i != clientSetups.end(); ++i) {
00093 dds->AddItem(i->first);
00094 clientSetupIndex[counter++] = i->second;
00095 }
00096
00097 PG_Button* apply = new PG_Button( this, PG_Rect( Width()/2 + 20, 30, Width()/2-30, 20),"Apply");
00098 apply->sigClick.connect( SigC::slot( *this, &MailOptionsDialog::cannedConfigSelected));
00099
00100
00101
00102 } else
00103 dds = NULL;
00104
00105 command = new PG_LineEdit( this, PG_Rect( 10, 60, Width() - 20, 25 ));
00106 command->SetText( CGameOptions::Instance()->mailProgram );
00107
00108 ASCString help = readtextmessage( 80 );
00109 if ( !help.empty() )
00110 new TextRenderer( this, PG_Rect( 10, 100, Width()-20, 160 ), help);
00111
00112 AddStandardButton("OK")->sigClick.connect( SigC::slot( *this, &MailOptionsDialog::ok));
00113 AddStandardButton("Cancel")->sigClick.connect( SigC::slot( *this, &MailOptionsDialog::cancel));
00114
00115 }
00116 };
00117
00118 void editEmailOptions()
00119 {
00120 MailOptionsDialog mod;
00121 mod.Show();
00122 mod.RunModal();
00123 }