images_scanner.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00053 int width;
00054 int height;
00055 bool is_rotation_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
00067
00068
00069
00070
00071 class ImagesScanner
00072 {
00073 public:
00074
00075
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
00091
00092
00093
00094
00095
00096
00097
00098
00099
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
00115
00116
00117 void set_filename(const std::string & filename);
00118
00119 void append_dir_separator(std::string & dirpath);
00120
00121
00122
00123
00124
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;
00147 bool recursive;
00148 bool isdir;
00149 std::string dir;
00150
00151 typedef std::vector<std::string> ExtNames;
00152 typedef std::vector<std::string>::iterator ExtNamesIter;
00153 ExtNames extnames;
00154
00155 int active;
00156 };
00157
00158 }
00159
00160 #endif // _IMAGES_SCANNER_H_
00161
00162