images_scanner.h

Go to the documentation of this file.
00001 /*
00002  * File Name: images_scanner.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-images.
00007  *
00008  * uds-plugin-images is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-images is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #ifndef _IMAGES_SCANNER_H_
00028 #define _IMAGES_SCANNER_H_
00029 
00030 #include <vector>
00031 #include <string>
00032 
00033 #include <glib.h>
00034 
00035 #include "plugin_type.h"
00036 
00037 namespace images
00038 {
00039     typedef enum
00040     {
00041         BY_FILEPATH = 0,
00042         BY_FILENAME,
00043         BY_EXT,
00044         BY_DATE,
00045         BY_SIZE,
00046     }SortType;
00047 
00048     struct Image
00049     {
00050         std::string path;
00051      
00052         // MetaData
00053         int width;     // '-1' means need to calculate.
00054         int height;    // '-1' means need to calculate.
00055         bool is_rotation_calculated;    // true/false means rotation is/is-not calculated
00056         PluginRotationDegree rotation;  // 
00057 
00058         std::string sort_field;
00059     };
00060 
00061     typedef Image *ImagePtr;
00062     typedef std::vector<ImagePtr> Images;
00063     typedef std::vector<ImagePtr>::iterator ImagesIter;
00064 
00065     /**
00066      * @brief  : Scan all the images in the formats supported by gdk_pixbuf
00067      *           under the input directory 
00068      *           or the directory which the input filename is located in.
00069      *           It also supports the option of scanning recursively or not.
00070      */
00071     class ImagesScanner
00072     {
00073         public:
00074             /**
00075              * @brief Construct a 'ImagesScanner'.
00076              */
00077             ImagesScanner(void);
00078             ~ImagesScanner(void);
00079 
00080         public:
00081             bool is_image(const std::string & filename);
00082             
00083             static bool get_size(const std::string & filename,
00084                                  int * width, int * height);             
00085 
00086             static void get_original_rotation(const std::string & filename, 
00087                                               PluginRotationDegree & rotation);
00088 
00089             /**
00090              * @brief Set the filename or directory to scan.
00091              * @param filename 
00092              * @param to_scan_dir Scan or not scan the directory where the filename is in.
00093              * @param recursive_flag Scan recursively or not.
00094              * @param sort_type Sort by date, size, etc.
00095              * @param sort_ascending Sort by ascending or descending.
00096              * @return Get the index of the current active image.
00097              *        The current active image is the input filename.
00098              *        Or if the input filename is directory, 
00099              *        the active image is the first image file found.
00100              */
00101             int scan_images(const std::string & filename,
00102                             bool to_scan_dir,
00103                             bool recursive_flag,
00104                             SortType sort_type,
00105                             bool sort_ascending,
00106                             Images & results);
00107         
00108        private:
00109             void get_supported_extnames(void);
00110 
00111             bool check_extname(const std::string & filename);
00112 
00113             /**
00114              * @brief Set the filename or directory to scan.
00115              * @param filename: the image filepath or dir
00116              */
00117             void set_filename(const std::string & filename);
00118 
00119             void append_dir_separator(std::string & dirpath);
00120             
00121             /**
00122             * @brief Scan the dir, check each file by using filter.
00123             *        If yes, add the filename into the results list.
00124             *        Meanwhile set the current activate image.
00125             */
00126             void scan_dir(const std::string & dirpath, 
00127                           Images & results);
00128 
00129             void sort_images(Images & results,
00130                              SortType sort_type, 
00131                              bool sort_ascending);
00132 
00133             static bool greater_by_filepath(Image * a, Image * b); 
00134             static bool greater_by_filename(Image * a, Image * b); 
00135             static bool greater_by_ext(Image * a, Image * b); 
00136             static bool greater_by_date(Image * a, Image * b); 
00137             static bool greater_by_size(Image * a, Image * b); 
00138 
00139             static bool less_by_filepath(Image * a, Image * b); 
00140             static bool less_by_filename(Image * a, Image * b); 
00141             static bool less_by_ext(Image * a, Image * b); 
00142             static bool less_by_date(Image * a, Image * b); 
00143             static bool less_by_size(Image * a, Image * b); 
00144 
00145         private:
00146             std::string filepath; ///< the original input file path
00147             bool recursive;       ///< scan recursively or not
00148             bool isdir;           ///< the input filename is directory
00149             std::string dir;      ///< the directory to scan
00150 
00151             typedef std::vector<std::string> ExtNames;
00152             typedef std::vector<std::string>::iterator ExtNamesIter;
00153             ExtNames extnames; ///<  stored in format doc jpg bmp png etc.
00154 
00155             int  active;        ///< the index of the active image
00156     };
00157 
00158 } // namespace image
00159 
00160 #endif // _IMAGES_SCANNER_H_
00161 
00162 
Generated by  doxygen 1.6.2-20100208