Develop and Download Open Source Software

Browse CVS Repository

Diff of /malonnote/mnModel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.29 by maloninc, Fri Dec 30 01:34:40 2005 UTC revision 1.36 by maloninc, Tue Oct 24 06:46:32 2006 UTC
# Line 2  Line 2 
2  #include "mnModel.h"  #include "mnModel.h"
3  #include <wx/dir.h>  #include <wx/dir.h>
4  #include <wx/regex.h>  #include <wx/regex.h>
5    #include <wx/progdlg.h>
6  #include <iconv.h>  #include <iconv.h>
7    #include <ctype.h>
8    
9  static void   toLower(char* string);  static void   toLower(char* string);
10  static char*  decode(const char* string);  static char*  decode(const char* string);
# Line 108  bool mnModel::matchWithToken(wxString* f Line 110  bool mnModel::matchWithToken(wxString* f
110          return ans;          return ans;
111  }  }
112    
113    void mnModel::readAll(bool progBarFlag)
114    {
115            int         fileCount = 0;
116            wxDir*      dir;
117            WikiData*   wikiData;
118        wxString*   fileName = new wxString();
119            char*       tokenList[MAX_TOKEN];
120            bool        cont;
121            wxProgressDialog* progBar = NULL;
122    
123            memset(tokenList, 0, sizeof(char*)*MAX_TOKEN);
124            tokenList[0] = "";
125    
126            dir = new wxDir(*wikiDataDir);
127        if ( !dir->IsOpened() )
128        {
129                    MN_FATAL_ERROR(wxT("wxDir has faild\n"));
130            return ;
131        }
132      
133            /* count number of files */
134            if (progBarFlag) {
135                    cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
136                    while(cont){
137                            fileCount++;
138                            cont = dir->GetNext(fileName);
139                    }
140                    progBar = new wxProgressDialog(wxT("Searching Data"), (wxT("Now searching... ") + *wikiDataDir), fileCount);
141            }
142    
143            fileCount = 0;
144        cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
145            while(cont){
146                    fileCount++;
147                    if (progBarFlag) progBar->Update(fileCount);
148                    matchWithToken(fileName, tokenList); /* match with token list, but never match, just read. */
149            cont = dir->GetNext(fileName);
150            }
151    
152            if (progBarFlag) {
153                    delete progBar;
154            }
155            delete dir;
156            delete fileName;
157    }
158    
159  WikiList* mnModel::search(const char* searchStr)  WikiList* mnModel::search(const char* searchStr)
160  {  {
161          int         i;          int         i;
# Line 461  WikiData::WikiData(wxString* dataDir, wx Line 509  WikiData::WikiData(wxString* dataDir, wx
509                  }                  }
510          }          }
511          fclose(fp);          fclose(fp);
512    
513            isWriteToFile = true;
514  }  }
515    
516  WikiData::WikiData(wxString* dataDir) {  WikiData::WikiData(wxString* dataDir) {
# Line 520  WikiData::WikiData(wxString* dataDir) { Line 570  WikiData::WikiData(wxString* dataDir) {
570          text    = new wxString(buf, conv);          text    = new wxString(buf, conv);
571    
572          if(fp) fclose(fp);          if(fp) fclose(fp);
573    
574            isWriteToFile = false;
575  }  }
576    
577  WikiData::~WikiData()  WikiData::~WikiData()
# Line 625  const wxString* WikiData::getText() Line 677  const wxString* WikiData::getText()
677                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
678          }          }
679    
680          if(text) {          if(text && isWriteToFile == true) {
681                  delete text;                  delete text;
682                  text = NULL;                  text = NULL;
683          }          }
684            else if(text && isWriteToFile == false) {
685                    return text;
686            }
687    
688          text = new wxString();          text = new wxString();
689          sprintf(fullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());          sprintf(fullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());
# Line 724  void WikiData::save() Line 779  void WikiData::save()
779                    
780          free(inbuf);          free(inbuf);
781          free(outbuf);          free(outbuf);
782            
783            isWriteToFile = true;
784  }  }
785    
786  /******* Tools ************************/  /******* Tools ************************/

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.36

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26