Advanced Strategic Command
mailoptionseditor.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include <boost/regex.hpp>
22 
23 #include "../paradialog.h"
24 #include "../widgets/dropdownselector.h"
25 #include "../widgets/textrenderer.h"
26 #include "../gameoptions.h"
27 #include "../dlg_box.h"
28 
30  typedef map<ASCString,ASCString> ClientSetups;
31  ClientSetups clientSetups;
32  map<int,ASCString> clientSetupIndex;
33 
34  PG_LineEdit* command;
35  DropDownSelector* dds;
36 
37  bool cannedConfigSelected( ) {
38  int index = dds->GetSelectedItemIndex();
39  if ( clientSetupIndex.find(index) != clientSetupIndex.end() ) {
40  command->SetText( clientSetupIndex[index]);
41  return true;
42  } else
43  return false;
44  }
45 
46  bool ok() {
47  CGameOptions::Instance()->mailProgram = command->GetText();
49  QuitModal();
50  return true;
51  }
52 
53  bool cancel() {
54  QuitModal();
55  return true;
56  }
57 
58 
59  public:
60  MailOptionsDialog() : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 600, 350), "Email Options")
61  {
63  if ( exist("email.clients")) {
64  tnfilestream stream ( "email.clients", tnstream::reading);
65  bool finished = false;
66  while ( !finished) {
68  finished = !stream.readTextString(line, false);
69 
70  if ( line.find('#') != 0 ) {
71  // this is not a comment
72 
73  boost::smatch what;
74  static boost::regex parser( "([^:]+):\\s*(\\S.*)");
75  if( boost::regex_match( line, what, parser)) {
76  ASCString client;
77  client.assign( what[1].first, what[1].second );
78 
79  ASCString command;
80  command.assign( what[2].first, what[2].second );
81 
82  clientSetups[client] = command;
83  }
84  }
85  }
86  }
87 
88  if ( clientSetups.size() > 0 ) {
89  dds = new DropDownSelector( this, PG_Rect( 10, 30, Width() / 2 , 20));
90  dds->AddItem("-- default configurations --");
91  int counter = 1;
92  for ( ClientSetups::iterator i = clientSetups.begin(); i != clientSetups.end(); ++i) {
93  dds->AddItem(i->first);
94  clientSetupIndex[counter++] = i->second;
95  }
96 
97  PG_Button* apply = new PG_Button( this, PG_Rect( Width()/2 + 20, 30, Width()/2-30, 20),"Apply");
98  apply->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &MailOptionsDialog::cannedConfigSelected)));
99 
100 
101  // dds->selectionSignal.connect( sigc::mem_fun( *this, &MailOptionsDialog::cannedConfigSelected));
102  } else
103  dds = NULL;
104 
105  command = new PG_LineEdit( this, PG_Rect( 10, 60, Width() - 20, 25 ));
106  command->SetText( CGameOptions::Instance()->mailProgram );
107 
109  if ( !help.empty() )
110  new TextRenderer( this, PG_Rect( 10, 100, Width()-20, 160 ), help);
111 
112  AddStandardButton("OK")->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &MailOptionsDialog::ok)));
113  AddStandardButton("Cancel")->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &MailOptionsDialog::cancel)));
114 
115  }
116 };
117 
119 {
120  MailOptionsDialog mod;
121  mod.Show();
122  mod.RunModal();
123 }
ASCString readtextmessage(int id)
returns the message with the given ID from the message system.
Definition: dlg_box.cpp:3048
void StandardButtonDirection(StandardButtonDirectonType dir)
Definition: paradialog.cpp:511
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void setChanged(bool flag=true)
Definition: gameoptions.h:272
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
void editEmailOptions()
void help(int id)
displays a dialogbog with the given help topic
Definition: dlg_box.cpp:3286
void AddItem(const std::string &text, void *userdata=NULL, Uint16 height=0)
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
Definition: basestrm.cpp:2444
virtual bool readTextString(ASCString &s, bool includeCR=false)
Reads a string.
Definition: basestrm.cpp:511
PG_Button * AddStandardButton(const ASCString &name)
Definition: paradialog.cpp:516
ASCString mailProgram
Definition: gameoptions.h:231
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181