fileselector.h

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-2010  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 #ifndef FILESELECTOR_H
00022 #define FILESELECTOR_H
00023 
00024 #include "selectionwindow.h"
00025 #include "../paradialog.h"
00026 #include "../graphics/blitter.h"
00027 #include "../loaders.h"
00028 
00029 class FileSelectionItemFactory;
00030 class SavegameSelectionItemFactory;
00031 
00032 class FileInfo
00033 {
00034    public:
00035       ASCString name;
00036       ASCString location;
00037       time_t modificationTime;
00038       int level;
00039       FileInfo( const ASCString& filename, const ASCString& filelocation, time_t time, int directorylevel  ) : name( filename), location( filelocation ), modificationTime( time ), level( directorylevel )
00040       {}
00041       FileInfo( const FileInfo& fi ) : name( fi.name ), location( fi.location ), modificationTime( fi.modificationTime ), level ( fi.level )
00042       {}
00043 }
00044 ;
00045 
00046 class SavegameWidget: public SelectionWidget {
00047       FileInfo fileInfo;
00048       ASCString time;
00049       bool fileInformationLoaded;
00050       GameFileInformation gfi;
00051       PG_Label* mapTitleLabel;
00052       static Surface alternateImage;
00053    public:
00054       SavegameWidget( PG_Widget* parent, const PG_Point& pos, int width, const FileInfo* fi );
00055       ASCString getName() const;
00056    protected:
00057       void display( SDL_Surface * surface, const PG_Rect & src, const PG_Rect & dst );
00058 
00059 };
00060 
00061 
00062 class FileSelectionWindow : public ASC_PG_Dialog {
00063       ASCString filename;
00064       ASCString wildcard;
00065       bool saveFile;
00066       bool overwriteMessage;
00067       FileSelectionItemFactory* factory;
00068 
00069    protected:
00070       void fileNameSelected( const ASCString& filename );
00071       void fileNameEntered( ASCString filename );
00072    public:
00074       FileSelectionWindow( PG_Widget *parent, const PG_Rect &r, const ASCString& fileWildcard, bool save, bool overwriteMessage );
00075       ASCString getFilename() { return filename; };
00076 };
00077 
00078 
00079 class FileSelectionItemFactory: public SelectionItemFactory  {
00080    protected:
00081       typedef deallocating_vector<FileInfo*> Items;
00082       Items::iterator it;
00083 
00084    private:      
00085       Items items;
00086       
00087    public:
00089       FileSelectionItemFactory( const ASCString& wildcard );
00090       
00091       static bool comp ( const FileInfo* i1, const FileInfo* i2 );
00092 
00093       void restart();
00094 
00095       int getLevel( const ASCString& name );
00096       
00097       SelectionWidget* spawnNextItem( PG_Widget* parent, const PG_Point& pos );
00098       
00099       SigC::Signal1<void,const ASCString& > filenameSelectedMouse;
00100       SigC::Signal1<void,const ASCString& > filenameSelectedKeyb;
00101       SigC::Signal1<void,const ASCString& > filenameMarked;
00102       
00103       void itemMarked( const SelectionWidget* widget );
00104       
00105       void itemSelected( const SelectionWidget* widget, bool mouse );
00106 };
00107 
00108 extern ASCString  selectFile( const ASCString& ext, bool load, bool overwriteMessage = true );
00109 
00110 
00111 class SavegameSelectionWindow : public ASC_PG_Dialog {
00112       ASCString filename;
00113       ASCString wildcard;
00114       bool saveFile;
00115       bool overwriteMessage;
00116       SavegameSelectionItemFactory* factory;
00117 
00118    protected:
00119       void fileNameSelected( const ASCString& filename );
00120       void fileNameEntered( ASCString filename );
00121    public:
00123       SavegameSelectionWindow( PG_Widget *parent, const PG_Rect &r, const ASCString& fileWildcard, bool save, bool overwriteMessage );
00124       ASCString getFilename() { return filename; };
00125 };
00126 
00127 
00128 class SavegameSelectionItemFactory: public SelectionItemFactory  {
00129    protected:
00130       typedef deallocating_vector<FileInfo*> Items;
00131       Items::iterator it;
00132 
00133    private:
00134       Items items;
00135 
00136    public:
00138       SavegameSelectionItemFactory( const ASCString& wildcard );
00139 
00140       static bool comp ( const FileInfo* i1, const FileInfo* i2 );
00141 
00142       void restart();
00143 
00144       int getLevel( const ASCString& name );
00145 
00146       SelectionWidget* spawnNextItem( PG_Widget* parent, const PG_Point& pos );
00147 
00148       SigC::Signal1<void,const ASCString& > filenameSelectedMouse;
00149       SigC::Signal1<void,const ASCString& > filenameSelectedKeyb;
00150       SigC::Signal1<void,const ASCString& > filenameMarked;
00151 
00152       void itemMarked( const SelectionWidget* widget );
00153 
00154       void itemSelected( const SelectionWidget* widget, bool mouse );
00155 };
00156 
00157 
00158 
00159 extern ASCString  selectSavegame( const ASCString& ext, bool load, bool overwriteMessage = true );
00160 
00161 #endif

Generated on Mon May 21 01:26:33 2012 for Advanced Strategic Command by  doxygen 1.5.1