• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

console/kabcclient

converter.cpp

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2005 - 2006 Kevin Krammer <kevin.krammer@gmx.at>
00003 //
00004 //  This program is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 //
00018 
00019 // standard includes
00020 #include <iostream>
00021 
00022 // Qt includes
00023 #include <QTextCodec>
00024 
00025 // KDE includes
00026 #include <kcomponentdata.h>
00027 
00028 // KABC includes
00029 #include <kabc/addressee.h>
00030 
00031 // local includes
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     // check if we have enough commandline parameters
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     // create format factory and check if the commandline parameters
00052     // match format names
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         // don't forget to delete the InputFormat instance we already have
00070         delete input;
00071 
00072         return -1;
00073     }
00074 
00075     // create codecs. just use local for this simple example
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         // don't forget to delete format instances
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         // don't forget to delete format instances
00096         delete input;
00097         delete output;
00098 
00099         return -1;
00100     }
00101 
00102     // the KComponentData instance is needed for the translation calls
00103     // inside the format implementations.
00104     // in real programs this is usually the KApplication object
00105     KComponentData instance("converter");
00106 
00107     // as long as there is possibly data on standard input
00108     // try to read it and convert it
00109     while (!cin.eof() && !cin.bad())
00110     {
00111         KABC::Addressee addressee = input->readAddressee(cin);
00112 
00113         // check if object actually contains anything
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 // End of File

console/kabcclient

Skip menu "console/kabcclient"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal