1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
/*******************************************
PDF Chain
Copyright: 2009 Martin Singer
<http://sourceforge.net/projects/pdfchain/>
Author: Martin Singer
<m_power3@users.sourceforge.net>
License: GPL version 3+
<http://www.gnu.org/licenses/>
Main
src/main.cc
*******************************************/
#include "definings.hh"
#include "mainwindow.hh"
#include "dialogs.hh"
/*** Main ***/
int main(int argc, char *argv[]){
Gtk::Main kit(argc, argv);
class_window_main window_main;
Gtk::Main::run(window_main);
return 0;
}
/*** Execute PDFTK Command ***/
bool execute(Gtk::Window* pt_parent, Glib::ustring command){
int i = -1;
bool error = false;
std::string str_command;
class_dialogs* pt_dialogs = new class_dialogs();
// Test for ASCII
//if(command.is_ascii() == true){
if(true){
std::cout << std::endl << command.c_str(); // Output
i = system(command.c_str()); // Execute Command
// Test for PDFTK-Error
if( i != 0){
// On Error
error = true;
// Error Messages
//pt_dialogs->error_cerr("class_dialogs::execute_command()", Text::err_PDFTK, i);
pt_dialogs->error_cerr("class_dialogs::execute_command()", Text::err_PDFTK, Text::err_msg_NO_OUTPUT_CREATED);
std::cerr << ": " << Text::str_QUOTE_BEGIN << i << Text::str_QUOTE_END;
pt_dialogs->error_message(pt_parent, Text::str_PDFTK, Text::err_PDFTK);
}
else{
// Info Message
pt_dialogs->info_message(pt_parent, Text::str_PDFTK, Text::msg_PDFTK);
}
}
else{
error = true;
// Error Messages
pt_dialogs->error_cerr("class_dialogs::execute_command()", Text::err_ASCII, command);
pt_dialogs->error_message(pt_parent, Text::str_ASCII, Text::err_ASCII);
}
std::cout << std::endl;
return error;
}
/*** Quoting (known) Special Characters for PDFTK ***/
Glib::ustring quote_out(Glib::ustring str){
Glib::ustring::size_type pos = 0, next_pos = 0;
// Quoting ' '
pos = next_pos = 0;
do{
pos = str.find(" ", next_pos, 1);
if(pos != Glib::ustring::npos){
str.insert(pos, "\\");
next_pos = pos + 2;
}
}while(pos != Glib::ustring::npos);
// Quoting ')'
pos = next_pos = 0;
do{
pos = str.find(")", next_pos, 1);
if(pos != Glib::ustring::npos){
str.insert(pos, "\\");
next_pos = pos + 2;
}
}while(pos != Glib::ustring::npos);
// Quoting '('
pos = next_pos = 0;
do{
pos = str.find("(", next_pos, 1);
if(pos != Glib::ustring::npos){
str.insert(pos, "\\");
next_pos = pos + 2;
}
}while(pos != Glib::ustring::npos);
return str;
}
/*** Get Pagenumber (loads and counts pages from a PDF) ***/
unsigned int get_pagenumber(Glib::ustring filename){
unsigned int pages = 0;
Glib::ustring ustring_file_contents;
Glib::ustring::size_type pos = 0;
Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename);
if(file->query_exists() == true){
Glib::RefPtr<Gio::FileInputStream> stream = file->read();
char read_buffer[BUFFER_SIZE];
gssize bytes_read = 0;
// Read PDF
do{
bytes_read = stream->read (read_buffer, sizeof (read_buffer));
ustring_file_contents += Glib::ustring(read_buffer, read_buffer + bytes_read);
}while(bytes_read != 0);
stream->close();
// Searching for Strings
pos = 0;
while(pos != Glib::ustring::npos){
if((pos = ustring_file_contents.find(STRING_AT_PDF1, pos)) != Glib::ustring::npos){
pages++;
pos++;
}
}
pos = 0;
while(pos != Glib::ustring::npos){
if((pos = ustring_file_contents.find(STRING_AT_PDF2, pos)) != Glib::ustring::npos){
pages++;
pos++;
}
}
pos = 0;
while(pos != Glib::ustring::npos){
if((pos = ustring_file_contents.find(STRING_AT_PDF3, pos)) != Glib::ustring::npos){
pages--;
pos++;
}
}
pos = 0;
while(pos != Glib::ustring::npos){
if((pos = ustring_file_contents.find(STRING_AT_PDF4, pos)) != Glib::ustring::npos){
pages--;
pos++;
}
}
}
if(pages == 0){
// Error Message
//dialogs.error_cerr("class_window_main::get_pagenumber()", Text::err_FILE_HAS_NO_PAGES, filename);
}
return pages;
}
/*** Get Filnemame (cut out form whole Path) ***/
Glib::ustring get_filename(Glib::ustring sourcepath){
Glib::ustring filename;
Glib::ustring::size_type pos = 0;
if((pos = sourcepath.rfind('/')) != Glib::ustring::npos){
filename = sourcepath;
filename.erase(0, pos+1);
}
return filename;
}
/*** Get ustring form unsigned int ***/
Glib::ustring get_ustring_from_unsigned_int(unsigned int i){
Glib::ustring str;
if(i == 0){
str = "0";
}
else{
while(i != 0){
str.insert(0, 1, i%10 + '0');
i /= 10;
}
}
return str;
}
/*** Get an upper case letter (0=A - 25=Z) ***/
char get_letter(unsigned int n){
if(n >= FILES_MAX){
// Error Message
//dialogs.error_cerr("class_window_main::merge_get_letter()", Text::err_UNDEFINED_CHARACTER_REQUESTED, "Z");
return 'Z';
}
return n+'A';
}
|