console/kabcclient
converter.cpp
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 #include <iostream>
00021
00022
00023 #include <QTextCodec>
00024
00025
00026 #include <kcomponentdata.h>
00027
00028
00029 #include <kabc/addressee.h>
00030
00031
00032 #include "formatfactory.h"
00033 #include "inputformat.h"
00034 #include "outputformat.h"
00035
00036 using std::cerr;
00037 using std::cout;
00038 using std::cin;
00039 using std::endl;
00040
00041 int main(int argc, char** argv)
00042 {
00043
00044 if (argc != 3)
00045 {
00046 cerr << "Wrong number of arguments." << endl;
00047 cerr << "Usage: converter inputformat outputformat" << endl;
00048 return -1;
00049 }
00050
00051
00052
00053 FormatFactory factory;
00054
00055 InputFormat* input = factory.inputFormat(argv[1]);
00056 if (input == 0)
00057 {
00058 cerr << "Program argument '" << argv[1] << endl;
00059 cerr << "' does not match any of the known input format names" << endl;
00060 return -1;
00061 }
00062
00063 OutputFormat* output = factory.outputFormat(argv[2]);
00064 if (output == 0)
00065 {
00066 cerr << "Program argument '" << argv[2] << endl;
00067 cerr << "' does not match any of the known output format names" << endl;
00068
00069
00070 delete input;
00071
00072 return -1;
00073 }
00074
00075
00076 QTextCodec* codec = QTextCodec::codecForLocale();
00077 if (!input->setCodec(codec))
00078 {
00079 cerr << "TextCodec '" << codec->name().data() << endl;
00080 cerr << "' rejected by input format '" << argv[1] << endl;
00081
00082
00083 delete input;
00084 delete output;
00085
00086 return -1;
00087 }
00088
00089 codec = QTextCodec::codecForLocale();
00090 if (!output->setCodec(codec))
00091 {
00092 cerr << "TextCodec '" << codec->name().data() << endl;
00093 cerr << "' rejected by output format '" << argv[2] << endl;
00094
00095
00096 delete input;
00097 delete output;
00098
00099 return -1;
00100 }
00101
00102
00103
00104
00105 KComponentData instance("converter");
00106
00107
00108
00109 while (!cin.eof() && !cin.bad())
00110 {
00111 KABC::Addressee addressee = input->readAddressee(cin);
00112
00113
00114 if (addressee.isEmpty())
00115 {
00116 cerr << "Failed to read an addressee." << endl;
00117 }
00118 else
00119 {
00120 output->writeAddressee(addressee, cout);
00121 }
00122 }
00123
00124 delete input;
00125 delete output;
00126
00127 return 0;
00128 }
00129
00130