OSDN Git Service

Refactor API to facilitate implementation of GUI ListView hooks.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Sat, 2 Jun 2012 22:49:11 +0000 (22:49 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Sat, 2 Jun 2012 22:49:11 +0000 (22:49 +0000)
ChangeLog
src/pkgbase.h
src/pkgkeys.c
src/pkgkeys.h
src/pkglist.h [new file with mode: 0644]
src/pkgshow.cpp

index 9a1fd84..b7bfc55 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2012-06-02  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Refactor API to facilitate implementation of GUI ListView hooks.
+
+       * src/pkgkeys.h (title_key, description_key): Declare them.
+       * src/pkgkeys.c (title_key, description_key): Define them; relocate...
+       * src/pkgshow.cpp (pkgDirectoryViewer::EmitDescription): ...from here.
+       (pkgXmlDocument::CalalogueAllPackages): New public method; factor...
+       (pkgXmlDocument::DisplayPackageInfo): ...from here, whence use it.
+       (pkgDirectoryViewerEngine::EnumerateComponents): New private method;
+       implement as a concrete method of this abstract base class; factor...
+       (pkgDirectoryViewer::Dispatch): ...from original inline implementation
+       within this method of the concrete derived class, whence use it.
+       (pkgDirectoryViewerEngine, pkgDirectory): Factor class declarations...
+       * src/pkglist.h: ...into this new header file; include it.
+
+       * src/pkgbase.h (pkgDirectory): Add forward class declaration.
+       (pkgXmlDocument::CatalogueAllPackages): Declare it.
+
 2012-05-02  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Update help text to document package version selection capability.
index be89802..833a9cc 100644 (file)
@@ -85,6 +85,7 @@ EXTERN_C int pkgPutEnv( int, char* );
 /* Begin class declarations.
  */
 class pkgSpecs;
+class pkgDirectory;
 
 class pkgXmlNode : public TiXmlElement
 {
@@ -418,8 +419,9 @@ class pkgXmlDocument : public TiXmlDocument
      */
     pkgXmlNode* FindPackageByName( const char*, const char* = NULL );
 
-    /* Method to display information about packages.
+    /* Methods to retrieve and display information about packages.
      */
+    pkgDirectory *CatalogueAllPackages();
     void DisplayPackageInfo( int, char** );
 
     /* Method to resolve the dependencies of a specified package,
index 2bcf764..45029b5 100644 (file)
@@ -31,6 +31,7 @@ const char *catalogue_key         =   "catalogue";
 const char *class_key              =   "class";
 const char *component_key          =   "component";
 const char *defaults_key           =   "defaults";
+const char *description_key        =   "description";
 const char *dirname_key            =   "dir";
 const char *download_key           =   "download";
 const char *download_host_key      =   "download-host";
@@ -61,6 +62,7 @@ const char *subsystem_key         =   "subsystem";
 const char *sysmap_key             =   "system-map";
 const char *sysroot_key            =   "sysroot";
 const char *tarname_key            =   "tarname";
+const char *title_key              =   "title";
 const char *uri_key                =   "uri";
 
 /* Some standard values, which may be associated with certain
index 9f5342c..d7fca4f 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2010, MinGW Project
+ * Copyright (C) 2010, 2012, MinGW Project
  *
  *
  * Public declarations of the global definitions for the string
@@ -42,6 +42,7 @@ EXTERN_C_DECL const char *catalogue_key;
 EXTERN_C_DECL const char *class_key;
 EXTERN_C_DECL const char *component_key;
 EXTERN_C_DECL const char *defaults_key;
+EXTERN_C_DECL const char *description_key;
 EXTERN_C_DECL const char *dirname_key;
 EXTERN_C_DECL const char *download_key;
 EXTERN_C_DECL const char *download_host_key;
@@ -72,6 +73,7 @@ EXTERN_C_DECL const char *subsystem_key;
 EXTERN_C_DECL const char *sysmap_key;
 EXTERN_C_DECL const char *sysroot_key;
 EXTERN_C_DECL const char *tarname_key;
+EXTERN_C_DECL const char *title_key;
 EXTERN_C_DECL const char *uri_key;
 
 /* Some standard values, which may be associated with certain
diff --git a/src/pkglist.h b/src/pkglist.h
new file mode 100644 (file)
index 0000000..cbc04c0
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef PKGLIST_H
+/*
+ * pkglist.h
+ *
+ * $Id$
+ *
+ * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
+ * Copyright (C) 2010, 2012, MinGW Project
+ *
+ *
+ * Declarations of the classes used to implement the package list
+ * viewers, for both CLI and GUI clients.
+ *
+ *
+ * This is free software.  Permission is granted to copy, modify and
+ * redistribute this software, under the provisions of the GNU General
+ * Public License, Version 3, (or, at your option, any later version),
+ * as published by the Free Software Foundation; see the file COPYING
+ * for licensing details.
+ *
+ * Note, in particular, that this software is provided "as is", in the
+ * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
+ * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
+ * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
+ * MinGW Project, accept liability for any damages, however caused,
+ * arising from the use of this software.
+ *
+ */
+#define PKGLIST_H  1
+
+class pkgDirectory;
+
+class pkgDirectoryViewerEngine
+{
+  /* A minimal abstract base class, through which directory
+   * traversal methods of the following "pkgDirectory" class
+   * gain access to an appropriate handler in a specialised
+   * directory viewer class, (or any other class which may
+   * provide directory traversal hooks).  All such helper
+   * classes should derive from this base class, providing
+   * a "Dispatch" method as the directory traversal hook.
+   */
+  public:
+    virtual void Dispatch( pkgXmlNode * ) = 0;
+
+    pkgDirectory *EnumerateComponents( pkgXmlNode * );
+};
+
+class pkgDirectory
+{
+  /* A locally defined class, used to manage a list of package
+   * or component package references in the form of an unbalanced
+   * binary tree, such that an in-order traversal will produce
+   * an alpha-numerically sorted package list.
+   */
+  public:
+    pkgDirectory( pkgXmlNode * );
+    pkgDirectory *Insert( const char *, pkgDirectory * );
+    void InOrder( pkgDirectoryViewerEngine * );
+    ~pkgDirectory();
+
+  protected:
+    pkgXmlNode *entry;
+    pkgDirectory *prev;
+    pkgDirectory *next;
+};
+
+#endif /* PKGLIST_H: $RCSfile$: end of file */ 
index c5edb7b..022dacf 100644 (file)
@@ -4,7 +4,7 @@
  * $Id$
  *
  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2009, 2010, MinGW Project
+ * Copyright (C) 2009, 2010, 2012, MinGW Project
  *
  *
  * Implementation of the classes and methods required to support the
@@ -31,6 +31,7 @@
 
 #include "pkgbase.h"
 #include "pkgkeys.h"
+#include "pkglist.h"
 
 #include "dmh.h"
 
@@ -453,46 +454,6 @@ pkgNroffLayoutEngine::WriteLn( int style, int offset, int maxlen )
   return curr;
 }
 
-class pkgDirectoryViewerEngine
-{
-  /* A minimal abstract base class, through which directory
-   * traversal methods of the following "pkgDirectory" class
-   * gain access to an appropriate handler in a specialised
-   * directory viewer class, (or any other class which may
-   * provide directory traversal hooks).  All such helper
-   * classes should derive from this base class, providing
-   * a "Dispatch" method as the directory traversal hook.
-   */
-  public:
-    virtual void Dispatch( pkgXmlNode* ) = 0;
-#if 0
-    pkgDirectoryViewerEngine()
-    {
-      for( int i = 1; i < 9; i++ ) printf( "%10d", i ); putchar( '\n' );
-      for( int i = 1; i < 9; i++ ) printf( "1234567890" ); putchar( '\n' );
-    }
-#endif
-};
-
-class pkgDirectory
-{
-  /* A locally defined class, used to manage a list of package
-   * or component package references in the form of an unbalanced
-   * binary tree, such that an in-order traversal will produce
-   * an alpha-numerically sorted package list.
-   */
-  public:
-    pkgDirectory( pkgXmlNode* );
-    pkgDirectory *Insert( const char*, pkgDirectory* );
-    void InOrder( pkgDirectoryViewerEngine* );
-    ~pkgDirectory();
-
-  protected:
-    pkgXmlNode *entry;
-    pkgDirectory *prev;
-    pkgDirectory *next;
-};
-
 /* Constructor...
  */
 pkgDirectory::pkgDirectory( pkgXmlNode *item ):
@@ -772,12 +733,10 @@ void pkgDirectoryViewer::EmitDescription( pkgXmlNode *pkg, const char *title )
    */
   int offset = 0;
 
-  /* These XML element and attribute identification keys should
+  /* This XML element and attribute identification key should
    * perhaps be defined in the pkgkeys.h header; once more, for
-   * the time being we simply define them locally.
+   * the time being we simply define it locally.
    */
-  const char *title_key = "title";
-  const char *description_key = "description";
   const char *paragraph_key = "paragraph";
 
   /* The procedure is recursive, selecting description elements
@@ -867,15 +826,7 @@ void pkgDirectoryViewer::Dispatch( pkgXmlNode *entry )
     /* The selected entity is a full package;
      * create an auxiliary directory...
      */
-    pkgDirectory *dir = NULL;
-    pkgXmlNode *cpt = entry->FindFirstAssociate( component_key );
-    while( cpt != NULL )
-    {
-      /* ...in which we enumerate its components.
-       */
-      dir = dir->Insert( class_key, new pkgDirectory( cpt ) );
-      cpt = cpt->FindNextAssociate( component_key );
-    }
+    pkgDirectory *dir = EnumerateComponents( entry );
 
     /* Signalling that a component list is to be included...
      */
@@ -1024,34 +975,11 @@ void pkgXmlDocument::DisplayPackageInfo( int argc, char **argv )
   }
 
   else
-  {
     /* No arguments were specified; interpret this as a request
      * to display information pertaining to all known packages in
      * the current mingw-get repository's universe, thus...
      */
-    pkgXmlNode *grp = GetRoot()->FindFirstAssociate( package_collection_key );
-    while( grp != NULL )
-    {
-      /* ...for each known package collection...
-       */
-      pkgXmlNode *pkg = grp->FindFirstAssociate( package_key );
-      while( pkg != NULL )
-      {
-       /* ...add an entry for each included package
-        * into the print-out directory...
-        */
-       dir = dir->Insert( name_key, new pkgDirectory( pkg ) );
-       /*
-        * ...enumerating each and every package...
-        */
-       pkg = pkg->FindNextAssociate( package_key );
-      }
-      /* ...then repeat for the next package collection,
-       * if any.
-       */
-      grp = grp->FindNextAssociate( package_collection_key );
-    }
-  }
+    dir = CatalogueAllPackages();
 
   /* Regardless of how the print-out directory was compiled,
    * we hand it off to the common viewer, for output.
@@ -1064,4 +992,56 @@ void pkgXmlDocument::DisplayPackageInfo( int argc, char **argv )
   delete dir;
 }
 
+pkgDirectory *pkgXmlDocument::CatalogueAllPackages()
+{
+  /* A helper method for compiling a catalogue of all available packages,
+   * into a linked list of collated pkgDirectory class instances.
+   *
+   * FIXME: This will eventually need to support filtering of the result,
+   * based on a package group category specification.
+   */
+  pkgDirectory *dir = NULL;
+  pkgXmlNode *grp = GetRoot()->FindFirstAssociate( package_collection_key );
+  while( grp != NULL )
+  {
+    /* ...for each known package collection...
+     */
+    pkgXmlNode *pkg = grp->FindFirstAssociate( package_key );
+    while( pkg != NULL )
+    {
+      /* ...add an entry for each included package
+       * into the print-out directory...
+       */
+      dir = dir->Insert( name_key, new pkgDirectory( pkg ) );
+      /*
+       * ...enumerating each and every package...
+       */
+      pkg = pkg->FindNextAssociate( package_key );
+    }
+    /* ...then repeat for the next package collection,
+     * if any.
+     */
+    grp = grp->FindNextAssociate( package_collection_key );
+  }
+  return dir;
+}
+
+pkgDirectory *pkgDirectoryViewerEngine::EnumerateComponents( pkgXmlNode *pkg )
+{
+  /* A convenience method for enumerating the component packages of
+   * a specified package set, returning the enumerated collection as
+   * a collated list, in a chain of pkgDirectory structures.
+   */
+  pkgDirectory *dir = NULL;
+  pkg = pkg->FindFirstAssociate( component_key );
+  while( pkg != NULL )
+  {
+    /* ...in which we enumerate its components.
+     */
+    dir = dir->Insert( class_key, new pkgDirectory( pkg ) );
+    pkg = pkg->FindNextAssociate( component_key );
+  }
+  return dir;
+}
+
 /* $RCSfile$: end of file */