include/ax_resource/ax_resource_library.h

Go to the documentation of this file.
00001 
00002 // Name:        ax_resource_library.h
00003 // Purpose:     Accessibility classes: AxResourceLibrary
00004 // Author:      Julian Smart
00005 // Modified by:
00006 // Created:     2009-03-20
00007 // RCS-ID:
00008 // Copyright:   (c) Julian Smart
00009 // Licence:     New BSD License
00011 
00012 #ifndef __AX_RESOURCELIBRART_H_
00013 #define __AX_RESOURCELIBRART_H_
00014 
00015 #include "wx/dynarray.h"
00016 
00017 #include "ax_resource/ax_resource.h"
00018 #include "ax_resource/ax_supportedfiles.h"
00019 
00020 class wxOutputStream;
00021 class wxInputStream;
00022 class wxDataOutputStream;
00023 class wxDataInputStream;
00024 class AxResourceLibrary;
00025 class wxEditorCommandManager;
00026 class wxDataStreamHelper;
00027 
00028 #define axLIBRARY_FORMAT_VERSION 1.0
00029 
00038 class AxResourceInfo: public wxObject
00039 {
00040 public:
00041     AxResourceInfo();
00042     AxResourceInfo(const AxResourceInfo& info) { Init(); Copy(info); }
00043     ~AxResourceInfo();
00044 
00046     void Init();
00047 
00048     void Copy(const AxResourceInfo& info);
00049     void operator=(const AxResourceInfo& info) { Init(); Copy(info); }
00050     bool operator==(const AxResourceInfo& info) const;
00051 
00052     bool Read(wxDataStreamHelper& helper);
00053     bool Write(wxDataStreamHelper& helper);
00054 
00056     AxResource* GetResource() const { return m_resource; }
00057     void SetResource(AxResource* resource) { m_resource = resource; }
00058 
00060     bool GetModified() const;
00061     void SetModified(bool mod);
00062 
00064     bool GetOwnsResource() const { return m_ownsResource; }
00065     void SetOwnsResource(bool owns) { m_ownsResource = owns; }
00066 
00068     void Clear();
00069 
00070     //int             m_bookType;
00071     //int             m_bookStatus; // owned, or on wishlist
00072 
00073     bool            m_deleted;
00074     long            m_recordIdentifier;
00075     AxResource*     m_resource;
00076     bool            m_ownsResource;
00077 
00078     //wxImageBlock    m_thumbnailImageBlock;
00079     //cdCoverDesign   m_coverDesign;
00080 };
00081 
00082 WX_DECLARE_OBJARRAY(AxResourceInfo, AxResourceInfoArray);
00083 
00084 /*
00085    AxFolder: represents a folder containing files; for example, a music album.
00086  */
00087 
00088 class AxFolder
00089 {
00090 public:
00091     AxFolder() {}
00092     AxFolder(const AxFolder& folder) {  Copy(folder); }
00093 
00094     void Copy(const AxFolder& folder) { m_filenames = folder.m_filenames; m_folderName = folder.m_folderName; }
00095     void operator= (const AxFolder& folder) { Copy(folder); }
00096 
00097     wxArrayString   m_filenames;
00098     wxString        m_folderName;
00099 };
00100 
00101 WX_DECLARE_OBJARRAY(AxFolder, AxFolders);
00102 
00111 class AxResourceSet: public wxObject
00112 {
00113 public:
00114     AxResourceSet(AxResourceLibrary* library = NULL);
00115     AxResourceSet(const AxResourceSet& set) { Init(); Copy(set); }
00116 
00118     void Init();
00119 
00120     void Copy(const AxResourceSet& set);
00121     void operator=(const AxResourceSet& set) { Init(); Copy(set); }
00122     bool operator==(const AxResourceSet& set) const;
00123 
00125     AxResource* GetResource(int idx) const;
00126 
00128     AxResourceLibrary* GetResourceLibrary() const { return m_library; }
00129 
00131     void SetResourceLibrary(AxResourceLibrary* library) { m_library = library; }
00132 
00134     void Clear();
00135 
00137     AxResourceArray& GetResources() { return m_resources; }
00138     const AxResourceArray& GetReources() const { return m_resources; }
00139 
00141     size_t GetCount() const { return m_resources.GetCount(); }
00142 
00143     AxResourceArray     m_resources;
00144     AxResourceLibrary*  m_library;
00145 };
00146 
00153 class AxResourceLibrarySettings: public wxObject
00154 {
00155 public:
00156 
00157     AxResourceLibrarySettings() { Init(); }
00158     AxResourceLibrarySettings(const AxResourceLibrarySettings& settings) { Copy(settings); }
00159     ~AxResourceLibrarySettings();
00160 
00161     void Init();
00162     void operator=(const AxResourceLibrarySettings& settings) { Copy(settings); }
00163     void Copy(const AxResourceLibrarySettings& settings);
00164 
00166     void SetMainLibraryPath(const wxString& path) { m_mainLibraryPath = path; }
00167     const wxString& GetMainLibraryPath() const { return m_mainLibraryPath; }
00168 
00170     void SetAdditionalLibraryPaths(const wxArrayString& paths) { m_additionalLibraryPaths = paths; }
00171     const wxArrayString& GetAdditionalLibraryPaths() const { return m_additionalLibraryPaths; }
00172     wxArrayString& GetAdditionalLibraryPaths() { return m_additionalLibraryPaths; }
00173 
00175     void SetLibraryDataFile(const wxString& path) { m_libraryDataFile = path; }
00176     const wxString& GetLibraryDataFile() const { return m_libraryDataFile; }
00177 
00179     wxString GetLibraryChangesDataFile() const;
00180 
00182     void SetSupportedFiles(const AxSupportedFiles& supported) { m_supportedFiles = supported; }
00183 
00185     AxSupportedFiles& GetSupportedFiles() { return m_supportedFiles; }
00186     const AxSupportedFiles& GetSupportedFiles() const { return m_supportedFiles; }
00187 
00188     wxString                m_mainLibraryPath;
00189     wxArrayString           m_additionalLibraryPaths;
00190     wxString                m_uploadPath;
00191     wxString                m_libraryDataFile;
00192     AxSupportedFiles        m_supportedFiles;
00193 };
00194 
00201 // Search flags
00202 #define axSEARCH_EXACT_MATCH    0x01
00203 #define axSEARCH_CONTAINS       0x02
00204 #define axSEARCH_IGNORE_CASE    0x04
00205 
00206 // I/O flags
00207 #define axWRITE_CHANGES_ONLY    0x01
00208 #define axREAD_MERGE            0x02
00209 
00210 //  Query flags
00211 #define axISBN_QUERY_EXACT_MATCH 0x01
00212 
00213 class AxResourceLibrary: public wxObject
00214 {
00215 public:
00216 
00217     AxResourceLibrary() { Init(); }
00218     AxResourceLibrary(const AxResourceLibrary& library) { Copy(library); }
00219     ~AxResourceLibrary();
00220 
00221     void Init();
00222     void operator=(const AxResourceLibrary& library) { Copy(library); }
00223     void Copy(const AxResourceLibrary& library);
00224 
00226     virtual bool Initialize();
00227 
00229     virtual bool Uninitialize();
00230 
00232     static AxResourceLibrary* GetResourceLibrary() { return sm_library; }
00233 
00235     virtual void CreateFullWorkingSet();
00236     virtual void CreateFullWorkingSet(AxResourceSet& workingSet);
00237 
00240     virtual void CreateWorkingSetFromSearch(const wxString& field, const wxString& value, int flags = axSEARCH_EXACT_MATCH);
00241     virtual void CreateWorkingSetFromSearch(AxResourceSet& workingSet, const wxString& field, const wxString& value, int flags = axSEARCH_EXACT_MATCH);
00242 
00244     virtual void ApplySearchToWorkingSet(const wxString& field, const wxString& value, int flags);
00245     virtual void ApplySearchToWorkingSet(AxResourceSet& workingSet, const wxString& field, const wxString& value, int flags);
00246 
00248     virtual bool Match(AxResource& resource, const wxString& field, const wxString& value, int flags);
00249 
00252     virtual bool RefreshAll();
00253 
00255     virtual bool LoadFromFolder(const wxString& folder, bool clearFirst = true, bool checkIfFileLoaded = false);
00256     virtual bool LoadFromFolder(AxResourceInfoArray& books, const wxString& folder, bool clearFirst = true, bool checkIfFileLoaded = false, bool allocId = true);
00257 
00259     virtual bool LoadFromFolders(const wxArrayString& folders, bool clearFirst = true, bool checkIfFileLoaded = false);
00260 
00262     virtual bool RefreshLibrary(bool clearAll, bool interactive, wxWindow* parent = NULL);
00263 
00265     virtual bool LoadLibrary();
00266 
00268     virtual bool SaveLibrary(bool forceConsolidatedWrite = false);
00269 
00271     virtual AxResource* CreateResourceFromFile(const wxString& filename);
00272 
00274     bool AggregateFiles(AxResourceInfoArray& books, wxArrayString& files, bool checkIfFileLoaded, bool allocId);
00275 
00277     bool LoadImageFromCoverDesign(AxResourceInfo& info, const wxSize& thumbnailImageSize);
00278 
00280     int AddResource(AxResource* resource);
00281 
00283     int AddResource(AxResourceInfo& info, bool isNew);
00284 
00286     bool RemoveSelectedBooks(bool interactive = true, wxWindow* win = NULL);
00287 
00289     bool RemoveResource(int sel, bool interactive = true, wxWindow* win = NULL);
00290 
00292     bool PurgeDeletedFiles();
00293 
00295     bool RecursivelyFindFiles(const wxString& folder, AxFolders& folders);
00296 
00298     bool LoadEpubBookInfo(const wxString& filename, AxResourceInfo& info, bool makeThumbnail, const wxSize& thumbnailImageSize, bool& foundCoverImage);
00299 
00301     bool IsFileSupported(const wxString& filename) const;
00302 
00304     bool IsFileInIndex(const wxString& filename) const;
00305     bool IsFileInIndex(const AxResourceInfoArray& books, const wxString& filename) const;
00306 
00308     int FindByFile(const wxString& filename) const;
00309     int FindByFile(const AxResourceInfoArray& books, const wxString& filename) const;
00310 
00312     AxResourceInfo* FindByRecordIdentifier(long id) const;
00313 
00315     wxString CreateHtmlSummary(AxResourceInfo& info, const wxColour& backgroundColour, const wxColour& textColour);
00316 
00318     wxString CreateHtmlBlankSummary(const wxColour& backgroundColour, const wxColour& textColour);
00319 
00321     int CompareItems(AxResource& item1, AxResource& item2, int col);
00322     int CompareItemsHelper(AxResource& item1, AxResource& item2, int col);
00323 
00325     virtual void Sort(int col);
00326 
00328     void UpdateSelectedBookInfo(int idx, bool forceClear = false);
00329 
00330     virtual bool Read(wxInputStream& stream, wxDataInputStream& dataStream, int flags = 0);
00331     virtual bool Write(wxOutputStream& stream, wxDataOutputStream& dataStream, int flags = 0);
00332 
00333     virtual bool Read(const wxString& filename, int flags = 0);
00334     virtual bool Write(const wxString& filename, int flags = 0);
00335 
00338     virtual bool CanWriteChangesSeparately(int percentageThreshold = 20);
00339 
00341     virtual void Clear();
00342 
00344     long GetLastIdentifier() const { return m_lastIdentifier; }
00345     void SetLastIdentifier(long id) { m_lastIdentifier = id; }
00346 
00348     long AllocateNewIdentifier();
00349 
00351     const AxResourceInfoArray& GetBooks() const { return m_resources; }
00352     AxResourceInfoArray& GetBooks() { return m_resources; }
00353 
00355     bool GetModified() const { return m_modified; }
00356     void SetModified(bool mod) { m_modified = mod; }
00357 
00359     wxArrayString& GetCurrentAuthors() { return m_currentAuthors; }
00360     wxArrayString& GetCurrentPublishers() { return m_currentPublishers; }
00361     wxArrayString& GetCurrentSubjects() { return m_currentSubjects; }
00362     wxArrayString& GetCurrentFormats() { return m_currentFormats; }
00363 
00365     void AddToCurrentAuthors(const wxString& author);
00366     void AddToCurrentPublishers(const wxString& publisher);
00367     void AddToCurrentSubjects(const wxString& subject);
00368     void AddToCurrentFormats(const wxString& format);
00369 
00371     void AddCurrentInfo(const AxResourceInfo& info);
00372 
00374     int GetSelection() const { return m_selection; }
00375 
00377     AxResourceInfo* GetSelectedBook() const;
00378 
00380     void SetSelection(int sel, bool select = true);
00381 
00383     void SetSingleSelection(int sel);
00384 
00386     void ClearSelections();
00387 
00389     bool GetSelections(wxArrayInt& selections);
00390 
00391     void DisableProcessing(bool disable) { m_disableProcessing = disable; }
00392     bool IsProcessingDisabled() const { return m_disableProcessing; }
00393 
00395     bool DoSearch(const wxString& searchText);
00396 
00398     // cdCoverDesign& GetDefaultCoverDesign() { return m_coverDesign; }
00399 
00401     // shEbookDownloadManager& GetDownloadManager() { return m_downloadManager; }
00402 
00404     const wxSize& GetSummaryCoverSize() const { return m_summaryCoverSize; }
00405     const wxSize& GetThumbnailCoverSize() const { return m_thumbnailCoverSize; }
00406     void SetSummaryCoverSize(const wxSize& sz) { m_summaryCoverSize = sz; }
00407     void SetThumbnailCoverSize(const wxSize& sz) { m_thumbnailCoverSize = sz; }
00408 
00410     // void InstantiateKeywords(AxResourceInfo& info, cdKeywordProvider& keywordProvider);
00411 
00413     int GetSortByCol() const { return m_sortByCol; }
00414     void SetSortByCol(int col) { m_sortByCol = col; }
00415 
00417     // const wxTreeItemId& GetSitesRootItem() const { return m_sitesRoot; }
00418 
00420     bool UploadFiles(wxWindow* parent);
00421 
00423     bool CanUploadFiles() const;
00424 
00426     void SetSettings(const AxResourceLibrarySettings& settings) { m_settings = settings; }
00427 
00429     AxResourceLibrarySettings& GetSettings() { return m_settings; }
00430     const AxResourceLibrarySettings& GetSettings() const { return m_settings; }
00431 
00436     void SetCommandManager(wxEditorCommandManager* manager) { m_commandManager = manager; }
00437     wxEditorCommandManager* GetCommandManager() const { return m_commandManager; }
00438 
00439 private:
00440     AxResourceInfoArray         m_resources;
00441 
00442     AxResourceSet               m_workingSet;
00443     bool                        m_modified;
00444 
00445     wxArrayString               m_currentAuthors;
00446     wxArrayString               m_currentPublishers;
00447     wxArrayString               m_currentSubjects;
00448     wxArrayString               m_currentFormats;
00449 
00450     int                         m_selection;
00451     int                         m_sortByCol;
00452     bool                        m_disableProcessing;
00453 
00454     wxSize                      m_summaryCoverSize;
00455     wxSize                      m_thumbnailCoverSize;
00456 
00457     long                        m_lastIdentifier;
00458 
00459     AxResourceLibrarySettings   m_settings;
00460 
00461     wxEditorCommandManager*     m_commandManager;
00462     
00463     static AxResourceLibrary*   sm_library;
00464 
00465     // cdCoverDesign            m_coverDesign;
00466 };
00467 
00469 int axFindByISBN(const AxResourceInfoArray& books, const wxString& isbn);
00470 
00471 #endif
00472     // __AX_RESOURCELIBRART_H_

Generated on Wed May 6 19:20:18 2009 for AxTk by  doxygen 1.5.1