Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

mailoptionseditor.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
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                   // this is not a comment
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             // dds->selectionSignal.connect( SigC::slot( *this, &MailOptionsDialog::cannedConfigSelected));
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 }

Generated on Tue Jun 24 01:27:44 2008 for Advanced Strategic Command by  doxygen 1.4.2