From ed99a30644c19b0a3cf0d2147243532df4daa16b Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 15 Feb 2013 21:57:54 -0600 Subject: Rename additional header files to avoid conflicts with KDE4 --- tdeabc/formats/CMakeLists.txt | 47 +++++++++ tdeabc/formats/Makefile.am | 22 ++++ tdeabc/formats/binary.desktop | 89 ++++++++++++++++ tdeabc/formats/binaryformat.cpp | 221 ++++++++++++++++++++++++++++++++++++++++ tdeabc/formats/binaryformat.h | 69 +++++++++++++ 5 files changed, 448 insertions(+) create mode 100644 tdeabc/formats/CMakeLists.txt create mode 100644 tdeabc/formats/Makefile.am create mode 100644 tdeabc/formats/binary.desktop create mode 100644 tdeabc/formats/binaryformat.cpp create mode 100644 tdeabc/formats/binaryformat.h (limited to 'tdeabc/formats') diff --git a/tdeabc/formats/CMakeLists.txt b/tdeabc/formats/CMakeLists.txt new file mode 100644 index 000000000..d7a9e0fc9 --- /dev/null +++ b/tdeabc/formats/CMakeLists.txt @@ -0,0 +1,47 @@ +################################################# +# +# (C) 2010 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_BINARY_DIR}/kabc + ${CMAKE_SOURCE_DIR}/kabc + + ${TQT_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR}/tdecore + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/dcop + ${CMAKE_SOURCE_DIR}/tdecore + ${CMAKE_SOURCE_DIR}/tdeio + ${CMAKE_SOURCE_DIR}/tdeio/tdeio +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### other data ################################ + +install( FILES binary.desktop DESTINATION ${DATA_INSTALL_DIR}/tdeabc/formats ) + + +##### kabcformat_binary ######################### + +set( target kabcformat_binary ) + +set( ${target}_SRCS + binaryformat.cpp +) + +tde_add_kpart( ${target} AUTOMOC + SOURCES ${${target}_SRCS} + LINK tdeabc-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdeabc/formats/Makefile.am b/tdeabc/formats/Makefile.am new file mode 100644 index 000000000..d769d88d7 --- /dev/null +++ b/tdeabc/formats/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES = -I$(top_srcdir)/kabc -I$(top_builddir)/kabc $(all_includes) + +kde_module_LTLIBRARIES = kabcformat_binary.la + +kabcformat_binary_la_SOURCES = binaryformat.cpp +kabcformat_binary_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) \ + -no-undefined +kabcformat_binary_la_LIBADD = $(LIB_KABC) $(LIB_QT) $(LIB_TDECORE) +kabcformat_binary_la_COMPILE_FIRST = $(top_builddir)/tdeabc/addressee.h + +# these are the headers for your project +noinst_HEADERS = binaryformat.h + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kabcformat_binary.pot + +linkdir = $(kde_datadir)/tdeabc/formats +link_DATA = binary.desktop +EXTRA_DIST = $(link_DATA) diff --git a/tdeabc/formats/binary.desktop b/tdeabc/formats/binary.desktop new file mode 100644 index 000000000..993286ad5 --- /dev/null +++ b/tdeabc/formats/binary.desktop @@ -0,0 +1,89 @@ +[Misc] +Name=Binary +Name[af]=Binêre +Name[ar]=ثنائي +Name[az]=İcraçı +Name[be]=Двайковы +Name[bg]=Двоичен +Name[bn]=বাইনারি +Name[br]=Binarel +Name[bs]=Binarno +Name[ca]=Binari +Name[cs]=Binární +Name[csb]=Binarny +Name[cy]=Deuaidd +Name[da]=Binær +Name[de]=Binär +Name[el]=Δυαδικό +Name[eo]=Duuma +Name[es]=Binario +Name[et]=Binaar +Name[eu]=Bitarra +Name[fa]=دوگانی +Name[fi]=Binääri +Name[fr]=Binaire +Name[fy]=Binêr +Name[ga]=Dénártha +Name[gl]=Binário +Name[he]=בינרית +Name[hi]=द्विचर +Name[hr]=Binarno +Name[hsb]=Binarny +Name[hu]=Bináris +Name[id]=Biner +Name[is]=Tvíunda +Name[it]=Binario +Name[ja]=バイナリ +Name[ka]=ორობითი +Name[kk]=Бинарлық +Name[km]=គោលពីរ +Name[ko]=바이너리 +Name[lb]=Binär +Name[lt]=Dvejetainis +Name[lv]=Binārs +Name[mk]=Бинарен +Name[mn]=Бинар +Name[ms]=Binari +Name[mt]=Binarju +Name[nb]=Binær +Name[nds]=Bineer +Name[ne]=बाइनरी +Name[nl]=Binair +Name[nn]=Binær +Name[nso]=Tselapedi +Name[pa]=ਬਾਈਨਰੀ +Name[pl]=Binarny +Name[pt]=Binário +Name[pt_BR]=Binário +Name[ro]=Binar +Name[ru]=Двоичный +Name[rw]=Nyabibiri +Name[se]=Binára +Name[sk]=Binárny +Name[sl]=Dvojiško +Name[sq]=Binarë +Name[sr]=Бинарни +Name[sr@Latn]=Binarni +Name[ss]=Lokuhamab ngakubili +Name[sv]=Binär +Name[ta]=இருமம் +Name[te]=ద్వియాశం +Name[tg]=Дутартиба +Name[th]=ไบนารี +Name[tr]=İkili +Name[tt]=Binar +Name[uk]=Двійковий +Name[uz]=Binar +Name[uz@cyrillic]=Бинар +Name[ven]=Zwivhili +Name[vi]=Nhị phân +Name[wa]=Binaire +Name[xh]=Ephindwe kabini +Name[zh_CN]=二进制 +Name[zh_HK]=二進位 +Name[zh_TW]=二進位 +Name[zu]=Okuhambisana ngambili + +[Plugin] +Type=binary +X-TDE-Library=kabcformat_binary diff --git a/tdeabc/formats/binaryformat.cpp b/tdeabc/formats/binaryformat.cpp new file mode 100644 index 000000000..f37146e57 --- /dev/null +++ b/tdeabc/formats/binaryformat.cpp @@ -0,0 +1,221 @@ +/* + This file is part of libkabc. + Copyright (c) 2002 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include +#include +#include + +#include "addressbook.h" +#include "addressee.h" +#include "picture.h" +#include "sound.h" + +#include "binaryformat.h" + +#define BINARY_FORMAT_VERSION 1 + +using namespace KABC; + +extern "C" +{ + KDE_EXPORT FormatPlugin *format() + { + return new BinaryFormat; + } +} + +bool BinaryFormat::load( Addressee &addressee, TQFile *file ) +{ + kdDebug(5700) << "BinaryFormat::load()" << endl; + TQDataStream stream( file ); + + if ( !checkHeader( stream ) ) + return false; + + loadAddressee( addressee, stream ); + + return true; +} + +bool BinaryFormat::loadAll( AddressBook*, Resource *resource, TQFile *file ) +{ + kdDebug(5700) << "BinaryFormat::loadAll()" << endl; + + TQDataStream stream( file ); + + if ( !checkHeader( stream ) ) + return false; + + TQ_UINT32 entries; + + stream >> entries; + + for ( uint i = 0; i < entries; ++i ) { + Addressee addressee; + loadAddressee( addressee, stream ); + addressee.setResource( resource ); + addressee.setChanged( false ); + resource->insertAddressee( addressee ); + } + + return true; +} + +void BinaryFormat::save( const Addressee &addressee, TQFile *file ) +{ + kdDebug(5700) << "BinaryFormat::save()" << endl; + + TQDataStream stream( file ); + + writeHeader( stream ); + + TQ_UINT32 entries = 1; + stream << entries; + saveAddressee( addressee, stream ); +} + +void BinaryFormat::saveAll( AddressBook*, Resource *resource, TQFile *file ) +{ + kdDebug(5700) << "BinaryFormat::saveAll()" << endl; + + TQ_UINT32 counter = 0; + TQDataStream stream( file ); + + writeHeader( stream ); + // set dummy number of entries + stream << counter; + + Resource::Iterator it; + for ( it = resource->begin(); it != resource->end(); ++it ) { + saveAddressee( (*it), stream ); + counter++; + (*it).setChanged( false ); + } + + // set real number of entries + stream.device()->at( 2 * sizeof( TQ_UINT32 ) ); + stream << counter; +} + +bool BinaryFormat::checkFormat( TQFile *file ) const +{ + kdDebug(5700) << "BinaryFormat::checkFormat()" << endl; + + TQDataStream stream( file ); + + return checkHeader( stream ); +} + +bool BinaryFormat::checkHeader( TQDataStream &stream ) const +{ + TQ_UINT32 magic, version; + + stream >> magic >> version; + + TQFile *file = dynamic_cast( stream.device() ); + + if ( !file ) { + kdError() << i18n("Not a file?") << endl; + return false; + } + + if ( magic != 0x2e93e ) { + kdError() << TQString(i18n("File '%1' is not binary format.").arg( file->name() )) << endl; + return false; + } + + if ( version != BINARY_FORMAT_VERSION ) { + kdError() << TQString(i18n("File '%1' is the wrong version.").arg( file->name() )) << endl; + return false; + } + + return true; +} + +void BinaryFormat::writeHeader( TQDataStream &stream ) +{ + TQ_UINT32 magic, version; + + magic = 0x2e93e; + version = BINARY_FORMAT_VERSION; + + stream << magic << version; +} + +void BinaryFormat::loadAddressee( Addressee &addressee, TQDataStream &stream ) +{ + stream >> addressee; +/* + // load pictures + Picture photo = addressee.photo(); + Picture logo = addressee.logo(); + + if ( photo.isIntern() ) { + TQImage img; + if ( !img.load( locateLocal( "data", "tdeabc/photos/" ) + addressee.uid() ) ) + kdDebug(5700) << "No photo available for '" << addressee.uid() << "'." << endl; + + addressee.setPhoto( img ); + } + + if ( logo.isIntern() ) { + TQImage img; + if ( !img.load( locateLocal( "data", "tdeabc/logos/" ) + addressee.uid() ) ) + kdDebug(5700) << "No logo available for '" << addressee.uid() << "'." << endl; + + addressee.setLogo( img ); + } + + // load sound + // TODO: load sound data from file +*/ +} + +void BinaryFormat::saveAddressee( const Addressee &addressee, TQDataStream &stream ) +{ + stream << addressee; +/* + // load pictures + Picture photo = addressee.photo(); + Picture logo = addressee.logo(); + + if ( photo.isIntern() ) { + TQImage img = photo.data(); + TQString fileName = locateLocal( "data", "tdeabc/photos/" ) + addressee.uid(); + + if ( !img.save( fileName, "PNG" ) ) + kdDebug(5700) << "Unable to save photo for '" << addressee.uid() << "'." << endl; + } + + if ( logo.isIntern() ) { + TQImage img = logo.data(); + TQString fileName = locateLocal( "data", "tdeabc/logos/" ) + addressee.uid(); + + if ( !img.save( fileName, "PNG" ) ) + kdDebug(5700) << "Unable to save logo for '" << addressee.uid() << "'." << endl; + } + + // save sound + // TODO: save the sound data to file +*/ +} diff --git a/tdeabc/formats/binaryformat.h b/tdeabc/formats/binaryformat.h new file mode 100644 index 000000000..09efde41a --- /dev/null +++ b/tdeabc/formats/binaryformat.h @@ -0,0 +1,69 @@ +/* + This file is part of libkabc. + Copyright (c) 2002 Tobias Koenig + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KABC_BINARYFORMAT_H +#define KABC_BINARYFORMAT_H + +#include "formatplugin.h" + +namespace KABC { + +class AddressBook; +class Addressee; + +/** + @short binary file format for addressbook entries. +*/ +class BinaryFormat : public FormatPlugin +{ +public: + /** + * Load single addressee from file. + */ + bool load( Addressee &, TQFile *file ); + + /** + * Load whole addressee from file. + */ + bool loadAll( AddressBook *, Resource *, TQFile *file ); + + /** + * Save single addressee to file. + */ + void save( const Addressee &, TQFile *file ); + + /** + * Save all addressees to file. + */ + void saveAll( AddressBook *, Resource *, TQFile *file ); + + /** + * Check for valid format of a file. + */ + bool checkFormat( TQFile *file ) const; + +private: + void loadAddressee( Addressee &, TQDataStream & ); + void saveAddressee( const Addressee &, TQDataStream & ); + bool checkHeader( TQDataStream & ) const; + void writeHeader( TQDataStream & ); +}; + +} +#endif -- cgit v1.2.1